8 plan skip_all => "POSIX is unavailable"
9 if $Config{extensions} !~ m!\bPOSIX\b!;
12 use POSIX ':termios_h';
15 if !eval "POSIX::Termios->new; 1" && $@ =~ /termios not implemented/;
18 # A termios struct that we've successfully read from a terminal device:
21 foreach (undef, qw(STDIN STDOUT STDERR)) {
29 $name = POSIX::ctermid();
30 skip("Can't get name of controlling terminal", 4)
32 open $handle, '<', $name or skip("can't open $name: $!", 4);
35 skip("$name not a tty", 4) unless -t $handle;
37 my $t = eval { POSIX::Termios->new };
38 is($@, '', "calling POSIX::Termios->new");
39 isa_ok($t, "POSIX::Termios", "checking the type of the object");
41 my $fileno = fileno $handle;
42 my $r = eval { $t->getattr($fileno) };
43 is($@, '', "calling getattr($fileno) for $name");
44 if(isnt($r, undef, "returned value ($r) is defined")) {
50 if (defined $termios) {
52 for my $i (0 .. NCCS-1) {
53 my $r = eval { $termios->getcc($i) };
54 is($@, '', "calling getcc($i)");
55 like($r, qr/\A-?[0-9]+\z/, 'returns an integer');
57 for my $i (NCCS, ~0) {
58 my $r = eval { $termios->getcc($i) };
59 like($@, qr/\ABad getcc subscript/, "calling getcc($i)");
60 is($r, undef, 'returns undef')
63 for my $method (qw(getcflag getiflag getispeed getlflag getoflag getospeed)) {
64 my $r = eval { $termios->$method() };
65 is($@, '', "calling $method()");
66 like($r, qr/\A-?[0-9]+\z/, 'returns an integer');
71 my $t = POSIX::Termios->new();
72 isa_ok($t, "POSIX::Termios", "checking the type of the object");
75 my @baud = (B50, B75, B110, B134, B150, B200, B300, B600, B1200, B1800,
76 B2400, B4800, B9600, B19200, B38400);
78 # On some platforms (eg Linux-that-I-tested), ispeed and ospeed are both
79 # "stored" in the same bits of c_cflag (as the man page documents)
80 # *as well as in struct members* (which you would assume obviates the need
81 # for using c_cflag), and the get*() functions return the value encoded
82 # within c_cflag, hence it's not possible to set/get them independently.
83 foreach my $out (@baud) {
84 is($t->setispeed(0), '0 but true', "setispeed(0)");
85 is($t->setospeed($out), '0 but true', "setospeed($out)");
86 is($t->getospeed(), $out, "getospeed() for $out");
88 foreach my $in (@baud) {
89 is($t->setospeed(0), '0 but true', "setospeed(0)");
90 is($t->setispeed($in), '0 but true', "setispeed($in)");
91 is($t->getispeed(), $in, "getispeed() for $in");