reference.i improvements, testcase coverage. language specific interface support for test-suite.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11247 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
54b87bdd7d
commit
1dc5175753
5 changed files with 97 additions and 4 deletions
|
|
@ -64,7 +64,7 @@ INCLUDES = -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)
|
|||
LIBS = -L.
|
||||
LIBPREFIX = lib
|
||||
ACTION = check
|
||||
INTERFACEDIR = ../
|
||||
INTERFACEDIR = $(if $(wildcard $*.i), ./, ../)
|
||||
|
||||
#
|
||||
# Please keep test cases in alphabetical order.
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ CPP_TEST_CASES += \
|
|||
li_cdata \
|
||||
li_cstring \
|
||||
li_cdata_carrays \
|
||||
byreference \
|
||||
|
||||
C_TEST_CASES += \
|
||||
li_cdata \
|
||||
|
|
|
|||
52
Examples/test-suite/perl5/byreference.i
Normal file
52
Examples/test-suite/perl5/byreference.i
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
%module byreference
|
||||
|
||||
%include "reference.i"
|
||||
|
||||
%inline %{
|
||||
double FrVal;
|
||||
double ToVal;
|
||||
void PDouble(double *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RDouble(double &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PFloat(float *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RFloat(float &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PInt(int *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RInt(int &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PShort(short *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RShort(short &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PLong(long *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RLong(long &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PUInt(unsigned int *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RUInt(unsigned int &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PUShort(unsigned short *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RUShort(unsigned short &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PULong(unsigned long *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RULong(unsigned long &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PUChar(unsigned char *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RUChar(unsigned char &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PChar(signed char *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RChar(signed char &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
void PBool(bool *REFERENCE, int t = 0)
|
||||
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
|
||||
void RBool(bool &REFERENCE, int t = 0)
|
||||
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
|
||||
%}
|
||||
36
Examples/test-suite/perl5/byreference_runme.pl
Normal file
36
Examples/test-suite/perl5/byreference_runme.pl
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 68;
|
||||
BEGIN { use_ok('byreference') }
|
||||
require_ok('byreference');
|
||||
|
||||
sub chk { my($type, $call, $v1, $v2) = @_;
|
||||
$byreference::FrVal = $v1;
|
||||
my $v = $v2;
|
||||
eval { $call->(\$v) };
|
||||
is($@, '', "$type check");
|
||||
is($byreference::ToVal, $v2, "$type out");
|
||||
is($v, $v1, "$type in");
|
||||
}
|
||||
chk("double*", \&byreference::PDouble, 12.2, 18.6);
|
||||
chk("double&", \&byreference::RDouble, 32.5, 64.8);
|
||||
chk("float*", \&byreference::PFloat, 64.5, 96.0);
|
||||
chk("float&", \&byreference::RFloat, 98.5, 6.25);
|
||||
chk("int*", \&byreference::PInt, 1887, 3356);
|
||||
chk("int&", \&byreference::RInt, 2622, 9867);
|
||||
chk("short*", \&byreference::PShort, 4752, 3254);
|
||||
chk("short&", \&byreference::RShort, 1898, 5757);
|
||||
chk("long*", \&byreference::PLong, 6687, 7132);
|
||||
chk("long&", \&byreference::RLong, 8346, 4398);
|
||||
chk("uint*", \&byreference::PUInt, 6853, 5529);
|
||||
chk("uint&", \&byreference::RUInt, 5483, 7135);
|
||||
chk("ushort*", \&byreference::PUShort, 9960, 9930);
|
||||
chk("ushort&", \&byreference::RUShort, 1193, 4178);
|
||||
chk("ulong*", \&byreference::PULong, 7960, 4788);
|
||||
chk("ulong&", \&byreference::RULong, 8829, 1603);
|
||||
chk("uchar*", \&byreference::PUChar, 110, 239);
|
||||
chk("uchar&", \&byreference::RUChar, 15, 97);
|
||||
chk("char*", \&byreference::PChar, -7, 118);
|
||||
chk("char&", \&byreference::RChar, -3, -107);
|
||||
chk("bool*", \&byreference::PBool, 0, 1);
|
||||
chk("bool&", \&byreference::RBool, 1, 0);
|
||||
|
|
@ -205,7 +205,7 @@ as follows :
|
|||
%typemap(typecheck) int *REFERENCE, int &REFERENCE,
|
||||
short *REFERENCE, short &REFERENCE,
|
||||
long *REFERENCE, long &REFERENCE,
|
||||
signed char *REFERENCE, unsigned char &REFERENCE,
|
||||
signed char *REFERENCE, signed char &REFERENCE,
|
||||
bool *REFERENCE, bool &REFERENCE
|
||||
{
|
||||
$1 = SvROK($input) && SvIOK(SvRV($input));
|
||||
|
|
@ -224,7 +224,11 @@ as follows :
|
|||
unsigned long *REFERENCE, unsigned long &REFERENCE,
|
||||
unsigned char *REFERENCE, unsigned char &REFERENCE
|
||||
{
|
||||
$1 = SvROK($input) && SvUOK(SvRV($input));
|
||||
$1 = SvROK($input);
|
||||
if($1) {
|
||||
SV *tmpsv = SvRV($input);
|
||||
$1 = SvUOK(tmpsv) || SvIOK(tmpsv);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(argout) double *REFERENCE, double &REFERENCE,
|
||||
|
|
@ -239,7 +243,7 @@ as follows :
|
|||
%typemap(argout) int *REFERENCE, int &REFERENCE,
|
||||
short *REFERENCE, short &REFERENCE,
|
||||
long *REFERENCE, long &REFERENCE,
|
||||
signed char *REFERENCE, unsigned char &REFERENCE,
|
||||
signed char *REFERENCE, signed char &REFERENCE,
|
||||
bool *REFERENCE, bool &REFERENCE
|
||||
{
|
||||
SV *tempsv;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue