Initial commit of Octave module.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10290 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Xavier Delacour 2008-03-01 23:35:44 +00:00
commit 393391965c
275 changed files with 14004 additions and 5 deletions

View file

@ -0,0 +1,82 @@
#######################################################################
# Makefile for octave test-suite
#######################################################################
LANGUAGE = octave
ifneq (,$(USE_VALGRIND))
OCTAVE = valgrind --leak-check=full --suppressions=pyswig.supp @OCTAVE@
else
OCTAVE = @OCTAVE@ -q
endif
SCRIPTSUFFIX = _runme.m
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
#CPP_TEST_CASES +=
#C_TEST_CASES +=
#
# This test only works with modern C compilers
#
#C_TEST_CASES += \
# complextest
include $(srcdir)/../common.mk
# Overridden variables here
LIBS = -L.
# Rules for the different types of tests
%.cpptest:
$(setup)
+$(swig_and_compile_cpp)
$(run_testcase)
%.ctest:
$(setup)
+$(swig_and_compile_cpp)
$(run_testcase)
%.multicpptest:
$(setup)
+$(swig_and_compile_multi_cpp)
$(run_testcase)
# Runs the testcase. A testcase is only run if
# a file is found which has _runme.m appended after the testcase name.
run_testcase = \
if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then ( \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH OCTAVEPATH=$(srcdir):OCTAVEPATH $(OCTAVE) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX);) \
fi;
# Clean: remove the generated .m file
%.clean:
@rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.m hugemod_b.m hugemod_runme.m
@rm -f $*.m;
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile octave_clean
cvsignore:
@echo '*wrap* *.mc *.so *.dll *.exp *.lib'
@echo Makefile
@for i in ${CPP_TEST_CASES} ${C_TEST_CASES}; do echo $$i.m; done
@for i in ${CPP_TEST_CASES} ${C_TEST_CASES}; do if grep -q $${i}_runme.m CVS/Entries ; then echo $${i}_runme.m; fi; done
@echo clientdata_prop_a.m
@echo clientdata_prop_b.m
@echo imports_a.m
@echo imports_b.m
@echo mod_a.m mod_b.m
@echo hugemod.h hugemod_a.i hugemod_b.i hugemod_a.m hugemod_b.m hugemod_runme.m
@echo template_typedef_import.m
hugemod:
perl hugemod.pl
$(MAKE) hugemod_a.cpptest
$(MAKE) hugemod_b.cpptest
time $(OCTAVE) hugemod_runme.m
time $(OCTAVE) hugemod_runme.m

View file

@ -0,0 +1,7 @@
abstract_access
d = abstract_access.D();
if (d.do_x() != 1)
error
endif

View file

@ -0,0 +1,8 @@
abstract_typedef2
a = A_UF();

View file

@ -0,0 +1,12 @@
abstract_typedef
e = Engine();
a = A();
if (a.write(e) != 1)
error
endif

View file

@ -0,0 +1,7 @@
abstract_virtual
d = D();
e = E();

View file

@ -0,0 +1,29 @@
argcargvtest
largs={'hi','hola','hello'};
if (mainc(largs) != 3)
error("bad main typemap");
endif
targs={'hi','hola'};
if (mainv(targs,1) != 'hola')
error("bad main typemap");
endif
targs={'hi', 'hola'};
if (mainv(targs,1) != 'hola')
error("bad main typemap");
endif
try
error_flag = 0;
mainv('hello',1);
error_flag = 1;
catch
end_try_catch
if (error_flag)
error("bad main typemap")
endif
initializeApp(largs);

View file

@ -0,0 +1,25 @@
array_member
f = Foo();
f.data = cvar.global_data;
for i=0:7,
if (get_value(f.data,i) != get_value(cvar.global_data,i))
error("Bad array assignment");
endif
endfor
for i=0:7,
set_value(f.data,i,-i);
endfor
cvar.global_data = f.data;
for i=0:7,
if (get_value(f.data,i) != get_value(cvar.global_data,i))
error("Bad array assignment")
endif
endfor

View file

@ -0,0 +1,18 @@
arrays_global
arrays_global.array_i = arrays_global.array_const_i;
BeginString_FIX44a;
BeginString_FIX44b;
BeginString_FIX44c;
BeginString_FIX44d;
BeginString_FIX44d;
BeginString_FIX44b ="12"'\0'"45";
BeginString_FIX44b;
BeginString_FIX44d;
BeginString_FIX44e;
BeginString_FIX44f;
test_a("hello","hi","chello","chi");
test_b("1234567","hi");

View file

@ -0,0 +1,40 @@
_callback
callback
if (foo(2) != 2)
error
endif
if (A_bar(2) != 4)
error
endif
if (foobar(3, _callback.foo) != foo(3))
error
endif
if (foobar(3, foo) != foo(3))
error
endif
if (foobar(3, A_bar) != A_bar(3))
error
endif
if (foobar(3, foof) != foof(3))
error
endif
if (foobar_i(3, foo_i) != foo_i(3))
error
endif
if (foobar_d(3.5, foo_d) != foo_d(3.5))
error
endif
a = A();
if (foobarm(3, a, A.foom_cb_ptr) != a.foom(3))
error
endif

View file

@ -0,0 +1,7 @@
class_ignore
a = class_ignore.Bar();
if (!strcmp(class_ignore.do_blah(a),"Bar::blah"))
error
endif

View file

@ -0,0 +1,7 @@
class_scope_weird
f = class_scope_weird.Foo();
g = class_scope_weird.Foo(3);
if (f.bar(3) != 3)
error
endif

View file

@ -0,0 +1,24 @@
compactdefaultargs
defaults1 = Defaults1(1000);
defaults1 = Defaults1();
if (defaults1.ret(10.0) != 10.0)
error
endif
if (defaults1.ret() != -1.0)
error
endif
defaults2 = Defaults2(1000);
defaults2 = Defaults2();
if (defaults2.ret(10.0) != 10.0)
error
endif
if (defaults2.ret() != -1.0)
error
endif

View file

@ -0,0 +1,19 @@
complextest
a = complex(-1,2);
if (complextest.Conj(a) != a.conjugate())
error("bad complex mapping")
endif
if (complextest.Conjf(a) != a.conjugate())
error("bad complex mapping")
endif
v = (complex(1,2), complex(2,3), complex(4,3), 1);
try
complextest.Copy_h(v);
catch
end_try_catch

View file

@ -0,0 +1,34 @@
constover
p = constover.test("test");
if (!strcmp(p,"test"))
error("test failed!")
endif
p = constover.test_pconst("test")
if (!strcmp(p,"test_pconst"))
error("test_pconst failed!")
endif
f = constover.Foo()
p = f.test("test")
if (!strcmp(p,"test"))
error("member-test failed!")
endif
p = f.test_pconst("test")
if (!strcmp(p,"test_pconst"))
error("member-test_pconst failed!")
endif
p = f.test_constm("test")
if (!strcmp(p,"test_constmethod"))
error("member-test_constm failed!")
endif
p = f.test_pconstm("test")
if (!strcmp(p,"test_pconstmethod"))
error("member-test_pconstm failed!")
endif

View file

@ -0,0 +1,44 @@
constructor_copy
f1 = Foo1(3);
f11 = Foo1(f1);
if (f1.x != f11.x)
error
endif
f8 = Foo8();
try
f81 = Foo8(f8);
good = 0;
catch
good = 1;
end_try_catch
if (!good)
error
endif
bi = Bari(5);
bc = Bari(bi);
if (bi.x != bc.x)
error
endif
bd = Bard(5);
try
bc = Bard(bd);
good = 0;
catch
good = 1;
end_try_catch
if (!good)
error
endif

View file

