/[fuse-comp]/t/fs.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /t/fs.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Mon Jul 9 10:35:02 2007 UTC revision 25 by dpavlin, Mon Jul 9 22:44:20 2007 UTC
# Line 4  use warnings; Line 4  use warnings;
4    
5  my $debug = shift @ARGV;  my $debug = shift @ARGV;
6    
7  use Test::More tests => 227;  use Test::More tests => 744;
8  use File::Slurp;  use File::Slurp;
9  use IO::File;  use IO::File;
10    
# Line 21  sub dump_debug { Line 21  sub dump_debug {
21          ok( open(my $d, '<', "$to/.debug"), 'open debug' );          ok( open(my $d, '<', "$to/.debug"), 'open debug' );
22          local $/;          local $/;
23          my $dump = <$d>;          my $dump = <$d>;
24          diag "DEBUG: $msg\n$dump\n";          diag "DEBUG: $msg\n$dump\n" if $debug;
25          ok( close($d), 'close debug' );          ok( close($d), 'close debug' );
26  }  }
27    
# Line 63  sub file { Line 63  sub file {
63                  ok( -e "$tmp/$path" , "in tmp $tmp/$path" ) if ( $op eq '<' );                  ok( -e "$tmp/$path" , "in tmp $tmp/$path" ) if ( $op eq '<' );
64                  # check total size if not append                  # check total size if not append
65                  if ( $op ne '>>' ) {                  if ( $op ne '>>' ) {
66                          cmp_ok( -s "$tmp/$path", '==', $size, "$tmp/$path = $size bytes" );                          cmp_ok( -s $pack, '==', $size, "$tmp/$path = $size bytes" );
67                  }                  }
68          } else {          } else {
69                  ok( -e "$from/$path", "on disk $from/$path" );                  ok( -e "$from/$path", "on disk $from/$path" );
70                    diag "$op curr_size: $orig_size size: $size";
71                    $size += $orig_size if ( $op eq '>>' );
72                  cmp_ok( -s "$from/$path", '==', $size, "$from/$path = $size bytes" );                  cmp_ok( -s "$from/$path", '==', $size, "$from/$path = $size bytes" );
73          }          }
74    
# Line 75  sub file { Line 77  sub file {
77          return $content;          return $content;
78  }  }
79    
80    sub md5sum {
81            my $path = shift;
82            my $md5sum = `md5sum $path`;
83            $md5sum =~ s/\s+.*$//s;
84            warn "## md5sum($path) = $md5sum\n" if $debug;
85            return $md5sum;
86    }
87    
88  my $buff = '<<--just a chunk of data-->>';  my $buff = '<<--just a chunk of data-->>';
89    
90  for my $i ( 1 .. 3 ) {  for my $i ( 1 .. 3 ) {
# Line 92  for my $i ( 1 .. 3 ) { Line 102  for my $i ( 1 .. 3 ) {
102          file( '>', $file, '' );          file( '>', $file, '' );
103          file( '<', $file, '' );          file( '<', $file, '' );
104    
105  #       file( '>', $file, $content );          file( '>', $file, $content );
106  #       file( '<', $file, $content );          file( '<', $file, $content );
107    
108    }
109    
110    
111    sub multiple_rw {
112    
113            diag "multiple read-write";
114            ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' );
115            $fh1->autoflush;
116            ok( print($fh1 "1.1\n"), 'print 1.1' );
117            ok( my $fh2 = IO::File->new(">> $to/m"), 'open 2' );
118            $fh2->autoflush;
119            ok( print($fh2 "2.1\n"), 'print 2.1' );
120            cmp_ok( read_file("$to/m"), 'eq', "1.1\n2.1\n", 'mixed' );
121            ok( print($fh1 "1.2\n"), 'print 1.2' );
122            cmp_ok( read_file("$to/m"), 'eq', "1.1\n1.2\n", 'just 1' );
123            dump_debug 'own twice';
124            ok( print($fh1 "x" x 65535), 'print 1 64k' );
125            ok( close($fh1), 'close 1' );
126            dump_debug 'own once';
127            ok( close($fh2), 'close 2' );
128            dump_debug 'closed';
129    
130            my @sizes;
131            my $size = 65536;
132            while ( $size > 1 ) {
133                    push @sizes, $size;
134                    $size /= 2;
135            }
136    
137            foreach my $size ( @sizes ) {
138                    ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' );
139                    ok( truncate( $fh1, $size ), 'truncate' );
140                    dump_debug 'truncate';
141                    ok( close($fh1), 'close 1' );
142                    cmp_ok( -s "$to/m", '==', $size, "truncated to $size" );
143            }
144    
145    
146            foreach my $size ( sort @sizes ) {
147                    my $orig_size = -s "$to/m";
148                    ok( my $fh1 = IO::File->new(">> $to/m"), 'open 1' );
149                    ok( print($fh1 "x" x $size), "print $size bytes" );
150                    dump_debug 'append';
151                    ok( close($fh1), 'close 1' );
152                    my $expected_size = $size + $orig_size;
153                    cmp_ok( -s "$to/m", '==', $expected_size, "appended upto $expected_size" );
154            }
155    
156            ok( $size = -s "$to/m", 'size' );
157            ok( my $md5sum = md5sum("$to/m"), 'md5sum m' );
158            ok( rename("$to/m", "$to/n"), 'rename' );
159            ok( -e "$to/n", "$to/n exists" );
160            ok( ! -e "$to/m", "$to/m gone" );
161            cmp_ok( -s "$to/n", '==', $size, 'size' );
162            cmp_ok( $md5sum, 'eq', md5sum("$to/n"), 'md5sums same' );
163    
164            ok( unlink("$to/n"), "$to/n unlink" );
165            ok( ! -e "$to/n", "$to/n gone" );
166    
167            {
168                    ok( my $fh1 = IO::File->new(">> $to/h"), "open $to/h" );
169                    ok( print($fh1 "foobar"), "print" );
170                    ok( unlink("$to/h"), 'create .fuse_hidden' );
171                    ok( ! -e "$to/h", "$to/h gone" );
172                    dump_debug 'hidden';
173                    ok( print($fh1 "foobar"), "print to hidden" );
174                    ok( close($fh1), "close $to/h" );
175                    diag $!;
176            }
177  }  }
178    
179  diag "multiple read-write";  multiple_rw;
180    multiple_rw;
181    
 ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' );  
 $fh1->autoflush;  
 ok( print($fh1 "1.1\n"), 'print 1.1' );  
 ok( my $fh2 = IO::File->new(">> $to/m"), 'open 2' );  
 $fh2->autoflush;  
 ok( print($fh2 "2.1\n"), 'print 2.1' );  
 cmp_ok( read_file("$to/m"), 'eq', "1.1\n2.1\n", 'mixed' );  
 ok( print($fh1 "1.2\n"), 'print 1.2' );  
 cmp_ok( read_file("$to/m"), 'eq', "1.1\n1.2\n", 'just 1' );  
182    

Legend:
Removed from v.12  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26