| 1 |
|
| #!/usr/bin/perl -w |
| 2 |
|
| # vim: ts=2 sw=2 expandtab |
| 3 |
|
| |
| 4 |
|
| # Tests error conditions. This has to be a separate test since it |
| 5 |
|
| # depends on ASSERT_DEFAULT being 0. All the other tests enable it. |
| 6 |
|
| |
| 7 |
|
| use strict; |
| 8 |
|
| use lib qw(./mylib ../mylib); |
| 9 |
|
| |
| 10 |
|
| sub POE::Kernel::ASSERT_DEFAULT () { 0 } |
| 11 |
|
| |
| 12 |
|
| BEGIN { |
| 13 |
|
| package |
| 14 |
|
| POE::Kernel; |
| 15 |
|
| use constant TRACE_DEFAULT => exists($INC{'Devel/Cover.pm'}); |
| 16 |
|
| } |
| 17 |
|
| |
| 18 |
|
| # use Test::More; |
| 19 |
|
| |
| 20 |
|
| print "1..0 # Skip most of these should move into other test files\n"; |
| 21 |
|
| |
| 22 |
|
| #use POSIX qw(:errno_h); |
| 23 |
|
| #use Socket; |
| 24 |
|
| # |
| 25 |
|
| #BEGIN { |
| 26 |
|
| # my @files_to_unuse = qw( |
| 27 |
|
| # POE/Kernel.pm |
| 28 |
|
| # |
| 29 |
|
| # POE/Loop/Event.pm |
| 30 |
|
| # POE/Loop/Gtk.pm |
| 31 |
|
| # POE/Loop/Poll.pm |
| 32 |
|
| # POE/Loop/Select.pm |
| 33 |
|
| # POE/Loop/Tk.pm |
| 34 |
|
| # |
| 35 |
|
| # POE/Loop/PerlSignals.pm |
| 36 |
|
| # POE/Loop/TkCommon.pm |
| 37 |
|
| # POE/Loop/TkActiveState.pm |
| 38 |
|
| # |
| 39 |
|
| # Event.pm Gtk.pm Tk.pm |
| 40 |
|
| # ); |
| 41 |
|
| # |
| 42 |
|
| # # Clean up after destructive tests. |
| 43 |
|
| # sub test_cleanup { |
| 44 |
|
| # # Not used in POE::Kernel now. |
| 45 |
|
| # |
| 46 |
|
| # delete @INC{ @files_to_unuse }; |
| 47 |
|
| # use Symbol qw(delete_package); |
| 48 |
|
| # delete_package("POE::Kernel"); |
| 49 |
|
| # } |
| 50 |
|
| # |
| 51 |
|
| # # Test that errors occur when multiple event loops are enabled. |
| 52 |
|
| # |
| 53 |
|
| # if ($^O eq 'MSWin32' and not $ENV{POE_DANTIC}) { |
| 54 |
|
| # for (1..3) { |
| 55 |
|
| # print "ok $_ # skipped: This test crashes ActiveState Perl.\n"; |
| 56 |
|
| # } |
| 57 |
|
| # } |
| 58 |
|
| # else { |
| 59 |
|
| # # Event + Tk |
| 60 |
|
| # @INC{'Event.pm', 'Tk.pm'} = (1,1); |
| 61 |
|
| # $Tk::VER .. SION = 800.021; |
| 62 |
|
| # stderr_pause(); |
| 63 |
|
| # eval 'use POE::Kernel'; |
| 64 |
|
| # stderr_resume(); |
| 65 |
|
| # print 'not ' unless defined $@ and length $@; |
| 66 |
|
| # print "ok 1\n"; |
| 67 |
|
| # test_cleanup(); |
| 68 |
|
| # |
| 69 |
|
| # # Gtk + Tk |
| 70 |
|
| # @INC{'Gtk.pm', 'Tk.pm'} = (1, 1); |
| 71 |
|
| # $Tk::VER .. SION = 800.021; |
| 72 |
|
| # stderr_pause(); |
| 73 |
|
| # eval 'use POE::Kernel'; |
| 74 |
|
| # stderr_resume(); |
| 75 |
|
| # print 'not ' unless defined $@ and length $@; |
| 76 |
|
| # print "ok 2\n"; |
| 77 |
|
| # test_cleanup(); |
| 78 |
|
| # |
| 79 |
|
| # # Event + Gtk |
| 80 |
|
| # @INC{'Event.pm', 'Gtk.pm'} = (1, 1); |
| 81 |
|
| # stderr_pause(); |
| 82 |
|
| # eval 'use POE::Kernel'; |
| 83 |
|
| # stderr_resume(); |
| 84 |
|
| # print 'not ' unless defined $@ and length $@; |
| 85 |
|
| # print "ok 3\n"; |
| 86 |
|
| # test_cleanup(); |
| 87 |
|
| # } |
| 88 |
|
| #} |
| 89 |
|
| # |
| 90 |
|
| ## Make these runtime so they occur after the above tests. |
| 91 |
|
| # |
| 92 |
|
| #use POE::Session; |
| 93 |
|
| #use POE::Kernel; |
| 94 |
|
| #use POE::Component::Server::TCP; |
| 95 |
|
| #use POE::Wheel::SocketFactory; |
| 96 |
|
| # |
| 97 |
|
| ## Test that errors occur when nonexistent modules are used. |
| 98 |
|
| #stderr_pause(); |
| 99 |
|
| #eval 'use POE qw(NonExistent);'; |
| 100 |
|
| #stderr_resume(); |
| 101 |
|
| #print "not " unless defined $@ and length $@; |
| 102 |
|
| #print "ok 4\n"; |
| 103 |
|
| # |
| 104 |
|
| ## Test that an error occurs when trying to instantiate POE directly. |
| 105 |
|
| #eval 'my $x = new POE;'; |
| 106 |
|
| #print "not " unless defined $@ and length $@; |
| 107 |
|
| #print "ok 5\n"; |
| 108 |
|
| # |
| 109 |
|
| #### Test state machine. |
| 110 |
|
| # |
| 111 |
|
| #sub test_start { |
| 112 |
|
| # my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; |
| 113 |
|
| # |
| 114 |
|
| # ### Aliases. |
| 115 |
|
| # |
| 116 |
|
| # # Test error handling for the Kernel's call() method. |
| 117 |
|
| # $! = 0; |
| 118 |
|
| # print "not " |
| 119 |
|
| # if defined $kernel->call( 1000 => 'nonexistent' ) or $! != ESRCH; |
| 120 |
|
| # print "ok 8\n"; |
| 121 |
|
| # |
| 122 |
|
| # # Test error handling for the Kernel's post() method. |
| 123 |
|
| # $! = 0; |
| 124 |
|
| # print "not " |
| 125 |
|
| # if defined $kernel->post( 1000 => 'nonexistent' ) or $! != ESRCH; |
| 126 |
|
| # print "ok 9\n"; |
| 127 |
|
| # |
| 128 |
|
| # # Failed alias addition. |
| 129 |
|
| # print "not " if $kernel->alias_set( 'kernel_alias' ) != EEXIST; |
| 130 |
|
| # print "ok 10\n"; |
| 131 |
|
| # |
| 132 |
|
| # # Failed alias removal. Not allowed to remove one from another |
| 133 |
|
| # # session. |
| 134 |
|
| # print "not " if $kernel->alias_remove( 'kernel_alias' ) != EPERM; |
| 135 |
|
| # print "ok 11\n"; |
| 136 |
|
| # |
| 137 |
|
| # # Failed alias removal. Not allowed to remove one that doesn't |
| 138 |
|
| # # exist. |
| 139 |
|
| # print "not " if $kernel->alias_remove( 'yatta yatta yatta' ) != ESRCH; |
| 140 |
|
| # print "ok 12\n"; |
| 141 |
|
| # |
| 142 |
|
| # ### IDs |
| 143 |
|
| # |
| 144 |
|
| # # Test failed ID->session and session->ID lookups. |
| 145 |
|
| # $! = 0; |
| 146 |
|
| # print "not " if defined $kernel->ID_id_to_session( 1000 ) or $! != ESRCH; |
| 147 |
|
| # print "ok 13\n"; |
| 148 |
|
| # |
| 149 |
|
| # print "not " if defined $kernel->ID_session_to_id( 1000 ) or $! != ESRCH; |
| 150 |
|
| # print "ok 14\n"; |
| 151 |
|
| # |
| 152 |
|
| # ### Signals. |
| 153 |
|
| # |
| 154 |
|
| # # Test failed signal() call. |
| 155 |
|
| # $! = 0; |
| 156 |
|
| # print "not " if defined $kernel->signal( 1000 => 'BOOGA' ) or $! != ESRCH; |
| 157 |
|
| # print "ok 15\n"; |
| 158 |
|
| # |
| 159 |
|
| # ### Extra references. |
| 160 |
|
| # $! = 0; |
| 161 |
|
| # print 'not ' if defined $kernel->refcount_increment( 'tag' ) or $! != ESRCH; |
| 162 |
|
| # print "ok 16\n"; |
| 163 |
|
| # |
| 164 |
|
| # $! = 0; |
| 165 |
|
| # print 'not ' if defined $kernel->refcount_decrement( 'tag' ) or $! != ESRCH; |
| 166 |
|
| # print "ok 17\n"; |
| 167 |
|
| #} |
| 168 |
|
| # |
| 169 |
|
| ## Did we get this far? |
| 170 |
|
| # |
| 171 |
|
| #print "ok 6\n"; |
| 172 |
|
| # |
| 173 |
|
| #print "not " if $POE::Kernel::poe_kernel->alias_set( 'kernel_alias' ); |
| 174 |
|
| #print "ok 7\n"; |
| 175 |
|
| # |
| 176 |
|
| #POE::Session->create |
| 177 |
|
| # ( inline_states => |
| 178 |
|
| # { _start => \&test_start, |
| 179 |
|
| # } |
| 180 |
|
| # ); |
| 181 |
|
| # |
| 182 |
|
| #print "not " if $POE::Kernel::poe_kernel->alias_remove( 'kernel_alias' ); |
| 183 |
|
| #print "ok 18\n"; |
| 184 |
|
| # |
| 185 |
|
| #print "not " |
| 186 |
|
| # unless $POE::Kernel::poe_kernel->state( woobly => sub { die } ) == ESRCH; |
| 187 |
|
| #print "ok 19\n"; |
| 188 |
|
| # |
| 189 |
|
| #### TCP Server problems. |
| 190 |
|
| # |
| 191 |
|
| #{ my $warnings = 0; |
| 192 |
|
| # local $SIG{__WARN__} = sub { $warnings++; }; |
| 193 |
|
| # |
| 194 |
|
| # POE::Component::Server::TCP->new |
| 195 |
|
| # ( Port => -1, |
| 196 |
|
| # Acceptor => sub { die }, |
| 197 |
|
| # Nonexistent => 'woobly', |
| 198 |
|
| # ); |
| 199 |
|
| # |
| 200 |
|
| # print "not " unless $warnings == 1; |
| 201 |
|
| # print "ok 20\n"; |
| 202 |
|
| #} |
| 203 |
|
| # |
| 204 |
|
| #### SocketFactory problems. |
| 205 |
|
| # |
| 206 |
|
| #{ my $warnings = 0; |
| 207 |
|
| # local $SIG{__WARN__} = sub { $warnings++; }; |
| 208 |
|
| # |
| 209 |
|
| # # Grar! No UNIX sockets on Windows. |
| 210 |
|
| # if ($^O eq 'MSWin32' and not $ENV{POE_DANTIC}) { |
| 211 |
|
| # print "ok 21 # skipped: $^O does not support listen on unbound sockets.\n"; |
| 212 |
|
| # print "ok 22 # skipped: $^O does not support UNIX sockets.\n"; |
| 213 |
|
| # } |
| 214 |
|
| # else { |
| 215 |
|
| # # Odd parameters. |
| 216 |
|
| # |
| 217 |
|
| # # Cygwin behaves differently. |
| 218 |
|
| # if ($^O eq "cygwin") { |
| 219 |
|
| # print |
| 220 |
|
| # "ok 21 # skipped: $^O does not support listen on unbound sockets.\n"; |
| 221 |
|
| # } |
| 222 |
|
| # else { |
| 223 |
|
| # POE::Wheel::SocketFactory->new |
| 224 |
|
| # ( SuccessEvent => [ ], |
| 225 |
|
| # FailureEvent => [ ], |
| 226 |
|
| # ); |
| 227 |
|
| # |
| 228 |
|
| # print "not " unless $warnings == 2; |
| 229 |
|
| # print "ok 21\n"; |
| 230 |
|
| # } |
| 231 |
|
| # |
| 232 |
|
| # # Any protocol on UNIX sockets. |
| 233 |
|
| # $warnings = 0; |
| 234 |
|
| # POE::Wheel::SocketFactory->new |
| 235 |
|
| # ( SocketDomain => AF_UNIX, |
| 236 |
|
| # SocketProtocol => "tcp", |
| 237 |
|
| # SuccessEvent => "okay", |
| 238 |
|
| # FailureEvent => "okay", |
| 239 |
|
| # ); |
| 240 |
|
| # |
| 241 |
|
| # print "not " unless $warnings == 1; |
| 242 |
|
| # print "ok 22\n"; |
| 243 |
|
| # } |
| 244 |
|
| # |
| 245 |
|
| # # Unsupported protocol for an address family. |
| 246 |
|
| # eval( 'POE::Wheel::SocketFactory->new ' . |
| 247 |
|
| # '( SocketDomain => AF_INET,' . |
| 248 |
|
| # ' SocketProtocol => "icmp",' . |
| 249 |
|
| # ' SuccessEvent => "okay",' . |
| 250 |
|
| # ' FailureEvent => "okay",' . |
| 251 |
|
| # ');' |
| 252 |
|
| # ); |
| 253 |
|
| # print 'not ' unless defined $@ and length $@; |
| 254 |
|
| # print "ok 23\n"; |
| 255 |
|
| #} |
| 256 |
|
| # |
| 257 |
|
| #### Main loop. |
| 258 |
|
| # |
| 259 |
|
| #stderr_pause(); |
| 260 |
|
| #$POE::Kernel::poe_kernel->run(); |
| 261 |
|
| #stderr_resume(); |
| 262 |
|
| # |
| 263 |
|
| #### Misuse of unusable modules. |
| 264 |
|
| # |
| 265 |
|
| #use POE::Wheel; |
| 266 |
|
| # |
| 267 |
|
| #eval 'POE::Wheel->new'; |
| 268 |
|
| #print 'not ' unless defined $@ and length $@; |
| 269 |
|
| #print "ok 24\n"; |
| 270 |
|
| # |
| 271 |
|
| #use POE::Component; |
| 272 |
|
| # |
| 273 |
|
| #eval 'POE::Component->new'; |
| 274 |
|
| #print 'not ' unless defined $@ and length $@; |
| 275 |
|
| #print "ok 25\n"; |
| 276 |
|
| # |
| 277 |
|
| #use POE::Driver; |
| 278 |
|
| # |
| 279 |
|
| #eval 'POE::Driver->new'; |
| 280 |
|
| #print 'not ' unless defined $@ and length $@; |
| 281 |
|
| #print "ok 26\n"; |
| 282 |
|
| # |
| 283 |
|
| #use POE::Filter; |
| 284 |
|
| # |
| 285 |
|
| #eval 'POE::Filter->new'; |
| 286 |
|
| #print 'not ' unless defined $@ and length $@; |
| 287 |
|
| #print "ok 27\n"; |
| 288 |
|
| # |
| 289 |
|
| #### Misuse of usable modules. |
| 290 |
|
| # |
| 291 |
|
| #use POE::Driver::SysRW; |
| 292 |
|
| # |
| 293 |
|
| #eval 'POE::Driver::SysRW->new( 1 )'; |
| 294 |
|
| #print 'not ' unless defined $@ and length $@; |
| 295 |
|
| #print "ok 28\n"; |
| 296 |
|
| # |
| 297 |
|
| #eval 'POE::Driver::SysRW->new( Booga => 1 )'; |
| 298 |
|
| #print 'not ' unless defined $@ and length $@; |
| 299 |
|
| #print "ok 29\n"; |
| 300 |
|
| # |
| 301 |
|
| #eval 'use POE::Filter::HTTPD;'; |
| 302 |
|
| #unless (defined $@ and length $@) { |
| 303 |
|
| # my $pfhttpd = POE::Filter::HTTPD->new(); |
| 304 |
|
| # |
| 305 |
|
| # eval '$pfhttpd->get_pending()'; |
| 306 |
|
| # print 'not ' unless defined $@ and length $@; |
| 307 |
|
| # print "ok 30\n"; |
| 308 |
|
| #} |
| 309 |
|
| #else { |
| 310 |
|
| # print "ok 30 # skipped: libwww-perl and URI are needed for this test.\n"; |
| 311 |
|
| #} |
| 312 |
|
| # |
| 313 |
|
| ## POE::Session constructor stuff. |
| 314 |
|
| # |
| 315 |
|
| #eval 'POE::Session->create( 1 )'; |
| 316 |
|
| #print 'not ' unless defined $@ and length $@; |
| 317 |
|
| #print "ok 31\n"; |
| 318 |
|
| # |
| 319 |
|
| #eval 'POE::Session->create( options => [] )'; |
| 320 |
|
| #print 'not ' unless defined $@ and length $@; |
| 321 |
|
| #print "ok 32\n"; |
| 322 |
|
| # |
| 323 |
|
| #eval 'POE::Session->create( inline_states => [] )'; |
| 324 |
|
| #print 'not ' unless defined $@ and length $@; |
| 325 |
|
| #print "ok 33\n"; |
| 326 |
|
| # |
| 327 |
|
| #eval 'POE::Session->create( inline_states => { _start => 1 } )'; |
| 328 |
|
| #print 'not ' unless defined $@ and length $@; |
| 329 |
|
| #print "ok 34\n"; |
| 330 |
|
| # |
| 331 |
|
| #eval 'POE::Session->create( package_states => {} )'; |
| 332 |
|
| #print 'not ' unless defined $@ and length $@; |
| 333 |
|
| #print "ok 35\n"; |
| 334 |
|
| # |
| 335 |
|
| #eval 'POE::Session->create( package_states => [ 1 ] )'; |
| 336 |
|
| #print 'not ' unless defined $@ and length $@; |
| 337 |
|
| #print "ok 36\n"; |
| 338 |
|
| # |
| 339 |
|
| #eval 'POE::Session->create( package_states => [ main => 1 ] )'; |
| 340 |
|
| #print 'not ' unless defined $@ and length $@; |
| 341 |
|
| #print "ok 37\n"; |
| 342 |
|
| # |
| 343 |
|
| #eval 'POE::Session->create( object_states => {} )'; |
| 344 |
|
| #print 'not ' unless defined $@ and length $@; |
| 345 |
|
| #print "ok 38\n"; |
| 346 |
|
| # |
| 347 |
|
| #eval 'POE::Session->create( object_states => [ 1 ] )'; |
| 348 |
|
| #print 'not ' unless defined $@ and length $@; |
| 349 |
|
| #print "ok 39\n"; |
| 350 |
|
| # |
| 351 |
|
| #eval 'POE::Session->create( package_states => [ main => 1 ] )'; |
| 352 |
|
| #print 'not ' unless defined $@ and length $@; |
| 353 |
|
| #print "ok 40\n"; |
| 354 |
|
| # |
| 355 |
|
| #eval 'POE::Session->new( 1 )'; ### DEPRECATED |
| 356 |
|
| #print 'not ' unless defined $@ and length $@; |
| 357 |
|
| #print "ok 41\n"; |
| 358 |
|
| # |
| 359 |
|
| #eval 'POE::Session->new( _start => 1 )'; |
| 360 |
|
| #print 'not ' unless defined $@ and length $@; |
| 361 |
|
| #print "ok 42\n"; |
| 362 |
|
| # |
| 363 |
|
| #eval 'POE::Session->new( sub {} => 1 )'; |
| 364 |
|
| #print 'not ' unless defined $@ and length $@; |
| 365 |
|
| #print "ok 43\n"; |
| 366 |
|
| # |
| 367 |
|
| #use POE::Wheel::FollowTail; |
| 368 |
|
| #use POE::Filter::Stream; |
| 369 |
|
| # |
| 370 |
|
| #eval 'POE::Wheel::FollowTail->new( )'; |
| 371 |
|
| #print 'not ' unless defined $@ and length $@; |
| 372 |
|
| #print "ok 44\n"; |
| 373 |
|
| # |
| 374 |
|
| #eval 'POE::Wheel::FollowTail->new( Handle => \*STDIN )'; |
| 375 |
|
| #print 'not ' unless defined $@ and length $@; |
| 376 |
|
| #print "ok 45\n"; |
| 377 |
|
| # |
| 378 |
|
| #eval( 'POE::Wheel::FollowTail->new( Handle => \*STDIN,' . |
| 379 |
|
| # ' Driver => POE::Driver::SysRW->new(),' . |
| 380 |
|
| # ')' |
| 381 |
|
| # ); |
| 382 |
|
| #print 'not ' unless defined $@ and length $@; |
| 383 |
|
| #print "ok 46\n"; |
| 384 |
|
| # |
| 385 |
|
| #eval( 'POE::Wheel::FollowTail->new( Handle => \*STDIN,' . |
| 386 |
|
| # ' Driver => POE::Driver::SysRW->new(),' . |
| 387 |
|
| # ' Filter => POE::Filter::Stream->new(),' . |
| 388 |
|
| # ')' |
| 389 |
|
| # ); |
| 390 |
|
| #print 'not ' unless defined $@ and length $@; |
| 391 |
|
| #print "ok 47\n"; |
| 392 |
|
| # |
| 393 |
|
| #if (($^O ne 'MSWin32' and $^O ne 'MacOS') or $ENV{POE_DANTIC}) { |
| 394 |
|
| # require POE::Wheel::Run; |
| 395 |
|
| # POE::Wheel::Run->import(); |
| 396 |
|
| # |
| 397 |
|
| # eval 'POE::Wheel::Run->new( 1 )'; |
| 398 |
|
| # print 'not ' unless defined $@ and length $@; |
| 399 |
|
| # print "ok 48\n"; |
| 400 |
|
| # |
| 401 |
|
| # eval 'POE::Wheel::Run->new( Program => 1 )'; |
| 402 |
|
| # print 'not ' unless defined $@ and length $@; |
| 403 |
|
| # print "ok 49\n"; |
| 404 |
|
| #} |
| 405 |
|
| #else { |
| 406 |
|
| # for (48..49) { |
| 407 |
|
| # print "ok $_ # skipped: $^O does not support POE::Wheel::Run.\n"; |
| 408 |
|
| # } |
| 409 |
|
| #} |
| 410 |
|
| |
| 411 |
|
| 1; |