@ -0,0 +1,135 @@
contract
contract.test_preassert(1,2);
try
contract.test_preassert(-1,0)
error("Failed! Preassertions are broken")
catch
end_try_catch
contract.test_postassert(3);
try
contract.test_postassert(-3);
error("Failed! Postassertions are broken")
catch
end_try_catch
contract.test_prepost(2,3);
contract.test_prepost(5,-4);
try
contract.test_prepost(-3,4);
error("Failed! Preassertions are broken")
catch
end_try_catch
try
contract.test_prepost(4,-10);
error("Failed! Postassertions are broken")
catch
end_try_catch
f = contract.Foo();
f.test_preassert(4,5);
try
f.test_preassert(-2,3);
error("Failed! Method preassertion.")
catch
end_try_catch
f.test_postassert(4);
try
f.test_postassert(-4);
error("Failed! Method postassertion")
catch
end_try_catch
f.test_prepost(3,4);
f.test_prepost(4,-3);
try
f.test_prepost(-4,2);
error("Failed! Method preassertion.")
catch
end_try_catch
try
f.test_prepost(4,-10);
error("Failed! Method postassertion.")
catch
end_try_catch
contract.Foo_stest_prepost(4,0);
try
contract.Foo_stest_prepost(-4,2);
error("Failed! Static method preassertion")
catch
end_try_catch
try
contract.Foo_stest_prepost(4,-10);
error("Failed! Static method posteassertion")
catch
end_try_catch
b = contract.Bar();
try
b.test_prepost(2,-4);
error("Failed! Inherited preassertion.")
catch
end_try_catch
d = contract.D();
try
d.foo(-1,1,1,1,1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch
try
d.foo(1,-1,1,1,1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch
try
d.foo(1,1,-1,1,1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch
try
d.foo(1,1,1,-1,1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch
try
d.foo(1,1,1,1,-1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch
try
d.bar(-1,1,1,1,1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch
try
d.bar(1,-1,1,1,1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch
try
d.bar(1,1,-1,1,1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch
try
d.bar(1,1,1,-1,1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch
try
d.bar(1,1,1,1,-1);
error("Failed! Inherited preassertion (D).")
catch
end_try_catch

View file

@ -0,0 +1,27 @@
cpp_enum
f = cpp_enum.Foo();
if (f.hola != cpp_enum.Foo_Hello)
error(f.hola);
error;
endif
f.hola = cpp_enum.Foo_Hi;
if (f.hola != cpp_enum.Foo_Hi)
error(f.hola);
error;
endif
f.hola = cpp_enum.Foo_Hello;
if (f.hola != cpp_enum.Foo_Hello)
error(f.hola);
error;
endif
cpp_enum.hi = cpp_enum.Hello;
if (cpp_enum.hi != cpp_enum.Hello)
error(cpp_enum.hi);
error;
endif

View file

@ -0,0 +1,55 @@
# Note: This example assumes that namespaces are flattened
cpp_namespace
n = cpp_namespace.fact(4);
if (n != 24)
error("Bad return value!")
endif
if (cpp_namespace.cvar.Foo != 42)
error("Bad variable value!")
endif
t = cpp_namespace.Test();
if (!strcmp(t.method(),"Test::method"))
error("Bad method return value!")
endif
if (!strcmp(cpp_namespace.do_method(t),"Test::method"))
error("Bad return value!")
endif
if (!strcmp(cpp_namespace.do_method2(t),"Test::method"))
error("Bad return value!")
endif
cpp_namespace.weird("hello", 4);
clear t;
t2 = cpp_namespace.Test2();
t3 = cpp_namespace.Test3();
t4 = cpp_namespace.Test4();
t5 = cpp_namespace.Test5();
if (cpp_namespace.foo3(42) != 42)
error("Bad return value!")
endif
if (!strcmp(cpp_namespace.do_method3(t2,40),"Test2::method"))
error("Bad return value!")
endif
if (!strcmp(cpp_namespace.do_method3(t3,40),"Test3::method"))
error("Bad return value!")
endif
if (!strcmp(cpp_namespace.do_method3(t4,40),"Test4::method"))
error("Bad return value!")
endif
if (!strcmp(cpp_namespace.do_method3(t5,40),"Test5::method"))
error("Bad return value!")
endif

View file

@ -0,0 +1,86 @@
default_args
if (default_args.Statics.staticmethod() != 60)
error
endif
if (default_args.cfunc1(1) != 2)
error
endif
if (default_args.cfunc2(1) != 3)
error
endif
if (default_args.cfunc3(1) != 4)
error
endif
f = default_args.Foo();
f.newname();
f.newname(1);
try
f = default_args.Foo(1);
ok = 1;
catch
ok = 0;
end_try_catch
if (ok)
error("Foo::Foo ignore is not working")
endif
try
f = default_args.Foo(1,2);
ok = 1;
catch
ok = 0;
end_try_catch
if (ok)
error("Foo::Foo ignore is not working")
endif
try
f = default_args.Foo(1,2,3);
ok = 1;
catch
ok = 0;
end_try_catch
if (ok)
error("Foo::Foo ignore is not working")
endif
try
m = f.meth(1);
ok = 1;
catch
ok = 0;
end_try_catch
if (ok)
error("Foo::meth ignore is not working")
endif
try
m = f.meth(1,2);
ok = 1;
catch
ok = 0;
end_try_catch
if (ok)
error("Foo::meth ignore is not working")
endif
try
m = f.meth(1,2,3);
ok = 1;
catch
ok = 0;
end_try_catch
if (ok)
error("Foo::meth ignore is not working")
endif

View file

@ -0,0 +1,111 @@
default_constructor
dc = default_constructor;
a = dc.new_A();
dc.delete_A(a);
aa = dc.new_AA();
dc.delete_AA(aa);
try
b = dc.new_B();
error("Whoa. new_BB created.")
catch
end_try_catch
del_b = dc.delete_B;
try
bb = dc.new_BB();
error("Whoa. new_BB created.")
catch
end_try_catch
del_bb = dc.delete_BB;
try
c = dc.new_C();
error("Whoa. new_C created.")
catch
end_try_catch
del_c = dc.delete_C;
cc = dc.new_CC();
dc.delete_CC(cc);
try
d = dc.new_D();
error("Whoa. new_D created")
catch
end_try_catch
del_d = dc.delete_D;
try
dd = dc.new_DD();
error("Whoa. new_DD created")
catch
end_try_catch
dd = dc.delete_DD;
try
ad = dc.new_AD();
error("Whoa. new_AD created")
catch
end_try_catch
del_ad = dc.delete_AD;
e = dc.new_E();
dc.delete_E(e);
ee = dc.new_EE();
dc.delete_EE(ee);
try
eb = dc.new_EB();
error("Whoa. new_EB created")
catch
end_try_catch
del_eb = dc.delete_EB;
f = dc.new_F();
try
del_f = dc.delete_F;
error("Whoa. delete_F created")
catch
end_try_catch
dc.F_destroy(f);
ff = dc.new_FFF();
try
del_ff = dc.delete_FFF;
error("Whoa. delete_FFF created")
catch
end_try_catch
dc.F_destroy(ff);
g = dc.new_G();
try
del_g = dc.delete_G;
error("Whoa. delete_G created")
catch
end_try_catch
dc.G_destroy(g);
gg = dc.new_GG();
dc.delete_GG(gg);
hh = default_constructor.HH(1,1);

View file

@ -0,0 +1,44 @@
director_abstract
MyFoo=@() subclass(director_abstract.Foo(),@ping);
function out=ping(self)
out="MyFoo::ping()";
end
a = MyFoo();
if (!strcmp(a.ping(),"MyFoo::ping()"))
error(a.ping())
endif
if (!strcmp(a.pong(),"Foo::pong();MyFoo::ping()"))
error(a.pong())
endif
MyExample1=@() subclass(director_abstract.Example1(),'Color',@(self,r,g,b) r);
MyExample2=@(a,b) subclass(director_abstract.Example2(a,b),'Color',@(self,r,g,b) g);
MyExample3=@() subclass(director_abstract.Example3_i(),'Color',@(self,r,g,b) b);
me1 = MyExample1();
if (director_abstract.Example1.get_color(me1, 1,2,3) != 1)
error
endif
me2 = MyExample2(1,2);
if (me2.get_color(me2, 1,2,3) != 2)
error
endif
me3 = MyExample3();
if (me3.get_color(me3, 1,2,3) != 3)
error
endif
# don't check that we cannot construct abstract bases, since we have no
# way of disambiguating that with the normal construction case using
# subclass. furthermore, calling a pure virtual method will still generate
# an error.

View file

@ -0,0 +1,110 @@
director_basic
function self=OctFoo()
global director_basic;
self=subclass(director_basic.Foo());
self.ping=@OctFoo_ping;
end
function string=OctFoo_ping(self)
string="OctFoo::ping()";
end
a = OctFoo();
if (!strcmp(a.ping(),"OctFoo::ping()"))
error(a.ping())
endif
if (!strcmp(a.pong(),"Foo::pong();OctFoo::ping()"))
error(a.pong())
endif
b = director_basic.Foo();
if (!strcmp(b.ping(),"Foo::ping()"))
error(b.ping())
endif
if (!strcmp(b.pong(),"Foo::pong();Foo::ping()"))
error(b.pong())
endif
a = director_basic.A1(1);
if (a.rg(2) != 2)
error
endif
function self=OctClass()
global director_basic;
self=subclass(director_basic.MyClass());
self.method=@OctClass_method;
self.vmethod=@OctClass_vmethod;
end
function OctClass_method(self,vptr)
self.cmethod = 7;
end
function out=OctClass_vmethod(self,b)
b.x = b.x + 31;
out=b;
end
b = director_basic.Bar(3);
d = director_basic.MyClass();
c = OctClass();
cc = director_basic.MyClass_get_self(c);
dd = director_basic.MyClass_get_self(d);
bc = cc.cmethod(b);
bd = dd.cmethod(b);
cc.method(b);
if (c.cmethod != 7)
error
endif
if (bc.x != 34)
error
endif
if (bd.x != 16)
error
endif
function self=OctMulti()
global director_basic;
self=subclass(director_basic.Foo(),director_basic.MyClass());
self.vmethod=@OctMulti_vmethod;
self.ping=@OctMulti_ping;
end
function out=OctMulti_vmethod(self,b)
b.x = b.x + 31;
out=b;
end
function out=OctMulti_ping(self)
out="OctFoo::ping()";
end
a = 0;
for i=0:100,
octmult = OctMulti();
octmult.pong();
clear octmult
endfor
octmult = OctMulti();
p1 = director_basic.Foo_get_self(octmult);
p2 = director_basic.MyClass_get_self(octmult);
p1.ping();
p2.vmethod(bc);

View file

@ -0,0 +1,98 @@
director_classic
TargetLangPerson=@() subclass(Person(),'id',@(self) "TargetLangPerson");
TargetLangChild=@() subclass(Child(),'id',@(self) "TargetLangChild");
TargetLangGrandChild=@() subclass(GrandChild(),'id',@(self) "TargetLangGrandChild");
# Semis - don't override id() in target language
TargetLangSemiPerson=@() subclass(Person());
TargetLangSemiChild=@() subclass(Child());
TargetLangSemiGrandChild=@() subclass(GrandChild());
# Orphans - don't override id() in C++
TargetLangOrphanPerson=@() subclass(OrphanPerson(),'id',@(self) "TargetLangOrphanPerson");
TargetLangOrphanChild=@() subclass(OrphanChild(),'id',@(self) "TargetLangOrphanChild");
function check(person,expected)
global Caller;
# Normal target language polymorphic call
ret = person.id();
if (ret != expected)
raise ("Failed. Received: " + ret + " Expected: " + expected);
endif
# Polymorphic call from C++
caller = Caller();
caller.setCallback(person);
ret = caller.call();
if (ret != expected)
error ("Failed. Received: " + ret + " Expected: " + expected);
endif
# Polymorphic call of object created in target language and passed to C++ and back again
baseclass = caller.baseClass();
ret = baseclass.id();
if (ret != expected)
error ("Failed. Received: " + ret + " Expected: " + expected);
endif
caller.resetCallback();
end
person = Person();
check(person, "Person");
clear person;
person = Child();
check(person, "Child");
clear person;
person = GrandChild();
check(person, "GrandChild");
clear person;
person = TargetLangPerson();
check(person, "TargetLangPerson");
clear person;
person = TargetLangChild();
check(person, "TargetLangChild");
clear person;
person = TargetLangGrandChild();
check(person, "TargetLangGrandChild");
clear person;
# Semis - don't override id() in target language
person = TargetLangSemiPerson();
check(person, "Person");
clear person;
person = TargetLangSemiChild();
check(person, "Child");
clear person;
person = TargetLangSemiGrandChild();
check(person, "GrandChild");
clear person;
# Orphans - don't override id() in C++
person = OrphanPerson();
check(person, "Person");
clear person;
person = OrphanChild();
check(person, "Child");
clear person;
person = TargetLangOrphanPerson();
check(person, "TargetLangOrphanPerson");
clear person;
person = TargetLangOrphanChild();
check(person, "TargetLangOrphanChild");
clear person;

View file

@ -0,0 +1,10 @@
director_default
f = Foo();
f = Foo(1);
f = Bar();
f = Bar(1);

View file

@ -0,0 +1,36 @@
director_detect
global MyBar=@(val=2) \
subclass(director_detect.Bar(),'val',val,@get_value,@get_class,@just_do_it,@clone);
function val=get_value(self)
self.val = self.val + 1;
val = self.val;
end
function ptr=get_class(self)
global director_detect;
self.val = self.val + 1;
ptr=director_detect.A();
end
function just_do_it(self)
self.val = self.val + 1;
end
function ptr=clone(self)
global MyBar;
ptr=MyBar(self.val);
end
b = MyBar();
f = b.baseclass();
v = f.get_value();
a = f.get_class();
f.just_do_it();
c = b.clone();
vc = c.get_value();
if ((v != 3) || (b.val != 5) || (vc != 6))
error("Bad virtual detection")
endif

View file

@ -0,0 +1,10 @@
director_enum
MyFoo=@() subclass(director_enum.Foo(),'say_hi',@(self,val) val);
b = director_enum.Foo();
a = MyFoo();
if (a.say_hi(director_enum.hello) != b.say_hello(director_enum.hi))
error
endif

View file

@ -0,0 +1,57 @@
director_exception
MyFoo=@() subclass(Foo(),
'ping',@(self) raise(NotImplementedError("MyFoo::ping() EXCEPTION")));
MyFoo2=@() subclass(Foo(),
'ping',@(self) true);
ok = 0;
a = MyFoo();
b = launder(a);
try
b.pong();
catch
[etype,e]=raised();
if (etype=="NotImplementedError")
ok=1;
endif
end_try_catch
if (!ok)
error
endif
ok = 0;
a = MyFoo2();
b = launder(a);
try
b.pong();
catch
ok = 1;
end_try_catch
if (!ok)
error
endif
try
raise(Exception2());
catch
if (!strcmp(raised,"Exception2"))
rethrow(lasterr);
endif
end_try_catch
try
raise(Exception1());
catch
if (!strcmp(raised,"Exception1"))
rethrow(lasterr);
endif
end_try_catch

View file

@ -0,0 +1,12 @@
director_extend
MyObject=@() subclass(SpObject(),'getFoo',@(self) 123);
m = MyObject();
if (m.dummy() != 666)
error("1st call")
endif
if (m.dummy() != 666)
error("2nd call")
endif

View file

@ -0,0 +1,56 @@
director_finalizer
MyFoo=@() subclass(Foo(),'__del__',@delete_MyFoo);
function delete_MyFoo(self)
self.orStatus(2);
try
Foo.__del__(self);
catch
end_try_catch
endfunction
resetStatus();
a = MyFoo();
clear a;
if (getStatus() != 3)
error
endif
resetStatus();
a = MyFoo();
launder(a);
if (getStatus() != 0)
error
endif
clear a;
if (getStatus() != 3)
error
endif
resetStatus();
a = MyFoo().__disown__();
deleteFoo(a);
if (getStatus() != 3)
error
endif
resetStatus();
a = MyFoo().__disown__();
deleteFoo(launder(a));
if (getStatus() != 3)
error
endif
resetStatus();

View file

@ -0,0 +1,9 @@
director_frob
foo = Bravo();
s = foo.abs_method();
if (!strcmp(s,"Bravo::abs_method()"))
error(s)
endif

View file

@ -0,0 +1,39 @@
director_nested
A=@() subclass(FooBar_int(),
'do_step',@(self) "A::do_step;",
'get_value',@(self) "A::get_value");
a = A();
if (!strcmp(a.step(),"Bar::step;Foo::advance;Bar::do_advance;A::do_step;"))
error("Bad A virtual resolution")
endif
B=@() subclass(FooBar_int(),
'do_advance',@(self) strcat("B::do_advance;",self.do_step()),
'do_step',@(self) "B::do_step;",
'get_value',@(self) 1);
b = B();
if (!strcmp(b.step(),"Bar::step;Foo::advance;B::do_advance;B::do_step;"))
error("Bad B virtual resolution")
endif
C=@() subclass(FooBar_int(),
'do_advance',@(self) strcat("C::do_advance;",self.FooBar_int.do_advance()),
'do_step',@(self) "C::do_step;",
'get_value',@(self) 2,
'get_name',@(self) strcat(self.FooBar_int.get_name()," hello"));
cc = C();
c = FooBar_int_get_self(cc);
c.advance();
if (!strcmp(c.get_name(),"FooBar::get_name hello"))
error
endif
if (!strcmp(c.name(),"FooBar::get_name hello"))
error
endif

View file

@ -0,0 +1,31 @@
director_stl
MyFoo=@() subclass(director_stl.Foo(),\
'ping',@(self,s) "MyFoo::ping():" + s,\
'pident',@(self,arg) arg,\
'vident',@(self,v) v,\
'vidents',@(self,v) v,\
'vsecond',@(self,v1,v2) v2,\
);
a = MyFoo();
a.tping("hello");
a.tpong("hello");
p = {1,2}
a.pident(p);
v = {3,4}
a.vident(v);
a.tpident(p);
a.tvident(v);
v1 = {3,4};
v2 = {5,6};
a.tvsecond(v1,v2);
vs=("hi", "hello");
vs;
a.tvidents(vs);

View file

@ -0,0 +1,27 @@
director_string
function out=get_first(self)
out = strcat(self.A.get_first()," world!");
end
function process_text(self,string)
self.A.process_text(string);
self.smem = "hello";
end
B=@(string) subclass(A(string),'get_first',@get_first,'process_text',@process_text);
b = B("hello");
b.get(0);
if (!strcmp(b.get_first(),"hello world!"))
error(b.get_first())
endif
b.call_process_func();
if (!strcmp(b.smem,"hello"))
error(b.smem)
endif

View file

@ -0,0 +1,16 @@
director_unroll
MyFoo=@() subclass(director_unroll.Foo(),'ping',@(self) "MyFoo::ping()");
a = MyFoo();
b = director_unroll.Bar();
b.set(a);
c = b.get();
if (swig_this(a) != swig_this(c))
a,c
error
endif

View file

@ -0,0 +1,21 @@
director_wstring
B=@(string) subclass(A(string),\
'get_first',A.get_first(self) + " world!",\
'process_text',@(self) self.smem = u"hello"\
);
b = B("hello");
b.get(0);
if (!strcmp(b.get_first(),"hello world!"))
error(b.get_first())
endif
b.call_process_func();
if (!strcmp(b.smem,"hello"))
error(smem)
endif

View file

@ -0,0 +1,14 @@
dynamic_cast
f = dynamic_cast.Foo();
b = dynamic_cast.Bar();
x = f.blah();
y = b.blah();
a = dynamic_cast.do_test(y);
if (!strcmp(a,"Bar::test"))
error("Failed!!")
endif

View file

@ -0,0 +1 @@
empty

View file

@ -0,0 +1,13 @@
enum_template
if (enum_template.MakeETest() != 1)
error
endif
enum_template.TakeETest(0);
try
a=enum_template.TakeETest(0);
error
catch
end_try_catch

View file

@ -0,0 +1,7 @@
enums
enums.bar2(1)
enums.bar3(1)
enums.bar1(1)

View file

@ -0,0 +1,45 @@
exception_order
a = A();
try
a.foo()
catch
if (!strcmp(raised(),"E1"))
error, "bad exception order"
endif
end_try_catch
try
a.bar()
catch
if (!strcmp(raised(),"E2"))
error, "bad exception order"
endif
end_try_catch
try
a.foobar()
catch
[t,e]=raised();
if (!strcmp(e.args(0),"postcatch unknown"))
error
endif
end_try_catch
try
a.barfoo(1)
catch
if (!strcmp(raised(),"E1"))
error, "bad exception order"
endif
end_try_catch
try
a.barfoo(2)
catch
if (!strcmp(raised(),"E2"))
error, "bad exception order"
endif
end_try_catch

View file

@ -0,0 +1,46 @@
extend_placement
foo = extend_placement.Foo();
foo = extend_placement.Foo(1);
foo = extend_placement.Foo(1,1);
foo.spam();
foo.spam("hello");
foo.spam(1);
foo.spam(1,1);
foo.spam(1,1,1);
foo.spam(extend_placement.Foo());
foo.spam(extend_placement.Foo(), 1.0);
bar = extend_placement.Bar();
bar = extend_placement.Bar(1);
bar.spam();
bar.spam("hello");
bar.spam(1);
bar.spam(1,1);
bar.spam(1,1,1);
bar.spam(extend_placement.Bar());
bar.spam(extend_placement.Bar(), 1.0);
foo = extend_placement.FooTi();
foo = extend_placement.FooTi(1);
foo = extend_placement.FooTi(1,1);
foo.spam();
foo.spam("hello");
foo.spam(1);
foo.spam(1,1);
foo.spam(1,1,1);
foo.spam(extend_placement.Foo());
foo.spam(extend_placement.Foo(), 1.0);
bar = extend_placement.BarTi();
bar = extend_placement.BarTi(1);
bar.spam();
bar.spam("hello");
bar.spam(1);
bar.spam(1,1);
bar.spam(1,1,1);
bar.spam(extend_placement.Bar());
bar.spam(extend_placement.Bar(), 1.0);

View file

@ -0,0 +1,10 @@
extend_template_ns
f = Foo_One();
if (f.test1(37) != 37)
error
endif
if (f.test2(42) != 42)
error
endif

View file

@ -0,0 +1,10 @@
extend_template
f = extend_template.Foo_0();
if (f.test1(37) != 37)
error
endif
if (f.test2(42) != 42)
error
endif

View file

@ -0,0 +1,6 @@
extend_variable
if (Foo.Bar != 42)
error
endif

View file

@ -0,0 +1,9 @@
file_test
file_test.nfile("stdout");
cstdout = file_test.GetStdOut();
file_test.nfile(cstdout);
file_test.nfile_name("test.dat");

View file

@ -0,0 +1,46 @@
friends
a = friends.A(2);
if (friends.get_val1(a) != 2)
error
endif
if (friends.get_val2(a) != 4)
error
endif
if (friends.get_val3(a) != 6)
error
endif
# nice overload working fine
if (friends.get_val1(1,2,3) != 1)
error
endif
b = friends.B(3);
# David's case
if (friends.mix(a,b) != 5)
error
endif
di = friends.D_d(2);
dd = friends.D_d(3.3);
# incredible template overloading working just fine
if (friends.get_val1(di) != 2)
error
endif
if (friends.get_val1(dd) != 3.3)
error
endif
friends.set(di, 4);
friends.set(dd, 1.3);
if (friends.get_val1(di) != 4)
error
endif
if (friends.get_val1(dd) != 1.3)
error
endif

View file

@ -0,0 +1,10 @@
fvirtual
sw = Switch();
n = Node();
i = sw.addChild(n);
if (i != 2)
error("addChild")
endif

View file

@ -0,0 +1,5 @@
global_ns_arg
a = foo(1);
b = bar();

View file

@ -0,0 +1,15 @@
grouping
x = grouping.test1(42);
if (x != 42)
error
endif
grouping.test2(42);
x = (grouping.do_unary(37, grouping.NEGATE));
if (x != -37)
error
endif
grouping.cvar.test3 = 42;

View file

@ -0,0 +1,10 @@
iadd
f = iadd.Foo();
f.AsA.x = 3;
f.AsA += f.AsA;
if (f.AsA.x != 6)
error
endif

View file

@ -0,0 +1,8 @@
import_nomodule
f = create_Foo();
test1(f,42);
delete_Foo(f);
b = Bar();
test1(b,37);

View file

@ -0,0 +1,19 @@
# This is the import runtime testcase.
imports_b
imports_a
x = imports_b.B();
x.hello();
a = imports_a.A();
c = imports_b.C();
a1 = c.get_a(c);
a2 = c.get_a_type(c);
a1.hello();
a2.hello();
assert(swig_this(a1)==swig_this(a2));
assert(strcmp(swig_type(a1),swig_type(a2)));

View file

@ -0,0 +1,24 @@
inctest
try
a = inctest.A();
catch
error("didn't find A\ntherefore, I didn't include \
'testdir/subdir1/hello.i'")
end_try_catch
try
b = inctest.B();
catch
error("didn't find B\ntherefore, I didn't include 'testdir/subdir2/hello.i'")
end_try_catch
# Check the import in subdirectory worked
if (inctest.importtest1(5) != 15)
error("import test 1 failed")
endif
if (!strcmp(inctest.importtest2("black"),"white"))
error("import test 2 failed")
endif

View file

@ -0,0 +1,22 @@
inherit_missing
a = inherit_missing.new_Foo();
b = inherit_missing.Bar();
c = inherit_missing.Spam();
x = inherit_missing.do_blah(a);
if (!strcmp(x, "Foo::blah"))
error("Whoa! Bad return %s", x)
endif
x = inherit_missing.do_blah(b);
if (!strcmp(x, "Bar::blah"))
error("Whoa! Bad return %s", x)
endif
x = inherit_missing.do_blah(c);
if (!strcmp(x, "Spam::blah"))
error("Whoa! Bad return %s", x)
endif
inherit_missing.delete_Foo(a);

View file

@ -0,0 +1,27 @@
inout
a = inout.AddOne1(1);
if (a != 2)
error
endif
a = inout.AddOne3(1,1,1);
if (a != [2,2,2])
error
endif
a = inout.AddOne1p((1,1));
if (a != (2,2))
error
endif
a = inout.AddOne2p((1,1),1);
if (a != [(2,2),2])
error
endif
a = inout.AddOne3p(1,(1,1),1);
if (a != [2,(2,2),2])
error
endif

View file

@ -0,0 +1,24 @@
inplaceadd
a = inplaceadd.A(7);
a += 5;
if (a.val != 12)
error
endif
a -= 5;
if a.val != 7:
error
endif
a *= 2;
if (a.val != 14)
error
endif
a += a;
if (a.val != 28)
error
endif

View file

@ -0,0 +1,22 @@
input
f = Foo();
if (f.foo(2) != 4)
error
endif
try
a=f.foo();
error
catch
end_try_catch
if (!strcmp(sfoo("Hello"),"Hello world"))
error
endif
try
a=sfoo();
error
catch
end_try_catch

View file

@ -0,0 +1,12 @@
langobj
x ="hello"
rx = sys.getrefcount(x)
v = identity(x)
rv = sys.getrefcount(v)
if v != x:
error
if rv - rx != 1:
error

View file

@ -0,0 +1,57 @@
li_attribute
aa = li_attribute.A(1,2,3);
if (aa.a != 1)
error
endif
aa.a = 3;
if (aa.a != 3)
error("aa.a = %i",aa.a)
endif
if (aa.b != 2)
error(aa.b)
endif
aa.b = 5;
if (aa.b != 5)
error
endif
if (aa.d != aa.b)
error
endif
if (aa.c != 3)
error
endif
pi = li_attribute.Param_i(7);
if (pi.value != 7)
error
endif
pi.value=3;
if (pi.value != 3)
error
endif
b = li_attribute.B(aa);
if (b.a.c != 3)
error
endif
myFoo = li_attribute.MyFoo;
myFoo.x = 8;
myClass = li_attribute.MyClass;
myClass.Foo = myFoo;
if (myClass.Foo.x != 8)
error
endif

View file

@ -0,0 +1,478 @@
li_boost_shared_ptr
debug = false;
function main()
if (debug)
printf("Started\n")
endif
li_boost_shared_ptr.cvar.debug_shared = debug;
# Change loop count to run for a long time to monitor memory
loopCount = 1 #5000
for i=0:loopCount,
self.runtest();
endif
if (li_boost_shared_ptr.Klass.getTotal_count() != 0)
error("Klass.total_count=", li_boost_shared_ptr.Klass.getTotal_count())
endif
wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING)
if (wrapper_count != 0)
error("shared_ptr wrapper count not zero: %i", wrapper_count)
endif
endif
if (debug)
error("Finished")
endif
endfunction
function runtest()
# simple shared_ptr usage - created in C++
k = li_boost_shared_ptr.Klass("me oh my");
val = k.getValue();
self.verifyValue("me oh my", val);
self.verifyCount(1, k);
# simple shared_ptr usage - not created in C++
k = li_boost_shared_ptr.factorycreate();
val = k.getValue();
self.verifyValue("factorycreate", val);
self.verifyCount(1, k);
# pass by shared_ptr
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.smartpointertest(k);
val = kret.getValue();
self.verifyValue("me oh my smartpointertest", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# pass by shared_ptr pointer
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.smartpointerpointertest(k);
val = kret.getValue();
self.verifyValue("me oh my smartpointerpointertest", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# pass by shared_ptr reference
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.smartpointerreftest(k);
val = kret.getValue();
self.verifyValue("me oh my smartpointerreftest", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# pass by shared_ptr pointer reference
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.smartpointerpointerreftest(k);
val = kret.getValue();
self.verifyValue("me oh my smartpointerpointerreftest", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# const pass by shared_ptr
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.constsmartpointertest(k);
val = kret.getValue();
self.verifyValue("me oh my", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# const pass by shared_ptr pointer
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.constsmartpointerpointertest(k);
val = kret.getValue();
self.verifyValue("me oh my", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# const pass by shared_ptr reference
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.constsmartpointerreftest(k);
val = kret.getValue();
self.verifyValue("me oh my", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# pass by value
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.valuetest(k);
val = kret.getValue();
self.verifyValue("me oh my valuetest", val);
self.verifyCount(1, k);
self.verifyCount(1, kret);
# pass by pointer
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.pointertest(k);
val = kret.getValue();
self.verifyValue("me oh my pointertest", val);
self.verifyCount(1, k);
self.verifyCount(1, kret);
# pass by reference
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.reftest(k);
val = kret.getValue();
self.verifyValue("me oh my reftest", val);
self.verifyCount(1, k);
self.verifyCount(1, kret);
# pass by pointer reference
k = li_boost_shared_ptr.Klass("me oh my");
kret = li_boost_shared_ptr.pointerreftest(k);
val = kret.getValue();
self.verifyValue("me oh my pointerreftest", val);
self.verifyCount(1, k);
self.verifyCount(1, kret);
# null tests
k = None;
if (li_boost_shared_ptr.smartpointertest(k) != None)
error("return was not null")
endif
if (li_boost_shared_ptr.smartpointerpointertest(k) != None)
error("return was not null")
endif
if (li_boost_shared_ptr.smartpointerreftest(k) != None)
error("return was not null")
endif
if (li_boost_shared_ptr.smartpointerpointerreftest(k) != None)
error("return was not null")
endif
if (li_boost_shared_ptr.nullsmartpointerpointertest(None) != "null pointer")
error("not null smartpointer pointer")
endif
try
li_boost_shared_ptr.valuetest(k)
error("Failed to catch null pointer")
catch
end_try_catch
if (li_boost_shared_ptr.pointertest(k) != None)
error("return was not null")
endif
try
li_boost_shared_ptr.reftest(k)
error("Failed to catch null pointer")
catch
end_try_catch
# $owner
k = li_boost_shared_ptr.pointerownertest();
val = k.getValue();
self.verifyValue("pointerownertest", val);
self.verifyCount(1, k);
k = li_boost_shared_ptr.smartpointerpointerownertest();
val = k.getValue();
self.verifyValue("smartpointerpointerownertest", val);
self.verifyCount(1, k);
# //////////////////////////////// Derived class ////////////////////////////////////////
# derived pass by shared_ptr
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.derivedsmartptrtest(k);
val = kret.getValue();
self.verifyValue("me oh my derivedsmartptrtest-Derived", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# derived pass by shared_ptr pointer
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.derivedsmartptrpointertest(k);
val = kret.getValue();
self.verifyValue("me oh my derivedsmartptrpointertest-Derived", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# derived pass by shared_ptr ref
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.derivedsmartptrreftest(k);
val = kret.getValue();
self.verifyValue("me oh my derivedsmartptrreftest-Derived", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# derived pass by shared_ptr pointer ref
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.derivedsmartptrpointerreftest(k);
val = kret.getValue();
self.verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# derived pass by pointer
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.derivedpointertest(k);
val = kret.getValue();
self.verifyValue("me oh my derivedpointertest-Derived", val);
self.verifyCount(1, k);
self.verifyCount(1, kret);
# derived pass by ref
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.derivedreftest(k);
val = kret.getValue();
self.verifyValue("me oh my derivedreftest-Derived", val);
self.verifyCount(1, k);
self.verifyCount(1, kret);
# //////////////////////////////// Derived and base class mixed ////////////////////////////////////////
# pass by shared_ptr (mixed)
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.smartpointertest(k);
val = kret.getValue();
self.verifyValue("me oh my smartpointertest-Derived", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# pass by shared_ptr pointer (mixed)
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.smartpointerpointertest(k);
val = kret.getValue();
self.verifyValue("me oh my smartpointerpointertest-Derived", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# pass by shared_ptr reference (mixed)
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.smartpointerreftest(k);
val = kret.getValue();
self.verifyValue("me oh my smartpointerreftest-Derived", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# pass by shared_ptr pointer reference (mixed)
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.smartpointerpointerreftest(k);
val = kret.getValue();
self.verifyValue("me oh my smartpointerpointerreftest-Derived", val);
self.verifyCount(2, k);
self.verifyCount(2, kret);
# pass by value (mixed)
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.valuetest(k);
val = kret.getValue();
self.verifyValue("me oh my valuetest", val); # note slicing
self.verifyCount(1, k);
self.verifyCount(1, kret);
# pass by pointer (mixed)
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.pointertest(k);
val = kret.getValue();
self.verifyValue("me oh my pointertest-Derived", val);
self.verifyCount(1, k);
self.verifyCount(1, kret);
# pass by ref (mixed)
k = li_boost_shared_ptr.KlassDerived("me oh my");
kret = li_boost_shared_ptr.reftest(k);
val = kret.getValue();
self.verifyValue("me oh my reftest-Derived", val);
self.verifyCount(1, k);
self.verifyCount(1, kret);
# //////////////////////////////// Overloading tests ////////////////////////////////////////
# Base class
k = li_boost_shared_ptr.Klass("me oh my");
self.verifyValue(li_boost_shared_ptr.overload_rawbyval(k), "rawbyval");
self.verifyValue(li_boost_shared_ptr.overload_rawbyref(k), "rawbyref");
self.verifyValue(li_boost_shared_ptr.overload_rawbyptr(k), "rawbyptr");
self.verifyValue(li_boost_shared_ptr.overload_rawbyptrref(k), "rawbyptrref");
self.verifyValue(li_boost_shared_ptr.overload_smartbyval(k), "smartbyval");
self.verifyValue(li_boost_shared_ptr.overload_smartbyref(k), "smartbyref");
self.verifyValue(li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr");
self.verifyValue(li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref");
# Derived class
k = li_boost_shared_ptr.KlassDerived("me oh my");
self.verifyValue(li_boost_shared_ptr.overload_rawbyval(k), "rawbyval");
self.verifyValue(li_boost_shared_ptr.overload_rawbyref(k), "rawbyref");
self.verifyValue(li_boost_shared_ptr.overload_rawbyptr(k), "rawbyptr");
self.verifyValue(li_boost_shared_ptr.overload_rawbyptrref(k), "rawbyptrref");
self.verifyValue(li_boost_shared_ptr.overload_smartbyval(k), "smartbyval");
self.verifyValue(li_boost_shared_ptr.overload_smartbyref(k), "smartbyref");
self.verifyValue(li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr");
self.verifyValue(li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref");
# //////////////////////////////// Member variables ////////////////////////////////////////
# smart pointer by value
m = li_boost_shared_ptr.MemberVariables();
k = li_boost_shared_ptr.Klass("smart member value");
m.SmartMemberValue = k;
val = k.getValue();
self.verifyValue("smart member value", val);
self.verifyCount(2, k);
kmember = m.SmartMemberValue;
val = kmember.getValue();
self.verifyValue("smart member value", val);
self.verifyCount(3, kmember);
self.verifyCount(3, k);
clear m;
self.verifyCount(2, kmember);
self.verifyCount(2, k);
# smart pointer by pointer
m = li_boost_shared_ptr.MemberVariables();
k = li_boost_shared_ptr.Klass("smart member pointer");
m.SmartMemberPointer = k;
val = k.getValue();
self.verifyValue("smart member pointer", val);
self.verifyCount(1, k);
kmember = m.SmartMemberPointer;
val = kmember.getValue();
self.verifyValue("smart member pointer", val);
self.verifyCount(2, kmember);
self.verifyCount(2, k);
clear m;
self.verifyCount(2, kmember);
self.verifyCount(2, k);
# smart pointer by reference
m = li_boost_shared_ptr.MemberVariables();
k = li_boost_shared_ptr.Klass("smart member reference");
m.SmartMemberReference = k;
val = k.getValue();
self.verifyValue("smart member reference", val);
self.verifyCount(2, k);
kmember = m.SmartMemberReference;
val = kmember.getValue();
self.verifyValue("smart member reference", val);
self.verifyCount(3, kmember);
self.verifyCount(3, k);
# The C++ reference refers to SmartMemberValue...
kmemberVal = m.SmartMemberValue;
val = kmember.getValue();
self.verifyValue("smart member reference", val);
self.verifyCount(4, kmemberVal);
self.verifyCount(4, kmember);
self.verifyCount(4, k);
clear m;
self.verifyCount(3, kmemberVal);
self.verifyCount(3, kmember);
self.verifyCount(3, k);
# plain by value
m = li_boost_shared_ptr.MemberVariables();
k = li_boost_shared_ptr.Klass("plain member value");
m.MemberValue = k;
val = k.getValue();
self.verifyValue("plain member value", val);
self.verifyCount(1, k);
kmember = m.MemberValue;
val = kmember.getValue();
self.verifyValue("plain member value", val);
self.verifyCount(1, kmember);
self.verifyCount(1, k);
clear m;
self.verifyCount(1, kmember);
self.verifyCount(1, k);
# plain by pointer
m = li_boost_shared_ptr.MemberVariables();
k = li_boost_shared_ptr.Klass("plain member pointer");
m.MemberPointer = k;
val = k.getValue();
self.verifyValue("plain member pointer", val);
self.verifyCount(1, k);
kmember = m.MemberPointer;
val = kmember.getValue();
self.verifyValue("plain member pointer", val);
self.verifyCount(1, kmember);
self.verifyCount(1, k);
clear m;
self.verifyCount(1, kmember);
self.verifyCount(1, k);
# plain by reference
m = li_boost_shared_ptr.MemberVariables();
k = li_boost_shared_ptr.Klass("plain member reference");
m.MemberReference = k;
val = k.getValue();
self.verifyValue("plain member reference", val);
self.verifyCount(1, k);
kmember = m.MemberReference;
val = kmember.getValue();
self.verifyValue("plain member reference", val);
self.verifyCount(1, kmember);
self.verifyCount(1, k);
clear m;
self.verifyCount(1, kmember);
self.verifyCount(1, k);
# null member variables
m = li_boost_shared_ptr.MemberVariables();
# shared_ptr by value
k = m.SmartMemberValue;
if (k != None)
error("expected null")
endif
m.SmartMemberValue = None;
k = m.SmartMemberValue;
if (k != None)
error("expected null")
endif
self.verifyCount(0, k);
# plain by value
try
m.MemberValue = None;
error("Failed to catch null pointer");
catch
end_try_catch
# templates
pid = li_boost_shared_ptr.PairIntDouble(10, 20.2)
if (pid.baseVal1 != 20 or pid.baseVal2 != 40.4)
error("Base values wrong")
endif
if (pid.val1 != 10 or pid.val2 != 20.2)
error("Derived Values wrong")
endif
endfunction
function verifyValue(expected,got)
if (expected != got)
error("verify value failed. Expected: %i, Got %i\n",expected,got)
endif
endfunction
function verifyCount(expected,k)
got = li_boost_shared_ptr.use_count(k);
if (expected != got)
error("verify value failed. Expected: %i, Got %i\n",expected,got)
endif
endfunction

View file

@ -0,0 +1,10 @@
li_carrays
d = doubleArray(10);
d(0) = 7;
d(5) = d(0) + 3;
if (d(5) + d(0) != 17)
error
endif

View file

@ -0,0 +1,17 @@
li_cmalloc
p = malloc_int();
free_int(p);
ok = 0;
try
p = calloc_int(-1);
free_int(p);
catch
ok = 1;
end_try_catch
if (ok != 1)
error
endif

View file

@ -0,0 +1,12 @@
li_cpointer
p = new_intp();
intp_assign(p,3);
if (intp_value(p) != 3)
error
endif
delete_intp(p);

View file

@ -0,0 +1,39 @@
li_cstring
if (count("ab\0ab\0ab\0", 0) != 3)
error
endif
if (!strcmp(test1(),"Hello World"))
error
endif
if (!strcmp(test2()," !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_"))
error
endif
if (!strcmp(test3("hello"),"hello-suffix"))
error(test3("hello"))
endif
if (!strcmp(test4("hello"),"hello-suffix"))
error(test4("hello"))
endif
if (!strcmp(test5(4),'xxxx'))
error
endif
if (!strcmp(test6(10),'xxxxx'))
error
endif
if (!strcmp(test7(),"Hello world!"))
error
endif
if (!strcmp(test8()," !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_"))
error
endif

View file

@ -0,0 +1,38 @@
li_cwstring
if (count("ab\0ab\0ab\0", 0) != 3)
error
endif
if (!strcmp(test1(),"Hello World"))
error
endif
if (!strcmp(test2()," !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_"))
error
endif
if (!strcmp(test3("hello"),"hello-suffix"))
error
endif
if (!strcmp(test4("hello"),"hello-suffix"))
error
endif
if (!strcmp(test5(4),'xxxx'))
error
endif
if (!strcmp(test6(10),'xxxxx'))
error
endif
if (!strcmp(test7(),"Hello world!"))
error
endif
if (!strcmp(test8()," !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_"))
error
endif

View file

@ -0,0 +1,13 @@
li_factory
circle = Geometry_create(Geometry.CIRCLE);
r = circle.radius();
if (r != 1.5)
error
endif
point = Geometry_create(Geometry.POINT);
w = point.width();
if (w != 1.0)
error
endif

View file

@ -0,0 +1,20 @@
li_implicit
b = B();
ai = A(1);
ad = A(2.0);
ab = A(b);
ai, get(ai);
ad, get(ad);
ab, get(ab);
if (get(ai) != get(1))
error("bad implicit type")
endif
if (get(ad) != get(2.0))
error("bad implicit type")
endif
if (get(ab) != get(b))
error("bad implicit type")
endif

View file

@ -0,0 +1,52 @@
li_std_carray
v3 = Vector3();
for i=0:len(v3),
v3(i) = i;
endfor
i = 0;
for d in v3,
if (d != i)
error
endif
i = i + 1;
endfor
m3 = Matrix3();
for i=0:len(m3),
v3 = m3(i);
for j=0:len(v3),
v3(j) = i + j;
endfor
endfor
i = 0;
for v3 in m3,
j = 0;
for d in v3,
if (d != i + j)
error
endif
j = j + 1;
endfor
i = i + 1
endfor
for i=0:len(m3),
for j=0:len(m3),
if (m3(i,j) != i + j)
error
endif
endfor
endfor
da = Vector3([1,2,3]);
ma = Matrix3({[1,2,3],[4,5,6],[7,8,9]});

View file

@ -0,0 +1,61 @@
li_std_map
a1 = li_std_map.A(3);
a2 = li_std_map.A(7);
p0 = li_std_map.pairii(1,2);
p1 = li_std_map.pairA(1,a1.this);
m = {};
m{1} = a1;
m{2} = a2;
pp1 = li_std_map.p_identa(p1);
mm = li_std_map.m_identa(m);
m = li_std_map.mapA();
m{1} = a1;
m{2} = a2;
pm ={};
for k in m,
pm{k} = m{k};
endfor
for k in m,
if (swig_this(pm{k}) != swig_this(m{k}))
error
endif
endfor
m = {};
m{1} = [1,2];
m["foo"] = "hello";
pm = li_std_map.pymap();
for k in m,
pm{k} = m{k};
endfor
for k in pm,
if (pm{k} != m{k})
error
endif
endfor
mii = li_std_map.mapii();
mii{1} = 1;
mii{1} = 2;
if (mii[1] != 2)
error
endif

View file

@ -0,0 +1,210 @@
%module li_std_pair
//
// activate the automatic comparison methods generation (==,!=,...)
//
%{
#include <algorithm> // for std::swap
%}
%include std_pair.i
%include std_string.i
%include std_complex.i
%inline
%{
struct A
{
int val;
A(int v = 0): val(v)
{
}
};
struct B
{
};
%}
%std_comp_methods(std::pair<std::string, int>);
namespace std {
%template(CIntPair) pair<const int, const int>;
%template() pair<double, double>;
%template(ShortPair) pair<short, short>;
%template(IntPair) pair<int, int>;
%extend pair<int, int>
{
%template(pair) pair<short,short>;
}
%template(SIPair) pair<std::string, int>;
%template(CIPair) pair<std::complex<double>, int>;
%template(SIIPair) pair<std::pair<std::string, int>, int>;
%template(AIntPair) pair<A, int>;
%template(CCIntPair) pair<const A, const pair<int, int> >;
%template(ABPair) pair<A, B>;
%template(IntAPair) pair<int, A>;
%template(pairP1) pair<int, A*>;
%template(pairP2) pair<A*, int>;
%template(pairP3) pair<A*, A*>;
%template(pairP4) pair<int, int*>;
%template(pairP5) pair<int*, int>;
%template(pairP6) pair<int*, int*>;
}
%std_comp_methods(std::pair<std::pair<std::string, int>, int>);
%apply std::pair<int,int> *INOUT {std::pair<int,int> *INOUT2};
%inline %{
/* Test the "out" typemap for pair<T, U> */
std::pair<int, int> makeIntPair(int a, int b) {
return std::make_pair(a, b);
}
/**
* There is no "out" typemap for a pointer to a pair, so
* this should return a wrapped instance of a std::pair
* instead of the native "array" type for the target language.
*/
std::pair<int, int> * makeIntPairPtr(int a, int b) {
static std::pair<int, int> p = std::make_pair(a, b);
return &p;
}
/**
* There is no "out" typemap for a non-const reference to a pair, so
* this should return a wrapped instance of a std::pair instead of
* the native "array" type for the target language.
*/
std::pair<int, int>& makeIntPairRef(int a, int b) {
static std::pair<int, int> p = std::make_pair(a, b);
return p;
}
/**
* There is no "out" typemap for a const reference to a pair, so
* this should return a wrapped instance of a std::pair
* instead of the native "array" type for the target language.
*/
const std::pair<int, int> & makeIntPairConstRef(int a, int b) {
static std::pair<int, int> p = std::make_pair(a, b);
return p;
}
/* Test the "in" typemap for pair<T, U> */
int product1(std::pair<int, int> p) {
return p.first*p.second;
}
/* Test the "in" typemap for const pair<T, U>& */
int product2(const std::pair<int, int>& p) {
return p.first*p.second;
}
std::pair<int, int>
p_ident(std::pair<int, int> p, const std::pair<int, int>& q) {
return p;
}
std::pair<int, A*>
p_identa(const std::pair<int, A*>& p) {
return p;
}
void
d_inout(double *INOUT) {
*INOUT += *INOUT;
}
void
d_inout(int *INOUT) {
*INOUT += *INOUT;
}
int
d_inout2(double *INOUT) {
*INOUT += *INOUT;
return 1;
}
void
p_inout(std::pair<int, int> *INOUT) {
std::swap(INOUT->first, INOUT->second);
}
int
p_inout2(std::pair<int, int> *INOUT) {
std::swap(INOUT->first, INOUT->second);
return 1;
}
void
p_inout3(std::pair<int,int> *INOUT, std::pair<int,int> *INOUT2) {
std::swap(*INOUT, *INOUT2);
}
void
p_inoutd(std::pair<double, double> *INOUT) {
std::swap(INOUT->first, INOUT->second);
}
std::string
s_ident(const std::string& s) {
return s;
}
#if 0
std::pair<char, char>
p_ident(std::pair<char, char> p, const std::pair<char, char>& q) {
return p;
}
/* Test the "in" typemap for const pair<T, U>* */
std::pair<A, B>
p_ident(std::pair<A, B> p, const std::pair<A, B>& q) {
return q;
}
/* Test the "in" typemap for const pair<T, U>* */
std::pair<int, A>
p_ident(std::pair<int, A> p, const std::pair<int, A>& q) {
return p;
}
std::pair<int, int>
p_ident(std::pair<int, int> p, const std::pair<A, int>& q) {
return p;
}
std::pair<int, int>
p_ident(std::pair<int, int> p, const std::pair<A, B>& q) {
return p;
}
#endif
%}
namespace std
{
%template(paircA1) pair<const int, A*>;
%template(paircA2) pair<const int, const A*>;
%template(pairiiA) pair<int,pair<int, A*> >;
}

View file

@ -0,0 +1,69 @@
li_std_pair
p = {1,2};
p1 = li_std_pair.p_inout(p);
assert(all(cell2mat(p1)==[2,1]));
p2 = li_std_pair.p_inoutd(p1);
assert(all(cell2mat(p2)==[1,2]));
d1 = li_std_pair.d_inout(2);
assert(d1==4);
[i,d2] = li_std_pair.d_inout2(2);
assert(all([i,d2]==[1,4]));
[i,p] = li_std_pair.p_inout2(p);
assert(i==1&&all([cell2mat(p)]==[2,1]));
[p3,p4] = li_std_pair.p_inout3(p1,p1);
assert(all(cell2mat(p3)==[2,1]));
assert(all(cell2mat(p4)==[2,1]));
psi = li_std_pair.SIPair("hello",1);
assert(psi=={"hello",1});
pci = li_std_pair.CIPair(complex(1,2),1);
assert(pci.first==complex(1,2)&&pci.second==1);
psi = li_std_pair.SIPair("hi",1);
assert(psi.first=="hi"&&psi.second==1);
psii = li_std_pair.SIIPair(psi,1);
assert(psii.first.first=="hi");
assert(psii.first.second==1);
assert(psii.second==1);
a = li_std_pair.A();
b = li_std_pair.B();
pab = li_std_pair.ABPair(a,b);
pab.first = a;
pab.first.val = 2;
assert(pab.first.val == 2);
pci = li_std_pair.CIntPair(1,0);
assert(pci.first==1&&pci.second==0);
a = li_std_pair.A(5);
p1 = li_std_pair.pairP1(1,a);
p2 = li_std_pair.pairP2(a,1);
p3 = li_std_pair.pairP3(a,a);
assert(a.val == li_std_pair.p_identa(p1){2}.val);
p = li_std_pair.IntPair(1,10);
assert(p.first==1&&p.second==10);
p.first = 1;
assert(p.first==1);
p = li_std_pair.paircA1(1,a);
assert(p.first==1);
assert(swig_this(p.second)==swig_this(a));
p = li_std_pair.paircA2(1,a);
assert(p.first==1);
assert(swig_this(p.second)==swig_this(a));
#pp = li_std_pair.pairiiA(1,p); # conversion pb re const of pairA1/A2
pp = li_std_pair.pairiiA(1,{1,A()});

View file

@ -0,0 +1,96 @@
li_std_set
s = set_string()
s.append("a")
s.append("b")
s.append("c")
sum = ""
for i in s:
sum = sum + i
if (sum != "abc")
error
i = s.__iter__()
if i.next() != "a":
error
if i.next() != "b":
error
if i.next() != "c":
error
b = s.begin()
e = s.end()
sum = ""
while (b != e):
sum = sum + b.next()
if sum != "abc":
error
b = s.rbegin()
e = s.rend()
sum = ""
while (b != e):
sum = sum + b.next()
if sum != "cba":
error
si = set_int()
si.append(1)
si.append(2)
si.append(3)
i = si.__iter__()
if i.next() != 1:
error
if i.next() != 2:
error
if i.next() != 3:
error
i = s.begin()
i.next()
s.erase(i)
b = s.begin()
e = s.end()
sum = ""
while (b != e):
sum = sum + b.next()
if sum != "ac":
error
b = s.begin()
e = s.end()
if e - b != 2:
error
m = b + 1
if m.value() != "c":
error
s = pyset()
s.insert((1,2))
s.insert(1)
s.insert("hello")
sum = ()
for i in s:
sum = sum + (i,)
if sum != (1, 'hello', (1, 2)):
error

View file

@ -0,0 +1,13 @@
li_std_stream
a = A();
o = ostringstream();
o << a << " " << 2345 << " " << 1.435;
if (o.str() != "A class 2345 1.435")
error
endif

View file

@ -0,0 +1,162 @@
li_std_string
x="hello";
if (li_std_string.test_ccvalue(x) != x)
error("bad string mapping")
endif
if (li_std_string.test_cvalue(x) != x)
error("bad string mapping")
endif
if (li_std_string.test_value(x) != x)
error("bad string mapping: %s, %s", x, li_std_string.test_value(x))
endif
if (li_std_string.test_const_reference(x) != x)
error("bad string mapping")
endif
s = li_std_string.string("he");
#s += "ll"
#s.append('o')
s = s + "llo";
if (s != x)
error("bad string mapping: %s, %s", s, x);
endif
if (s[1:4] != x[1:4])
error("bad string mapping")
endif
if (li_std_string.test_value(s) != x)
error("bad string mapping")
endif
if (li_std_string.test_const_reference(s) != x)
error("bad string mapping")
endif
a = li_std_string.A(s);
if (li_std_string.test_value(a) != x)
error("bad string mapping")
endif
if (li_std_string.test_const_reference(a) != x)
error("bad string mapping")
endif
b = li_std_string.string(" world");
s = a + b;
if (a + b != "hello world")
error("bad string mapping: %s", a + b)
endif
if (a + " world" != "hello world")
error("bad string mapping")
endif
if ("hello" + b != "hello world")
error("bad string mapping")
endif
c = ("hello" + b)
if (c.find_last_of("l") != 9)
error("bad string mapping")
endif
s = "hello world";
b = li_std_string.B("hi");
b.name = li_std_string.string("hello");
if (b.name != "hello")
error("bad string mapping")
endif
b.a = li_std_string.A("hello");
if (b.a != "hello")
error("bad string mapping")
endif
if (li_std_string.test_value_basic1(x) != x)
error("bad string mapping")
endif
if (li_std_string.test_value_basic2(x) != x)
error("bad string mapping")
endif
if (li_std_string.test_value_basic3(x) != x)
error("bad string mapping")
endif
# Global variables
s = "initial string";
if (li_std_string.cvar.GlobalString2 != "global string 2")
error("GlobalString2 test 1")
endif
li_std_string.cvar.GlobalString2 = s;
if (li_std_string.cvar.GlobalString2 != s)
error("GlobalString2 test 2")
endif
if (li_std_string.cvar.ConstGlobalString != "const global string")
error("ConstGlobalString test")
endif
# Member variables
myStructure = li_std_string.Structure();
if (myStructure.MemberString2 != "member string 2")
error("MemberString2 test 1")
endif
myStructure.MemberString2 = s;
if (myStructure.MemberString2 != s)
error("MemberString2 test 2")
endif
if (myStructure.ConstMemberString != "const member string")
error("ConstMemberString test")
endif
if (li_std_string.cvar.Structure_StaticMemberString2 != "static member string 2")
error("StaticMemberString2 test 1")
endif
li_std_string.cvar.Structure_StaticMemberString2 = s;
if (li_std_string.cvar.Structure_StaticMemberString2 != s)
error("StaticMemberString2 test 2")
endif
if (li_std_string.cvar.Structure_ConstStaticMemberString != "const static member string")
error("ConstStaticMemberString test")
endif
if (li_std_string.test_reference_input("hello") != "hello")
error
endif
s = li_std_string.test_reference_inout("hello");
if (s != "hellohello")
error
endif
if (li_std_string.empty() != "")
error
endif
if (li_std_string.c_empty() != "")
error
endif
if (li_std_string.c_null() != None)
error
endif

View file

@ -0,0 +1,160 @@
li_std_vector
iv = IntVector(4);
for i=0:4,
iv(i) = i;
endfor
x = average(iv);
y = average([1,2,3,4]);
a = half([10,10.5,11,11.5]);
dv = DoubleVector(10);
for i=0:10,
dv(i) = i/2.0;
endfor
halve_in_place(dv);
bv = BoolVector(4);
bv(0)= 1;
bv(1)= 0;
bv(2)= 4;
bv(3)= 0;
if (bv(0) != bv(2))
error("bad std::vector<bool> mapping")
endif
b = B(5);
va = VecA([b,None,b,b]);
if (va(0).f(1) != 6)
error("bad std::vector<A*> mapping")
endif
if (vecAptr(va) != 6)
error("bad std::vector<A*> mapping")
endif
b.val = 7;
if (va(3).f(1) != 8)
error("bad std::vector<A*> mapping")
endif
ip = PtrInt();
ap = new_ArrInt(10);
ArrInt_setitem(ip,0,123);
ArrInt_setitem(ap,2,123);
vi = IntPtrVector((ip,ap,None));
if (ArrInt_getitem(vi[0],0) != ArrInt_getitem(vi[1],2))
error("bad std::vector<int*> mapping")
endif
delete_ArrInt(ap);
a = halfs([10,8,4,3]);
v = IntVector();
v(0:2) = [1,2];
if (v(0) != 1 || v[1] != 2)
error("bad setslice")
endif
if (v(0:-1)(0) != 1)
error("bad getslice")
endif
if (v(0:-2).size() != 0)
error("bad getslice")
v(0:1) = [2];
if (v(0) != 2)
error("bad setslice")
endif
v(1:) = [3];
if (v(1) != 3)
error("bad setslice")
endif
v(2:) = [3]
if (v(2) != 3)
error("bad setslice")
endif
if (v(0:)(0) != v(0))
error("bad getslice")
endif
v.erase(:)
if (v.size() != 0)
error("bad getslice")
endif
v.erase(:)
if (v.size() != 0)
error("bad getslice")
endif
v = vecStr({"hello ", "world"});
if (v(0) != 'hello world')
error,"bad std::string+std::vector"
endif
pv = pyvector({1, "hello", (1,2)});
if (pv(1) != "hello")
error
endif
iv = IntVector(5);
for i=0:5,
iv(i) = i
endif
iv(1:3) = [];
if (iv(1) != 3)
error
endif
# Overloading checks
if (overloaded1(iv) != "vector<int>")
error
endif
if (overloaded1(dv) != "vector<double>")
error
endif
if (overloaded2(iv) != "vector<int>")
error
endif
if (overloaded2(dv) != "vector<double>")
error
endif
if (overloaded3(iv) != "vector<int> *")
error
endif
if (overloaded3(None) != "vector<int> *")
error
endif
if (overloaded3(100) != "int")
error
endif

View file

@ -0,0 +1,14 @@
li_std_wstream
a = A();
o = wostringstream();
o << a << u" " << 2345 << u" " << 1.435 << wends;
if (o.str() != "A class 2345 1.435\0")
error
endif

View file

@ -0,0 +1,90 @@
li_std_wstring
x="h";
if (li_std_wstring.test_wcvalue(x) != x)
error("bad string mapping")
endif
x="hello";
if (li_std_wstring.test_ccvalue(x) != x)
error("bad string mapping")
endif
if (li_std_wstring.test_cvalue(x) != x)
error("bad string mapping")
endif
if (li_std_wstring.test_value(x) != x)
error("bad string mapping")
endif
if (li_std_wstring.test_const_reference(x) != x)
error("bad string mapping")
endif
s = li_std_wstring.wstring("he");
s = s + "llo";
if (s != x)
error("bad string mapping")
endif
if (s(1:4) != x(1:4))
error("bad string mapping")
endif
if (li_std_wstring.test_value(s) != x)
error("bad string mapping")
endif
if (li_std_wstring.test_const_reference(s) != x)
error("bad string mapping")
endif
a = li_std_wstring.A(s);
if (li_std_wstring.test_value(a) != x)
error("bad string mapping")
endif
if (li_std_wstring.test_const_reference(a) != x)
error("bad string mapping")
endif
b = li_std_wstring.wstring(" world");
if (a + b != "hello world")
error("bad string mapping")
endif
if (a + " world" != "hello world")
error("bad string mapping")
endif
if ("hello" + b != "hello world")
error("bad string mapping")
endif
c = "hello" + b;
if (c.find_last_of("l") != 9)
error("bad string mapping")
endif
s = "hello world";
b = li_std_wstring.B("hi");
b.name = li_std_wstring.wstring("hello");
if (b.name != "hello")
error("bad string mapping")
endif
b.a = li_std_wstring.A("hello");
if (b.a != "hello")
error("bad string mapping")
endif

View file

@ -0,0 +1,45 @@
# Example using pointers to member functions
member_pointer
function check(what,expected,actual)
if (expected != actual)
error ("Failed: %s, Expected: %f, Actual: %f",what,expected,actual);
endif
end
# Get the pointers
area_pt = areapt;
perim_pt = perimeterpt;
# Create some objects
s = Square(10);
# Do some calculations
check ("Square area ", 100.0, do_op(s,area_pt));
check ("Square perim", 40.0, do_op(s,perim_pt));
memberPtr = cvar.areavar;
memberPtr = cvar.perimetervar;
# Try the variables
check ("Square area ", 100.0, do_op(s,cvar.areavar));
check ("Square perim", 40.0, do_op(s,cvar.perimetervar));
# Modify one of the variables
cvar.areavar = perim_pt;
check ("Square perimeter", 40.0, do_op(s,cvar.areavar));
# Try the constants
memberPtr = AREAPT;
memberPtr = PERIMPT;
memberPtr = NULLPT;
check ("Square area ", 100.0, do_op(s,AREAPT));
check ("Square perim", 40.0, do_op(s,PERIMPT));

View file

@ -0,0 +1,86 @@
minherit
a = minherit.Foo();
b = minherit.Bar();
c = minherit.FooBar();
d = minherit.Spam();
if (a.xget() != 1)
error("Bad attribute value")
endif
if (b.yget() != 2)
error("Bad attribute value")
endif
if (c.xget() != 1 || c.yget() != 2 || c.zget() != 3)
error("Bad attribute value")
endif
if (d.xget() != 1 || d.yget() != 2 || d.zget() != 3 || d.wget() != 4)
error("Bad attribute value")
endif
if (minherit.xget(a) != 1)
error("Bad attribute value %d",minherit.xget(a))
endif
if (minherit.yget(b) != 2)
error("Bad attribute value %d",minherit.yget(b))
endif
if (minherit.xget(c) != 1 || minherit.yget(c) != 2 || minherit.zget(c) != 3)
error("Bad attribute value %d %d %d",minherit.xget(c),minherit.yget(c),minherit.zget(c))
endif
if (minherit.xget(d) != 1 || minherit.yget(d) != 2 || minherit.zget(d) != 3 || minherit.wget(d) != 4)
error("Bad attribute value %d %d %d %d",minherit.xget(d),minherit.yget(d),minherit.zget(d),minherit.wget(d))
endif
# Cleanse all of the pointers and see what happens
aa = minherit.toFooPtr(a);
bb = minherit.toBarPtr(b);
cc = minherit.toFooBarPtr(c);
dd = minherit.toSpamPtr(d);
if (aa.xget() != 1)
error("Bad attribute value");
endif
if (bb.yget() != 2)
error("Bad attribute value");
endif
if (cc.xget() != 1 || cc.yget() != 2 || cc.zget() != 3)
error("Bad attribute value")
endif
if (dd.xget() != 1 || dd.yget() != 2 || dd.zget() != 3 || dd.wget() != 4)
error("Bad attribute value")
endif
if (minherit.xget(aa) != 1)
error("Bad attribute value %d",minherit.xget(aa));
endif
if (minherit.yget(bb) != 2)
error("Bad attribute value %d",minherit.yget(bb));
endif
if (minherit.xget(cc) != 1 || minherit.yget(cc) != 2 || minherit.zget(cc) != 3)
error("Bad attribute value %d %d %d",minherit.xget(cc),minherit.yget(cc),minherit.zget(cc));
endif
if (minherit.xget(dd) != 1 || minherit.yget(dd) != 2 || minherit.zget(dd) != 3 || minherit.wget(dd) != 4)
error("Bad attribute value %d %d %d %d",minherit.xget(dd),minherit.yget(dd),minherit.zget(dd),minherit.wget(dd))
endif

View file

@ -0,0 +1,7 @@
mod_a
mod_b
c = mod_b.C();
d = mod_b.D();
d.DoSomething(c);

View file

@ -0,0 +1,24 @@
multi_import_a
multi_import_b
x = multi_import_b.XXX();
if (x.testx() != 0)
error
endif
y = multi_import_b.YYY();
if (y.testx() != 0)
error
endif
if (y.testy() != 1)
error
endif
z = multi_import_a.ZZZ();
if (z.testx() != 0)
error
endif
if (z.testz() != 2)
error
endif

View file

@ -0,0 +1,39 @@
namespace_class
try
p = Private1();
ok = 1;
catch
ok = 0;
end_try_catch
if (ok)
error("Private1 is private")
endif
try
p = Private2();
ok = 1;
catch
ok = 0;
end_try_catch
if (ok)
error("Private2 is private")
endif
EulerT3D.toFrame(1,1,1);
b = BooT_i();
b = BooT_H();
f = FooT_i();
f.quack(1);
f = FooT_d();
f.moo(1);
f = FooT_H();
f.foo(Hi);

View file

@ -0,0 +1,106 @@
namespace_typemap
if (!strcmp(stest1("hello"),"hello"))
error
endif
if (!strcmp(stest2("hello"),"hello"))
error
endif
if (!strcmp(stest3("hello"),"hello"))
error
endif
if (!strcmp(stest4("hello"),"hello"))
error
endif
if (!strcmp(stest5("hello"),"hello"))
error
endif
if (!strcmp(stest6("hello"),"hello"))
error
endif
if (!strcmp(stest7("hello"),"hello"))
error
endif
if (!strcmp(stest8("hello"),"hello"))
error
endif
if (!strcmp(stest9("hello"),"hello"))
error
endif
if (!strcmp(stest10("hello"),"hello"))
error
endif
if (!strcmp(stest11("hello"),"hello"))
error
endif
if (!strcmp(stest12("hello"),"hello"))
error
endif
c = complex(2,3)
r = c.real
if (ctest1(c) != r)
error
endif
if (ctest2(c) != r)
error
endif
if (ctest3(c) != r)
error
endif
if (ctest4(c) != r)
error
endif
if (ctest5(c) != r)
error
endif
if (ctest6(c) != r)
error
endif
if (ctest7(c) != r)
error
endif
if (ctest8(c) != r)
error
endif
if (ctest9(c) != r)
error
endif
if (ctest10(c) != r)
error
endif
if (ctest11(c) != r)
error
endif
if (ctest12(c) != r)
error
endif
try
ttest1(-14)
error
catch
end_try_catch

View file

@ -0,0 +1,4 @@
namespace_virtual_method
x = namespace_virtual_method.Spam();

View file

@ -0,0 +1,14 @@
naturalvar
f = Foo();
b = Bar();
b.f = f;
cvar.s = "hello";
b.s = "hello";
if (b.s != cvar.s)
error
endif

View file

@ -0,0 +1,36 @@
nondynamic
aa = nondynamic.A();
aa.a = 1;
aa.b = 2;
try
aa.c = 2;
err = 0;
catch
err = 1;
end_try_catch
if (!err)
error("A is not static")
endif
B=@() subclass(nondynamic.A(),'c',4);
bb = B();
bb.c = 3;
try
bb.d = 2
err = 0
catch
err = 1
end_try_catch
if (!err)
error("B is not static")
endif
cc = nondynamic.C();
cc.d = 3;

View file

@ -0,0 +1,58 @@
overload_complicated
pInt = None;
# Check the correct constructors are available
p = Pop(pInt);
p = Pop(pInt, 0);
# Check overloaded in const only and pointers/references which target languages cannot disambiguate
if (p.hip(0) != 701)
error("Test 1 failed")
endif
if (p.hip(pInt) != 702)
error("Test 2 failed")
endif
# Reverse the order for the above
if (p.hop(pInt) != 805)
error("Test 3 failed")
endif
if (p.hop(0) != 801)
error("Test 4 failed")
endif
# Few more variations and order shuffled
if (p.pop(0) != 901)
error("Test 5 failed")
endif
if (p.pop(pInt) != 902)
error("Test 6 failed")
endif
if (p.pop() != 905)
error("Test 7 failed")
endif
# Overload on const only
if (p.bop(pInt) != 1001)
error("Test 8 failed")
endif
if (p.bip(pInt) != 2001)
error("Test 9 failed")
endif
# Globals
if (muzak(0) != 3001)
error("Test 10 failed")
endif
if (muzak(pInt) != 3002)
error("Test 11 failed")
endif

View file

@ -0,0 +1,3 @@
overload_copy
f = Foo();
g = Foo(f);

View file

@ -0,0 +1,19 @@
overload_extend
f = overload_extend.Foo();
if (f.test() != 0)
error
endif
if (f.test(3) != 1)
error
endif
if (f.test("hello") != 2)
error
endif
if (f.test(3,2) != 5)
error
endif
if (f.test(3.1)-.1 != 1003) # :)
error
endif

View file

@ -0,0 +1,30 @@
overload_extendc
f = overload_extendc.Foo();
if (f.test(3) != 1)
error
endif
if (f.test("hello") != 2)
error
endif
if (f.test(3.5,2.5) != 3)
error
endif
if (f.test("hello",20) != 1020)
error
endif
if (f.test("hello",20,100) != 120)
error
endif
# C default args
if (f.test(f) != 30)
error
endif
if (f.test(f,100) != 120)
error
endif
if (f.test(f,100,200) != 300)
error
endif

View file

@ -0,0 +1,8 @@
overload_rename
f = overload_rename.Foo(1);
f = overload_rename.Foo(1,1);
f = overload_rename.Foo_int(1,1);
f = overload_rename.Foo_int(1,1,1);

View file

@ -0,0 +1,229 @@
overload_simple_cast
Ai=@(x) subclass('x',x,'__int',@(self) self.x);
Ad=@(x) subclass('x',x,'__float',@(self) self.x);
ai = Ai(4);
ad = Ad(5.0);
add = Ad(5.5);
try
fint(add);
good = 0;
catch
good = 1;
end_try_catch
if (!good)
error("fint(int)")
endif
if (!strcmp(fint(ad),"fint:int"))
error("fint(int)")
endif
if (!strcmp(fdouble(ad),"fdouble:double"))
error("fdouble(double)")
endif
if (!strcmp(fint(ai),"fint:int"))
error("fint(int)")
endif
if (!strcmp(fint(5.0),"fint:int"))
error("fint(int)")
endif
if (!strcmp(fint(3),"fint:int"))
error("fint(int)")
endif
if (!strcmp(fint(3.0),"fint:int"))
error("fint(int)")
endif
if (!strcmp(fdouble(ad),"fdouble:double"))
error("fdouble(double)")
endif
if (!strcmp(fdouble(3),f"fdouble:double"))
error("fdouble(double)")
endif
if (!strcmp(fdouble(3.0),"fdouble:double"))
error("fdouble(double)")
endif
if (!strcmp(fid(3,3.0),"fid:intdouble"))
error("fid:intdouble")
endif
if (!strcmp(fid(3.0,3),"fid:doubleint"))
error("fid:doubleint")
endif
if (!strcmp(fid(ad,ai),"fid:doubleint"))
error("fid:doubleint")
endif
if (!strcmp(fid(ai,ad),"fid:intdouble"))
error("fid:intdouble")
endif
if (!strcmp(foo(3),"foo:int"))
error("foo(int)")
endif
if (!strcmp(foo(3.0),"foo:double"))
error("foo(double)")
endif
if (!strcmp(foo("hello"),"foo:char *"))
error("foo(char *)")
endif
f = Foo();
b = Bar();
if (!strcmp(foo(f),"foo:Foo *"))
error("foo(Foo *)")
endif
if (!strcmp(foo(b),"foo:Bar *"))
error("foo(Bar *)")
endif
v = malloc_void(32);
if (!strcmp(foo(v),"foo:void *"))
error("foo(void *)")
endif
s = Spam();
if (!strcmp(s.foo(3),"foo:int"))
error("Spam::foo(int)")
endif
if (!strcmp(s.foo(3.0),"foo:double"))
error("Spam::foo(double)")
endif
if (!strcmp(s.foo("hello"),"foo:char *"))
error("Spam::foo(char *)")
endif
if (!strcmp(s.foo(f),"foo:Foo *"))
error("Spam::foo(Foo *)")
endif
if (!strcmp(s.foo(b),"foo:Bar *"))
error("Spam::foo(Bar *)")
endif
if (!strcmp(s.foo(v),"foo:void *"))
error("Spam::foo(void *)")
endif
if (!strcmp(Spam_bar(3),"bar:int"))
error("Spam::bar(int)")
endif
if (!strcmp(Spam_bar(3.0),"bar:double"))
error("Spam::bar(double)")
endif
if (!strcmp(Spam_bar("hello"),"bar:char *"))
error("Spam::bar(char *)")
endif
if (!strcmp(Spam_bar(f),"bar:Foo *"))
error("Spam::bar(Foo *)")
endif
if (!strcmp(Spam_bar(b),"bar:Bar *"))
error("Spam::bar(Bar *)")
endif
if (!strcmp(Spam_bar(v),"bar:void *"))
error("Spam::bar(void *)")
endif
# Test constructors
s = Spam();
if (!strcmp(s.type,"none"))
error("Spam()")
endif
s = Spam(3);
if (!strcmp(s.type,"int"))
error("Spam(int)")
endif
s = Spam(3.4);
if (!strcmp(s.type,"double"))
error("Spam(double)")
endif
s = Spam("hello");
if (!strcmp(s.type,"char *"))
error("Spam(char *)")
endif
s = Spam(f);
if (!strcmp(s.type,"Foo *"))
error("Spam(Foo *)")
endif
s = Spam(b);
if (!strcmp(s.type,"Bar *"))
error("Spam(Bar *)")
endif
s = Spam(v);
if (!strcmp(s.type,"void *"))
error("Spam(void *)")
endif
# unsigned long long
ullmax = 9223372036854775807; #0xffffffffffffffff
ullmaxd = 9007199254740992.0;
ullmin = 0;
ullmind = 0.0;
if (ull(ullmin) != ullmin)
error("ull(ullmin)")
endif
if (ull(ullmax) != ullmax)
error("ull(ullmax)")
endif
if (ull(ullmind) != ullmind)
error("ull(ullmind)")
endif
if (ull(ullmaxd) != ullmaxd)
error("ull(ullmaxd)")
endif
# long long
llmax = 9223372036854775807; #0x7fffffffffffffff
llmin = -9223372036854775808;
# these are near the largest floats we can still convert into long long
llmaxd = 9007199254740992.0;
llmind = -9007199254740992.0;
if (ll(llmin) != llmin)
error("ll(llmin)")
endif
if (ll(llmax) != llmax)
error("ll(llmax)")
endif
if (ll(llmind) != llmind)
error("ll(llmind)")
endif
if (ll(llmaxd) != llmaxd)
error("ll(llmaxd)")
endif
free_void(v);

View file

@ -0,0 +1,125 @@
overload_simple
# unless explicitly casted via {{u}int{8,16,32,64},double,single},
# octave will take numeric literals as doubles.
if (!strcmp(foo(3),"foo:int"))
error("foo(int)")
endif
if (!strcmp(foo(3.1),"foo:double"))
error("foo(double)")
endif
if (!strcmp(foo("hello"),"foo:char *"))
error("foo(char *)")
endif
f = Foo();
b = Bar();
if (!strcmp(foo(f),"foo:Foo *"))
error("foo(Foo *)")
endif
if (!strcmp(foo(b),"foo:Bar *"))
error("foo(Bar *)")
endif
v = malloc_void(32);
if (!strcmp(foo(v),"foo:void *"))
error("foo(void *)")
endif
s = Spam();
if (!strcmp(s.foo(3),"foo:int"))
error("Spam::foo(int)")
endif
if (!strcmp(s.foo(3.1),"foo:double"))
error("Spam::foo(double)")
endif
if (!strcmp(s.foo("hello"),"foo:char *"))
error("Spam::foo(char *)")
endif
if (!strcmp(s.foo(f),"foo:Foo *"))
error("Spam::foo(Foo *)")
endif
if (!strcmp(s.foo(b),"foo:Bar *"))
error("Spam::foo(Bar *)")
endif
if (!strcmp(s.foo(v),"foo:void *"))
error("Spam::foo(void *)")
endif
if (!strcmp(Spam_bar(3),"bar:int"))
error("Spam::bar(int)")
endif
if (!strcmp(Spam_bar(3.1),"bar:double"))
error("Spam::bar(double)")
endif
if (!strcmp(Spam_bar("hello"),"bar:char *"))
error("Spam::bar(char *)")
endif
if (!strcmp(Spam_bar(f),"bar:Foo *"))
error("Spam::bar(Foo *)")
endif
if (!strcmp(Spam_bar(b),"bar:Bar *"))
error("Spam::bar(Bar *)")
endif
if (!strcmp(Spam_bar(v),"bar:void *"))
error("Spam::bar(void *)")
endif
# Test constructors
s = Spam();
if (!strcmp(s.type,"none"))
error("Spam()")
endif
s = Spam(3);
if (!strcmp(s.type,"int"))
error("Spam(int)")
endif
s = Spam(3.4);
if (!strcmp(s.type,"double"))
error("Spam(double)")
endif
s = Spam("hello");
if (!strcmp(s.type,"char *"))
error("Spam(char *)")
endif
s = Spam(f);
if (!strcmp(s.type,"Foo *"))
error("Spam(Foo *)")
endif
s = Spam(b);
if (!strcmp(s.type,"Bar *"))
error("Spam(Bar *)")
endif
s = Spam(v);
if (!strcmp(s.type,"void *"))
error("Spam(void *)")
endif
free_void(v);
a = ClassA();
b = a.method1(1);

View file

@ -0,0 +1,13 @@
overload_subtype
f = Foo();
b = Bar();
if (spam(f) != 1)
error("foo")
endif
if (spam(b) != 2)
error("bar")
endif

View file

@ -0,0 +1,188 @@
overload_template_fast
# unless explicitly casted via {{u}int{8,16,32,64},double,single},
# octave will take numeric literals as doubles.
f = foo();
a = max(3,4);
b = max(3.4,5.2);
# mix 1
if (mix1("hi") != 101)
error("mix1(const char*)")
endif
if (mix1(1.1, 1.1) != 102)
error("mix1(double, const double &)")
endif
if (mix1(1.1) != 103)
error("mix1(double)")
endif
# mix 2
if (mix2("hi") != 101)
error("mix2(const char*)")
endif
if (mix2(1.1, 1.1) != 102)
error("mix2(double, const double &)")
endif
if (mix2(1.1) != 103)
error("mix2(double)")
endif
# mix 3
if (mix3("hi") != 101)
error("mix3(const char*)")
endif
if (mix3(1.1, 1.1) != 102)
error("mix3(double, const double &)")
endif
if (mix3(1.1) != 103)
error("mix3(double)")
endif
# Combination 1
if (overtparams1(100) != 10)
error("overtparams1(int)")
endif
if (overtparams1(100.1, 100) != 20)
error("overtparams1(double, int)")
endif
# Combination 2
if (overtparams2(100.1, 100) != 40)
error("overtparams2(double, int)")
endif
# Combination 3
if (overloaded() != 60)
error("overloaded()")
endif
if (overloaded(100.1, 100) != 70)
error("overloaded(double, int)")
endif
# Combination 4
if (overloadedagain("hello") != 80)
error("overloadedagain(const char *)")
endif
if (overloadedagain() != 90)
error("overloadedagain(double)")
endif
# specializations
if (specialization(10) != 202)
error("specialization(int)")
endif
if (specialization(10.1) != 203)
error("specialization(double)")
endif
if (specialization(10, 10) != 204)
error("specialization(int, int)")
endif
if (specialization(10.1, 10.1) != 205)
error("specialization(double, double)")
endif
if (specialization("hi", "hi") != 201)
error("specialization(const char *, const char *)")
endif
# simple specialization
xyz();
xyz_int();
xyz_double();
# a bit of everything
if (overload("hi") != 0)
error("overload()")
endif
if (overload(1) != 10)
error("overload(int t)")
endif
if (overload(1, 1) != 20)
error("overload(int t, const int &)")
endif
if (overload(1, "hello") != 30)
error("overload(int t, const char *)")
endif
k = Klass();
if (overload(k) != 10)
error("overload(Klass t)")
endif
if (overload(k, k) != 20)
error("overload(Klass t, const Klass &)")
endif
if (overload(k, "hello") != 30)
error("overload(Klass t, const char *)")
endif
if (overload(10.1, "hi") != 40)
error("overload(double t, const char *)")
endif
if (overload() != 50)
error("overload(const char *)")
endif
# everything put in a namespace
if (nsoverload("hi") != 1000)
error("nsoverload()")
endif
if (nsoverload(1) != 1010)
error("nsoverload(int t)")
endif
if (nsoverload(1, 1) != 1020)
error("nsoverload(int t, const int &)")
endif
if (nsoverload(1, "hello") != 1030)
error("nsoverload(int t, const char *)")
endif
if (nsoverload(k) != 1010)
error("nsoverload(Klass t)")
endif
if (nsoverload(k, k) != 1020)
error("nsoverload(Klass t, const Klass &)")
endif
if (nsoverload(k, "hello") != 1030)
error("nsoverload(Klass t, const char *)")
endif
if (nsoverload(10.1, "hi") != 1040)
error("nsoverload(double t, const char *)")
endif
if (nsoverload() != 1050)
error("nsoverload(const char *)")
endif
A.foo(1);
b = B();
b.foo(1);

View file

@ -0,0 +1,184 @@
overload_template
f = foo();
a = max(3,4);
b = max(3.4,5.2);
# mix 1
if (mix1("hi") != 101)
error("mix1(const char*)")
endif
if (mix1(1.0, 1.0) != 102)
error("mix1(double, const double &)")
endif
if (mix1(1.0) != 103)
error("mix1(double)")
endif
# mix 2
if (mix2("hi") != 101)
error("mix2(const char*)")
endif
if (mix2(1.0, 1.0) != 102)
error("mix2(double, const double &)")
endif
if (mix2(1.0) != 103)
error("mix2(double)")
endif
# mix 3
if (mix3("hi") != 101)
error("mix3(const char*)")
endif
if (mix3(1.0, 1.0) != 102)
error("mix3(double, const double &)")
endif
if (mix3(1.0) != 103)
error("mix3(double)")
endif
# Combination 1
if (overtparams1(100) != 10)
error("overtparams1(int)")
endif
if (overtparams1(100.0, 100) != 20)
error("overtparams1(double, int)")
endif
# Combination 2
if (overtparams2(100.0, 100) != 40)
error("overtparams2(double, int)")
endif
# Combination 3
if (overloaded() != 60)
error("overloaded()")
endif
if (overloaded(100.0, 100) != 70)
error("overloaded(double, int)")
endif
# Combination 4
if (overloadedagain("hello") != 80)
error("overloadedagain(const char *)")
endif
if (overloadedagain() != 90)
error("overloadedagain(double)")
endif
# specializations
if (specialization(10) != 202)
error("specialization(int)")
endif
if (specialization(10.1) != 203)
error("specialization(double)")
endif
if (specialization(10, 10) != 204)
error("specialization(int, int)")
endif
if (specialization(10.0, 10.1) != 205)
error("specialization(double, double)")
endif
if (specialization("hi", "hi") != 201)
error("specialization(const char *, const char *)")
endif
# simple specialization
xyz();
xyz_int();
xyz_double();
# a bit of everything
if (overload("hi") != 0)
error("overload()")
endif
if (overload(1) != 10)
error("overload(int t)")
endif
if (overload(1, 1) != 20)
error("overload(int t, const int &)")
endif
if (overload(1, "hello") != 30)
error("overload(int t, const char *)")
endif
k = Klass();
if (overload(k) != 10)
error("overload(Klass t)")
endif
if (overload(k, k) != 20)
error("overload(Klass t, const Klass &)")
endif
if (overload(k, "hello") != 30)
error("overload(Klass t, const char *)")
endif
if (overload(10.1, "hi") != 40)
error("overload(double t, const char *)")
endif
if (overload() != 50)
error("overload(const char *)")
endif
# everything put in a namespace
if (nsoverload("hi") != 1000)
error("nsoverload()")
endif
if (nsoverload(1) != 1010)
error("nsoverload(int t)")
endif
if (nsoverload(1, 1) != 1020)
error("nsoverload(int t, const int &)")
endif
if (nsoverload(1, "hello") != 1030)
error("nsoverload(int t, const char *)")
endif
if (nsoverload(k) != 1010)
error("nsoverload(Klass t)")
endif
if (nsoverload(k, k) != 1020)
error("nsoverload(Klass t, const Klass &)")
endif
if (nsoverload(k, "hello") != 1030)
error("nsoverload(Klass t, const char *)")
endif
if (nsoverload(10.1, "hi") != 1040)
error("nsoverload(double t, const char *)")
endif
if (nsoverload() != 1050)
error("nsoverload(const char *)")
endif
A_foo(1);
b = B();
b.foo(1);

View file

@ -0,0 +1,18 @@
preproc
if (preproc.cvar.endif != 1)
error
endif
if (preproc.cvar.define != 1)
error
endif
if (preproc.cvar.defined != 1)
error
endif
if (2*preproc.one != preproc.two)
error
endif

View file

@ -0,0 +1,53 @@
primitive_ref
if (ref_int(3) != 3)
error
endif
if (ref_uint(3) != 3)
error
endif
if (ref_short(3) != 3)
error
endif
if (ref_ushort(3) != 3)
error
endif
if (ref_long(3) != 3)
error
endif
if (ref_ulong(3) != 3)
error
endif
if (ref_schar(3) != 3)
error
endif
if (ref_uchar(3) != 3)
error
endif
if (ref_float(3.5) != 3.5)
error
endif
if (ref_double(3.5) != 3.5)
error
endif
if (ref_bool(true) != true)
error
endif
if (!strcmp(ref_char('x'),'x'))
error
endif
if (ref_over(0) != 0)
error
endif

View file

@ -0,0 +1,402 @@
primitive_types
var_init();
# assigning globals calls
cvar.var_bool = sct_bool;
cvar.var_schar = sct_schar;
cvar.var_uchar = sct_uchar;
cvar.var_int = sct_int;
cvar.var_uint = sct_uint;
cvar.var_short = sct_short;
cvar.var_ushort = sct_ushort;
cvar.var_long = sct_long;
cvar.var_ulong = sct_ulong;
cvar.var_llong = sct_llong;
cvar.var_ullong = sct_ullong;
cvar.var_char = sct_char;
cvar.var_pchar = sct_pchar;
cvar.var_pcharc = sct_pcharc;
cvar.var_pint = sct_pint;
cvar.var_sizet = sct_sizet;
cvar.var_hello = sct_hello;
cvar.var_myint = sct_myint;
cvar.var_namet = def_namet;
cvar.var_parami = sct_parami;
cvar.var_paramd = sct_paramd;
cvar.var_paramc = sct_paramc;
v_check();
function octerror(name, val, cte)
name, val, cte
error
endfunction
if cvar.var_bool != cct_bool:
octerror("bool", cvar.var_bool, cct_bool)
endif
if cvar.var_schar != cct_schar:
octerror("schar", cvar.var_schar, cct_schar)
endif
if cvar.var_uchar != cct_uchar:
octerror("uchar", cvar.var_uchar, cct_uchar)
endif
if cvar.var_int != cct_int:
octerror("int", cvar.var_int, cct_int)
endif
if cvar.var_uint != cct_uint:
octerror("uint", cvar.var_uint, cct_uint)
endif
if cvar.var_short != cct_short:
octerror("short", cvar.var_short, cct_short)
endif
if cvar.var_ushort != cct_ushort:
octerror("ushort", cvar.var_ushort, cct_ushort)
endif
if cvar.var_long != cct_long:
octerror("long", cvar.var_long, cct_long)
endif
if cvar.var_ulong != cct_ulong:
octerror("ulong", cvar.var_ulong, cct_ulong)
endif
if cvar.var_llong != cct_llong:
octerror("llong", cvar.var_llong, cct_llong)
endif
if cvar.var_ullong != cct_ullong:
octerror("ullong", cvar.var_ullong, cct_ullong)
endif
if cvar.var_char != cct_char:
octerror("char", cvar.var_char, cct_char)
endif
if cvar.var_pchar != cct_pchar:
octerror("pchar", cvar.var_pchar, cct_pchar)
endif
if cvar.var_pcharc != cct_pcharc:
octerror("pchar", cvar.var_pcharc, cct_pcharc)
endif
if cvar.var_pint != cct_pint:
octerror("pint", cvar.var_pint, cct_pint)
endif
if cvar.var_sizet != cct_sizet:
octerror("sizet", cvar.var_sizet, cct_sizet)
endif
if cvar.var_hello != cct_hello:
octerror("hello", cvar.var_hello, cct_hello)
endif
if cvar.var_myint != cct_myint:
octerror("myint", cvar.var_myint, cct_myint)
endif
if cvar.var_namet != def_namet:
octerror("name", cvar.var_namet, def_namet)
endif
function OctTest()
self=subclass(TestDirector);
self.ident=@(self,x) x;
self.vval_bool=@(self, x) self.ident(x);
self.vval_schar=@(self, x) self.ident(x);
self.vval_uchar=@(self, x) self.ident(x);
self.vval_int=@(self, x) self.ident(x);
self.vval_uint=@(self, x) self.ident(x);
self.vval_short=@(self, x) self.ident(x);
self.vval_ushort=@(self, x) self.ident(x);
self.vval_long=@(self, x) self.ident(x);
self.vval_ulong=@(self, x) self.ident(x);
self.vval_llong=@(self, x) self.ident(x);
self.vval_ullong=@(self, x) self.ident(x);
self.vval_float=@(self, x) self.ident(x);
self.vval_double=@(self, x) self.ident(x);
self.vval_char=@(self, x) self.ident(x);
self.vval_pchar=@(self, x) self.ident(x);
self.vval_pcharc=@(self, x) self.ident(x);
self.vval_pint=@(self, x) self.ident(x);
self.vval_sizet=@(self, x) self.ident(x);
self.vval_hello=@(self, x) self.ident(x);
self.vval_myint=@(self, x) self.ident(x);
self.vref_bool=@(self, x) self.ident(x);
self.vref_schar=@(self, x) self.ident(x);
self.vref_uchar=@(self, x) self.ident(x);
self.vref_int=@(self, x) self.ident(x);
self.vref_uint=@(self, x) self.ident(x);
self.vref_short=@(self, x) self.ident(x);
self.vref_ushort=@(self, x) self.ident(x);
self.vref_long=@(self, x) self.ident(x);
self.vref_ulong=@(self, x) self.ident(x);
self.vref_llong=@(self, x) self.ident(x);
self.vref_ullong=@(self, x) self.ident(x);
self.vref_float=@(self, x) self.ident(x);
self.vref_double=@(self, x) self.ident(x);
self.vref_char=@(self, x) self.ident(x);
self.vref_pchar=@(self, x) self.ident(x);
self.vref_pcharc=@(self, x) self.ident(x);
self.vref_pint=@(self, x) self.ident(x);
self.vref_sizet=@(self, x) self.ident(x);
self.vref_hello=@(self, x) self.ident(x);
self.vref_myint=@(self, x) self.ident(x);
endfunction
t = Test();
p = OctTest();
# internal call check
if (t.c_check() != p.c_check())
error, "bad director"
endif
p.var_bool = p.stc_bool;
p.var_schar = p.stc_schar;
p.var_uchar = p.stc_uchar;
p.var_int = p.stc_int;
p.var_uint = p.stc_uint;
p.var_short = p.stc_short;
p.var_ushort = p.stc_ushort;
p.var_long = p.stc_long;
p.var_ulong = p.stc_ulong;
p.var_llong = p.stc_llong;
p.var_ullong = p.stc_ullong;
p.var_char = p.stc_char;
p.var_pchar = sct_pchar;
p.var_pcharc = sct_pcharc;
p.var_pint = sct_pint;
p.var_sizet = sct_sizet;
p.var_hello = sct_hello;
p.var_myint = sct_myint;
p.var_namet = def_namet;
p.var_parami = sct_parami;
p.var_paramd = sct_paramd;
p.var_paramc = sct_paramc;
p.v_check();
t.var_bool = t.stc_bool;
t.var_schar = t.stc_schar;
t.var_uchar = t.stc_uchar;
t.var_int = t.stc_int;
t.var_uint = t.stc_uint;
t.var_short = t.stc_short;
t.var_ushort = t.stc_ushort;
t.var_long = t.stc_long;
t.var_ulong = t.stc_ulong;
t.var_llong = t.stc_llong;
t.var_ullong = t.stc_ullong;
t.var_char = t.stc_char;
t.var_pchar = sct_pchar;
t.var_pcharc = sct_pcharc;
t.var_pint = sct_pint;
t.var_sizet = sct_sizet;
t.var_hello = sct_hello;
t.var_myint = sct_myint;
t.var_namet = def_namet;
t.var_parami = sct_parami;
t.var_paramd = sct_paramd;
t.var_paramc = sct_paramc;
t.v_check();
# this value contains a '0' char!
if (def_namet != 'ho\0la')
error
endif
t.var_namet = def_namet;
if (t.var_namet != def_namet)
error
endif
t.var_namet = 'holac';
if (t.var_namet != 'holac')
error
endif
t.var_namet = 'hol';
if (t.var_namet != 'hol')
error
endif
if (t.strlen('hile') != 4)
error
endif
if (t.strlen('hil\0') != 4)
error
endif
cvar.var_char = '\0';
if (cvar.var_char != '\0')
error
endif
cvar.var_char = 0;
if (cvar.var_char != '\0')
error
endif
cvar.var_namet = '\0';
if (cvar.var_namet != '')
error
endif
cvar.var_namet = '';
if (cvar.var_namet != '')
error, "bad char empty case"
endif
cvar.var_pchar = None;
if (cvar.var_pchar != None)
error, "bad None case"
endif
cvar.var_pchar = '';
if (cvar.var_pchar != '')
error
endif
cvar.var_pcharc = None;
if (cvar.var_pcharc != None)
error
endif
cvar.var_pcharc = '';
if (cvar.var_pcharc != '')
error
endif
#
# creating a raw char*
#
pc = new_pchar(5);
pchar_setitem(pc, 0, 'h');
pchar_setitem(pc, 1, 'o');
pchar_setitem(pc, 2, 'l');
pchar_setitem(pc, 3, 'a');
pchar_setitem(pc, 4, 0);
if (t.strlen(pc) != 4)
error
endif
cvar.var_pchar = pc;
if (cvar.var_pchar != "hola")
error
endif
cvar.var_namet = pc;
if (cvar.var_namet != "hola")
error
endif
delete_pchar(pc);
#
# Now when things should fail
#
try
error = 0;
a = t.var_uchar;
t.var_uchar = 10000;
err = 1;
catch
if (a != t.var_uchar)
err = 1;
endif
end_try_catch
if (err)
error
endif
try
err = 0;
a = t.var_char;
t.var_char = '23';
err = 1;
catch
if (a != t.var_char)
error = 1
endif
end_try_catch
if (err)
error
endif
try
err = 0
a = t.var_uint
t.var_uint = -1
err = 1;
catch
if a != t.var_uint:
err = 1;
endif
end_try_catch
if (err)
error
endif
#
#
try
err = 0;
a = t.var_namet;
t.var_namet = '123456';
err = 1;
catch
if (a != t.var_namet)
err = 1;
endif
end_try_catch
if (err)
error
endif
#
#
#
t2 = p.vtest(t);
if (t.var_namet != t2.var_namet)
error
endif
if (cvar.fixsize != 'ho\0la\0\0\0')
error
endif
cvar.fixsize = 'ho';
if (cvar.fixsize != 'ho\0\0\0\0\0\0')
error
endif
f = Foo(3);
f1 = fptr_val(f);
f2 = fptr_ref(f);
if (f1._a != f2._a)
error
endif
v = char_foo(1,3);
if (v !=3)
error
endif
s = char_foo(1,"hello");
if (s !="hello")
error
endif
v = SetPos(1,3);
if (v !=4)
error
endif

View file

@ -0,0 +1,32 @@
import _profiletest
import profiletest
a = profiletest.A()
print a
print a.this
b = profiletest.B()
fn = b.fn
i = 50000
while i:
a = fn(a) #1
a = fn(a) #2
a = fn(a) #3
a = fn(a) #4
a = fn(a) #5
a = fn(a) #6
a = fn(a) #7
a = fn(a) #8
a = fn(a) #9
a = fn(a) #10
a = fn(a) #1
a = fn(a) #2
a = fn(a) #3
a = fn(a) #4
a = fn(a) #5
a = fn(a) #6
a = fn(a) #7
a = fn(a) #8
a = fn(a) #9
a = fn(a) #20
i -= 1

Some files were not shown because too many files have changed in this diff Show more