Upgrade to CPAN-1.88_77.
[p5sagit/p5-mst-13.2.git] / ext / Win32API / File / t / tie.t
1 #!perl
2 # vim:syntax=perl:
3
4 BEGIN { $|= 1; print "1..10\n"; }
5 END   { print "not ok 1\n" unless $main::loaded; }
6
7 use strict;
8 use warnings;
9 use Win32API::File qw(:ALL);
10 use IO::File;
11
12 $main::loaded = 1;
13
14 print "ok 1\n";
15
16 unlink "foo.txt";
17
18 my $fh = new Win32API::File "+> foo.txt"
19         or die fileLastError();
20
21 my $tell = tell $fh;
22 print "# tell \$fh == '$tell'\n";
23 print "not " unless
24         tell $fh == 0;
25 print "ok 2\n";
26
27 my $text = "some text\n";
28
29 print "not " unless
30         print $fh $text;
31 print "ok 3\n";
32
33 $tell = tell $fh;
34 print "# after printing 'some text\\n', tell is: '$tell'\n";
35 print "not " unless
36         $tell == length($text) + 1;
37 print "ok 4\n";
38
39 print "not " unless
40         seek($fh, 0, 0) == 0;
41 print "ok 5\n";
42
43 print "not " unless
44         not eof $fh;
45 print "ok 6\n";
46
47 my $readline = <$fh>;
48
49 my $pretty_readline = $readline;
50 $pretty_readline =~ s/\r/\\r/g;  $pretty_readline =~ s/\n/\\n/g;  
51 print "# read line is '$pretty_readline'\n";
52
53 print "not " unless
54         $readline eq "some text\r\n";
55 print "ok 7\n";
56
57 print "not " unless
58         eof $fh;
59 print "ok 8\n";
60
61 print "not " unless
62         close $fh;
63 print "ok 9\n";
64
65 # Test out binmode (should be only LF with print, no CR).
66
67 $fh = new Win32API::File "+> foo.txt"
68         or die fileLastError();
69 binmode $fh;
70 print $fh "hello there\n";
71 seek $fh, 0, 0;
72
73 print "not " unless
74         <$fh> eq "hello there\n";
75 print "ok 10\n";
76
77 close $fh;
78
79 unlink "foo.txt";