1#!perl 2 3use strict; 4use warnings; 5 6use Test::More tests => 7; 7 8use_ok('XS::APItest'); 9 10# test sv_rvweaken() and sv_get_backrefs() 11# 12# weaken() maps to sv_rvweaken() and is the same as the one 13# from Scalar::Utils - we recreate it in XS::APItest so 14# we can test it even if we build without Scalar::Utils 15# 16# has_backrefs() maps to sv_get_backrefs(), which would not 17# normally be useful to Perl code. (Er, maybe :-) 18 19# has_backrefs is really an internal routine 20# which would not normally have to worry about refs 21# and things like that, but to use it from perl we cant 22# have an AV/HV without having an RV wrapping it, so we 23# mandate the ref always. 24 25my $foo= "foo"; 26my $bar= "bar"; 27 28my $scalar_ref= \$foo; 29my $array_ref= [ qw(this is an array) ]; 30my $hash_ref= { this => is => a => 'hash' }; 31 32my $nrml_scalar_ref= \$bar; 33my $nrml_array_ref= [ qw( this is an array ) ]; 34my $nrml_hash_ref= { this => is => a => 'hash' }; 35 36# we could probably do other tests here, such as 37# verify the refcount of the referents, but maybe 38# another day. 39apitest_weaken(my $weak_scalar_ref= $scalar_ref); 40apitest_weaken(my $weak_array_ref= $array_ref); 41apitest_weaken(my $weak_hash_ref= $hash_ref); 42 43ok(has_backrefs($scalar_ref), "scalar with backrefs"); 44ok(has_backrefs($array_ref), "array with backrefs"); 45ok(has_backrefs($hash_ref), "hash with backrefs"); 46 47ok(!has_backrefs($nrml_scalar_ref), "scalar without backrefs"); 48ok(!has_backrefs($nrml_array_ref), "array without backrefs"); 49ok(!has_backrefs($nrml_hash_ref), "hash without backrefs"); 50 511; 52 53