xref: /openbsd-src/gnu/usr.bin/perl/cpan/Term-ReadKey/t/02_terminal_functions.t (revision c90a81c56dcebd6a1b73fe4aff9b03385b8e63b3)
1use strict;
2use warnings;
3
4
5use Test::More tests => 7;
6
7use Term::ReadKey;
8use Fcntl;
9
10if ( not exists $ENV{COLUMNS} ){
11    $ENV{COLUMNS} = 80;
12    $ENV{LINES}   = 24;
13}
14
15SKIP:
16{
17    eval {
18        if ( $^O =~ /Win32/i ){
19            sysopen( IN,  'CONIN$',  O_RDWR ) or die "Unable to open console input:$!";
20            sysopen( OUT, 'CONOUT$', O_RDWR ) or die "Unable to open console output:$!";
21        }
22        else{
23            if ( open( IN, "</dev/tty" ) ){
24                *OUT = *IN;
25                die "Foo" unless -t OUT;
26            }
27            else{
28                die "/dev/tty is absent\n";
29            }
30        }
31    };
32    skip( 'Because Term::ReadKey need at least a tty to be useful', 1 ) if $@;
33    *IN = *IN;    # Make single-use warning go away
34    $|  = 1;
35    no strict "subs";
36    my $size1 = join( ",", GetTerminalSize( \IN ) );
37    my $size2 = join( ",", GetTerminalSize("IN") );
38    my $size3 = join( ",", GetTerminalSize(*IN) );
39    my $size4 = join( ",", GetTerminalSize( \*IN ) );
40
41    my $size_result=0;
42    if ( ( $size1 eq $size2 ) && ( $size2 eq $size3 ) && ( $size3 eq $size4 ) ){
43        $size_result = 1;
44    }
45    is($size_result, 1, "Comparing TerminalSize IN");
46
47    my $usable_terminal=0;
48    for (my $i = 1; $i < 6; $i++){
49        if ( &Term::ReadKey::termoptions() == $i ){
50            $usable_terminal = 1;
51            last;
52        }
53    }
54    is($usable_terminal, 1, "Manipulating the terminal.");
55
56    my @modes;
57    eval {
58        push( @modes, "O_NODELAY" ) if &Term::ReadKey::blockoptions() & 1;
59        push( @modes, "poll()" )    if &Term::ReadKey::blockoptions() & 2;
60        push( @modes, "select()" )  if &Term::ReadKey::blockoptions() & 4;
61        push( @modes, "Win32" )     if &Term::ReadKey::blockoptions() & 8;
62    };
63    is($@, '', "Check non-blocking read");
64
65    eval {
66        my @size = GetTerminalSize(OUT);
67    };
68    is($@, '', "Check TerminalSize OUT");
69
70    eval {
71        my @speeds = GetSpeed();
72    };
73    is($@, '', "Check Terminal communication speed");
74
75    my %chars;
76    eval {
77        %chars = GetControlChars(IN);
78    };
79    is($@, '', "Validate GetControlChars function");
80
81    my %origchars = %chars;
82    eval {
83        SetControlChars( %origchars, IN );
84    };
85    is($@, '', "Validate SetControlChars function");
86}
87