| 1 |
BEGIN { # Magic Perl CORE pragma |
| 2 |
if ($ENV{PERL_CORE}) { |
| 3 |
chdir 't' if -d 't'; |
| 4 |
@INC = '../lib'; |
| 5 |
} |
| 6 |
} |
| 7 |
|
| 8 |
use strict; |
| 9 |
use warnings; |
| 10 |
use Test::More tests => 16; |
| 11 |
|
| 12 |
BEGIN { |
| 13 |
eval "use threads; 1" or eval "use forks; 1"; |
| 14 |
diag $@ if !ok( !$@, "threads or forks loaded ok" ); |
| 15 |
} |
| 16 |
BEGIN { use_ok('Thread::Queue::Any') } |
| 17 |
|
| 18 |
my $q = Thread::Queue::Any->new; |
| 19 |
isa_ok( $q, 'Thread::Queue::Any', 'check object type' ); |
| 20 |
can_ok( $q,qw( |
| 21 |
dequeue |
| 22 |
dequeue_dontwait |
| 23 |
dequeue_keep |
| 24 |
dequeue_nb |
| 25 |
enqueue |
| 26 |
new |
| 27 |
pending |
| 28 |
) ); |
| 29 |
|
| 30 |
$q->enqueue( qw(a b c) ); |
| 31 |
$q->enqueue( [qw(a b c)] ); |
| 32 |
$q->enqueue( {a => 1, b => 2, c => 3} ); |
| 33 |
|
| 34 |
is( $q->pending, 3, 'check number pending'); |
| 35 |
|
| 36 |
my @l = $q->dequeue; |
| 37 |
is( @l, 3, 'check # elements simple list' ); |
| 38 |
ok( ($l[0] eq 'a' and $l[1] eq 'b' and $l[2] eq 'c'), 'check simple list' ); |
| 39 |
|
| 40 |
my @lr = $q->dequeue_nb; |
| 41 |
cmp_ok( @lr, '==', 1, 'check # elements list ref' ); |
| 42 |
is( ref($lr[0]), 'ARRAY', 'check type of list ref' ); |
| 43 |
ok( |
| 44 |
($lr[0]->[0] eq 'a' and $lr[0]->[1] eq 'b' and $lr[0]->[2] eq 'c'), |
| 45 |
'check list ref' |
| 46 |
); |
| 47 |
|
| 48 |
my @hr = $q->dequeue_keep; |
| 49 |
cmp_ok( @hr, '==', 1, 'check # elements hash ref, #1' ); |
| 50 |
is( ref($hr[0]), 'HASH', 'check type of hash ref, #1' ); |
| 51 |
|
| 52 |
@hr = $q->dequeue; |
| 53 |
cmp_ok( @hr, '==', 1, 'check # elements hash ref, #2' ); |
| 54 |
is( ref($hr[0]), 'HASH', 'check type of hash ref, #2' ); |
| 55 |
ok( |
| 56 |
($hr[0]->{a} == 1 and $hr[0]->{b} == 2 and $hr[0]->{c} == 3), |
| 57 |
'check hash ref' |
| 58 |
); |
| 59 |
|
| 60 |
my @e = $q->dequeue_dontwait; |
| 61 |
cmp_ok( @e, '==', 0, 'check # elements non blocking' ); |