bump version on modules changed since 5.13.0
[p5sagit/p5-mst-13.2.git] / ext / XS-APItest / t / my_cxt.t
1 #!perl -w
2
3 # test per-interpeter static data API (MY_CXT)
4 # DAPM Dec 2005
5
6 my $threads;
7 BEGIN {
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
24 use Test::More tests => 16;
25
26 BEGIN {
27     use_ok('XS::APItest');
28 };
29
30 is(my_cxt_getint(), 99, "initial int value");
31 is(my_cxt_getsv($_),  "initial", "initial SV value$_")
32     foreach '', ' (context arg)';
33
34 my_cxt_setint(1234);
35 is(my_cxt_getint(), 1234, "new int value");
36
37 my_cxt_setsv("abcd");
38 is(my_cxt_getsv($_),  "abcd", "new SV value$_")
39     foreach '', ' (context arg)';
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             foreach '', ' (context arg)';
48     my_cxt_setsv("dcba");
49     is(my_cxt_getsv($_),  "dcba", "new SV value (child)$_")
50             foreach '', ' (context arg)';
51 }
52
53 SKIP: {
54     skip "No threads", 6 unless $threads;
55     threads->create(\&do_thread)->join;
56 }
57
58 is(my_cxt_getint(), 1234,  "int value preserved after join");
59 is(my_cxt_getsv($_),  "abcd", "SV value preserved after join$_")
60         foreach '', ' (context arg)';