3 # Test for memory leaks.
5 # XXX TODO: This test file doesn't actually seem to work! If you remove
6 # the sv_2mortal() in the XS file, it still happily passes all tests...
14 chdir 't' if -d 't' && !$ENV{PERL_CORE};
15 unshift @INC, ('../lib', '../blib/arch'); # for running manually
19 use Math::BigInt::FastCalc;
21 #############################################################################
22 package Math::BigInt::FastCalc::LeakCheck;
23 use base qw(Math::BigInt::FastCalc);
26 sub DESTROY { $destroyed++; }
28 #############################################################################
31 for my $method (qw(_zero _one _two _ten))
35 my $num = Math::BigInt::FastCalc::LeakCheck->$method();
36 bless $num, "Math::BigInt::FastCalc::LeakCheck";
38 is ($destroyed, 1, "$method does not leak memory");
41 my $num = Math::BigInt::FastCalc->_zero();
42 for my $method (qw(_is_zero _is_one _is_two _is_ten _num))
46 my $rc = Math::BigInt::FastCalc->$method($num);
47 bless \$rc, "Math::BigInt::FastCalc::LeakCheck";
49 is ($destroyed, 1, "$method does not leak memory");
52 my $num_10 = Math::BigInt::FastCalc->_ten();
53 my $num_2 = Math::BigInt::FastCalc->_two();
55 my $num_long = Math::BigInt::FastCalc->_new("1234567890");
56 my $num_long_2 = Math::BigInt::FastCalc->_new("12345678900987654321");
58 is (Math::BigInt::FastCalc->_str($num_long), "1234567890");
59 is (Math::BigInt::FastCalc->_str($num_long_2), "12345678900987654321");
61 # to hit all possible code branches
62 _test_acmp($num, $num);
63 _test_acmp($num_10, $num_10);
64 _test_acmp($num, $num_10);
65 _test_acmp($num_10, $num);
66 _test_acmp($num, $num_2);
67 _test_acmp($num_2, $num);
68 _test_acmp($num_long, $num);
69 _test_acmp($num, $num_long);
70 _test_acmp($num_long, $num_long);
71 _test_acmp($num_long, $num_long_2);
72 _test_acmp($num_long_2, $num_long);
80 my $rc = Math::BigInt::FastCalc->_acmp($n1,$n2);
81 bless \$rc, "Math::BigInt::FastCalc::LeakCheck";
83 my $n_1 = Math::BigInt::FastCalc->_str($n1);
84 my $n_2 = Math::BigInt::FastCalc->_str($n2);
85 is ($destroyed, 1, "_acmp($n_1,$n_2) does not leak memory");