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