1use strict; 2use warnings; 3 4BEGIN { 5 use Config; 6 if (! $Config{'useithreads'}) { 7 print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); 8 exit(0); 9 } 10} 11 12use ExtUtils::testlib; 13 14my $TEST = 1; 15 16sub is { 17 my ($got, $exp, $name) = @_; 18 19 my $ok = ($got eq $exp); 20 21 # You have to do it this way or VMS will get confused. 22 if ($ok) { 23 print("ok $TEST - $name\n"); 24 } else { 25 print("not ok $TEST - $name\n"); 26 printf("# Failed test at line %d\n", (caller)[2]); 27 print("# Got: $got\n"); 28 print("# Expected: $exp\n"); 29 } 30 31 $TEST++; 32 33 return ($ok); 34} 35 36BEGIN { 37 $| = 1; 38 print("1..12\n"); ### Number of tests that will be run ### 39}; 40 41use threads; 42use threads::shared; 43 44### Start of Testing ### 45 46binmode STDOUT, ":utf8"; 47 48my $plain = 'foo'; 49my $utf8 = "\x{123}\x{84}\x{20F}\x{2C1}"; 50my $code = \&is; 51 52my %a :shared; 53$a{$plain} = $plain; 54$a{$utf8} = $utf8; 55$a{$code} = 'code'; 56 57is(exists($a{$plain}), 1, 'Found plain key in shared hash'); 58is(exists($a{$utf8}), 1, 'Found UTF-8 key in shared hash'); 59is(exists($a{$code}), 1, 'Found code ref key in shared hash'); 60 61while (my ($key, $value) = each (%a)) { 62 if ($key eq $plain) { 63 is($key, $plain, 'Plain key in shared hash'); 64 } elsif ($key eq $utf8) { 65 is($key, $utf8, 'UTF-8 key in shared hash'); 66 } elsif ($key eq "$code") { 67 is($key, "$code", 'Code ref key in shared hash'); 68 } else { 69 is($key, "???", 'Bad key'); 70 } 71} 72 73my $a = &share({}); 74$$a{$plain} = $plain; 75$$a{$utf8} = $utf8; 76$$a{$code} = 'code'; 77 78is(exists($$a{$plain}), 1, 'Found plain key in shared hash ref'); 79is(exists($$a{$utf8}), 1, 'Found UTF-8 key in shared hash ref'); 80is(exists($$a{$code}), 1, 'Found code ref key in shared hash ref'); 81 82while (my ($key, $value) = each (%$a)) { 83 if ($key eq $plain) { 84 is($key, $plain, 'Plain key in shared hash ref'); 85 } elsif ($key eq $utf8) { 86 is($key, $utf8, 'UTF-8 key in shared hash ref'); 87 } elsif ($key eq "$code") { 88 is($key, "$code", 'Code ref key in shared hash ref'); 89 } else { 90 is($key, "???", 'Bad key'); 91 } 92} 93 94exit(0); 95 96# EOF 97