diff options
Diffstat (limited to 'Examples/test-suite/javascript')
171 files changed, 5120 insertions, 26 deletions
diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index 8127415f1..febff1607 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -8,18 +8,49 @@ NODEJS = @NODEJS@ SCRIPTSUFFIX = _runme.js OBJEXT = @OBJEXT@ SO = @SO@ +GYP_CXXFLAGS = @BOOST_CPPFLAGS@ @PLATCXXFLAGS@ -I$(shell npm config get prefix)/lib/node_modules/node-addon-api +HAVE_CXX11 = @HAVE_CXX11@ +HAVE_CXX14 = @HAVE_CXX14@ +HAVE_CXX17 = @HAVE_CXX17@ +HAVE_CXX20 = @HAVE_CXX20@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ +CPP_TEST_CASES += \ + iadd \ + inplaceadd \ + input \ + javascript_lib_arrays \ + li_factory \ + li_std_containers_int \ + li_std_map_member + +# napi fails +FAILING_CPP_TESTS += \ + smart_pointer_static \ + SWIGEXE = $(top_builddir)/swig SWIG_LIB_DIR = $(top_srcdir)/Lib ifneq (, $(ENGINE)) - JSENGINE=$(ENGINE) + JSENGINE=$(ENGINE) +else +ifneq (, $(NODEJS)) + JSENGINE=node else - JSENGINE=node +ifneq (, @JSCENABLED@) + JSENGINE=jsc +else +ifneq (, @JSV8ENABLED@) + JSENGINE=v8 +else + # Shouldn't happen, but avoid empty value if it does. + JSENGINE=node +endif +endif +endif endif ifneq (, $(V8_VERSION)) @@ -39,45 +70,61 @@ _setup = \ echo "$(ACTION)ing $(LANGUAGE) ($(JSENGINE)) testcase $*" ; \ fi; -ifeq (node,$(JSENGINE)) - - SWIGOPT += -v8 -DBUILDING_NODE_EXTENSION=1 +SWIGOPT += -$(JSENGINE) +ifeq ($(JSENGINE), $(filter $(JSENGINE), node napi)) + SWIGOPT += -DBUILDING_NODE_EXTENSION=1 + # shut up some warnings - # contract macro has an empty 'else' at the end... - aggregate.cpptest: GYP_CFLAGS = \"-Wno-empty-body\" - contract.cpptest: GYP_CFLAGS = \"-Wno-empty-body\" # dunno... ignoring generously apply_signed_char.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" constant_pointers.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" + cpp11_ref_qualifiers.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" + director_basic.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" enum_thorough.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" + member_funcptr_galore.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" + director_unwrap_result.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" + + # Run with asan: + # ASAN=1 ENGINE=napi make <test_name>.cpptest + # + ifneq (, $(ASAN)) + GYP_CFLAGS += \"-fsanitize=address\" + GYP_OPTS = --debug + ASAN_PRELOAD = $(shell $(CC) -print-file-name=libasan.so) + LSAN_OPTIONS = suppressions=$(srcdir)/node_template/napi-leaks-suppression.txt + BUILD = Debug + else + BUILD = Release + endif setup_node = \ test -d $* || mkdir $* && \ - sed -e 's|$$testcase|$*|g; s|$$cflags|$(GYP_CFLAGS)|g; s|$$srcdir|$(srcdir)|g' \ + sed -e 's|$$testcase|$*|g; s|$$cflags|$(GYP_CFLAGS)|g; s|$$cxxflags|"$(GYP_CXXFLAGS)"|g; s|$$srcdir|$(srcdir)|g' \ $(srcdir)/node_template/binding.gyp.in > $*/binding.gyp && \ - sed -e 's|$$testcase|$*|g;' \ + sed -e 's|$$testcase|$*|g; s|$$build|$(BUILD)|g;' \ $(srcdir)/node_template/index.js.in > $*/index.js - + # Note: we need to use swig in C parse mode, but make node-gyp believe it is c++ (via file extension) swig_and_compile_c = \ $(setup_node) && \ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' \ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='-javascript $(SWIGOPT) -o $*_wrap.cxx $(srcdir)/../$*.i' swiginvoke && \ - MAKEFLAGS= $(COMPILETOOL) $(NODEGYP) --loglevel=silent --directory $* configure build 1>>/dev/null + MAKEFLAGS= $(COMPILETOOL) $(NODEGYP) --loglevel=silent --directory $* configure $(GYP_OPTS) build 1>>/dev/null swig_and_compile_cpp = \ $(setup_node) && \ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' \ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ SWIGOPT='-c++ -javascript $(SWIGOPT) $(srcdir)/../$*.i' swiginvoke && \ - MAKEFLAGS= $(COMPILETOOL) $(NODEGYP) --loglevel=silent --directory $* configure build 1>>/dev/null + MAKEFLAGS= $(COMPILETOOL) $(NODEGYP) --loglevel=silent --directory $* configure $(GYP_OPTS) build 1>>/dev/null run_testcase = \ if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \ - env NODE_PATH=$$PWD:$(srcdir) $(RUNTOOL) $(NODEJS) $(srcdir)/$*$(SCRIPTSUFFIX); \ + env NODE_PATH=$$PWD:$(srcdir) LD_PRELOAD=$(ASAN_PRELOAD) LSAN_OPTIONS=$(LSAN_OPTIONS) \ + $(RUNTOOL) $(NODEJS) $(srcdir)/$*$(SCRIPTSUFFIX); \ fi @@ -96,8 +143,6 @@ ifeq (node,$(JSENGINE)) else - SWIGOPT += -$(JSENGINE) - run_testcase = \ if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \ $(RUNTOOL) $(top_builddir)/Tools/javascript/javascript -$(JSENGINE) $(srcdir)/$*$(SCRIPTSUFFIX); \ @@ -131,6 +176,7 @@ clean: rm -f imports_a$${ext} imports_b$${ext}; \ rm -f import_stl_a$${ext} import_stl_b$${ext}; \ rm -f mod_a$${ext} mod_b$${ext}; \ - rm -f multi_import_a$${ext} multi_import_b$${ext}; \ + rm -f multi_import_a$${ext} multi_import_b$${ext} multi_import_d$${ext}; \ rm -f packageoption_a$${ext} packageoption_b$${ext} packageoption_c$${ext}; \ + rm -f template_typedef_cplx2$${ext}; \ done diff --git a/Examples/test-suite/javascript/argcargvtest_runme.js b/Examples/test-suite/javascript/argcargvtest_runme.js new file mode 100644 index 000000000..855354224 --- /dev/null +++ b/Examples/test-suite/javascript/argcargvtest_runme.js @@ -0,0 +1,45 @@ +var test = require("argcargvtest"); + +const largs = ["hi", "hola", "hello"]; +if (test.mainc(largs) != 3) + throw "calling mainc failed"; + +const targs = ["hi", "hola"]; +if (test.mainv(targs, 0) != "hi") + throw "calling mainv failed"; +if (test.mainv(targs, 1) != "hola") + throw "calling mainv failed"; +if (test.mainv(targs, 2) != "<<NULL>>") + throw "calling mainv failed"; + +caughtException = false; +try { + test.mainv("hello", 1); +} catch (err) { + caughtException = true; +} +if (!caughtException) { + throw "mainv without array should fail" +} + +test.initializeApp(largs); + +// Check that an empty array works. +const empty_args = []; +if (test.mainc(empty_args) != 0) + throw "bad main typemap"; +if (test.mainv(empty_args, 0) != "<<NULL>>") + throw "calling mainv failed"; + +// Check that empty strings are handled. +const empty_string = ["hello", "", "world"]; +if (test.mainc(empty_string) != 3) + throw "bad main typemap"; +if (test.mainv(empty_string, 0) != "hello") + throw "bad main typemap"; +if (test.mainv(empty_string, 1) != "") + throw "bad main typemap"; +if (test.mainv(empty_string, 2) != "world") + throw "bad main typemap"; +if (test.mainv(empty_string, 3) != "<<NULL>>") + throw "bad main typemap"; diff --git a/Examples/test-suite/javascript/catches_strings_runme.js b/Examples/test-suite/javascript/catches_strings_runme.js new file mode 100644 index 000000000..9d9db3247 --- /dev/null +++ b/Examples/test-suite/javascript/catches_strings_runme.js @@ -0,0 +1,23 @@ +var catches_strings = require("catches_strings"); + +exception_thrown = false; +try { + catches_strings.StringsThrower.charstring(); +} catch (e) { + if (!(e.message || e).includes("charstring message")) + throw new Error("incorrect exception message " + e.message); + exception_thrown = true; +} +if (!exception_thrown) + throw new Error("Should have thrown an exception"); + +exception_thrown = false; +try { + catches_strings.StringsThrower.stdstring(); +} catch (e) { + if (!(e.message || e).includes("stdstring message")) + throw new Error("incorrect exception message " + e.message); + exception_thrown = true; +} +if (!exception_thrown) + throw new Error("Should have thrown an exception"); diff --git a/Examples/test-suite/javascript/class_scope_weird_runme.js b/Examples/test-suite/javascript/class_scope_weird_runme.js index 73c118d61..ca18c1b4d 100644 --- a/Examples/test-suite/javascript/class_scope_weird_runme.js +++ b/Examples/test-suite/javascript/class_scope_weird_runme.js @@ -4,3 +4,14 @@ f = new class_scope_weird.Foo(); g = new class_scope_weird.Foo(3); if (f.bar(3) != 3) throw RuntimeError; + +// Test missing new keyword during constructor call +var caughtException = false; +try { + g = class_scope_weird.Foo(4); +} catch (err) { + caughtException = true; +} +if (!caughtException) { + throw new Error("Instantiation exception not thrown"); +} diff --git a/Examples/test-suite/javascript/constant_directive_runme.js b/Examples/test-suite/javascript/constant_directive_runme.js new file mode 100644 index 000000000..2bebfffa3 --- /dev/null +++ b/Examples/test-suite/javascript/constant_directive_runme.js @@ -0,0 +1,36 @@ +var constant_directive = require("constant_directive"); + +if (!constant_directive.TYPE1_CONSTANT1 instanceof constant_directive.Type1) { + throw new Error("Failure: TYPE1_CONSTANT1 type: " + + typeof constant_directive.TYPE1_CONSTANT1); + +} +if (!constant_directive.getType1Instance() instanceof constant_directive.Type1) { + throw new Error("Failure: getType1Instance() type: " + + typeof constant_directive.getType1Instance()); +} + +if (constant_directive.TYPE1_CONSTANT1.val != 1) { + throw new Error("constant_directive.TYPE1_CONSTANT1.val is %r (should be 1) " + + constant_directive.TYPE1_CONSTANT1.val); +} + +if (constant_directive.TYPE1_CONSTANT2.val != 2) { + throw new Error("constant_directive.TYPE1_CONSTANT2.val is %r (should be 2) " + + constant_directive.TYPE1_CONSTANT2.val); +} + +if (constant_directive.TYPE1_CONSTANT3.val != 3) { + throw new Error("constant_directive.TYPE1_CONSTANT3.val is %r (should be 3) " + + constant_directive.TYPE1_CONSTANT3.val); +} + +if (constant_directive.TYPE1CONST_CONSTANT1.val != 1) { + throw new Error("constant_directive.TYPE1CONST_CONSTANT1.val is %r (should be 1) " + + constant_directive.TYPE1CONST_CONSTANT1.val); +} + +if (constant_directive.TYPE1CPTR_CONSTANT1.val != 1) { + throw new Error("constant_directive.TYPE1CPTR_CONSTANT1.val is %r (should be 1) " + + constant_directive.TYPE1CPTR_CONSTANT1.val); +} diff --git a/Examples/test-suite/javascript/cpp11_alternate_function_syntax_runme.js b/Examples/test-suite/javascript/cpp11_alternate_function_syntax_runme.js new file mode 100644 index 000000000..2823a6788 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_alternate_function_syntax_runme.js @@ -0,0 +1,28 @@ +var cpp11_alternate_function_syntax = require("cpp11_alternate_function_syntax"); + +a = new cpp11_alternate_function_syntax.SomeStruct(); + +res = a.addNormal(4, 5); +if (res != 9) { + throw new Error("SomeStruct::addNormal(4,5) returns ", res, " should be 9."); +} + +res = a.addAlternate(4, 5); +if (res != 9) { + throw new Error("SomeStruct::addAlternate(4,5) returns ", res, " should be 9."); +} + +res = a.addAlternateConst(4, 5); +if (res != 9) { + throw new Error("SomeStruct::addAlternateConst(4,5) returns ", res, " should be 9."); +} + +res = a.addAlternateNoExcept(4, 5); +if (res != 9) { + throw new Error("SomeStruct::addAlternateNoExcept(4,5) returns ", res, " should be 9."); +} + +res = a.addAlternateConstNoExcept(4, 5); +if (res != 9) { + throw new Error("SomeStruct::addAlternateConstNoExcept(4,5) returns ", res, " should be 9."); +} diff --git a/Examples/test-suite/javascript/cpp11_decltype_runme.js b/Examples/test-suite/javascript/cpp11_decltype_runme.js new file mode 100644 index 000000000..c067d9b55 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_decltype_runme.js @@ -0,0 +1,22 @@ +var cpp11_decltype = require("cpp11_decltype"); + +a = new cpp11_decltype.A; +a.i = 5; +if (a.i != 5) { + throw new Error("Assignment to a.i failed."); +} + +a.j = 10; +if (a.j != 10) { + throw new Error("Assignment to a.j failed."); +} + +b = a.get_number(5); +if (b != 10) { + throw new Error("get_number(5) should return 10."); +} + +b = a.get_number(6); +if (b != 0) { + throw new Error("get_number(6) should return 0."); +} diff --git a/Examples/test-suite/javascript/cpp11_final_class_runme.js b/Examples/test-suite/javascript/cpp11_final_class_runme.js new file mode 100644 index 000000000..3e72b05e2 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_final_class_runme.js @@ -0,0 +1,64 @@ +var cpp11_final_class = require("cpp11_final_class"); + +fc1 = new cpp11_final_class.FinalClass1(); +fc1.method1(); + +fc2 = new cpp11_final_class.FinalClass2(); +fc2.method2(); + +fc3 = new cpp11_final_class.FinalClass3(); +fc3.method3(); + +fc4 = new cpp11_final_class.FinalClass4(); +fc4.method4(); +fc4final = cpp11_final_class.final; +cpp11_final_class.final.method4(); + +fc5 = new cpp11_final_class.FinalClass5(); +fc5.method5(); +fc5.final_member_var.finalmethod(); +fc5final = fc5.get_final_member(); +fc5final.finalmethod(); +fc5final = fc5.get_final_member2(); +fc5final.finalmethod(); + +fc6 = new cpp11_final_class.FinalClass6(); +fc6.method6(); +fc6.final(); + +o = new cpp11_final_class.override(); +o.omethod(); + +y = new cpp11_final_class.Y(); +fv4 = new cpp11_final_class.FinalVar4(); +yy = fv4.final; + +fv5 = new cpp11_final_class.FinalVar5(); +yy = fv5.final; + +fv6 = new cpp11_final_class.FinalVar6(); +yy = fv6.final; + +fv7 = new cpp11_final_class.FinalVar7(); +yy = fv7.final; + +fv8 = new cpp11_final_class.FinalVar8(); +yy = fv8.final; + +fv9 = new cpp11_final_class.FinalVar9(); +yy = fv9.final; + +fv10 = new cpp11_final_class.FinalVar10(); +fv10.b10(y); + +// Removed due to Visual C++ compiler limitations +/*fv11 = FinalVar11() +fv11.a11(y) +fe1 = FinalEnum1() +fe1.enum_in(FinalEnum1.final) + +fe2 = FinalEnum2() +fe2f = fe2.final*/ + +s3f = new cpp11_final_class.Space3_final(); +s3f.fmethod(); diff --git a/Examples/test-suite/javascript/cpp11_initializer_list_runme.js b/Examples/test-suite/javascript/cpp11_initializer_list_runme.js new file mode 100644 index 000000000..dfff44f01 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_initializer_list_runme.js @@ -0,0 +1,4 @@ +var cpp11_initializer_list = require("cpp11_initializer_list"); + +a = new cpp11_initializer_list.A(); +a = new cpp11_initializer_list.A(11.1); diff --git a/Examples/test-suite/javascript/cpp11_move_only_runme.js b/Examples/test-suite/javascript/cpp11_move_only_runme.js new file mode 100644 index 000000000..26daf5df4 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_move_only_runme.js @@ -0,0 +1,22 @@ +var cpp11_move_only = require("cpp11_move_only"); + +// Output +cpp11_move_only.Counter.reset_counts(); +var mo = cpp11_move_only.MoveOnly.create(); +cpp11_move_only.Counter.check_counts(1, 0, 0, 2, 0, 2); + +cpp11_move_only.Counter.reset_counts(); +var mo = cpp11_move_only.MovableCopyable.create(); +cpp11_move_only.Counter.check_counts(2, 1, 0, 0, 1, 2); + +// Move semantics not used +cpp11_move_only.Counter.reset_counts(); +var mo = cpp11_move_only.MovableCopyable.createConst(); +cpp11_move_only.Counter.check_counts(2, 1, 1, 0, 0, 2); + +// Input +cpp11_move_only.Counter.reset_counts(); +var mo = new cpp11_move_only.MovableCopyable(222); +cpp11_move_only.Counter.check_counts(1, 0, 0, 0, 0, 0); +cpp11_move_only.MovableCopyable.take(mo); +cpp11_move_only.Counter.check_counts(2, 0, 1, 1, 0, 2); diff --git a/Examples/test-suite/javascript/cpp11_move_typemaps_runme.js b/Examples/test-suite/javascript/cpp11_move_typemaps_runme.js new file mode 100644 index 000000000..1e888cb9c --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_move_typemaps_runme.js @@ -0,0 +1,30 @@ +var cpp11_move_typemaps = require("cpp11_move_typemaps"); + +cpp11_move_typemaps.Counter.reset_counts(); +mo = new cpp11_move_typemaps.MoveOnly(111); +cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 0, 0, 0); +cpp11_move_typemaps.MoveOnly.take(mo); +cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 1, 0, 2); +delete mo; +cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 1, 0, 2); + +cpp11_move_typemaps.Counter.reset_counts(); +mo = new cpp11_move_typemaps.MovableCopyable(111); +cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 0, 0, 0); +cpp11_move_typemaps.MovableCopyable.take(mo); +cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 1, 0, 2); +delete mo; +cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 1, 0, 2); + +mo = new cpp11_move_typemaps.MoveOnly(222); +cpp11_move_typemaps.MoveOnly.take(mo); +exception_thrown = false; +try { + cpp11_move_typemaps.MoveOnly.take(mo); +} catch (e) { + if (!e.message.includes("cannot release ownership as memory is not owned")) + throw new Error("incorrect exception message:" + e.message); + exception_thrown = true; +} +if (!exception_thrown) + throw new Error("double usage of take should have been an error"); diff --git a/Examples/test-suite/javascript/cpp11_null_pointer_constant_runme.js b/Examples/test-suite/javascript/cpp11_null_pointer_constant_runme.js new file mode 100644 index 000000000..5477c40c9 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_null_pointer_constant_runme.js @@ -0,0 +1,20 @@ +var cpp11_null_pointer_constant = require("cpp11_null_pointer_constant"); + +a = new cpp11_null_pointer_constant.A(); + +if (a._myA != null) { + throw new Error( + "cpp11_null_pointer_constant: _myA should be None, but is ", a._myA); +} + +b = new cpp11_null_pointer_constant.A(); +if (a._myA != b._myA) { + throw new Error( + "cpp11_null_pointer_constant: a._myA should be the same as b._myA, but ", a._myA, "!=", b._myA); +} + +a._myA = new cpp11_null_pointer_constant.A(); +if (a._myA == null) { + throw new Error(( + "cpp11_null_pointer_constant: _myA should be object, but is None")); +} diff --git a/Examples/test-suite/javascript/cpp11_ref_qualifiers_runme.js b/Examples/test-suite/javascript/cpp11_ref_qualifiers_runme.js new file mode 100644 index 000000000..d544caf29 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_ref_qualifiers_runme.js @@ -0,0 +1,51 @@ +var cpp11_ref_qualifiers = require("cpp11_ref_qualifiers"); + +h = new cpp11_ref_qualifiers.Host(); + +// Basic testing +h.h1(); +h.h2(); +h.h6(); +h.h7(); + +h.h(); + +// %feature testing +f = new cpp11_ref_qualifiers.Features(); +if (f.F1() != "F1") { + throw new Error("Fail"); +} +if (f.F2() != "F2") { + throw new Error("Fail"); +} +if (f.F3() != "F3") { + throw new Error("Fail"); +} + +if (f.C1(0) != "C1") { + throw new Error("Fail"); +} +if (f.C2(0) != "C2") { + throw new Error("Fail"); +} +if (f.C3(0) != "C3") { + throw new Error("Fail"); +} + +// %rename testing +r = new cpp11_ref_qualifiers.Renames(); +r.RR1(); +r.RR2(); +r.RR3(); + +r.SS1(0); +r.SS2(0); +r.SS3(0); + +// Conversion operators +co = new cpp11_ref_qualifiers.ConversionOperators(); +s = co.StringConvertCopy(); +s = co.StringConvertMove(); + +co2 = new cpp11_ref_qualifiers.ConversionOperators2(); +s = co2.StringConvertMove(); diff --git a/Examples/test-suite/javascript/cpp11_ref_qualifiers_rvalue_unignore_runme.js b/Examples/test-suite/javascript/cpp11_ref_qualifiers_rvalue_unignore_runme.js new file mode 100644 index 000000000..19d20957f --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_ref_qualifiers_rvalue_unignore_runme.js @@ -0,0 +1,4 @@ +var cpp11_ref_qualifiers_rvalue_unignore = require("cpp11_ref_qualifiers_rvalue_unignore"); + +new cpp11_ref_qualifiers_rvalue_unignore.RefQualifier().m1(); +new cpp11_ref_qualifiers_rvalue_unignore.RefQualifier().m2(); diff --git a/Examples/test-suite/javascript/cpp11_result_of_runme.js b/Examples/test-suite/javascript/cpp11_result_of_runme.js new file mode 100644 index 000000000..d996ca132 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_result_of_runme.js @@ -0,0 +1,13 @@ +var cpp11_result_of = require("cpp11_result_of"); + +result = cpp11_result_of.test_result(cpp11_result_of.SQUARE, 3.0); +if (result != 9.0) { + throw new Error("test_result(square, 3.0) is not 9.0. Got: " + str( + result)); +} + +result = cpp11_result_of.test_result_alternative1(cpp11_result_of.SQUARE, 3.0); +if (result != 9.0) { + throw new Error("test_result_alternative1(square, 3.0) is not 9.0. Got: " + str( + result)); +} diff --git a/Examples/test-suite/javascript/cpp11_rvalue_reference_move_runme.js b/Examples/test-suite/javascript/cpp11_rvalue_reference_move_runme.js new file mode 100644 index 000000000..c642b4265 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_rvalue_reference_move_runme.js @@ -0,0 +1,87 @@ +var cpp11_rvalue_reference_move = require("cpp11_rvalue_reference_move"); + +{ + // Function containing rvalue reference parameter + cpp11_rvalue_reference_move.Counter.reset_counts(); + mo = new cpp11_rvalue_reference_move.MovableCopyable(222); + cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 0, 0, 0); + cpp11_rvalue_reference_move.MovableCopyable.movein(mo); + cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 2); + if (!cpp11_rvalue_reference_move.MovableCopyable.is_nullptr(mo)) + throw new Error("is_nullptr failed"); + delete mo; + cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 2); +} + +{ + // Move constructor test + cpp11_rvalue_reference_move.Counter.reset_counts(); + mo = new cpp11_rvalue_reference_move.MovableCopyable(222); + cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 0, 0, 0); + mo_moved = new cpp11_rvalue_reference_move.MovableCopyable(mo); + cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 1); + if (!cpp11_rvalue_reference_move.MovableCopyable.is_nullptr(mo)) + throw new Error("is_nullptr failed"); + delete mo; + cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 1); + // delete mo_moved; + // cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 1, 0, 2); + // Above not deleting the C++ object(node v12) - can't reliably control GC - use the movein function instead to delete + cpp11_rvalue_reference_move.MovableCopyable.movein(mo_moved); + cpp11_rvalue_reference_move.Counter.check_counts(1, 0, 0, 2, 0, 3); +} + +{ + // Move assignment operator test + cpp11_rvalue_reference_move.Counter.reset_counts(); + mo111 = new cpp11_rvalue_reference_move.MovableCopyable(111); + mo222 = new cpp11_rvalue_reference_move.MovableCopyable(222); + cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 0, 0); + mo111.MoveAssign(mo222); + cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1); + if (!cpp11_rvalue_reference_move.MovableCopyable.is_nullptr(mo222)) + throw new Error("is_nullptr failed"); + delete mo222; + cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1); + // delete mo111; + // cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 2); + // Above not deleting the C++ object(node v12) - can't reliably control GC - use the movein function instead to delete + cpp11_rvalue_reference_move.MovableCopyable.movein(mo111); + cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 1, 1, 3); +} + +{ + // null check + cpp11_rvalue_reference_move.Counter.reset_counts(); + exception_thrown = false; + try { + cpp11_rvalue_reference_move.MovableCopyable.movein(null); + } catch (e) { + if (!e.message.includes("invalid null reference")) + throw new Error("incorrect exception message " + e.message); + exception_thrown = true; + } + if (!exception_thrown) + throw new Error("Should have thrown null error"); + cpp11_rvalue_reference_move.Counter.check_counts(0, 0, 0, 0, 0, 0); +} + +{ + // output + cpp11_rvalue_reference_move.Counter.reset_counts(); + var mc = cpp11_rvalue_reference_move.MovableCopyable.moveout(1234); + cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1); + cpp11_rvalue_reference_move.MovableCopyable.check_numbers_match(mc, 1234); + + exception_thrown = false; + try { + cpp11_rvalue_reference_move.MovableCopyable.movein(mc); + } catch (e) { + if (!e.message.includes("cannot release ownership as memory is not owned")) + throw new Error("incorrect exception message " + e.message); + exception_thrown = true; + } + if (!exception_thrown) + throw new Error("Should have thrown 'Cannot release ownership as memory is not owned' error"); + cpp11_rvalue_reference_move.Counter.check_counts(2, 0, 0, 0, 1, 1); +} diff --git a/Examples/test-suite/javascript/cpp11_rvalue_reference_runme.js b/Examples/test-suite/javascript/cpp11_rvalue_reference_runme.js new file mode 100644 index 000000000..5ffe08d97 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_rvalue_reference_runme.js @@ -0,0 +1,31 @@ +var cpp11_rvalue_reference = require("cpp11_rvalue_reference"); + +a = new cpp11_rvalue_reference.A(); + +a.setAcopy(5); +if (a.getAcopy() != 5) { + throw new Error("int A::getAcopy() value is " + + a.getAcopy() + " should be 5"); +} + +ptr = a.getAptr(); + +a.setAptr(ptr); +if (a.getAcopy() != 5) { + throw new Error("after A::setAptr(): int A::getAcopy() value is " + a.getAcopy( + ) + " should be 5"); +} + +a.setAref(ptr); +if (a.getAcopy() != 5) { + throw new Error("after A::setAref(): int A::getAcopy() value is " + a.getAcopy( + ) + " should be 5"); +} + +rvalueref = a.getAmove(); + +a.setAref(rvalueref); +if (a.getAcopy() != 5) { + throw new Error("after A::setAmove(): int A::getAcopy() value is " + a.getAcopy( + ) + " should be 5"); +} diff --git a/Examples/test-suite/javascript/cpp11_std_unique_ptr_runme.js b/Examples/test-suite/javascript/cpp11_std_unique_ptr_runme.js new file mode 100644 index 000000000..9e7d87971 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_std_unique_ptr_runme.js @@ -0,0 +1,129 @@ +var cpp11_std_unique_ptr = require("cpp11_std_unique_ptr"); + +var checkCount = function(expected_count) { + actual_count = cpp11_std_unique_ptr.Klass.getTotal_count(); + if (actual_count != expected_count) + throw new Error("Counts incorrect, expected:" + expected_count + " actual:" + actual_count); +} + +// Test raw pointer handling involving virtual inheritance +{ + kini = new cpp11_std_unique_ptr.KlassInheritance("KlassInheritanceInput"); + checkCount(1); + s = cpp11_std_unique_ptr.useKlassRawPtr(kini); + if (s !== "KlassInheritanceInput") + throw new Error("Incorrect string: " + s); + // delete kini; + // Above not deleting the C++ object(node v12) - can't reliably control GC + cpp11_std_unique_ptr.takeKlassUniquePtr(kini); + checkCount(0); +} + + +// unique_ptr as input +{ + kin = new cpp11_std_unique_ptr.Klass("KlassInput"); + checkCount(1); + s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin); + checkCount(0); + if (s !== "KlassInput") + throw new Error("Incorrect string: " + s); + if (!cpp11_std_unique_ptr.is_nullptr(kin)) + throw new Error("is_nullptr failed"); + delete kin; // Should not fail, even though already deleted + checkCount(0); +} + +{ + kin = new cpp11_std_unique_ptr.Klass("KlassInput"); + checkCount(1); + s = cpp11_std_unique_ptr.takeKlassUniquePtr(kin); + checkCount(0); + if (s !== "KlassInput") + throw new Error("Incorrect string: " + s); + if (!cpp11_std_unique_ptr.is_nullptr(kin)) + throw new Error("is_nullptr failed"); + exception_thrown = false; + try { + cpp11_std_unique_ptr.takeKlassUniquePtr(kin); + } catch (e) { + if (!e.message.includes("cannot release ownership as memory is not owned")) + throw new Error("incorrect exception message " + e.message); + exception_thrown = true; + } + if (!exception_thrown) + throw new Error("double usage of takeKlassUniquePtr should have been an error"); + delete kin; // Should not fail, even though already deleted + checkCount(0); +} + +{ + kin = new cpp11_std_unique_ptr.Klass("KlassInput"); + exception_thrown = false; + notowned = cpp11_std_unique_ptr.get_not_owned_ptr(kin); + try { + cpp11_std_unique_ptr.takeKlassUniquePtr(notowned); + } catch (e) { + if (!e.message.includes("cannot release ownership as memory is not owned")) + throw new Error("incorrect exception message " + e.message); + exception_thrown = true; + } + if (!exception_thrown) + throw new Error("Should have thrown 'Cannot release ownership as memory is not owned' error"); + checkCount(1); + // delete kin; + // Above not deleting the C++ object(node v12) - can't reliably control GC + cpp11_std_unique_ptr.takeKlassUniquePtr(kin); + checkCount(0); +} + +{ + kini = new cpp11_std_unique_ptr.KlassInheritance("KlassInheritanceInput"); + checkCount(1); + s = cpp11_std_unique_ptr.takeKlassUniquePtr(kini); + checkCount(0); + if (s !== "KlassInheritanceInput") + throw new Error("Incorrect string: " + s); + if (!cpp11_std_unique_ptr.is_nullptr(kini)) + throw new Error("is_nullptr failed"); + delete kini; // Should not fail, even though already deleted + checkCount(0); +} + +cpp11_std_unique_ptr.takeKlassUniquePtr(null); +cpp11_std_unique_ptr.takeKlassUniquePtr(cpp11_std_unique_ptr.make_null()); +checkCount(0); + +// overloaded parameters +if (cpp11_std_unique_ptr.overloadTest() != 0) + throw new RuntimeException("overloadTest failed"); +if (cpp11_std_unique_ptr.overloadTest(null) != 1) + throw new RuntimeException("overloadTest failed"); +if (cpp11_std_unique_ptr.overloadTest(new cpp11_std_unique_ptr.Klass("over")) != 1) + throw new RuntimeException("overloadTest failed"); +checkCount(0); + + +// unique_ptr as output +k1 = cpp11_std_unique_ptr.makeKlassUniquePtr("first"); +if (k1.getLabel() !== "first") + throw new Error("wrong object label"); + +k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second"); +checkCount(2); + +// delete k1; +// Above not deleting the C++ object(node v12) - can't reliably control GC +cpp11_std_unique_ptr.takeKlassUniquePtr(k1); +checkCount(1); + +if (k2.getLabel() !== "second") + throw new Error("wrong object label"); + +// delete k2; +// Above not deleting the C++ object(node v12) - can't reliably control GC +cpp11_std_unique_ptr.takeKlassUniquePtr(k2); +checkCount(0); + +if (cpp11_std_unique_ptr.makeNullUniquePtr() != null) + throw new Error("null failure"); diff --git a/Examples/test-suite/javascript/cpp11_thread_local_runme.js b/Examples/test-suite/javascript/cpp11_thread_local_runme.js new file mode 100644 index 000000000..5419307c4 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_thread_local_runme.js @@ -0,0 +1,47 @@ +var cpp11_thread_local = require("cpp11_thread_local"); + +t = new cpp11_thread_local.ThreadLocals(); +if (t.stval != 11) { + throw new Error; +} +if (t.tsval != 22) { + throw new Error; +} +if (t.tscval99 != 99) { + throw new Error; +} + +cpp11_thread_local.etval = -11; +if (cpp11_thread_local.etval != -11) { + throw new Error; +} + +cpp11_thread_local.stval = -22; +if (cpp11_thread_local.stval != -22) { + throw new Error; +} + +cpp11_thread_local.tsval = -33; +if (cpp11_thread_local.tsval != -33) { + throw new Error; +} + +cpp11_thread_local.etval = -44; +if (cpp11_thread_local.etval != -44) { + throw new Error; +} + +cpp11_thread_local.teval = -55; +if (cpp11_thread_local.teval != -55) { + throw new Error; +} + +cpp11_thread_local.ectval = -66; +if (cpp11_thread_local.ectval != -66) { + throw new Error; +} + +cpp11_thread_local.ecpptval = -66; +if (cpp11_thread_local.ecpptval != -66) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/cpp11_using_typedef_struct_runme.js b/Examples/test-suite/javascript/cpp11_using_typedef_struct_runme.js new file mode 100644 index 000000000..4acfdb883 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_using_typedef_struct_runme.js @@ -0,0 +1,13 @@ +var cpp11_using_typedef_struct = require("cpp11_using_typedef_struct"); + +var b = new cpp11_using_typedef_struct.AffineMatrix(); +b.x = b.y = b.z = 1; + +if (cpp11_using_typedef_struct.fn1(b) != b.x) + throw new Error('failed'); + +var bb = new cpp11_using_typedef_struct.xCacheView(); +bb.x = 123; + +if (cpp11_using_typedef_struct.fn2(bb) != 123) + throw new Error('failed'); diff --git a/Examples/test-suite/javascript/cpp11_variadic_function_templates_runme.js b/Examples/test-suite/javascript/cpp11_variadic_function_templates_runme.js new file mode 100644 index 000000000..11c538c88 --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_variadic_function_templates_runme.js @@ -0,0 +1,23 @@ +var cpp11_variadic_function_templates = require("cpp11_variadic_function_templates"); + +const {A, B, C, D, variadicmix1} = cpp11_variadic_function_templates; + +ec = new cpp11_variadic_function_templates.EmplaceContainer(); +ec.emplace(new A()); +ec.emplace(new A(), new B()); +ec.emplace(new A(), new B(), new C()); +ec.emplace(new A(), new B(), new C(), new D()); + +function check(expected, got) { + if (expected != got) { + throw new Error("failed: {} != {}".format(expected, got)); + } +} +a = new A(); +b = new B(); +c = new C(); +check(variadicmix1(), 20); +check(variadicmix1(a), 20); +check(variadicmix1(a, b), 10); +check(variadicmix1(a, b, c), 20); +check(variadicmix1(11, 22), 10); diff --git a/Examples/test-suite/javascript/cpp14_binary_integer_literals_runme.js b/Examples/test-suite/javascript/cpp14_binary_integer_literals_runme.js new file mode 100644 index 000000000..655ef913a --- /dev/null +++ b/Examples/test-suite/javascript/cpp14_binary_integer_literals_runme.js @@ -0,0 +1,33 @@ +var cpp14_binary_integer_literals = require("cpp14_binary_integer_literals"); + +if (cpp14_binary_integer_literals.b1 != 1) { + throw new Error; +} + +if (cpp14_binary_integer_literals.b2 != 2) { + throw new Error; +} + +if (cpp14_binary_integer_literals.b3 != 3) { + throw new Error; +} + +if (cpp14_binary_integer_literals.b4 != 4) { + throw new Error; +} + +if (cpp14_binary_integer_literals.b5 != 5) { + throw new Error; +} + +if (cpp14_binary_integer_literals.b6 != 6) { + throw new Error; +} + +if (cpp14_binary_integer_literals.b7 != 7) { + throw new Error; +} + +if (cpp14_binary_integer_literals.b8 != 8) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/cpp17_hex_floating_literals_runme.js b/Examples/test-suite/javascript/cpp17_hex_floating_literals_runme.js new file mode 100644 index 000000000..0d2585fa9 --- /dev/null +++ b/Examples/test-suite/javascript/cpp17_hex_floating_literals_runme.js @@ -0,0 +1,37 @@ +var cpp17_hex_floating_literals = require("cpp17_hex_floating_literals"); + +if (cpp17_hex_floating_literals.f1 != 0.) { + throw new Error; +} + +if (cpp17_hex_floating_literals.f2 != 0.) { + throw new Error; +} + +if (cpp17_hex_floating_literals.f3 != 0.) { + throw new Error; +} + +if (cpp17_hex_floating_literals.f4 != 7.5) { + throw new Error; +} + +if (cpp17_hex_floating_literals.f5 != 20.) { + throw new Error; +} + +if (cpp17_hex_floating_literals.f6 != 64.) { + throw new Error; +} + +if (cpp17_hex_floating_literals.f7 != 11452.) { + throw new Error; +} + +if (cpp17_hex_floating_literals.f8 != 149140.) { + throw new Error; +} + +if (cpp17_hex_floating_literals.f9 != 18253638.) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/cpp17_nested_namespaces_runme.js b/Examples/test-suite/javascript/cpp17_nested_namespaces_runme.js new file mode 100644 index 000000000..f711c7235 --- /dev/null +++ b/Examples/test-suite/javascript/cpp17_nested_namespaces_runme.js @@ -0,0 +1,18 @@ +var cpp17_nested_namespaces = require("cpp17_nested_namespaces"); + +new cpp17_nested_namespaces.A1Struct().A1Method() +new cpp17_nested_namespaces.B1Struct().B1Method() +new cpp17_nested_namespaces.C1Struct().C1Method() +new cpp17_nested_namespaces.createA1Struct().A1Method() +new cpp17_nested_namespaces.createB1Struct().B1Method() +new cpp17_nested_namespaces.createC1Struct().C1Method() + +new cpp17_nested_namespaces.B2Struct().B2Method() +new cpp17_nested_namespaces.C2Struct().C2Method() +new cpp17_nested_namespaces.createB2Struct().B2Method() +new cpp17_nested_namespaces.createC2Struct().C2Method() + +new cpp17_nested_namespaces.B3Struct().B3Method() +new cpp17_nested_namespaces.C3Struct().C3Method() +new cpp17_nested_namespaces.createB3Struct().B3Method() +new cpp17_nested_namespaces.createC3Struct().C3Method() diff --git a/Examples/test-suite/javascript/cpp17_u8_char_literals_runme.js b/Examples/test-suite/javascript/cpp17_u8_char_literals_runme.js new file mode 100644 index 000000000..94aaafd6e --- /dev/null +++ b/Examples/test-suite/javascript/cpp17_u8_char_literals_runme.js @@ -0,0 +1,13 @@ +var cpp17_u8_char_literals = require("cpp17_u8_char_literals"); + +if (cpp17_u8_char_literals.a != "a") { + throw new Error; +} + +if (cpp17_u8_char_literals.u != "u") { + throw new Error; +} + +if (cpp17_u8_char_literals.u8 != "8") { + throw new Error; +} diff --git a/Examples/test-suite/javascript/cpp20_spaceship_operator_runme.js b/Examples/test-suite/javascript/cpp20_spaceship_operator_runme.js new file mode 100644 index 000000000..d59a9f656 --- /dev/null +++ b/Examples/test-suite/javascript/cpp20_spaceship_operator_runme.js @@ -0,0 +1,21 @@ +var cpp20_spaceship_operator = require("cpp20_spaceship_operator"); + +function check_equal(a, b) { + if (a != b) { + throw new Error("{} is not equal to {}".format(a, b)); + } +} + +check_equal(cpp20_spaceship_operator.ALIEN, 1); +check_equal(cpp20_spaceship_operator.SPACE, 1); +check_equal(cpp20_spaceship_operator.COMET, 1); +check_equal(cpp20_spaceship_operator.v, 42); + +x = new cpp20_spaceship_operator.A(1); +y = new cpp20_spaceship_operator.A(2); + +check_equal(cpp20_spaceship_operator.spaceship(x, y) < 0, true); +check_equal(cpp20_spaceship_operator.spaceship(x, x), 0); +check_equal(cpp20_spaceship_operator.spaceship(y, x) > 0, true); + +check_equal(cpp20_spaceship_operator.f(), 42); diff --git a/Examples/test-suite/javascript/default_arg_values_runme.js b/Examples/test-suite/javascript/default_arg_values_runme.js new file mode 100644 index 000000000..f9cc44376 --- /dev/null +++ b/Examples/test-suite/javascript/default_arg_values_runme.js @@ -0,0 +1,36 @@ +var default_arg_values = require("default_arg_values"); + +var d = new default_arg_values.Display(); + +if (d.draw1() != 0) { + throw new Error; +} + +if (d.draw1(12) != 12) { + throw new Error; +} + +p = default_arg_values.createPtr(123); +if (d.draw2() != 0) { + throw new Error; +} + +if (d.draw2(p) != 123) { + throw new Error; +} + +if (d.bool0() != false || typeof d.bool0() != typeof false) { + throw new Error; +} + +if (d.bool1() != true || typeof d.bool1() != typeof true) { + throw new Error; +} + +if (d.mybool0() != false || typeof d.mybool0() != typeof false) { + throw new Error; +} + +if (d.mybool1() != true || typeof d.mybool1() != typeof false) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/default_args_c_runme.js b/Examples/test-suite/javascript/default_args_c_runme.js new file mode 100644 index 000000000..a252802a1 --- /dev/null +++ b/Examples/test-suite/javascript/default_args_c_runme.js @@ -0,0 +1,28 @@ +var default_args_c = require("default_args_c"); + +if (default_args_c.foo1() != 1) { + throw new Error("failed"); +} +if (default_args_c.foo43() != 43) { + throw new Error("failed"); +} + +f = new default_args_c.FooStruct(); +f.no_arg(); +f.one_req(null); +f.one_opt(); +f.one_opt(null); +f.two_arg(null); +f.two_arg(null, null); + +default_args_c.StaticStruct.no_arg(); +default_args_c.StaticStruct.one_req(null); +default_args_c.StaticStruct.one_opt(); +default_args_c.StaticStruct.one_opt(null); +default_args_c.StaticStruct.two_arg(null); +default_args_c.StaticStruct.two_arg(null, null); + +default_args_c.global_opts1(); +default_args_c.global_opts1(null); +default_args_c.global_opts2(null); +default_args_c.global_opts2(null, null); diff --git a/Examples/test-suite/javascript/default_args_runme.js b/Examples/test-suite/javascript/default_args_runme.js new file mode 100644 index 000000000..23603481a --- /dev/null +++ b/Examples/test-suite/javascript/default_args_runme.js @@ -0,0 +1,216 @@ +var default_args = require('default_args'); +ec = new default_args.EnumClass(); +if (!ec.blah()) { + throw new Error("EnumClass::blah() default arguments don't work"); +} + +de = new default_args.DerivedEnumClass(); +de.accelerate(); +de.accelerate(default_args.EnumClass.SLOW); + +if (default_args.Statics.staticMethod() != 60) { + throw new Error; +} + +if (default_args.cfunc1(1) != 2) { + throw new Error; +} + +if (default_args.cfunc2(1) != 3) { + throw new Error; +} + +if (default_args.cfunc3(1) != 4) { + throw new Error; +} + +f = new default_args.Foo(); + +f.newname(); +f.newname(1); +f.defaulted1(); +f.defaulted2(); + +if (f.double_if_void_ptr_is_null(2, null) != 4) { + throw new Error; +} + +if (f.double_if_void_ptr_is_null(3) != 6) { + throw new Error; +} + +if (f.double_if_handle_is_null(4, null) != 8) { + throw new Error; +} + +if (f.double_if_handle_is_null(5) != 10) { + throw new Error; +} + +if (f.double_if_dbl_ptr_is_null(6, null) != 12) { + throw new Error; +} + +if (f.double_if_dbl_ptr_is_null(7) != 14) { + throw new Error; +} + +try { + f = default_args.Foo(1); + error = 1; +} catch { + error = 0; +} +if (error) { + throw new Error("Foo::Foo ignore is not working"); +} + +try { + f = default_args.Foo(1, 2); + error = 1; +} catch { + error = 0; +} +if (error) { + throw new Error("Foo::Foo ignore is not working"); +} + +try { + f = default_args.Foo(1, 2, 3); + error = 1; +} catch { + error = 0; +} +if (error) { + throw new Error("Foo::Foo ignore is not working"); +} + +try { + m = f.meth(1); + error = 1; +} catch { + error = 0; +} +if (error) { + throw new Error("Foo::meth ignore is not working"); +} + +try { + m = f.meth(1, 2); + error = 1; +} catch { + error = 0; +} +if (error) { + throw new Error("Foo::meth ignore is not working"); +} + +try { + m = f.meth(1, 2, 3); + error = 1; +} catch { + error = 0; +} +if (error) { + throw new Error("Foo::meth ignore is not working"); +} + +Klass_inc = default_args.Klass.inc; + +if (Klass_inc(100, new default_args.Klass(22)).val != 122) { + throw new Error("Klass::inc failed"); +} + +if (Klass_inc(100).val != 99) { + throw new Error("Klass::inc failed"); +} + +if (Klass_inc().val != 0) { + throw new Error("Klass::inc failed"); +} + +tricky = new default_args.TrickyInPython(); +if (tricky.value_m1(10) != -1) { + throw new Error("trickyvalue_m1 failed"); +} +if (tricky.value_m1(10, 10) != 10) { + throw new Error("trickyvalue_m1 failed"); +} +if (tricky.value_0xabcdef(10) != 0xabcdef) { + throw new Error("trickyvalue_0xabcdef failed"); +} +if (tricky.value_0644(10) != 420) { + throw new Error("trickyvalue_0644 failed"); +} +if (tricky.value_perm(10) != 420) { + throw new Error("trickyvalue_perm failed"); +} +if (tricky.value_m01(10) != -1) { + throw new Error("trickyvalue_m01 failed"); +} +if (!tricky.booltest2()) { + throw new Error("booltest2 failed"); +} + +if (tricky.max_32bit_int1() != 0x7FFFFFFF) { + throw new Error("max_32bit_int1 failed"); +} +if (tricky.min_32bit_int1() != -2147483648) { + throw new Error("min_32bit_int1 failed"); +} +if (tricky.max_32bit_int2() != 0x7FFFFFFF) { + throw new Error("max_32bit_int2 failed"); +} + +tricky.too_big_32bit_int1(); +tricky.too_small_32bit_int1(); +tricky.too_big_32bit_int2(); +tricky.too_small_32bit_int2(); + +default_args.seek(); +default_args.seek(10); + +if (!default_args.booltest()) { + throw new Error("booltest failed"); +} + +if (default_args.slightly_off_square(10) != 102) { + throw new Error; +} + +if (default_args.slightly_off_square() != 291) { + throw new Error; +} + +if ((new default_args.CDA()).cdefaultargs_test1() != 1) { + throw new Error; +} + +if ((new default_args.CDA()).cdefaultargs_test2() != 1) { + throw new Error; +} + +if (default_args.chartest1() != "x") { + throw new Error; +} + +// JavaScriptCore cannot accept a '\0' string +if (default_args.chartest2() != "\0" && default_args.chartest2() != '') { + throw new Error; +} + +if (default_args.chartest3() != "\1") { + throw new Error; +} + +if (default_args.chartest4() != "\n") { + throw new Error; +} + +if (default_args.chartest5() != "B") { + throw new Error; +} + +if (default_args.chartest6() != "C") { + throw new Error; +} diff --git a/Examples/test-suite/javascript/enums_runme.js b/Examples/test-suite/javascript/enums_runme.js new file mode 100644 index 000000000..02f6a4cff --- /dev/null +++ b/Examples/test-suite/javascript/enums_runme.js @@ -0,0 +1,22 @@ + +var enums = require("enums"); + +enums.bar2(1); +enums.bar3(1); +enums.bar1(1); + +if (enums.enumInstance != 2) { + throw new Error; +} + +if (enums.Slap != 10) { + throw new Error; +} + +if (enums.Mine != 11) { + throw new Error; +} + +if (enums.Thigh != 12) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/exception_classname_runme.js b/Examples/test-suite/javascript/exception_classname_runme.js new file mode 100644 index 000000000..6e97cb6a9 --- /dev/null +++ b/Examples/test-suite/javascript/exception_classname_runme.js @@ -0,0 +1,6 @@ +var exception_classname = require("exception_classname"); + +a = new exception_classname.Exception(); +if (a.testfunc() != 42) { + throw new Error("Not 42!"); +} diff --git a/Examples/test-suite/javascript/extend_placement_runme.js b/Examples/test-suite/javascript/extend_placement_runme.js new file mode 100644 index 000000000..1644cb75f --- /dev/null +++ b/Examples/test-suite/javascript/extend_placement_runme.js @@ -0,0 +1,46 @@ +var extend_placement = require("extend_placement"); + +foo = new extend_placement.Foo(); +foo = new extend_placement.Foo(1); +foo = new extend_placement.Foo(1, 1); +foo.spam(); +foo.spam("hello"); +foo.spam(1); +foo.spam(1, 1); +foo.spam(1, 1, 1); +foo.spam(new extend_placement.Foo()); +foo.spam(new extend_placement.Foo(), 1.0); + + +bar = new extend_placement.Bar(); +bar = new extend_placement.Bar(1); +bar.spam(); +bar.spam("hello"); +bar.spam(1); +bar.spam(1, 1); +bar.spam(1, 1, 1); +bar.spam(new extend_placement.Bar()); +bar.spam(new extend_placement.Bar(), 1.0); + + +foo = new extend_placement.FooTi(); +foo = new extend_placement.FooTi(1); +foo = new extend_placement.FooTi(1, 1); +foo.spam(); +foo.spam("hello"); +foo.spam(1); +foo.spam(1, 1); +foo.spam(1, 1, 1); +foo.spam(new extend_placement.Foo()); +foo.spam(new extend_placement.Foo(), 1.0); + + +bar = new extend_placement.BarTi(); +bar = new extend_placement.BarTi(1); +bar.spam(); +bar.spam("hello"); +bar.spam(1); +bar.spam(1, 1); +bar.spam(1, 1, 1); +bar.spam(new extend_placement.Bar()); +bar.spam(new extend_placement.Bar(), 1.0); diff --git a/Examples/test-suite/javascript/extend_template_method_runme.js b/Examples/test-suite/javascript/extend_template_method_runme.js new file mode 100644 index 000000000..42402045d --- /dev/null +++ b/Examples/test-suite/javascript/extend_template_method_runme.js @@ -0,0 +1,54 @@ +var extend_template_method = require("extend_template_method"); + +em = new extend_template_method.ExtendMe(); + +ret_double = em.do_stuff_double(1, 1.1); +if (ret_double != 1.1) { + throw new Error("double failed " + ret_double); +} +ret_string = em.do_stuff_string(1, "hello there"); +if (ret_string != "hello there") { + throw new Error("string failed " + ret_string); +} + +ret_double = em.do_overloaded_stuff(1.1); +if (ret_double != 1.1) { + throw new Error("double failed " + ret_double); +} +ret_string = em.do_overloaded_stuff("hello there"); +if (ret_string != "hello there") { + throw new Error("string failed " + ret_string); +} + +if (extend_template_method.ExtendMe.static_method(123) != 123) { + throw new Error("static_method failed"); +} + +em2 = new extend_template_method.ExtendMe(123); + +em = new extend_template_method.TemplateExtend(); + +ret_double = em.do_template_stuff_double(1, 1.1); +if (ret_double != 1.1) { + throw new Error("double failed " + ret_double); +} +ret_string = em.do_template_stuff_string(1, "hello there"); +if (ret_string != "hello there") { + throw new Error("string failed " + ret_string); +} + + +ret_double = em.do_template_overloaded_stuff(1.1); +if (ret_double != 1.1) { + throw new Error("double failed " + ret_double); +} +ret_string = em.do_template_overloaded_stuff("hello there"); +if (ret_string != "hello there") { + throw new Error("string failed " + ret_string); +} + +if (extend_template_method.TemplateExtend.static_template_method(123) != 123) { + throw new Error("static_template_method failed"); +} + +em2 = new extend_template_method.TemplateExtend(123); diff --git a/Examples/test-suite/javascript/extend_template_ns_runme.js b/Examples/test-suite/javascript/extend_template_ns_runme.js new file mode 100644 index 000000000..d6ae71c61 --- /dev/null +++ b/Examples/test-suite/javascript/extend_template_ns_runme.js @@ -0,0 +1,9 @@ +var extend_template_ns = require("extend_template_ns"); +f = new extend_template_ns.Foo_One(); +if (f.test1(37) != 37) { + throw new Error; +} + +if (f.test2(42) != 42) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/extend_template_runme.js b/Examples/test-suite/javascript/extend_template_runme.js new file mode 100644 index 000000000..e8decbb1e --- /dev/null +++ b/Examples/test-suite/javascript/extend_template_runme.js @@ -0,0 +1,10 @@ +var extend_template = require("extend_template"); + +f = new extend_template.Foo_0(); +if (f.test1(37) != 37) { + throw new Error; +} + +if (f.test2(42) != 42) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/extend_variable_runme.js b/Examples/test-suite/javascript/extend_variable_runme.js new file mode 100644 index 000000000..5e111a552 --- /dev/null +++ b/Examples/test-suite/javascript/extend_variable_runme.js @@ -0,0 +1,5 @@ +var extend_variable = require("extend_variable"); + +if (extend_variable.Foo.Bar != 42) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/extern_c_runme.js b/Examples/test-suite/javascript/extern_c_runme.js new file mode 100644 index 000000000..43d60a636 --- /dev/null +++ b/Examples/test-suite/javascript/extern_c_runme.js @@ -0,0 +1,12 @@ +var extern_c = require("extern_c"); + +function check(flag) { + if (!flag) { + throw new Error("Test failed"); + } +} + +extern_c.RealFunction(2); +check(extern_c.int2 == 123); +check(extern_c.int3 == 456); +check(extern_c.int4 == 789); diff --git a/Examples/test-suite/javascript/final_c_runme.js b/Examples/test-suite/javascript/final_c_runme.js new file mode 100644 index 000000000..98d74ed98 --- /dev/null +++ b/Examples/test-suite/javascript/final_c_runme.js @@ -0,0 +1,7 @@ +var final_c = require("final_c"); + +final_c.init(); +f = final_c.final; +if ((f.yval != 123)) { + throw new Error("f.yval fail"); +} diff --git a/Examples/test-suite/javascript/friends_runme.js b/Examples/test-suite/javascript/friends_runme.js new file mode 100644 index 000000000..6913eb935 --- /dev/null +++ b/Examples/test-suite/javascript/friends_runme.js @@ -0,0 +1,53 @@ +var friends = require("friends"); + +a = new friends.A(2); + +if (friends.get_val1(a) != 2) { + throw new Error; +} +if (friends.get_val2(a) != 4) { + throw new Error; +} +if (friends.get_val3(a) != 6) { + throw new Error; +} + +// nice overload working fine +if (friends.get_val1(1, 2, 3) != 1) { + throw new Error; +} + +b = new friends.B(3); + +// David's case +if (friends.mix(a, b) != 5) { + throw new Error; +} + +di = new friends.D_i(2); +dd = new friends.D_d(3.3); + +// incredible template overloading working just fine +if (friends.get_val1(di) != 2) { + throw new Error; +} +if (friends.get_val1(dd) != 3.3) { + throw new Error; +} + +friends.set(di, 4); +friends.set(dd, 1.3); + +if (friends.get_val1(di) != 4) { + throw new Error; +} +if (friends.get_val1(dd) != 1.3) { + throw new Error; +} + +if (friends.chum_blah() != 1234) { + throw new Error("failed"); +} +if (friends.mate_blah() != 4321) { + throw new Error("failed"); +} diff --git a/Examples/test-suite/javascript/funcptr_cpp_runme.js b/Examples/test-suite/javascript/funcptr_cpp_runme.js new file mode 100644 index 000000000..c1f76ca80 --- /dev/null +++ b/Examples/test-suite/javascript/funcptr_cpp_runme.js @@ -0,0 +1,17 @@ +var funcptr_cpp = require("funcptr_cpp"); + +if (funcptr_cpp.call1(funcptr_cpp.ADD_BY_VALUE, 10, 11) != 21) { + throw new Error; +} +if (funcptr_cpp.call2(funcptr_cpp.ADD_BY_POINTER, 12, 13) != 25) { + throw new Error; +} +if (funcptr_cpp.call3(funcptr_cpp.ADD_BY_REFERENCE, 14, 15) != 29) { + throw new Error; +} +if (funcptr_cpp.call1(funcptr_cpp.ADD_BY_VALUE_C, 2, 3) != 5) { + throw new Error; +} +if (funcptr_cpp.callconst1(funcptr_cpp.ADD_BY_VALUE_C, 2, 3) != 5) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/functors_runme.js b/Examples/test-suite/javascript/functors_runme.js new file mode 100644 index 000000000..1c68282eb --- /dev/null +++ b/Examples/test-suite/javascript/functors_runme.js @@ -0,0 +1,12 @@ +var functors = require("functors"); + +var a = new functors.Functor0(10); +var b = new functors.Functor1(10); +var c = new functors.Functor2(10); + +if (a.Funktor() != -10) + throw Error("a failed"); +if (b.Funktor(1) != 11) + throw Error("b failed"); +if (c.Funktor(1, 2) != 13) + throw Error("c failed"); diff --git a/Examples/test-suite/javascript/fvirtual_runme.js b/Examples/test-suite/javascript/fvirtual_runme.js new file mode 100644 index 000000000..a6dbcb96f --- /dev/null +++ b/Examples/test-suite/javascript/fvirtual_runme.js @@ -0,0 +1,8 @@ +var fvirtual = require('fvirtual'); + +var sw = new fvirtual.NodeSwitch(); +var n = new fvirtual.Node(); +var i = sw.addChild(n); + +if (i != 2) + throw Error("addChild"); diff --git a/Examples/test-suite/javascript/global_functions_runme.js b/Examples/test-suite/javascript/global_functions_runme.js new file mode 100644 index 000000000..f2d8f0ea9 --- /dev/null +++ b/Examples/test-suite/javascript/global_functions_runme.js @@ -0,0 +1,69 @@ +var global_functions = require("global_functions"); + + +function check(a, b) { + if (a != b) { + throw new Error("Failed: " + str(a) + " != " + str(b)); + } +} +global_functions.global_void(); +check(global_functions.global_one(1), 1); +check(global_functions.global_two(2, 2), 4); + +fail = true; +try { + global_functions.global_void(1); +} catch (e) { + if (e instanceof TypeError) fail = false; +} +fail = false; +if (fail) { + throw new Error("argument count check failed"); +} + +fail = true; +try { + global_functions.global_one(); +} catch (e) { + if (e instanceof TypeError) fail = false; +} +fail = false; +if (fail) { + throw new Error("argument count check failed"); +} + +fail = true; +try { + global_functions.global_one(2, 2); +} catch (e) { + if (e instanceof TypeError) fail = false; +} +fail = false; + +if (fail) { + throw new Error("argument count check failed"); +} + +fail = true; +try { + global_functions.global_two(1); +} catch (e) { + if (e instanceof TypeError) fail = false; +} +fail = false; + +if (fail) { + throw new Error("argument count check failed"); +} + +fail = true; +try { + global_functions.global_two(3, 3, 3); +} catch (e) { + if (e instanceof TypeError) fail = false; +} +fail = false; + +if (fail) { + throw new Error("argument count check failed"); +} diff --git a/Examples/test-suite/javascript/global_namespace_runme.js b/Examples/test-suite/javascript/global_namespace_runme.js new file mode 100644 index 000000000..f90fece60 --- /dev/null +++ b/Examples/test-suite/javascript/global_namespace_runme.js @@ -0,0 +1,41 @@ +var global_namespace = require("global_namespace"); + + +k1 = new global_namespace.Klass1(); +k2 = new global_namespace.Klass2(); +k3 = new global_namespace.Klass3(); +k4 = new global_namespace.Klass4(); +k5 = new global_namespace.Klass5(); +k6 = new global_namespace.Klass6(); +k7 = new global_namespace.Klass7(); + +global_namespace.KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7); +global_namespace.KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7); + +k1 = global_namespace.getKlass1A(); +k2 = global_namespace.getKlass2A(); +k3 = global_namespace.getKlass3A(); +k4 = global_namespace.getKlass4A(); +k5 = global_namespace.getKlass5A(); +k6 = global_namespace.getKlass6A(); +k7 = global_namespace.getKlass7A(); + +global_namespace.KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7); +global_namespace.KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7); + +k1 = global_namespace.getKlass1B(); +k2 = global_namespace.getKlass2B(); +k3 = global_namespace.getKlass3B(); +k4 = global_namespace.getKlass4B(); +k5 = global_namespace.getKlass5B(); +k6 = global_namespace.getKlass6B(); +k7 = global_namespace.getKlass7B(); + +global_namespace.KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7); +global_namespace.KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7); + +global_namespace.XYZMethods.methodA(new global_namespace.XYZ1(), new global_namespace.XYZ2(), new global_namespace.XYZ3(), new global_namespace.XYZ4(), new global_namespace.XYZ5(), new global_namespace.XYZ6(), new global_namespace.XYZ7()); +global_namespace.XYZMethods.methodB(new global_namespace.XYZ1(), new global_namespace.XYZ2(), new global_namespace.XYZ3(), new global_namespace.XYZ4(), new global_namespace.XYZ5(), new global_namespace.XYZ6(), new global_namespace.XYZ7()); + +global_namespace.TheEnumMethods.methodA(global_namespace.theenum1, global_namespace.theenum2, global_namespace.theenum3); +global_namespace.TheEnumMethods.methodA(global_namespace.theenum1, global_namespace.theenum2, global_namespace.theenum3); diff --git a/Examples/test-suite/javascript/global_ns_arg_runme.js b/Examples/test-suite/javascript/global_ns_arg_runme.js new file mode 100644 index 000000000..fbbc65912 --- /dev/null +++ b/Examples/test-suite/javascript/global_ns_arg_runme.js @@ -0,0 +1,4 @@ +var global_ns_arg = require("global_ns_arg"); + +a = global_ns_arg.foo(1); +b = global_ns_arg.bar_fn(); diff --git a/Examples/test-suite/javascript/global_vars_runme.js b/Examples/test-suite/javascript/global_vars_runme.js new file mode 100644 index 000000000..1f5e1718a --- /dev/null +++ b/Examples/test-suite/javascript/global_vars_runme.js @@ -0,0 +1,25 @@ +var global_vars = require("global_vars"); + +// In javascript, assigning to a non-existent variable is +// not an error + +global_vars.init(); +b = global_vars.b; +if (b != "string b") { + throw new Error("Unexpected string: " + b.toString()); +} +global_vars.b = "a string value"; +b = global_vars.b; +if (b != "a string value") { + throw new Error("Unexpected string: " + b.toString()); +} + +x = global_vars.x; +if (x != 1234) { + throw new Error("Unexpected x: " + x.toString()); +} +global_vars.x = 9876; +x = global_vars.x; +if (x != 9876) { + throw new Error("Unexpected string: " + x.toString()); +} diff --git a/Examples/test-suite/javascript/grouping_runme.js b/Examples/test-suite/javascript/grouping_runme.js new file mode 100644 index 000000000..2649dea8f --- /dev/null +++ b/Examples/test-suite/javascript/grouping_runme.js @@ -0,0 +1,15 @@ +var grouping = require("grouping"); + +var x = grouping.test1(42); +if (x != 42) + throw new Error; + +grouping.test2(42); + +var x = grouping.do_unary(37, grouping.NEGATE); +if (x != -37) + throw new Error; + +grouping.test3 = 42; +if (grouping.test3 !== 42) + throw new Error; diff --git a/Examples/test-suite/javascript/iadd_runme.js b/Examples/test-suite/javascript/iadd_runme.js new file mode 100644 index 000000000..0036ac353 --- /dev/null +++ b/Examples/test-suite/javascript/iadd_runme.js @@ -0,0 +1,9 @@ +var iadd = require('iadd'); + +var f = new iadd.Foo(); + +f.AsA.x = 3; +f.AsA.addto(f.AsA); + +if (f.AsA.x != 6) + throw new Error; diff --git a/Examples/test-suite/javascript/ignore_parameter_runme.js b/Examples/test-suite/javascript/ignore_parameter_runme.js new file mode 100644 index 000000000..07dcf2f7d --- /dev/null +++ b/Examples/test-suite/javascript/ignore_parameter_runme.js @@ -0,0 +1,24 @@ +const ignore_parameter = require('ignore_parameter'); + +function check(a, b) { + if (a !== b) throw new Error(`'${a}' != '${b}`); +} + +check(ignore_parameter.jaguar(200, 0), "hello"); +check(ignore_parameter.lotus("foo", 1), 101); +check(ignore_parameter.tvr("bar", 2), 8.8); +check(ignore_parameter.ferrari(), 101); +check(ignore_parameter.fiat(17), 17); + +car = new ignore_parameter.SportsCars(); +check(car.daimler(200, 0), "hello"); +check(car.astonmartin("foo", 1), 101); +check(car.bugatti("bar", 2), 8.8); +check(car.lamborghini(), 101); +check(car.maseratti(289), 289); +check(car.audi(), 8.8); + +new ignore_parameter.MiniCooper(200, 0); +new ignore_parameter.MorrisMinor("baz", 0); +new ignore_parameter.FordAnglia("quux", 200); +new ignore_parameter.AustinAllegro(); diff --git a/Examples/test-suite/javascript/import_nomodule_runme.js b/Examples/test-suite/javascript/import_nomodule_runme.js new file mode 100644 index 000000000..ad3340119 --- /dev/null +++ b/Examples/test-suite/javascript/import_nomodule_runme.js @@ -0,0 +1,8 @@ +var import_nomodule = require("import_nomodule"); + +f = import_nomodule.create_Foo(); +import_nomodule.test1(f, 42); +import_nomodule.delete_Foo(f); + +b = new import_nomodule.Bar(); +import_nomodule.test1(b, 37); diff --git a/Examples/test-suite/javascript/inctest_runme.js b/Examples/test-suite/javascript/inctest_runme.js new file mode 100644 index 000000000..e0a42eab4 --- /dev/null +++ b/Examples/test-suite/javascript/inctest_runme.js @@ -0,0 +1,22 @@ +var inctest = require("inctest"); + +try { + a = new inctest.A(); +} catch (e) { + throw new Error("didn't find A, therefore, I didn't include 'testdir/subdir1/hello.i'"); +} + +try { + b = new inctest.B(); +} catch (e) { + throw new Error("didn't find B, therefore, I didn't include 'testdir/subdir2/hello.i'"); +} + +// Check the var in subdirectory worked = require("in subdirectory worked") +if (inctest.importtest1(5) != 15) { + throw new Error("var test 1 failed"); +} + +if (inctest.importtest2("black") != "white") { + throw new Error("var test 2 failed"); +} diff --git a/Examples/test-suite/javascript/inherit_missing_runme.js b/Examples/test-suite/javascript/inherit_missing_runme.js new file mode 100644 index 000000000..05f5760e2 --- /dev/null +++ b/Examples/test-suite/javascript/inherit_missing_runme.js @@ -0,0 +1,19 @@ +var inherit_missing = require("inherit_missing"); + +a = inherit_missing.new_Foo() +b = new inherit_missing.Bar() +c = new inherit_missing.Spam() + +x = inherit_missing.do_blah(a) +if (x != "Foo::blah") + throw new Error("Whoa! Bad return {}".format(x)) + +x = inherit_missing.do_blah(b) +if (x != "Bar::blah") + throw new Error("Whoa! Bad return {}".format(x)) + +x = inherit_missing.do_blah(c) +if (x != "Spam::blah") + throw new Error("Whoa! Bad return {}".format(x)) + +inherit_missing.delete_Foo(a) diff --git a/Examples/test-suite/javascript/inplaceadd_runme.js b/Examples/test-suite/javascript/inplaceadd_runme.js new file mode 100644 index 000000000..436d58198 --- /dev/null +++ b/Examples/test-suite/javascript/inplaceadd_runme.js @@ -0,0 +1,23 @@ +var inplaceadd = require("inplaceadd"); +a = new inplaceadd.A(7); + +a.addTo(5); +if (a.val != 12) { + throw new Error(`a.val: ${a.val}`); +} + +a.subFrom(5); +if (a.val != 7) { + throw new Error(`a.val: ${a.val}`); +} + +a.mulTo(2); + +if (a.val != 14) { + throw new Error(`a.val: ${a.val}`); +} + +a.addTo(a); +if (a.val != 28) { + throw new Error(`a.val: ${a.val}`); +} diff --git a/Examples/test-suite/javascript/input_runme.js b/Examples/test-suite/javascript/input_runme.js new file mode 100644 index 000000000..bc970f019 --- /dev/null +++ b/Examples/test-suite/javascript/input_runme.js @@ -0,0 +1,22 @@ +var input = require("input"); + +f = new input.Foo(); +if (f.foo(2) != 4) { + throw new Error; +} + +if (f.foo(null) != null) { + throw new Error; +} + +if (f.foo() != null) { + throw new Error; +} + +if (input.sfoo("Hello") != "Hello world") { + throw new Error; +} + +if (input.sfoo() != null) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/integers_runme.js b/Examples/test-suite/javascript/integers_runme.js new file mode 100644 index 000000000..4aeb13d7a --- /dev/null +++ b/Examples/test-suite/javascript/integers_runme.js @@ -0,0 +1,24 @@ +var integers = require("integers"); + +function checkOne(val, signed, typeName) { + typeName = (signed ? 'signed_' : 'unsigned_') + typeName + + var size = integers[typeName + '_size']() + if ((!signed && val < 0) || (size < 8)) + return // out of range, skip test + + ret = integers[typeName + '_identity'](val) + if (ret !== val) + throw "Incorrect value: expected " + val + ", got " + ret +} + +function checkAll(val) { + checkOne(val, true, 'long') + checkOne(val, false, 'long') + checkOne(val, true, 'long_long') + checkOne(val, false, 'long_long') +} + +checkAll(3902408827) +checkAll(Number.MAX_SAFE_INTEGER) +checkAll(Number.MIN_SAFE_INTEGER) diff --git a/Examples/test-suite/javascript/javascript_lib_arrays_runme.js b/Examples/test-suite/javascript/javascript_lib_arrays_runme.js new file mode 100644 index 000000000..1eb586134 --- /dev/null +++ b/Examples/test-suite/javascript/javascript_lib_arrays_runme.js @@ -0,0 +1,20 @@ +var javascript_lib_arrays = require("javascript_lib_arrays"); + +var arr = [1, 2, 3, 4, 5]; + +function check(a, b) { + if (a !== b) { + throw new Error("Not equal: " + a + " " + b) + } +} + +function check_array(a, b) { + if (a.length != b.length) + throw new Error("Array length mismatch " + a.length + " " + b.length) + if (!a.every(function(element, index) { return element === b[index]; })) + throw new Error("Arrays don't match a:" + a + " b:" + b) +} + +check(15, javascript_lib_arrays.sum1(arr, arr.length)); +check(6, javascript_lib_arrays.sum2(arr)); +check_array([1, 2, 3, 4], javascript_lib_arrays.data3) diff --git a/Examples/test-suite/javascript/keyword_rename_c_runme.js b/Examples/test-suite/javascript/keyword_rename_c_runme.js new file mode 100644 index 000000000..148443723 --- /dev/null +++ b/Examples/test-suite/javascript/keyword_rename_c_runme.js @@ -0,0 +1,3 @@ +var keyword_rename_c = require("keyword_rename_c"); +keyword_rename_c._instanceof(1); +keyword_rename_c._finally(1); diff --git a/Examples/test-suite/javascript/keyword_rename_runme.js b/Examples/test-suite/javascript/keyword_rename_runme.js new file mode 100644 index 000000000..54b9ecc6d --- /dev/null +++ b/Examples/test-suite/javascript/keyword_rename_runme.js @@ -0,0 +1,3 @@ +var keyword_rename = require("keyword_rename") +keyword_rename._instanceof(1) +keyword_rename._finally(1) diff --git a/Examples/test-suite/javascript/langobj_runme.js b/Examples/test-suite/javascript/langobj_runme.js new file mode 100644 index 000000000..c033c98e8 --- /dev/null +++ b/Examples/test-suite/javascript/langobj_runme.js @@ -0,0 +1,7 @@ +var langobj = require("langobj"); + +x = "hello"; +v = langobj.identity(x); +if (v !== x) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/li_attribute_runme.js b/Examples/test-suite/javascript/li_attribute_runme.js new file mode 100644 index 000000000..707bea1f7 --- /dev/null +++ b/Examples/test-suite/javascript/li_attribute_runme.js @@ -0,0 +1,107 @@ +var li_attribute = require("li_attribute"); + +aa = new li_attribute.A(1, 2, 3); + +if (aa.a != 1) { + throw new Error; +} +aa.a = 3; +if (aa.a != 3) { + throw new Error("aa.a: {}" + aa.a.toString()); +} + +if (aa.b != 2) { + throw new Error("aa.b: {}" + aa.b.toString()); +} +aa.b = 5; +if (aa.b != 5) { + throw new Error; +} + +if (aa.d != aa.b) { + throw new Error; +} + +if (aa.c != 3) { + throw new Error; +} +fail = true; +try { + aa.c = 5; +} catch (e) { + fail = false; +} +if (aa.c != 3 || fail) { + throw new Error; +} + +pi = new li_attribute.Param_i(7); +if (pi.value != 7) { + throw new Error; +} + +pi.value = 3; +if (pi.value != 3) { + throw new Error; +} + +b = new li_attribute.B(aa); + +if (b.a.c != 3) { + throw new Error; +} + +// class/struct attribute with get/set methods using return/pass by reference +myFoo = new li_attribute.MyFoo(); +myFoo.x = 8; +myClass = new li_attribute.MyClass(); +myClass.Foo = myFoo; +if (myClass.Foo.x != 8) { + throw new Error; +} +myClass.Foo2 = myFoo; +if (myClass.Foo2.x != 8) { + throw new Error; +} + +// class/struct attribute with get/set methods using return/pass by value +myClassVal = new li_attribute.MyClassVal(); +if (myClassVal.ReadWriteFoo.x != -1) { + throw new Error; +} +if (myClassVal.ReadOnlyFoo.x != -1) { + throw new Error; +} +myClassVal.ReadWriteFoo = myFoo; +if (myClassVal.ReadWriteFoo.x != 8) { + throw new Error; +} +if (myClassVal.ReadOnlyFoo.x != 8) { + throw new Error; +} + +// string attribute with get/set methods using return/pass by value +myStringyClass = new li_attribute.MyStringyClass("initial string"); +if (myStringyClass.ReadWriteString != "initial string") { + throw new Error; +} +if (myStringyClass.ReadOnlyString != "initial string") { + throw new Error; +} +myStringyClass.ReadWriteString = "changed string"; +if (myStringyClass.ReadWriteString != "changed string") { + throw new Error; +} +if (myStringyClass.ReadOnlyString != "changed string") { + throw new Error; +} + +// In JS, accessing a non-existing attribute does not throw, it returns undefined +if (myFoo.does_not_exist !== undefined) { + throw new Error; +} +// Additionally, creating attributes is always possible unless the object is frozen +myFoo.does_not_exist = 'value'; +if (myFoo.does_not_exist !== 'value') { + throw new Error; +} diff --git a/Examples/test-suite/javascript/li_attribute_template_runme.js b/Examples/test-suite/javascript/li_attribute_template_runme.js new file mode 100644 index 000000000..57a934e80 --- /dev/null +++ b/Examples/test-suite/javascript/li_attribute_template_runme.js @@ -0,0 +1,69 @@ +// Check usage of template attributes + +var li_attribute_template = require("li_attribute_template"); + +chell = new li_attribute_template.Cintint(1, 2, 3); + + +function rassert(what, master) { + if (what != master) { + throw new Error("what: {}".format(what)); + } +} + +// Testing primitive by value attribute +rassert(chell.a, 1); + +chell.a = 3; +rassert(chell.a, 3); + +// Testing primitive by ref attribute + +rassert(chell.b, 2); + +chell.b = 5; +rassert(chell.b, 5); + +// Testing string +chell.str = "abc"; +rassert(chell.str, "abc"); + +// Testing class by value + +rassert(chell.d.value, 1); + +chell.d = new li_attribute_template.Foo(2); +rassert(chell.d.value, 2); + +// Testing class by reference + +rassert(chell.e.value, 2); + +chell.e = new li_attribute_template.Foo(3); +rassert(chell.e.value, 3); + +chell.e.value = 4; +rassert(chell.e.value, 4); + +// Testing moderately complex template by value +rassert(chell.f.first, 1); +rassert(chell.f.second, 2); + +pair = new li_attribute_template.pair_intint(3, 4); +chell.f = pair; +rassert(chell.f.first, 3); +rassert(chell.f.second, 4); + +// Testing moderately complex template by ref +rassert(chell.g.first, 2); +rassert(chell.g.second, 3); + +pair = new li_attribute_template.pair_intint(4, 5); +chell.g = pair; +rassert(chell.g.first, 4); +rassert(chell.g.second, 5); + +chell.g.first = 6; +chell.g.second = 7; +rassert(chell.g.first, 6); +rassert(chell.g.second, 7); diff --git a/Examples/test-suite/javascript/li_carrays_cpp_runme.js b/Examples/test-suite/javascript/li_carrays_cpp_runme.js new file mode 100644 index 000000000..ca4802e4b --- /dev/null +++ b/Examples/test-suite/javascript/li_carrays_cpp_runme.js @@ -0,0 +1,25 @@ +var li_carrays_cpp = require("li_carrays_cpp"); + +d = new li_carrays_cpp.doubleArray(10); + +d.setitem(0, 7); +d.setitem(5, d.getitem(0) + 3); + +if (d.getitem(5) + d.getitem(0) != 17) { + throw new Error; +} + +shorts = new li_carrays_cpp.shortArray(5); + +sum = li_carrays_cpp.sum_array(shorts); +if (sum != 0) { + throw new Error("incorrect zero sum, got: " + sum.toString()); +} + +for (i = 0; i < 5; i++) + shorts.setitem(i, i); + +sum = li_carrays_cpp.sum_array(shorts); +if (sum != 0 + 1 + 2 + 3 + 4) { + throw new Error("incorrect sum, got: " + sum.toString()); +} diff --git a/Examples/test-suite/javascript/li_carrays_runme.js b/Examples/test-suite/javascript/li_carrays_runme.js new file mode 100644 index 000000000..44f1f2611 --- /dev/null +++ b/Examples/test-suite/javascript/li_carrays_runme.js @@ -0,0 +1,25 @@ +var li_carrays = require("li_carrays"); + +d = new li_carrays.doubleArray(10); + +d.setitem(0, 7); +d.setitem(5, d.getitem(0) + 3); + +if (d.getitem(5) + d.getitem(0) != 17) { + throw new Error; +} + +shorts = new li_carrays.shortArray(5); + +sum = li_carrays.sum_array(shorts); +if (sum != 0) { + throw new Error("incorrect zero sum, got: " + sum.toString()); +} + +for (i = 0; i < 5; i++) + shorts.setitem(i, i); + +sum = li_carrays.sum_array(shorts); +if (sum != 0 + 1 + 2 + 3 + 4) { + throw new Error("incorrect sum, got: " + sum.toString()); +} diff --git a/Examples/test-suite/javascript/li_cdata_cpp_runme.js b/Examples/test-suite/javascript/li_cdata_cpp_runme.js new file mode 100644 index 000000000..1a88d002f --- /dev/null +++ b/Examples/test-suite/javascript/li_cdata_cpp_runme.js @@ -0,0 +1,10 @@ + +var li_cdata_cpp = require("li_cdata_cpp"); + +s = "ABC abc"; +m = li_cdata_cpp.malloc(256); +li_cdata_cpp.memmove(m, s); +ss = li_cdata_cpp.cdata(m, 7); +if (ss !== "ABC abc") { + throw new Error("failed"); +} diff --git a/Examples/test-suite/javascript/li_cdata_runme.js b/Examples/test-suite/javascript/li_cdata_runme.js new file mode 100644 index 000000000..38c8467af --- /dev/null +++ b/Examples/test-suite/javascript/li_cdata_runme.js @@ -0,0 +1,10 @@ + +var li_cdata = require("li_cdata"); + +s = "ABC abc"; +m = li_cdata.malloc(256); +li_cdata.memmove(m, s); +ss = li_cdata.cdata(m, 7); +if (ss !== "ABC abc") { + throw new Error("failed"); +} diff --git a/Examples/test-suite/javascript/li_cmalloc_runme.js b/Examples/test-suite/javascript/li_cmalloc_runme.js new file mode 100644 index 000000000..5c2ba850d --- /dev/null +++ b/Examples/test-suite/javascript/li_cmalloc_runme.js @@ -0,0 +1,16 @@ +var li_cmalloc = require("li_cmalloc"); + +p = li_cmalloc.malloc_int(1); +li_cmalloc.free_int(p); + +ok = false; +try { + p = li_cmalloc.calloc_int(-1); + li_cmalloc.free_int(p); +} catch { + ok = true; +} + +if (!ok) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/li_constraints_runme.js b/Examples/test-suite/javascript/li_constraints_runme.js new file mode 100644 index 000000000..785ca4462 --- /dev/null +++ b/Examples/test-suite/javascript/li_constraints_runme.js @@ -0,0 +1,58 @@ +var li_constraints = require("li_constraints"); + +function check_double(except, f, val, name) { + var actual = true; + var proper = false; + try { + f(val); + } catch(e) { + actual = false; + proper = e.message === "Expected a " + name + " value."; + } + if (actual) { + if (!except) + throw new Error("function '" + name + "' with " + val + " should perform an exception"); + } else { + if (except) + throw new Error("function '" + name + "' with " + val + " should not perform an exception"); + else if (!proper) + throw new Error("function '" + name + "' with " + val + " should perform a proper exception"); + } +} + +const nonnegative = function (val) { li_constraints.test_nonnegative(val); }; +check_double(true, nonnegative, 10, "non-negative"); +check_double(true, nonnegative, 0, "non-negative"); +check_double(false, nonnegative, -10, "non-negative"); + +const nonpositive = function (val) { li_constraints.test_nonpositive(val); }; +check_double(false, nonpositive, 10, "non-positive"); +check_double(true, nonpositive, 0, "non-positive"); +check_double(true, nonpositive, -10, "non-positive"); + +const positive = function (val) { li_constraints.test_positive(val); }; +check_double(true, positive, 10, "positive"); +check_double(false, positive, 0, "positive"); +check_double(false, positive, -10, "positive"); + +const negative = function (val) { li_constraints.test_negative(val); }; +check_double(false, negative, 10, "negative"); +check_double(false, negative, 0, "negative"); +check_double(true, negative, -10, "negative"); + +const nonzero = function (val) { li_constraints.test_nonzero(val); }; +check_double(true, nonzero, 10, "nonzero"); +check_double(false, nonzero, 0, "nonzero"); +check_double(true, nonzero, -10, "nonzero"); + +var have_exception = false; +try { + li_constraints.test_nonnull(null); +} catch(e) { + have_exception = e.message === "Received a NULL pointer."; +} +if (!have_exception) { + throw new Error("test_nonnull should perform a proper exception with 'null' value"); +} +const nonnull = li_constraints.get_nonnull(); +li_constraints.test_nonnull(nonnull); diff --git a/Examples/test-suite/javascript/li_cpointer_cpp_runme.js b/Examples/test-suite/javascript/li_cpointer_cpp_runme.js new file mode 100644 index 000000000..4ba19eece --- /dev/null +++ b/Examples/test-suite/javascript/li_cpointer_cpp_runme.js @@ -0,0 +1,16 @@ +var li_cpointer_cpp = require("li_cpointer_cpp"); + + +p = li_cpointer_cpp.new_intp(); + +if (li_cpointer_cpp.intp_value(p) != 0) { + throw new Error("not initialized"); +} + +li_cpointer_cpp.intp_assign(p, 3); + +if (li_cpointer_cpp.intp_value(p) != 3) { + throw new Error; +} + +li_cpointer_cpp.delete_intp(p); diff --git a/Examples/test-suite/javascript/li_cpointer_runme.js b/Examples/test-suite/javascript/li_cpointer_runme.js new file mode 100644 index 000000000..836b79fac --- /dev/null +++ b/Examples/test-suite/javascript/li_cpointer_runme.js @@ -0,0 +1,16 @@ +var li_cpointer = require("li_cpointer"); + + +p = li_cpointer.new_intp(); + +if (li_cpointer.intp_value(p) != 0) { + throw new Error("not initialized"); +} + +li_cpointer.intp_assign(p, 3); + +if (li_cpointer.intp_value(p) != 3) { + throw new Error; +} + +li_cpointer.delete_intp(p); diff --git a/Examples/test-suite/javascript/li_factory_runme.js b/Examples/test-suite/javascript/li_factory_runme.js new file mode 100644 index 000000000..c7a963f03 --- /dev/null +++ b/Examples/test-suite/javascript/li_factory_runme.js @@ -0,0 +1,13 @@ +var li_factory = require("li_factory"); + +circle = li_factory.Geometry.create(li_factory.Geometry.CIRCLE); +r = circle.radius(); +if ((r != 1.5)) { + throw new Error; +} + +point = li_factory.Geometry.create(li_factory.Geometry.POINT); +w = point.width(); +if ((w != 1.0)) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/li_std_auto_ptr_runme.js b/Examples/test-suite/javascript/li_std_auto_ptr_runme.js new file mode 100644 index 000000000..b336076c6 --- /dev/null +++ b/Examples/test-suite/javascript/li_std_auto_ptr_runme.js @@ -0,0 +1,130 @@ +var li_std_auto_ptr = require("li_std_auto_ptr"); + +var checkCount = function(expected_count) { + actual_count = li_std_auto_ptr.Klass.getTotal_count(); + if (actual_count != expected_count) + throw new Error("Counts incorrect, expected:" + expected_count + " actual:" + actual_count); +} + +// Test raw pointer handling involving virtual inheritance +{ + kini = new li_std_auto_ptr.KlassInheritance("KlassInheritanceInput"); + checkCount(1); + s = li_std_auto_ptr.useKlassRawPtr(kini); + if (s !== "KlassInheritanceInput") + throw new Error("Incorrect string: " + s); + // delete kini; + // Above not deleting the C++ object(node v12) - can't reliably control GC + li_std_auto_ptr.takeKlassAutoPtr(kini); + checkCount(0); +} + + +// auto_ptr as input +{ + kin = new li_std_auto_ptr.Klass("KlassInput"); + checkCount(1); + s = li_std_auto_ptr.takeKlassAutoPtr(kin); + checkCount(0); + if (s !== "KlassInput") + throw new Error("Incorrect string: " + s); + if (!li_std_auto_ptr.is_nullptr(kin)) + throw new Error("is_nullptr failed"); + delete kin; // Should not fail, even though already deleted + checkCount(0); +} + +{ + kin = new li_std_auto_ptr.Klass("KlassInput"); + checkCount(1); + s = li_std_auto_ptr.takeKlassAutoPtr(kin); + checkCount(0); + if (s !== "KlassInput") + throw new Error("Incorrect string: " + s); + if (!li_std_auto_ptr.is_nullptr(kin)) + throw new Error("is_nullptr failed"); + exception_thrown = false; + try { + li_std_auto_ptr.takeKlassAutoPtr(kin); + } catch (e) { + if (!e.message.includes("cannot release ownership as memory is not owned")) + throw new Error("incorrect exception message " + e.message); + exception_thrown = true; + } + if (!exception_thrown) + throw new Error("double usage of takeKlassAutoPtr should have been an error"); + delete kin; // Should not fail, even though already deleted + checkCount(0); +} + +{ + kin = new li_std_auto_ptr.Klass("KlassInput"); + exception_thrown = false; + notowned = li_std_auto_ptr.get_not_owned_ptr(kin); + try { + li_std_auto_ptr.takeKlassAutoPtr(notowned); + } catch (e) { + if (!e.message.includes("cannot release ownership as memory is not owned")) + throw new Error("incorrect exception message " + e.message); + exception_thrown = true; + } + if (!exception_thrown) + throw new Error("Should have thrown 'Cannot release ownership as memory is not owned' error"); + checkCount(1); + // delete kin; + // Above not deleting the C++ object(node v12) - can't reliably control GC + li_std_auto_ptr.takeKlassAutoPtr(kin); + checkCount(0); +} + +{ + kini = new li_std_auto_ptr.KlassInheritance("KlassInheritanceInput"); + checkCount(1); + s = li_std_auto_ptr.takeKlassAutoPtr(kini); + checkCount(0); + if (s !== "KlassInheritanceInput") + throw new Error("Incorrect string: " + s); + if (!li_std_auto_ptr.is_nullptr(kini)) + throw new Error("is_nullptr failed"); + delete kini; // Should not fail, even though already deleted + checkCount(0); +} + +li_std_auto_ptr.takeKlassAutoPtr(null); +li_std_auto_ptr.takeKlassAutoPtr(li_std_auto_ptr.make_null()); +checkCount(0); + +// overloaded parameters +if (li_std_auto_ptr.overloadTest() != 0) + throw new Error("overloadTest failed"); +if (li_std_auto_ptr.overloadTest(null) != 1) + throw new Error("overloadTest failed"); +if (li_std_auto_ptr.overloadTest(new li_std_auto_ptr.Klass("over")) != 1) + throw new Error("overloadTest failed"); +checkCount(0); + + +// auto_ptr as output +k1 = li_std_auto_ptr.makeKlassAutoPtr("first"); +if (k1.getLabel() !== "first") + throw new Error("wrong object label"); + +k2 = li_std_auto_ptr.makeKlassAutoPtr("second"); +checkCount(2); + +// delete k1; +// Above not deleting the C++ object(node v12) - can't reliably control GC +li_std_auto_ptr.takeKlassAutoPtr(k1); +checkCount(1); + +if (k2.getLabel() !== "second") + throw new Error("wrong object label"); + +// delete k2; +// Above not deleting the C++ object(node v12) - can't reliably control GC +li_std_auto_ptr.takeKlassAutoPtr(k2); + +if (li_std_auto_ptr.makeNullAutoPtr() != null) + throw new Error("null failure"); + +checkCount(0); diff --git a/Examples/test-suite/javascript/li_std_containers_int_runme.js b/Examples/test-suite/javascript/li_std_containers_int_runme.js new file mode 100644 index 000000000..88688e35d --- /dev/null +++ b/Examples/test-suite/javascript/li_std_containers_int_runme.js @@ -0,0 +1,37 @@ +// In JS std::vector and std::list cannot behave as native containers +// because there is no overloading +var li_std_containers_int = require("li_std_containers_int"); + +function set_check(container, idx, value, size) { + container.set(idx, value); + if (container.get(idx) !== value) + throw new Error( + `Failed setting value at ${idx} in ${container.toString} to ${value}, got ${container.getitem(idx)}`); + if (container.size() != size) + throw new Error(`Expected a size of ${size}, got ${container.size()}`); +} + +function err_check(container, idx, value, size) { + let fail = true; + try { + container.set(idx, value); + } catch { + fail = false; + } + if (fail) throw new Error( + `Expected an exception setting value at ${idx} in ${container.toString} to ${value}, got ${container.get(idx)}`); + if (container.size() != size) + throw new Error(`Expected a size of ${size}, got ${container.size()}`); +} + +var vector; + +vector = new li_std_containers_int.vector_int(); +err_check(vector, 0, 10, 0); + +vector = new li_std_containers_int.vector_int(2); +set_check(vector, 0, 10, 2); +set_check(vector, 1, 0, 2); +err_check(vector, 2, 20, 2); +err_check(vector, 0, 'string', 2); +err_check(vector, 0, {}, 2); diff --git a/Examples/test-suite/javascript/li_std_map_member_runme.js b/Examples/test-suite/javascript/li_std_map_member_runme.js new file mode 100644 index 000000000..98e27454c --- /dev/null +++ b/Examples/test-suite/javascript/li_std_map_member_runme.js @@ -0,0 +1,13 @@ +var li_std_map_member = require("li_std_map_member"); + +a = new li_std_map_member.mapita(); +a.set(1, new li_std_map_member.TestA()); + +if ((a.get(1).i != 1)) { + throw new Error("a[1] != 1"); +} + +a.get(1).i = 2; +if ((a.get(1).i != 2)) { + throw new Error("a[1] != 2"); +} diff --git a/Examples/test-suite/javascript/li_std_map_runme.js b/Examples/test-suite/javascript/li_std_map_runme.js new file mode 100644 index 000000000..5f9b0f646 --- /dev/null +++ b/Examples/test-suite/javascript/li_std_map_runme.js @@ -0,0 +1,49 @@ +// In JavaScript, std::map has very limited capabilities and no iterator at all +var li_std_map = require("li_std_map"); + +function set_check(container, idx, value, size) { + container.set(idx, value); + if (container.get(idx) !== value) + throw new Error( + `Failed setting value at ${idx} in ${container.toString} to ${value}, got ${container.getitem(idx)}`); + if (container.size() != size) + throw new Error(`Expected a size of ${size}, got ${container.size()}`); +} + +function err_check(container, idx, value, size) { + let fail = true; + try { + container.set(idx, value); + } catch { + fail = false; + } + if (fail) throw new Error( + `Expected an exception setting value at ${idx} in ${container.toString} to ${value}, got ${container.get(idx)}`); + if (container.size() != size) + throw new Error(`Expected a size of ${size}, got ${container.size()}`); +} + +var map; + +map = new li_std_map.IntIntMap(); +set_check(map, 0, 10, 1); +set_check(map, 1, 0, 2); +set_check(map, 2, 20, 3); +err_check(map, 0, 'string', 3); + +if (!map.has_key(2)) throw new Error('Expected key to be found'); +if (map.has_key(5)) throw new Error('Expected key to not be found'); +map.del(2); +if (map.has_key(2)) throw new Error('Expected key to not be found'); + + +map = new li_std_map.StringIntMap(); +set_check(map, '0', 10, 1); +set_check(map, '1', 0, 2); +set_check(map, '2', 20, 3); +err_check(map, '0', 'string', 3); + +if (!map.has_key('2')) throw new Error('Expected key to be found'); +if (map.has_key('5')) throw new Error('Expected key to not be found'); +map.del('2'); +if (map.has_key('2')) throw new Error('Expected key to not be found'); diff --git a/Examples/test-suite/javascript/li_std_pair_runme.js b/Examples/test-suite/javascript/li_std_pair_runme.js new file mode 100644 index 000000000..97bd97049 --- /dev/null +++ b/Examples/test-suite/javascript/li_std_pair_runme.js @@ -0,0 +1,53 @@ +var li_std_pair = require("li_std_pair"); + +function check(flag) { + if (!flag) { + throw new Error("Check failed"); + } +} + +intPair = li_std_pair.makeIntPair(7, 6); +check(typeof intPair === 'object'); +if (Object.keys(intPair).length) { + // When using raw V8, intPair will be an object with two properties + check(Object.keys(intPair).length == 2); +} else { + // When using NAPI, intPair will be an object of class intPair whose + // prototype will have two properties + check(Object.keys(Object.getPrototypeOf(intPair)).length == 2); +} +check(intPair.first === 7); +check(intPair.second === 6); + +intPairConstRef = li_std_pair.makeIntPairConstRef(7, 6); +check(typeof intPairConstRef === 'object'); +check(intPairConstRef.first === 7); +check(intPairConstRef.second === 6); + +// +// Each of these should return a reference to a wrapped +// std:: pair < int, int > object(i.e.an intPair instance). +intPairPtr = li_std_pair.makeIntPairPtr(7, 6); +check(typeof intPairPtr === 'object'); +check(intPairPtr.first === 7); +check(intPairPtr.second === 6); + +intPairRef = li_std_pair.makeIntPairRef(7, 6); +check(typeof intPairRef === 'object'); +check(intPairRef.first === 7); +check(intPairRef.second === 6); + +// Now test various input typemaps.Each of the wrapped C++ functions +//(product1, product2 and product3) is expecting an argument of a +// different type(see li_std_pair.i).Typemaps should be in place to +// convert this tuple into the expected argument type. +check(li_std_pair.product1(intPair) === 42); +check(li_std_pair.product2(intPair) === 42); +// check(product3(intPair) == 42) # TODO, if (desirable to match Ruby wrappers behaviour.Requires equivalent to typemap(in) std:: pair * in Lib / ruby / std_pair.i and further fixes to stop recursive calls to swig:) {asptr which this testcase shows.Plus further changes for any type of sequence type(including other STL containers) to be accepted by all methods taking an STL container to match Ruby behaviour. + +// +// Similarly, each of the input typemaps should know what to do +// with an intPair instance. +check(li_std_pair.product1(intPairPtr) === 42); +check(li_std_pair.product2(intPairPtr) === 42); +check(li_std_pair.product3(intPairPtr) === 42); diff --git a/Examples/test-suite/javascript/li_std_pair_using_runme.js b/Examples/test-suite/javascript/li_std_pair_using_runme.js new file mode 100644 index 000000000..5e9ac7283 --- /dev/null +++ b/Examples/test-suite/javascript/li_std_pair_using_runme.js @@ -0,0 +1,9 @@ +var li_std_pair_using = require("li_std_pair_using"); + +one = new li_std_pair_using.StringStringPair("one", "numero uno"); +two = new li_std_pair_using.StringIntPair("two", 2); + +tuple = li_std_pair_using.bounce(one); +if (typeof tuple !== 'object' && tuple.first !== one.first || tuple.second !== one.second) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/li_std_vector_enum_runme.js b/Examples/test-suite/javascript/li_std_vector_enum_runme.js new file mode 100644 index 000000000..cc46cd842 --- /dev/null +++ b/Examples/test-suite/javascript/li_std_vector_enum_runme.js @@ -0,0 +1,21 @@ +var li_std_vector_enum = require("li_std_vector_enum"); + + +function check(a, b) { + if ((a != b)) { + throw new Error("Not equal: ", a, b); + } +} + +ev = new li_std_vector_enum.EnumVector(); + +check(ev.nums.get(0), 10); +check(ev.nums.get(1), 20); +check(ev.nums.get(2), 30); + +expected = 10; +for (let i = 0; i < ev.nums.size(); i++) { + let val = ev.nums.get(i); + check(val, expected); + expected += 10; +} diff --git a/Examples/test-suite/javascript/li_std_vector_runme.js b/Examples/test-suite/javascript/li_std_vector_runme.js new file mode 100644 index 000000000..500a4e59b --- /dev/null +++ b/Examples/test-suite/javascript/li_std_vector_runme.js @@ -0,0 +1,14 @@ +var li_std_vector = require("li_std_vector"); + +if (li_std_vector.typedef_test(101) != 101) { + throw new Error; +} + +let fail = false; +try { + sv = new li_std_vector.StructVector(); + sv.add(null); + fail = true; +} catch { } + +if (fail) throw new Error(); diff --git a/Examples/test-suite/javascript/li_typemaps_runme.js b/Examples/test-suite/javascript/li_typemaps_runme.js new file mode 100644 index 000000000..c0b1b43b0 --- /dev/null +++ b/Examples/test-suite/javascript/li_typemaps_runme.js @@ -0,0 +1,50 @@ +var li_typemaps = require("li_typemaps"); + +function check(a, b) { + if (a !== b) { + throw new Error("Not equal: " + a + " " + b) + } +} + +function check_array(a, b) { + if (a.length != b.length) + throw new Error("Array length mismatch " + a.length + " " + b.length) + if (!a.every(function(element, index) { return element === b[index]; })) + throw new Error("Arrays don't match a:" + a + " b:" + b) +} + +// Check double INPUT typemaps +check(li_typemaps.in_double(22.22), 22.22) +check(li_typemaps.inr_double(22.22), 22.22) + +// Check double OUTPUT typemaps +check_array(li_typemaps.out_double(22.22), [22.22]) +check_array(li_typemaps.outr_double(22.22), [22.22]) + +// Check double INOUT typemaps +check_array(li_typemaps.inout_double(22.22), [22.22]) +check_array(li_typemaps.inoutr_double(22.22), [22.22]) + +// check long long +check(li_typemaps.in_ulonglong(20), 20) +check(li_typemaps.inr_ulonglong(20), 20) +check_array(li_typemaps.out_ulonglong(20), [20]) +check_array(li_typemaps.outr_ulonglong(20), [20]) +check_array(li_typemaps.inout_ulonglong(20), [20]) +check_array(li_typemaps.inoutr_ulonglong(20), [20]) + +// check bools +check(li_typemaps.in_bool(true), true) +check(li_typemaps.inr_bool(false), false) +check_array(li_typemaps.out_bool(true), [true]) +check_array(li_typemaps.outr_bool(false), [false]) +check_array(li_typemaps.inout_bool(true), [true]) +check_array(li_typemaps.inoutr_bool(false), [false]) + +// the others +check_array(li_typemaps.inoutr_int2(1,2), [1, 2]) + +fi = li_typemaps.out_foo(10) +check(fi[0].a, 10) +check(fi[1], 20) +check(fi[2], 30) diff --git a/Examples/test-suite/javascript/member_pointer_const_runme.js b/Examples/test-suite/javascript/member_pointer_const_runme.js new file mode 100644 index 000000000..a4f0d0aa1 --- /dev/null +++ b/Examples/test-suite/javascript/member_pointer_const_runme.js @@ -0,0 +1,51 @@ +// Example using pointers to member functions +var member_pointer_const = require("member_pointer_const"); + +function check(what, expected, actual) { + if (expected != actual) { + throw new Error( + "Failed: ", what, " Expected: ", expected, " Actual: ", actual); + } +} + +// Get the pointers + +area_pt = member_pointer_const.areapt(); +perim_pt = member_pointer_const.perimeterpt(); + +// Create some objects + +s = new member_pointer_const.Square(10); + +// Do some calculations + +check("Square area ", 100.0, member_pointer_const.do_op(s, area_pt)); +check("Square perim", 40.0, member_pointer_const.do_op(s, perim_pt)); + +memberPtr = member_pointer_const.areavar; +memberPtr = member_pointer_const.perimetervar; + +// Try the variables +check("Square area ", 100.0, member_pointer_const.do_op(s, member_pointer_const.areavar)); +check("Square perim", 40.0, member_pointer_const.do_op(s, member_pointer_const.perimetervar)); + +// Modify one of the variables +member_pointer_const.areavar = perim_pt; + +check("Square perimeter", 40.0, member_pointer_const.do_op(s, member_pointer_const.areavar)); + +// Try the constants +memberPtr = member_pointer_const.AREAPT; +memberPtr = member_pointer_const.PERIMPT; +memberPtr = member_pointer_const.NULLPT; + +check("Square area ", 100.0, member_pointer_const.do_op(s, member_pointer_const.AREAPT)); +check("Square perim", 40.0, member_pointer_const.do_op(s, member_pointer_const.PERIMPT)); + +// Typedefs +check("Square perim", 40.0, member_pointer_const.do_op_td(s, perim_pt)); + +check("Add by value", 3, member_pointer_const.call1(member_pointer_const.ADD_BY_VALUE, 1, 2)); +// TODO: For some reason, these are commented out in the shared interface file? +//check("Add by pointer", 7, member_pointer_const.call2(member_pointer_const.ADD_BY_POINTER, 3, 4)); +//check("Add by reference", 11, member_pointer_const.call3(member_pointer_const.ADD_BY_REFERENCE, 5, 6)); diff --git a/Examples/test-suite/javascript/member_pointer_runme.js b/Examples/test-suite/javascript/member_pointer_runme.js new file mode 100644 index 000000000..6c11ec6d6 --- /dev/null +++ b/Examples/test-suite/javascript/member_pointer_runme.js @@ -0,0 +1,51 @@ +// Example using pointers to member functions + +var member_pointer = require("member_pointer"); + +function check(what, expected, actual) { + if (expected != actual) { + throw new Error( + "Failed: ", what, " Expected: ", expected, " Actual: ", actual); + } +} + +// Get the pointers + +area_pt = member_pointer.areapt(); +perim_pt = member_pointer.perimeterpt(); + +// Create some objects + +s = new member_pointer.Square(10); + +// Do some calculations + +check("Square area ", 100.0, member_pointer.do_op(s, area_pt)); +check("Square perim", 40.0, member_pointer.do_op(s, perim_pt)); + +memberPtr = member_pointer.areavar; +memberPtr = member_pointer.perimetervar; + +// Try the variables +check("Square area ", 100.0, member_pointer.do_op(s, member_pointer.areavar)); +check("Square perim", 40.0, member_pointer.do_op(s, member_pointer.perimetervar)); + +// Modify one of the variables +member_pointer.areavar = perim_pt; + +check("Square perimeter", 40.0, member_pointer.do_op(s, member_pointer.areavar)); + +// Try the constants +memberPtr = member_pointer.AREAPT; +memberPtr = member_pointer.PERIMPT; +memberPtr = member_pointer.NULLPT; + +check("Square area ", 100.0, member_pointer.do_op(s, member_pointer.AREAPT)); +check("Square perim", 40.0, member_pointer.do_op(s, member_pointer.PERIMPT)); + +// Typedefs +check("Square perim", 40.0, member_pointer.do_op_td(s, perim_pt)); + +check("Add by value", 3, member_pointer.call1(member_pointer.ADD_BY_VALUE, 1, 2)); +check("Add by pointer", 7, member_pointer.call2(member_pointer.ADD_BY_POINTER, 3, 4)); +check("Add by reference", 11, member_pointer.call3(member_pointer.ADD_BY_REFERENCE, 5, 6)); diff --git a/Examples/test-suite/javascript/memberin_extend_c_runme.js b/Examples/test-suite/javascript/memberin_extend_c_runme.js new file mode 100644 index 000000000..d5cf69da9 --- /dev/null +++ b/Examples/test-suite/javascript/memberin_extend_c_runme.js @@ -0,0 +1,7 @@ +var memberin_extend_c = require("memberin_extend_c"); + +t = new memberin_extend_c.Person(); +t.name = "Fred Bloggs"; +if (t.name != "FRED BLOGGS") { + throw new Error("name wrong"); +} diff --git a/Examples/test-suite/javascript/multivalue_runme.js b/Examples/test-suite/javascript/multivalue_runme.js new file mode 100644 index 000000000..c3bad52e7 --- /dev/null +++ b/Examples/test-suite/javascript/multivalue_runme.js @@ -0,0 +1,25 @@ +var multivalue = require("multivalue"); + +var [q, r] = multivalue.divide_l(37, 5); +if (q != 7) { + throw new Error("Test divide_l quotient"); +} +if (r != 2) { + throw new Error("Test divide_l remainder"); +} + +var [q, r] = multivalue.divide_v(41, 7); +if (q != 5) { + throw new Error("Test divide_v quotient"); +} +if (r != 6) { + throw new Error("Test divide_v remainder"); +} + +var [q, r] = multivalue.divide_l(91, 13); +if (q != 7) { + throw new Error("Test divide_mv quotient"); +} +if (r != 0) { + throw new Error("Test divide_mv remainder"); +} diff --git a/Examples/test-suite/javascript/name_warnings_runme.js b/Examples/test-suite/javascript/name_warnings_runme.js new file mode 100644 index 000000000..30605d149 --- /dev/null +++ b/Examples/test-suite/javascript/name_warnings_runme.js @@ -0,0 +1,10 @@ +var name_warnings = require("name_warnings"); + +function check(flag) { + if (!flag) { + throw new Error("Test failed"); + } +} + +four = name_warnings.double_an_int(2); +check(four == 4); diff --git a/Examples/test-suite/javascript/namespace_class_runme.js b/Examples/test-suite/javascript/namespace_class_runme.js new file mode 100644 index 000000000..6aa01053e --- /dev/null +++ b/Examples/test-suite/javascript/namespace_class_runme.js @@ -0,0 +1,45 @@ +var namespace_class = require("namespace_class"); + +try { + p = namespace_class.Private1(); + error = 1; +} catch { + error = 0; +} + +if ((error)) { + throw new Error("Private1 is private"); +} + +try { + p = namespace_class.Private2(); + error = 1; +} catch { + error = 0; +} + +if ((error)) { + throw new Error("Private2 is private"); +} + +namespace_class.EulerT3D.toFrame(1, 1, 1); + +b = new namespace_class.BooT_i(); +b = new namespace_class.BooT_H(); + + +f = new namespace_class.FooT_i(); +f.quack(1); + +f = new namespace_class.FooT_d(); +f.moo(1); + +f = new namespace_class.FooT_H(); +f.foo(namespace_class.Hi); + +// This test works only in Node.js +if (typeof process !== 'undefined') { + if (!f.constructor.name.includes("FooT_H") || !(f instanceof namespace_class.FooT_H)) { + throw new Error("Incorrect type: " + f.toString()); + } +} diff --git a/Examples/test-suite/javascript/namespace_typemap_runme.js b/Examples/test-suite/javascript/namespace_typemap_runme.js new file mode 100644 index 000000000..b51605ac0 --- /dev/null +++ b/Examples/test-suite/javascript/namespace_typemap_runme.js @@ -0,0 +1,49 @@ +var namespace_typemap = require("namespace_typemap"); + +if (namespace_typemap.stest1("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest2("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest3("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest4("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest5("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest6("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest7("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest8("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest9("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest10("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest11("hello") != "hello") { + throw new Error; +} + +if (namespace_typemap.stest12("hello") != "hello") { + throw new Error; +} diff --git a/Examples/test-suite/javascript/naturalvar_runme.js b/Examples/test-suite/javascript/naturalvar_runme.js new file mode 100644 index 000000000..894bd4c31 --- /dev/null +++ b/Examples/test-suite/javascript/naturalvar_runme.js @@ -0,0 +1,13 @@ +var naturalvar = require("naturalvar"); + +f = new naturalvar.Foo(); +b = new naturalvar.Bar(); + +b.f = f; + +naturalvar.s = "hello"; +b.s = "hello"; + +if (b.s != naturalvar.s) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/nested_in_template_runme.js b/Examples/test-suite/javascript/nested_in_template_runme.js new file mode 100644 index 000000000..c3c58e70e --- /dev/null +++ b/Examples/test-suite/javascript/nested_in_template_runme.js @@ -0,0 +1,6 @@ +var nested_in_template = require("nested_in_template"); + +cd = new nested_in_template.ConcreteDerived(88); +if (cd.m_value != 88) { + throw new Error("ConcreteDerived not created correctly"); +} diff --git a/Examples/test-suite/javascript/nested_template_base_runme.js b/Examples/test-suite/javascript/nested_template_base_runme.js new file mode 100644 index 000000000..fcf8416ac --- /dev/null +++ b/Examples/test-suite/javascript/nested_template_base_runme.js @@ -0,0 +1,14 @@ +var nested_template_base = require("nested_template_base"); + +ois = new nested_template_base.InnerS(123); +oic = new nested_template_base.InnerC(); + +// Check base method is available +if ((oic.outer(ois).val != 123)) { + throw new Error("Wrong value calling outer"); +} + +// Check non-derived class using base class +if ((oic.innerc().outer(ois).val != 123)) { + throw new Error("Wrong value calling innerc"); +} diff --git a/Examples/test-suite/javascript/nested_workaround_runme.js b/Examples/test-suite/javascript/nested_workaround_runme.js new file mode 100644 index 000000000..5d02e7c0d --- /dev/null +++ b/Examples/test-suite/javascript/nested_workaround_runme.js @@ -0,0 +1,15 @@ +var nested_workaround = require("nested_workaround"); + +inner = new nested_workaround.Inner(5); +outer = new nested_workaround.Outer(); +newInner = outer.doubleInnerValue(inner); +if (newInner.getValue() != 10) { + throw new Error; +} + +outer = new nested_workaround.Outer(); +inner = outer.createInner(3); +newInner = outer.doubleInnerValue(inner); +if (outer.getInnerValue(newInner) != 6) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/node_template/binding.gyp.in b/Examples/test-suite/javascript/node_template/binding.gyp.in index a82ac2f3e..87e70bb5b 100644 --- a/Examples/test-suite/javascript/node_template/binding.gyp.in +++ b/Examples/test-suite/javascript/node_template/binding.gyp.in @@ -19,7 +19,7 @@ ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', { 'cflags': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cflags], - 'cflags_cc': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cflags], + 'cflags_cc': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cxxflags, $cflags], 'cflags!': [ '-fno-exceptions' ], 'cflags_cc!': [ '-fno-exceptions', '-fno-rtti' ] } diff --git a/Examples/test-suite/javascript/node_template/index.js.in b/Examples/test-suite/javascript/node_template/index.js.in index 72330499d..107545f9f 100644 --- a/Examples/test-suite/javascript/node_template/index.js.in +++ b/Examples/test-suite/javascript/node_template/index.js.in @@ -1 +1 @@ -module.exports = require('./build/Release/$testcase'); +module.exports = require('./build/$build/$testcase'); diff --git a/Examples/test-suite/javascript/not_c_keywords_runme.js b/Examples/test-suite/javascript/not_c_keywords_runme.js new file mode 100644 index 000000000..e74976f01 --- /dev/null +++ b/Examples/test-suite/javascript/not_c_keywords_runme.js @@ -0,0 +1,8 @@ +var not_c_keywords = require("not_c_keywords"); + +cs = new not_c_keywords.ComplexStruct(); +cs.init(); +if (cs.complex != 123) { + throw new Error("complex not correct"); +} +cs.complex = 456; diff --git a/Examples/test-suite/javascript/operator_overload_runme.js b/Examples/test-suite/javascript/operator_overload_runme.js new file mode 100644 index 000000000..1f3f3882a --- /dev/null +++ b/Examples/test-suite/javascript/operator_overload_runme.js @@ -0,0 +1,111 @@ +var operator_overload = require("operator_overload"); +var { Op } = operator_overload; + +// first check all the operators are implemented correctly from pure C++ code +Op.sanity_check(); + +pop = (new Op(6)).Divide(new Op(3)); + +// test routine +a = new Op(); +b = new Op(5); +c = new Op(b); // copy construct +d = new Op(2); +dd = new Op(); +dd.Equal(d); // assignment operator + +// test equality +if (!a.NotEqual(b)) { + throw new Error("a!=b"); +} +if (!b.EqualEqual(c)) { + throw new Error("b==c"); +} +if (!a.NotEqual(d)) { + throw new Error("a!=d"); +} +if (!d.EqualEqual(dd)) { + throw new Error("d==dd"); +} + +// test < +if (!a.LessThan(b)) { + throw new Error("a<b"); +} +if (!a.LessThanEqual(b)) { + throw new Error("a<=b"); +} +if (!b.LessThanEqual(c)) { + throw new Error("b<=c"); +} +if (!b.GreaterThanEqual(c)) { + throw new Error("b>=c"); +} +if (!b.GreaterThan(d)) { + throw new Error("b>d"); +} +if (!b.GreaterThanEqual(d)) { + throw new Error("b>=d"); +} + +// test += +e = new Op(3); +e.PlusEqual(d); +if (!e.EqualEqual(b)) { + throw new Error(`e==b (${e.i}==${b.i})`); +} +e.MinusEqual(c); +if (!e.EqualEqual(a)) { + throw new Error("e==a"); +} +e = new Op(1); +e.MultiplyEqual(b); +if (!e.EqualEqual(c)) { + throw new Error("e==c"); +} +e.DivideEqual(d); +if (!e.EqualEqual(d)) { + throw new Error("e==d"); +} +e.PercentEqual(c); +if (!e.EqualEqual(d)) { + throw new Error("e==d"); +} + +// test + +f = new Op(1); +g = new Op(1); +if (!f.Plus(g).EqualEqual(new Op(2))) { + throw new Error("f+g==Op(2)"); +} +if (!f.Minus(g).EqualEqual(new Op(0))) { + throw new Error("f-g==Op(0)"); +} +if (!f.Multiply(g).EqualEqual(new Op(1))) { + throw new Error("f*g==Op(1)"); +} +if (!f.Divide(g).EqualEqual(new Op(1))) { + throw new Error("f/g==Op(1)"); +} +if (!f.Percent(g).EqualEqual(new Op(0))) { + throw new Error("f%g==Op(0)"); +} + +// test unary operators +if (!a.Minus().EqualEqual(a)) { + throw new Error("-a==a"); +} +if (!b.Minus().EqualEqual(new Op(-5))) { + throw new Error("-b==Op(-5)"); +} + +// test functors +if (!b.Functor() == 5) { + throw new Error("functor"); +} +if (!b.Functor(1) == 6) { + throw new Error("functor"); +} +if (!b.Functor(1, 2) == 8) { + throw new Error("functor"); +} diff --git a/Examples/test-suite/javascript/operbool_runme.js b/Examples/test-suite/javascript/operbool_runme.js new file mode 100644 index 000000000..b1bf89fa8 --- /dev/null +++ b/Examples/test-suite/javascript/operbool_runme.js @@ -0,0 +1,6 @@ +#!/usr/bin/env python +var operbool = require("operbool"); +const b = new operbool.Test(); +if (b.operator_bool()) { + throw new Error("operbool failed"); +} diff --git a/Examples/test-suite/javascript/overload_bool_runme.js b/Examples/test-suite/javascript/overload_bool_runme.js new file mode 100644 index 000000000..2a1a95549 --- /dev/null +++ b/Examples/test-suite/javascript/overload_bool_runme.js @@ -0,0 +1,60 @@ +var overload_bool = require("overload_bool"); + +// Overloading bool, int, string +if (overload_bool.overloaded(true) != "bool") { + throw new Error("wrong!"); +} +if (overload_bool.overloaded(false) != "bool") { + throw new Error("wrong!"); +} + +if (overload_bool.overloaded(0) != "int") { + throw new Error("wrong!"); +} +if (overload_bool.overloaded(1) != "int") { + throw new Error("wrong!"); +} +if (overload_bool.overloaded(2) != "int") { + throw new Error("wrong!"); +} + +if (overload_bool.overloaded("1234") != "string") { + throw new Error("wrong!"); +} + +// Test bool masquerading as int +// Not possible + +// Test int masquerading as bool +// Not possible + + +/////////////////////////////////////////////// + +// Overloading bool, int, string +if (overload_bool.overloaded_ref(true) != "bool") { + throw new Error("wrong!"); +} +if (overload_bool.overloaded_ref(false) != "bool") { + throw new Error("wrong!"); +} + +if (overload_bool.overloaded_ref(0) != "int") { + throw new Error("wrong!"); +} +if (overload_bool.overloaded_ref(1) != "int") { + throw new Error("wrong!"); +} +if (overload_bool.overloaded_ref(2) != "int") { + throw new Error("wrong!"); +} + +if (overload_bool.overloaded_ref("1234") != "string") { + throw new Error("wrong!"); +} + +// Test bool masquerading as int +// Not possible + +// Test int masquerading as bool +// Not possible diff --git a/Examples/test-suite/javascript/overload_complicated_runme.js b/Examples/test-suite/javascript/overload_complicated_runme.js new file mode 100644 index 000000000..19ba3ee6e --- /dev/null +++ b/Examples/test-suite/javascript/overload_complicated_runme.js @@ -0,0 +1,58 @@ +var overload_complicated = require("overload_complicated"); + +pInt = null; + +// Check the correct constructors are available +p = new overload_complicated.Pop(pInt); + +p = new overload_complicated.Pop(pInt, false); + +// Check overloaded in const only and pointers/references which target +// languages cannot disambiguate +if (p.hip(false) != 701) { + throw new Error("Test 1 failed"); +} + +if (p.hip(pInt) != 702) { + throw new Error("Test 2 failed"); +} + +// Reverse the order for the above +if (p.hop(pInt) != 805) { + throw new Error("Test 3 failed"); +} + +if (p.hop(false) != 801) { + throw new Error("Test 4 failed"); +} + +// Few more variations and order shuffled +if (p.pop(false) != 901) { + throw new Error("Test 5 failed"); +} + +if (p.pop(pInt) != 902) { + throw new Error("Test 6 failed"); +} + +if (p.pop() != 905) { + throw new Error("Test 7 failed"); +} + +// Overload on const only +if (p.bop(pInt) != 1001) { + throw new Error("Test 8 failed"); +} + +if (p.bip(pInt) != 2001) { + throw new Error("Test 9 failed"); +} + +// Globals +if (overload_complicated.muzak(false) != 3001) { + throw new Error("Test 10 failed"); +} + +if (overload_complicated.muzak(pInt) != 3002) { + throw new Error("Test 11 failed"); +} diff --git a/Examples/test-suite/javascript/overload_extend2_runme.js b/Examples/test-suite/javascript/overload_extend2_runme.js new file mode 100644 index 000000000..c5463ab3b --- /dev/null +++ b/Examples/test-suite/javascript/overload_extend2_runme.js @@ -0,0 +1,29 @@ +var overload_extend2 = require("overload_extend2"); + +f = new overload_extend2.Foo(); +if (f.test(3) != 1) { + throw new Error; +} +if (f.test("hello") != 2) { + throw new Error; +} +if (f.test(3.5, 2.5) != 3) { + throw new Error; +} +if (f.test("hello", 20) != 1020) { + throw new Error; +} +if (f.test("hello", 20, 100) != 120) { + throw new Error; +} + +// C default args +if (f.test(f) != 30) { + throw new Error; +} +if (f.test(f, 100) != 120) { + throw new Error; +} +if (f.test(f, 100, 200) != 300) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/overload_extend_c_runme.js b/Examples/test-suite/javascript/overload_extend_c_runme.js new file mode 100644 index 000000000..d69a20546 --- /dev/null +++ b/Examples/test-suite/javascript/overload_extend_c_runme.js @@ -0,0 +1,19 @@ +var overload_extend_c = require("overload_extend_c"); + +f = new overload_extend_c.Foo(); +if (f.test() != 0) { + throw new Error; +} +if (f.test(3) != 1) { + throw new Error; +} +if (f.test("hello") != 2) { + throw new Error; +} +if (f.test(3, 2) != 5) { + throw new Error; +} +// In JavaScript there is no difference between 3.0 and 3 +if (f.test(3.0) != 1) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/overload_extend_runme.js b/Examples/test-suite/javascript/overload_extend_runme.js new file mode 100644 index 000000000..cd127db71 --- /dev/null +++ b/Examples/test-suite/javascript/overload_extend_runme.js @@ -0,0 +1,19 @@ +var overload_extend = require("overload_extend") + +f = new overload_extend.Foo() +if (f.test() != 0) { + throw new Error +} +if (f.test(3) != 1) { + throw new Error +} +if (f.test("hello") != 2) { + throw new Error +} +if (f.test(3, 2) != 5) { + throw new Error +} +// In JavaScript there is no difference between 3.0 and 3 +if (f.test(3.0) != 1) { + throw new Error +} diff --git a/Examples/test-suite/javascript/overload_null_runme.js b/Examples/test-suite/javascript/overload_null_runme.js index f1e35cac7..f6c31a436 100644 --- a/Examples/test-suite/javascript/overload_null_runme.js +++ b/Examples/test-suite/javascript/overload_null_runme.js @@ -37,13 +37,13 @@ check(13, o.byval1cpr(x)); // check(15, o.byval2cpr(null)); check(16, o.byval2cpr(x)); -// forward class declaration -check(17, o.byval1forwardptr(x)); -// check(18, o.byval1forwardptr(null)); +// fwd class declaration +check(17, o.byval1fwdptr(x)); +// check(18, o.byval1fwdptr(null)); -// check(19, o.byval2forwardptr(null)); -check(20, o.byval2forwardptr(x)); +// check(19, o.byval2fwdptr(null)); +check(20, o.byval2fwdptr(x)); -check(21, o.byval1forwardref(x)); +check(21, o.byval1fwdref(x)); -check(22, o.byval2forwardref(x)); +check(22, o.byval2fwdref(x)); diff --git a/Examples/test-suite/javascript/overload_simple_runme.js b/Examples/test-suite/javascript/overload_simple_runme.js new file mode 100644 index 000000000..8a56ee205 --- /dev/null +++ b/Examples/test-suite/javascript/overload_simple_runme.js @@ -0,0 +1,105 @@ +var overload_simple = require("overload_simple"); + +if (overload_simple.foo(3) != "foo:int") { + throw new Error("foo(int)"); +} + +if (overload_simple.foo("hello") != "foo:char *") { + throw new Error("foo(char *)"); +} + +f = new overload_simple.Foo(); +b = new overload_simple.Bar(); + +if (overload_simple.foo(f) != "foo:Foo *") { + throw new Error("foo(Foo *)"); +} + +if (overload_simple.foo(b) != "foo:Bar *") { + throw new Error("foo(Bar *)"); +} + +v = overload_simple.malloc_void(32); + +if (overload_simple.foo(v) != "foo:void *") { + throw new Error("foo(void *)"); +} + +s = new overload_simple.Spam(); + +if (s.foo(3) != "foo:int") { + throw new Error("Spam::foo(int)"); +} + +if (s.foo("hello") != "foo:char *") { + throw new Error("Spam::foo(char *)"); +} + +if (s.foo(f) != "foo:Foo *") { + throw new Error("Spam::foo(Foo *)"); +} + +if (s.foo(b) != "foo:Bar *") { + throw new Error("Spam::foo(Bar *)"); +} + +if (s.foo(v) != "foo:void *") { + throw new Error("Spam::foo(void *)"); +} + +if (overload_simple.Spam.bar(3) != "bar:int") { + throw new Error("Spam::bar(int)"); +} + +if (overload_simple.Spam.bar("hello") != "bar:char *") { + throw new Error("Spam::bar(char *)"); +} + +if (overload_simple.Spam.bar(f) != "bar:Foo *") { + throw new Error("Spam::bar(Foo *)"); +} + +if (overload_simple.Spam.bar(b) != "bar:Bar *") { + throw new Error("Spam::bar(Bar *)"); +} + +if (overload_simple.Spam.bar(v) != "bar:void *") { + throw new Error("Spam::bar(void *)"); +} + +// Test constructors + +s = new overload_simple.Spam(); +if (s.type != "none") { + throw new Error("Spam()"); +} + +s = new overload_simple.Spam(3); +if (s.type != "int") { + throw new Error("Spam(int)"); +} + +s = new overload_simple.Spam("hello"); +if (s.type != "char *") { + throw new Error("Spam(char *)"); +} + +s = new overload_simple.Spam(f); +if (s.type != "Foo *") { + throw new Error("Spam(Foo *)"); +} + +s = new overload_simple.Spam(b); +if (s.type != "Bar *") { + throw new Error("Spam(Bar *)"); +} + +s = new overload_simple.Spam(v); +if (s.type != "void *") { + throw new Error("Spam(void *)"); +} + +overload_simple.free_void(v); + +a = new overload_simple.ClassA(); +b = a.method1(1); diff --git a/Examples/test-suite/javascript/overload_template_fast_runme.js b/Examples/test-suite/javascript/overload_template_fast_runme.js new file mode 100644 index 000000000..759c7c9b0 --- /dev/null +++ b/Examples/test-suite/javascript/overload_template_fast_runme.js @@ -0,0 +1,136 @@ +var overload_template_fast = require("overload_template_fast"); + +f = overload_template_fast.foo(); + +a = overload_template_fast.maximum(3, 4); +b = overload_template_fast.maximum(3.4, 5.2); + +// overload_template_fast.mix 1 +if (overload_template_fast.mix1("hi") != 101) { + throw new Error("mix1(const char*)"); +} + +if (overload_template_fast.mix1(1.0, 1.0) != 102) { + throw new Error("mix1(double, const double &)"); +} + +if (overload_template_fast.mix1(1.0) != 103) { + throw new Error("mix1(double)"); +} +// overload_template_fast.mix 2 +if (overload_template_fast.mix2("hi") != 101) { + throw new Error("mix2(const char*)"); +} +if (overload_template_fast.mix2(1.0, 1.0) != 102) { + throw new Error("mix2(double, const double &)"); +} +if (overload_template_fast.mix2(1.0) != 103) { + throw new Error("mix2(double)"); +} +// overload_template_fast.mix 3 +if (overload_template_fast.mix3("hi") != 101) { + throw new Error("mix3(const char*)"); +} +if (overload_template_fast.mix3(1.0, 1.0) != 102) { + throw new Error("mix3(double, const double &)"); +} +if (overload_template_fast.mix3(1.0) != 103) { + throw new Error("mix3(double)"); +} +// Combination 1 +if (overload_template_fast.overtparams1(100) != 10) { + throw new Error("overtparams1(int)"); +} +if (overload_template_fast.overtparams1(100.0, 100) != 20) { + throw new Error("overtparams1(double, int)"); +} +// Combination 2 +if (overload_template_fast.overtparams2(100.0, 100) != 40) { + throw new Error("overtparams2(double, int)"); +} +// Combination 3 +if (overload_template_fast.overloaded() != 60) { + throw new Error("overloaded()"); +} +if (overload_template_fast.overloaded(100.0, 100) != 70) { + throw new Error("overloaded(double, int)"); +} +// Combination 4 +if (overload_template_fast.overloadedagain("hello") != 80) { + throw new Error("overloadedagain(const char *)"); +} +if (overload_template_fast.overloadedagain() != 90) { + throw new Error("overloadedagain(double)"); +} +// specializations +if (overload_template_fast.specialization(10) != 202) { + throw new Error("specialization(int)"); +} +if (overload_template_fast.specialization(10, 10) != 204) { + throw new Error("specialization(int, int)"); +} +if (overload_template_fast.specialization("hi", "hi") != 201) { + throw new Error("specialization(const char *, const char *)"); +} + +// simple specialization +overload_template_fast.xyz(); +overload_template_fast.xyz_int(); +overload_template_fast.xyz_double(); + +// a bit of everything +if (overload_template_fast.overload("hi") != 0) { + throw new Error("overload()"); +} +if (overload_template_fast.overload(1) != 10) { + throw new Error("overload(int t)"); +} +if (overload_template_fast.overload(1, 1) != 20) { + throw new Error("overload(int t, const int &)"); +} +if (overload_template_fast.overload(1, "hello") != 30) { + throw new Error("overload(int t, const char *)"); +} +k = new overload_template_fast.Klass(); +if (overload_template_fast.overload(k) != 10) { + throw new Error("overload(Klass t)"); +} +if (overload_template_fast.overload(k, k) != 20) { + throw new Error("overload(Klass t, const Klass &)"); +} +if (overload_template_fast.overload(k, "hello") != 30) { + throw new Error("overload(Klass t, const char *)"); +} +if (overload_template_fast.overload() != 50) { + throw new Error("overload(const char *)"); +} + +// everything put in a namespace +if (overload_template_fast.nsoverload("hi") != 1000) { + throw new Error("nsoverload()"); +} +if (overload_template_fast.nsoverload(1) != 1010) { + throw new Error("nsoverload(int t)"); +} +if (overload_template_fast.nsoverload(1, 1) != 1020) { + throw new Error("nsoverload(int t, const int &)"); +} +if (overload_template_fast.nsoverload(1, "hello") != 1030) { + throw new Error("nsoverload(int t, const char *)"); +} +if (overload_template_fast.nsoverload(k) != 1010) { + throw new Error("nsoverload(Klass t)"); +} +if (overload_template_fast.nsoverload(k, k) != 1020) { + throw new Error("nsoverload(Klass t, const Klass &)"); +} +if (overload_template_fast.nsoverload(k, "hello") != 1030) { + throw new Error("nsoverload(Klass t, const char *)"); +} +if (overload_template_fast.nsoverload() != 1050) { + throw new Error("nsoverload(const char *)"); +} + +overload_template_fast.A.foo(1); +b = new overload_template_fast.B(); +b.foo(1); diff --git a/Examples/test-suite/javascript/overload_template_runme.js b/Examples/test-suite/javascript/overload_template_runme.js new file mode 100644 index 000000000..ef4e23826 --- /dev/null +++ b/Examples/test-suite/javascript/overload_template_runme.js @@ -0,0 +1,133 @@ +var overload_template = require("overload_template"); +f = overload_template.foo(); + +a = overload_template.maximum(3, 4); +b = overload_template.maximum(3.4, 5.2); + +// mix 1 +if (overload_template.mix1("hi") != 101) { + throw new Error("mix1(const char*)"); +} +if (overload_template.mix1(1.0, 1.0) != 102) { + throw new Error("mix1(double, const double &)"); +} +if (overload_template.mix1(1.0) != 103) { + throw new Error("mix1(double)"); +} +// mix 2 +if (overload_template.mix2("hi") != 101) { + throw new Error("mix2(const char*)"); +} +if (overload_template.mix2(1.0, 1.0) != 102) { + throw new Error("mix2(double, const double &)"); +} +if (overload_template.mix2(1.0) != 103) { + throw new Error("mix2(double)"); +} +// mix 3 +if (overload_template.mix3("hi") != 101) { + throw new Error("mix3(const char*)"); +} +if (overload_template.mix3(1.0, 1.0) != 102) { + throw new Error("mix3(double, const double &)"); +} +if (overload_template.mix3(1.0) != 103) { + throw new Error("mix3(double)"); +} +// Combination 1 +if (overload_template.overtparams1(100) != 10) { + throw new Error("overtparams1(int)"); +} +if (overload_template.overtparams1(100.0, 100) != 20) { + throw new Error("overtparams1(double, int)"); +} +// Combination 2 +if (overload_template.overtparams2(100.0, 100) != 40) { + throw new Error("overtparams2(double, int)"); +} +// Combination 3 +if (overload_template.overloaded() != 60) { + throw new Error("overloaded()"); +} +if (overload_template.overloaded(100.0, 100) != 70) { + throw new Error("overloaded(double, int)"); +} +// Combination 4 +if (overload_template.overloadedagain("hello") != 80) { + throw new Error("overloadedagain(const char *)"); +} +if (overload_template.overloadedagain() != 90) { + throw new Error("overloadedagain(double)"); +} +// specializations +if (overload_template.specialization(10) != 202) { + throw new Error("specialization(int)"); +} +if (overload_template.specialization(10, 10) != 204) { + throw new Error("specialization(int, int)"); +} +if (overload_template.specialization("hi", "hi") != 201) { + throw new Error("specialization(const char *, const char *)"); +} + +// simple specialization +overload_template.xyz(); +overload_template.xyz_int(); +overload_template.xyz_double(); + +// a bit of everything +if (overload_template.overload("hi") != 0) { + throw new Error("overload()"); +} +if (overload_template.overload(1) != 10) { + throw new Error("overload(int t)"); +} +if (overload_template.overload(1, 1) != 20) { + throw new Error("overload(int t, const int &)"); +} +if (overload_template.overload(1, "hello") != 30) { + throw new Error("overload(int t, const char *)"); +} +k = new overload_template.Klass(); +if (overload_template.overload(k) != 10) { + throw new Error("overload(Klass t)"); +} +if (overload_template.overload(k, k) != 20) { + throw new Error("overload(Klass t, const Klass &)"); +} +if (overload_template.overload(k, "hello") != 30) { + throw new Error("overload(Klass t, const char *)"); +} +if (overload_template.overload() != 50) { + throw new Error("overload(const char *)"); +} + +// everything put in a namespace +if (overload_template.nsoverload("hi") != 1000) { + throw new Error("nsoverload()"); +} +if (overload_template.nsoverload(1) != 1010) { + throw new Error("nsoverload(int t)"); +} +if (overload_template.nsoverload(1, 1) != 1020) { + throw new Error("nsoverload(int t, const int &)"); +} +if (overload_template.nsoverload(1, "hello") != 1030) { + throw new Error("nsoverload(int t, const char *)"); +} +if (overload_template.nsoverload(k) != 1010) { + throw new Error("nsoverload(Klass t)"); +} +if (overload_template.nsoverload(k, k) != 1020) { + throw new Error("nsoverload(Klass t, const Klass &)"); +} +if (overload_template.nsoverload(k, "hello") != 1030) { + throw new Error("nsoverload(Klass t, const char *)"); +} +if (overload_template.nsoverload() != 1050) { + throw new Error("nsoverload(const char *)"); +} + +overload_template.A.foo(1); +b = new overload_template.B(); +b.foo(1); diff --git a/Examples/test-suite/javascript/pointer_reference_runme.js b/Examples/test-suite/javascript/pointer_reference_runme.js new file mode 100644 index 000000000..d63b2fd3b --- /dev/null +++ b/Examples/test-suite/javascript/pointer_reference_runme.js @@ -0,0 +1,20 @@ +var pointer_reference = require("pointer_reference"); + +s = pointer_reference.get(); +if (s.value != 10) { + throw new Error("get test failed"); +} + +ss = new pointer_reference.Struct(20); +pointer_reference.set(ss); +if (pointer_reference.Struct.instance.value != 20) { + throw new Error("set test failed"); +} + +if (pointer_reference.overloading(1) != 111) { + throw new Error("overload test 1 failed"); +} + +if (pointer_reference.overloading(ss) != 222) { + throw new Error("overload test 2 failed"); +} diff --git a/Examples/test-suite/javascript/preproc_cpp_runme.js b/Examples/test-suite/javascript/preproc_cpp_runme.js new file mode 100644 index 000000000..e426bfb3e --- /dev/null +++ b/Examples/test-suite/javascript/preproc_cpp_runme.js @@ -0,0 +1,4 @@ +var preproc_cpp = require("preproc_cpp"); + +t1 = new preproc_cpp.tcxMessageTest(); +t2 = new preproc_cpp.tcxMessageBug(); diff --git a/Examples/test-suite/javascript/preproc_defined_runme.js b/Examples/test-suite/javascript/preproc_defined_runme.js new file mode 100644 index 000000000..433de6446 --- /dev/null +++ b/Examples/test-suite/javascript/preproc_defined_runme.js @@ -0,0 +1,24 @@ +var preproc_defined = require("preproc_defined"); + +if (preproc_defined.call_checking() != 1) { + throw new Error; +} + +d = new preproc_defined.Defined(); +d.defined = 10; + +preproc_defined.thing(10); +preproc_defined.stuff(10); +preproc_defined.bumpf(10); + +if (preproc_defined.a != 2) { + throw new Error; +} + +if (preproc_defined.b != 42) { + throw new Error; +} + +if (preproc_defined.z != 8) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/preproc_gcc_output_runme.js b/Examples/test-suite/javascript/preproc_gcc_output_runme.js new file mode 100644 index 000000000..8bc4dcb2b --- /dev/null +++ b/Examples/test-suite/javascript/preproc_gcc_output_runme.js @@ -0,0 +1,5 @@ +var preproc_gcc_output = require("preproc_gcc_output"); + +preproc_gcc_output.header1_function_a(99); +preproc_gcc_output.header1_function_b(99); +preproc_gcc_output.header2_function(99); diff --git a/Examples/test-suite/javascript/primitive_ref_runme.js b/Examples/test-suite/javascript/primitive_ref_runme.js new file mode 100644 index 000000000..23556e5ee --- /dev/null +++ b/Examples/test-suite/javascript/primitive_ref_runme.js @@ -0,0 +1,53 @@ +var primitive_ref = require("primitive_ref"); + +if (primitive_ref.ref_int(3) != 3) { + throw new Error +} + +if (primitive_ref.ref_uint(3) != 3) { + throw new Error +} + +if (primitive_ref.ref_short(3) != 3) { + throw new Error +} + +if (primitive_ref.ref_ushort(3) != 3) { + throw new Error +} + +if (primitive_ref.ref_long(3) != 3) { + throw new Error +} + +if (primitive_ref.ref_ulong(3) != 3) { + throw new Error +} + +if (primitive_ref.ref_schar(3) != 3) { + throw new Error +} + +if (primitive_ref.ref_uchar(3) != 3) { + throw new Error +} + +if (primitive_ref.ref_float(3.5) != 3.5) { + throw new Error +} + +if (primitive_ref.ref_double(3.5) != 3.5) { + throw new Error +} + +if (primitive_ref.ref_bool(true) != true) { + throw new Error +} + +if (primitive_ref.ref_char("x") != "x") { + throw new Error +} + +if (primitive_ref.ref_over(0) != 0) { + throw new Error +} diff --git a/Examples/test-suite/javascript/profiletest_runme.js b/Examples/test-suite/javascript/profiletest_runme.js new file mode 100644 index 000000000..241f17287 --- /dev/null +++ b/Examples/test-suite/javascript/profiletest_runme.js @@ -0,0 +1,30 @@ +var profiletest = require("profiletest"); + +a = new profiletest.A(); + +b = new profiletest.B(); +// Directly calling fn is not possible in JavaScript where +// member methods require passing a this object (like C/C++) +fn = b.fn; +for (let i = 50000; i >= 0; i--) { + a = fn.call(b, a); // 1 + a = fn.call(b, a); // 2 + a = fn.call(b, a); // 3 + a = fn.call(b, a); // 4 + a = fn.call(b, a); // 5 + a = fn.call(b, a); // 6 + a = fn.call(b, a); // 7 + a = fn.call(b, a); // 8 + a = fn.call(b, a); // 9 + a = fn.call(b, a); // 10 + a = fn.call(b, a); // 1 + a = fn.call(b, a); // 2 + a = fn.call(b, a); // 3 + a = fn.call(b, a); // 4 + a = fn.call(b, a); // 5 + a = fn.call(b, a); // 6 + a = fn.call(b, a); // 7 + a = fn.call(b, a); // 8 + a = fn.call(b, a); // 9 + a = fn.call(b, a); // 20 +} diff --git a/Examples/test-suite/javascript/reference_global_vars_runme.js b/Examples/test-suite/javascript/reference_global_vars_runme.js new file mode 100644 index 000000000..295e0f3a2 --- /dev/null +++ b/Examples/test-suite/javascript/reference_global_vars_runme.js @@ -0,0 +1,90 @@ +var reference_global_vars = require("reference_global_vars"); + +// const class reference variable +if (reference_global_vars.getconstTC().num != 33) { + throw new Error; +} + +// primitive reference variables +reference_global_vars.var_bool = reference_global_vars.createref_bool(false); +if (reference_global_vars.value_bool(reference_global_vars.var_bool) != false) { + throw new Error; +} + +reference_global_vars.var_bool = reference_global_vars.createref_bool(true); +if (reference_global_vars.value_bool(reference_global_vars.var_bool) != true) { + throw new Error; +} + +reference_global_vars.var_char = reference_global_vars.createref_char("w"); +if (reference_global_vars.value_char(reference_global_vars.var_char) != "w") { + throw new Error; +} + +reference_global_vars.var_unsigned_char = reference_global_vars.createref_unsigned_char(10); +if (reference_global_vars.value_unsigned_char(reference_global_vars.var_unsigned_char) != 10) { + throw new Error; +} + +reference_global_vars.var_signed_char = reference_global_vars.createref_signed_char(10); +if (reference_global_vars.value_signed_char(reference_global_vars.var_signed_char) != 10) { + throw new Error; +} + +reference_global_vars.var_short = reference_global_vars.createref_short(10); +if (reference_global_vars.value_short(reference_global_vars.var_short) != 10) { + throw new Error; +} + +reference_global_vars.var_unsigned_short = reference_global_vars.createref_unsigned_short(10); +if (reference_global_vars.value_unsigned_short(reference_global_vars.var_unsigned_short) != 10) { + throw new Error; +} + +reference_global_vars.var_int = reference_global_vars.createref_int(10); +if (reference_global_vars.value_int(reference_global_vars.var_int) != 10) { + throw new Error; +} + +reference_global_vars.var_unsigned_int = reference_global_vars.createref_unsigned_int(10); +if (reference_global_vars.value_unsigned_int(reference_global_vars.var_unsigned_int) != 10) { + throw new Error; +} + +reference_global_vars.var_long = reference_global_vars.createref_long(10); +if (reference_global_vars.value_long(reference_global_vars.var_long) != 10) { + throw new Error; +} + +reference_global_vars.var_unsigned_long = reference_global_vars.createref_unsigned_long(10); +if (reference_global_vars.value_unsigned_long(reference_global_vars.var_unsigned_long) != 10) { + throw new Error; +} + +reference_global_vars.var_long_long = reference_global_vars.createref_long_long(0x6FFFFFFFFFFFFFF8); +if (reference_global_vars.value_long_long(reference_global_vars.var_long_long) != 0x6FFFFFFFFFFFFFF8) { + throw new Error; +} + +//ull = abs(0xFFFFFFF2FFFFFFF0) +ull = 55834574864; +reference_global_vars.var_unsigned_long_long = reference_global_vars.createref_unsigned_long_long(ull); +if (reference_global_vars.value_unsigned_long_long(reference_global_vars.var_unsigned_long_long) != ull) { + throw new Error; +} + +reference_global_vars.var_float = reference_global_vars.createref_float(10.5); +if (reference_global_vars.value_float(reference_global_vars.var_float) != 10.5) { + throw new Error; +} + +reference_global_vars.var_double = reference_global_vars.createref_double(10.5); +if (reference_global_vars.value_double(reference_global_vars.var_double) != 10.5) { + throw new Error; +} + +// class reference variable +reference_global_vars.var_TestClass = reference_global_vars.createref_TestClass(new reference_global_vars.TestClass(20)); +if (reference_global_vars.value_TestClass(reference_global_vars.var_TestClass).num != 20) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/rename_pcre_encoder_runme.js b/Examples/test-suite/javascript/rename_pcre_encoder_runme.js new file mode 100644 index 000000000..b0e3a2891 --- /dev/null +++ b/Examples/test-suite/javascript/rename_pcre_encoder_runme.js @@ -0,0 +1,18 @@ +var rename_pcre_encoder = require("rename_pcre_encoder"); + +s = new rename_pcre_encoder.SomeWidget(); +s.put_borderWidth(3); +if (s.get_borderWidth() != 3) { + throw new Error(`Border should be 3, not ${s.get_borderWidth()}`); +} + +s.put_size(4, 5); +a = new rename_pcre_encoder.AnotherWidget(); +a.DoSomething(); + +evt = new rename_pcre_encoder.wxEVTSomeEvent(); +t = new rename_pcre_encoder.xUnchangedName(); + +if (rename_pcre_encoder.StartINSAneAndUNSAvoryTraNSAtlanticRaNSAck() != 42) { + throw new Error("Unexpected result of renamed function call"); +} diff --git a/Examples/test-suite/javascript/rename_predicates_runme.js b/Examples/test-suite/javascript/rename_predicates_runme.js new file mode 100644 index 000000000..d8c69ccf6 --- /dev/null +++ b/Examples/test-suite/javascript/rename_predicates_runme.js @@ -0,0 +1,48 @@ +var rename_predicates = require("rename_predicates"); + +r = new rename_predicates.RenamePredicates(123); +r.MF_member_function(); +rename_predicates.RenamePredicates.MF_static_member_function(); +r.MF_extend_function_before(); +r.MF_extend_function_after(); +rename_predicates.GF_global_function(); + +if (r.MV_member_variable != 123) { + throw new Error("variable wrong"); +} +r.MV_member_variable = 1234; +if (r.MV_member_variable != 1234) { + throw new Error("variable wrong"); +} + +if (rename_predicates.RenamePredicates.MV_static_member_variable != 456) { + throw new Error("variable wrong"); +} +rename_predicates.RenamePredicates_MV_static_member_variable = 4567; +if (rename_predicates.RenamePredicates_MV_static_member_variable != 4567) { + throw new Error("variable wrong"); +} + +if (rename_predicates.GV_global_variable != 789) { + throw new Error("variable wrong"); +} +rename_predicates.GV_global_variable = 7890; +if (rename_predicates.GV_global_variable != 7890) { + throw new Error("variable wrong"); +} + +rename_predicates.UC_UPPERCASE(); +rename_predicates.LC_lowercase(); +rename_predicates.TI_Title(); +rename_predicates.FU_FirstUpperCase(); +rename_predicates.FL_firstLowerCase(); +rename_predicates.CA_CamelCase(); +rename_predicates.LC_lowerCamelCase(); +rename_predicates.UC_under_case_it(); + +ex = new rename_predicates.ExtendCheck(); +ex.MF_real_member1(); +ex.MF_real_member2(); +ex.EX_EXTENDMETHOD1(); +ex.EX_EXTENDMETHOD2(); +ex.EX_EXTENDMETHOD3(); diff --git a/Examples/test-suite/javascript/rename_rstrip_encoder_runme.js b/Examples/test-suite/javascript/rename_rstrip_encoder_runme.js new file mode 100644 index 000000000..129749ccc --- /dev/null +++ b/Examples/test-suite/javascript/rename_rstrip_encoder_runme.js @@ -0,0 +1,5 @@ +var rename_rstrip_encoder = require("rename_rstrip_encoder"); + +s = new rename_rstrip_encoder.SomeThing(); +a = new rename_rstrip_encoder.AnotherThing(); +a.DoClsX(); diff --git a/Examples/test-suite/javascript/rename_strip_encoder_runme.js b/Examples/test-suite/javascript/rename_strip_encoder_runme.js new file mode 100644 index 000000000..67a6a9383 --- /dev/null +++ b/Examples/test-suite/javascript/rename_strip_encoder_runme.js @@ -0,0 +1,5 @@ +var rename_strip_encoder = require("rename_strip_encoder"); + +s = new rename_strip_encoder.SomeWidget(); +a = new rename_strip_encoder.AnotherWidget(); +a.DoSomething(); diff --git a/Examples/test-suite/javascript/return_const_value_runme.js b/Examples/test-suite/javascript/return_const_value_runme.js new file mode 100644 index 000000000..ef0ba28dd --- /dev/null +++ b/Examples/test-suite/javascript/return_const_value_runme.js @@ -0,0 +1,11 @@ +var return_const_value = require("return_const_value"); + +p = return_const_value.Foo_ptr.getPtr(); +if ((p.getVal() != 17)) { + throw new Error(`Runtime test1 failed. p.getVal()=${p.getVal()}`); +} + +p = return_const_value.Foo_ptr.getConstPtr(); +if ((p.getVal() != 17)) { + throw new Error(`Runtime test2 failed. p.getVal()=${p.getVal()}`); +} diff --git a/Examples/test-suite/javascript/smart_pointer_member_runme.js b/Examples/test-suite/javascript/smart_pointer_member_runme.js new file mode 100644 index 000000000..9cf4893a9 --- /dev/null +++ b/Examples/test-suite/javascript/smart_pointer_member_runme.js @@ -0,0 +1,24 @@ +var smart_pointer_member = require("smart_pointer_member"); + + +f = new smart_pointer_member.Foo(); +f.y = 1; + +if (f.y != 1) { + throw new Error; +} + +b = new smart_pointer_member.Bar(f); +b.y = 2; + +if (f.y != 2) { + throw new Error(`Failed ${f.y} ${f.x}`); +} + +if (b.ZZ != f.ZZ) { + throw new Error(`Failed ${b.x} ${f.x}`); +} + +if (b.z != f.z) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/smart_pointer_multi_runme.js b/Examples/test-suite/javascript/smart_pointer_multi_runme.js new file mode 100644 index 000000000..089bcc8ff --- /dev/null +++ b/Examples/test-suite/javascript/smart_pointer_multi_runme.js @@ -0,0 +1,16 @@ +var smart_pointer_multi = require("smart_pointer_multi"); + +f = new smart_pointer_multi.Foo(); +b = new smart_pointer_multi.Bar(f); +s = new smart_pointer_multi.Spam(b); +g = new smart_pointer_multi.Grok(b); + +s.x = 3; +if (s.getx() != 3) { + throw new Error; +} + +g.x = 4; +if (g.getx() != 4) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/smart_pointer_multi_typedef_runme.js b/Examples/test-suite/javascript/smart_pointer_multi_typedef_runme.js new file mode 100644 index 000000000..aaf5baf77 --- /dev/null +++ b/Examples/test-suite/javascript/smart_pointer_multi_typedef_runme.js @@ -0,0 +1,16 @@ +var smart_pointer_multi_typedef = require("smart_pointer_multi_typedef"); + +f = new smart_pointer_multi_typedef.Foo(); +b = new smart_pointer_multi_typedef.Bar(f); +s = new smart_pointer_multi_typedef.Spam(b); +g = new smart_pointer_multi_typedef.Grok(b); + +s.x = 3; +if (s.getx() != 3) { + throw new Error; +} + +g.x = 4; +if (g.getx() != 4) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/smart_pointer_not_runme.js b/Examples/test-suite/javascript/smart_pointer_not_runme.js new file mode 100644 index 000000000..2c3a65ec1 --- /dev/null +++ b/Examples/test-suite/javascript/smart_pointer_not_runme.js @@ -0,0 +1,30 @@ +var smart_pointer_not = require("smart_pointer_not"); + +f = new smart_pointer_not.Foo(); +b = new smart_pointer_not.Bar(f); +s = new smart_pointer_not.Spam(f); +g = new smart_pointer_not.Grok(f); + +// This is the only that should work +f.getx(); + +// Accessing an inexistent property in JS +// does not throw - it returns undefined +fail = false; +try { + x = b.getx(); + fail = new Error("Error! b.x"); +} catch { } +if (fail) throw fail; + +try { + x = s.getx(); + fail = new Error("Error! b.x"); +} catch { } +if (fail) throw fail; + +try { + x = g.getx(); + fail = new Error("Error! b.x"); +} catch { } +if (fail) throw fail; diff --git a/Examples/test-suite/javascript/smart_pointer_rename_runme.js b/Examples/test-suite/javascript/smart_pointer_rename_runme.js new file mode 100644 index 000000000..f497c5114 --- /dev/null +++ b/Examples/test-suite/javascript/smart_pointer_rename_runme.js @@ -0,0 +1,16 @@ +var smart_pointer_rename = require("smart_pointer_rename"); + +f = new smart_pointer_rename.Foo(); +b = new smart_pointer_rename.Bar(f); + +if (b.test() != 3) { + throw new Error; +} + +if (b.ftest1(1) != 1) { + throw new Error; +} + +if (b.ftest2(2, 3) != 2) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/smart_pointer_simple_runme.js b/Examples/test-suite/javascript/smart_pointer_simple_runme.js new file mode 100644 index 000000000..e00dcefb7 --- /dev/null +++ b/Examples/test-suite/javascript/smart_pointer_simple_runme.js @@ -0,0 +1,15 @@ +var smart_pointer_simple = require("smart_pointer_simple"); + +f = new smart_pointer_simple.Foo(); +b = new smart_pointer_simple.Bar(f); + +b.x = 3; +if (b.getx() != 3) { + throw new Error; +} + +fp = b.__deref__(); +fp.x = 4; +if (fp.getx() != 4) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/smart_pointer_templatevariables_runme.js b/Examples/test-suite/javascript/smart_pointer_templatevariables_runme.js new file mode 100644 index 000000000..ddb5f8bd0 --- /dev/null +++ b/Examples/test-suite/javascript/smart_pointer_templatevariables_runme.js @@ -0,0 +1,22 @@ +var smart_pointer_templatevariables = require("smart_pointer_templatevariables"); + +d = new smart_pointer_templatevariables.DiffImContainerPtr_D(smart_pointer_templatevariables.create(1234, 5678)); + +// TODO xyz has been commented out in the shared test file, find out why + +if ((d.id != 1234)) { + throw new Error; +} +//if ((d.xyz != 5678)) { +// throw new Error; +//} + +d.id = 4321; +//d.xyz = 8765; + +if ((d.id != 4321)) { + throw new Error; +} +//if ((d.xyz != 8765)) { +// throw new Error; +//} diff --git a/Examples/test-suite/javascript/smart_pointer_typedef_runme.js b/Examples/test-suite/javascript/smart_pointer_typedef_runme.js new file mode 100644 index 000000000..9641a12f9 --- /dev/null +++ b/Examples/test-suite/javascript/smart_pointer_typedef_runme.js @@ -0,0 +1,15 @@ +var smart_pointer_typedef = require("smart_pointer_typedef"); + +f = new smart_pointer_typedef.Foo(); +b = new smart_pointer_typedef.Bar(f); + +b.x = 3; +if (b.getx() != 3) { + throw new Error; +} + +fp = b.__deref__(); +fp.x = 4; +if (fp.getx() != 4) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/sneaky1_runme.js b/Examples/test-suite/javascript/sneaky1_runme.js new file mode 100644 index 000000000..bb887ff22 --- /dev/null +++ b/Examples/test-suite/javascript/sneaky1_runme.js @@ -0,0 +1,5 @@ +var sneaky1 = require("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/javascript/special_variable_macros_runme.js b/Examples/test-suite/javascript/special_variable_macros_runme.js new file mode 100644 index 000000000..264a1a9f1 --- /dev/null +++ b/Examples/test-suite/javascript/special_variable_macros_runme.js @@ -0,0 +1,37 @@ +var special_variable_macros = require("special_variable_macros"); + +var cvar = special_variable_macros; +var name = new special_variable_macros.Name(); +if (special_variable_macros.testFred(name) != "none") { + throw new Error("test failed"); +} +if (cvar.accessed_examplekw != 0) { + throw new Error("Precondition failed"); +} +if (special_variable_macros.testJack(name) != "$specialname") { + throw new Error("test failed"); +} +if (cvar.accessed_examplekw != 1) { + throw new Error("Postcondition failed"); +} +if (special_variable_macros.testJill(name) != "jilly") { + throw new Error("test failed"); +} +if (special_variable_macros.testMary(name) != "SWIGTYPE_p_NameWrap") { + throw new Error("test failed"); +} +if (special_variable_macros.testJames(name) != "SWIGTYPE_Name") { + throw new Error("test failed"); +} +if (special_variable_macros.testJim(name) != "multiname num") { + throw new Error("test failed"); +} +if (special_variable_macros.testJohn(new special_variable_macros.PairIntBool(10, false)) != 123) { + throw new Error("test failed"); +} +if (special_variable_macros.makeStringInt("stringint", 999) != "stringint") { + throw new Error("test failed"); +} +if (special_variable_macros.provideStringInt(999) != "1000") { + throw new Error("test failed"); +} diff --git a/Examples/test-suite/javascript/static_const_member_2_runme.js b/Examples/test-suite/javascript/static_const_member_2_runme.js new file mode 100644 index 000000000..be54c781b --- /dev/null +++ b/Examples/test-suite/javascript/static_const_member_2_runme.js @@ -0,0 +1,13 @@ +var static_const_member_2 = require("static_const_member_2"); + +c = new static_const_member_2.Test_int(); +a = c.forward_field; +a = c.current_profile; +a = c.RightIndex; +a = static_const_member_2.Test_int.backward_field; +a = static_const_member_2.Test_int.LeftIndex; +a = static_const_member_2.Test_int.cavity_flags; + +if (static_const_member_2.Foo.BAZ.val != 2 * static_const_member_2.Foo.BAR.val) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/struct_initialization_runme.js b/Examples/test-suite/javascript/struct_initialization_runme.js new file mode 100644 index 000000000..9ae8e7913 --- /dev/null +++ b/Examples/test-suite/javascript/struct_initialization_runme.js @@ -0,0 +1,25 @@ +var struct_initialization = require("struct_initialization"); + +if (struct_initialization.instanceC1.x != 10) { + throw new Error; +} + +if (struct_initialization.instanceD1.x != 10) { + throw new Error; +} + +if (struct_initialization.instanceD2.x != 20) { + throw new Error; +} + +if (struct_initialization.instanceD3.x != 30) { + throw new Error; +} + +if (struct_initialization.instanceE1.x != 1) { + throw new Error; +} + +if (struct_initialization.instanceF1.x != 1) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/struct_rename_runme.js b/Examples/test-suite/javascript/struct_rename_runme.js new file mode 100644 index 000000000..25ec7a0fb --- /dev/null +++ b/Examples/test-suite/javascript/struct_rename_runme.js @@ -0,0 +1,3 @@ +var struct_rename = require("struct_rename"); + +b = new struct_rename.Bar(); diff --git a/Examples/test-suite/javascript/template_class_reuse_name_runme.js b/Examples/test-suite/javascript/template_class_reuse_name_runme.js new file mode 100644 index 000000000..aa444967b --- /dev/null +++ b/Examples/test-suite/javascript/template_class_reuse_name_runme.js @@ -0,0 +1,42 @@ +var template_class_reuse_name = require("template_class_reuse_name"); + +new template_class_reuse_name.Bool1().tt() +new template_class_reuse_name.Bool1False().ff() + +new template_class_reuse_name.Bool2().tt() +new template_class_reuse_name.Bool2False().ff() + +new template_class_reuse_name.Bool3().tt() +new template_class_reuse_name.Bool3False().ff() + +new template_class_reuse_name.Bool4().tt() +new template_class_reuse_name.Bool4False().ff() + + +new template_class_reuse_name.BoolForward1().tt() +new template_class_reuse_name.BoolForward1False().ff() + +new template_class_reuse_name.BoolForward2().tt() +new template_class_reuse_name.BoolForward2False().ff() + +new template_class_reuse_name.BoolForward3().tt() +new template_class_reuse_name.BoolForward3False().ff() + +new template_class_reuse_name.BoolForward4().tt() +new template_class_reuse_name.BoolForward4False().ff() + + +new template_class_reuse_name.IntBool1().tt() +new template_class_reuse_name.IntBool1False().ff() + +new template_class_reuse_name.IntBool2().tt() +new template_class_reuse_name.IntBool2False().ff() + +new template_class_reuse_name.IntBool3().tt() +new template_class_reuse_name.IntBool3False().ff() + +new template_class_reuse_name.IntBool4().tt() +new template_class_reuse_name.IntBool4False().ff() + +new template_class_reuse_name.Duplicate2_0().n() +new template_class_reuse_name.Duplicate3().n() diff --git a/Examples/test-suite/javascript/template_classes_runme.js b/Examples/test-suite/javascript/template_classes_runme.js new file mode 100644 index 000000000..2d898eac6 --- /dev/null +++ b/Examples/test-suite/javascript/template_classes_runme.js @@ -0,0 +1,52 @@ +var template_classes = require("template_classes"); + +// This test is just testing incorrect number of arguments/parameters checking + +point = new template_classes.PointInt(); + +rectangle = new template_classes.RectangleInt(); +rectangle.setPoint(point); +rectangle.getPoint(); +template_classes.RectangleInt.static_noargs(); +template_classes.RectangleInt.static_onearg(1); + +fail = true; +try { + rectangle.setPoint(); +} catch { + fail = false; +} +if (fail) { + throw new Error("argument count check failed"); +} + + +fail = true; +try { + rectangle.getPoint(0); +} catch { + fail = false; +} +if (fail) { + throw new Error("argument count check failed"); +} + +fail = true; +try { + RectangleInt.static_noargs(0); +} catch { + fail = false; +} +if (fail) { + throw new Error("argument count check failed"); +} + +fail = true; +try { + RectangleInt.static_onearg(); +} catch { + fail = false; +} +if (fail) { + throw new Error("argument count check failed"); +} diff --git a/Examples/test-suite/javascript/template_construct_runme.js b/Examples/test-suite/javascript/template_construct_runme.js new file mode 100644 index 000000000..8191c0e75 --- /dev/null +++ b/Examples/test-suite/javascript/template_construct_runme.js @@ -0,0 +1,3 @@ +var template_construct = require("template_construct") + +f = new template_construct.Foo_int(2); diff --git a/Examples/test-suite/javascript/template_default_arg_overloaded_extend_runme.js b/Examples/test-suite/javascript/template_default_arg_overloaded_extend_runme.js new file mode 100644 index 000000000..5f7f512a8 --- /dev/null +++ b/Examples/test-suite/javascript/template_default_arg_overloaded_extend_runme.js @@ -0,0 +1,22 @@ +var template_default_arg_overloaded_extend = require("template_default_arg_overloaded_extend"); + +function check(flag) { + if (!flag) { + throw new Error("failed"); + } +} + +rs = new template_default_arg_overloaded_extend.ResultSet(); + +check(rs.go_get_method(0, new template_default_arg_overloaded_extend.SearchPoint()) == -1); +check(rs.go_get_method(0, new template_default_arg_overloaded_extend.SearchPoint(), 100) == 100); + +check(rs.go_get_template(0, new template_default_arg_overloaded_extend.SearchPoint()) == -2); +check(rs.go_get_template(0, new template_default_arg_overloaded_extend.SearchPoint(), 100) == 100); + +check(rs.over() == "over(int)"); +check(rs.over(10) == "over(int)"); +check(rs.over(new template_default_arg_overloaded_extend.SearchPoint()) == "over(giai2::SearchPoint, int)"); +check(rs.over(new template_default_arg_overloaded_extend.SearchPoint(), 10) == "over(giai2::SearchPoint, int)"); +check(rs.over(true, new template_default_arg_overloaded_extend.SearchPoint()) == "over(bool, gaia2::SearchPoint, int)"); +check(rs.over(true, new template_default_arg_overloaded_extend.SearchPoint(), 10) == "over(bool, gaia2::SearchPoint, int)"); diff --git a/Examples/test-suite/javascript/template_default_arg_overloaded_runme.js b/Examples/test-suite/javascript/template_default_arg_overloaded_runme.js new file mode 100644 index 000000000..d0b61b09d --- /dev/null +++ b/Examples/test-suite/javascript/template_default_arg_overloaded_runme.js @@ -0,0 +1,49 @@ +var template_default_arg_overloaded = require("template_default_arg_overloaded"); + +function check(expected, got) { + if (expected != got) { + throw new Error("Expected: " + str(expected) + " got: " + str(got)); + } +} + + +pl = new template_default_arg_overloaded.PropertyList(); +check(1, pl.setInt("int", 10)); +check(1, pl.setInt("int", 10, false)); + +check(2, pl.set("int", pl)); +check(2, pl.set("int", pl, false)); + +check(3, pl.setInt("int", 10, "int")); +check(3, pl.setInt("int", 10, "int", false)); + + +pl = new template_default_arg_overloaded.PropertyListGlobal(); +check(1, pl.setIntGlobal("int", 10)); +check(1, pl.setIntGlobal("int", 10, false)); + +check(2, pl.set("int", pl)); +check(2, pl.set("int", pl, false)); + +check(3, pl.setIntGlobal("int", 10, "int")); +check(3, pl.setIntGlobal("int", 10, "int", false)); + + +check(1, template_default_arg_overloaded.GoopIntGlobal(10)); +check(1, template_default_arg_overloaded.GoopIntGlobal(10, true)); + +check(2, template_default_arg_overloaded.goopGlobal(3)); +check(2, template_default_arg_overloaded.goopGlobal()); + +check(3, template_default_arg_overloaded.GoopIntGlobal("int", false)); +check(3, template_default_arg_overloaded.GoopIntGlobal("int")); + + +check(1, template_default_arg_overloaded.GoopInt(10)); +check(1, template_default_arg_overloaded.GoopInt(10, true)); + +check(2, template_default_arg_overloaded.goop(3)); +check(2, template_default_arg_overloaded.goop()); + +check(3, template_default_arg_overloaded.GoopInt("int", false)); +check(3, template_default_arg_overloaded.GoopInt("int")); diff --git a/Examples/test-suite/javascript/template_default_arg_runme.js b/Examples/test-suite/javascript/template_default_arg_runme.js new file mode 100644 index 000000000..f8b7fd9ba --- /dev/null +++ b/Examples/test-suite/javascript/template_default_arg_runme.js @@ -0,0 +1,112 @@ +var template_default_arg = require("template_default_arg"); + + +helloInt = new template_default_arg.Hello_int(); +helloInt.foo(template_default_arg.Hello_int.hi); + + +x = new template_default_arg.X_int(); +if ((x.meth(20, 200) != 200)) { + throw new Error(("X_int test 1 failed")); +} +if ((x.meth(20) != 0)) { + throw new Error(("X_int test 2 failed")); +} +if ((x.meth() != 0)) { + throw new Error(("X_int test 3 failed")); +} + + +y = new template_default_arg.Y_unsigned(); +if ((y.meth(20.0, 200) != 200)) { + throw new Error(("Y_unsigned test 1 failed")); +} +if ((y.meth(20) != 0)) { + throw new Error(("Y_unsigned test 2 failed")); +} +if ((y.meth() != 0)) { + throw new Error(("Y_unsigned test 3 failed")); +} + + +x = new template_default_arg.X_longlong(); +x = new template_default_arg.X_longlong(20.0); +x = new template_default_arg.X_longlong(20.0, 200); + + +x = new template_default_arg.X_int(); +x = new template_default_arg.X_int(20.0); +x = new template_default_arg.X_int(20.0, 200); + + +x = new template_default_arg.X_hello_unsigned(); +x = new template_default_arg.X_hello_unsigned(20.0); +x = new template_default_arg.X_hello_unsigned( + 20.0, new template_default_arg.Hello_int()); + + +y = new template_default_arg.Y_hello_unsigned(); +y.meth(20.0, new template_default_arg.Hello_int()); +y.meth(new template_default_arg.Hello_int()); +y.meth(); + + +fz = new template_default_arg.Foo_Z_8(); +x = new template_default_arg.X_Foo_Z_8(); +fzc = x.meth(fz); + + +// Templated functions + +// plain function: int ott(Foo<int>) +if ((template_default_arg.ott(new template_default_arg.Foo_int()) != 30)) { + throw new Error(("ott test 1 failed")); +} + +// %template(ott) ott<int, int> +if ((template_default_arg.ott() != 10)) { + throw new Error(("ott test 2 failed")); +} +if ((template_default_arg.ott(1) != 10)) { + throw new Error(("ott test 3 failed")); +} +if ((template_default_arg.ott(1, 1) != 10)) { + throw new Error(("ott test 4 failed")); +} + +if ((template_default_arg.ott("hi") != 20)) { + throw new Error(("ott test 5 failed")); +} +if ((template_default_arg.ott("hi", 1) != 20)) { + throw new Error(("ott test 6 failed")); +} +if ((template_default_arg.ott("hi", 1, 1) != 20)) { + throw new Error(("ott test 7 failed")); +} + +// %template(ott) ott<const char *> +if ((template_default_arg.ottstring(new template_default_arg.Hello_int(), "hi") != 40)) { + throw new Error(("ott test 8 failed")); +} + +if ((template_default_arg.ottstring(new template_default_arg.Hello_int()) != 40)) { + throw new Error(("ott test 9 failed")); +} + +// %template(ott) ott<int> +if ((template_default_arg.ottint(new template_default_arg.Hello_int(), 1) != 50)) { + throw new Error(("ott test 10 failed")); +} + +if ((template_default_arg.ottint(new template_default_arg.Hello_int()) != 50)) { + throw new Error(("ott test 11 failed")); +} + +// %template(ott) ott<double> +if ((template_default_arg.ott(new template_default_arg.Hello_int(), 1.0) != 60)) { + throw new Error(("ott test 12 failed")); +} + +if ((template_default_arg.ott(new template_default_arg.Hello_int()) != 60)) { + throw new Error(("ott test 13 failed")); +} diff --git a/Examples/test-suite/javascript/template_default_cache_runme.js b/Examples/test-suite/javascript/template_default_cache_runme.js new file mode 100644 index 000000000..d1376d45b --- /dev/null +++ b/Examples/test-suite/javascript/template_default_cache_runme.js @@ -0,0 +1,11 @@ +var template_default_cache = require("template_default_cache"); + +ap = template_default_cache.get_mp_a(); +bp = template_default_cache.get_mp_b(); + +if (!ap instanceof template_default_cache.AModelPtr) { + throw new Error("get_mp_a fail"); +} +if (!bp instanceof template_default_cache.BModelPtr) { + throw new Error("get_mp_b fail"); +} diff --git a/Examples/test-suite/javascript/template_extend1_runme.js b/Examples/test-suite/javascript/template_extend1_runme.js new file mode 100644 index 000000000..20ebbf24b --- /dev/null +++ b/Examples/test-suite/javascript/template_extend1_runme.js @@ -0,0 +1,12 @@ +var template_extend1 = require("template_extend1"); + +a = new template_extend1.lBaz(); +b = new template_extend1.dBaz(); + +if (a.foo() != "lBaz::foo") { + throw new Error; +} + +if (b.foo() != "dBaz::foo") { + throw new Error; +} diff --git a/Examples/test-suite/javascript/template_extend2_runme.js b/Examples/test-suite/javascript/template_extend2_runme.js new file mode 100644 index 000000000..84eab3ac2 --- /dev/null +++ b/Examples/test-suite/javascript/template_extend2_runme.js @@ -0,0 +1,12 @@ +var template_extend2 = require("template_extend2"); + +a = new template_extend2.lBaz(); +b = new template_extend2.dBaz(); + +if (a.foo() != "lBaz::foo") { + throw new Error; +} + +if (b.foo() != "dBaz::foo") { + throw new Error; +} diff --git a/Examples/test-suite/javascript/template_inherit_runme.js b/Examples/test-suite/javascript/template_inherit_runme.js new file mode 100644 index 000000000..f5ba56922 --- /dev/null +++ b/Examples/test-suite/javascript/template_inherit_runme.js @@ -0,0 +1,67 @@ +var template_inherit = require("template_inherit"); +a = new template_inherit.FooInt(); +b = new template_inherit.FooDouble(); +c = new template_inherit.BarInt(); +d = new template_inherit.BarDouble(); +e = new template_inherit.FooUInt(); +f = new template_inherit.BarUInt(); + +if (a.blah() != "Foo") { + throw new Error; +} + +if (b.blah() != "Foo") { + throw new Error; +} + +if (e.blah() != "Foo") { + throw new Error; +} + +if (c.blah() != "Bar") { + throw new Error; +} + +if (d.blah() != "Bar") { + throw new Error; +} + +if (f.blah() != "Bar") { + throw new Error; +} + +if (c.foomethod() != "foomethod") { + throw new Error; +} + +if (d.foomethod() != "foomethod") { + throw new Error; +} + +if (f.foomethod() != "foomethod") { + throw new Error; +} + +if (template_inherit.invoke_blah_int(a) != "Foo") { + throw new Error; +} + +if (template_inherit.invoke_blah_int(c) != "Bar") { + throw new Error; +} + +if (template_inherit.invoke_blah_double(b) != "Foo") { + throw new Error; +} + +if (template_inherit.invoke_blah_double(d) != "Bar") { + throw new Error; +} + +if (template_inherit.invoke_blah_uint(e) != "Foo") { + throw new Error; +} + +if (template_inherit.invoke_blah_uint(f) != "Bar") { + throw new Error; +} diff --git a/Examples/test-suite/javascript/template_ns4_runme.js b/Examples/test-suite/javascript/template_ns4_runme.js new file mode 100644 index 000000000..3ba576260 --- /dev/null +++ b/Examples/test-suite/javascript/template_ns4_runme.js @@ -0,0 +1,6 @@ +var template_ns4 = require("template_ns4"); + +d = template_ns4.make_Class_DD(); +if (d.test() != "test") { + throw new Error; +} diff --git a/Examples/test-suite/javascript/template_ns_runme.js b/Examples/test-suite/javascript/template_ns_runme.js new file mode 100644 index 000000000..dde3a330c --- /dev/null +++ b/Examples/test-suite/javascript/template_ns_runme.js @@ -0,0 +1,21 @@ +var template_ns = require("template_ns"); +p1 = new template_ns.pairii(2, 3); +p2 = new template_ns.pairii(p1); + +if (p2.first != 2) { + throw new Error; +} +if (p2.second != 3) { + throw new Error; +} + +p3 = new template_ns.pairdd(3.5, 2.5); +p4 = new template_ns.pairdd(p3); + +if (p4.first != 3.5) { + throw new Error; +} + +if (p4.second != 2.5) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/template_opaque_runme.js b/Examples/test-suite/javascript/template_opaque_runme.js new file mode 100644 index 000000000..cb115ac0f --- /dev/null +++ b/Examples/test-suite/javascript/template_opaque_runme.js @@ -0,0 +1,5 @@ +var template_opaque = require("template_opaque"); + +v = new template_opaque.OpaqueVectorType(10); + +template_opaque.FillVector(v); diff --git a/Examples/test-suite/javascript/template_ref_type_runme.js b/Examples/test-suite/javascript/template_ref_type_runme.js new file mode 100644 index 000000000..7fd05303d --- /dev/null +++ b/Examples/test-suite/javascript/template_ref_type_runme.js @@ -0,0 +1,5 @@ +var template_ref_type = require("template_ref_type"); + +xr = new template_ref_type.XC(); +y = new template_ref_type.Y(); +y.find(xr); diff --git a/Examples/test-suite/javascript/template_rename_runme.js b/Examples/test-suite/javascript/template_rename_runme.js new file mode 100644 index 000000000..ae8f84900 --- /dev/null +++ b/Examples/test-suite/javascript/template_rename_runme.js @@ -0,0 +1,12 @@ +var template_rename = require("template_rename"); + +i = new template_rename.iFoo(); +d = new 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/javascript/template_tbase_template_runme.js b/Examples/test-suite/javascript/template_tbase_template_runme.js new file mode 100644 index 000000000..090126d7c --- /dev/null +++ b/Examples/test-suite/javascript/template_tbase_template_runme.js @@ -0,0 +1,6 @@ +var template_tbase_template = require("template_tbase_template"); + +a = template_tbase_template.make_Class_dd(); +if (a.test() != "test") { + throw new Error; +} diff --git a/Examples/test-suite/javascript/template_template_parameters_runme.js b/Examples/test-suite/javascript/template_template_parameters_runme.js new file mode 100644 index 000000000..b832b2c40 --- /dev/null +++ b/Examples/test-suite/javascript/template_template_parameters_runme.js @@ -0,0 +1,38 @@ +var template_template_parameters = require("template_template_parameters"); + +// Test part 1 +listBool = new template_template_parameters.ListFastBool(); +listBool.item = true; +x_boolean = listBool.allotype; +if (listBool.item != true) { + throw new Error("Failed"); +} + +listDouble = new template_template_parameters.ListDefaultDouble(); +listDouble.item = 10.2; +x_double = listDouble.allotype; +if (listDouble.item != 10.2) { + throw new Error("Failed"); +} + +// Test part 2 +floatTestStruct = new template_template_parameters.FloatTestStruct(); +floatContainer2 = floatTestStruct.x; +floatContainer2.x = 8.1; +intTestStruct = new template_template_parameters.IntTestStruct(); +intContainer1 = intTestStruct.x; +intContainer1.x = 91; +if (intContainer1.x != 91) { + throw new Error("Failed"); +} +if (intTestStruct.x.x != 91) { + throw new Error("Failed"); +} +intTestStructReturned = template_template_parameters.TestStructContainer1Method(intTestStruct); +if (intTestStructReturned.x.x != 101) { + throw new Error("Failed"); +} + +// Test part 3 +mfi99 = new template_template_parameters.MyFootInt99(); +mfi99.addTo(mfi99); // __iadd__ diff --git a/Examples/test-suite/javascript/template_type_namespace_runme.js b/Examples/test-suite/javascript/template_type_namespace_runme.js new file mode 100644 index 000000000..056d645bd --- /dev/null +++ b/Examples/test-suite/javascript/template_type_namespace_runme.js @@ -0,0 +1,5 @@ +var template_type_namespace = require("template_type_namespace"); + +if (template_type_namespace.foo().get(0) != "foo") { + throw new Error; +} diff --git a/Examples/test-suite/javascript/template_typedef_cplx2_runme.js b/Examples/test-suite/javascript/template_typedef_cplx2_runme.js new file mode 100644 index 000000000..f97e92781 --- /dev/null +++ b/Examples/test-suite/javascript/template_typedef_cplx2_runme.js @@ -0,0 +1,24 @@ +var template_typedef_cplx2 = require("template_typedef_cplx2"); + +// +// double case +// + +var d, e; + +try { + d = template_typedef_cplx2.make_Identity_double(); + // This test is not possible in JSC where all SWIG proxies inherit from Object + if (typeof print === 'undefined') + if (!d.constructor.name.includes('ArithUnaryFunction')) throw new Error; +} catch { + throw new Error(`${d} is not an ArithUnaryFunction`); +} + +try { + e = template_typedef_cplx2.make_Multiplies_double_double_double_double(d, d); + if (typeof print === 'undefined') + if (!e.constructor.name.includes('ArithUnaryFunction')) throw new Error; +} catch { + throw new Error(`${e} is not an ArithUnaryFunction`); +} diff --git a/Examples/test-suite/javascript/template_typedef_cplx3_runme.js b/Examples/test-suite/javascript/template_typedef_cplx3_runme.js new file mode 100644 index 000000000..0bec61109 --- /dev/null +++ b/Examples/test-suite/javascript/template_typedef_cplx3_runme.js @@ -0,0 +1,19 @@ +var template_typedef_cplx3 = require("template_typedef_cplx3"); + +// +// this is OK +// + + +s = new template_typedef_cplx3.Sin(); +s.get_base_value(); +s.get_value(); +s.get_arith_value(); +template_typedef_cplx3.my_func_r(s); +template_typedef_cplx3.make_Multiplies_double_double_double_double(s, s); + +// +// Here we fail +// +d = template_typedef_cplx3.make_Identity_double(); +template_typedef_cplx3.my_func_r(d); diff --git a/Examples/test-suite/javascript/template_typedef_cplx4_runme.js b/Examples/test-suite/javascript/template_typedef_cplx4_runme.js new file mode 100644 index 000000000..1f6a65c02 --- /dev/null +++ b/Examples/test-suite/javascript/template_typedef_cplx4_runme.js @@ -0,0 +1,19 @@ +var template_typedef_cplx4 = require("template_typedef_cplx4"); + +// +// this is OK +// + + +s = new template_typedef_cplx4.Sin(); +s.get_base_value(); +s.get_value(); +s.get_arith_value(); +template_typedef_cplx4.my_func_r(s); +template_typedef_cplx4.make_Multiplies_double_double_double_double(s, s); + +// +// Here we fail +// +d = template_typedef_cplx4.make_Identity_double(); +template_typedef_cplx4.my_func_r(d); diff --git a/Examples/test-suite/javascript/template_typedef_cplx_runme.js b/Examples/test-suite/javascript/template_typedef_cplx_runme.js new file mode 100644 index 000000000..977b98621 --- /dev/null +++ b/Examples/test-suite/javascript/template_typedef_cplx_runme.js @@ -0,0 +1,24 @@ +var template_typedef_cplx = require("template_typedef_cplx"); + +// +// double case +// + +var d, e; + +try { + d = template_typedef_cplx.make_Identity_double(); + // This test is not possible in JSC where all SWIG proxies inherit from Object + if (typeof print === 'undefined') + if (!d.constructor.name.includes('ArithUnaryFunction')) throw new Error; +} catch { + throw new Error(`${d} is not an ArithUnaryFunction`); +} + +try { + e = template_typedef_cplx.make_Multiplies_double_double_double_double(d, d); + if (typeof print === 'undefined') + if (!e.constructor.name.includes('ArithUnaryFunction')) throw new Error; +} catch { + throw new Error(`${e} is not an ArithUnaryFunction`); +} diff --git a/Examples/test-suite/javascript/template_typemaps_typedef2_runme.js b/Examples/test-suite/javascript/template_typemaps_typedef2_runme.js new file mode 100644 index 000000000..911a3fce6 --- /dev/null +++ b/Examples/test-suite/javascript/template_typemaps_typedef2_runme.js @@ -0,0 +1,42 @@ +var template_typemaps_typedef2 = require("template_typemaps_typedef2"); + +m1 = new template_typemaps_typedef2.MultimapIntA(); + +dummy_pair = m1.make_dummy_pair(); +val = m1.typemap_test(dummy_pair).val; +if (val != 1234) { + throw new Error("typemaps not working"); +} + +m2 = new template_typemaps_typedef2.MultimapAInt(); + +// TODO: typemaps and specializations not quite working as expected. T needs expanding, but at least the right typemap is being picked up. +//dummy_pair = m2.make_dummy_pair() +//val = m2.typemap_test(dummy_pair) + +// if (val != 4321) { +// throw new Error, "typemaps not working" + +if (template_typemaps_typedef2.typedef_test1(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef2.typedef_test1 not working"); +} + +if (template_typemaps_typedef2.typedef_test2(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef2.typedef_test2 not working"); +} + +if (template_typemaps_typedef2.typedef_test3(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef2.typedef_test3 not working"); +} + +if (template_typemaps_typedef2.typedef_test4(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef2.typedef_test4 not working"); +} + +if (template_typemaps_typedef2.typedef_test5(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef2.typedef_test5 not working"); +} + +if (template_typemaps_typedef2.typedef_test6(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef2.typedef_test6 not working"); +} diff --git a/Examples/test-suite/javascript/template_typemaps_typedef_runme.js b/Examples/test-suite/javascript/template_typemaps_typedef_runme.js new file mode 100644 index 000000000..d94c4be82 --- /dev/null +++ b/Examples/test-suite/javascript/template_typemaps_typedef_runme.js @@ -0,0 +1,42 @@ +var template_typemaps_typedef = require("template_typemaps_typedef"); + +m1 = new template_typemaps_typedef.MultimapIntA(); + +dummy_pair = m1.make_dummy_pair(); +val = m1.typemap_test(dummy_pair).val; +if (val != 1234) { + throw new Error("typemaps not working"); +} + +m2 = new template_typemaps_typedef.MultimapAInt(); + +// TODO: typemaps and specializations not quite working as expected. T needs expanding, but at least the right typemap is being picked up. +//dummy_pair = m2.make_dummy_pair() +//val = m2.typemap_test(dummy_pair) + +// if (val != 4321) { +// throw new Error, "typemaps not working" + +if (template_typemaps_typedef.typedef_test1(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef.typedef_test1 not working"); +} + +if (template_typemaps_typedef.typedef_test2(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef.typedef_test2 not working"); +} + +if (template_typemaps_typedef.typedef_test3(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef.typedef_test3 not working"); +} + +if (template_typemaps_typedef.typedef_test4(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef.typedef_test4 not working"); +} + +if (template_typemaps_typedef.typedef_test5(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef.typedef_test5 not working"); +} + +if (template_typemaps_typedef.typedef_test6(dummy_pair).val != 1234) { + throw new Error("template_typemaps_typedef.typedef_test6 not working"); +} diff --git a/Examples/test-suite/javascript/template_using_directive_typedef_runme.js b/Examples/test-suite/javascript/template_using_directive_typedef_runme.js new file mode 100644 index 000000000..de5482f95 --- /dev/null +++ b/Examples/test-suite/javascript/template_using_directive_typedef_runme.js @@ -0,0 +1,15 @@ +var template_using_directive_typedef = require("template_using_directive_typedef") + +vo = new template_using_directive_typedef.Vector_Obj(); + +h = new template_using_directive_typedef.Holder(); +h.holder_use1(vo, vo, vo); +h.holder_use2(vo, vo, vo); +h.holder_use3(vo, vo, vo); + +template_using_directive_typedef.tns_holder_use(vo, vo); +template_using_directive_typedef.tns_use(vo, vo, vo); +template_using_directive_typedef.global_holder_use(vo); +template_using_directive_typedef.global_use(vo, vo, vo); +template_using_directive_typedef.ns1_holder_use(vo); +template_using_directive_typedef.ns2_holder_use(vo, vo, vo, vo); diff --git a/Examples/test-suite/javascript/typedef_classforward_same_name_runme.js b/Examples/test-suite/javascript/typedef_classforward_same_name_runme.js new file mode 100644 index 000000000..ff8a1ed4f --- /dev/null +++ b/Examples/test-suite/javascript/typedef_classforward_same_name_runme.js @@ -0,0 +1,13 @@ +var typedef_classforward_same_name = require("typedef_classforward_same_name"); + +foo = new typedef_classforward_same_name.Foo(); +foo.x = 5; +if (typedef_classforward_same_name.extractFoo(foo) != 5) { + throw new Error("unexpected value"); +} + +boo = new typedef_classforward_same_name.Boo(); +boo.x = 5; +if (typedef_classforward_same_name.extractBoo(boo) != 5) { + throw new Error("unexpected value"); +} diff --git a/Examples/test-suite/javascript/typedef_funcptr_runme.js b/Examples/test-suite/javascript/typedef_funcptr_runme.js new file mode 100644 index 000000000..ca0f81a1e --- /dev/null +++ b/Examples/test-suite/javascript/typedef_funcptr_runme.js @@ -0,0 +1,25 @@ +var typedef_funcptr = require("typedef_funcptr"); + +a = 100; +b = 10; + +if (typedef_funcptr.do_op(a, b, typedef_funcptr.addf) != 110) { + throw new Error("addf failed"); +} +if (typedef_funcptr.do_op(a, b, typedef_funcptr.subf) != 90) { + throw new Error("subf failed"); +} + +if (typedef_funcptr.do_op_typedef_int(a, b, typedef_funcptr.addf) != 110) { + throw new Error("addf failed"); +} +if (typedef_funcptr.do_op_typedef_int(a, b, typedef_funcptr.subf) != 90) { + throw new Error("subf failed"); +} + +if (typedef_funcptr.do_op_typedef_Integer(a, b, typedef_funcptr.addf) != 110) { + throw new Error("addf failed"); +} +if (typedef_funcptr.do_op_typedef_Integer(a, b, typedef_funcptr.subf) != 90) { + throw new Error("subf failed"); +} diff --git a/Examples/test-suite/javascript/typedef_inherit_runme.js b/Examples/test-suite/javascript/typedef_inherit_runme.js index 7590e1e6e..1ebb128da 100644 --- a/Examples/test-suite/javascript/typedef_inherit_runme.js +++ b/Examples/test-suite/javascript/typedef_inherit_runme.js @@ -21,3 +21,7 @@ if (x != "Spam::blah") x = typedef_inherit.do_blah2(d); if (x != "Grok::blah") print ("Whoa! Bad return" + x); + +x = d.far(); +if (x != "Spam::far") + print ("Whoa! Bad return" + x); diff --git a/Examples/test-suite/javascript/typedef_typedef_runme.js b/Examples/test-suite/javascript/typedef_typedef_runme.js new file mode 100644 index 000000000..2a7b649ed --- /dev/null +++ b/Examples/test-suite/javascript/typedef_typedef_runme.js @@ -0,0 +1,6 @@ +var typedef_typedef = require("typedef_typedef"); + +b = new typedef_typedef.B(); +if (b.getValue(123) != 1234) { + throw new Error("Failed"); +} diff --git a/Examples/test-suite/javascript/typemap_documentation_runme.js b/Examples/test-suite/javascript/typemap_documentation_runme.js new file mode 100644 index 000000000..c0118d742 --- /dev/null +++ b/Examples/test-suite/javascript/typemap_documentation_runme.js @@ -0,0 +1,27 @@ +var typemap_documentation = require("typemap_documentation"); + +f = new typemap_documentation.Foo(); +f.x = 55; +b = new typemap_documentation.Bar(); +b.y = 44; + +if (55 != typemap_documentation.GrabVal(f)) { + throw new Error("bad value"); +} + +try { + typemap_documentation.GrabVal(b); +} catch (e) { + // This is working only in NAPI, other backends throw generic errors + //if (!(e instanceof TypeError)) + // throw e; + if (!e.message.includes('expecting type Foo')) + throw e; +} + +if (55 != typemap_documentation.GrabValFooBar(f)) { + throw new Error("bad f value"); +} +if (44 != typemap_documentation.GrabValFooBar(b)) { + throw new Error("bad b value"); +} diff --git a/Examples/test-suite/javascript/typemap_out_optimal_runme.js b/Examples/test-suite/javascript/typemap_out_optimal_runme.js new file mode 100644 index 000000000..d9f303a34 --- /dev/null +++ b/Examples/test-suite/javascript/typemap_out_optimal_runme.js @@ -0,0 +1,5 @@ +var typemap_out_optimal = require("typemap_out_optimal"); + +typemap_out_optimal.XX.trace = false; +x = typemap_out_optimal.XX.create(); +x = typemap_out_optimal.XX.createConst(); diff --git a/Examples/test-suite/javascript/typemap_qualifier_strip_runme.js b/Examples/test-suite/javascript/typemap_qualifier_strip_runme.js new file mode 100644 index 000000000..e4f5c12cd --- /dev/null +++ b/Examples/test-suite/javascript/typemap_qualifier_strip_runme.js @@ -0,0 +1,69 @@ +var typemap_qualifier_strip = require("typemap_qualifier_strip"); + +val = typemap_qualifier_strip.create_int(111); +if (typemap_qualifier_strip.testA1(val) != 1234) { + throw new Error; +} + +if (typemap_qualifier_strip.testA2(val) != 1234) { + throw new Error; +} + +if (typemap_qualifier_strip.testA3(val) != 1234) { + throw new Error; +} + +if (typemap_qualifier_strip.testA4(val) != 1234) { + throw new Error; +} + + +if (typemap_qualifier_strip.testB1(val) != 111) { + throw new Error; +} + +if (typemap_qualifier_strip.testB2(val) != 111) { + throw new Error; +} + +if (typemap_qualifier_strip.testB3(val) != 111) { + throw new Error; +} + +if (typemap_qualifier_strip.testB4(val) != 111) { + throw new Error; +} + + +if (typemap_qualifier_strip.testC1(val) != 5678) { + throw new Error; +} + +if (typemap_qualifier_strip.testC2(val) != 111) { + throw new Error; +} + +if (typemap_qualifier_strip.testC3(val) != 5678) { + throw new Error; +} + +if (typemap_qualifier_strip.testC4(val) != 111) { + throw new Error; +} + + +if (typemap_qualifier_strip.testD1(val) != 111) { + throw new Error; +} + +if (typemap_qualifier_strip.testD2(val) != 3456) { + throw new Error; +} + +if (typemap_qualifier_strip.testD3(val) != 111) { + throw new Error; +} + +if (typemap_qualifier_strip.testD4(val) != 111) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/typemap_template_typedef_runme.js b/Examples/test-suite/javascript/typemap_template_typedef_runme.js new file mode 100644 index 000000000..3410e12b5 --- /dev/null +++ b/Examples/test-suite/javascript/typemap_template_typedef_runme.js @@ -0,0 +1,33 @@ +var typemap_template_typedef = require("typemap_template_typedef"); + +function check(got, expected) { + if (got != expected) { + throw new Error("got: " + got.toString() + " expected: " + expected.toString()); + } +} + +x = new typemap_template_typedef.XXXInt(); + +check(x.aa1(0), 0); +check(x.aa2(0), 55); +check(x.aa3(0), 0); +check(typemap_template_typedef.aa1(0), 0); +check(typemap_template_typedef.aa2(0), 0); + +check(x.bb1(0), 0); +check(x.bb2(0), 66); +check(x.bb3(0), 0); +check(typemap_template_typedef.bb1(0), 0); +check(typemap_template_typedef.bb2(0), 0); + +check(x.cc1(0), 0); +check(x.cc2(0), 77); +check(x.cc3(0), 77); +check(typemap_template_typedef.cc1(0), 0); +check(typemap_template_typedef.cc2(0), 0); + +check(x.dd1(0), 0); +check(x.dd2(0), 88); +check(x.dd3(0), 0); +check(typemap_template_typedef.dd1(0), 0); +check(typemap_template_typedef.dd2(0), 0) diff --git a/Examples/test-suite/javascript/typename_runme.js b/Examples/test-suite/javascript/typename_runme.js new file mode 100644 index 000000000..48434ec7c --- /dev/null +++ b/Examples/test-suite/javascript/typename_runme.js @@ -0,0 +1,12 @@ +var typename = require("typename"); +f = new typename.Foo(); +b = new typename.Bar(); + +x = typename.twoFoo(f); +if (typeof x !== 'number') { + throw new Error("Wrong return type (FloatType) !"); +} +y = typename.twoBar(b); +if (typeof y !== 'number') { + throw new Error("Wrong return type (IntType)!"); +} diff --git a/Examples/test-suite/javascript/types_directive_runme.js b/Examples/test-suite/javascript/types_directive_runme.js new file mode 100644 index 000000000..f4f0a2b7a --- /dev/null +++ b/Examples/test-suite/javascript/types_directive_runme.js @@ -0,0 +1,14 @@ +var types_directive = require("types_directive"); + +d1 = new types_directive.Time1(2001, 2, 3, 60) +// check that a Time1 instance is accepted where Date is expected +newDate = types_directive.add(d1, 7) +if (newDate.day != 10) + throw new Error("newDate mismatch") + +d2 = new types_directive.Time2(1999, 8, 7, 60) +// check that a Time2 instance is accepted where Date is expected +newDate = types_directive.add(d2, 7) +if (newDate.day != 14) + throw new Error("newDate mismatch") + diff --git a/Examples/test-suite/javascript/unicode_strings_runme.js b/Examples/test-suite/javascript/unicode_strings_runme.js new file mode 100644 index 000000000..cd7f537d2 --- /dev/null +++ b/Examples/test-suite/javascript/unicode_strings_runme.js @@ -0,0 +1,27 @@ +var unicode_strings = require("unicode_strings"); + +// This uses slightly different encoding than the Python test +// but AFAIK, it is the V8 handling that is the correct one + +function check(s1, s2) { + for (let i in s1) { + if (s1[i] !== s2[i]) + console.error(`Character number ${i}, ${s1.charCodeAt(i)} != ${s2.charCodeAt(i)}`); + } + if (s1 != s2) { + throw new Error(`'${s1}' != '${s2}'`); + } +} + +// The C++ string contains an invalid UTF-8 character +// V8 transforms it to \ufffd +// JSC silently refuses it +test_string = "h\ufffdllo w\u00f6rld"; + +if (typeof print === 'undefined') { + check(unicode_strings.non_utf8_c_str(), test_string); + check(unicode_strings.non_utf8_std_string(), test_string); +} else { + check(unicode_strings.non_utf8_c_str(), ''); + check(unicode_strings.non_utf8_std_string(), ''); +} diff --git a/Examples/test-suite/javascript/using_private_runme.js b/Examples/test-suite/javascript/using_private_runme.js new file mode 100644 index 000000000..ee3ecb35e --- /dev/null +++ b/Examples/test-suite/javascript/using_private_runme.js @@ -0,0 +1,16 @@ +var using_private = require("using_private"); + +f = new using_private.FooBar(); +f.x = 3; + +if (f.blah(4) != 4) { + throw new Error("blah(int)"); +} + +if (f.defaulted() != -1) { + throw new Error("defaulted()"); +} + +if (f.defaulted(222) != 222) { + throw new Error("defaulted(222)"); +} diff --git a/Examples/test-suite/javascript/using_protected_runme.js b/Examples/test-suite/javascript/using_protected_runme.js new file mode 100644 index 000000000..990f56111 --- /dev/null +++ b/Examples/test-suite/javascript/using_protected_runme.js @@ -0,0 +1,8 @@ +var using_protected = require("using_protected"); + +f = new using_protected.FooBar(); +f.x = 3; + +if (f.blah(4) != 4) { + throw new Error("blah(int)"); +} diff --git a/Examples/test-suite/javascript/varargs_overload_runme.js b/Examples/test-suite/javascript/varargs_overload_runme.js new file mode 100644 index 000000000..337f4adb4 --- /dev/null +++ b/Examples/test-suite/javascript/varargs_overload_runme.js @@ -0,0 +1,79 @@ +var varargs_overload = require("varargs_overload"); + +if (varargs_overload.vararg_over1("Hello") != "Hello") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over1(2) != "2") { + throw new Error("Failed"); +} + + +if (varargs_overload.vararg_over2("Hello") != "Hello") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over2(2, 2.2) != "2 2.2") { + throw new Error("Failed"); +} + + +if (varargs_overload.vararg_over3("Hello") != "Hello") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over3(2, 2.2, "hey") != "2 2.2 hey") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over4("Hello") != "Hello") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over4(123) != "123") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over4("Hello", 123) != "Hello") { + throw new Error("Failed"); +} + + +// Same as above but non-vararg function declared first + +if (varargs_overload.vararg_over6("Hello") != "Hello") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over6(2) != "2") { + throw new Error("Failed"); +} + + +if (varargs_overload.vararg_over7("Hello") != "Hello") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over7(2, 2.2) != "2 2.2") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over8("Hello") != "Hello") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over8(2, 2.2, "hey") != "2 2.2 hey") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over9("Hello") != "Hello") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over9(123) != "123") { + throw new Error("Failed"); +} + +if (varargs_overload.vararg_over9("Hello", 123) != "Hello") { + throw new Error("Failed"); +} diff --git a/Examples/test-suite/javascript/virtual_derivation_runme.js b/Examples/test-suite/javascript/virtual_derivation_runme.js new file mode 100644 index 000000000..be87a5d9a --- /dev/null +++ b/Examples/test-suite/javascript/virtual_derivation_runme.js @@ -0,0 +1,8 @@ +var virtual_derivation = require("virtual_derivation"); +// +// very innocent example +// +b = new virtual_derivation.B(3) +if (b.get_a() != b.get_b()) + throw new Error("something is really wrong") + diff --git a/Examples/test-suite/javascript/virtual_poly_runme.js b/Examples/test-suite/javascript/virtual_poly_runme.js new file mode 100644 index 000000000..7cdb03930 --- /dev/null +++ b/Examples/test-suite/javascript/virtual_poly_runme.js @@ -0,0 +1,44 @@ +var virtual_poly = require("virtual_poly"); + +d = new virtual_poly.NDouble(3.5); +i = new virtual_poly.NInt(2); + +// +// the copy methods return the right polymorphic types +// +dc = d.copy(); +ic = i.copy(); + +if (d.get() != dc.get()) { + throw new Error; +} + +if (i.get() != ic.get()) { + throw new Error; +} + +virtual_poly.incr(ic); + +if ((i.get() + 1) != ic.get()) { + throw new Error; +} + + +dr = d.ref_this(); +if (d.get() != dr.get()) { + throw new Error; +} + + +// +// 'narrowing' also works +// +ddc = virtual_poly.NDouble.narrow(d.nnumber()); +if (d.get() != ddc.get()) { + throw new Error; +} + +dic = virtual_poly.NInt.narrow(i.nnumber()); +if (i.get() != dic.get()) { + throw new Error; +} diff --git a/Examples/test-suite/javascript/voidtest_runme.js b/Examples/test-suite/javascript/voidtest_runme.js new file mode 100644 index 000000000..8ff0c0ba9 --- /dev/null +++ b/Examples/test-suite/javascript/voidtest_runme.js @@ -0,0 +1,28 @@ +var voidtest = require("voidtest"); + +voidtest.globalfunc(); +var f = new voidtest.Foo(); +f.memberfunc(); + +voidtest.Foo.staticmemberfunc(); + +if (f.memberfunc() !== (function(){}())) { + throw new Error("f.memberfunc() didn't return same result as pure Javascript equivalent"); +} + +v1 = voidtest.vfunc1(f); +v2 = voidtest.vfunc2(f); +if (!voidtest.test_pointers_equal(v1, v2)) { + throw new Error("!voidtest.test_pointers_equal(v1, v2)"); +} + +v3 = voidtest.vfunc3(v1); +if (!voidtest.test_pointers_equal(v3.get_this(), f.get_this())) { + throw new Error("!voidtest.test_pointers_equal(v3.get_this(), f.get_this())"); +} +v4 = voidtest.vfunc1(f); +if (!voidtest.test_pointers_equal(v4, v1)) { + throw new Error("!voidtest.test_pointers_equal(v4, v1)"); +} + +v3.memberfunc(); |