1# Tests for VMS::Stdio v2.2
2use VMS::Stdio;
3import VMS::Stdio qw(&flush &getname &rewind &sync &tmpnam);
4
5print "1..19\n";
6print +(defined(&getname) ? '' : 'not '), "ok 1\n";
7
8#VMS can pretend that it is UNIX.
9my $perl = $^X;
10$perl = VMS::Filespec::vmsify($perl) if $^O eq 'VMS';
11
12$name = "test$$";
13$name++ while -e "$name.tmp";
14$fh = VMS::Stdio::vmsopen("+>$name",'ctx=rec','shr=put','fop=dlt','dna=.tmp');
15print +($fh ? '' : 'not '), "ok 2\n";
16
17print +(flush($fh) ? '' : 'not '),"ok 3\n";
18print +(sync($fh) ? '' : 'not '),"ok 4\n";
19
20$time = (stat("$name.tmp"))[9];
21print +($time ? '' : 'not '), "ok 5\n";
22
23$fh->autoflush;  # Can we autoload autoflush from IO::File?  Do or die.
24print "ok 6\n";
25
26print 'not ' unless print $fh scalar(localtime($time)),"\n";
27print "ok 7\n";
28
29print +(rewind($fh) ? '' : 'not '),"ok 8\n";
30
31chop($line = <$fh>);
32print +($line eq localtime($time) ? '' : 'not '), "ok 9\n";
33
34($gotname) = (getname($fh) =~/\](.*);/);
35
36#we may be in UNIX emulation mode.
37if (!defined($gotname)) {
38   ($gotname) = (VMS::Filespec::vmsify(getname($fh)) =~/\](.*)/);
39}
40print +("\U$gotname" eq "\U$name.tmp" ? '' : 'not '), "ok 10\n";
41
42$sfh = VMS::Stdio::vmssysopen($name, O_RDONLY, 0,
43                              'ctx=rec', 'shr=put', 'dna=.tmp');
44print +($sfh ? '' : 'not ($!) '), "ok 11\n";
45
46close($fh);
47sysread($sfh,$line,24);
48print +($line eq localtime($time) ? '' : 'not '), "ok 12\n";
49
50undef $sfh;
51print +(stat("$name.tmp") ? 'not ' : ''),"ok 13\n";
52
53print +(&VMS::Stdio::tmpnam ? '' : 'not '),"ok 14\n";
54
55#if (open(P, qq[| $^X -e "1 while (<STDIN>);print 'Foo';1 while (<STDIN>); print 'Bar'" >$name.tmp])) {
56#  print P "Baz\nQuux\n";
57#  print +(VMS::Stdio::writeof(P) ? '' : 'not '),"ok 15\n";
58#  print P "Baz\nQuux\n";
59#  print +(close(P) ? '' : ''),"ok 16\n";
60#  $fh = VMS::Stdio::vmsopen("$name.tmp");
61#  chomp($line = <$fh>);
62#  close $fh;
63#  unlink("$name.tmp");
64#  print +($line eq 'FooBar' ? '' : 'not '),"ok 17\n";
65#}
66#else {
67print "ok 15\nok 16\nok 17\n";
68#}
69
70$sfh = VMS::Stdio::vmsopen(">$name.tmp");
71$setuperl = "\$ MCR $perl\nBEGIN { \@INC = qw(@INC) };\nuse VMS::Stdio qw(&setdef);";
72print $sfh qq[\$ here = F\$Environment("Default")\n];
73print $sfh "$setuperl\nsetdef();\n\$ Show Default\n\$ Set Default 'here'\n";
74print $sfh "$setuperl\nsetdef('..');\n\$ Show Default\n";
75close $sfh;
76@defs = map { /(\S+)/ && $1 } `\@$name.tmp`;
77unlink("$name.tmp");
78print +($defs[0] eq uc($ENV{'SYS$LOGIN'}) ? '' : "not ($defs[0]) "),"ok 18\n";
79#print +($defs[1] eq VMS::Filespec::rmsexpand('[-]') ? '' : "not ($defs[1]) "),"ok 19\n";
80
81# This is not exactly a test of VMS::Stdio, but we need it to create a record-oriented
82# file and then make sure perlio can write to it without introducing spurious newlines.
83
841 while unlink 'rectest.lis';
85END { 1 while unlink 'rectest.lis'; }
86
87$fh = VMS::Stdio::vmsopen('>rectest.lis', 'rfm=var', 'rat=cr')
88   or die "Couldn't open rectest.lis: $!";
89close $fh;
90
91open $fh, '>', 'rectest.lis'
92   or die "Couldn't open rectest.lis: $!";
93
94for (1..20) { print $fh ('Z' x 2048) . "\n" ; }
95
96close $fh;
97
98open $fh, '<', 'rectest.lis'
99   or die "Couldn't open rectest.lis: $!";
100
101my @records = <$fh>;
102close $fh;
103
104if (scalar(@records) == 20) {
105    print "ok 19\n";
106}
107else {
108    print "not ok 18 # Expected 20 got " . scalar(@records) . "\n";
109}
110