Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,193 @@
#######################################################################
# Makefile for Go test-suite
#######################################################################
LANGUAGE = go
GO = @GO@
GOGCC = @GOGCC@
GCCGO = @GCCGO@
GO1 = @GO1@
GO12 = @GO12@
GO13 = @GO13@
GO15 = @GO15@
GOC = @GOC@
GOVERSIONOPTION = @GOVERSIONOPTION@
host = @host@
SCRIPTSUFFIX = _runme.go
GOCOMPILEARG = `if $(GO15); then echo tool compile; elif $(GO1); then echo tool $(GOC:c=g); fi`
GOLD = `if $(GO15); then echo link; else echo $(GOC:c=l); fi`
GOTOOL = `if $(GO1) ; then echo go tool; fi`
GOPACK = `if $(GO1) ; then echo go tool pack; else echo gopack; fi`
GOOBJEXT = `if $(GO15); then echo o; else echo $(GOC:c=); fi`
OSXOLDGOLINKFLAGS = `if [ -n "\`$(GO) $(GOVERSIONOPTION) | grep -E 'go1($|.0|.1|.2|.3)'\`" ] && [ -n "\`echo $(host) | grep darwin\`" ]; then echo "-Wl,-U,__cgo_topofstack"; fi`
SO = @SO@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
abs_top_srcdir = @abs_top_srcdir@
CPP_TEST_CASES = \
go_inout \
go_director_inout
MULTI_CPP_TEST_CASES = \
go_subdir_import
include $(srcdir)/../common.mk
INCLUDES = -I$(abs_top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)
.SUFFIXES: .cpptest .ctest .multicpptest
# Rules for the different types of tests
%.cpptest:
$(setup)
+$(swig_and_compile_cpp)
$(run_testcase_cpp)
if ! $(GO15); then \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \
TARGET='$(TARGETPREFIX)$*$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' INTERFACE='$*.i' \
$(LANGUAGE)$(VARIANT)_cpp_nocgo && \
$(run_testcase_cpp); \
fi
%.ctest:
$(setup)
+$(swig_and_compile_c)
$(run_testcase)
if ! $(GO15); then \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CSRCS='$(CSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT)' NOLINK=true \
TARGET='$(TARGETPREFIX)$*$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' INTERFACE='$*.i' \
$(LANGUAGE)$(VARIANT)_nocgo && \
$(run_testcase); \
fi
%.multicpptest:
$(setup)
+$(swig_and_compile_multi_cpp)
$(run_multi_testcase)
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)
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" \
$(LANGUAGE)$(VARIANT)_cpp; \
done
$(run_multi_testcase)
go_subdir_import.multicpptest:
$(setup)
mkdir -p testdir/go_subdir_import/
mkdir -p gopath/src/testdir/go_subdir_import/
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
LIBS='$(LIBS)' INTERFACEPATH='$(SRCDIR)$(INTERFACEDIR)go_subdir_import_b.i' \
INCLUDES='$(INCLUDES)' SWIGOPT='$(SWIGOPT) -outdir .' NOLINK=true \
TARGET='$(TARGETPREFIX)go_subdir_import_b$(TARGETSUFFIX)' INTERFACEDIR='$(INTERFACEDIR)' \
INTERFACE='testdir/go_subdir_import/go_subdir_import_b.i' \
$(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" \
$(LANGUAGE)$(VARIANT)_cpp; \
done
if $(GOGCC); then \
cp gopath/src/testdir/go_subdir_import/go_subdir_import_b/go_subdir_import_b.a gopath/src/testdir/go_subdir_import/go_subdir_import_b.gox; \
cp gopath/src/testdir/go_subdir_import/go_subdir_import_b/go_subdir_import_b.a .; \
cp gopath/src/testdir/go_subdir_import/go_subdir_import_c/go_subdir_import_c.a gopath/src/testdir/go_subdir_import/go_subdir_import_c.gox; \
cp gopath/src/testdir/go_subdir_import/go_subdir_import_c/go_subdir_import_c.a testdir/go_subdir_import/; \
fi
$(run_multi_testcase)
# Runs the testcase.
run_testcase = \
if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GCCGO) -c -g -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.a; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS) $(OSXOLDGOLINKFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
fi && \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \
fi
run_testcase_cpp = \
if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GCCGO) -c -g -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.a -lstdc++; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS) $(OSXOLDGOLINKFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
fi && \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \
fi
run_multi_testcase = \
if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GCCGO) -c -g -I . -I gopath/src $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
files=`cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; \
$(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.a; done` -lstdc++; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS) $(OSXOLDGOLINKFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
fi && \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \
fi
%.clean:
@rm -rf $*.go $*_gc.c $*_wrap.* $*_runme $*.gox $*.a
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 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 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 -rf gopath
cvsignore:
@echo '*_gc.c *_wrap.* *.so *.dll *.exp *.lib'
@echo Makefile
@echo mod_a.go mod_b.go imports_a.go imports_b.go
@echo clientdata_prop_a.go clientdata_prop_b.go
@echo multi_import_a.go multi_import_b.go
@echo packageoption_a.go packageoption_b.go packageoption_c.go
@for i in ${CPP_TEST_CASES} ${C_TEST_CASES}; do echo $$i.go; done

View File

@@ -0,0 +1,10 @@
package main
import "./abstract_access"
func main() {
d := abstract_access.NewD()
if d.Do_x() != 1 {
panic(d.Do_x())
}
}

View File

@@ -0,0 +1,7 @@
package main
import "./abstract_typedef2"
func main() {
abstract_typedef2.NewA_UF()
}

View File

@@ -0,0 +1,11 @@
package main
import "./abstract_typedef"
func main() {
e := abstract_typedef.NewEngine()
a := abstract_typedef.NewA()
if !a.Write(e) {
panic("failed")
}
}

View File

@@ -0,0 +1,8 @@
package main
import "./abstract_virtual"
func main() {
abstract_virtual.NewD()
abstract_virtual.NewE()
}

View File

@@ -0,0 +1,41 @@
package main
import wrap "./argout"
func main() {
ip := wrap.New_intp()
wrap.Intp_assign(ip, 42)
if r := wrap.Incp(ip); r != 42 {
panic(r)
}
if r := wrap.Intp_value(ip); r != 43 {
panic(r)
}
p := wrap.New_intp()
wrap.Intp_assign(p, 2)
if r := wrap.Incp(p); r != 2 {
panic(r)
}
if r := wrap.Intp_value(p); r != 3 {
panic(r)
}
r := wrap.New_intp()
wrap.Intp_assign(r, 7)
if r := wrap.Incr(r); r != 7 {
panic(r)
}
if r := wrap.Intp_value(r); r != 8 {
panic(r)
}
tr := wrap.New_intp()
wrap.Intp_assign(tr, 4)
if r := wrap.Inctr(tr); r != 4 {
panic(r)
}
if r := wrap.Intp_value(tr); r != 5 {
panic(r)
}
}

View File

@@ -0,0 +1,26 @@
package main
import . "./array_member"
func main() {
f := NewFoo()
f.SetData(GetGlobal_data())
for i := 0; i < 8; i++ {
if Get_value(f.GetData(), i) != Get_value(GetGlobal_data(), i) {
panic("Bad array assignment")
}
}
for i := 0; i < 8; i++ {
Set_value(f.GetData(), i, -i)
}
SetGlobal_data(f.GetData())
for i := 0; i < 8; i++ {
if Get_value(f.GetData(), i) != Get_value(GetGlobal_data(), i) {
panic("Bad array assignment")
}
}
}

View File

@@ -0,0 +1,22 @@
package main
import . "./arrays_global"
func main() {
SetArray_i(GetArray_const_i())
GetBeginString_FIX44a()
GetBeginString_FIX44b()
GetBeginString_FIX44c()
GetBeginString_FIX44d()
GetBeginString_FIX44d()
SetBeginString_FIX44b("12\00045")
GetBeginString_FIX44b()
GetBeginString_FIX44d()
GetBeginString_FIX44e()
GetBeginString_FIX44f()
Test_a("hello", "hi", "chello", "chi")
Test_b("1234567", "hi")
}

View File

@@ -0,0 +1,25 @@
package main
import . "./char_binary"
func main() {
t := NewTest()
if t.Strlen("hile") != 4 {
print(t.Strlen("hile"))
panic("bad multi-arg typemap")
}
if t.Strlen("hil\000") != 4 {
panic("bad multi-arg typemap")
}
// creating a raw char*
pc := New_pchar(5)
Pchar_setitem(pc, 0, 'h')
Pchar_setitem(pc, 1, 'o')
Pchar_setitem(pc, 2, 'l')
Pchar_setitem(pc, 3, 'a')
Pchar_setitem(pc, 4, 0)
Delete_pchar(pc)
}

View File

@@ -0,0 +1,10 @@
package main
import "./class_ignore"
func main() {
a := class_ignore.NewBar()
if class_ignore.Do_blah(a) != "Bar::blah" {
panic(class_ignore.Do_blah(a))
}
}

View File

@@ -0,0 +1,11 @@
package main
import "./class_scope_weird"
func main() {
f := class_scope_weird.NewFoo()
class_scope_weird.NewFoo(3)
if f.Bar(3) != 3 {
panic(f.Bar(3))
}
}

View File

@@ -0,0 +1,29 @@
package main
import . "./compactdefaultargs"
func main() {
defaults1 := NewDefaults1(1000)
defaults1 = NewDefaults1()
if defaults1.Ret(10.0) != 10.0 {
println(1, defaults1.Ret(10.0))
panic(defaults1.Ret(10.0))
}
if defaults1.Ret() != -1.0 {
println(2, defaults1.Ret())
panic(defaults1.Ret())
}
defaults2 := NewDefaults2(1000)
defaults2 = NewDefaults2()
if defaults2.Ret(10.0) != 10.0 {
panic(defaults2.Ret(10.0))
}
if defaults2.Ret() != -1.0 {
panic(defaults2.Ret())
}
}

View File

@@ -0,0 +1,50 @@
package main
import (
"./constover"
"fmt"
"os"
)
func main() {
error := 0
p := constover.Test("test")
if p != "test" {
fmt.Println("test failed!")
error = 1
}
p = constover.Test_pconst("test")
if p != "test_pconst" {
fmt.Println("test_pconst failed!")
error = 1
}
f := constover.NewFoo()
p = f.Test("test")
if p != "test" {
fmt.Println("member-test failed!")
error = 1
}
p = f.Test_pconst("test")
if p != "test_pconst" {
fmt.Println("member-test_pconst failed!")
error = 1
}
p = f.Test_constm("test")
if p != "test_constmethod" {
fmt.Println("member-test_constm failed!")
error = 1
}
p = f.Test_pconstm("test")
if p != "test_pconstmethod" {
fmt.Println("member-test_pconstm failed!")
error = 1
}
os.Exit(error)
}

View File

@@ -0,0 +1,34 @@
package main
import . "./constructor_copy"
func main() {
f1 := NewFoo1(3)
f11 := NewFoo1(f1)
if f1.GetX() != f11.GetX() {
panic("f1/f11 x mismatch")
}
bi := NewBari(5)
bc := NewBari(bi)
if bi.GetX() != bc.GetX() {
panic("bi/bc x mismatch")
}
bd := NewBard(5)
good := false
func() {
defer func() {
if recover() != nil {
good = true
}
}()
NewBard(bd)
}()
if !good {
panic("bd !good")
}
}

View File

@@ -0,0 +1,208 @@
package main
import "./contract"
func main() {
contract.Test_preassert(1, 2)
contract.Test_postassert(3)
func() {
defer func() {
if recover() == nil {
panic("Failed! Postassertions are broken")
}
}()
contract.Test_postassert(-3)
}()
contract.Test_prepost(2, 3)
contract.Test_prepost(5, -4)
func() {
defer func() {
if recover() == nil {
panic("Failed! Preassertions are broken")
}
}()
contract.Test_prepost(-3, 4)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Postassertions are broken")
}
}()
contract.Test_prepost(4, -10)
}()
f := contract.NewFoo()
f.Test_preassert(4, 5)
func() {
defer func() {
if recover() == nil {
panic("Failed! Method preassertion.")
}
}()
f.Test_preassert(-2, 3)
}()
f.Test_postassert(4)
func() {
defer func() {
if recover() == nil {
panic("Failed! Method postassertion")
}
}()
f.Test_postassert(-4)
}()
f.Test_prepost(3, 4)
f.Test_prepost(4, -3)
func() {
defer func() {
if recover() == nil {
panic("Failed! Method preassertion.")
}
}()
f.Test_prepost(-4, 2)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Method postassertion.")
}
}()
f.Test_prepost(4, -10)
}()
contract.FooStest_prepost(4, 0)
func() {
defer func() {
if recover() == nil {
panic("Failed! Static method preassertion")
}
}()
contract.FooStest_prepost(-4, 2)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Static method posteassertion")
}
}()
contract.FooStest_prepost(4, -10)
}()
b := contract.NewBar()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion.")
}
}()
b.Test_prepost(2, -4)
}()
d := contract.NewD()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Foo(-1, 1, 1, 1, 1)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Foo(1, -1, 1, 1, 1)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Foo(1, 1, -1, 1, 1)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Foo(1, 1, 1, -1, 1)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Foo(1, 1, 1, 1, -1)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Bar(-1, 1, 1, 1, 1)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Bar(1, -1, 1, 1, 1)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Bar(1, 1, -1, 1, 1)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Bar(1, 1, 1, -1, 1)
}()
func() {
defer func() {
if recover() == nil {
panic("Failed! Inherited preassertion (D).")
}
}()
d.Bar(1, 1, 1, 1, -1)
}()
//Namespace
contract.NewMyClass(1)
func() {
defer func() {
if recover() == nil {
panic("Failed! constructor preassertion")
}
}()
contract.NewMyClass(0)
}()
}

