Merge branch 'more_argcargv'
* more_argcargv: Document argc argv library argcargv.i cosmetic updates Typemaps for (int ARGC, char **ARGV) fixup 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. Add Lua test for argcargv.i Add argcargv.i to more languages: Perl 5, Tcl, PHP Add argcargv.i to Lua
This commit is contained in:
commit
d60724b636
15 changed files with 360 additions and 23 deletions
|
|
@ -1,8 +1,10 @@
|
|||
%module argcargvtest
|
||||
|
||||
#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCTAVE) && !defined(SWIGR) && !defined(SWIGSCILAB)
|
||||
%include <argcargv.i>
|
||||
|
||||
%apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) }
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
|
||||
|
|
|
|||
26
Examples/test-suite/lua/argcargvtest_runme.lua
Normal file
26
Examples/test-suite/lua/argcargvtest_runme.lua
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
require("import") -- the import fn
|
||||
import("argcargvtest") -- import lib
|
||||
v = argcargvtest
|
||||
|
||||
-- catch "undefined" global variables
|
||||
local env = _ENV -- Lua 5.2
|
||||
if not env then env = getfenv () end -- Lua 5.1
|
||||
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||
|
||||
largs = {"hi", "hola", "hello"}
|
||||
assert(v.mainc(largs) == 3, "bad main typemap")
|
||||
|
||||
targs = {"hi", "hola"}
|
||||
assert(v.mainv(targs, 1) == "hola", "bad main typemap")
|
||||
|
||||
targs = {"hi", "hola"}
|
||||
assert(v.mainv(targs, 1) == "hola", "bad main typemap")
|
||||
|
||||
errorVal = 0
|
||||
function try()
|
||||
mainv("hello", 1)
|
||||
errorVal = 1
|
||||
end
|
||||
assert(not pcall(try) and errorVal == 0, "bad main typemap")
|
||||
|
||||
v.initializeApp(largs)
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue