⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typemap.t

📁 source of perl for linux application,
💻 T
字号:
BEGIN {    chdir 't' if -d 't';    @INC = '../lib';    require Config; import Config;    if ($Config{'extensions'} !~ /\bXS\/Typemap\b/) {        print "1..0 # Skip: XS::Typemap was not built\n";        exit 0;    }}use Test;BEGIN { plan tests => 84 }use strict;use warnings;use XS::Typemap;ok(1);# Some inheritance trees to check ISA relationshipsBEGIN {  package intObjPtr::SubClass;  use base qw/ intObjPtr /;  sub xxx { 1; }}BEGIN {  package intRefIvPtr::SubClass;  use base qw/ intRefIvPtr /;  sub xxx { 1 }}# T_SV - standard perl scalar valueprint "# T_SV\n";my $sv = "Testing T_SV";ok( T_SV($sv), $sv);# T_SVREF - reference to Scalarprint "# T_SVREF\n";$sv .= "REF";my $svref = \$sv;ok( T_SVREF($svref), $svref );# Now test that a non reference is rejected# the typemaps croakeval { T_SVREF( "fail - not ref" ) };ok( $@ );# T_AVREF - reference to a perl Arrayprint "# T_AVREF\n";my @array;ok( T_AVREF(\@array), \@array);# Now test that a non array ref is rejectedeval { T_AVREF( \$sv ) };ok( $@ );# T_HVREF - reference to a perl Hashprint "# T_HVREF\n";my %hash;ok( T_HVREF(\%hash), \%hash);# Now test that a non hash ref is rejectedeval { T_HVREF( \@array ) };ok( $@ );# T_CVREF - reference to perl subroutineprint "# T_CVREF\n";my $sub = sub { 1 };ok( T_CVREF($sub), $sub );# Now test that a non code ref is rejectedeval { T_CVREF( \@array ) };ok( $@ );# T_SYSRET - system return valuesprint "# T_SYSRET\n";# first check successok( T_SYSRET_pass );# ... now failureok( T_SYSRET_fail, undef);# T_UV - unsigned integerprint "# T_UV\n";ok( T_UV(5), 5 );    # passok( T_UV(-4) != -4); # fail# T_IV - signed integerprint "# T_IV\n";ok( T_IV(5), 5);ok( T_IV(-4), -4);ok( T_IV(4.1), int(4.1));ok( T_IV("52"), "52");ok( T_IV(4.5) != 4.5); # failure# Skip T_INT# T_ENUM - enum listprint "# T_ENUM\n";ok( T_ENUM() ); # just hope for a true value# T_BOOL - booleanprint "# T_BOOL\n";ok( T_BOOL(52) );ok( ! T_BOOL(0) );ok( ! T_BOOL('') );ok( ! T_BOOL(undef) );# Skip T_U_INT# Skip T_SHORT# T_U_SHORT aka U16print "# T_U_SHORT\n";ok( T_U_SHORT(32000), 32000);if ($Config{shortsize} == 2) {  ok( T_U_SHORT(65536) != 65536); # probably dont want to test edge cases} else {  ok(1); # e.g. Crays have shortsize 4 (T3X) or 8 (CXX and SVX)}# T_U_LONG aka U32print "# T_U_LONG\n";ok( T_U_LONG(65536), 65536);ok( T_U_LONG(-1) != -1);# T_CHARprint "# T_CHAR\n";ok( T_CHAR("a"), "a");ok( T_CHAR("-"), "-");ok( T_CHAR(chr(128)),chr(128));ok( T_CHAR(chr(256)) ne chr(256));# T_U_CHARprint "# T_U_CHAR\n";ok( T_U_CHAR(127), 127);ok( T_U_CHAR(128), 128);ok( T_U_CHAR(-1) != -1);ok( T_U_CHAR(300) != 300);# T_FLOATprint "# T_FLOAT\n";# limited precisionok( sprintf("%6.3f",T_FLOAT(52.345)), sprintf("%6.3f",52.345));# T_NVprint "# T_NV\n";ok( T_NV(52.345), 52.345);# T_DOUBLEprint "# T_DOUBLE\n";ok( sprintf("%6.3f",T_DOUBLE(52.345)), sprintf("%6.3f",52.345));# T_PVprint "# T_PV\n";ok( T_PV("a string"), "a string");ok( T_PV(52), 52);# T_PTRprint "# T_PTR\n";my $t = 5;my $ptr = T_PTR_OUT($t);ok( T_PTR_IN( $ptr ), $t );# T_PTRREFprint "# T_PTRREF\n";$t = -52;$ptr = T_PTRREF_OUT( $t );ok( ref($ptr), "SCALAR");ok( T_PTRREF_IN( $ptr ), $t );# test that a non-scalar ref is rejectedeval { T_PTRREF_IN( $t ); };ok( $@ );# T_PTROBJprint "# T_PTROBJ\n";$t = 256;$ptr = T_PTROBJ_OUT( $t );ok( ref($ptr), "intObjPtr");ok( $ptr->T_PTROBJ_IN, $t );# check that normal scalar refs faileval {intObjPtr::T_PTROBJ_IN( \$t );};ok( $@ );# check that inheritance worksbless $ptr, "intObjPtr::SubClass";ok( ref($ptr), "intObjPtr::SubClass");ok( $ptr->T_PTROBJ_IN, $t );# Skip T_REF_IV_REF# T_REF_IV_PTRprint "# T_REF_IV_PTR\n";$t = -365;$ptr = T_REF_IV_PTR_OUT( $t );ok( ref($ptr), "intRefIvPtr");ok( $ptr->T_REF_IV_PTR_IN(), $t);# inheritance should not workbless $ptr, "intRefIvPtr::SubClass";eval { $ptr->T_REF_IV_PTR_IN };ok( $@ );# Skip T_PTRDESC# Skip T_REFREF# Skip T_REFOBJ# T_OPAQUEPTRprint "# T_OPAQUEPTR\n";$t = 22;my $p = T_OPAQUEPTR_IN( $t );ok( T_OPAQUEPTR_OUT($p), $t);# T_OPAQUEPTR with a structprint "# T_OPAQUEPTR with a struct\n";my @test = (5,6,7);$p = T_OPAQUEPTR_IN_struct(@test);my @result = T_OPAQUEPTR_OUT_struct($p);ok(scalar(@result),scalar(@test));for (0..$#test) {  ok($result[$_], $test[$_]);}# T_OPAQUEprint "# T_OPAQUE\n";$t = 48;$p = T_OPAQUE_IN( $t );ok(T_OPAQUEPTR_OUT_short( $p ), $t); # Test using T_OPAQUEPTRok(T_OPAQUE_OUT( $p ), $t );         # Test using T_OPQAQUE# T_OPAQUE_arrayprint "# A packed  array\n";my @opq = (2,4,8);my $packed = T_OPAQUE_array(@opq);my @uopq = unpack("i*",$packed);ok(scalar(@uopq), scalar(@opq));for (0..$#opq) {  ok( $uopq[$_], $opq[$_]);}# Skip T_PACKED# Skip T_PACKEDARRAY# Skip T_DATAUNIT# Skip T_CALLBACK# T_ARRAYprint "# T_ARRAY\n";my @inarr = (1,2,3,4,5,6,7,8,9,10);my @outarr = T_ARRAY( 5, @inarr );ok(scalar(@outarr), scalar(@inarr));for (0..$#inarr) {  ok($outarr[$_], $inarr[$_]);}# T_STDIOprint "# T_STDIO\n";# open a file in XS for writemy $testfile= "stdio.tmp";my $fh = T_STDIO_open( $testfile );ok( $fh );# write to it using perlif (defined $fh) {  my @lines = ("NormalSTDIO\n", "PerlIO\n");  # print to it using FILE* through XS  ok( T_STDIO_print($fh, $lines[0]), length($lines[0]));  # print to it using normal perl  ok(print $fh "$lines[1]");  # close it using XS if using perlio, using Perl otherwise  ok( $Config{useperlio} ? T_STDIO_close( $fh ) : close( $fh ) );  # open from perl, and check contents  open($fh, "< $testfile");  ok($fh);  my $line = <$fh>;  ok($line,$lines[0]);  $line = <$fh>;  ok($line,$lines[1]);  ok(close($fh));  ok(unlink($testfile));} else {  for (1..8) {    skip("Skip Test not relevant since file was not opened correctly",0);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -