diff options
Diffstat (limited to 'Examples/test-suite/octave')
159 files changed, 6306 insertions, 0 deletions
diff --git a/Examples/test-suite/octave/Makefile.in b/Examples/test-suite/octave/Makefile.in new file mode 100644 index 0000000..70de84a --- /dev/null +++ b/Examples/test-suite/octave/Makefile.in @@ -0,0 +1,90 @@ +####################################################################### +# Makefile for octave test-suite +####################################################################### + +LANGUAGE = octave +OCTAVE = @OCTAVE@ -q +SCRIPTSUFFIX = _runme.m +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ + +CPP_TEST_CASES += \ + li_std_pair_extra \ + li_std_string_extra \ + octave_cell_deref + +CPP_TEST_BROKEN += \ + implicittest \ + li_implicit \ + li_std_map \ + li_std_set \ + li_std_stream + +#C_TEST_CASES += + +# +# This test only works with modern C compilers +# +#C_TEST_CASES += \ +# complextest + +include $(srcdir)/../common.mk + +# Overridden variables here +LIBS = -L. + +# Custom tests - tests with additional commandline options +# none! + +# 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 $(RUNTOOL) $(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 diff --git a/Examples/test-suite/octave/abstract_access_runme.m b/Examples/test-suite/octave/abstract_access_runme.m new file mode 100644 index 0000000..e49343a --- /dev/null +++ b/Examples/test-suite/octave/abstract_access_runme.m @@ -0,0 +1,7 @@ +abstract_access + +d = abstract_access.D(); +if (d.do_x() != 1) + error +endif + diff --git a/Examples/test-suite/octave/abstract_typedef2_runme.m b/Examples/test-suite/octave/abstract_typedef2_runme.m new file mode 100644 index 0000000..7f364db --- /dev/null +++ b/Examples/test-suite/octave/abstract_typedef2_runme.m @@ -0,0 +1,8 @@ +abstract_typedef2 + +a = A_UF(); + + + + + diff --git a/Examples/test-suite/octave/abstract_typedef_runme.m b/Examples/test-suite/octave/abstract_typedef_runme.m new file mode 100644 index 0000000..f28cf3c --- /dev/null +++ b/Examples/test-suite/octave/abstract_typedef_runme.m @@ -0,0 +1,12 @@ +abstract_typedef +e = Engine(); + +a = A(); + + +if (a.write(e) != 1) + error +endif + + + diff --git a/Examples/test-suite/octave/abstract_virtual_runme.m b/Examples/test-suite/octave/abstract_virtual_runme.m new file mode 100644 index 0000000..9845a58 --- /dev/null +++ b/Examples/test-suite/octave/abstract_virtual_runme.m @@ -0,0 +1,7 @@ +abstract_virtual + + +d = D(); + +e = E(); + diff --git a/Examples/test-suite/octave/argcargvtest_runme.m b/Examples/test-suite/octave/argcargvtest_runme.m new file mode 100644 index 0000000..f246dd9 --- /dev/null +++ b/Examples/test-suite/octave/argcargvtest_runme.m @@ -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); diff --git a/Examples/test-suite/octave/array_member_runme.m b/Examples/test-suite/octave/array_member_runme.m new file mode 100644 index 0000000..56b7968 --- /dev/null +++ b/Examples/test-suite/octave/array_member_runme.m @@ -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 + + + diff --git a/Examples/test-suite/octave/arrays_global_runme.m b/Examples/test-suite/octave/arrays_global_runme.m new file mode 100644 index 0000000..619d381 --- /dev/null +++ b/Examples/test-suite/octave/arrays_global_runme.m @@ -0,0 +1,19 @@ +arrays_global + +arrays_global.cvar.array_i = arrays_global.cvar.array_const_i; + +cvar.BeginString_FIX44a; +cvar.BeginString_FIX44b; +cvar.BeginString_FIX44c; +cvar.BeginString_FIX44d; +cvar.BeginString_FIX44d; +cvar.BeginString_FIX44b = strcat("12","\0","45"); +cvar.BeginString_FIX44b; +cvar.BeginString_FIX44d; +cvar.BeginString_FIX44e; +cvar.BeginString_FIX44f; + +test_a("hello","hi","chello","chi"); + +test_b("1234567","hi"); + diff --git a/Examples/test-suite/octave/callback_runme.m b/Examples/test-suite/octave/callback_runme.m new file mode 100644 index 0000000..db9f788 --- /dev/null +++ b/Examples/test-suite/octave/callback_runme.m @@ -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 diff --git a/Examples/test-suite/octave/class_ignore_runme.m b/Examples/test-suite/octave/class_ignore_runme.m new file mode 100644 index 0000000..76bbcd3 --- /dev/null +++ b/Examples/test-suite/octave/class_ignore_runme.m @@ -0,0 +1,7 @@ +class_ignore + +a = class_ignore.Bar(); + +if (!strcmp(class_ignore.do_blah(a),"Bar::blah")) + error +endif diff --git a/Examples/test-suite/octave/class_scope_weird_runme.m b/Examples/test-suite/octave/class_scope_weird_runme.m new file mode 100644 index 0000000..2fc8578 --- /dev/null +++ b/Examples/test-suite/octave/class_scope_weird_runme.m @@ -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 diff --git a/Examples/test-suite/octave/compactdefaultargs_runme.m b/Examples/test-suite/octave/compactdefaultargs_runme.m new file mode 100644 index 0000000..08e8727 --- /dev/null +++ b/Examples/test-suite/octave/compactdefaultargs_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/complextest_runme.m b/Examples/test-suite/octave/complextest_runme.m new file mode 100644 index 0000000..cd0f9f4 --- /dev/null +++ b/Examples/test-suite/octave/complextest_runme.m @@ -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 diff --git a/Examples/test-suite/octave/constover_runme.m b/Examples/test-suite/octave/constover_runme.m new file mode 100644 index 0000000..febcdae --- /dev/null +++ b/Examples/test-suite/octave/constover_runme.m @@ -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 + + diff --git a/Examples/test-suite/octave/constructor_copy_runme.m b/Examples/test-suite/octave/constructor_copy_runme.m new file mode 100644 index 0000000..5d52ab5 --- /dev/null +++ b/Examples/test-suite/octave/constructor_copy_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/contract_runme.m b/Examples/test-suite/octave/contract_runme.m new file mode 100644 index 0000000..9170e77 --- /dev/null +++ b/Examples/test-suite/octave/contract_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/cpp_enum_runme.m b/Examples/test-suite/octave/cpp_enum_runme.m new file mode 100644 index 0000000..fe5f3b1 --- /dev/null +++ b/Examples/test-suite/octave/cpp_enum_runme.m @@ -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 diff --git a/Examples/test-suite/octave/cpp_namespace_runme.m b/Examples/test-suite/octave/cpp_namespace_runme.m new file mode 100644 index 0000000..ac6c663 --- /dev/null +++ b/Examples/test-suite/octave/cpp_namespace_runme.m @@ -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 + + diff --git a/Examples/test-suite/octave/default_args_runme.m b/Examples/test-suite/octave/default_args_runme.m new file mode 100644 index 0000000..f8a6560 --- /dev/null +++ b/Examples/test-suite/octave/default_args_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/default_constructor_runme.m b/Examples/test-suite/octave/default_constructor_runme.m new file mode 100644 index 0000000..41d0f3f --- /dev/null +++ b/Examples/test-suite/octave/default_constructor_runme.m @@ -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); + + diff --git a/Examples/test-suite/octave/director_abstract_runme.m b/Examples/test-suite/octave/director_abstract_runme.m new file mode 100644 index 0000000..00fb676 --- /dev/null +++ b/Examples/test-suite/octave/director_abstract_runme.m @@ -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. + diff --git a/Examples/test-suite/octave/director_basic_runme.m b/Examples/test-suite/octave/director_basic_runme.m new file mode 100644 index 0000000..9de54a3 --- /dev/null +++ b/Examples/test-suite/octave/director_basic_runme.m @@ -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); + + + diff --git a/Examples/test-suite/octave/director_classic_runme.m b/Examples/test-suite/octave/director_classic_runme.m new file mode 100644 index 0000000..c1f8e95 --- /dev/null +++ b/Examples/test-suite/octave/director_classic_runme.m @@ -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; + diff --git a/Examples/test-suite/octave/director_default_runme.m b/Examples/test-suite/octave/director_default_runme.m new file mode 100644 index 0000000..c0b479d --- /dev/null +++ b/Examples/test-suite/octave/director_default_runme.m @@ -0,0 +1,10 @@ +director_default + + +f = Foo(); +f = Foo(1); + + +f = Bar(); +f = Bar(1); + diff --git a/Examples/test-suite/octave/director_detect_runme.m b/Examples/test-suite/octave/director_detect_runme.m new file mode 100644 index 0000000..f2d8c8d --- /dev/null +++ b/Examples/test-suite/octave/director_detect_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/director_enum_runme.m b/Examples/test-suite/octave/director_enum_runme.m new file mode 100644 index 0000000..96f158d --- /dev/null +++ b/Examples/test-suite/octave/director_enum_runme.m @@ -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 diff --git a/Examples/test-suite/octave/director_extend_runme.m b/Examples/test-suite/octave/director_extend_runme.m new file mode 100644 index 0000000..1cbeac8 --- /dev/null +++ b/Examples/test-suite/octave/director_extend_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/director_frob_runme.m b/Examples/test-suite/octave/director_frob_runme.m new file mode 100644 index 0000000..16585cc --- /dev/null +++ b/Examples/test-suite/octave/director_frob_runme.m @@ -0,0 +1,9 @@ +director_frob + +foo = Bravo(); +s = foo.abs_method(); + +if (!strcmp(s,"Bravo::abs_method()")) + error(s) +endif + diff --git a/Examples/test-suite/octave/director_nested_runme.m b/Examples/test-suite/octave/director_nested_runme.m new file mode 100644 index 0000000..6e1d0de --- /dev/null +++ b/Examples/test-suite/octave/director_nested_runme.m @@ -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 diff --git a/Examples/test-suite/octave/director_stl_runme.m b/Examples/test-suite/octave/director_stl_runme.m new file mode 100644 index 0000000..e8f4c5e --- /dev/null +++ b/Examples/test-suite/octave/director_stl_runme.m @@ -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); + diff --git a/Examples/test-suite/octave/director_string_runme.m b/Examples/test-suite/octave/director_string_runme.m new file mode 100644 index 0000000..c2d4e9c --- /dev/null +++ b/Examples/test-suite/octave/director_string_runme.m @@ -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 + + diff --git a/Examples/test-suite/octave/director_unroll_runme.m b/Examples/test-suite/octave/director_unroll_runme.m new file mode 100644 index 0000000..6ca213c --- /dev/null +++ b/Examples/test-suite/octave/director_unroll_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/director_wstring_runme.m b/Examples/test-suite/octave/director_wstring_runme.m new file mode 100644 index 0000000..b59ff6e --- /dev/null +++ b/Examples/test-suite/octave/director_wstring_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/dynamic_cast_runme.m b/Examples/test-suite/octave/dynamic_cast_runme.m new file mode 100644 index 0000000..dad0ba2 --- /dev/null +++ b/Examples/test-suite/octave/dynamic_cast_runme.m @@ -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 + + diff --git a/Examples/test-suite/octave/empty_runme.m b/Examples/test-suite/octave/empty_runme.m new file mode 100644 index 0000000..e7b64f1 --- /dev/null +++ b/Examples/test-suite/octave/empty_runme.m @@ -0,0 +1,2 @@ +empty + diff --git a/Examples/test-suite/octave/enum_template_runme.m b/Examples/test-suite/octave/enum_template_runme.m new file mode 100644 index 0000000..ca10f1f --- /dev/null +++ b/Examples/test-suite/octave/enum_template_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/enums_runme.m b/Examples/test-suite/octave/enums_runme.m new file mode 100644 index 0000000..91f2ce2 --- /dev/null +++ b/Examples/test-suite/octave/enums_runme.m @@ -0,0 +1,7 @@ + +enums + +enums.bar2(1) +enums.bar3(1) +enums.bar1(1) + diff --git a/Examples/test-suite/octave/exception_order_runme.m b/Examples/test-suite/octave/exception_order_runme.m new file mode 100644 index 0000000..3fb2b9a --- /dev/null +++ b/Examples/test-suite/octave/exception_order_runme.m @@ -0,0 +1,44 @@ +exception_order + + +a = A(); + +try + a.foo() +catch + if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E1\n")) + error("bad exception order") + endif +end_try_catch + +try + a.bar() +catch + if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E2\n")) + error("bad exception order") + endif +end_try_catch + +try + a.foobar() +catch + if (!strcmp(lasterror.message, "error: postcatch unknown (SWIG_RuntimeError)\n")) + error("bad exception order") + endif +end_try_catch + +try + a.barfoo(1) +catch + if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E1\n")) + error("bad exception order") + endif +end_try_catch + +try + a.barfoo(2) +catch + if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E2 *\n")) + error("bad exception order") + endif +end_try_catch diff --git a/Examples/test-suite/octave/extend_placement_runme.m b/Examples/test-suite/octave/extend_placement_runme.m new file mode 100644 index 0000000..b7a8e78 --- /dev/null +++ b/Examples/test-suite/octave/extend_placement_runme.m @@ -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); diff --git a/Examples/test-suite/octave/extend_template_ns_runme.m b/Examples/test-suite/octave/extend_template_ns_runme.m new file mode 100644 index 0000000..401ea63 --- /dev/null +++ b/Examples/test-suite/octave/extend_template_ns_runme.m @@ -0,0 +1,10 @@ +extend_template_ns + +f = Foo_One(); +if (f.test1(37) != 37) + error +endif + +if (f.test2(42) != 42) + error +endif diff --git a/Examples/test-suite/octave/extend_template_runme.m b/Examples/test-suite/octave/extend_template_runme.m new file mode 100644 index 0000000..1cad7bf --- /dev/null +++ b/Examples/test-suite/octave/extend_template_runme.m @@ -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 diff --git a/Examples/test-suite/octave/extend_variable_runme.m b/Examples/test-suite/octave/extend_variable_runme.m new file mode 100644 index 0000000..c55b6c5 --- /dev/null +++ b/Examples/test-suite/octave/extend_variable_runme.m @@ -0,0 +1,6 @@ +extend_variable + +if (Foo.Bar != 42) + error +endif + diff --git a/Examples/test-suite/octave/file_test_runme.m b/Examples/test-suite/octave/file_test_runme.m new file mode 100644 index 0000000..4c22a30 --- /dev/null +++ b/Examples/test-suite/octave/file_test_runme.m @@ -0,0 +1,9 @@ +file_test + +file_test.nfile("stdout"); + +cstdout = file_test.GetStdOut(); + +file_test.nfile(cstdout); +file_test.nfile_name("test.dat"); + diff --git a/Examples/test-suite/octave/friends_runme.m b/Examples/test-suite/octave/friends_runme.m new file mode 100644 index 0000000..e18f47a --- /dev/null +++ b/Examples/test-suite/octave/friends_runme.m @@ -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 diff --git a/Examples/test-suite/octave/fvirtual_runme.m b/Examples/test-suite/octave/fvirtual_runme.m new file mode 100644 index 0000000..e755a55 --- /dev/null +++ b/Examples/test-suite/octave/fvirtual_runme.m @@ -0,0 +1,10 @@ +fvirtual + +sw = NodeSwitch(); +n = Node(); +i = sw.addChild(n); + +if (i != 2) + error("addChild") +endif + diff --git a/Examples/test-suite/octave/global_ns_arg_runme.m b/Examples/test-suite/octave/global_ns_arg_runme.m new file mode 100644 index 0000000..fa3625e --- /dev/null +++ b/Examples/test-suite/octave/global_ns_arg_runme.m @@ -0,0 +1,5 @@ +global_ns_arg + +a = foo(1); +b = bar(); + diff --git a/Examples/test-suite/octave/grouping_runme.m b/Examples/test-suite/octave/grouping_runme.m new file mode 100644 index 0000000..26b896c --- /dev/null +++ b/Examples/test-suite/octave/grouping_runme.m @@ -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; diff --git a/Examples/test-suite/octave/iadd_runme.m b/Examples/test-suite/octave/iadd_runme.m new file mode 100755 index 0000000..c386c66 --- /dev/null +++ b/Examples/test-suite/octave/iadd_runme.m @@ -0,0 +1,10 @@ +iadd + +f = iadd.Foo(); + +f.AsA.x = 3; +f.AsA += f.AsA; + +if (f.AsA.x != 6) + error +endif diff --git a/Examples/test-suite/octave/import_nomodule_runme.m b/Examples/test-suite/octave/import_nomodule_runme.m new file mode 100644 index 0000000..a70b468 --- /dev/null +++ b/Examples/test-suite/octave/import_nomodule_runme.m @@ -0,0 +1,8 @@ +import_nomodule + +f = create_Foo(); +test1(f,42); +delete_Foo(f); + +b = Bar(); +test1(b,37); diff --git a/Examples/test-suite/octave/imports_runme.m b/Examples/test-suite/octave/imports_runme.m new file mode 100644 index 0000000..be9db59 --- /dev/null +++ b/Examples/test-suite/octave/imports_runme.m @@ -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))); + diff --git a/Examples/test-suite/octave/inctest_runme.m b/Examples/test-suite/octave/inctest_runme.m new file mode 100644 index 0000000..ab0cb64 --- /dev/null +++ b/Examples/test-suite/octave/inctest_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/inherit_missing_runme.m b/Examples/test-suite/octave/inherit_missing_runme.m new file mode 100644 index 0000000..8517e2d --- /dev/null +++ b/Examples/test-suite/octave/inherit_missing_runme.m @@ -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); diff --git a/Examples/test-suite/octave/inout_runme.m b/Examples/test-suite/octave/inout_runme.m new file mode 100644 index 0000000..74caaff --- /dev/null +++ b/Examples/test-suite/octave/inout_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/inplaceadd_runme.m b/Examples/test-suite/octave/inplaceadd_runme.m new file mode 100644 index 0000000..2bc1937 --- /dev/null +++ b/Examples/test-suite/octave/inplaceadd_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/input_runme.m b/Examples/test-suite/octave/input_runme.m new file mode 100644 index 0000000..7578621 --- /dev/null +++ b/Examples/test-suite/octave/input_runme.m @@ -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 diff --git a/Examples/test-suite/octave/li_attribute_runme.m b/Examples/test-suite/octave/li_attribute_runme.m new file mode 100644 index 0000000..548e733 --- /dev/null +++ b/Examples/test-suite/octave/li_attribute_runme.m @@ -0,0 +1,85 @@ +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 + +# class/struct attribute with get/set methods using return/pass by reference +myFoo = li_attribute.MyFoo(); +myFoo.x = 8; +myClass = li_attribute.MyClass(); +myClass.Foo = myFoo; +if (myClass.Foo.x != 8) + error +endif + +# class/struct attribute with get/set methods using return/pass by value +myClassVal = li_attribute.MyClassVal(); +if (myClassVal.ReadWriteFoo.x != -1) + error +endif +if (myClassVal.ReadOnlyFoo.x != -1) + error +endif +myClassVal.ReadWriteFoo = myFoo; +if (myClassVal.ReadWriteFoo.x != 8) + error +endif +if (myClassVal.ReadOnlyFoo.x != 8) + error +endif + +# string attribute with get/set methods using return/pass by value +myStringyClass = li_attribute.MyStringyClass("initial string"); +if (myStringyClass.ReadWriteString != "initial string") + error +endif +if (myStringyClass.ReadOnlyString != "initial string") + error +endif +myStringyClass.ReadWriteString = "changed string"; +if (myStringyClass.ReadWriteString != "changed string") + error +endif +if (myStringyClass.ReadOnlyString != "changed string") + error +endif + diff --git a/Examples/test-suite/octave/li_boost_shared_ptr_runme.m b/Examples/test-suite/octave/li_boost_shared_ptr_runme.m new file mode 100644 index 0000000..ca09316 --- /dev/null +++ b/Examples/test-suite/octave/li_boost_shared_ptr_runme.m @@ -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(); + endfor + + 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 || pid.baseVal2 != 40.4) + error("Base values wrong") + endif + if (pid.val1 != 10 || 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 + + diff --git a/Examples/test-suite/octave/li_carrays_runme.m b/Examples/test-suite/octave/li_carrays_runme.m new file mode 100644 index 0000000..8ec7e59 --- /dev/null +++ b/Examples/test-suite/octave/li_carrays_runme.m @@ -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 diff --git a/Examples/test-suite/octave/li_cmalloc_runme.m b/Examples/test-suite/octave/li_cmalloc_runme.m new file mode 100644 index 0000000..45faf73 --- /dev/null +++ b/Examples/test-suite/octave/li_cmalloc_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/li_cpointer_runme.m b/Examples/test-suite/octave/li_cpointer_runme.m new file mode 100644 index 0000000..bf660a6 --- /dev/null +++ b/Examples/test-suite/octave/li_cpointer_runme.m @@ -0,0 +1,12 @@ +li_cpointer + + +p = new_intp(); +intp_assign(p,3); + +if (intp_value(p) != 3) + error +endif + +delete_intp(p); + diff --git a/Examples/test-suite/octave/li_cstring_runme.m b/Examples/test-suite/octave/li_cstring_runme.m new file mode 100644 index 0000000..0d2bdb7 --- /dev/null +++ b/Examples/test-suite/octave/li_cstring_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/li_cwstring_runme.m b/Examples/test-suite/octave/li_cwstring_runme.m new file mode 100644 index 0000000..4cfef7f --- /dev/null +++ b/Examples/test-suite/octave/li_cwstring_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/li_factory_runme.m b/Examples/test-suite/octave/li_factory_runme.m new file mode 100644 index 0000000..d87920d --- /dev/null +++ b/Examples/test-suite/octave/li_factory_runme.m @@ -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 diff --git a/Examples/test-suite/octave/li_implicit_runme.m b/Examples/test-suite/octave/li_implicit_runme.m new file mode 100644 index 0000000..2ca8b59 --- /dev/null +++ b/Examples/test-suite/octave/li_implicit_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/li_std_carray_runme.m b/Examples/test-suite/octave/li_std_carray_runme.m new file mode 100644 index 0000000..4943fa8 --- /dev/null +++ b/Examples/test-suite/octave/li_std_carray_runme.m @@ -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]}); + + + + diff --git a/Examples/test-suite/octave/li_std_map_runme.m b/Examples/test-suite/octave/li_std_map_runme.m new file mode 100644 index 0000000..f37c780 --- /dev/null +++ b/Examples/test-suite/octave/li_std_map_runme.m @@ -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.IntIntMap(); + +mii{1} = 1; +mii{1} = 2; + +if (mii[1] != 2) + error +endif + + diff --git a/Examples/test-suite/octave/li_std_pair_extra_runme.m b/Examples/test-suite/octave/li_std_pair_extra_runme.m new file mode 100644 index 0000000..0f9e9a2 --- /dev/null +++ b/Examples/test-suite/octave/li_std_pair_extra_runme.m @@ -0,0 +1,69 @@ +li_std_pair_extra + +p = {1,2}; +p1 = li_std_pair_extra.p_inout(p); +assert(all(cell2mat(p1)==[2,1])); +p2 = li_std_pair_extra.p_inoutd(p1); +assert(all(cell2mat(p2)==[1,2])); + +d1 = li_std_pair_extra.d_inout(2); +assert(d1==4); + +[i,d2] = li_std_pair_extra.d_inout2(2); +assert(all([i,d2]==[1,4])); + +[i,p] = li_std_pair_extra.p_inout2(p); +assert(i==1&&all([cell2mat(p)]==[2,1])); +[p3,p4] = li_std_pair_extra.p_inout3(p1,p1); +assert(all(cell2mat(p3)==[2,1])); +assert(all(cell2mat(p4)==[2,1])); + +psi = li_std_pair_extra.SIPair("hello",1); +assert(psi=={"hello",1}); +pci = li_std_pair_extra.CIPair(complex(1,2),1); +assert(pci.first==complex(1,2)&&pci.second==1); + + +psi = li_std_pair_extra.SIPair("hi",1); +assert(psi.first=="hi"&&psi.second==1); + +psii = li_std_pair_extra.SIIPair(psi,1); +assert(psii.first.first=="hi"); +assert(psii.first.second==1); +assert(psii.second==1); + +a = li_std_pair_extra.A(); +b = li_std_pair_extra.B(); + +pab = li_std_pair_extra.ABPair(a,b); + +pab.first = a; +pab.first.val = 2; + +assert(pab.first.val == 2); + +pci = li_std_pair_extra.CIntPair(1,0); +assert(pci.first==1&&pci.second==0); + +a = li_std_pair_extra.A(5); +p1 = li_std_pair_extra.pairP1(1,a); +p2 = li_std_pair_extra.pairP2(a,1); +p3 = li_std_pair_extra.pairP3(a,a); + +assert(a.val == li_std_pair_extra.p_identa(p1){2}.val); + +p = li_std_pair_extra.IntPair(1,10); +assert(p.first==1&&p.second==10); +p.first = 1; +assert(p.first==1); + +p = li_std_pair_extra.paircA1(1,a); +assert(p.first==1); +assert(swig_this(p.second)==swig_this(a)); + +p = li_std_pair_extra.paircA2(1,a); +assert(p.first==1); +assert(swig_this(p.second)==swig_this(a)); +#pp = li_std_pair_extra.pairiiA(1,p); # conversion pb re const of pairA1/A2 +pp = li_std_pair_extra.pairiiA(1,{1,A()}); + diff --git a/Examples/test-suite/octave/li_std_set_runme.m b/Examples/test-suite/octave/li_std_set_runme.m new file mode 100644 index 0000000..9bd4f15 --- /dev/null +++ b/Examples/test-suite/octave/li_std_set_runme.m @@ -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 diff --git a/Examples/test-suite/octave/li_std_stream_runme.m b/Examples/test-suite/octave/li_std_stream_runme.m new file mode 100644 index 0000000..bf9402e --- /dev/null +++ b/Examples/test-suite/octave/li_std_stream_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/li_std_string_extra_runme.m b/Examples/test-suite/octave/li_std_string_extra_runme.m new file mode 100644 index 0000000..8d506af --- /dev/null +++ b/Examples/test-suite/octave/li_std_string_extra_runme.m @@ -0,0 +1,162 @@ +li_std_string_extra + +x="hello"; + + + +if (li_std_string_extra.test_ccvalue(x) != x) + error("bad string mapping") +endif + +if (li_std_string_extra.test_cvalue(x) != x) + error("bad string mapping") +endif + +if (li_std_string_extra.test_value(x) != x) + error("bad string mapping: %s, %s", x, li_std_string_extra.test_value(x)) +endif + +if (li_std_string_extra.test_const_reference(x) != x) + error("bad string mapping") +endif + + +s = li_std_string_extra.string("he"); +#s += "ll" +#s.append("ll") +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_extra.test_value(s) != x) + error("bad string mapping") +endif + +if (li_std_string_extra.test_const_reference(s) != x) + error("bad string mapping") +endif + +a = li_std_string_extra.A(s); + +if (li_std_string_extra.test_value(a) != x) + error("bad string mapping") +endif + +if (li_std_string_extra.test_const_reference(a) != x) + error("bad string mapping") +endif + +b = li_std_string_extra.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 = (li_std_string_extra.string("hello") + b); +if (c.find_last_of("l") != 9) + error("bad string mapping") +endif + +s = "hello world"; + +b = li_std_string_extra.B("hi"); + +b.name = li_std_string_extra.string("hello"); +if (b.name != "hello") + error("bad string mapping") +endif + + +b.a = li_std_string_extra.A("hello"); +if (b.a != "hello") + error("bad string mapping") +endif + + +if (li_std_string_extra.test_value_basic1(x) != x) + error("bad string mapping") +endif + +if (li_std_string_extra.test_value_basic2(x) != x) + error("bad string mapping") +endif + + +if (li_std_string_extra.test_value_basic3(x) != x) + error("bad string mapping") +endif + +# Global variables +s = "initial string"; +if (li_std_string_extra.cvar.GlobalString2 != "global string 2") + error("GlobalString2 test 1") +endif +li_std_string_extra.cvar.GlobalString2 = s; +if (li_std_string_extra.cvar.GlobalString2 != s) + error("GlobalString2 test 2") +endif +if (li_std_string_extra.cvar.ConstGlobalString != "const global string") + error("ConstGlobalString test") +endif + +# Member variables +myStructure = li_std_string_extra.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_extra.cvar.Structure_StaticMemberString2 != "static member string 2") + error("StaticMemberString2 test 1") +endif +li_std_string_extra.cvar.Structure_StaticMemberString2 = s; +if (li_std_string_extra.cvar.Structure_StaticMemberString2 != s) + error("StaticMemberString2 test 2") +endif +if (li_std_string_extra.cvar.Structure_ConstStaticMemberString != "const static member string") + error("ConstStaticMemberString test") +endif + + +if (li_std_string_extra.test_reference_input("hello") != "hello") + error +endif +s = li_std_string_extra.test_reference_inout("hello"); +if (s != "hellohello") + error +endif + + +if (li_std_string_extra.stdstring_empty() != "") + error +endif + + +if (li_std_string_extra.c_empty() != "") + error +endif + +#if (li_std_string_extra.c_null() != None) +# error +#endif diff --git a/Examples/test-suite/octave/li_std_vector_runme.m b/Examples/test-suite/octave/li_std_vector_runme.m new file mode 100644 index 0000000..83d1f2c --- /dev/null +++ b/Examples/test-suite/octave/li_std_vector_runme.m @@ -0,0 +1,11 @@ +li_std_vector + +iv = IntVector(4); +for i=0:3, + iv(i) = i; +endfor +x = average(iv); + +if (x != 1.5) + error("average failed"); +endif diff --git a/Examples/test-suite/octave/li_std_wstream_runme.m b/Examples/test-suite/octave/li_std_wstream_runme.m new file mode 100644 index 0000000..a017e8a --- /dev/null +++ b/Examples/test-suite/octave/li_std_wstream_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/li_std_wstring_runme.m b/Examples/test-suite/octave/li_std_wstring_runme.m new file mode 100644 index 0000000..e46c1f2 --- /dev/null +++ b/Examples/test-suite/octave/li_std_wstring_runme.m @@ -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 + + diff --git a/Examples/test-suite/octave/member_pointer_runme.m b/Examples/test-suite/octave/member_pointer_runme.m new file mode 100644 index 0000000..c13350b --- /dev/null +++ b/Examples/test-suite/octave/member_pointer_runme.m @@ -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)); + diff --git a/Examples/test-suite/octave/minherit_runme.m b/Examples/test-suite/octave/minherit_runme.m new file mode 100644 index 0000000..24d2091 --- /dev/null +++ b/Examples/test-suite/octave/minherit_runme.m @@ -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 + + + + + + + + diff --git a/Examples/test-suite/octave/mod_runme.m b/Examples/test-suite/octave/mod_runme.m new file mode 100644 index 0000000..faebf70 --- /dev/null +++ b/Examples/test-suite/octave/mod_runme.m @@ -0,0 +1,7 @@ +mod_a +mod_b + +c = mod_b.C(); +d = mod_b.D(); +d.DoSomething(c); + diff --git a/Examples/test-suite/octave/multi_import_runme.m b/Examples/test-suite/octave/multi_import_runme.m new file mode 100644 index 0000000..08149aa --- /dev/null +++ b/Examples/test-suite/octave/multi_import_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/namespace_class_runme.m b/Examples/test-suite/octave/namespace_class_runme.m new file mode 100644 index 0000000..564cf87 --- /dev/null +++ b/Examples/test-suite/octave/namespace_class_runme.m @@ -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); + diff --git a/Examples/test-suite/octave/namespace_typemap_runme.m b/Examples/test-suite/octave/namespace_typemap_runme.m new file mode 100644 index 0000000..ca37307 --- /dev/null +++ b/Examples/test-suite/octave/namespace_typemap_runme.m @@ -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 = real(c); + +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 diff --git a/Examples/test-suite/octave/namespace_virtual_method_runme.m b/Examples/test-suite/octave/namespace_virtual_method_runme.m new file mode 100644 index 0000000..b78e912 --- /dev/null +++ b/Examples/test-suite/octave/namespace_virtual_method_runme.m @@ -0,0 +1,4 @@ +namespace_virtual_method + +x = namespace_virtual_method.Spam(); + diff --git a/Examples/test-suite/octave/naturalvar_runme.m b/Examples/test-suite/octave/naturalvar_runme.m new file mode 100644 index 0000000..889563f --- /dev/null +++ b/Examples/test-suite/octave/naturalvar_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/nondynamic_runme.m b/Examples/test-suite/octave/nondynamic_runme.m new file mode 100644 index 0000000..7b3b441 --- /dev/null +++ b/Examples/test-suite/octave/nondynamic_runme.m @@ -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; + diff --git a/Examples/test-suite/octave/null_pointer_runme.m b/Examples/test-suite/octave/null_pointer_runme.m new file mode 100644 index 0000000..51b6eaf --- /dev/null +++ b/Examples/test-suite/octave/null_pointer_runme.m @@ -0,0 +1,3 @@ +null_pointer; + +assert(func([])); diff --git a/Examples/test-suite/octave/octave_cell_deref_runme.m b/Examples/test-suite/octave/octave_cell_deref_runme.m new file mode 100644 index 0000000..5a98c0a --- /dev/null +++ b/Examples/test-suite/octave/octave_cell_deref_runme.m @@ -0,0 +1,8 @@ +octave_cell_deref; + +assert(func("hello")); +assert(func({"hello"})); + +c = func2(); +assert(strcmp(c{1}, "hello")); +assert(c{2} == 4); diff --git a/Examples/test-suite/octave/overload_complicated_runme.m b/Examples/test-suite/octave/overload_complicated_runme.m new file mode 100755 index 0000000..0313be9 --- /dev/null +++ b/Examples/test-suite/octave/overload_complicated_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/overload_copy_runme.m b/Examples/test-suite/octave/overload_copy_runme.m new file mode 100644 index 0000000..b303ba6 --- /dev/null +++ b/Examples/test-suite/octave/overload_copy_runme.m @@ -0,0 +1,3 @@ +overload_copy +f = Foo(); +g = Foo(f); diff --git a/Examples/test-suite/octave/overload_extend_runme.m b/Examples/test-suite/octave/overload_extend_runme.m new file mode 100644 index 0000000..42c7938 --- /dev/null +++ b/Examples/test-suite/octave/overload_extend_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/overload_extendc_runme.m b/Examples/test-suite/octave/overload_extendc_runme.m new file mode 100644 index 0000000..fec586d --- /dev/null +++ b/Examples/test-suite/octave/overload_extendc_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/overload_rename_runme.m b/Examples/test-suite/octave/overload_rename_runme.m new file mode 100644 index 0000000..4a416cf --- /dev/null +++ b/Examples/test-suite/octave/overload_rename_runme.m @@ -0,0 +1,8 @@ +overload_rename + + +f = overload_rename.Foo(1); +f = overload_rename.Foo(1,1); +f = overload_rename.new_Foo_int(1,1); +f = overload_rename.new_Foo_int(1,1,1); + diff --git a/Examples/test-suite/octave/overload_simple_cast_runme.m b/Examples/test-suite/octave/overload_simple_cast_runme.m new file mode 100644 index 0000000..65bc422 --- /dev/null +++ b/Examples/test-suite/octave/overload_simple_cast_runme.m @@ -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); + diff --git a/Examples/test-suite/octave/overload_simple_runme.m b/Examples/test-suite/octave/overload_simple_runme.m new file mode 100644 index 0000000..e980610 --- /dev/null +++ b/Examples/test-suite/octave/overload_simple_runme.m @@ -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); diff --git a/Examples/test-suite/octave/overload_subtype_runme.m b/Examples/test-suite/octave/overload_subtype_runme.m new file mode 100644 index 0000000..b34be97 --- /dev/null +++ b/Examples/test-suite/octave/overload_subtype_runme.m @@ -0,0 +1,13 @@ +overload_subtype + +f = Foo(); +b = Bar(); + +if (spam(f) != 1) + error("foo") +endif + +if (spam(b) != 2) + error("bar") +endif + diff --git a/Examples/test-suite/octave/overload_template_fast_runme.m b/Examples/test-suite/octave/overload_template_fast_runme.m new file mode 100644 index 0000000..f99ce86 --- /dev/null +++ b/Examples/test-suite/octave/overload_template_fast_runme.m @@ -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 = maximum(3,4); +b = maximum(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); diff --git a/Examples/test-suite/octave/overload_template_runme.m b/Examples/test-suite/octave/overload_template_runme.m new file mode 100644 index 0000000..d7b1cbb --- /dev/null +++ b/Examples/test-suite/octave/overload_template_runme.m @@ -0,0 +1,184 @@ +overload_template +f = foo(); + +a = maximum(3,4); +b = maximum(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); diff --git a/Examples/test-suite/octave/preproc_runme.m b/Examples/test-suite/octave/preproc_runme.m new file mode 100644 index 0000000..791b38b --- /dev/null +++ b/Examples/test-suite/octave/preproc_runme.m @@ -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 + diff --git a/Examples/test-suite/octave/primitive_ref_runme.m b/Examples/test-suite/octave/primitive_ref_runme.m new file mode 100644 index 0000000..68a5750 --- /dev/null +++ b/Examples/test-suite/octave/primitive_ref_runme.m @@ -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 diff --git a/Examples/test-suite/octave/primitive_types_runme.m b/Examples/test-suite/octave/primitive_types_runme.m new file mode 100644 index 0000000..568e351 --- /dev/null +++ b/Examples/test-suite/octave/primitive_types_runme.m @@ -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 diff --git a/Examples/test-suite/octave/profiletest_runme.m b/Examples/test-suite/octave/profiletest_runme.m new file mode 100644 index 0000000..d4f07dc --- /dev/null +++ b/Examples/test-suite/octave/profiletest_runme.m @@ -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 diff --git a/Examples/test-suite/octave/refcount_runme.m b/Examples/test-suite/octave/refcount_runme.m new file mode 100644 index 0000000..3ce5bcd --- /dev/null +++ b/Examples/test-suite/octave/refcount_runme.m @@ -0,0 +1,15 @@ +refcount +# +# very innocent example +# + +a = A3(); +b1 = B(a); +b2 = B.create(a); + + +if (a.ref_count() != 3) + error("This program will crash... now") +endif + + diff --git a/Examples/test-suite/octave/reference_global_vars_runme.m b/Examples/test-suite/octave/reference_global_vars_runme.m new file mode 100644 index 0000000..67ad9c5 --- /dev/null +++ b/Examples/test-suite/octave/reference_global_vars_runme.m @@ -0,0 +1,91 @@ +reference_global_vars + +# const class reference variable +if (getconstTC().num != 33) + error +endif + +# primitive reference variables +cvar.var_bool = createref_bool(false); +if (value_bool(cvar.var_bool) != 0) + error +endif + +cvar.var_bool = createref_bool(true); +if (value_bool(cvar.var_bool) != 1) + error +endif + +cvar.var_char = createref_char('w'); +if (!strcmp(value_char(cvar.var_char),'w')) + error +endif + +cvar.var_unsigned_char = createref_unsigned_char(10); +if (value_unsigned_char(cvar.var_unsigned_char) != 10) + error +endif + +cvar.var_signed_char = createref_signed_char(10); +if (value_signed_char(cvar.var_signed_char) != 10) + error +endif + +cvar.var_short = createref_short(10); +if (value_short(cvar.var_short) != 10) + error +endif + +cvar.var_unsigned_short = createref_unsigned_short(10); +if (value_unsigned_short(cvar.var_unsigned_short) != 10) + error +endif + +cvar.var_int = createref_int(10); +if (value_int(cvar.var_int) != 10) + error +endif + +cvar.var_unsigned_int = createref_unsigned_int(10); +if (value_unsigned_int(cvar.var_unsigned_int) != 10) + error +endif + +cvar.var_long = createref_long(10); +if (value_long(cvar.var_long) != 10) + error +endif + +cvar.var_unsigned_long = createref_unsigned_long(10); +if (value_unsigned_long(cvar.var_unsigned_long) != 10) + error +endif + +cvar.var_long_long = createref_long_long(int64(0x6FFFFFFFFFFFFFF8)); +if (value_long_long(cvar.var_long_long) != int64(0x6FFFFFFFFFFFFFF8)) + error +endif + +#ull = abs(0xFFFFFFF2FFFFFFF0) +ull = uint64(55834574864); +cvar.var_unsigned_long_long = createref_unsigned_long_long(ull); +if (value_unsigned_long_long(cvar.var_unsigned_long_long) != ull) + error +endif + +cvar.var_float = createref_float(10.5); +if (value_float(cvar.var_float) != 10.5) + error +endif + +cvar.var_double = createref_double(10.5); +if (value_double(cvar.var_double) != 10.5) + error +endif + +# class reference variable +cvar.var_TestClass = createref_TestClass(TestClass(20)); +if (value_TestClass(cvar.var_TestClass).num != 20) + error +endif + diff --git a/Examples/test-suite/octave/rename_scope_runme.m b/Examples/test-suite/octave/rename_scope_runme.m new file mode 100644 index 0000000..154f99d --- /dev/null +++ b/Examples/test-suite/octave/rename_scope_runme.m @@ -0,0 +1,15 @@ +rename_scope + +a = Natural_UP(); +b = Natural_BP(); + +if (a.rtest() != 1) + error +endif + +if (b.rtest() != 1) + error +endif + +f = @equals; + diff --git a/Examples/test-suite/octave/ret_by_value_runme.m b/Examples/test-suite/octave/ret_by_value_runme.m new file mode 100644 index 0000000..d17c9f2 --- /dev/null +++ b/Examples/test-suite/octave/ret_by_value_runme.m @@ -0,0 +1,10 @@ +ret_by_value + +a = ret_by_value.get_test(); +if (a.myInt != 100) + error +endif + +if (a.myShort != 200) + error +endif diff --git a/Examples/test-suite/octave/return_const_value_runme.m b/Examples/test-suite/octave/return_const_value_runme.m new file mode 100644 index 0000000..1219c92 --- /dev/null +++ b/Examples/test-suite/octave/return_const_value_runme.m @@ -0,0 +1,11 @@ +return_const_value + +p = return_const_value.Foo_ptr.getPtr(); +if (p.getVal() != 17) + error("Runtime test1 faild. p.getVal()=", p.getVal()) +endif + +p = return_const_value.Foo_ptr.getConstPtr(); +if (p.getVal() != 17) + error("Runtime test2 faild. p.getVal()=", p.getVal()) +endif diff --git a/Examples/test-suite/octave/smart_pointer_extend_runme.m b/Examples/test-suite/octave/smart_pointer_extend_runme.m new file mode 100644 index 0000000..c30cd9f --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_extend_runme.m @@ -0,0 +1,41 @@ +smart_pointer_extend + +f = Foo(); +b = Bar(f); + +if (b.extension() != f.extension()) + error +endif + + +b = CBase(); +d = CDerived(); +p = CPtr(); + +if (b.bar() != p.bar()) + error +endif + +if (d.foo() != p.foo()) + error +endif + +if (b.hello() != p.hello()) + error +endif + + + +d = DFoo(); + +dp = DPtrFoo(d); + +if (d.SExt(1) != dp.SExt(1)) + error +endif + +if (d.Ext(1) != dp.Ext(1)) + error +endif + + diff --git a/Examples/test-suite/octave/smart_pointer_member_runme.m b/Examples/test-suite/octave/smart_pointer_member_runme.m new file mode 100644 index 0000000..30251c3 --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_member_runme.m @@ -0,0 +1,39 @@ +smart_pointer_member + +f = Foo(); +f.y = 1; + +if (f.y != 1) + error +endif + +b = Bar(f); +b.y = 2; + +if (f.y != 2) + error("f.y = %i, b.y = %i",f.y,b.y) +endif + +if (swig_this(b.x) != swig_this(f.x)) + error +endif + +if (b.z != f.z) + error +endif + +try + if (Foo.z == Bar.z) + error + endif + error +catch +end_try_catch + + + + + + + + diff --git a/Examples/test-suite/octave/smart_pointer_multi_runme.m b/Examples/test-suite/octave/smart_pointer_multi_runme.m new file mode 100644 index 0000000..71ef910 --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_multi_runme.m @@ -0,0 +1,17 @@ +smart_pointer_multi + +f = Foo(); +b = Bar(f); +s = Spam(b); +g = Grok(b); + +s.x = 3; +if (s.getx() != 3) + error +endif + +g.x = 4; +if (g.getx() != 4) + error +endif + diff --git a/Examples/test-suite/octave/smart_pointer_multi_typedef_runme.m b/Examples/test-suite/octave/smart_pointer_multi_typedef_runme.m new file mode 100644 index 0000000..4b77e0e --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_multi_typedef_runme.m @@ -0,0 +1,18 @@ +smart_pointer_multi_typedef + +f = Foo(); +b = Bar(f); +s = Spam(b); +g = Grok(b); + +s.x = 3; +if (s.getx() != 3) + error +endif + +g.x = 4; +if (g.getx() != 4) + error +endif + + diff --git a/Examples/test-suite/octave/smart_pointer_not_runme.m b/Examples/test-suite/octave/smart_pointer_not_runme.m new file mode 100644 index 0000000..8b3fea8 --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_not_runme.m @@ -0,0 +1,42 @@ +smart_pointer_not + +f = Foo(); +b = Bar(f); +s = Spam(f); +g = Grok(f); + +try + x = b.x; + error("Error! b.x") +catch +end_try_catch + +try + x = s.x; + error("Error! s.x") +catch +end_try_catch + +try + x = g.x; + error("Error! g.x") +catch +end_try_catch + +try + x = b.getx(); + error("Error! b.getx()") +catch +end_try_catch + +try + x = s.getx(); + error("Error! s.getx()") +catch +end_try_catch + +try + x = g.getx(); + error("Error! g.getx()") +catch +end_try_catch diff --git a/Examples/test-suite/octave/smart_pointer_overload_runme.m b/Examples/test-suite/octave/smart_pointer_overload_runme.m new file mode 100644 index 0000000..214437d --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_overload_runme.m @@ -0,0 +1,27 @@ +smart_pointer_overload + +f = Foo(); +b = Bar(f); + + +if (f.test(3) != 1) + error +endif +if (f.test(3.5) != 2) + error +endif +if (f.test("hello") != 3) + error +endif + +if (b.test(3) != 1) + error +endif +if (b.test(3.5) != 2) + error +endif +if (b.test("hello") != 3) + error +endif + + diff --git a/Examples/test-suite/octave/smart_pointer_rename_runme.m b/Examples/test-suite/octave/smart_pointer_rename_runme.m new file mode 100644 index 0000000..260ee3e --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_rename_runme.m @@ -0,0 +1,17 @@ +smart_pointer_rename + +f = Foo(); +b = Bar(f); + +if (b.test() != 3) + error +endif + +if (b.ftest1(1) != 1) + error +endif + +if (b.ftest2(2,3) != 2) + error +endif + diff --git a/Examples/test-suite/octave/smart_pointer_simple_runme.m b/Examples/test-suite/octave/smart_pointer_simple_runme.m new file mode 100644 index 0000000..26f32e0 --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_simple_runme.m @@ -0,0 +1,15 @@ +smart_pointer_simple + +f = Foo(); +b = Bar(f); + +b.x = 3; +if (b.getx() != 3) + error +endif + +fp = b.__deref__(); +fp.x = 4; +if (fp.getx() != 4) + error +endif diff --git a/Examples/test-suite/octave/smart_pointer_templatevariables_runme.m b/Examples/test-suite/octave/smart_pointer_templatevariables_runme.m new file mode 100644 index 0000000..4884fa2 --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_templatevariables_runme.m @@ -0,0 +1,19 @@ +smart_pointer_templatevariables + +d = DiffImContainerPtr_D(create(1234, 5678)); + +if (d.id != 1234) + error +endif +#if (d.xyz != 5678): +# error + +d.id = 4321; +#d.xyz = 8765 + +if (d.id != 4321) + error +endif +#if (d.xyz != 8765): +# error + diff --git a/Examples/test-suite/octave/smart_pointer_typedef_runme.m b/Examples/test-suite/octave/smart_pointer_typedef_runme.m new file mode 100644 index 0000000..8fa6ca2 --- /dev/null +++ b/Examples/test-suite/octave/smart_pointer_typedef_runme.m @@ -0,0 +1,15 @@ +smart_pointer_typedef + +f = Foo(); +b = Bar(f); + +b.x = 3; +if (b.getx() != 3) + error +endif + +fp = b.__deref__(); +fp.x = 4; +if (fp.getx() != 4) + error +endif diff --git a/Examples/test-suite/octave/sneaky1_runme.m b/Examples/test-suite/octave/sneaky1_runme.m new file mode 100644 index 0000000..e044370 --- /dev/null +++ b/Examples/test-suite/octave/sneaky1_runme.m @@ -0,0 +1,5 @@ +sneaky1 +x = sneaky1.add(3,4); +y = sneaky1.subtract(3,4); +z = sneaky1.mul(3,4); +w = sneaky1.divide(3,4); diff --git a/Examples/test-suite/octave/static_const_member_2_runme.m b/Examples/test-suite/octave/static_const_member_2_runme.m new file mode 100644 index 0000000..b242bfc --- /dev/null +++ b/Examples/test-suite/octave/static_const_member_2_runme.m @@ -0,0 +1,18 @@ +static_const_member_2 + +c = Test_int(); +try + a = c.forward_field; + a = c.current_profile; + a = c.RightIndex; + a = Test_int.backward_field; + a = Test_int.LeftIndex; + a = Test_int.cavity_flags; +catch +end_try_catch + + +if (Foo.BAZ.val != 2*Foo.BAR.val) + error +endif + diff --git a/Examples/test-suite/octave/std_containers_runme.m b/Examples/test-suite/octave/std_containers_runme.m new file mode 100644 index 0000000..074f0fd --- /dev/null +++ b/Examples/test-suite/octave/std_containers_runme.m @@ -0,0 +1,135 @@ +std_containers + + +cube = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}; + +icube = std_containers.cident(cube); +for i=len(cube), + if (cube{i} != icube{i}) + error("bad cident") + endif +endfor + + +p = {1,2}; +if (p != std_containers.pident(p)) + error("bad pident") +endif + +v = {1,2,3,4,5,6}; +iv = std_containers.vident(v); +for i=0:len(v), + if (v{i} != iv{i}) + error("bad vident") + endif +endfor + + +iv = std_containers.videntu(v); +for i=0:len(v), + if (v{i} != iv{i}) + error("bad videntu") + endif +endfor + + +vu = std_containers.vector_ui(v); +if (vu{2} != std_containers.videntu(vu){2}) + error("bad videntu") +endif + + +if (v(0:3)(1) != vu(0:3)(1)) + error("bad getslice") +endif + + +m = {[1,2,3],[2,3],[3,4]}; +im = std_containers.midenti(m); + +for i=0:len(m), + for j=0:len(m(i)), + if (m(i)(j) != im(i)(j)) + error("bad getslice") + endif + endfor +endfor + +m = {[1,0,1],[1,1],[1,1]}; +im = std_containers.midentb(m); +for i=0:len(m), + for j in range(0,len(m[i])): + if (m(i)(j) != im(i)(j)) + error("bad getslice") + endif + endfor +endfor + + +mi = std_containers.imatrix(m); +mc = std_containers.cmatrix(m); +if (mi(0)(1) != mc(0)(1)) + error("bad matrix") +endif + + +map ={}; +map{'hello'} = 1; +map{'hi'} = 2; +map{'3'} = 2; + +imap = std_containers.mapident(map); +for k in map, + if (map(k) != imap(k)) + error("bad map") + endif +endfor + + +mapc ={}; +c1 = std_containers.C(); +c2 = std_containers.C(); +mapc(1) = swig_this(c1); +mapc(2) = c2; + +std_containers.mapidentc(mapc); + + +vi = std_containers.vector_i([2,2,3,4]); + + +v = [1,2]; +v1 = std_containers.v_inout(vi); +vi(1), v1(1); + +[v1,v2] = std_containers.v_inout2(v1,v2); + +a1 = std_containers.A(1); +a2 = std_containers.A(2); + +p1 = {1,a1}; +p2 = {2,a2}; +v = (p1,p2); +v2= std_containers.pia_vident(v); + +v2(0)(1).a; +v2(1)(1).a; + +v3 = std_containers.vector_piA(v2); + +v3(0)(1).a; +v3(1)(1).a; + +s = std_containers.set_i(); +s.append(1); +s.append(2); +s.append(3); +j=1; +for i in s, + if (i != j) + error + endif + j = j + 1; +endfor + + diff --git a/Examples/test-suite/octave/struct_rename_runme.m b/Examples/test-suite/octave/struct_rename_runme.m new file mode 100644 index 0000000..1b57d8f --- /dev/null +++ b/Examples/test-suite/octave/struct_rename_runme.m @@ -0,0 +1,4 @@ +struct_rename + +b = struct_rename.Bar(); + diff --git a/Examples/test-suite/octave/struct_value_runme.m b/Examples/test-suite/octave/struct_value_runme.m new file mode 100644 index 0000000..7340a36 --- /dev/null +++ b/Examples/test-suite/octave/struct_value_runme.m @@ -0,0 +1,13 @@ +struct_value + +b = struct_value.Bar(); + +b.a.x = 3; +if (b.a.x != 3) + error +endif + +b.b.x = 3; +if (b.b.x != 3) + error +endif diff --git a/Examples/test-suite/octave/swigobject_runme.m b/Examples/test-suite/octave/swigobject_runme.m new file mode 100644 index 0000000..614e2a4 --- /dev/null +++ b/Examples/test-suite/octave/swigobject_runme.m @@ -0,0 +1,28 @@ +swigobject + +a = A(); + +a1 = a_ptr(a); +a2 = a_ptr(a); + +if (swig_this(a1) != swig_this(a2)) + error +endif + + +lthis = uint64(swig_this(a.this)); +xstr1 = printf("0x%x",lthis); +xstr2 = pointer_str(a); + +if (xstr1 != xstr2) + error +endif + +s = str(a.this); +r = repr(a.this); + +v1 = v_ptr(a); +v2 = v_ptr(a); +if (uint64(v1) != uint64(v2)) + error +endif diff --git a/Examples/test-suite/octave/template_construct_runme.m b/Examples/test-suite/octave/template_construct_runme.m new file mode 100644 index 0000000..2ed0664 --- /dev/null +++ b/Examples/test-suite/octave/template_construct_runme.m @@ -0,0 +1 @@ +template_construct diff --git a/Examples/test-suite/octave/template_default_arg_runme.m b/Examples/test-suite/octave/template_default_arg_runme.m new file mode 100644 index 0000000..e500662 --- /dev/null +++ b/Examples/test-suite/octave/template_default_arg_runme.m @@ -0,0 +1,117 @@ +template_default_arg + + +helloInt = template_default_arg.Hello_int(); +helloInt.foo(template_default_arg.Hello_int_hi); + + +x = template_default_arg.X_int(); +if (x.meth(20.0, 200) != 200) + error("X_int test 1 failed") +endif +if (x.meth(20) != 20) + error("X_int test 2 failed") +endif +if (x.meth() != 0) + error("X_int test 3 failed") +endif + + + +y = template_default_arg.Y_unsigned(); +if (y.meth(20.0, 200) != 200) + error("Y_unsigned test 1 failed") +endif +if (y.meth(20) != 20) + error("Y_unsigned test 2 failed") +endif +if (y.meth() != 0) + error("Y_unsigned test 3 failed") +endif + + + +x = template_default_arg.X_longlong(); +x = template_default_arg.X_longlong(20.0); +x = template_default_arg.X_longlong(20.0, 200); + + +x = template_default_arg.X_int(); +x = template_default_arg.X_int(20.0); +x = template_default_arg.X_int(20.0, 200); + + +x = template_default_arg.X_hello_unsigned(); +x = template_default_arg.X_hello_unsigned(20.0); +x = template_default_arg.X_hello_unsigned(20.0, template_default_arg.Hello_int()); + + +y = template_default_arg.Y_hello_unsigned(); +y.meth(20.0, template_default_arg.Hello_int()); +y.meth(template_default_arg.Hello_int()); +y.meth(); + + + +fz = template_default_arg.Foo_Z_8(); +x = template_default_arg.X_Foo_Z_8(); +fzc = x.meth(fz); + + +# Templated functions + +# plain function: int ott(Foo<int>) +if (template_default_arg.ott(template_default_arg.Foo_int()) != 30) + error("ott test 1 failed") +endif + +# %template(ott) ott<int, int> +if (template_default_arg.ott() != 10) + error("ott test 2 failed") +endif +if (template_default_arg.ott(1) != 10) + error("ott test 3 failed") +endif +if (template_default_arg.ott(1, 1) != 10) + error("ott test 4 failed") +endif + +if (template_default_arg.ott("hi") != 20) + error("ott test 5 failed") +endif +if (template_default_arg.ott("hi", 1) != 20) + error("ott test 6 failed") +endif +if (template_default_arg.ott("hi", 1, 1) != 20) + error("ott test 7 failed") +endif + +# %template(ott) ott<const char *> +if (template_default_arg.ottstring(template_default_arg.Hello_int(), "hi") != 40) + error("ott test 8 failed") +endif + +if (template_default_arg.ottstring(template_default_arg.Hello_int()) != 40) + error("ott test 9 failed") +endif + +# %template(ott) ott<int> +if (template_default_arg.ottint(template_default_arg.Hello_int(), 1) != 50) + error("ott test 10 failed") +endif + +if (template_default_arg.ottint(template_default_arg.Hello_int()) != 50) + error("ott test 11 failed") +endif + +# %template(ott) ott<double> +if (template_default_arg.ott(template_default_arg.Hello_int(), 1.0) != 60) + error("ott test 12 failed") +endif + +if (template_default_arg.ott(template_default_arg.Hello_int()) != 60) + error("ott test 13 failed") +endif + + + diff --git a/Examples/test-suite/octave/template_extend1_runme.m b/Examples/test-suite/octave/template_extend1_runme.m new file mode 100644 index 0000000..e672da7 --- /dev/null +++ b/Examples/test-suite/octave/template_extend1_runme.m @@ -0,0 +1,12 @@ +template_extend1 + +a = template_extend1.lBaz(); +b = template_extend1.dBaz(); + +if (!strcmp(a.foo(),"lBaz::foo")) + error +endif + +if (!strcmp(b.foo(),"dBaz::foo")) + error +endif diff --git a/Examples/test-suite/octave/template_extend2_runme.m b/Examples/test-suite/octave/template_extend2_runme.m new file mode 100644 index 0000000..93c44d7 --- /dev/null +++ b/Examples/test-suite/octave/template_extend2_runme.m @@ -0,0 +1,12 @@ +template_extend2 + +a = template_extend2.lBaz(); +b = template_extend2.dBaz(); + +if (!strcmp(a.foo(),"lBaz::foo")) + error +endif + +if (!strcmp(b.foo(),"dBaz::foo")) + error +endif diff --git a/Examples/test-suite/octave/template_inherit_runme.m b/Examples/test-suite/octave/template_inherit_runme.m new file mode 100644 index 0000000..ce7931e --- /dev/null +++ b/Examples/test-suite/octave/template_inherit_runme.m @@ -0,0 +1,68 @@ +template_inherit +a = FooInt(); +b = FooDouble(); +c = BarInt(); +d = BarDouble(); +e = FooUInt(); +f = BarUInt(); + +if (!strcmp(a.blah(),"Foo")) + error +endif + +if (!strcmp(b.blah(),"Foo")) + error +endif + +if (!strcmp(e.blah(),"Foo")) + error +endif + +if (!strcmp(c.blah(),"Bar")) + error +endif + +if (!strcmp(d.blah(),"Bar")) + error +endif + +if (!strcmp(f.blah(),"Bar")) + error +endif + +if (!strcmp(c.foomethod(),"foomethod")) + error +endif + +if (!strcmp(d.foomethod(),"foomethod")) + error +endif + +if (!strcmp(f.foomethod(),"foomethod")) + error +endif + +if (!strcmp(invoke_blah_int(a),"Foo")) + error +endif + +if (!strcmp(invoke_blah_int(c),"Bar")) + error +endif + +if (!strcmp(invoke_blah_double(b),"Foo")) + error +endif + +if (!strcmp(invoke_blah_double(d),"Bar")) + error +endif + +if (!strcmp(invoke_blah_uint(e),"Foo")) + error +endif + +if (!strcmp(invoke_blah_uint(f),"Bar")) + error +endif + diff --git a/Examples/test-suite/octave/template_matrix_runme.m b/Examples/test-suite/octave/template_matrix_runme.m new file mode 100644 index 0000000..b8fb3d3 --- /dev/null +++ b/Examples/test-suite/octave/template_matrix_runme.m @@ -0,0 +1,6 @@ +template_matrix +passVector([1,2,3]); +passMatrix({[1,2],[1,2,3]}); +passCube({{[1,2],[1,2,3]},{[1,2],[1,2,3]}}); + + diff --git a/Examples/test-suite/octave/template_ns4_runme.m b/Examples/test-suite/octave/template_ns4_runme.m new file mode 100644 index 0000000..58ced7c --- /dev/null +++ b/Examples/test-suite/octave/template_ns4_runme.m @@ -0,0 +1,6 @@ +template_ns4 + +d = make_Class_DD(); +if (!strcmp(d.test(),"test")) + error +endif diff --git a/Examples/test-suite/octave/template_ns_runme.m b/Examples/test-suite/octave/template_ns_runme.m new file mode 100644 index 0000000..29a2f53 --- /dev/null +++ b/Examples/test-suite/octave/template_ns_runme.m @@ -0,0 +1,21 @@ +template_ns +p1 = pairii(2,3); +p2 = pairii(p1); + +if (p2.first != 2) + error +endif +if (p2.second != 3) + error +endif + +p3 = pairdd(3.5,2.5); +p4 = pairdd(p3); + +if (p4.first != 3.5) + error +endif + +if (p4.second != 2.5) + error +endif diff --git a/Examples/test-suite/octave/template_opaque_runme.m b/Examples/test-suite/octave/template_opaque_runme.m new file mode 100644 index 0000000..1c123b3 --- /dev/null +++ b/Examples/test-suite/octave/template_opaque_runme.m @@ -0,0 +1,7 @@ +template_opaque + +v = template_opaque.OpaqueVectorType(10); + +template_opaque.FillVector(v); + + diff --git a/Examples/test-suite/octave/template_ref_type_runme.m b/Examples/test-suite/octave/template_ref_type_runme.m new file mode 100644 index 0000000..ef77e06 --- /dev/null +++ b/Examples/test-suite/octave/template_ref_type_runme.m @@ -0,0 +1,5 @@ +template_ref_type + +xr = template_ref_type.XC(); +y = template_ref_type.Y(); +y.find(xr); diff --git a/Examples/test-suite/octave/template_rename_runme.m b/Examples/test-suite/octave/template_rename_runme.m new file mode 100644 index 0000000..7cb5493 --- /dev/null +++ b/Examples/test-suite/octave/template_rename_runme.m @@ -0,0 +1,12 @@ +template_rename + +i = template_rename.iFoo(); +d = template_rename.dFoo(); + +a = i.blah_test(4); +b = i.spam_test(5); +c = i.groki_test(6); + +x = d.blah_test(7); +y = d.spam(8); +z = d.grok_test(9); diff --git a/Examples/test-suite/octave/template_static_runme.m b/Examples/test-suite/octave/template_static_runme.m new file mode 100644 index 0000000..c54139a --- /dev/null +++ b/Examples/test-suite/octave/template_static_runme.m @@ -0,0 +1,3 @@ +template_static + +Foo_bar_double(1); diff --git a/Examples/test-suite/octave/template_tbase_template_runme.m b/Examples/test-suite/octave/template_tbase_template_runme.m new file mode 100644 index 0000000..da8ec4c --- /dev/null +++ b/Examples/test-suite/octave/template_tbase_template_runme.m @@ -0,0 +1,6 @@ +template_tbase_template + +a = make_Class_dd(); +if (!strcmp(a.test(),"test")) + error +endif diff --git a/Examples/test-suite/octave/template_type_namespace_runme.m b/Examples/test-suite/octave/template_type_namespace_runme.m new file mode 100644 index 0000000..bbdcdef --- /dev/null +++ b/Examples/test-suite/octave/template_type_namespace_runme.m @@ -0,0 +1,5 @@ +template_type_namespace + +assert(strcmp(foo()(1),"foo")); + + diff --git a/Examples/test-suite/octave/template_typedef_cplx2_runme.m b/Examples/test-suite/octave/template_typedef_cplx2_runme.m new file mode 100644 index 0000000..94d3beb --- /dev/null +++ b/Examples/test-suite/octave/template_typedef_cplx2_runme.m @@ -0,0 +1,103 @@ +template_typedef_cplx2 + +# +# double case +# + +try + d = make_Identity_double(); + a = swig_this(d); +catch + d + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(d)) != 1) + d + error("is not an ArithUnaryFunction") + error +endif + +try + e = make_Multiplies_double_double_double_double(d, d); + a = swig_this(e); +catch + e + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(e)) != 1) + e + error("is not an ArithUnaryFunction") +endif + + +# +# complex case +# + +try + c = make_Identity_complex(); + a = swig_this(c); +catch + c + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(c)) != 1) + c + error("is not an ArithUnaryFunction") +endif + +try + f = make_Multiplies_complex_complex_complex_complex(c, c); + a = swig_this(f); +catch + f + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(f)) != 1) + f + error("is not an ArithUnaryFunction") +endif + +# +# Mix case +# + +try + g = make_Multiplies_double_double_complex_complex(d, c); + a = swig_this(g); +catch + g + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(g)) != 1) + g + error("is not an ArithUnaryFunction") + error +endif + + +try + h = make_Multiplies_complex_complex_double_double(c, d); + a = swig_this(h); +catch + h + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(h)) == -1) + h + error("is not an ArithUnaryFunction") +endif + +try + a = g.get_value(); +catch + error(g, "has not get_value() method") + error +end_try_catch + diff --git a/Examples/test-suite/octave/template_typedef_cplx3_runme.m b/Examples/test-suite/octave/template_typedef_cplx3_runme.m new file mode 100644 index 0000000..d21f279 --- /dev/null +++ b/Examples/test-suite/octave/template_typedef_cplx3_runme.m @@ -0,0 +1,34 @@ +template_typedef_cplx3 + +# +# this is OK +# + + +s = Sin(); +s.get_base_value(); +s.get_value(); +s.get_arith_value(); +my_func_r(s); +make_Multiplies_double_double_double_double(s,s); + +z = CSin(); +z.get_base_value(); +z.get_value(); +z.get_arith_value(); +my_func_c(z); +make_Multiplies_complex_complex_complex_complex(z,z); + +# +# Here we fail +# +d = make_Identity_double(); +my_func_r(d); + +c = make_Identity_complex(); +my_func_c(c); + + + + + diff --git a/Examples/test-suite/octave/template_typedef_cplx4_runme.m b/Examples/test-suite/octave/template_typedef_cplx4_runme.m new file mode 100644 index 0000000..4db276d --- /dev/null +++ b/Examples/test-suite/octave/template_typedef_cplx4_runme.m @@ -0,0 +1,33 @@ +template_typedef_cplx4 + +# +# this is OK +# + + +s = Sin(); +s.get_base_value(); +s.get_value(); +s.get_arith_value(); +my_func_r(s); +make_Multiplies_double_double_double_double(s,s); + +z = CSin(); +z.get_base_value(); +z.get_value(); +z.get_arith_value(); +my_func_c(z); +make_Multiplies_complex_complex_complex_complex(z,z); + +# +# Here we fail +# +d = make_Identity_double(); +my_func_r(d); + +c = make_Identity_complex(); +my_func_c(c); + + + + diff --git a/Examples/test-suite/octave/template_typedef_cplx_runme.m b/Examples/test-suite/octave/template_typedef_cplx_runme.m new file mode 100644 index 0000000..d00981c --- /dev/null +++ b/Examples/test-suite/octave/template_typedef_cplx_runme.m @@ -0,0 +1,92 @@ +template_typedef_cplx + +# +# double case +# + +try + d = make_Identity_double(); + a = swig_this(d); +catch + d + error("is not an instance") +end_try_catch + +if (findstr("ArithUnaryFunction",swig_type(d)) != 1) + d + error("is not an ArithUnaryFunction") +endif + +try + e = make_Multiplies_double_double_double_double(d, d); + a = swig_this(e); +catch + error(e, "is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(e)) != 1); + c + error("is not an ArithUnaryFunction") +endif + + +# +# complex case +# + +try + c = make_Identity_complex(); + a = swig_this(c); +catch + c + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(c)) != 1) + c + error("is not an ArithUnaryFunction") +endif + +try + f = make_Multiplies_complex_complex_complex_complex(c, c); + a = swig_this(f); +catch + f + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(f)) != 1) + f + error("is not an ArithUnaryFunction") +endif + +# +# Mix case +# + +try + g = make_Multiplies_double_double_complex_complex(d, c); + a = swig_this(g); +catch + g + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(g)) != 1) + g + error("is not an ArithUnaryFunction") +endif + + +try + h = make_Multiplies_complex_complex_double_double(c, d); + a = swig_this(h); +catch + h + error("is not an instance") +end_try_catch + +if (findstr('ArithUnaryFunction',swig_type(h)) != 1) + h + error("is not an ArithUnaryFunction") +endif diff --git a/Examples/test-suite/octave/template_typedef_import_runme.m b/Examples/test-suite/octave/template_typedef_import_runme.m new file mode 100644 index 0000000..0574ab1 --- /dev/null +++ b/Examples/test-suite/octave/template_typedef_import_runme.m @@ -0,0 +1,34 @@ +template_typedef_cplx2 +template_typedef_import + +# +# this is OK +# + + +s = Sin(); +s.get_base_value(); +s.get_value(); +s.get_arith_value(); +my_func_r(s); +make_Multiplies_double_double_double_double(s,s); + +z = CSin(); +z.get_base_value(); +z.get_value(); +z.get_arith_value(); +my_func_c(z); +make_Multiplies_complex_complex_complex_complex(z,z); + +# +# Here we fail +# +d = make_Identity_double(); +my_func_r(d); + +c = make_Identity_complex(); +my_func_c(c); + + + + diff --git a/Examples/test-suite/octave/template_typedef_runme.m b/Examples/test-suite/octave/template_typedef_runme.m new file mode 100644 index 0000000..8d8af79 --- /dev/null +++ b/Examples/test-suite/octave/template_typedef_runme.m @@ -0,0 +1,51 @@ +template_typedef + +d = make_Identity_float(); +c = make_Identity_reald(); + + +try + a = swig_this(d); + a = swig_this(c); +catch + error +end_try_catch + +try + e = make_Multiplies_float_float_float_float(d, d); + a = swig_this(e); +catch + e + error("is not an instance") +end_try_catch + +try + f = make_Multiplies_reald_reald_reald_reald(c, c); + a = swig_this(f); +catch + f + error("is not an instance"); +end_try_catch + +try + g = make_Multiplies_float_float_reald_reald(d, c); + a = swig_this(g); +catch + error(g, "is not an instance") +end_try_catch + + +# the old large format +if (strcmp("<unknown>",swig_typequery("vfncs::ArithUnaryFunction<vfncs::arith_traits<float,double>::argument_type,vfncs::arith_traits<float,double >::result_type > *"))) + error +endif + +# the reduced format +if (strcmp("<unknown>",swig_typequery("vfncs::ArithUnaryFunction<double,double> *"))) + error +endif + +# this is a bad name +if (!strcmp("<unknown>",swig_typequery("vfncs::ArithUnaryFunction<double,doublex> *"))) + error +endif diff --git a/Examples/test-suite/octave/typedef_class_runme.m b/Examples/test-suite/octave/typedef_class_runme.m new file mode 100644 index 0000000..97d2aed --- /dev/null +++ b/Examples/test-suite/octave/typedef_class_runme.m @@ -0,0 +1,7 @@ +typedef_class + +a = typedef_class.RealA(); +a.a = 3; + +b = typedef_class.B(); +b.testA(a); diff --git a/Examples/test-suite/octave/typedef_inherit_runme.m b/Examples/test-suite/octave/typedef_inherit_runme.m new file mode 100644 index 0000000..6c4c47a --- /dev/null +++ b/Examples/test-suite/octave/typedef_inherit_runme.m @@ -0,0 +1,27 @@ +typedef_inherit + +a = typedef_inherit.Foo(); +b = typedef_inherit.Bar(); + +x = typedef_inherit.do_blah(a); +if (!strcmp(x,"Foo::blah")) + error("Whoa! Bad return", x) +endif + +x = typedef_inherit.do_blah(b); +if (!strcmp(x,"Bar::blah")) + error("Whoa! Bad return", x) +endif + +c = typedef_inherit.Spam(); +d = typedef_inherit.Grok(); + +x = typedef_inherit.do_blah2(c); +if (!strcmp(x,"Spam::blah")) + error("Whoa! Bad return", x) +endif + +x = typedef_inherit.do_blah2(d); +if (!strcmp(x,"Grok::blah")) + error("Whoa! Bad return", x) +endif diff --git a/Examples/test-suite/octave/typedef_scope_runme.m b/Examples/test-suite/octave/typedef_scope_runme.m new file mode 100644 index 0000000..9e6d101 --- /dev/null +++ b/Examples/test-suite/octave/typedef_scope_runme.m @@ -0,0 +1,14 @@ +typedef_scope + +b = typedef_scope.Bar(); +x = b.test1(42,"hello"); +if (x != 42) + error("Failed!!") +endif + +x = b.test2(42,"hello"); +if (!strcmp(x,"hello")) + error("Failed!!") +endif + + diff --git a/Examples/test-suite/octave/typemap_namespace_runme.m b/Examples/test-suite/octave/typemap_namespace_runme.m new file mode 100644 index 0000000..ec62a39 --- /dev/null +++ b/Examples/test-suite/octave/typemap_namespace_runme.m @@ -0,0 +1,10 @@ +typemap_namespace + +if (!strcmp(test1("hello"),"hello")) + error +endif + +if (!strcmp(test2("hello"),"hello")) + error +endif + diff --git a/Examples/test-suite/octave/typemap_ns_using_runme.m b/Examples/test-suite/octave/typemap_ns_using_runme.m new file mode 100644 index 0000000..dd3f657 --- /dev/null +++ b/Examples/test-suite/octave/typemap_ns_using_runme.m @@ -0,0 +1,5 @@ +typemap_ns_using + +if (typemap_ns_using.spam(37) != 37) + error +endif diff --git a/Examples/test-suite/octave/typename_runme.m b/Examples/test-suite/octave/typename_runme.m new file mode 100644 index 0000000..c47f817 --- /dev/null +++ b/Examples/test-suite/octave/typename_runme.m @@ -0,0 +1,13 @@ +typename +f = typename.Foo(); +b = typename.Bar(); + +x = typename.twoFoo(f); +if (x == floor(x)) + error("Wrong return type!") +endif +y = typename.twoBar(b); +if (y != floor(y)) + error("Wrong return type!") +endif + diff --git a/Examples/test-suite/octave/types_directive_runme.m b/Examples/test-suite/octave/types_directive_runme.m new file mode 100644 index 0000000..0757c6c --- /dev/null +++ b/Examples/test-suite/octave/types_directive_runme.m @@ -0,0 +1,15 @@ +types_directive + +d1 = Time1(2001, 2, 3, 60); +newDate = add(d1, 7); # check that a Time1 instance is accepted where Date is expected +if (newDate.day != 10) + error +endif + +d2 = Time2(1999, 8, 7, 60); +newDate = add(d2, 7); # check that a Time2 instance is accepted where Date is expected +if (newDate.day != 14) + error +endif + + diff --git a/Examples/test-suite/octave/unions_runme.m b/Examples/test-suite/octave/unions_runme.m new file mode 100644 index 0000000..05ac252 --- /dev/null +++ b/Examples/test-suite/octave/unions_runme.m @@ -0,0 +1,49 @@ + +# This is the union runtime testcase. It ensures that values within a +# union embedded within a struct can be set and read correctly. + +unions + +# Create new instances of SmallStruct and BigStruct for later use +small = unions.SmallStruct(); +small.jill = 200; + +big = unions.BigStruct(); +big.smallstruct = small; +big.jack = 300; + +# Use SmallStruct then BigStruct to setup EmbeddedUnionTest. +# Ensure values in EmbeddedUnionTest are set correctly for each. +eut = unions.EmbeddedUnionTest(); + +# First check the SmallStruct in EmbeddedUnionTest +eut.number = 1; +eut.uni.small = small; +Jill1 = eut.uni.small.jill; +if (Jill1 != 200) + error("Runtime test1 failed. eut.uni.small.jill=%i" , Jill1) +endif + +Num1 = eut.number; +if (Num1 != 1) + error("Runtime test2 failed. eut.number=%i" , Num1) +endif + +# Secondly check the BigStruct in EmbeddedUnionTest +eut.number = 2; +eut.uni.big = big; +Jack1 = eut.uni.big.jack; +if (Jack1 != 300) + error("Runtime test3 failed. eut.uni.big.jack=%i" , Jack1) +endif + +Jill2 = eut.uni.big.smallstruct.jill; +if (Jill2 != 200) + error("Runtime test4 failed. eut.uni.big.smallstruct.jill=%i" , Jill2) +endif + +Num2 = eut.number; +if (Num2 != 2) + error("Runtime test5 failed. eut.number=%i" , Num2) +endif + diff --git a/Examples/test-suite/octave/using1_runme.m b/Examples/test-suite/octave/using1_runme.m new file mode 100644 index 0000000..0c37daf --- /dev/null +++ b/Examples/test-suite/octave/using1_runme.m @@ -0,0 +1,5 @@ +using1 + +if (using1.spam(37) != 37) + error +endif diff --git a/Examples/test-suite/octave/using2_runme.m b/Examples/test-suite/octave/using2_runme.m new file mode 100644 index 0000000..205c6d7 --- /dev/null +++ b/Examples/test-suite/octave/using2_runme.m @@ -0,0 +1,5 @@ +using2 + +if (using2.spam(37) != 37) + error +endif diff --git a/Examples/test-suite/octave/using_composition_runme.m b/Examples/test-suite/octave/using_composition_runme.m new file mode 100644 index 0000000..9b58d6d --- /dev/null +++ b/Examples/test-suite/octave/using_composition_runme.m @@ -0,0 +1,43 @@ +using_composition + +f = FooBar(); +if (f.blah(3) != 3) + error("FooBar::blah(int)") +endif + +if (f.blah(3.5) != 3.5) + error("FooBar::blah(double)") +endif + +if (!strcmp(f.blah("hello"),"hello")) + error("FooBar::blah(char *)") +endif + + +f = FooBar2(); +if (f.blah(3) != 3) + error("FooBar2::blah(int)") +endif + +if (f.blah(3.5) != 3.5) + error("FooBar2::blah(double)") +endif + +if (!strcmp(f.blah("hello"),"hello")) + error("FooBar2::blah(char *)") +endif + + +f = FooBar3(); +if (f.blah(3) != 3) + error("FooBar3::blah(int)") +endif + +if (f.blah(3.5) != 3.5) + error("FooBar3::blah(double)") +endif + +if (!strcmp(f.blah("hello"),"hello")) + error("FooBar3::blah(char *)") +endif + diff --git a/Examples/test-suite/octave/using_extend_runme.m b/Examples/test-suite/octave/using_extend_runme.m new file mode 100644 index 0000000..b9c13fa --- /dev/null +++ b/Examples/test-suite/octave/using_extend_runme.m @@ -0,0 +1,27 @@ +using_extend + +f = FooBar(); +if (f.blah(3) != 3) + error("blah(int)") +endif + +if (f.blah(3.5) != 3.5) + error("blah(double)") +endif + +if (!strcmp(f.blah("hello"),"hello")) + error("blah(char *)") +endif + +if (f.blah(3,4) != 7) + error("blah(int,int)") +endif + +if (f.blah(3.5,7.5) != (3.5+7.5)) + error("blah(double,double)") +endif + + +if (f.duh(3) != 3) + error("duh(int)") +endif diff --git a/Examples/test-suite/octave/using_inherit_runme.m b/Examples/test-suite/octave/using_inherit_runme.m new file mode 100644 index 0000000..effd0e2 --- /dev/null +++ b/Examples/test-suite/octave/using_inherit_runme.m @@ -0,0 +1,61 @@ +using_inherit + +b = Bar(); +if (b.test(3) != 3) + error("Bar::test(int)") +endif + +if (b.test(3.5) != 3.5) + error("Bar::test(double)") +endif + + +b = Bar2(); +if (b.test(3) != 6) + error("Bar2::test(int)") +endif + +if (b.test(3.5) != 7.0) + error("Bar2::test(double)") +endif + + +b = Bar3(); +if (b.test(3) != 6) + error("Bar3::test(int)") +endif + +if (b.test(3.5) != 7.0) + error("Bar3::test(double)") +endif + + +b = Bar4(); +if (b.test(3) != 6) + error("Bar4::test(int)") +endif + +if (b.test(3.5) != 7.0) + error("Bar4::test(double)") +endif + + +b = Fred1(); +if (b.test(3) != 3) + error("Fred1::test(int)") +endif + +if (b.test(3.5) != 7.0) + error("Fred1::test(double)") +endif + + +b = Fred2(); +if (b.test(3) != 3) + error("Fred2::test(int)") +endif + +if (b.test(3.5) != 7.0) + error("Fred2::test(double)") +endif + diff --git a/Examples/test-suite/octave/using_private_runme.m b/Examples/test-suite/octave/using_private_runme.m new file mode 100644 index 0000000..3ac71db --- /dev/null +++ b/Examples/test-suite/octave/using_private_runme.m @@ -0,0 +1,16 @@ +using_private + +f = FooBar(); +f.x = 3; + +if (f.blah(4) != 4) + error, "blah(int)" +endif + +if (f.defaulted() != -1) + error, "defaulted()" +endif + +if (f.defaulted(222) != 222) + error, "defaulted(222)" +endif diff --git a/Examples/test-suite/octave/using_protected_runme.m b/Examples/test-suite/octave/using_protected_runme.m new file mode 100644 index 0000000..ed4b1c3 --- /dev/null +++ b/Examples/test-suite/octave/using_protected_runme.m @@ -0,0 +1,8 @@ +using_protected + +f = FooBar(); +f.x = 3; + +if (f.blah(4) != 4) + error("blah(int)") +endif diff --git a/Examples/test-suite/octave/varargs_runme.m b/Examples/test-suite/octave/varargs_runme.m new file mode 100644 index 0000000..dcdcb24 --- /dev/null +++ b/Examples/test-suite/octave/varargs_runme.m @@ -0,0 +1,23 @@ +varargs + +if (!strcmp(varargs.test("Hello"),"Hello")) + error("Failed") +endif + +f = varargs.Foo("Greetings"); +if (!strcmp(f.str,"Greetings")) + error("Failed") +endif + +if (!strcmp(f.test("Hello"),"Hello")) + error("Failed") +endif + + +if (!strcmp(varargs.test_def("Hello",1),"Hello")) + error("Failed") +endif + +if (!strcmp(varargs.test_def("Hello"),"Hello")) + error("Failed") +endif diff --git a/Examples/test-suite/octave/virtual_derivation_runme.m b/Examples/test-suite/octave/virtual_derivation_runme.m new file mode 100644 index 0000000..8ce8503 --- /dev/null +++ b/Examples/test-suite/octave/virtual_derivation_runme.m @@ -0,0 +1,9 @@ +virtual_derivation +# +# very innocent example +# +b = B(3); +if (b.get_a() != b.get_b()) + error("something is really wrong") +endif + diff --git a/Examples/test-suite/octave/virtual_poly_runme.m b/Examples/test-suite/octave/virtual_poly_runme.m new file mode 100644 index 0000000..0c7c951 --- /dev/null +++ b/Examples/test-suite/octave/virtual_poly_runme.m @@ -0,0 +1,44 @@ +virtual_poly + +d = virtual_poly.NDouble(3.5); +i = virtual_poly.NInt(2); + +# +# the copy methods return the right polymorphic types +# +dc = d.copy(); +ic = i.copy(); + +if (d.get() != dc.get()) + error +endif + +if (i.get() != ic.get()) + error +endif + +virtual_poly.incr(ic); + +if ((i.get() + 1) != ic.get()) + error +endif + + +dr = d.ref_this(); +if (d.get() != dr.get()) + error +endif + + +# +# 'narrowing' also works +# +ddc = virtual_poly.NDouble_narrow(d.nnumber()); +if (d.get() != ddc.get()) + error +endif + +dic = virtual_poly.NInt_narrow(i.nnumber()); +if (i.get() != dic.get()) + error +endif diff --git a/Examples/test-suite/octave/voidtest_runme.m b/Examples/test-suite/octave/voidtest_runme.m new file mode 100644 index 0000000..e62f8a5 --- /dev/null +++ b/Examples/test-suite/octave/voidtest_runme.m @@ -0,0 +1,38 @@ +voidtest + +voidtest.globalfunc(); +f = voidtest.Foo(); +f.memberfunc(); + +voidtest.Foo_staticmemberfunc(); + +function fvoid() +end + +try + a = f.memberfunc(); +catch +end_try_catch +try + a = fvoid(); +catch +end_try_catch + + +v1 = voidtest.vfunc1(f); +v2 = voidtest.vfunc2(f); +if (swig_this(v1) != swig_this(v2)) + error +endif + +v3 = voidtest.vfunc3(v1); +if (swig_this(v3) != swig_this(f)) + error +endif +v4 = voidtest.vfunc1(f); +if (swig_this(v4) != swig_this(v1)) + error +endif + + +v3.memberfunc(); diff --git a/Examples/test-suite/octave/wrapmacro_runme.m b/Examples/test-suite/octave/wrapmacro_runme.m new file mode 100644 index 0000000..5069f2c --- /dev/null +++ b/Examples/test-suite/octave/wrapmacro_runme.m @@ -0,0 +1,8 @@ +wrapmacro + +a = 2; +b = -1; +wrapmacro.maximum(a,b); +wrapmacro.maximum(a/7.0, -b*256); +wrapmacro.GUINT16_SWAP_LE_BE_CONSTANT(1); + |
