CORBA-omniORB

 view release on metacpan or  search on metacpan

omnithreads/t/basic.t  view on Meta::CPAN

use strict;
use warnings;

BEGIN {
    if ($ENV{'PERL_CORE'}){
        chdir 't';
        unshift @INC, '../lib';
    }
    use Config;
    if (! $Config{'useithreads'}) {
        print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
        exit(0);
    }
}

use ExtUtils::testlib;

sub ok {
    my ($id, $ok, $name) = @_;

    # You have to do it this way or VMS will get confused.
    if ($ok) {
        print("ok $id - $name\n");
    } else {
        print("not ok $id - $name\n");
        printf("# Failed test at line %d\n", (caller)[2]);
    }

    return ($ok);
}

BEGIN {
    $| = 1;
    print("1..30\n");   ### Number of tests that will be run ###
};

use omnithreads;

if ($omnithreads::VERSION && ! exists($ENV{'PERL_CORE'})) {
    print(STDERR "# Testing omnithreads $omnithreads::VERSION\n");
}

ok(1, 1, 'Loaded');

### Start of Testing ###

ok(2, 1 == $omnithreads::threads, "Check that omnithreads::threads is true");

sub test1 {
    ok(3,'bar' eq $_[0], "Test that argument passing works");
}
omnithreads->create('test1', 'bar')->join();

sub test2 {
    ok(4,'bar' eq $_[0]->[0]->{'foo'}, "Test that passing arguments as references work");
}
omnithreads->create(\&test2, [{'foo' => 'bar'}])->join();

sub test3 {
    ok(5, shift() == 1, "Test a normal sub");
}
omnithreads->create(\&test3, 1)->join();


# sub test4 {
#     ok(6, 1, "Detach test");
# }
# {
#     my $thread1 = omnithreads->create('test4');
#     $thread1->detach();
#     while ($thread1->is_running()) {
#         omnithreads->yield();
#         sleep 1;
#     }
# }
# ok(7, 1, "Detach test");
ok(6, 1, "Dummy test");
omnithreads->create(sub { ok(7, 1, "Dummy test") })->join;


sub test5 {
    omnithreads->create('test6')->join();
    ok(9, 1, "Nested thread test");
}

sub test6 {



( run in 2.433 seconds using v1.01-cache-2.11-cpan-364913b4093 )