1 ################################################################################
3 # !!!!! Do NOT edit this file directly! !!!!!
5 # Edit mktests.PL and/or parts/inc/magic instead.
7 # This file was automatically generated from the definition files in the
8 # parts/inc/ subdirectory by mktests.PL. To learn more about how all this
9 # works, please read the F<HACKERS> file that came with this distribution.
11 ################################################################################
14 if ($ENV{'PERL_CORE'}) {
16 @INC = ('../lib', '../ext/Devel-PPPort/t') if -d '../lib' && -d '../ext';
17 require Config; import Config;
19 if (" $Config{'extensions'} " !~ m[ Devel/PPPort ]) {
20 print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
30 require 'testutil.pl' if $@;
43 package Devel::PPPort;
46 @ISA = qw(DynaLoader);
47 bootstrap Devel::PPPort;
52 ok(my $obj1 = Devel::PPPort->new_with_mg());
53 ok(Devel::PPPort::as_string($obj1), 'hello');
56 my $obj = bless {}, 'Fake::Class';
57 ok(Devel::PPPort::as_string($obj), "Sorry, your princess is in another castle.");
59 # Find with other magic (not the magic we are looking for)
60 ok($obj = Devel::PPPort->new_with_other_mg());
61 ok(Devel::PPPort::as_string($obj), "Sorry, your princess is in another castle.");
63 # Okay, attempt to remove magic that isn't there
64 Devel::PPPort::remove_other_magic($obj1);
65 ok(Devel::PPPort::as_string($obj1), 'hello');
67 # Remove magic that IS there
68 Devel::PPPort::remove_null_magic($obj1);
69 ok(Devel::PPPort::as_string($obj1), "Sorry, your princess is in another castle.");
71 # Removing when no magic present
72 Devel::PPPort::remove_null_magic($obj1);
73 ok(Devel::PPPort::as_string($obj1), "Sorry, your princess is in another castle.");
77 tie %h, 'Tie::StdHash';
81 &Devel::PPPort::sv_catpv_mg($h{foo}, 'bar');
82 ok($h{foo}, 'foobar');
84 &Devel::PPPort::sv_catpvn_mg($h{bar}, 'baz');
87 &Devel::PPPort::sv_catsv_mg($h{foo}, '42');
88 ok($h{foo}, 'foobar42');
90 &Devel::PPPort::sv_setiv_mg($h{bar}, 42);
93 &Devel::PPPort::sv_setnv_mg($h{PI}, 3.14159);
94 ok(abs($h{PI} - 3.14159) < 0.01);
96 &Devel::PPPort::sv_setpv_mg($h{mhx}, 'mhx');
99 &Devel::PPPort::sv_setpvn_mg($h{mhx}, 'Marcus');
100 ok($h{mhx}, 'Marcus');
102 &Devel::PPPort::sv_setsv_mg($h{sv}, 'SV');
105 &Devel::PPPort::sv_setuv_mg($h{sv}, 4711);
108 &Devel::PPPort::sv_usepvn_mg($h{sv}, 'Perl');
111 # v1 is treated as a bareword in older perls...
112 my $ver = do { local $SIG{'__WARN__'} = sub {}; eval qq[v1.2.0] };
113 ok("$]" < 5.009 || $@ eq '');
114 ok("$]" < 5.009 || Devel::PPPort::SvVSTRING_mg($ver));
115 ok(!Devel::PPPort::SvVSTRING_mg(4711));
118 ok(Devel::PPPort::sv_magic_portable($foo));
121 if ( "$]" < '5.007003' ) {
123 skip 'skip: no SV_NOSTEAL support', 0;
126 tie my $scalar, 'TieScalarCounter', 10;
129 ok tied($scalar)->{fetch}, 1;
130 ok tied($scalar)->{store}, 0;
131 ok Devel::PPPort::magic_SvIV_nomg($scalar), 10;
132 ok tied($scalar)->{fetch}, 1;
133 ok tied($scalar)->{store}, 0;
134 ok Devel::PPPort::magic_SvUV_nomg($scalar), 10;
135 ok tied($scalar)->{fetch}, 1;
136 ok tied($scalar)->{store}, 0;
137 ok Devel::PPPort::magic_SvNV_nomg($scalar), 10;
138 ok tied($scalar)->{fetch}, 1;
139 ok tied($scalar)->{store}, 0;
140 ok Devel::PPPort::magic_SvPV_nomg_nolen($scalar), 10;
141 ok tied($scalar)->{fetch}, 1;
142 ok tied($scalar)->{store}, 0;
143 ok Devel::PPPort::magic_SvTRUE_nomg($scalar);
144 ok tied($scalar)->{fetch}, 1;
145 ok tied($scalar)->{store}, 0;
147 my $object = OverloadedObject->new('string', 5.5, 0);
149 ok Devel::PPPort::magic_SvIV_nomg($object), 5;
150 ok Devel::PPPort::magic_SvUV_nomg($object), 5;
151 ok Devel::PPPort::magic_SvNV_nomg($object), 5.5;
152 ok Devel::PPPort::magic_SvPV_nomg_nolen($object), 'string';
153 ok !Devel::PPPort::magic_SvTRUE_nomg($object);
156 package TieScalarCounter;
159 my ($class, $value) = @_;
160 return bless { fetch => 0, store => 0, value => $value }, $class;
166 return $self->{value};
170 my ($self, $value) = @_;
172 $self->{value} = $value;
175 package OverloadedObject;
178 my ($class, $str, $num, $bool) = @_;
179 return bless { str => $str, num => $num, bool => $bool }, $class;
183 '""' => sub { $_[0]->{str} },
184 '0+' => sub { $_[0]->{num} },
185 'bool' => sub { $_[0]->{bool} },