File: 001basic.t

package info (click to toggle)
libthread-serialize-perl 1.00-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 108 kB
  • sloc: perl: 46; makefile: 4
file content (70 lines) | stat: -rw-r--r-- 2,008 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
BEGIN {                                # Magic Perl CORE pragma
    if ($ENV{PERL_CORE}) {
        chdir 't' if -d 't';
        @INC = '../lib';
    }
}

use strict;
use warnings;

my %Loaded;
BEGIN {
     $Loaded{threads}= eval "use threads; 1";
     $Loaded{forks}=   eval "use forks; 1" if !$Loaded{threads};
}

use Thread::Serialize; # can't fake bare import call yet with Test::More
use Test::More;

diag "threads loaded" if $Loaded{threads};
diag "forks loaded"   if $Loaded{forks};
ok( $Loaded{threads} || $Loaded{forks}, "thread-like module loaded" );

my $class= 'Thread::Serialize';
can_ok( $class, qw( freeze thaw ) );
ok( !defined( $Thread::Serialize::no_external_perl ),
 "Check flag being unset" );

test();

delete $INC{'Thread/Serialize.pm'};
$Thread::Serialize::no_external_perl = 1;
{
    local $SIG{__WARN__}= sub {};  # don't want to see warnings ever
    require Thread::Serialize;
}
is( $Thread::Serialize::no_external_perl,'Signature obtained locally',
 "Check flag being set and changed" );

test();

done_testing( 3 + 6 + 1 + 6 );

#-------------------------------------------------------------------------------
# Good for 6 tests

sub test {
    my $scalar= '1234';
    my $frozen= freeze($scalar);
    is( thaw($frozen), $scalar,                       'check contents' );

    my @array= qw(a b c);
    $frozen= freeze(@array);
    is( join( '', thaw($frozen) ), join( '',@array ), 'check contents' );

    $frozen= freeze( \@array );
    is( join( '', @{ thaw($frozen) } ), join( '', @array ), 'check contents' );

    $frozen= freeze();
    is( join( '', thaw($frozen) ), '',                'check contents' );

    $frozen= freeze(undef);
    ok( !defined( thaw($frozen) ),                    'check contents' );

    my %hash= ( a => 'A', b => 'B', c => 'C' );
    $frozen= freeze( \%hash );
    is( join( '', sort %{ thaw($frozen) } ), join( '', sort %hash ),
      'check contents' );
} #test
#-------------------------------------------------------------------------------