From: Artur Bergman Date: Fri, 26 Oct 2001 08:30:11 +0000 (+0000) Subject: Add tests for references in hashes. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0dc5f2bb966f13a2958959b7f7d94400bd67c466;p=p5sagit%2Fp5-mst-13.2.git Add tests for references in hashes. p4raw-id: //depot/perl@12670 --- diff --git a/MANIFEST b/MANIFEST index e0b0ab8..2e3e9af 100644 --- a/MANIFEST +++ b/MANIFEST @@ -588,6 +588,7 @@ ext/threads/shared/t/sv_simple.t thread shared variables ext/threads/shared/t/sv_refs.t thread shared variables ext/threads/shared/t/av_simple.t Tests for basic shared array functionality. ext/threads/shared/t/hv_simple.t Tests for basic shared hash functionality. +ext/threads/shared/t/hv_refs.t Test shared hashes containing references ext/Time/HiRes/Changes Time::HiRes extension ext/Time/HiRes/hints/dynixptx.pl Hint for Time::HiRes for named architecture ext/Time/HiRes/hints/sco.pl Hints for Time::HiRes for named architecture diff --git a/ext/threads/shared/t/hv_refs.t b/ext/threads/shared/t/hv_refs.t new file mode 100644 index 0000000..53029bf --- /dev/null +++ b/ext/threads/shared/t/hv_refs.t @@ -0,0 +1,44 @@ +BEGIN { +# chdir 't' if -d 't'; +# push @INC ,'../lib'; + require Config; import Config; + unless ($Config{'useithreads'}) { + print "1..0 # Skip: no useithreads\n"; + exit 0; + } +} + + +sub ok { + my ($id, $ok, $name) = @_; + + # You have to do it this way or VMS will get confused. + print $ok ? "ok $id - $name\n" : "not ok $id - $name\n"; + + printf "# Failed test at line %d\n", (caller)[2] unless $ok; + + return $ok; +} + + + +use ExtUtils::testlib; +use strict; +BEGIN { print "1..7\n" }; +use threads; +use threads::shared; +ok(1,1,"loaded"); +my $foo; +share($foo); +my %foo; +share(%foo); +$foo{"foo"} = \$foo; +ok(2, ${$foo{foo}} == undef, "Check deref"); +$foo = "test"; +ok(3, ${$foo{foo}} eq "test", "Check deref after assign"); +threads->create(sub{${$foo{foo}} = "test2";})->join(); +ok(4, $foo eq "test2", "Check after assign in another thread"); +ok(5, threads::shared::_thrcnt($foo) == 2, "Check refcount"); +my $bar = delete($foo{foo}); +ok(6, $$bar eq "test2", "check delete"); +ok(7, threads::shared::_thrcnt($foo) == 1, "Check refcount after delete");