summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteffen Mueller <smueller@cpan.org>2012-01-16 18:08:37 +0100
committerSteffen Mueller <smueller@cpan.org>2012-01-21 14:36:55 +0100
commita879031f80de94f6edee43d827fa67fd889ab5f4 (patch)
tree2abeacd3b46a4f852b4c7287b3429e418885ef73
parent5707bc763856e64d1d4dd093fb1935b66557a943 (diff)
downloadperl-a879031f80de94f6edee43d827fa67fd889ab5f4.tar.gz
Cleanup: Condense tests and add a few
-rw-r--r--ext/XS-Typemap/t/Typemap.t114
1 files changed, 34 insertions, 80 deletions
diff --git a/ext/XS-Typemap/t/Typemap.t b/ext/XS-Typemap/t/Typemap.t
index c8ab9f9655..f40b9075cf 100644
--- a/ext/XS-Typemap/t/Typemap.t
+++ b/ext/XS-Typemap/t/Typemap.t
@@ -6,7 +6,7 @@ BEGIN {
}
}
-use Test::More tests => 92;
+use Test::More tests => 84;
use strict;
use warnings;
@@ -28,104 +28,90 @@ BEGIN {
}
# T_SV - standard perl scalar value
-print "# T_SV\n";
-
+note("T_SV");
my $sv = "Testing T_SV";
is( T_SV($sv), $sv);
# T_SVREF - reference to Scalar
-print "# T_SVREF\n";
-
+note("T_SVREF");
$sv .= "REF";
my $svref = \$sv;
is( T_SVREF($svref), $svref );
+is( ${ T_SVREF($svref) }, $$svref );
# Now test that a non reference is rejected
# the typemaps croak
eval { T_SVREF( "fail - not ref" ) };
ok( $@ );
+note("T_SVREF_REFCOUNT_FIXED");
is( T_SVREF_REFCOUNT_FIXED($svref), $svref );
+is( ${ T_SVREF_REFCOUNT_FIXED($svref) }, $$svref );
eval { T_SVREF_REFCOUNT_FIXED( "fail - not ref" ) };
ok( $@ );
# T_AVREF - reference to a perl Array
-print "# T_AVREF\n";
-
+note("T_AVREF");
my @array;
is( T_AVREF(\@array), \@array);
-
# Now test that a non array ref is rejected
eval { T_AVREF( \$sv ) };
ok( $@ );
# T_AVREF_REFCOUNT_FIXED - reference to a perl Array, refcount fixed
-print "# T_AVREF_REFCOUNT_FIXED\n";
-
+note("T_AVREF_REFCOUNT_FIXED");
is( T_AVREF_REFCOUNT_FIXED(\@array), \@array);
-
# Now test that a non array ref is rejected
eval { T_AVREF_REFCOUNT_FIXED( \$sv ) };
ok( $@ );
# T_HVREF - reference to a perl Hash
-print "# T_HVREF\n";
-
+note("T_HVREF");
my %hash;
is( T_HVREF(\%hash), \%hash);
-
# Now test that a non hash ref is rejected
eval { T_HVREF( \@array ) };
ok( $@ );
# T_HVREF_REFCOUNT_FIXED - reference to a perl Hash, refcount fixed
-print "# T_HVREF_REFCOUNT_FIXED\n";
-
+note("T_HVREF_REFCOUNT_FIXED");
is( T_HVREF_REFCOUNT_FIXED(\%hash), \%hash);
-
# Now test that a non hash ref is rejected
eval { T_HVREF_REFCOUNT_FIXED( \@array ) };
ok( $@ );
-
# T_CVREF - reference to perl subroutine
-print "# T_CVREF\n";
+note("T_CVREF");
my $sub = sub { 1 };
is( T_CVREF($sub), $sub );
-
# Now test that a non code ref is rejected
eval { T_CVREF( \@array ) };
ok( $@ );
is( T_CVREF_REFCOUNT_FIXED($sub), $sub );
-
# Now test that a non code ref is rejected
eval { T_CVREF_REFCOUNT_FIXED( \@array ) };
ok( $@ );
# T_SYSRET - system return values
-print "# T_SYSRET\n";
-
+note("T_SYSRET");
# first check success
ok( T_SYSRET_pass );
-
# ... now failure
is( T_SYSRET_fail, undef);
# T_UV - unsigned integer
-print "# T_UV\n";
-
+note("T_UV");
is( T_UV(5), 5 ); # pass
isnt( T_UV(-4), -4); # fail
# T_IV - signed integer
-print "# T_IV\n";
-
+note("T_IV");
is( T_IV(5), 5);
is( T_IV(-4), -4);
is( T_IV(4.1), int(4.1));
@@ -136,12 +122,10 @@ isnt( T_IV(4.5), 4.5); # failure
# Skip T_INT
# T_ENUM - enum list
-print "# T_ENUM\n";
-
-ok( T_ENUM() ); # just hope for a true value
+ok( T_ENUM(), 'T_ENUM' ); # just hope for a true value
# T_BOOL - boolean
-print "# T_BOOL\n";
+note("T_BOOL");
ok( T_BOOL(52) );
ok( ! T_BOOL(0) );
@@ -153,9 +137,7 @@ ok( ! T_BOOL(undef) );
# Skip T_SHORT
# T_U_SHORT aka U16
-
-print "# T_U_SHORT\n";
-
+note("T_U_SHORT");
is( T_U_SHORT(32000), 32000);
if ($Config{shortsize} == 2) {
isnt( T_U_SHORT(65536), 65536); # probably dont want to test edge cases
@@ -164,62 +146,46 @@ if ($Config{shortsize} == 2) {
}
# T_U_LONG aka U32
-
-print "# T_U_LONG\n";
-
+note("T_U_LONG");
is( T_U_LONG(65536), 65536);
isnt( T_U_LONG(-1), -1);
# T_CHAR
-
-print "# T_CHAR\n";
-
+note("T_CHAR");
is( T_CHAR("a"), "a");
is( T_CHAR("-"), "-");
is( T_CHAR(chr(128)),chr(128));
isnt( T_CHAR(chr(256)), chr(256));
# T_U_CHAR
-
-print "# T_U_CHAR\n";
-
+note("T_U_CHAR");
is( T_U_CHAR(127), 127);
is( T_U_CHAR(128), 128);
isnt( T_U_CHAR(-1), -1);
isnt( T_U_CHAR(300), 300);
# T_FLOAT
-print "# T_FLOAT\n";
-
# limited precision
-is( sprintf("%6.3f",T_FLOAT(52.345)), sprintf("%6.3f",52.345));
+is( sprintf("%6.3f",T_FLOAT(52.345)), sprintf("%6.3f",52.345), "T_FLOAT");
# T_NV
-print "# T_NV\n";
-
-is( T_NV(52.345), 52.345);
+is( T_NV(52.345), 52.345, "T_NV" );
# T_DOUBLE
-print "# T_DOUBLE\n";
-
-is( sprintf("%6.3f",T_DOUBLE(52.345)), sprintf("%6.3f",52.345));
+is( sprintf("%6.3f",T_DOUBLE(52.345)), sprintf("%6.3f",52.345), "T_DOUBLE" );
# T_PV
-print "# T_PV\n";
-
+note("T_PV");
is( T_PV("a string"), "a string");
is( T_PV(52), 52);
# T_PTR
-print "# T_PTR\n";
-
my $t = 5;
my $ptr = T_PTR_OUT($t);
-is( T_PTR_IN( $ptr ), $t );
+is( T_PTR_IN( $ptr ), $t, "T_PTR" );
# T_PTRREF
-print "# T_PTRREF\n";
-
+note("T_PTRREF");
$t = -52;
$ptr = T_PTRREF_OUT( $t );
is( ref($ptr), "SCALAR");
@@ -230,8 +196,7 @@ eval { T_PTRREF_IN( $t ); };
ok( $@ );
# T_PTROBJ
-print "# T_PTROBJ\n";
-
+note("T_PTROBJ");
$t = 256;
$ptr = T_PTROBJ_OUT( $t );
is( ref($ptr), "intObjPtr");
@@ -249,8 +214,7 @@ is( $ptr->T_PTROBJ_IN, $t );
# Skip T_REF_IV_REF
# T_REF_IV_PTR
-print "# T_REF_IV_PTR\n";
-
+note("T_REF_IV_PTR");
$t = -365;
$ptr = T_REF_IV_PTR_OUT( $t );
is( ref($ptr), "intRefIvPtr");
@@ -268,15 +232,13 @@ ok( $@ );
# Skip T_REFOBJ
# T_OPAQUEPTR
-print "# T_OPAQUEPTR\n";
-
+note("T_OPAQUEPTR");
$t = 22;
my $p = T_OPAQUEPTR_IN( $t );
is( T_OPAQUEPTR_OUT($p), $t);
# T_OPAQUEPTR with a struct
-print "# T_OPAQUEPTR with a struct\n";
-
+note("T_OPAQUEPTR with a struct");
my @test = (5,6,7);
$p = T_OPAQUEPTR_IN_struct(@test);
my @result = T_OPAQUEPTR_OUT_struct($p);
@@ -286,15 +248,14 @@ for (0..$#test) {
}
# T_OPAQUE
-print "# T_OPAQUE\n";
-
+note("T_OPAQUE");
$t = 48;
$p = T_OPAQUE_IN( $t );
is(T_OPAQUEPTR_OUT_short( $p ), $t); # Test using T_OPAQUEPTR
is(T_OPAQUE_OUT( $p ), $t ); # Test using T_OPQAQUE
# T_OPAQUE_array
-print "# A packed array\n";
+note("A packed array");
my @opq = (2,4,8);
my $packed = T_OPAQUE_array(@opq);
@@ -313,19 +274,12 @@ for (0..$#opq) {
# Skip T_CALLBACK
# T_ARRAY
-print "# T_ARRAY\n";
my @inarr = (1,2,3,4,5,6,7,8,9,10);
my @outarr = T_ARRAY( 5, @inarr );
-is(scalar(@outarr), scalar(@inarr));
-
-for (0..$#inarr) {
- is($outarr[$_], $inarr[$_]);
-}
-
-
+is_deeply(\@outarr, \@inarr, "T_ARRAY");
# T_STDIO
-print "# T_STDIO\n";
+note("T_STDIO");
# open a file in XS for write
my $testfile= "stdio.tmp";