summaryrefslogtreecommitdiff
path: root/subversion/bindings/swig/perl/native/t/2fs.t
blob: 43e40c785bd347a630b6a258bf9af7547942e204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl -w
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
#

use Test::More tests => 22;
use strict;
no warnings 'once'; # shut up about variables that are only used once.

require SVN::Core;
require SVN::Repos;
require SVN::Fs;
use File::Path qw(rmtree);
use File::Temp qw(tempdir);

my $BINARY_DATA = "foo\0\n\t\x1F\x7F\x80\xA0\x{FF}bar";

my $repospath = tempdir('svn-perl-test-XXXXXX', TMPDIR => 1, CLEANUP => 1);

my $repos;

# TEST
ok($repos = SVN::Repos::create("$repospath", undef, undef, undef, undef),
   "create repository at $repospath");

my $fs = $repos->fs;

# TEST
cmp_ok($fs->youngest_rev, '==', 0,
       "new repository start with rev 0");

# TEST
is($fs->path, "$repospath/db", '$fs->path()');
# TEST
is(SVN::Fs::type($fs->path), 'fsfs', 'SVN::Fs::type()');

my $txn = $fs->begin_txn($fs->youngest_rev);

my $txns = $fs->list_transactions;
# TEST
ok(eq_array($fs->list_transactions, [$txn->name]), 'list transaction');

# TEST
isa_ok($txn->root, '_p_svn_fs_root_t', '$txn->root()');
# TEST
is($txn->root->txn_name, $txn->name, '$txn->root->txn_name()');
# TEST
is($fs->revision_root($fs->youngest_rev)->txn_name, undef);

$txn->root->make_dir('trunk');

my $path = 'trunk/filea';
my $text = "this is just a test\n";
$txn->root->make_file($path);
{
    my $stream = $txn->root->apply_text($path, undef);
    # TEST
    isa_ok($stream, 'SVN::Stream', '$txn->root->apply_text');
    print $stream $text;
    close $stream;
}
$txn->commit;

# TEST
cmp_ok($fs->youngest_rev, '==', 1, 'revision increased');

my $root = $fs->revision_root($fs->youngest_rev);

# TEST
cmp_ok($root->check_path($path), '==', $SVN::Node::file, 'check_path');
# TEST
ok(!$root->is_dir($path), 'is_dir');
# TEST
ok($root->is_file($path), 'is_file');
{
    my $stream = $root->file_contents($path);
    local $/;
    # TEST
    is(<$stream>, $text, 'content verified');
    # TEST
    is($root->file_md5_checksum($path), 'dd2314129f81675e95b940ff94ddc935',
       'md5 verified');
}

# TEST
cmp_ok($root->file_length($path), '==', length($text), 'file_length');

# Revision properties
# TEST
isa_ok($fs->revision_proplist(1), 'HASH', 'revision_proplist: object');
# TEST
is($fs->revision_prop(1, 'not:exists'), undef, 'revision_prop: nonexistent');
# TEST
like($fs->revision_prop(1, 'svn:date'), qr/^\d+-\d+-\d+T\d+:\d+:\d+\.\d+Z$/,
     'revision_prop: svn:date');

# To create a revision property is a bit more difficult, because we have
# to set up a 'pre-revprop-change' hook script.  These tests are skipped
# on systems on which I don't know how to do that.
SKIP: {
    skip "don't know how to create 'pre-revprop-change' hook script on $^O", 3
        if $^O eq 'MSWin32';

    my $script_filename = "$repospath/hooks/pre-revprop-change";
    open my $script, '>', $script_filename
        or die "error creating hook script '$script_filename': $!";
    print $script "#!/bin/sh\nexit 0\n";
    close $script;
    chmod 0755, $script_filename
        or die "error making hook script '$script_filename' executable: $!";

    $fs->change_rev_prop(1, 'test-prop', 'foo');
    # TEST
    is($fs->revision_prop(1, 'test-prop'), 'foo', 'change_rev_prop');

    $fs->change_rev_prop(1, 'test-prop', undef);
    # TEST
    is($fs->revision_prop(1, 'test-prop'), undef, 'change_rev_prop: deleted');

    $fs->change_rev_prop(1, 'binary-prop', $BINARY_DATA);
    # TEST
    is($fs->revision_prop(1, 'binary-prop'), $BINARY_DATA,
       'change_rev_prop with binary data');
}

END {
diag "cleanup";
rmtree($repospath);
}