diff options
Diffstat (limited to 'Examples/test-suite/go')
-rw-r--r-- | Examples/test-suite/go/Makefile.in | 72 | ||||
-rw-r--r-- | Examples/test-suite/go/argcargvtest_runme.go | 55 | ||||
-rw-r--r-- | Examples/test-suite/go/catches_strings_runme.go | 32 | ||||
-rw-r--r-- | Examples/test-suite/go/class_case_runme.go | 12 | ||||
-rw-r--r-- | Examples/test-suite/go/cpp11_std_array_runme.go | 68 | ||||
-rw-r--r-- | Examples/test-suite/go/friends_runme.go | 15 | ||||
-rw-r--r-- | Examples/test-suite/go/go_director_inout_runme.go | 46 | ||||
-rw-r--r-- | Examples/test-suite/go/go_inout_runme.go | 8 | ||||
-rw-r--r-- | Examples/test-suite/go/li_constraints_runme.go | 70 | ||||
-rw-r--r-- | Examples/test-suite/go/smart_pointer_extend_runme.go | 4 | ||||
-rw-r--r-- | Examples/test-suite/go/special_variable_macros_runme.go | 6 | ||||
-rw-r--r-- | Examples/test-suite/go/typedef_inherit_runme.go | 5 | ||||
-rw-r--r-- | Examples/test-suite/go/typemap_out_optimal_runme.go | 3 |
13 files changed, 344 insertions, 52 deletions
diff --git a/Examples/test-suite/go/Makefile.in b/Examples/test-suite/go/Makefile.in index 8283327d6..b2ac72620 100644 --- a/Examples/test-suite/go/Makefile.in +++ b/Examples/test-suite/go/Makefile.in @@ -12,6 +12,10 @@ SCRIPTSUFFIX = _runme.go SO = @SO@ +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@ @@ -43,17 +47,9 @@ INCLUDES = -I$(abs_top_srcdir)/$(EXAMPLES)/$(TEST_SUITE) %.multicpptest: $(setup) - mkdir -p gopath/$*/src 2>/dev/null || true - if ! test -d gopath/$*/src/swigtests; then \ - (cd gopath/$*/src && ln -s . swigtests); \ - fi + $(go_multicpp_setup) +for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - LIBS='$(LIBS)' INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ - TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR='$(INTERFACEDIR)' INTERFACE="$$f.i" \ - GOMOD="$*" \ - $(LANGUAGE)$(VARIANT)_cpp; \ + $(call swig_and_compile_cpp_helper,$${f},'$(SWIGOPT)') GOMOD="$*"; \ done $(run_multi_testcase) @@ -61,28 +57,9 @@ li_windows.cpptest: # Does not work because go build won't build li_windows.go, # because file names with "windows" are only built on Windows. -multi_import.multicpptest: - $(setup) - mkdir -p gopath/multi_import/src 2>/dev/null || true - if ! test -d gopath/multi_import/src/swigtests; then \ - (cd gopath/multi_import/src && ln -s . swigtests); \ - fi - for f in multi_import_b multi_import_a; do \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - LIBS='$(LIBS)' INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ - TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR='$(INTERFACEDIR)' INTERFACE="$$f.i" \ - GOMOD="multi_import" \ - $(LANGUAGE)$(VARIANT)_cpp; \ - done - $(run_multi_testcase) - go_subdir_import.multicpptest: $(setup) - mkdir -p gopath/go_subdir_import/src 2>/dev/null || true - if ! test -d gopath/go_subdir_import/src/swigtests; then \ - (cd gopath/go_subdir_import/src && ln -s . swigtests); \ - fi + $(go_multicpp_setup) mkdir -p testdir/go_subdir_import 2>/dev/null || true mkdir -p gopath/go_subdir_import/src/testdir/go_subdir_import 2>/dev/null || true $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ @@ -93,16 +70,17 @@ go_subdir_import.multicpptest: INTERFACE='testdir/go_subdir_import/go_subdir_import_b.i' \ GOMOD="go_subdir_import" \ $(LANGUAGE)$(VARIANT)_cpp; - for f in testdir/go_subdir_import/go_subdir_import_c go_subdir_import_a ; do \ - $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - LIBS='$(LIBS)' INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \ - TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR='$(INTERFACEDIR)' INTERFACE="$$f.i" \ - GOMOD="go_subdir_import" \ - $(LANGUAGE)$(VARIANT)_cpp; \ + +for f in testdir/go_subdir_import/go_subdir_import_c go_subdir_import_a ; do \ + $(call swig_and_compile_cpp_helper,$${f},'$(SWIGOPT)') GOMOD="go_subdir_import"; \ done $(run_multi_testcase) +go_multicpp_setup = \ + mkdir -p gopath/$*/src 2>/dev/null || true; \ + if ! test -d gopath/$*/src/swigtests; then \ + (cd gopath/$*/src && ln -s . swigtests); \ + fi + # Runs the testcase. run_testcase = \ if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \ @@ -121,8 +99,7 @@ run_testcase = \ cp gopath/src/$*/* gopath/src/swigtests/$*/; \ mkdir gopath/src/$*/runme 2>/dev/null || true; \ cp $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) gopath/src/$*/runme/runme.go; \ - (cd gopath/src/$*/runme && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o runme runme.go); \ - cp gopath/src/$*/runme/runme $*_runme; \ + (cd gopath/src/$*/runme && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o ../../../../$*_runme runme.go); \ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ fi @@ -143,8 +120,7 @@ run_testcase_cpp = \ cp gopath/src/$*/* gopath/src/swigtests/$*/; \ mkdir gopath/src/$*/runme 2>/dev/null || true; \ cp $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) gopath/src/$*/runme/runme.go; \ - (cd gopath/src/$*/runme && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o runme runme.go); \ - cp gopath/src/$*/runme/runme $*_runme; \ + (cd gopath/src/$*/runme && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o ../../../../$*_runme runme.go); \ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ fi @@ -164,7 +140,7 @@ run_multi_testcase = \ CGO_LDFLAGS="$(LDFLAGS) -lm"; \ export CGO_LDFLAGS; \ (cd gopath/$*/src/$* && \ - $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o ../../../../$*_runme) && \ + $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o ../../../../$*_runme) && \ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \ fi @@ -173,16 +149,18 @@ run_multi_testcase = \ clean: $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' go_clean - rm -f mod_a.go mod_a.gox mod_b.go mod_b.gox - rm -f imports_a.go imports_a.gox imports_b.go imports_b.gox rm -f clientdata_prop_a.go clientdata_prop_a.gox rm -f clientdata_prop_b.go clientdata_prop_b.gox + rm -f import_stl_a.go import_stl_a.gox + rm -f import_stl_b.go import_stl_b.gox + rm -f imports_a.go imports_a.gox imports_b.go imports_b.gox + rm -f mod_a.go mod_a.gox mod_b.go mod_b.gox rm -f multi_import_a.go multi_import_a.gox rm -f multi_import_b.go multi_import_b.gox - rm -rf go_subdir_import_a.go go_subdir_import_a.gox testdir + rm -f multi_import_d.go multi_import_d.gox rm -f packageoption_a.go packageoption_a.gox rm -f packageoption_b.go packageoption_b.gox rm -f packageoption_c.go packageoption_c.gox - rm -f import_stl_a.go import_stl_a.gox - rm -f import_stl_b.go import_stl_b.gox + rm -f template_typedef_cplx2.go template_typedef_cplx2.gox + rm -rf go_subdir_import_a.go go_subdir_import_a.gox testdir rm -rf gopath diff --git a/Examples/test-suite/go/argcargvtest_runme.go b/Examples/test-suite/go/argcargvtest_runme.go new file mode 100644 index 000000000..1bb1feb77 --- /dev/null +++ b/Examples/test-suite/go/argcargvtest_runme.go @@ -0,0 +1,55 @@ +package main + +import wrap "swigtests/argcargvtest" + +func main() { + largs := []string{"hi", "hola", "hello"} + if ri := wrap.Mainc(largs); ri != 3 { + panic(ri) + } + + targs := []string{"hi", "hola"} + if rs := wrap.Mainv(targs, 0); rs != "hi" { + panic(rs) + } + if rs := wrap.Mainv(targs, 1); rs != "hola" { + panic(rs) + } + if rs := wrap.Mainv(targs, 2); rs != "<<NULL>>" { + panic(rs) + } + +// For dynamically typed languages we test this throws an exception or similar +// at runtime, but for Go this doesn't even compile (but we can't easily +// test for that here). +// wrap.Mainv("hello", 1) + + wrap.InitializeApp(largs) + + // Check that an empty array works. + empty_args := []string{}; + if ri := wrap.Mainc(empty_args); ri != 0 { + panic(ri) + } + if rs := wrap.Mainv(empty_args, 0); rs != "<<NULL>>" { + panic(rs) + } + + // Check that empty strings are handled. + empty_string := []string{"hello", "", "world"}; + if ri := wrap.Mainc(empty_string); ri != 3 { + panic(ri) + } + if rs := wrap.Mainv(empty_string, 0); rs != "hello" { + panic(rs) + } + if rs := wrap.Mainv(empty_string, 1); rs != "" { + panic(rs) + } + if rs := wrap.Mainv(empty_string, 2); rs != "world" { + panic(rs) + } + if rs := wrap.Mainv(empty_string, 3); rs != "<<NULL>>" { + panic(rs) + } +} diff --git a/Examples/test-suite/go/catches_strings_runme.go b/Examples/test-suite/go/catches_strings_runme.go new file mode 100644 index 000000000..b31565c24 --- /dev/null +++ b/Examples/test-suite/go/catches_strings_runme.go @@ -0,0 +1,32 @@ +package main + +import "strings" +import . "swigtests/catches_strings" + +func main() { + { + exception_thrown := false + func() { + defer func() { + exception_thrown = strings.Index(recover().(string), "charstring message") == 0 + }() + StringsThrowerCharstring() + }() + if !exception_thrown { + panic(0) + } + } + + { + exception_thrown := false + func() { + defer func() { + exception_thrown = strings.Index(recover().(string), "stdstring message") == 0 + }() + StringsThrowerStdstring() + }() + if !exception_thrown { + panic(0) + } + } +} diff --git a/Examples/test-suite/go/class_case_runme.go b/Examples/test-suite/go/class_case_runme.go new file mode 100644 index 000000000..7d0870b47 --- /dev/null +++ b/Examples/test-suite/go/class_case_runme.go @@ -0,0 +1,12 @@ +package main + +import . "swigtests/class_case" + +func main() { + b2 := NewClassB2() + // This used to fail with: + // panic: interface conversion: interface {} is class_case.SwigcptrClassB2, not int + if Test2(b2) != 1 { + panic("Unexpected overload used") + } +} diff --git a/Examples/test-suite/go/cpp11_std_array_runme.go b/Examples/test-suite/go/cpp11_std_array_runme.go new file mode 100644 index 000000000..97b5df2ec --- /dev/null +++ b/Examples/test-suite/go/cpp11_std_array_runme.go @@ -0,0 +1,68 @@ +package main + +import ( + "fmt" + "swigtests/cpp11_std_array" +) + +func CompareContainers(actual cpp11_std_array.ArrayInt6, expected [6]int) error { + if int(actual.Size()) != len(expected) { + return fmt.Errorf("Sizes are different: %d %d", actual.Size(), len(expected)) + } + for i := 0; i < int(actual.Size()); i++ { + actualValue := actual.Get(i) + expectedValue := expected[i] + if actualValue != expectedValue { + return fmt.Errorf("Value is wrong for element %d. Expected %d got: %d", i, expectedValue, actualValue) + } + } + if actual.IsEmpty() { + return fmt.Errorf("ai should not be empty") + } + return nil +} + +func main() { + ai := cpp11_std_array.NewArrayInt6() + ps := [6]int{0, 0, 0, 0, 0, 0} + CompareContainers(ai, ps) + + vals := [6]int{10, 20, 30, 40, 50, 60} + for i := 0; i < len(vals); i++ { + ai.Set(i, vals[i]) + } + CompareContainers(ai, vals); + + // Check return + vals = [6]int{-2, -1, 0, 0, 1, 2} + CompareContainers(cpp11_std_array.ArrayOutVal(), vals); + CompareContainers(cpp11_std_array.ArrayOutConstRef(), vals); + CompareContainers(cpp11_std_array.ArrayOutRef(), vals); + CompareContainers(cpp11_std_array.ArrayOutPtr(), vals); + + // Check passing arguments + vals = [6]int{9, 8, 7, 6, 5, 4} + valsArrayInt6 := cpp11_std_array.NewArrayInt6() + for i := 0; i < len(vals); i++ { + valsArrayInt6.Set(i, vals[i]) + } + + ai = cpp11_std_array.ArrayInVal(valsArrayInt6); + CompareContainers(ai, vals); + + ai = cpp11_std_array.ArrayInConstRef(valsArrayInt6); + CompareContainers(ai, vals); + + ai = cpp11_std_array.NewArrayInt6(valsArrayInt6); + cpp11_std_array.ArrayInRef(ai); + CompareContainers(ai, vals); + + ai = cpp11_std_array.NewArrayInt6(valsArrayInt6); + cpp11_std_array.ArrayInPtr(ai); + CompareContainers(ai, vals); + + // Fill + ai.Fill(111) + vals = [6]int{111, 111, 111, 111, 111, 111} + CompareContainers(ai, vals); +} diff --git a/Examples/test-suite/go/friends_runme.go b/Examples/test-suite/go/friends_runme.go index b6b9e93f3..393d6f61e 100644 --- a/Examples/test-suite/go/friends_runme.go +++ b/Examples/test-suite/go/friends_runme.go @@ -27,24 +27,31 @@ func main() { panic(0) } - di := friends.NewD_d(2) + di := friends.NewD_i(2) dd := friends.NewD_d(3.3) // incredible template overloading working just fine - if friends.Get_val1(di).(float64) != 2 { + if friends.Get_val1(di).(int) != 2 { panic(0) } if friends.Get_val1(dd).(float64) != 3.3 { panic(0) } - friends.Set(di, 4.0) + friends.Set(di, 4) friends.Set(dd, 1.3) - if friends.Get_val1(di).(float64) != 4 { + if friends.Get_val1(di).(int) != 4 { panic(0) } if friends.Get_val1(dd).(float64) != 1.3 { panic(0) } + + if friends.Chum_blah() != 1234 { + panic(0) + } + if friends.Mate_blah() != 4321 { + panic(0) + } } diff --git a/Examples/test-suite/go/go_director_inout_runme.go b/Examples/test-suite/go/go_director_inout_runme.go index 171b3c223..6b68543a2 100644 --- a/Examples/test-suite/go/go_director_inout_runme.go +++ b/Examples/test-suite/go/go_director_inout_runme.go @@ -14,6 +14,35 @@ func (p *GoMyClass) Adjust(m map[string]interface{}) wrap.GoRetStruct { return wrap.GoRetStruct{s} } +func (p *GoMyClass) S1(s string) { + if s != "S1" { + panic(s) + } +} + +func (p *GoMyClass) S2(s *string) { + if *s != "S2" { + panic(s) + } + *s = "R2" +} + +func (p *GoMyClass) S3(s *string) { + if *s != "S3" { + panic(s) + } + *s = "R3" +} + +func (p *GoMyClass) S4(s []string) { + if s[0] != "T1" { + panic(s) + } + if s[1] != "T2" { + panic(s) + } +} + func main() { a := wrap.NewDirectorMyClass(&GoMyClass{}) m := map[string]interface{}{ @@ -24,6 +53,23 @@ func main() { panic(s) } + a.S1("S1") + str := "S2" + a.S2(&str) + if str != "R2" { + panic(str) + } + str = "S3" + a.S3(&str) + if str != "R3" { + panic(str) + } + + a.CallS4([]string{ "T1", "T2" }) + + a.S5(&str) + a.S5(nil) + a = wrap.NewDirectorMyClass(nil) s = a.Adjust(m) if s.Str != `{"first":"second"}` { diff --git a/Examples/test-suite/go/go_inout_runme.go b/Examples/test-suite/go/go_inout_runme.go index 2dc5b9908..981b7f2b3 100644 --- a/Examples/test-suite/go/go_inout_runme.go +++ b/Examples/test-suite/go/go_inout_runme.go @@ -50,4 +50,12 @@ func main() { fmt.Println("for c2.M got", pm, "want", want) panic(pm) } + + c1 := go_inout.NewC1() + c2.M2(c1) + c2.M2(nil) + + if !go_inout.Strings([]string{"1", "2"}) { + panic("Strings failed") + } } diff --git a/Examples/test-suite/go/li_constraints_runme.go b/Examples/test-suite/go/li_constraints_runme.go new file mode 100644 index 000000000..6dda260e4 --- /dev/null +++ b/Examples/test-suite/go/li_constraints_runme.go @@ -0,0 +1,70 @@ +package main + +import wrap "swigtests/li_constraints" +import "fmt"; + +func check_double(except bool, f func (float64), val float64, name string) { + actual := true + proper := false + func() { + defer func() { + r := recover(); + if r != nil { + actual = false + proper = fmt.Sprintf("%s", r) == fmt.Sprintf("Expected a %s value.", name) + } + }() + f(val); + }() + if actual { + if !except { + panic(fmt.Sprintf("function '%s' with %d should perform an exception", name, val)); + } + } else { + if except { + panic(fmt.Sprintf("function '%s' with %d should not perform an exception", name, val)); + } else if !proper { + panic(fmt.Sprintf("function '%s' with %d should perform a proper exception", name, val)); + } + } +} + +func main() { + check_double(true, wrap.Test_nonnegative, 10, "non-negative"); + check_double(true, wrap.Test_nonnegative, 0, "non-negative"); + check_double(false, wrap.Test_nonnegative, -10, "non-negative"); + + check_double(false, wrap.Test_nonpositive, 10, "non-positive"); + check_double(true, wrap.Test_nonpositive, 0, "non-positive"); + check_double(true, wrap.Test_nonpositive, -10, "non-positive"); + + check_double(true, wrap.Test_positive, 10, "positive"); + check_double(false, wrap.Test_positive, 0, "positive"); + check_double(false, wrap.Test_positive, -10, "positive"); + + check_double(false, wrap.Test_negative, 10, "negative"); + check_double(false, wrap.Test_negative, 0, "negative"); + check_double(true, wrap.Test_negative, -10, "negative"); + + check_double(true, wrap.Test_nonzero, 10, "nonzero"); + check_double(false, wrap.Test_nonzero, 0, "nonzero"); + check_double(true, wrap.Test_nonzero, -10, "nonzero"); + + have_exception := false + func() { + defer func() { + r := recover() + if r != nil { + have_exception = "Received a NULL pointer." == fmt.Sprintf("%s", r) + } + }() + // The NULL value + // We can not use Go `nil` as is it can not be convert to a uintptr value. + wrap.Test_nonnull(uintptr(0)); + }() + if !have_exception { + panic("test_nonnull should perform exception with 'null' value") + } + nonnull := wrap.Get_nonnull(); + wrap.Test_nonnull(nonnull); +} diff --git a/Examples/test-suite/go/smart_pointer_extend_runme.go b/Examples/test-suite/go/smart_pointer_extend_runme.go index f91c9ac99..e349be18a 100644 --- a/Examples/test-suite/go/smart_pointer_extend_runme.go +++ b/Examples/test-suite/go/smart_pointer_extend_runme.go @@ -22,6 +22,10 @@ func main() { panic(0) } + if d.Bar() != p.Bar() { + panic(0) + } + if CBaseHello() != p.Hello() { panic(0) } diff --git a/Examples/test-suite/go/special_variable_macros_runme.go b/Examples/test-suite/go/special_variable_macros_runme.go index 597c48748..13b451897 100644 --- a/Examples/test-suite/go/special_variable_macros_runme.go +++ b/Examples/test-suite/go/special_variable_macros_runme.go @@ -25,4 +25,10 @@ func main() { if special_variable_macros.TestJohn(special_variable_macros.NewPairIntBool(10, false)) != 123 { panic("test failed") } + if special_variable_macros.MakeStringInt("stringint", 999) != "stringint" { + panic("test failed") + } + if special_variable_macros.ProvideStringInt(999) != "1000" { + panic("test failed") + } } diff --git a/Examples/test-suite/go/typedef_inherit_runme.go b/Examples/test-suite/go/typedef_inherit_runme.go index f2dbb3263..eef3ef47a 100644 --- a/Examples/test-suite/go/typedef_inherit_runme.go +++ b/Examples/test-suite/go/typedef_inherit_runme.go @@ -28,4 +28,9 @@ func main() { if x != "Grok::blah" { panic(x) } + + x = d.Far() + if x != "Spam::far" { + panic(x) + } } diff --git a/Examples/test-suite/go/typemap_out_optimal_runme.go b/Examples/test-suite/go/typemap_out_optimal_runme.go index 0cccd97a6..646aa8ece 100644 --- a/Examples/test-suite/go/typemap_out_optimal_runme.go +++ b/Examples/test-suite/go/typemap_out_optimal_runme.go @@ -3,6 +3,7 @@ package main import . "swigtests/typemap_out_optimal" func main() { - SetXXDebug(false) + SetXXTrace(false) _ = XXCreate() + _ = XXCreateConst() } |