View File

@@ -0,0 +1,171 @@
package main
import "fmt"
import . "./cpp11_strongly_typed_enumerations"
func enumCheck(actual int, expected int) int {
if actual != expected {
panic(fmt.Sprintf("Enum value mismatch. Expected: %d Actual: %d", expected, actual))
}
return expected + 1
}
func main() {
var val = 0
val = enumCheck(int(Enum1_Val1), val)
val = enumCheck(int(Enum1_Val2), val)
val = enumCheck(int(Enum1_Val3), 13)
val = enumCheck(int(Enum1_Val4), val)
val = enumCheck(int(Enum1_Val5a), 13)
val = enumCheck(int(Enum1_Val6a), val)
val = 0
val = enumCheck(int(Enum2_Val1), val)
val = enumCheck(int(Enum2_Val2), val)
val = enumCheck(int(Enum2_Val3), 23)
val = enumCheck(int(Enum2_Val4), val)
val = enumCheck(int(Enum2_Val5b), 23)
val = enumCheck(int(Enum2_Val6b), val)
val = 0
val = enumCheck(int(Val1), val)
val = enumCheck(int(Val2), val)
val = enumCheck(int(Val3), 43)
val = enumCheck(int(Val4), val)
val = 0
val = enumCheck(int(Enum5_Val1), val)
val = enumCheck(int(Enum5_Val2), val)
val = enumCheck(int(Enum5_Val3), 53)
val = enumCheck(int(Enum5_Val4), val)
val = 0
val = enumCheck(int(Enum6_Val1), val)
val = enumCheck(int(Enum6_Val2), val)
val = enumCheck(int(Enum6_Val3), 63)
val = enumCheck(int(Enum6_Val4), val)
val = 0
val = enumCheck(int(Enum7td_Val1), val)
val = enumCheck(int(Enum7td_Val2), val)
val = enumCheck(int(Enum7td_Val3), 73)
val = enumCheck(int(Enum7td_Val4), val)
val = 0
val = enumCheck(int(Enum8_Val1), val)
val = enumCheck(int(Enum8_Val2), val)
val = enumCheck(int(Enum8_Val3), 83)
val = enumCheck(int(Enum8_Val4), val)
val = 0
val = enumCheck(int(Enum10_Val1), val)
val = enumCheck(int(Enum10_Val2), val)
val = enumCheck(int(Enum10_Val3), 103)
val = enumCheck(int(Enum10_Val4), val)
val = 0
val = enumCheck(int(Class1Enum12_Val1), 1121)
val = enumCheck(int(Class1Enum12_Val2), 1122)
val = enumCheck(int(Class1Enum12_Val3), val)
val = enumCheck(int(Class1Enum12_Val4), val)
val = enumCheck(int(Class1Enum12_Val5c), 1121)
val = enumCheck(int(Class1Enum12_Val6c), val)
val = 0
val = enumCheck(int(Class1Val1), 1131)
val = enumCheck(int(Class1Val2), 1132)
val = enumCheck(int(Class1Val3), val)
val = enumCheck(int(Class1Val4), val)
val = enumCheck(int(Class1Val5d), 1131)
val = enumCheck(int(Class1Val6d), val)
val = 0
val = enumCheck(int(Class1Enum14_Val1), 1141)
val = enumCheck(int(Class1Enum14_Val2), 1142)
val = enumCheck(int(Class1Enum14_Val3), val)
val = enumCheck(int(Class1Enum14_Val4), val)
val = enumCheck(int(Class1Enum14_Val5e), 1141)
val = enumCheck(int(Class1Enum14_Val6e), val)
// Requires nested class support to work
//val = 0
//val = enumCheck(int(Class1Struct1Enum12_Val1), 3121)
//val = enumCheck(int(Class1Struct1Enum12_Val2), 3122)
//val = enumCheck(int(Class1Struct1Enum12_Val3), val)
//val = enumCheck(int(Class1Struct1Enum12_Val4), val)
//val = enumCheck(int(Class1Struct1Enum12_Val5f), 3121)
//val = enumCheck(int(Class1Struct1Enum12_Val6f), val)
//
//val = 0
//val = enumCheck(int(Class1Struct1Val1), 3131)
//val = enumCheck(int(Class1Struct1Val2), 3132)
//val = enumCheck(int(Class1Struct1Val3), val)
//val = enumCheck(int(Class1Struct1Val4), val)
//
//val = 0
//val = enumCheck(int(Class1Struct1Enum14_Val1), 3141)
//val = enumCheck(int(Class1Struct1Enum14_Val2), 3142)
//val = enumCheck(int(Class1Struct1Enum14_Val3), val)
//val = enumCheck(int(Class1Struct1Enum14_Val4), val)
//val = enumCheck(int(Class1Struct1Enum14_Val5g), 3141)
//val = enumCheck(int(Class1Struct1Enum14_Val6g), val)
val = 0
val = enumCheck(int(Class2Enum12_Val1), 2121)
val = enumCheck(int(Class2Enum12_Val2), 2122)
val = enumCheck(int(Class2Enum12_Val3), val)
val = enumCheck(int(Class2Enum12_Val4), val)
val = enumCheck(int(Class2Enum12_Val5h), 2121)
val = enumCheck(int(Class2Enum12_Val6h), val)
val = 0
val = enumCheck(int(Class2Val1), 2131)
val = enumCheck(int(Class2Val2), 2132)
val = enumCheck(int(Class2Val3), val)
val = enumCheck(int(Class2Val4), val)
val = enumCheck(int(Class2Val5i), 2131)
val = enumCheck(int(Class2Val6i), val)
val = 0
val = enumCheck(int(Class2Enum14_Val1), 2141)
val = enumCheck(int(Class2Enum14_Val2), 2142)
val = enumCheck(int(Class2Enum14_Val3), val)
val = enumCheck(int(Class2Enum14_Val4), val)
val = enumCheck(int(Class2Enum14_Val5j), 2141)
val = enumCheck(int(Class2Enum14_Val6j), val)
// Requires nested class support to work
//val = 0
//val = enumCheck(int(Class2Struct1Enum12_Val1), 4121)
//val = enumCheck(int(Class2Struct1Enum12_Val2), 4122)
//val = enumCheck(int(Class2Struct1Enum12_Val3), val)
//val = enumCheck(int(Class2Struct1Enum12_Val4), val)
//val = enumCheck(int(Class2Struct1Enum12_Val5k), 4121)
//val = enumCheck(int(Class2Struct1Enum12_Val6k), val)
//
//val = 0
//val = enumCheck(int(Class2Struct1Val1), 4131)
//val = enumCheck(int(Class2Struct1Val2), 4132)
//val = enumCheck(int(Class2Struct1Val3), val)
//val = enumCheck(int(Class2Struct1Val4), val)
//val = enumCheck(int(Class2Struct1Val5l), 4131)
//val = enumCheck(int(Class2Struct1Val6l), val)
//
//val = 0
//val = enumCheck(int(Class2Struct1Enum14_Val1), 4141)
//val = enumCheck(int(Class2Struct1Enum14_Val2), 4142)
//val = enumCheck(int(Class2Struct1Enum14_Val3), val)
//val = enumCheck(int(Class2Struct1Enum14_Val4), val)
//val = enumCheck(int(Class2Struct1Enum14_Val5m), 4141)
//val = enumCheck(int(Class2Struct1Enum14_Val6m), val)
class1 := NewClass1()
enumCheck(int(class1.Class1Test1(Enum1_Val5a)), 13)
enumCheck(int(class1.Class1Test2(Class1Enum12_Val5c)), 1121)
//enumCheck(int(class1.Class1Test3(Class1Struct1Enum12_Val5f)), 3121)
enumCheck(int(GlobalTest1(Enum1_Val5a)), 13)
enumCheck(int(GlobalTest2(Class1Enum12_Val5c)), 1121)
//enumCheck(int(GlobalTest3(Class1Struct1Enum12_Val5f)), 3121)
}

View File

@@ -0,0 +1,27 @@
package main
import "./cpp_enum"
func main() {
f := cpp_enum.NewFoo()
if f.GetHola() != cpp_enum.FooHello {
panic(f.GetHola())
}
f.SetHola(cpp_enum.FooHi)
if f.GetHola() != cpp_enum.FooHi {
panic(f.GetHola())
}
f.SetHola(cpp_enum.FooHello)
if f.GetHola() != cpp_enum.FooHello {
panic(f.GetHola())
}
cpp_enum.SetHi(cpp_enum.Hello)
if cpp_enum.GetHi() != cpp_enum.Hello {
panic(cpp_enum.Hi)
}
}

View File

@@ -0,0 +1,57 @@
// Note: This example assumes that namespaces are flattened
package main
import "./cpp_namespace"
func main() {
n := cpp_namespace.Fact(4)
if n != 24 {
panic("Bad return value!")
}
if cpp_namespace.GetFoo() != 42 {
panic("Bad variable value!")
}
t := cpp_namespace.NewTest()
if t.Method() != "Test::method" {
panic("Bad method return value!")
}
if cpp_namespace.Do_method(t) != "Test::method" {
panic("Bad return value!")
}
if cpp_namespace.Do_method2(t) != "Test::method" {
panic("Bad return value!")
}
cpp_namespace.Weird("hello", 4)
cpp_namespace.DeleteTest(t)
t2 := cpp_namespace.NewTest2()
t3 := cpp_namespace.NewTest3()
t4 := cpp_namespace.NewTest4()
t5 := cpp_namespace.NewTest5()
if cpp_namespace.Foo3(42) != 42 {
panic("Bad return value!")
}
if cpp_namespace.Do_method3(t2, 40) != "Test2::method" {
panic("Bad return value!")
}
if cpp_namespace.Do_method3(t3, 40) != "Test3::method" {
panic("Bad return value!")
}
if cpp_namespace.Do_method3(t4, 40) != "Test4::method" {
panic("Bad return value!")
}
if cpp_namespace.Do_method3(t5, 40) != "Test5::method" {
panic("Bad return value!")
}
}

View File

@@ -0,0 +1,13 @@
package main
import . "./cpp_static"
func main() {
StaticFunctionTestStatic_func()
StaticFunctionTestStatic_func_2(1)
StaticFunctionTestStatic_func_3(1, 2)
SetStaticMemberTestStatic_int(10)
if GetStaticMemberTestStatic_int() != 10 {
panic(GetStaticMemberTestStatic_int())
}
}

View File

@@ -0,0 +1,26 @@
package main
import "./default_args"
func main() {
if default_args.StaticsStaticmethod() != 60 {
panic(0)
}
if default_args.Cfunc1(1) != 2 {
panic(0)
}
if default_args.Cfunc2(1) != 3 {
panic(0)
}
if default_args.Cfunc3(1) != 4 {
panic(0)
}
f := default_args.NewFoo()
f.Newname()
f.Newname(1)
}

View File

@@ -0,0 +1,32 @@
package main
import dc "./default_constructor"
func main() {
a := dc.NewA()
dc.DeleteA(a)
aa := dc.NewAA()
dc.DeleteAA(aa)
cc := dc.NewCC()
dc.DeleteCC(cc)
e := dc.NewE()
dc.DeleteE(e)
ee := dc.NewEE()
dc.DeleteEE(ee)
f := dc.NewF()
f.Destroy()
g := dc.NewG()
dc.GDestroy(g)
gg := dc.NewGG()
dc.DeleteGG(gg)
dc.NewHH(1, 1)
}

View File

@@ -0,0 +1,10 @@
package main
import . "./director_alternating"
func main() {
id := GetBar().Id()
if id != IdFromGetBar() {
panic(id)
}
}

View File

@@ -0,0 +1,114 @@
package main
import "./director_basic"
type GoFoo struct{}
func (p *GoFoo) Ping() string {
return "GoFoo::ping()"
}
func f1() {
a := director_basic.NewDirectorFoo(&GoFoo{})
if a.Ping() != "GoFoo::ping()" {
panic(a.Ping())
}
if a.Pong() != "Foo::pong();GoFoo::ping()" {
panic(a.Pong())
}
b := director_basic.NewFoo()
if b.Ping() != "Foo::ping()" {
panic(b.Ping())
}
if b.Pong() != "Foo::pong();Foo::ping()" {
panic(b.Pong())
}
a1 := director_basic.NewA1(1)
if a1.Rg(2) != 2 {
panic(0)
}
}
type GoClass struct {
cmethod int
}
func (p *GoClass) Method(uintptr) {
p.cmethod = 7
}
func (p *GoClass) Vmethod(b director_basic.Bar) director_basic.Bar {
b.SetX(b.GetX() + 31)
return b
}
var bc director_basic.Bar
func f2() {
b := director_basic.NewBar(3)
d := director_basic.NewMyClass()
pc := &GoClass{0}
c := director_basic.NewDirectorMyClass(pc)
cc := director_basic.MyClassGet_self(c)
dd := director_basic.MyClassGet_self(d)
bc = cc.Cmethod(b)
bd := dd.Cmethod(b)
cc.Method(b.Swigcptr())
if pc.cmethod != 7 {
panic(pc.cmethod)
}
if bc.GetX() != 34 {
panic(bc.GetX())
}
if bd.GetX() != 16 {
panic(bd.GetX())
}
}
type GoMulti struct {
GoClass
}
func (p *GoMulti) Vmethod(b director_basic.Bar) director_basic.Bar {
b.SetX(b.GetX() + 31)
return b
}
func (p *GoMulti) Ping() string {
return "GoFoo::ping()"
}
func f3() {
for i := 0; i < 100; i++ {
p := &GoMulti{GoClass{0}}
gomult := director_basic.NewDirectorFoo(p)
gomult.Pong()
director_basic.DeleteDirectorFoo(gomult)
}
p := &GoMulti{GoClass{0}}
gomult := director_basic.NewDirectorMyClass(p)
fgomult := director_basic.NewDirectorFoo(gomult)
p1 := director_basic.FooGet_self(fgomult.(director_basic.Foo))
p2 := director_basic.MyClassGet_self(gomult.(director_basic.MyClass))
p1.Ping()
p2.Vmethod(bc)
}
func main() {
f1()
f2()
f3()
}

View File

@@ -0,0 +1,135 @@
package main
import "fmt"
import . "./director_classic"
type TargetLangPerson struct{} // From Person
func (p *TargetLangPerson) Id() string {
return "TargetLangPerson"
}
type TargetLangChild struct{} // Form Child
func (p *TargetLangChild) Id() string {
return "TargetLangChild"
}
type TargetLangGrandChild struct{} // From Grandchild
func (p *TargetLangGrandChild) Id() string {
return "TargetLangGrandChild"
}
// Semis - don't override id() in target language
type TargetLangSemiPerson struct{} // From Person
type TargetLangSemiChild struct{} // From Child
type TargetLangSemiGrandChild struct{} // From GrandChild
// Orphans - don't override id() in C++
type TargetLangOrphanPerson struct{} // From OrphanPerson
func (p *TargetLangOrphanPerson) Id() string {
return "TargetLangOrphanPerson"
}
type TargetLangOrphanChild struct{} // From OrphanChild
func (p *TargetLangOrphanChild) Id() string {
return "TargetLangOrphanChild"
}
func check(person Person, expected string) {
debug := false
// Normal target language polymorphic call
ret := person.Id()
if debug {
fmt.Println(ret)
}
if ret != expected {
panic("Failed. Received: " + ret + " Expected: " + expected)
}
// Polymorphic call from C++
caller := NewCaller()
caller.SetCallback(person)
ret = caller.Call()
if debug {
fmt.Println(ret)
}
if ret != expected {
panic("Failed. Received: " + ret + " Expected: " + expected)
}
// Polymorphic call of object created in target language and
// passed to C++ and back again
baseclass := caller.BaseClass()
ret = baseclass.Id()
if debug {
fmt.Println(ret)
}
if ret != expected {
panic("Failed. Received: " + ret + " Expected: " + expected)
}
caller.ResetCallback()
if debug {
fmt.Println("----------------------------------------")
}
}
func main() {
person := NewPerson()
check(person, "Person")
DeletePerson(person)
person = NewChild()
check(person, "Child")
DeletePerson(person)
person = NewGrandChild()
check(person, "GrandChild")
DeletePerson(person)
person = NewDirectorPerson(&TargetLangPerson{})
check(person, "TargetLangPerson")
DeleteDirectorPerson(person)
person = NewDirectorChild(&TargetLangChild{})
check(person, "TargetLangChild")
DeleteDirectorChild(person.(Child))
person = NewDirectorGrandChild(&TargetLangGrandChild{})
check(person, "TargetLangGrandChild")
DeleteDirectorGrandChild(person.(GrandChild))
// Semis - don't override id() in target language
person = NewDirectorPerson(&TargetLangSemiPerson{})
check(person, "Person")
DeleteDirectorPerson(person)
person = NewDirectorChild(&TargetLangSemiChild{})
check(person, "Child")
DeleteDirectorChild(person.(Child))
person = NewDirectorGrandChild(&TargetLangSemiGrandChild{})
check(person, "GrandChild")
DeleteDirectorGrandChild(person.(GrandChild))
// Orphans - don't override id() in C++
person = NewOrphanPerson()
check(person, "Person")
DeleteOrphanPerson(person.(OrphanPerson))
person = NewOrphanChild()
check(person, "Child")
DeleteOrphanChild(person.(OrphanChild))
person = NewDirectorOrphanPerson(&TargetLangOrphanPerson{})
check(person, "TargetLangOrphanPerson")
DeleteDirectorOrphanPerson(person.(OrphanPerson))
person = NewDirectorOrphanChild(&TargetLangOrphanChild{})
check(person, "TargetLangOrphanChild")
DeleteDirectorOrphanChild(person.(OrphanChild))
}

View File

@@ -0,0 +1,11 @@
package main
import . "./director_default"
func main() {
NewFoo()
NewFoo(1)
NewBar()
NewBar(1)
}

View File

@@ -0,0 +1,46 @@
package main
import "./director_detect"
type MyBar struct {
val int
} // From director_detect.Bar
func NewMyBar() director_detect.Bar {
return director_detect.NewDirectorBar(&MyBar{2})
}
func (p *MyBar) Get_value() int {
p.val++
return p.val
}
func (p *MyBar) Get_class() director_detect.A {
p.val++
return director_detect.NewA()
}
func (p *MyBar) Just_do_it() {
p.val++
}
func (p *MyBar) Clone() director_detect.Bar {
return director_detect.NewDirectorBar(&MyBar{p.val})
}
func main() {
b := NewMyBar()
f := b.Baseclass()
v := f.Get_value()
_ = f.Get_class()
f.Just_do_it()
c := b.DirectorInterface().(*MyBar).Clone()
vc := c.Get_value()
if (v != 3) || (b.DirectorInterface().(*MyBar).val != 5) || (vc != 6) {
panic("Bad virtual detection")
}
}

