Fix argcargv.i in Perl5, Tcl, PHP
Add missing type map for type check. Add testing of argcargv.i for Perl5, Tcl, PHP and Ruby. Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
This commit is contained in:
parent
464d548d71
commit
b88fe498ca
7 changed files with 123 additions and 0 deletions
20
Examples/test-suite/perl5/argcargvtest_runme.pl
Normal file
20
Examples/test-suite/perl5/argcargvtest_runme.pl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 8;
|
||||
BEGIN { use_ok('argcargvtest') }
|
||||
require_ok('argcargvtest');
|
||||
|
||||
my $largs = ["hi", "hola", "hello"];
|
||||
is(argcargvtest::mainc($largs), 3, "test main typemap 1");
|
||||
|
||||
my $targs = ["hi", "hola"];
|
||||
is(argcargvtest::mainv($targs, 1), "hola", "test main typemap 2");
|
||||
|
||||
my $errorVal = 0;
|
||||
my $ret = eval qq(argcargvtest::mainv("hello", 1); \$errorVal = 1;);
|
||||
is($ret, undef, "test main typemap 3");
|
||||
is($errorVal, 0, "test main typemap 4");
|
||||
|
||||
is(argcargvtest::initializeApp($largs), undef, "test main typemap 5");
|
||||
|
||||
ok(1, "done");
|
||||
29
Examples/test-suite/php/argcargvtest_runme.php
Normal file
29
Examples/test-suite/php/argcargvtest_runme.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
require "tests.php";
|
||||
|
||||
// New functions
|
||||
check::functions(array('mainc', 'mainv', 'initializeapp'));
|
||||
// New classes
|
||||
check::classes(array('argcargvtest'));
|
||||
// No new vars
|
||||
check::globals(array());
|
||||
|
||||
$largs = array('hi', 'hola', 'hello');
|
||||
check::equal(mainc($largs), 3, 'Test main typemap 1');
|
||||
|
||||
$targs = array('hi', 'hola');
|
||||
check::equal(mainv($targs, 1), 'hola', 'Test main typemap 2');
|
||||
|
||||
$error = 0;
|
||||
try {
|
||||
mainv('hello', 1);
|
||||
$error = 1;
|
||||
}
|
||||
catch (exception $e) {
|
||||
}
|
||||
check::equal($error, 0, 'Test main typemap 3');
|
||||
|
||||
initializeApp($largs);
|
||||
|
||||
check::done();
|
||||
32
Examples/test-suite/ruby/argcargvtest_runme.rb
Normal file
32
Examples/test-suite/ruby/argcargvtest_runme.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'swig_assert'
|
||||
require 'argcargvtest'
|
||||
|
||||
include Argcargvtest
|
||||
|
||||
|
||||
$largs = ["hi", "hola", "hello"]
|
||||
if mainc($largs) != 3
|
||||
raise RuntimeError, "bad main typemap"
|
||||
end
|
||||
|
||||
$targs = ["hi", "hola"]
|
||||
if mainv($targs, 1) != "hola"
|
||||
raise RuntimeError, "bad main typemap"
|
||||
end
|
||||
|
||||
$error = 0
|
||||
$ret = 0
|
||||
begin
|
||||
mainv("hello", 1)
|
||||
$error = 1
|
||||
rescue => e
|
||||
$ret = 1
|
||||
end
|
||||
|
||||
if $error == 1 or $ret != 1
|
||||
raise RuntimeError, "bad main typemap"
|
||||
end
|
||||
|
||||
initializeApp($largs)
|
||||
28
Examples/test-suite/tcl/argcargvtest_runme.tcl
Normal file
28
Examples/test-suite/tcl/argcargvtest_runme.tcl
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
if [ catch { load ./argcargvtest[info sharedlibextension] argcargvtest} err_msg ] {
|
||||
puts stderr "Could not load shared object:\n$err_msg"
|
||||
}
|
||||
|
||||
set largs {hi hola hello}
|
||||
if {[mainc $largs] != 3} {
|
||||
puts stderr "bad main typemap"
|
||||
exit 1
|
||||
}
|
||||
|
||||
set targs {hi hola}
|
||||
if {[mainv $targs 1] != "hola"} {
|
||||
puts stderr "bad main typemap"
|
||||
exit 1
|
||||
}
|
||||
|
||||
set targs " hi hola "
|
||||
if {[mainv $targs 1] != "hola"} {
|
||||
puts stderr "bad main typemap"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if { ! [ catch { mainv("hello", 1) } ] } {
|
||||
puts stderr "bad main typemap"
|
||||
exit 1
|
||||
}
|
||||
|
||||
initializeApp $largs
|
||||
|
|
@ -24,6 +24,11 @@
|
|||
$2[i] = NULL;
|
||||
}
|
||||
|
||||
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
|
||||
AV *av = (AV *)SvRV($input);
|
||||
$1 = SvTYPE(av) == SVt_PVAV;
|
||||
}
|
||||
|
||||
%typemap(freearg) (int ARGC, char **ARGV) {
|
||||
if ($2 != NULL) {
|
||||
free((void *)$2);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@
|
|||
$2[i] = NULL;
|
||||
}
|
||||
|
||||
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
|
||||
$1 = Z_TYPE($input) == IS_ARRAY;
|
||||
}
|
||||
|
||||
%typemap(freearg) (int ARGC, char **ARGV) {
|
||||
if ($2 != NULL) {
|
||||
free((void *)$2);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@
|
|||
$2[i] = NULL;
|
||||
}
|
||||
|
||||
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
|
||||
int len;
|
||||
$1 = Tcl_ListObjLength(interp, $input, &len) == TCL_OK;
|
||||
}
|
||||
|
||||
%typemap(freearg) (int ARGC, char **ARGV) {
|
||||
if ($2 != NULL) {
|
||||
free((void *)$2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue