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