View File

@@ -0,0 +1,17 @@
package main
import "./director_enum"
type MyFoo struct{} // From director_enum.Foo
func (p *MyFoo) Say_hi(val director_enum.EnumDirectorHello) director_enum.EnumDirectorHello {
return val
}
func main() {
b := director_enum.NewFoo()
a := director_enum.NewDirectorFoo(&MyFoo{})
if a.Say_hi(director_enum.Hello) != b.Say_hello(director_enum.Hi) {
panic(0)
}
}

View File

@@ -0,0 +1,95 @@
package main
import . "./director_exception"
type Exception struct {
msg string
}
func NewException(a, b string) *Exception {
return &Exception{a + b}
}
type MyFoo struct{} // From Foo
func (p *MyFoo) Ping() string {
panic("MyFoo::ping() EXCEPTION")
}
type MyFoo2 struct{} // From Foo
func (p *MyFoo2) Ping() bool {
return true // should return a string
}
type MyFoo3 struct{} // From Foo
func (p *MyFoo3) Ping() string {
panic(NewException("foo", "bar"))
}
func main() {
// Check that the NotImplementedError raised by MyFoo.ping()
// is returned by MyFoo.pong().
ok := false
a := NewDirectorFoo(&MyFoo{})
b := Launder(a)
func() {
defer func() {
e := recover()
if e.(string) == "MyFoo::ping() EXCEPTION" {
ok = true
} else {
panic("Unexpected error message: " + e.(string))
}
}()
b.Pong()
}()
if !ok {
panic(0)
}
// Check that if the method has the wrong return type it is
// not called.
ok = false
a = NewDirectorFoo(&MyFoo2{})
b = Launder(a)
e := b.Pong()
if e != "Foo::pong();"+"Foo::ping()" {
panic(e)
}
// Check that the director can return an exception which
// requires two arguments to the constructor, without mangling
// it.
ok = false
a = NewDirectorFoo(&MyFoo3{})
b = Launder(a)
func() {
defer func() {
e := recover()
if e.(*Exception).msg == "foobar" {
ok = true
} else {
panic("Unexpected error message: " + e.(string))
}
}()
b.Pong()
}()
if !ok {
panic(0)
}
func() {
defer func() {
e := recover()
_ = e.(Exception2)
}()
panic(NewException2())
}()
func() {
defer func() {
e := recover()
_ = e.(Exception1)
}()
panic(NewException1())
}()
}

View File

@@ -0,0 +1,18 @@
// Test case from bug #1506850 "When threading is enabled, the
// interpreter will infinitely wait on a mutex the second time this
// type of extended method is called. Attached is an example program
// that waits on the mutex to be unlocked."
package main
import . "./director_extend"
func main() {
m := NewSpObject()
if m.Dummy() != 666 {
panic("1st call")
}
if m.Dummy() != 666 {
panic("2nd call")
}
}

View File

@@ -0,0 +1,37 @@
package main
import . "./director_finalizer"
type MyFoo struct{} // From Foo
func DeleteMyFoo(p Foo) {
p.OrStatus(2)
DeleteFoo(p)
}
func main() {
ResetStatus()
a := NewDirectorFoo(&MyFoo{})
DeleteMyFoo(a)
if GetStatus() != 3 {
panic(0)
}
ResetStatus()
a = NewDirectorFoo(&MyFoo{})
Launder(a)
if GetStatus() != 0 {
panic(0)
}
DeleteMyFoo(a)
if GetStatus() != 3 {
panic(0)
}
ResetStatus()
}

View File

@@ -0,0 +1,12 @@
package main
import . "./director_frob"
func main() {
foo := NewBravo()
s := foo.Abs_method()
if s != "Bravo::abs_method()" {
panic(s)
}
}

View File

@@ -0,0 +1,79 @@
package main
import . "./director_nested"
type A struct{} // From FooBar_int
func (p *A) Do_step() string {
return "A::do_step;"
}
func (p *A) Get_value() string {
return "A::get_value"
}
func f1() {
a := NewDirectorFooBar_int(&A{})
if a.Step() != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;" {
panic("Bad A virtual resolution")
}
}
type B struct{} // From FooBar_int
func (p *B) Do_advance() string {
return "B::do_advance;" + p.Do_step()
}
func (p *B) Do_step() string {
return "B::do_step;"
}
func (p *B) Get_value() int {
return 1
}
func f2() {
b := NewDirectorFooBar_int(&B{})
if b.Step() != "Bar::step;Foo::advance;B::do_advance;B::do_step;" {
panic("Bad B virtual resolution")
}
}
type C struct {
fbi FooBar_int
} // From FooBar_int
func (p *C) Do_advance() string {
return "C::do_advance;" + DirectorFooBar_intDo_advance(p.fbi)
}
func (p *C) Do_step() string {
return "C::do_step;"
}
func (p *C) Get_value() int {
return 2
}
func (p *C) Get_name() string {
return DirectorFooBar_intGet_name(p.fbi) + " hello"
}
func f3() {
m := &C{nil}
cc := NewDirectorFooBar_int(m)
m.fbi = cc
c := FooBar_intGet_self(cc)
c.Advance()
if c.Get_name() != "FooBar::get_name hello" {
panic(0)
}
if c.Name() != "FooBar::get_name hello" {
panic(0)
}
}
func main() {
f1()
f2()
f3()
}

View File

@@ -0,0 +1,49 @@
package main
import "fmt"
import "./director_profile"
type MyB struct{} // From director_profile.B
func (p *MyB) Vfi(a int) int {
return a + 3
}
func main() {
_ = director_profile.NewA()
myb := director_profile.NewDirectorB(&MyB{})
b := director_profile.BGet_self(myb)
fi := func(a int) int {
return b.Fi(a)
}
i := 50000
a := 1
for i != 0 {
a = fi(a) // 1
a = fi(a) // 2
a = fi(a) // 3
a = fi(a) // 4
a = fi(a) // 5
a = fi(a) // 6
a = fi(a) // 7
a = fi(a) // 8
a = fi(a) // 9
a = fi(a) // 10
a = fi(a) // 1
a = fi(a) // 2
a = fi(a) // 3
a = fi(a) // 4
a = fi(a) // 5
a = fi(a) // 6
a = fi(a) // 7
a = fi(a) // 8
a = fi(a) // 9
a = fi(a) // 20
i -= 1
}
if false {
fmt.Println(a)
}
}

View File

@@ -0,0 +1,73 @@
package main
import . "./director_protected"
type FooBar struct{} // From Bar
func (p *FooBar) Ping() string {
return "FooBar::ping();"
}
type FooBar2 struct{} // From Bar
func (p *FooBar2) Ping() string {
return "FooBar2::ping();"
}
func (p *FooBar2) Pang() string {
return "FooBar2::pang();"
}
type FooBar3 struct{} // From Bar
func (p *FooBar3) Cheer() string {
return "FooBar3::cheer();"
}
func main() {
b := NewBar()
f := b.Create()
fb := NewDirectorBar(&FooBar{})
fb2 := NewDirectorBar(&FooBar2{})
fb3 := NewDirectorBar(&FooBar3{})
s := fb.Used()
if s != "Foo::pang();Bar::pong();Foo::pong();FooBar::ping();" {
panic(0)
}
s = fb2.Used()
if s != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();" {
panic(0)
}
s = b.Pong()
if s != "Bar::pong();Foo::pong();Bar::ping();" {
panic(0)
}
s = f.Pong()
if s != "Bar::pong();Foo::pong();Bar::ping();" {
panic(0)
}
s = fb.Pong()
if s != "Bar::pong();Foo::pong();FooBar::ping();" {
panic(0)
}
s = fb3.DirectorInterface().(*FooBar3).Cheer()
if s != "FooBar3::cheer();" {
panic(s)
}
if fb2.Callping() != "FooBar2::ping();" {
panic("bad fb2.callping")
}
if fb2.Callcheer() != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();" {
panic("bad fb2.callcheer")
}
if fb3.Callping() != "Bar::ping();" {
panic("bad fb3.callping")
}
if fb3.Callcheer() != "FooBar3::cheer();" {
panic("bad fb3.callcheer")
}
}

View File

@@ -0,0 +1,39 @@
package main
import . "./director_string"
type B struct { // From A
abi A
smem string
}
func NewB(s string) A {
p := &B{nil, ""}
ret := NewDirectorA(p, s)
p.abi = ret
return ret
}
func (p *B) Get_first() string {
return DirectorAGet_first(p.abi) + " world!"
}
func (p *B) Process_text(s string) {
DirectorAProcess_text(p.abi, s)
p.smem = "hello"
}
func main() {
b := NewB("hello")
b.Get(0)
if b.Get_first() != "hello world!" {
panic(b.Get_first())
}
b.Call_process_func()
if b.DirectorInterface().(*B).smem != "hello" {
panic(b.DirectorInterface().(*B).smem)
}
}

View File

@@ -0,0 +1,21 @@
package main
import "./director_unroll"
type MyFoo struct{} // From director_unroll.Foo
func (p *MyFoo) Ping() string {
return "MyFoo::ping()"
}
func main() {
a := director_unroll.NewDirectorFoo(&MyFoo{})
b := director_unroll.NewBar()
b.Set(a)
c := b.Get()
if c.Ping() != "MyFoo::ping()" {
panic(c.Ping())
}
}

View File

@@ -0,0 +1,10 @@
package main
import . "./disown"
func main() {
a := NewA()
b := NewB()
b.Acquire(a)
}

View File

@@ -0,0 +1,16 @@
package main
import "./dynamic_cast"
func main() {
f := dynamic_cast.NewFoo()
b := dynamic_cast.NewBar()
_ = f.Blah()
y := b.Blah()
a := dynamic_cast.Do_test(dynamic_cast.FooToBar(y))
if a != "Bar::test" {
panic("Failed!!")
}
}

View File

@@ -0,0 +1,6 @@
package main
import _ "./empty_c"
func main() {
}

View File

@@ -0,0 +1,6 @@
package main
import _ "./empty"
func main() {
}

View File

@@ -0,0 +1,11 @@
package main
import "./enum_template"
func main() {
if enum_template.MakeETest() != 1 {
panic(0)
}
enum_template.TakeETest(0)
}

View File

@@ -0,0 +1,25 @@
package main
import "./enums"
func main() {
enums.Bar2(1)
enums.Bar3(1)
enums.Bar1(1)
if enums.GetEnumInstance() != 2 {
panic(0)
}
if enums.GetSlap() != 10 {
panic(0)
}
if enums.GetMine() != 11 {
panic(0)
}
if enums.GetThigh() != 12 {
panic(0)
}
}

