| 1 | #!./perl
|
|---|
| 2 |
|
|---|
| 3 | print "1..42\n";
|
|---|
| 4 |
|
|---|
| 5 | chdir('op') || chdir('t/op') || die "sysio.t: cannot look for myself: $!";
|
|---|
| 6 | @INC = '../../lib';
|
|---|
| 7 |
|
|---|
| 8 | open(I, 'sysio.t') || die "sysio.t: cannot find myself: $!";
|
|---|
| 9 |
|
|---|
| 10 | $reopen = ($^O eq 'VMS' ||
|
|---|
| 11 | $^O eq 'os2' ||
|
|---|
| 12 | $^O eq 'MSWin32' ||
|
|---|
| 13 | $^O eq 'NetWare' ||
|
|---|
| 14 | $^O eq 'dos' ||
|
|---|
| 15 | $^O eq 'mpeix');
|
|---|
| 16 |
|
|---|
| 17 | $x = 'abc';
|
|---|
| 18 |
|
|---|
| 19 | # should not be able to do negative lengths
|
|---|
| 20 | eval { sysread(I, $x, -1) };
|
|---|
| 21 | print 'not ' unless ($@ =~ /^Negative length /);
|
|---|
| 22 | print "ok 1\n";
|
|---|
| 23 |
|
|---|
| 24 | # $x should be intact
|
|---|
| 25 | print 'not ' unless ($x eq 'abc');
|
|---|
| 26 | print "ok 2\n";
|
|---|
| 27 |
|
|---|
| 28 | # should not be able to read before the buffer
|
|---|
| 29 | eval { sysread(I, $x, 1, -4) };
|
|---|
| 30 | print 'not ' unless ($x eq 'abc');
|
|---|
| 31 | print "ok 3\n";
|
|---|
| 32 |
|
|---|
| 33 | # $x should be intact
|
|---|
| 34 | print 'not ' unless ($x eq 'abc');
|
|---|
| 35 | print "ok 4\n";
|
|---|
| 36 |
|
|---|
| 37 | $a ='0123456789';
|
|---|
| 38 |
|
|---|
| 39 | # default offset 0
|
|---|
| 40 | print 'not ' unless(sysread(I, $a, 3) == 3);
|
|---|
| 41 | print "ok 5\n";
|
|---|
| 42 |
|
|---|
| 43 | # $a should be as follows
|
|---|
| 44 | print 'not ' unless ($a eq '#!.');
|
|---|
| 45 | print "ok 6\n";
|
|---|
| 46 |
|
|---|
| 47 | # reading past the buffer should zero pad
|
|---|
| 48 | print 'not ' unless(sysread(I, $a, 2, 5) == 2);
|
|---|
| 49 | print "ok 7\n";
|
|---|
| 50 |
|
|---|
| 51 | # the zero pad should be seen now
|
|---|
| 52 | print 'not ' unless ($a eq "#!.\0\0/p");
|
|---|
| 53 | print "ok 8\n";
|
|---|
| 54 |
|
|---|
| 55 | # try changing the last two characters of $a
|
|---|
| 56 | print 'not ' unless(sysread(I, $a, 3, -2) == 3);
|
|---|
| 57 | print "ok 9\n";
|
|---|
| 58 |
|
|---|
| 59 | # the last two characters of $a should have changed (into three)
|
|---|
| 60 | print 'not ' unless ($a eq "#!.\0\0erl");
|
|---|
| 61 | print "ok 10\n";
|
|---|
|
|---|