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 { |
85ce96a1 |
8 | push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS'; |
9 | require Config; import Config; |
10 | if ($Config{'extensions'} !~ /\bXS\/APItest\b/) { |
11 | # Look, I'm using this fully-qualified variable more than once! |
12 | my $arch = $MacPerl::Architecture; |
13 | print "1..0 # Skip: XS::APItest was not built\n"; |
14 | exit 0; |
15 | } |
16 | $threads = $Config{'useithreads'}; |
17 | # must 'use threads' before 'use Test::More' |
18 | eval 'use threads' if $threads; |
19 | } |
20 | |
21 | use warnings; |
22 | use strict; |
23 | |
9568a123 |
24 | use Test::More tests => 16; |
85ce96a1 |
25 | |
26 | BEGIN { |
27 | use_ok('XS::APItest'); |
28 | }; |
29 | |
30 | is(my_cxt_getint(), 99, "initial int value"); |
9568a123 |
31 | is(my_cxt_getsv($_), "initial", "initial SV value$_") |
32 | foreach '', ' (context arg)'; |
85ce96a1 |
33 | |
34 | my_cxt_setint(1234); |
35 | is(my_cxt_getint(), 1234, "new int value"); |
36 | |
37 | my_cxt_setsv("abcd"); |
9568a123 |
38 | is(my_cxt_getsv($_), "abcd", "new SV value$_") |
39 | foreach '', ' (context arg)'; |
85ce96a1 |
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 | |
9568a123 |
46 | is(my_cxt_getsv($_), "initial_clone", "initial sv value (child)$_") |
47 | foreach '', ' (context arg)'; |
85ce96a1 |
48 | my_cxt_setsv("dcba"); |
9568a123 |
49 | is(my_cxt_getsv($_), "dcba", "new SV value (child)$_") |
50 | foreach '', ' (context arg)'; |
85ce96a1 |
51 | } |
52 | |
53 | SKIP: { |
9568a123 |
54 | skip "No threads", 6 unless $threads; |
878090d5 |
55 | threads->create(\&do_thread)->join; |
85ce96a1 |
56 | } |
57 | |
58 | is(my_cxt_getint(), 1234, "int value preserved after join"); |
9568a123 |
59 | is(my_cxt_getsv($_), "abcd", "SV value preserved after join$_") |
60 | foreach '', ' (context arg)'; |