View File

@@ -0,0 +1,58 @@
package main
import "strings"
import . "./exception_order"
func main() {
a := NewA()
func() {
defer func() {
e := recover()
if strings.Index(e.(string), "E1") == -1 {
panic(e.(string))
}
}()
a.Foo()
}()
func() {
defer func() {
e := recover()
if strings.Index(e.(string), "E2") == -1 {
panic(e.(string))
}
}()
a.Bar()
}()
func() {
defer func() {
e := recover()
if e.(string) != "postcatch unknown" {
panic("bad exception order")
}
}()
a.Foobar()
}()
func() {
defer func() {
e := recover()
if strings.Index(e.(string), "E1") == -1 {
panic(e.(string))
}
}()
a.Barfoo(1)
}()
func() {
defer func() {
e := recover()
if strings.Index(e.(string), "E2") == -1 {
panic(e.(string))
}
}()
a.Barfoo(2)
}()
}

View File

@@ -0,0 +1,47 @@
package main
import "./extend_placement"
func main() {
foo := extend_placement.NewFoo()
foo = extend_placement.NewFoo(1)
foo = extend_placement.NewFoo(1, 1)
foo.Spam()
foo.Spam("hello")
foo.Spam(1)
foo.Spam(1, 1)
foo.Spam(1, 1, 1)
foo.Spam(extend_placement.NewFoo())
foo.Spam(extend_placement.NewFoo(), 1.0)
bar := extend_placement.NewBar()
bar = extend_placement.NewBar(1)
bar.Spam()
bar.Spam("hello")
bar.Spam(1)
bar.Spam(1, 1)
bar.Spam(1, 1, 1)
bar.Spam(extend_placement.NewBar())
bar.Spam(extend_placement.NewBar(), 1.0)
footi := extend_placement.NewFooTi()
footi = extend_placement.NewFooTi(1)
footi = extend_placement.NewFooTi(1, 1)
footi.Spam()
footi.Spam("hello")
footi.Spam(1)
footi.Spam(1, 1)
footi.Spam(1, 1, 1)
footi.Spam(extend_placement.NewFoo())
footi.Spam(extend_placement.NewFoo(), 1.0)
barti := extend_placement.NewBarTi()
barti = extend_placement.NewBarTi(1)
barti.Spam()
barti.Spam("hello")
barti.Spam(1)
barti.Spam(1, 1)
barti.Spam(1, 1, 1)
barti.Spam(extend_placement.NewBar())
barti.Spam(extend_placement.NewBar(), 1.0)
}

View File

@@ -0,0 +1,14 @@
package main
import . "./extend_template_ns"
func main() {
f := NewFoo_One()
if f.Test1(37) != 37 {
panic(0)
}
if f.Test2(42) != 42 {
panic(0)
}
}

View File

@@ -0,0 +1,14 @@
package main
import "./extend_template"
func main() {
f := extend_template.NewFoo_0()
if f.Test1(37) != 37 {
panic(0)
}
if f.Test2(42) != 42 {
panic(0)
}
}

View File

@@ -0,0 +1,9 @@
package main
import . "./extend_variable"
func main() {
if FooBar != 42 {
panic(0)
}
}

View File

@@ -0,0 +1,7 @@
package main
import "./extern_c"
func main() {
extern_c.RealFunction(2)
}

View File

@@ -0,0 +1,50 @@
package main
import "./friends"
func main() {
a := friends.NewA(2)
if friends.Get_val1(a).(int) != 2 {
panic(0)
}
if friends.Get_val2(a) != 4 {
panic(0)
}
if friends.Get_val3(a) != 6 {
panic(0)
}
// nice overload working fine
if friends.Get_val1(1, 2, 3).(int) != 1 {
panic(0)
}
b := friends.NewB(3)
// David's case
if friends.Mix(a, b) != 5 {
panic(0)
}
di := friends.NewD_d(2)
dd := friends.NewD_d(3.3)
// incredible template overloading working just fine
if friends.Get_val1(di).(float64) != 2 {
panic(0)
}
if friends.Get_val1(dd).(float64) != 3.3 {
panic(0)
}
friends.Set(di, 4.0)
friends.Set(dd, 1.3)
if friends.Get_val1(di).(float64) != 4 {
panic(0)
}
if friends.Get_val1(dd).(float64) != 1.3 {
panic(0)
}
}

View File

@@ -0,0 +1,13 @@
package main
import . "./fvirtual"
func main() {
sw := NewNodeSwitch()
n := NewNode()
i := sw.AddChild(n)
if i != 2 {
panic("addChild")
}
}

View File

@@ -0,0 +1,8 @@
package main
import . "./global_ns_arg"
func main() {
Foo(1)
Bar_fn()
}

View File

@@ -0,0 +1,32 @@
package main
import (
wrap "./go_director_inout"
)
type GoMyClass struct {}
func (p *GoMyClass) Adjust(m map[string]interface{}) wrap.GoRetStruct {
s := ""
for k, v := range m {
s += k + "," + v.(string) + ";"
}
return wrap.GoRetStruct{s}
}
func main() {
a := wrap.NewDirectorMyClass(&GoMyClass{})
m := map[string]interface{}{
"first": "second",
}
s := a.Adjust(m)
if s.Str != "first,second;" {
panic(s)
}
a = wrap.NewDirectorMyClass(nil)
s = a.Adjust(m)
if s.Str != `{"first":"second"}` {
panic(s.Str)
}
}

View File

@@ -0,0 +1,53 @@
package main
import (
"encoding/json"
"fmt"
"reflect"
"./go_inout"
)
type S struct {
A int
B string
C float64
}
func (p *S) MarshalJSON() ([]byte, error) {
return json.Marshal(*p)
}
func main() {
v := &S{12, "hi", 34.5}
m := go_inout.Same(v)
want := map[string]interface{}{
// The type of A changes from int to float64 because
// JSON has no ints.
"A": float64(12),
"B": "hi",
"C": 34.5,
}
if !reflect.DeepEqual(m, want) {
fmt.Println("got", m, "want", want)
panic(m)
}
a := []string{"a", "bc", "def"}
go_inout.DoubleArray(&a)
dwant := []string{"a", "bc", "def", "aa", "bcbc", "defdef"}
if !reflect.DeepEqual(a, dwant) {
fmt.Println("got", a, "want", dwant)
panic(a)
}
c2 := go_inout.NewC2()
pm := c2.M()
want = map[string]interface{}{
"ID": float64(1),
}
if !reflect.DeepEqual(*pm, want) {
fmt.Println("for c2.M got", pm, "want", want)
panic(pm)
}
}

View File

@@ -0,0 +1,16 @@
package main
import (
"go_subdir_import_a"
"testdir/go_subdir_import/go_subdir_import_b"
"testdir/go_subdir_import/go_subdir_import_c"
)
func main() {
b := go_subdir_import_b.NewObjB();
c := go_subdir_import_c.NewObjC();
v := go_subdir_import_a.AddFive(b, c)
if v != 50 {
panic(0)
}
}

View File

@@ -0,0 +1,19 @@
package main
import "./grouping"
func main() {
x := grouping.Test1(42)
if x != 42 {
panic(0)
}
grouping.Test2(42)
x = grouping.Do_unary(37, grouping.NEGATE)
if x != -37 {
panic(0)
}
grouping.SetTest3(42)
}

View File

@@ -0,0 +1,12 @@
package main
import . "./import_nomodule"
func main() {
f := Create_Foo()
Test1(f, 42)
Delete_Foo(f)
b := NewBar()
Test1(b, 37)
}

View File

@@ -0,0 +1,17 @@
// This is the import runtime testcase.
package main
import "imports_b"
import "imports_a"
func main() {
x := imports_b.NewB()
x.Hello()
_ = imports_a.NewA()
c := imports_b.NewC()
_ = c.Get_a(c)
_ = c.Get_a_type(c)
}

View File

@@ -0,0 +1,18 @@
package main
import "./inctest"
func main() {
inctest.NewA()
inctest.NewB()
// Check the import in subdirectory worked
if inctest.Importtest1(5) != 15 {
panic("import test 1 failed")
}
a := []byte("black")
if inctest.Importtest2(string(a)) != "white" {
panic("import test 2 failed")
}
}

View File

@@ -0,0 +1,15 @@
package main
import wrap "./inherit_member"
func main() {
s := wrap.NewChild()
s.SetPvar("p")
s.SetCvar("c")
if s.GetPvar() != "p" {
panic(s.GetPvar())
}
if s.GetCvar() != "c" {
panic(s.GetCvar())
}
}

View File

@@ -0,0 +1,26 @@
package main
import "./inherit_missing"
func main() {
a := inherit_missing.New_Foo()
b := inherit_missing.NewBar()
c := inherit_missing.NewSpam()
x := inherit_missing.Do_blah(a)
if x != "Foo::blah" {
panic(x)
}
x = inherit_missing.Do_blah(b)
if x != "Bar::blah" {
panic(x)
}
x = inherit_missing.Do_blah(c)
if x != "Spam::blah" {
panic(x)
}
inherit_missing.Delete_Foo(a)
}

View File

@@ -0,0 +1,14 @@
package main
import . "./input"
func main() {
f := NewFoo()
if f.Foo(2) != 4 {
panic(0)
}
if Sfoo("Hello") != "Hello world" {
panic(0)
}
}

View File

@@ -0,0 +1,8 @@
package main
import "./keyword_rename_c"
func main() {
keyword_rename_c.Xgo(1)
keyword_rename_c.Xchan(1)
}

View File

@@ -0,0 +1,8 @@
package main
import "./keyword_rename"
func main() {
keyword_rename.Xgo(1)
keyword_rename.Xchan(1)
}

View File

@@ -0,0 +1,90 @@
package main
import "./li_attribute"
func main() {
aa := li_attribute.NewA(1, 2, 3)
if aa.GetA() != 1 {
panic(0)
}
aa.SetA(3)
if aa.GetA() != 3 {
panic(aa.GetA())
}
if aa.GetB() != 2 {
panic(aa.GetB())
}
aa.SetB(5)
if aa.GetB() != 5 {
panic(0)
}
if aa.GetD() != aa.GetB() {
panic(0)
}
if aa.GetC() != 3 {
panic(0)
}
pi := li_attribute.NewParam_i(7)
if pi.GetValue() != 7 {
panic(0)
}
pi.SetValue(3)
if pi.GetValue() != 3 {
panic(0)
}
b := li_attribute.NewB(aa)
if b.GetA().GetC() != 3 {
panic(0)
}
// class/struct attribute with get/set methods using
// return/pass by reference
myFoo := li_attribute.NewMyFoo()
myFoo.SetX(8)
myClass := li_attribute.NewMyClass()
myClass.SetFoo(myFoo)
if myClass.GetFoo().GetX() != 8 {
panic(0)
}
// class/struct attribute with get/set methods using
// return/pass by value
myClassVal := li_attribute.NewMyClassVal()
if myClassVal.GetReadWriteFoo().GetX() != -1 {
panic(0)
}
if myClassVal.GetReadOnlyFoo().GetX() != -1 {
panic(0)
}
myClassVal.SetReadWriteFoo(myFoo)
if myClassVal.GetReadWriteFoo().GetX() != 8 {
panic(0)
}
if myClassVal.GetReadOnlyFoo().GetX() != 8 {
panic(0)
}
// string attribute with get/set methods using return/pass by
// value
myStringyClass := li_attribute.NewMyStringyClass("initial string")
if myStringyClass.GetReadWriteString() != "initial string" {
panic(0)
}
if myStringyClass.GetReadOnlyString() != "initial string" {
panic(0)
}
myStringyClass.SetReadWriteString("changed string")
if myStringyClass.GetReadWriteString() != "changed string" {
panic(0)
}
if myStringyClass.GetReadOnlyString() != "changed string" {
panic(0)
}
}

View File

@@ -0,0 +1,14 @@
package main
import . "./li_carrays_cpp"
func main() {
d := NewDoubleArray(10)
d.Setitem(0, 7)
d.Setitem(5, d.Getitem(0)+3)
if d.Getitem(5)+d.Getitem(0) != 17 {
panic(0)
}
}

View File

@@ -0,0 +1,14 @@
package main
import . "./li_carrays"
func main() {
d := NewDoubleArray(10)
d.Setitem(0, 7)
d.Setitem(5, d.Getitem(0)+3)
if d.Getitem(5)+d.Getitem(0) != 17 {
panic(0)
}
}

View File

@@ -0,0 +1,13 @@
package main
import . "./li_cdata_cpp"
func main() {
s := "ABC abc"
m := Malloc(256)
Memmove(m, s, len(s))
ss := Cdata(m, 7)
if string(ss) != "ABC abc" {
panic("failed")
}
}

View File

@@ -0,0 +1,13 @@
package main
import . "./li_cdata"
func main() {
s := "ABC abc"
m := Malloc(256)
Memmove(m, s, len(s))
ss := Cdata(m, 7)
if string(ss) != "ABC abc" {
panic("failed")
}
}

View File

@@ -0,0 +1,25 @@
package main
import . "./li_cmalloc"
func main() {
p := Malloc_int()
Free_int(p)
ok := false
func() {
defer func() {
if recover() != nil {
ok = true
}
}()
p = Calloc_int(-1)
if p == nil {
ok = true
}
Free_int(p)
}()
if !ok {
panic(0)
}
}

View File

@@ -0,0 +1,14 @@
package main
import . "./li_cpointer_cpp"
func main() {
p := New_intp()
Intp_assign(p, 3)
if Intp_value(p) != 3 {
panic(0)
}
Delete_intp(p)
}

View File

@@ -0,0 +1,14 @@
package main
import . "./li_cpointer"
func main() {
p := New_intp()
Intp_assign(p, 3)
if Intp_value(p) != 3 {
panic(0)
}
Delete_intp(p)
}

View File

@@ -0,0 +1,30 @@
package main
import "./li_std_map"
func main() {
a1 := li_std_map.NewA(3)
a2 := li_std_map.NewA(7)
_ = li_std_map.NewPairii(1, 2)
p1 := li_std_map.NewPairA(1, a1)
m := li_std_map.NewMapA()
m.Set(1, a1)
m.Set(2, a2)
_ = li_std_map.P_identa(p1)
_ = li_std_map.M_identa(m)
m = li_std_map.NewMapA()
m.Set(1, a1)
m.Set(2, a2)
mii := li_std_map.NewIntIntMap()
mii.Set(1, 1)
mii.Set(1, 2)
if mii.Get(1) != 2 {
panic(0)
}
}

View File

@@ -0,0 +1,19 @@
package main
import . "./li_std_vector_ptr"
import "fmt"
func check(val1 int, val2 int) {
if val1 != val2 {
panic(fmt.Sprintf("Values are not the same %d %d", val1, val2))
}
}
func main() {
ip1 := MakeIntPtr(11)
ip2 := MakeIntPtr(22)
vi := NewIntPtrVector()
vi.Add(ip1)
vi.Add(ip2)
check(GetValueFromVector(vi, 0), 11)
check(GetValueFromVector(vi, 1), 22)
}

View File

@@ -0,0 +1,49 @@
// Example using pointers to member functions
package main
import "fmt"
import . "./member_pointer"
func check(what string, expected float64, actual float64) {
if expected != actual {
panic(fmt.Sprintf("Failed: %s Expected: %f Actual; %f", what, expected, actual))
}
}
func main() {
// Get the pointers
area_pt := Areapt()
perim_pt := Perimeterpt()
// Create some objects
s := NewSquare(10)
// Do some calculations
check("Square area ", 100.0, Do_op(s, area_pt))
check("Square perim", 40.0, Do_op(s, perim_pt))
_ = GetAreavar()
_ = GetPerimetervar()
// Try the variables
check("Square area ", 100.0, Do_op(s, GetAreavar()))
check("Square perim", 40.0, Do_op(s, GetPerimetervar()))
// Modify one of the variables
SetAreavar(perim_pt)
check("Square perimeter", 40.0, Do_op(s, GetAreavar()))
// Try the constants
_ = AREAPT
_ = PERIMPT
_ = NULLPT
check("Square area ", 100.0, Do_op(s, AREAPT))
check("Square perim", 40.0, Do_op(s, PERIMPT))
}

View File

@@ -0,0 +1,11 @@
package main
import "./memberin_extend_c"
func main() {
t := memberin_extend_c.NewPerson()
t.SetName("Fred Bloggs")
if t.GetName() != "FRED BLOGGS" {
panic("name wrong")
}
}

View File

@@ -0,0 +1,82 @@
package main
import "fmt"
import "./minherit"
func main() {
a := minherit.NewFoo()
b := minherit.NewBar()
c := minherit.NewFooBar()
d := minherit.NewSpam()
if a.Xget() != 1 {
panic("1 Bad attribute value")
}
if b.Yget() != 2 {
panic("2 Bad attribute value")
}
if c.Xget() != 1 || c.Yget() != 2 || c.Zget() != 3 {
panic("3 Bad attribute value")
}
if d.Xget() != 1 || d.Yget() != 2 || d.Zget() != 3 || d.Wget() != 4 {
panic("4 Bad attribute value")
}
if minherit.Xget(a) != 1 {
panic(fmt.Sprintf("5 Bad attribute value %d", minherit.Xget(a)))
}
if minherit.Yget(b) != 2 {
panic(fmt.Sprintf("6 Bad attribute value %d", minherit.Yget(b)))
}
if minherit.Xget(c) != 1 || minherit.Yget(c.SwigGetBar()) != 2 || minherit.Zget(c) != 3 {
panic(fmt.Sprintf("7 Bad attribute value %d %d %d", minherit.Xget(c), minherit.Yget(c.SwigGetBar()), minherit.Zget(c)))
}
if minherit.Xget(d) != 1 || minherit.Yget(d.SwigGetBar()) != 2 || minherit.Zget(d) != 3 || minherit.Wget(d) != 4 {
panic(fmt.Sprintf("8 Bad attribute value %d %d %d %d", minherit.Xget(d), minherit.Yget(d.SwigGetBar()), minherit.Zget(d), minherit.Wget(d)))
}
// Cleanse all of the pointers and see what happens
aa := minherit.ToFooPtr(a)
bb := minherit.ToBarPtr(b)
cc := minherit.ToFooBarPtr(c)
dd := minherit.ToSpamPtr(d)
if aa.Xget() != 1 {
panic("9 Bad attribute value")
}
if bb.Yget() != 2 {
panic("10 Bad attribute value")
}
if cc.Xget() != 1 || cc.Yget() != 2 || cc.Zget() != 3 {
panic("11 Bad attribute value")
}
if dd.Xget() != 1 || dd.Yget() != 2 || dd.Zget() != 3 || dd.Wget() != 4 {
panic("12 Bad attribute value")
}
if minherit.Xget(aa) != 1 {
panic(fmt.Sprintf("13 Bad attribute value %d", minherit.Xget(aa)))
}
if minherit.Yget(bb) != 2 {
panic(fmt.Sprintf("14 Bad attribute value %d", minherit.Yget(bb)))
}
if minherit.Xget(cc) != 1 || minherit.Yget(cc.SwigGetBar()) != 2 || minherit.Zget(cc) != 3 {
panic(fmt.Sprintf("15 Bad attribute value %d %d %d", minherit.Xget(cc), minherit.Yget(cc.SwigGetBar()), minherit.Zget(cc)))
}
if minherit.Xget(dd) != 1 || minherit.Yget(dd.SwigGetBar()) != 2 || minherit.Zget(dd) != 3 || minherit.Wget(dd) != 4 {
panic(fmt.Sprintf("16 Bad attribute value %d %d %d %d", minherit.Xget(dd), minherit.Yget(dd.SwigGetBar()), minherit.Zget(dd), minherit.Wget(dd)))
}
}

View File

@@ -0,0 +1,10 @@
package main
import "mod_a"
import "mod_b"
func main() {
c := mod_b.NewC()
d := mod_b.NewD()
d.DoSomething(mod_a.SwigcptrA(c.Swigcptr()))
}

View File

@@ -0,0 +1,29 @@
package main
import "multi_import_a"
import "multi_import_b"
func main() {
x := multi_import_b.NewXXX()
if x.Testx() != 0 {
panic(0)
}
y := multi_import_b.NewYYY()
if y.Testx() != 0 {
panic(0)
}
if y.Testy() != 1 {
panic(0)
}
z := multi_import_a.NewZZZ()
if z.Testx() != 0 {
println("z.Testx", z.Testx(), z.Testz())
panic(0)
}
if z.Testz() != 2 {
println("z.Testz", z.Testz())
panic(0)
}
}

View File

@@ -0,0 +1,19 @@
package main
import . "./namespace_class"
func main() {
EulerT3DToFrame(1, 1, 1)
_ = NewBooT_i()
_ = NewBooT_H()
f1 := NewFooT_i()
f1.Quack(1)
f2 := NewFooT_d()
f2.Moo(1)
f3 := NewFooT_H()
f3.Foo(Hi)
}

View File

