Commit | Line | Data |
85ce96a1 |
1 | #!perl -w |
2 | |
3 | # test per-interpeter static data API (MY_CXT) |
4 | # DAPM Dec 2005 |
5 | |
6 | my $threads; |
7 | BEGIN { |
8 | chdir 't' if -d 't'; |
9 | @INC = '../lib'; |
10 | push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS'; |
11 | require Config; import Config; |
12 | if ($Config{'extensions'} !~ /\bXS\/APItest\b/) { |
13 | # Look, I'm using this fully-qualified variable more than once! |
14 | my $arch = $MacPerl::Architecture; |
15 | print "1..0 # Skip: XS::APItest was not built\n"; |
16 | exit 0; |
17 | } |
18 | $threads = $Config{'useithreads'}; |
19 | # must 'use threads' before 'use Test::More' |
20 | eval 'use threads' if $threads; |
21 | } |
22 | |
23 | use warnings; |
24 | use strict; |
25 | |
26 | use Test::More tests => 11; |
27 | |
28 | BEGIN { |
29 | use_ok('XS::APItest'); |
30 | }; |
31 | |
32 | is(my_cxt_getint(), 99, "initial int value"); |
33 | is(my_cxt_getsv(), "initial", "initial SV value"); |
34 | |
35 | my_cxt_setint(1234); |
36 | is(my_cxt_getint(), 1234, "new int value"); |
37 | |
38 | my_cxt_setsv("abcd"); |
39 | is(my_cxt_getsv(), "abcd", "new SV value"); |
40 | |
41 | sub do_thread { |
42 | is(my_cxt_getint(), 1234, "initial int value (child)"); |
43 | my_cxt_setint(4321); |
44 | is(my_cxt_getint(), 4321, "new int value (child)"); |
45 | |
46 | is(my_cxt_getsv(), "initial_clone", "initial sv value (child)"); |
47 | my_cxt_setsv("dcba"); |
48 | is(my_cxt_getsv(), "dcba", "new SV value (child)"); |
49 | } |
50 | |
51 | SKIP: { |
52 | skip "No threads", 4 unless $threads; |
878090d5 |
53 | threads->create(\&do_thread)->join; |
85ce96a1 |
54 | } |
55 | |
56 | is(my_cxt_getint(), 1234, "int value preserved after join"); |
57 | is(my_cxt_getsv(), "abcd", "SV value preserved after join"); |