@@ -0,0 +1,116 @@
package main
import . "./namespace_typemap"
func main() {
if Stest1("hello") != "hello" {
panic(0)
}
if Stest2("hello") != "hello" {
panic(0)
}
if Stest3("hello") != "hello" {
panic(0)
}
if Stest4("hello") != "hello" {
panic(0)
}
if Stest5("hello") != "hello" {
panic(0)
}
if Stest6("hello") != "hello" {
panic(0)
}
if Stest7("hello") != "hello" {
panic(0)
}
if Stest8("hello") != "hello" {
panic(0)
}
if Stest9("hello") != "hello" {
panic(0)
}
if Stest10("hello") != "hello" {
panic(0)
}
if Stest11("hello") != "hello" {
panic(0)
}
if Stest12("hello") != "hello" {
panic(0)
}
c := complex(2, 3)
r := real(c)
if Ctest1(c) != r {
println(Ctest1(c))
panic(Ctest1(c))
}
if Ctest2(c) != r {
panic(0)
}
if Ctest3(c) != r {
panic(0)
}
if Ctest4(c) != r {
panic(0)
}
if Ctest5(c) != r {
panic(0)
}
if Ctest6(c) != r {
panic(0)
}
if Ctest7(c) != r {
panic(0)
}
if Ctest8(c) != r {
panic(0)
}
if Ctest9(c) != r {
panic(0)
}
if Ctest10(c) != r {
panic(0)
}
if Ctest11(c) != r {
panic(0)
}
if Ctest12(c) != r {
panic(0)
}
ok := false
func() {
defer func() {
ok = recover() != nil
}()
Ttest1(-14)
}()
if !ok {
panic(0)
}
}

View File

@@ -0,0 +1,7 @@
package main
import "./namespace_virtual_method"
func main() {
_ = namespace_virtual_method.NewSpam()
}

View File

@@ -0,0 +1,17 @@
package main
import . "./naturalvar"
func main() {
f := NewFoo()
b := NewBar()
b.SetF(f)
SetS("hello")
b.SetS("hello")
if b.GetS() != GetS() {
panic(0)
}
}

View File

@@ -0,0 +1,19 @@
package main
import . "./nested_workaround"
func main() {
inner := NewInner(5)
outer := NewOuter()
newInner := outer.DoubleInnerValue(inner)
if newInner.GetValue() != 10 {
panic(0)
}
outer = NewOuter()
inner = outer.CreateInner(3)
newInner = outer.DoubleInnerValue(inner)
if outer.GetInnerValue(newInner) != 6 {
panic(0)
}
}

View File

@@ -0,0 +1,62 @@
package main
import . "./overload_complicated"
func main() {
var pInt *int
// Check the correct constructors are available
p := NewPop(pInt)
p = NewPop(pInt, false)
// Check overloaded in const only and pointers/references
// which target languages cannot disambiguate
if p.Hip(false) != 701 {
panic("Test 1 failed")
}
if p.Hip(pInt) != 702 {
panic("Test 2 failed")
}
// Reverse the order for the above
if p.Hop(pInt) != 805 {
panic("Test 3 failed")
}
if p.Hop(false) != 801 {
panic("Test 4 failed")
}
// Few more variations and order shuffled
if p.Pop(false) != 901 {
panic("Test 5 failed")
}
if p.Pop(pInt) != 902 {
panic("Test 6 failed")
}
if p.Pop() != 905 {
panic("Test 7 failed")
}
// Overload on const only
if p.Bop(pInt) != 1001 {
panic("Test 8 failed")
}
if p.Bip(pInt) != 2001 {
panic("Test 9 failed")
}
// Globals
if Muzak(false) != 3001 {
panic("Test 10 failed")
}
if Muzak(pInt) != 3002 {
panic("Test 11 failed")
}
}

View File

@@ -0,0 +1,8 @@
package main
import . "./overload_copy"
func main() {
f := NewFoo()
_ = NewFoo(f)
}

View File

@@ -0,0 +1,33 @@
package main
import "./overload_extend2"
func main() {
f := overload_extend2.NewFoo()
if f.Test(3) != 1 {
panic(0)
}
if f.Test("hello") != 2 {
panic(0)
}
if f.Test(3.5, 2.5) != 3 {
panic(0)
}
if f.Test("hello", 20) != 1020 {
panic(0)
}
if f.Test("hello", 20, 100) != 120 {
panic(0)
}
// C default args
if f.Test(f) != 30 {
panic(0)
}
if f.Test(f, 100) != 120 {
panic(0)
}
if f.Test(f, 100, 200) != 300 {
panic(0)
}
}

View File

@@ -0,0 +1,22 @@
package main
import "./overload_extend_c"
func main() {
f := overload_extend_c.NewFoo()
if f.Test().(int) != 0 {
panic(0)
}
if f.Test(3).(int) != 1 {
panic(0)
}
if f.Test("hello").(int) != 2 {
panic(0)
}
if f.Test(float64(3), float64(2)).(float64) != 5 {
panic(0)
}
if f.Test(3.0).(float64) != 1003 {
panic(0)
}
}

View File

@@ -0,0 +1,22 @@
package main
import "./overload_extend"
func main() {
f := overload_extend.NewFoo()
if f.Test().(int) != 0 {
panic(0)
}
if f.Test(3).(int) != 1 {
panic(0)
}
if f.Test("hello").(int) != 2 {
panic(0)
}
if f.Test(float64(3), float64(2)).(float64) != 5 {
panic(0)
}
if f.Test(3.0).(float64) != 1003 {
panic(0)
}
}

View File

@@ -0,0 +1,15 @@
package main
import "./overload_polymorphic"
func main(){
t := overload_polymorphic.NewDerived()
if overload_polymorphic.Test(t) != 0 {
panic("failed 1")
}
if overload_polymorphic.Test2(t) != 1 {
panic("failed 2")
}
}

View File

@@ -0,0 +1,10 @@
package main
import "./overload_rename"
func main() {
_ = overload_rename.NewFoo(float32(1))
_ = overload_rename.NewFoo(float32(1), float32(1))
_ = overload_rename.NewFoo_int(float32(1), 1)
_ = overload_rename.NewFoo_int(float32(1), 1, float32(1))
}

View File

@@ -0,0 +1,125 @@
package main
import . "./overload_simple"
func main() {
if Foo(3) != "foo:int" {
panic("foo(int)")
}
if Foo(3.0) != "foo:double" {
panic("foo(double)")
}
if Foo("hello") != "foo:char *" {
panic("foo(char *)")
}
f := NewFoos()
b := NewBar()
if Foo(f) != "foo:Foo *" {
panic("foo(Foo *)")
}
if Foo(b) != "foo:Bar *" {
panic("foo(Bar *)")
}
v := Malloc_void(32)
if Foo(v) != "foo:void *" {
panic("foo(void *)")
}
s := NewSpam()
if s.Foo(3) != "foo:int" {
panic("Spam::foo(int)")
}
if s.Foo(3.0) != "foo:double" {
panic("Spam::foo(double)")
}
if s.Foo("hello") != "foo:char *" {
panic("Spam::foo(char *)")
}
if s.Foo(f) != "foo:Foo *" {
panic("Spam::foo(Foo *)")
}
if s.Foo(b) != "foo:Bar *" {
panic("Spam::foo(Bar *)")
}
if s.Foo(v) != "foo:void *" {
panic("Spam::foo(void *)")
}
if SpamBar(3) != "bar:int" {
panic("Spam::bar(int)")
}
if SpamBar(3.0) != "bar:double" {
panic("Spam::bar(double)")
}
if SpamBar("hello") != "bar:char *" {
panic("Spam::bar(char *)")
}
if SpamBar(f) != "bar:Foo *" {
panic("Spam::bar(Foo *)")
}
if SpamBar(b) != "bar:Bar *" {
panic("Spam::bar(Bar *)")
}
if SpamBar(v) != "bar:void *" {
panic("Spam::bar(void *)")
}
// Test constructors
s = NewSpam()
if s.GetXtype() != "none" {
panic("Spam()")
}
s = NewSpam(3)
if s.GetXtype() != "int" {
panic("Spam(int)")
}
s = NewSpam(3.4)
if s.GetXtype() != "double" {
panic("Spam(double)")
}
s = NewSpam("hello")
if s.GetXtype() != "char *" {
panic("Spam(char *)")
}
s = NewSpam(f)
if s.GetXtype() != "Foo *" {
panic("Spam(Foo *)")
}
s = NewSpam(b)
if s.GetXtype() != "Bar *" {
panic("Spam(Bar *)")
}
s = NewSpam(v)
if s.GetXtype() != "void *" {
panic("Spam(void *)")
}
Free_void(v)
a := NewClassA()
_ = a.Method1(1)
}

View File

@@ -0,0 +1,16 @@
package main
import . "./overload_subtype"
func main() {
f := NewFoo()
b := NewBar()
if Spam(f) != 1 {
panic("foo")
}
if Spam(b) != 2 {
panic("bar")
}
}

View File

@@ -0,0 +1,186 @@
package main
import . "./overload_template_fast"
func main() {
_ = Foo()
_ = Maximum(3, 4)
_ = Maximum(3.4, 5.2)
// mix 1
if Mix1("hi") != 101 {
panic("mix1(const char*)")
}
if Mix1(1.0, 1.0) != 102 {
panic("mix1(double, const double &)")
}
if Mix1(1.0) != 103 {
panic("mix1(double)")
}
// mix 2
if Mix2("hi") != 101 {
panic("mix2(const char*)")
}
if Mix2(1.0, 1.0) != 102 {
panic("mix2(double, const double &)")
}
if Mix2(1.0) != 103 {
panic("mix2(double)")
}
// mix 3
if Mix3("hi") != 101 {
panic("mix3(const char*)")
}
if Mix3(1.0, 1.0) != 102 {
panic("mix3(double, const double &)")
}
if Mix3(1.0) != 103 {
panic("mix3(double)")
}
// Combination 1
if Overtparams1(100) != 10 {
panic("overtparams1(int)")
}
if Overtparams1(100.0, 100) != 20 {
panic("overtparams1(double, int)")
}
// Combination 2
if Overtparams2(100.0, 100) != 40 {
panic("overtparams2(double, int)")
}
// Combination 3
if Overloaded() != 60 {
panic("overloaded()")
}
if Overloaded(100.0, 100) != 70 {
panic("overloaded(double, int)")
}
// Combination 4
if Overloadedagain("hello") != 80 {
panic("overloadedagain(const char *)")
}
if Overloadedagain() != 90 {
panic("overloadedagain(double)")
}
// specializations
if Specialization(10) != 202 {
panic("specialization(int)")
}
if Specialization(10.0) != 203 {
panic("specialization(double)")
}
if Specialization(10, 10) != 204 {
panic("specialization(int, int)")
}
if Specialization(10.0, 10.0) != 205 {
panic("specialization(double, double)")
}
if Specialization("hi", "hi") != 201 {
panic("specialization(const char *, const char *)")
}
// simple specialization
Xyz()
Xyz_int()
Xyz_double()
// a bit of everything
if Overload("hi") != 0 {
panic("overload()")
}
if Overload(1) != 10 {
panic("overload(int t)")
}
if Overload(1, 1) != 20 {
panic("overload(int t, const int &)")
}
if Overload(1, "hello") != 30 {
panic("overload(int t, const char *)")
}
k := NewKlass()
if Overload(k) != 10 {
panic("overload(Klass t)")
}
if Overload(k, k) != 20 {
panic("overload(Klass t, const Klass &)")
}
if Overload(k, "hello") != 30 {
panic("overload(Klass t, const char *)")
}
if Overload(10.0, "hi") != 40 {
panic("overload(double t, const char *)")
}
if Overload() != 50 {
panic("overload(const char *)")
}
// everything put in a namespace
if Nsoverload("hi") != 1000 {
panic("nsoverload()")
}
if Nsoverload(1) != 1010 {
panic("nsoverload(int t)")
}
if Nsoverload(1, 1) != 1020 {
panic("nsoverload(int t, const int &)")
}
if Nsoverload(1, "hello") != 1030 {
panic("nsoverload(int t, const char *)")
}
if Nsoverload(k) != 1010 {
panic("nsoverload(Klass t)")
}
if Nsoverload(k, k) != 1020 {
panic("nsoverload(Klass t, const Klass &)")
}
if Nsoverload(k, "hello") != 1030 {
panic("nsoverload(Klass t, const char *)")
}
if Nsoverload(10.0, "hi") != 1040 {
panic("nsoverload(double t, const char *)")
}
if Nsoverload() != 1050 {
panic("nsoverload(const char *)")
}
AFoo(1)
b := NewB()
b.Foo(1)
}

View File

@@ -0,0 +1,186 @@
package main
import . "./overload_template"
func main() {
_ = Foo()
_ = Maximum(3, 4)
_ = Maximum(3.4, 5.2)
// mix 1
if Mix1("hi") != 101 {
panic("mix1(const char*)")
}
if Mix1(1.0, 1.0) != 102 {
panic("mix1(double, const double &)")
}
if Mix1(1.0) != 103 {
panic("mix1(double)")
}
// mix 2
if Mix2("hi") != 101 {
panic("mix2(const char*)")
}
if Mix2(1.0, 1.0) != 102 {
panic("mix2(double, const double &)")
}
if Mix2(1.0) != 103 {
panic("mix2(double)")
}
// mix 3
if Mix3("hi") != 101 {
panic("mix3(const char*)")
}
if Mix3(1.0, 1.0) != 102 {
panic("mix3(double, const double &)")
}
if Mix3(1.0) != 103 {
panic("mix3(double)")
}
// Combination 1
if Overtparams1(100) != 10 {
panic("overtparams1(int)")
}
if Overtparams1(100.0, 100) != 20 {
panic("overtparams1(double, int)")
}
// Combination 2
if Overtparams2(100.0, 100) != 40 {
panic("overtparams2(double, int)")
}
// Combination 3
if Overloaded() != 60 {
panic("overloaded()")
}
if Overloaded(100.0, 100) != 70 {
panic("overloaded(double, int)")
}
// Combination 4
if Overloadedagain("hello") != 80 {
panic("overloadedagain(const char *)")
}
if Overloadedagain() != 90 {
panic("overloadedagain(double)")
}
// specializations
if Specialization(10) != 202 {
panic("specialization(int)")
}
if Specialization(10.0) != 203 {
panic("specialization(double)")
}
if Specialization(10, 10) != 204 {
panic("specialization(int, int)")
}
if Specialization(10.0, 10.0) != 205 {
panic("specialization(double, double)")
}
if Specialization("hi", "hi") != 201 {
panic("specialization(const char *, const char *)")
}
// simple specialization
Xyz()
Xyz_int()
Xyz_double()
// a bit of everything
if Overload("hi") != 0 {
panic("overload()")
}
if Overload(1) != 10 {
panic("overload(int t)")
}
if Overload(1, 1) != 20 {
panic("overload(int t, const int &)")
}
if Overload(1, "hello") != 30 {
panic("overload(int t, const char *)")
}
k := NewKlass()
if Overload(k) != 10 {
panic("overload(Klass t)")
}
if Overload(k, k) != 20 {
panic("overload(Klass t, const Klass &)")
}
if Overload(k, "hello") != 30 {
panic("overload(Klass t, const char *)")
}
if Overload(10.0, "hi") != 40 {
panic("overload(double t, const char *)")
}
if Overload() != 50 {
panic("overload(const char *)")
}
// everything put in a namespace
if Nsoverload("hi") != 1000 {
panic("nsoverload()")
}
if Nsoverload(1) != 1010 {
panic("nsoverload(int t)")
}
if Nsoverload(1, 1) != 1020 {
panic("nsoverload(int t, const int &)")
}
if Nsoverload(1, "hello") != 1030 {
panic("nsoverload(int t, const char *)")
}
if Nsoverload(k) != 1010 {
panic("nsoverload(Klass t)")
}
if Nsoverload(k, k) != 1020 {
panic("nsoverload(Klass t, const Klass &)")
}
if Nsoverload(k, "hello") != 1030 {
panic("nsoverload(Klass t, const char *)")
}
if Nsoverload(10.0, "hi") != 1040 {
panic("nsoverload(double t, const char *)")
}
if Nsoverload() != 1050 {
panic("nsoverload(const char *)")
}
AFoo(1)
b := NewB()
b.Foo(1)
}

View File

@@ -0,0 +1,21 @@
package main
import "./preproc"
func main() {
if preproc.GetEndif() != 1 {
panic(0)
}
if preproc.GetDefine() != 1 {
panic(0)
}
if preproc.GetDefined() != 1 {
panic(0)
}
if 2*preproc.One != preproc.Two {
panic(0)
}
}

View File

@@ -0,0 +1,57 @@
package main
import . "./primitive_ref"
func main() {
if Ref_int(3) != 3 {
panic(0)
}
if Ref_uint(3) != 3 {
panic(0)
}
if Ref_short(3) != 3 {
panic(0)
}
if Ref_ushort(3) != 3 {
panic(0)
}
if Ref_long(3) != 3 {
panic(0)
}
if Ref_ulong(3) != 3 {
panic(0)
}
if Ref_schar(3) != 3 {
panic(0)
}
if Ref_uchar(3) != 3 {
panic(0)
}
if Ref_float(3.5) != 3.5 {
panic(0)
}
if Ref_double(3.5) != 3.5 {
panic(0)
}
if Ref_bool(true) != true {
panic(0)
}
if Ref_char('x') != 'x' {
panic(0)
}
if Ref_over(0) != 0 {
panic(0)
}
}

View File

@@ -0,0 +1,38 @@
package main
import "fmt"
import "./profiletest"
func main() {
a := profiletest.NewA()
if false {
fmt.Println(a)
}
b := profiletest.NewB()
fn := func(a profiletest.A) profiletest.A { return b.Fn(a) }
i := 50000
for i != 0 {
a = fn(a) //1
a = fn(a) //2
a = fn(a) //3
a = fn(a) //4
a = fn(a) //5
a = fn(a) //6
a = fn(a) //7
a = fn(a) //8
a = fn(a) //9
a = fn(a) //10
a = fn(a) //1
a = fn(a) //2
a = fn(a) //3
a = fn(a) //4
a = fn(a) //5
a = fn(a) //6
a = fn(a) //7
a = fn(a) //8
a = fn(a) //9
a = fn(a) //20
i -= 1
}
}

View File

@@ -0,0 +1,32 @@
package main
import . "./refcount"
// very innocent example
func main() {
a := NewA3()
_ = NewB(a)
b2 := BCreate(a)
if a.Ref_count() != 3 {
panic("This program will crash... now")
}
rca := b2.Get_rca()
// _ = BCreate(rca)
_ = rca
if a.Ref_count() != 4 {
panic("This program will crash... now")
}
/* Requires smart pointer support.
v := NewVector_A(2)
v.Set(0, a)
v.Set(1, a)
_ = v.Get(0)
DeleteVector_A(v)
*/
}

View File

@@ -0,0 +1,98 @@
package main
import . "./reference_global_vars"
func main() {
// const class reference variable
if GetconstTC().GetNum() != 33 {
panic(0)
}
// primitive reference variables
SetVar_bool(Createref_bool(false))
if Value_bool(GetVar_bool()) != false {
println(1, GetVar_bool(), Value_bool(GetVar_bool()))
panic(0)
}
SetVar_bool(Createref_bool(true))
if Value_bool(GetVar_bool()) != true {
println(2, GetVar_bool(), Value_bool(GetVar_bool()))
panic(0)
}
SetVar_char(Createref_char('w'))
if Value_char(GetVar_char()) != 'w' {
println(3, GetVar_char(), Value_char(GetVar_char()))
panic(0)
}
SetVar_unsigned_char(Createref_unsigned_char(10))
if Value_unsigned_char(GetVar_unsigned_char()) != 10 {
println(4, GetVar_unsigned_char(), Value_unsigned_char(GetVar_unsigned_char()))
panic(0)
}
SetVar_signed_char(Createref_signed_char(10))
if Value_signed_char(GetVar_signed_char()) != 10 {
panic(0)
}
SetVar_short(Createref_short(10))
if Value_short(GetVar_short()) != 10 {
panic(0)
}
SetVar_unsigned_short(Createref_unsigned_short(10))
if Value_unsigned_short(GetVar_unsigned_short()) != 10 {
panic(0)
}
SetVar_int(Createref_int(10))
if Value_int(GetVar_int()) != 10 {
panic(0)
}
SetVar_unsigned_int(Createref_unsigned_int(10))
if Value_unsigned_int(GetVar_unsigned_int()) != 10 {
panic(0)
}
SetVar_long(Createref_long(10))
if Value_long(GetVar_long()) != 10 {
panic(0)
}
SetVar_unsigned_long(Createref_unsigned_long(10))
if Value_unsigned_long(GetVar_unsigned_long()) != 10 {
panic(0)
}
SetVar_long_long(Createref_long_long(0x6FFFFFFFFFFFFFF8))
if Value_long_long(GetVar_long_long()) != 0x6FFFFFFFFFFFFFF8 {
panic(0)
}
//ull = abs(0xFFFFFFF2FFFFFFF0)
ull := uint64(55834574864)
SetVar_unsigned_long_long(Createref_unsigned_long_long(ull))
if Value_unsigned_long_long(GetVar_unsigned_long_long()) != ull {
panic(0)
}
SetVar_float(Createref_float(10.5))
if Value_float(GetVar_float()) != 10.5 {
panic(0)
}
SetVar_double(Createref_double(10.5))
if Value_double(GetVar_double()) != 10.5 {
panic(0)
}
// class reference variable
SetVar_TestClass(Createref_TestClass(NewTestClass(20)))
if Value_TestClass(GetVar_TestClass()).GetNum() != 20 {
panic(0)
}
}

View File

@@ -0,0 +1,18 @@
package main
import . "./rename_scope"
func main() {
a := NewNatural_UP()
b := NewNatural_BP()
if a.Rtest() != 1 {
panic(0)
}
if b.Rtest() != 1 {
panic(0)
}
_ = Equals
}

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