Add support for the Go programming language.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12108 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
09f14197ac
commit
5af2978f77
259 changed files with 16159 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/* File : example.i */
|
||||
%module dynamic_cast
|
||||
|
||||
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
|
||||
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO)
|
||||
%apply SWIGTYPE *DYNAMIC { Foo * };
|
||||
#endif
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ public:
|
|||
};
|
||||
%}
|
||||
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP)
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO)
|
||||
%typemap(out) Foo *blah {
|
||||
Bar *downcast = dynamic_cast<Bar *>($1);
|
||||
*(Bar **)&$result = downcast;
|
||||
|
|
@ -37,6 +37,14 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(SWIGGO)
|
||||
%insert(go_runtime) %{
|
||||
func FooToBar(f Foo) Bar {
|
||||
return SwigcptrBar(f.Swigcptr())
|
||||
}
|
||||
%}
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
|
||||
class Bar : public Foo {
|
||||
|
|
@ -54,7 +62,7 @@ char *do_test(Bar *b) {
|
|||
}
|
||||
%}
|
||||
|
||||
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
|
||||
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO)
|
||||
// A general purpose function for dynamic casting of a Foo *
|
||||
%{
|
||||
static swig_type_info *
|
||||
|
|
|
|||
110
Examples/test-suite/go/Makefile.in
Normal file
110
Examples/test-suite/go/Makefile.in
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#######################################################################
|
||||
# Makefile for Go test-suite
|
||||
#######################################################################
|
||||
|
||||
LANGUAGE = go
|
||||
GO = 6g
|
||||
GOGCC = false
|
||||
SCRIPTSUFFIX = _runme.go
|
||||
|
||||
GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; fi`
|
||||
GOC = $(GO:g=c)
|
||||
GOLD = $(GO:g=l)
|
||||
|
||||
GOOBJEXT = $(GO:g=)
|
||||
|
||||
SO = @SO@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
top_builddir = @top_builddir@
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
||||
# Custom tests - tests with additional commandline options
|
||||
constant_pointers.cpptest: SWIGOPT += -rename foo=foofn
|
||||
director_enum.cpptest: SWIGOPT += -rename Hello=Helloe
|
||||
director_finalizer.cpptest: SWIGOPT += -rename deleteFoo=deleteFooFn
|
||||
enum_thorough.cpptest: SWIGOPT += -rename One=Onee -rename Two=Twoe
|
||||
mixed_types.cpptest: SWIGOPT += -rename Hello=Helloe
|
||||
overload_simple.cpptest: SWIGOPT += -rename foo=foofn
|
||||
smart_pointer_extend.cpptest: SWIGOPT += -rename CPtrFoo=CPtrFoos
|
||||
smart_pointer_member.cpptest: SWIGOPT += -rename Foo=Foos
|
||||
special_variable_macros.cpptest: SWIGOPT += -rename Name=Names
|
||||
template_partial_specialization.cpptest: SWIGOPT += -rename b=bfn
|
||||
template_partial_specialization_typedef.cpptest: SWIGOPT += -rename b=bfn
|
||||
template_specialization_enum.cpptest: SWIGOPT += -rename Hello=Helloe
|
||||
preproc.ctest: SWIGOPT += -rename a5=a5c -rename a6=a6c
|
||||
mod.multicpptest: SWIGOPT += -rename GetC=GetCFn
|
||||
|
||||
.SUFFIXES: .cpptest .ctest .multicpptest
|
||||
|
||||
# Rules for the different types of tests
|
||||
%.cpptest:
|
||||
$(setup)
|
||||
+$(swig_and_compile_cpp)
|
||||
$(run_testcase)
|
||||
|
||||
%.ctest:
|
||||
$(setup)
|
||||
+$(swig_and_compile_c)
|
||||
$(run_testcase)
|
||||
|
||||
%.multicpptest:
|
||||
$(setup)
|
||||
+$(swig_and_compile_multi_cpp)
|
||||
$(run_multi_testcase)
|
||||
|
||||
multi_import.multicpptest:
|
||||
$(setup)
|
||||
for f in multi_import_b multi_import_a; do \
|
||||
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile CXXSRCS="$(CXXSRCS)" \
|
||||
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" LIBS='$(LIBS)' \
|
||||
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \
|
||||
TARGET="$(TARGETPREFIX)$${f}$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$$f.i" \
|
||||
$(LANGUAGE)$(VARIANT)_cpp; \
|
||||
done
|
||||
$(run_multi_testcase)
|
||||
|
||||
# Runs the testcase.
|
||||
run_testcase = \
|
||||
if test -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \
|
||||
$(GO) -I . $(GOCOMPILEARG) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
|
||||
if $(GOGCC) ; then \
|
||||
$(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*$(SO); \
|
||||
else \
|
||||
$(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
|
||||
fi && \
|
||||
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH ./$*_runme; \
|
||||
fi
|
||||
|
||||
run_multi_testcase = \
|
||||
if test -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \
|
||||
$(GO) -I . $(GOCOMPILEARG) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
|
||||
if $(GOGCC) ; then \
|
||||
files=`cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; \
|
||||
$(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.@OBJEXT@ $$f$(SO); done`; \
|
||||
else \
|
||||
$(GOLD) -L . -r $${GOROOT}/pkg/$${GOOS}_$${GOARCH}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
|
||||
fi && \
|
||||
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH ./$*_runme; \
|
||||
fi
|
||||
|
||||
%.clean:
|
||||
@rm -f $*.go $*_gc.c $*_wrap.* $*_runme
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile go_clean
|
||||
rm -f mod_a.go mod_b.go imports_a.go imports_b.go
|
||||
rm -f clientdata_prop_a.go clientdata_prop_b.go
|
||||
rm -f multi_import_a.go multi_import_b.go
|
||||
rm -f packageoption_a.go packageoption_b.go packageoption_c.go
|
||||
|
||||
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
|
||||
10
Examples/test-suite/go/abstract_access_runme.go
Normal file
10
Examples/test-suite/go/abstract_access_runme.go
Normal 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())
|
||||
}
|
||||
}
|
||||
7
Examples/test-suite/go/abstract_typedef2_runme.go
Normal file
7
Examples/test-suite/go/abstract_typedef2_runme.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "./abstract_typedef2"
|
||||
|
||||
func main() {
|
||||
abstract_typedef2.NewA_UF()
|
||||
}
|
||||
11
Examples/test-suite/go/abstract_typedef_runme.go
Normal file
11
Examples/test-suite/go/abstract_typedef_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
8
Examples/test-suite/go/abstract_virtual_runme.go
Normal file
8
Examples/test-suite/go/abstract_virtual_runme.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
import "./abstract_virtual"
|
||||
|
||||
func main() {
|
||||
abstract_virtual.NewD()
|
||||
abstract_virtual.NewE()
|
||||
}
|
||||
26
Examples/test-suite/go/array_member_runme.go
Normal file
26
Examples/test-suite/go/array_member_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Examples/test-suite/go/arrays_global_runme.go
Normal file
22
Examples/test-suite/go/arrays_global_runme.go
Normal 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")
|
||||
}
|
||||
10
Examples/test-suite/go/class_ignore_runme.go
Normal file
10
Examples/test-suite/go/class_ignore_runme.go
Normal 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))
|
||||
}
|
||||
}
|
||||
11
Examples/test-suite/go/class_scope_weird_runme.go
Normal file
11
Examples/test-suite/go/class_scope_weird_runme.go
Normal 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))
|
||||
}
|
||||
}
|
||||
29
Examples/test-suite/go/compactdefaultargs_runme.go
Normal file
29
Examples/test-suite/go/compactdefaultargs_runme.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import . "./compactdefaultargs"
|
||||
|
||||
func main() {
|
||||
defaults1 := NewDefaults1(1000)
|
||||
defaults1 = NewDefaults1()
|
||||
|
||||
if defaults1.Ret(float64(10.0)) != 10.0 {
|
||||
println(1, defaults1.Ret(float64(10.0)))
|
||||
panic(defaults1.Ret(float64(10.0)))
|
||||
}
|
||||
|
||||
if defaults1.Ret() != -1.0 {
|
||||
println(2, defaults1.Ret())
|
||||
panic(defaults1.Ret())
|
||||
}
|
||||
|
||||
defaults2 := NewDefaults2(1000)
|
||||
defaults2 = NewDefaults2()
|
||||
|
||||
if defaults2.Ret(float64(10.0)) != 10.0 {
|
||||
panic(defaults2.Ret(float64(10.0)))
|
||||
}
|
||||
|
||||
if defaults2.Ret() != -1.0 {
|
||||
panic(defaults2.Ret())
|
||||
}
|
||||
}
|
||||
50
Examples/test-suite/go/constover_runme.go
Normal file
50
Examples/test-suite/go/constover_runme.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"./constover"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
34
Examples/test-suite/go/constructor_copy_runme.go
Normal file
34
Examples/test-suite/go/constructor_copy_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
208
Examples/test-suite/go/contract_runme.go
Normal file
208
Examples/test-suite/go/contract_runme.go
Normal 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
|
||||
my := contract.NewMyClass(1)
|
||||
func() {
|
||||
defer func() {
|
||||
if recover() == nil {
|
||||
panic("Failed! constructor preassertion")
|
||||
}
|
||||
}()
|
||||
my = contract.NewMyClass(0)
|
||||
}()
|
||||
}
|
||||
27
Examples/test-suite/go/cpp_enum_runme.go
Normal file
27
Examples/test-suite/go/cpp_enum_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
57
Examples/test-suite/go/cpp_namespace_runme.go
Normal file
57
Examples/test-suite/go/cpp_namespace_runme.go
Normal 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!")
|
||||
}
|
||||
}
|
||||
13
Examples/test-suite/go/cpp_static_runme.go
Normal file
13
Examples/test-suite/go/cpp_static_runme.go
Normal 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())
|
||||
}
|
||||
}
|
||||
26
Examples/test-suite/go/default_args_runme.go
Normal file
26
Examples/test-suite/go/default_args_runme.go
Normal 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)
|
||||
}
|
||||
35
Examples/test-suite/go/default_constructor_runme.go
Normal file
35
Examples/test-suite/go/default_constructor_runme.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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()
|
||||
|
||||
ff := dc.NewFFF()
|
||||
ff.Destroy()
|
||||
|
||||
g := dc.NewG()
|
||||
|
||||
dc.GDestroy(g)
|
||||
|
||||
gg := dc.NewGG()
|
||||
dc.DeleteGG(gg)
|
||||
|
||||
dc.NewHH(1, 1)
|
||||
}
|
||||
62
Examples/test-suite/go/director_abstract_runme.go
Normal file
62
Examples/test-suite/go/director_abstract_runme.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package main
|
||||
|
||||
import "./director_abstract"
|
||||
|
||||
type MyFoo struct{}
|
||||
|
||||
func (p *MyFoo) Ping() string {
|
||||
return "MyFoo::ping()"
|
||||
}
|
||||
|
||||
func f1() {
|
||||
a := director_abstract.NewDirectorFoo(&MyFoo{})
|
||||
|
||||
if a.Ping() != "MyFoo::ping()" {
|
||||
panic(a.Ping())
|
||||
}
|
||||
|
||||
if a.Pong() != "Foo::pong();MyFoo::ping()" {
|
||||
panic(a.Pong())
|
||||
}
|
||||
}
|
||||
|
||||
type MyExample1 struct{}
|
||||
|
||||
func (p *MyExample1) Color(r, g, b byte) int {
|
||||
return int(r)
|
||||
}
|
||||
|
||||
type MyExample2 struct{}
|
||||
|
||||
func (p *MyExample2) Color(r, g, b byte) int {
|
||||
return int(g)
|
||||
}
|
||||
|
||||
type MyExample3 struct{}
|
||||
|
||||
func (p *MyExample3) Color(r, g, b byte) int {
|
||||
return int(b)
|
||||
}
|
||||
|
||||
func f2() {
|
||||
me1 := director_abstract.NewDirectorExample1(&MyExample1{})
|
||||
if director_abstract.Example1Get_color(me1, 1, 2, 3) != 1 {
|
||||
println(director_abstract.Example1Get_color(me1, 1, 2, 3))
|
||||
panic(0)
|
||||
}
|
||||
|
||||
me2 := director_abstract.NewDirectorExample2(&MyExample2{}, 1, 2)
|
||||
if director_abstract.Example2Get_color(me2, 1, 2, 3) != 2 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
me3 := director_abstract.NewDirectorExample3_i(&MyExample3{})
|
||||
if director_abstract.Example3_iGet_color(me3, 1, 2, 3) != 3 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
f1()
|
||||
f2()
|
||||
}
|
||||
115
Examples/test-suite/go/director_basic_runme.go
Normal file
115
Examples/test-suite/go/director_basic_runme.go
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
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()
|
||||
}
|
||||
135
Examples/test-suite/go/director_classic_runme.go
Normal file
135
Examples/test-suite/go/director_classic_runme.go
Normal 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))
|
||||
}
|
||||
11
Examples/test-suite/go/director_default_runme.go
Normal file
11
Examples/test-suite/go/director_default_runme.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
import . "./director_default"
|
||||
|
||||
func main() {
|
||||
NewFoo()
|
||||
NewFoo(1)
|
||||
|
||||
NewBar()
|
||||
NewBar(1)
|
||||
}
|
||||
46
Examples/test-suite/go/director_detect_runme.go
Normal file
46
Examples/test-suite/go/director_detect_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
17
Examples/test-suite/go/director_enum_runme.go
Normal file
17
Examples/test-suite/go/director_enum_runme.go
Normal 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.EnumDirectorHelloe) director_enum.EnumDirectorHelloe {
|
||||
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)
|
||||
}
|
||||
}
|
||||
95
Examples/test-suite/go/director_exception_runme.go
Normal file
95
Examples/test-suite/go/director_exception_runme.go
Normal 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())
|
||||
}()
|
||||
}
|
||||
18
Examples/test-suite/go/director_extend_runme.go
Normal file
18
Examples/test-suite/go/director_extend_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
37
Examples/test-suite/go/director_finalizer_runme.go
Normal file
37
Examples/test-suite/go/director_finalizer_runme.go
Normal 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()
|
||||
}
|
||||
12
Examples/test-suite/go/director_frob_runme.go
Normal file
12
Examples/test-suite/go/director_frob_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
79
Examples/test-suite/go/director_nested_runme.go
Normal file
79
Examples/test-suite/go/director_nested_runme.go
Normal 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()
|
||||
}
|
||||
49
Examples/test-suite/go/director_profile_runme.go
Normal file
49
Examples/test-suite/go/director_profile_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
48
Examples/test-suite/go/director_protected_runme.go
Normal file
48
Examples/test-suite/go/director_protected_runme.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
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();"
|
||||
}
|
||||
|
||||
func main() {
|
||||
b := NewBar()
|
||||
f := b.Create()
|
||||
fb := NewDirectorBar(&FooBar{})
|
||||
fb2 := NewDirectorBar(&FooBar2{})
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
39
Examples/test-suite/go/director_string_runme.go
Normal file
39
Examples/test-suite/go/director_string_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
28
Examples/test-suite/go/director_thread_runme.go
Normal file
28
Examples/test-suite/go/director_thread_runme.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import . "./director_thread"
|
||||
|
||||
type Derived struct {
|
||||
abi Foo
|
||||
} // From Foo
|
||||
func (p *Derived) Do_foo() {
|
||||
p.abi.SetVal(p.abi.GetVal() - 1)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// FIXME: This test fails until we fix callbacks from a
|
||||
// different thread.
|
||||
return
|
||||
|
||||
p := &Derived{nil}
|
||||
d := NewDirectorFoo(p)
|
||||
p.abi = d
|
||||
d.Run()
|
||||
|
||||
if d.GetVal() >= 0 {
|
||||
panic(d.GetVal())
|
||||
}
|
||||
|
||||
d.Stop()
|
||||
}
|
||||
21
Examples/test-suite/go/director_unroll_runme.go
Normal file
21
Examples/test-suite/go/director_unroll_runme.go
Normal 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())
|
||||
}
|
||||
}
|
||||
10
Examples/test-suite/go/disown_runme.go
Normal file
10
Examples/test-suite/go/disown_runme.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package main
|
||||
|
||||
import . "./disown"
|
||||
|
||||
func main() {
|
||||
a := NewA()
|
||||
|
||||
b := NewB()
|
||||
b.Acquire(a)
|
||||
}
|
||||
16
Examples/test-suite/go/dynamic_cast_runme.go
Normal file
16
Examples/test-suite/go/dynamic_cast_runme.go
Normal 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!!")
|
||||
}
|
||||
}
|
||||
6
Examples/test-suite/go/empty_runme.go
Normal file
6
Examples/test-suite/go/empty_runme.go
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
import _ "./empty"
|
||||
|
||||
func main() {
|
||||
}
|
||||
11
Examples/test-suite/go/enum_template_runme.go
Normal file
11
Examples/test-suite/go/enum_template_runme.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
import "./enum_template"
|
||||
|
||||
func main() {
|
||||
if enum_template.MakeETest() != 1 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
enum_template.TakeETest(0)
|
||||
}
|
||||
25
Examples/test-suite/go/enums_runme.go
Normal file
25
Examples/test-suite/go/enums_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
58
Examples/test-suite/go/exception_order_runme.go
Normal file
58
Examples/test-suite/go/exception_order_runme.go
Normal 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)
|
||||
}()
|
||||
}
|
||||
47
Examples/test-suite/go/extend_placement_runme.go
Normal file
47
Examples/test-suite/go/extend_placement_runme.go
Normal 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(), float64(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(), float64(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(), float64(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(), float64(1.0))
|
||||
}
|
||||
14
Examples/test-suite/go/extend_template_ns_runme.go
Normal file
14
Examples/test-suite/go/extend_template_ns_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
14
Examples/test-suite/go/extend_template_runme.go
Normal file
14
Examples/test-suite/go/extend_template_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
9
Examples/test-suite/go/extend_variable_runme.go
Normal file
9
Examples/test-suite/go/extend_variable_runme.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package main
|
||||
|
||||
import . "./extend_variable"
|
||||
|
||||
func main() {
|
||||
if FooBar != 42 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
7
Examples/test-suite/go/extern_c_runme.go
Normal file
7
Examples/test-suite/go/extern_c_runme.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "./extern_c"
|
||||
|
||||
func main() {
|
||||
extern_c.RealFunction(2)
|
||||
}
|
||||
50
Examples/test-suite/go/friends_runme.go
Normal file
50
Examples/test-suite/go/friends_runme.go
Normal 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, float64(4.0))
|
||||
friends.Set(dd, float64(1.3))
|
||||
|
||||
if friends.Get_val1(di).(float64) != 4 {
|
||||
panic(0)
|
||||
}
|
||||
if friends.Get_val1(dd).(float64) != 1.3 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
13
Examples/test-suite/go/fvirtual_runme.go
Normal file
13
Examples/test-suite/go/fvirtual_runme.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package main
|
||||
|
||||
import . "./fvirtual"
|
||||
|
||||
func main() {
|
||||
sw := NewNodeSwitch()
|
||||
n := NewNode()
|
||||
i := sw.AddChild(n)
|
||||
|
||||
if i != 2 {
|
||||
panic("addChild")
|
||||
}
|
||||
}
|
||||
8
Examples/test-suite/go/global_ns_arg_runme.go
Normal file
8
Examples/test-suite/go/global_ns_arg_runme.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
import . "./global_ns_arg"
|
||||
|
||||
func main() {
|
||||
Foo(1)
|
||||
Bar()
|
||||
}
|
||||
19
Examples/test-suite/go/grouping_runme.go
Normal file
19
Examples/test-suite/go/grouping_runme.go
Normal 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)
|
||||
}
|
||||
12
Examples/test-suite/go/import_nomodule_runme.go
Normal file
12
Examples/test-suite/go/import_nomodule_runme.go
Normal 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)
|
||||
}
|
||||
17
Examples/test-suite/go/imports_runme.go
Normal file
17
Examples/test-suite/go/imports_runme.go
Normal 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)
|
||||
}
|
||||
18
Examples/test-suite/go/inctest_runme.go
Normal file
18
Examples/test-suite/go/inctest_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
26
Examples/test-suite/go/inherit_missing_runme.go
Normal file
26
Examples/test-suite/go/inherit_missing_runme.go
Normal 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)
|
||||
}
|
||||
14
Examples/test-suite/go/input_runme.go
Normal file
14
Examples/test-suite/go/input_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
8
Examples/test-suite/go/keyword_rename_runme.go
Normal file
8
Examples/test-suite/go/keyword_rename_runme.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
import "./keyword_rename"
|
||||
|
||||
func main() {
|
||||
keyword_rename.Xgo(1)
|
||||
keyword_rename.Xchan(1)
|
||||
}
|
||||
90
Examples/test-suite/go/li_attribute_runme.go
Normal file
90
Examples/test-suite/go/li_attribute_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
14
Examples/test-suite/go/li_carrays_runme.go
Normal file
14
Examples/test-suite/go/li_carrays_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
13
Examples/test-suite/go/li_cdata_runme.go
Normal file
13
Examples/test-suite/go/li_cdata_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
25
Examples/test-suite/go/li_cmalloc_runme.go
Normal file
25
Examples/test-suite/go/li_cmalloc_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
14
Examples/test-suite/go/li_cpointer_runme.go
Normal file
14
Examples/test-suite/go/li_cpointer_runme.go
Normal 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)
|
||||
}
|
||||
30
Examples/test-suite/go/li_std_map_runme.go
Normal file
30
Examples/test-suite/go/li_std_map_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
49
Examples/test-suite/go/member_pointer_runme.go
Normal file
49
Examples/test-suite/go/member_pointer_runme.go
Normal 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))
|
||||
}
|
||||
11
Examples/test-suite/go/memberin_extend_c_runme.go
Normal file
11
Examples/test-suite/go/memberin_extend_c_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
82
Examples/test-suite/go/minherit_runme.go
Normal file
82
Examples/test-suite/go/minherit_runme.go
Normal 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)))
|
||||
}
|
||||
}
|
||||
10
Examples/test-suite/go/mod_runme.go
Normal file
10
Examples/test-suite/go/mod_runme.go
Normal 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()))
|
||||
}
|
||||
29
Examples/test-suite/go/multi_import_runme.go
Normal file
29
Examples/test-suite/go/multi_import_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
19
Examples/test-suite/go/namespace_class_runme.go
Normal file
19
Examples/test-suite/go/namespace_class_runme.go
Normal 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)
|
||||
}
|
||||
116
Examples/test-suite/go/namespace_typemap_runme.go
Normal file
116
Examples/test-suite/go/namespace_typemap_runme.go
Normal 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 := cmplx(float64(2), float64(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)
|
||||
}
|
||||
}
|
||||
7
Examples/test-suite/go/namespace_virtual_method_runme.go
Normal file
7
Examples/test-suite/go/namespace_virtual_method_runme.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "./namespace_virtual_method"
|
||||
|
||||
func main() {
|
||||
_ = namespace_virtual_method.NewSpam()
|
||||
}
|
||||
17
Examples/test-suite/go/naturalvar_runme.go
Normal file
17
Examples/test-suite/go/naturalvar_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
19
Examples/test-suite/go/nested_workaround_runme.go
Normal file
19
Examples/test-suite/go/nested_workaround_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
62
Examples/test-suite/go/overload_complicated_runme.go
Normal file
62
Examples/test-suite/go/overload_complicated_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
8
Examples/test-suite/go/overload_copy_runme.go
Normal file
8
Examples/test-suite/go/overload_copy_runme.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
import . "./overload_copy"
|
||||
|
||||
func main() {
|
||||
f := NewFoo()
|
||||
_ = NewFoo(f)
|
||||
}
|
||||
22
Examples/test-suite/go/overload_extend_runme.go
Normal file
22
Examples/test-suite/go/overload_extend_runme.go
Normal 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(float64(3.0)).(float64) != 1003 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
33
Examples/test-suite/go/overload_extendc_runme.go
Normal file
33
Examples/test-suite/go/overload_extendc_runme.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import "./overload_extendc"
|
||||
|
||||
func main() {
|
||||
f := overload_extendc.NewFoo()
|
||||
if f.Test(3) != 1 {
|
||||
panic(0)
|
||||
}
|
||||
if f.Test("hello") != 2 {
|
||||
panic(0)
|
||||
}
|
||||
if f.Test(float64(3.5), float64(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)
|
||||
}
|
||||
}
|
||||
10
Examples/test-suite/go/overload_rename_runme.go
Normal file
10
Examples/test-suite/go/overload_rename_runme.go
Normal 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))
|
||||
}
|
||||
125
Examples/test-suite/go/overload_simple_runme.go
Normal file
125
Examples/test-suite/go/overload_simple_runme.go
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
package main
|
||||
|
||||
import . "./overload_simple"
|
||||
|
||||
func main() {
|
||||
if Foofn(3) != "foo:int" {
|
||||
panic("foo(int)")
|
||||
}
|
||||
|
||||
if Foofn(float64(3.0)) != "foo:double" {
|
||||
panic("foo(double)")
|
||||
}
|
||||
|
||||
if Foofn("hello") != "foo:char *" {
|
||||
panic("foo(char *)")
|
||||
}
|
||||
|
||||
f := NewFoo()
|
||||
b := NewBar()
|
||||
|
||||
if Foofn(f) != "foo:Foo *" {
|
||||
panic("foo(Foo *)")
|
||||
}
|
||||
|
||||
if Foofn(b) != "foo:Bar *" {
|
||||
panic("foo(Bar *)")
|
||||
}
|
||||
|
||||
v := Malloc_void(32)
|
||||
|
||||
if Foofn(v) != "foo:void *" {
|
||||
panic("foo(void *)")
|
||||
}
|
||||
s := NewSpam()
|
||||
|
||||
if s.Foofn(3) != "foo:int" {
|
||||
panic("Spam::foo(int)")
|
||||
}
|
||||
|
||||
if s.Foofn(float64(3.0)) != "foo:double" {
|
||||
panic("Spam::foo(double)")
|
||||
}
|
||||
|
||||
if s.Foofn("hello") != "foo:char *" {
|
||||
panic("Spam::foo(char *)")
|
||||
}
|
||||
|
||||
if s.Foofn(f) != "foo:Foo *" {
|
||||
panic("Spam::foo(Foo *)")
|
||||
}
|
||||
|
||||
if s.Foofn(b) != "foo:Bar *" {
|
||||
panic("Spam::foo(Bar *)")
|
||||
}
|
||||
|
||||
if s.Foofn(v) != "foo:void *" {
|
||||
panic("Spam::foo(void *)")
|
||||
}
|
||||
|
||||
if SpamBar(3) != "bar:int" {
|
||||
panic("Spam::bar(int)")
|
||||
}
|
||||
|
||||
if SpamBar(float64(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(float64(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)
|
||||
}
|
||||
16
Examples/test-suite/go/overload_subtype_runme.go
Normal file
16
Examples/test-suite/go/overload_subtype_runme.go
Normal 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")
|
||||
}
|
||||
}
|
||||
187
Examples/test-suite/go/overload_template_fast_runme.go
Normal file
187
Examples/test-suite/go/overload_template_fast_runme.go
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
package main
|
||||
|
||||
import . "./overload_template_fast"
|
||||
|
||||
func main() {
|
||||
_ = Foo()
|
||||
|
||||
_ = Maximum(3, 4)
|
||||
_ = Maximum(float64(3.4), float64(5.2))
|
||||
|
||||
// mix 1
|
||||
if Mix1("hi") != 101 {
|
||||
panic("mix1(const char*)")
|
||||
}
|
||||
|
||||
if Mix1(float64(1.0), float64(1.0)) != 102 {
|
||||
panic("mix1(double, const double &)")
|
||||
}
|
||||
|
||||
if Mix1(float64(1.0)) != 103 {
|
||||
panic("mix1(double)")
|
||||
}
|
||||
|
||||
// mix 2
|
||||
if Mix2("hi") != 101 {
|
||||
panic("mix2(const char*)")
|
||||
}
|
||||
|
||||
if Mix2(float64(1.0), float64(1.0)) != 102 {
|
||||
panic("mix2(double, const double &)")
|
||||
}
|
||||
|
||||
if Mix2(float64(1.0)) != 103 {
|
||||
panic("mix2(double)")
|
||||
}
|
||||
|
||||
// mix 3
|
||||
if Mix3("hi") != 101 {
|
||||
panic("mix3(const char*)")
|
||||
}
|
||||
|
||||
if Mix3(float64(1.0), float64(1.0)) != 102 {
|
||||
panic("mix3(double, const double &)")
|
||||
}
|
||||
|
||||
if Mix3(float64(1.0)) != 103 {
|
||||
panic("mix3(double)")
|
||||
}
|
||||
|
||||
// Combination 1
|
||||
if Overtparams1(100) != 10 {
|
||||
panic("overtparams1(int)")
|
||||
}
|
||||
|
||||
if Overtparams1(float64(100.0), 100) != 20 {
|
||||
panic("overtparams1(double, int)")
|
||||
}
|
||||
|
||||
// Combination 2
|
||||
if Overtparams2(float64(100.0), 100) != 40 {
|
||||
panic("overtparams2(double, int)")
|
||||
}
|
||||
|
||||
// Combination 3
|
||||
if Overloaded() != 60 {
|
||||
panic("overloaded()")
|
||||
}
|
||||
|
||||
if Overloaded(float64(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(float64(10.0)) != 203 {
|
||||
panic("specialization(double)")
|
||||
}
|
||||
|
||||
if Specialization(10, 10) != 204 {
|
||||
panic("specialization(int, int)")
|
||||
}
|
||||
|
||||
if Specialization(float64(10.0), float64(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(float64(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(float64(10.0), "hi") != 1040 {
|
||||
panic("nsoverload(double t, const char *)")
|
||||
}
|
||||
|
||||
if Nsoverload() != 1050 {
|
||||
panic("nsoverload(const char *)")
|
||||
}
|
||||
|
||||
AFoo(1)
|
||||
b := NewB()
|
||||
b.Foo(1)
|
||||
}
|
||||
188
Examples/test-suite/go/overload_template_runme.go
Normal file
188
Examples/test-suite/go/overload_template_runme.go
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
package main
|
||||
|
||||
import . "./overload_template"
|
||||
|
||||
func main() {
|
||||
_ = Foo()
|
||||
|
||||
_ = Maximum(3, 4)
|
||||
_ = Maximum(float64(3.4), float64(5.2))
|
||||
|
||||
// mix 1
|
||||
if Mix1("hi") != 101 {
|
||||
panic("mix1(const char*)")
|
||||
}
|
||||
|
||||
if Mix1(float64(1.0), float64(1.0)) != 102 {
|
||||
panic("mix1(double, const double &)")
|
||||
}
|
||||
|
||||
if Mix1(float64(1.0)) != 103 {
|
||||
panic("mix1(double)")
|
||||
}
|
||||
|
||||
// mix 2
|
||||
if Mix2("hi") != 101 {
|
||||
panic("mix2(const char*)")
|
||||
}
|
||||
|
||||
if Mix2(float64(1.0), float64(1.0)) != 102 {
|
||||
panic("mix2(double, const double &)")
|
||||
}
|
||||
|
||||
if Mix2(float64(1.0)) != 103 {
|
||||
panic("mix2(double)")
|
||||
}
|
||||
|
||||
// mix 3
|
||||
if Mix3("hi") != 101 {
|
||||
panic("mix3(const char*)")
|
||||
}
|
||||
|
||||
if Mix3(float64(1.0), float64(1.0)) != 102 {
|
||||
panic("mix3(double, const double &)")
|
||||
}
|
||||
|
||||
if Mix3(float64(1.0)) != 103 {
|
||||
panic("mix3(double)")
|
||||
}
|
||||
|
||||
// Combination 1
|
||||
if Overtparams1(100) != 10 {
|
||||
panic("overtparams1(int)")
|
||||
}
|
||||
|
||||
if Overtparams1(float64(100.0), 100) != 20 {
|
||||
panic("overtparams1(double, int)")
|
||||
}
|
||||
|
||||
// Combination 2
|
||||
if Overtparams2(float64(100.0), 100) != 40 {
|
||||
panic("overtparams2(double, int)")
|
||||
}
|
||||
|
||||
// Combination 3
|
||||
if Overloaded() != 60 {
|
||||
panic("overloaded()")
|
||||
}
|
||||
|
||||
if Overloaded(float64(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(float64(10.0)) != 203 {
|
||||
panic("specialization(double)")
|
||||
}
|
||||
|
||||
if Specialization(10, 10) != 204 {
|
||||
panic("specialization(int, int)")
|
||||
}
|
||||
|
||||
if Specialization(float64(10.0), float64(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(float64(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(float64(10.0), "hi") != 1040 {
|
||||
panic("nsoverload(double t, const char *)")
|
||||
}
|
||||
|
||||
if Nsoverload() != 1050 {
|
||||
panic("nsoverload(const char *)")
|
||||
}
|
||||
|
||||
AFoo(1)
|
||||
b := NewB()
|
||||
b.Foo(1)
|
||||
}
|
||||
21
Examples/test-suite/go/preproc_runme.go
Normal file
21
Examples/test-suite/go/preproc_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
57
Examples/test-suite/go/primitive_ref_runme.go
Normal file
57
Examples/test-suite/go/primitive_ref_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
38
Examples/test-suite/go/profiletest_runme.go
Normal file
38
Examples/test-suite/go/profiletest_runme.go
Normal 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
|
||||
}
|
||||
}
|
||||
32
Examples/test-suite/go/refcount_runme.go
Normal file
32
Examples/test-suite/go/refcount_runme.go
Normal 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)
|
||||
*/
|
||||
}
|
||||
98
Examples/test-suite/go/reference_global_vars_runme.go
Normal file
98
Examples/test-suite/go/reference_global_vars_runme.go
Normal 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)
|
||||
}
|
||||
}
|
||||
18
Examples/test-suite/go/rename_scope_runme.go
Normal file
18
Examples/test-suite/go/rename_scope_runme.go
Normal 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
|
||||
}
|
||||
9
Examples/test-suite/go/rename_strip_encoder_runme.go
Normal file
9
Examples/test-suite/go/rename_strip_encoder_runme.go
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
package main
|
||||
|
||||
import . "./rename_strip_encoder"
|
||||
|
||||
func main() {
|
||||
_ = NewSomeWidget()
|
||||
a := NewAnotherWidget()
|
||||
a.DoSomething()
|
||||
}
|
||||
14
Examples/test-suite/go/ret_by_value_runme.go
Normal file
14
Examples/test-suite/go/ret_by_value_runme.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import "./ret_by_value"
|
||||
|
||||
func main() {
|
||||
a := ret_by_value.Get_test()
|
||||
if a.GetMyInt() != 100 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if a.GetMyShort() != 200 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
15
Examples/test-suite/go/return_const_value_runme.go
Normal file
15
Examples/test-suite/go/return_const_value_runme.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package main
|
||||
|
||||
import "./return_const_value"
|
||||
|
||||
func main() {
|
||||
p := return_const_value.Foo_ptrGetPtr()
|
||||
if p.GetVal() != 17 {
|
||||
panic("Runtime test1 failed")
|
||||
}
|
||||
|
||||
p = return_const_value.Foo_ptrGetConstPtr()
|
||||
if p.GetVal() != 17 {
|
||||
panic("Runtime test2 failed")
|
||||
}
|
||||
}
|
||||
40
Examples/test-suite/go/smart_pointer_extend_runme.go
Normal file
40
Examples/test-suite/go/smart_pointer_extend_runme.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import . "./smart_pointer_extend"
|
||||
|
||||
func main() {
|
||||
f := NewFoo()
|
||||
b := NewBar(f)
|
||||
|
||||
if b.Extension() != f.Extension() {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
b2 := NewCBase()
|
||||
d := NewCDerived()
|
||||
p := NewCPtr()
|
||||
|
||||
if b2.Bar() != p.Bar() {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if d.Foo() != p.Foo() {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if CBaseHello() != p.Hello() {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
d2 := NewDFoo()
|
||||
|
||||
dp := NewDPtrFoo(d2)
|
||||
|
||||
if DFooSExt(1) != dp.SExt(1) {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if d2.Ext(1) != dp.Ext(1) {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
30
Examples/test-suite/go/smart_pointer_member_runme.go
Normal file
30
Examples/test-suite/go/smart_pointer_member_runme.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import . "./smart_pointer_member"
|
||||
|
||||
func main() {
|
||||
f := NewFoos()
|
||||
f.SetY(1)
|
||||
|
||||
if f.GetY() != 1 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
b := NewBar(f)
|
||||
b.SetY(2)
|
||||
|
||||
if f.GetY() != 2 {
|
||||
fmt.Println(f.GetY())
|
||||
fmt.Println(b.GetY())
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if b.GetX() != f.GetX() {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if b.GetZ() != GetFoosZ() {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
20
Examples/test-suite/go/smart_pointer_multi_runme.go
Normal file
20
Examples/test-suite/go/smart_pointer_multi_runme.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import . "./smart_pointer_multi"
|
||||
|
||||
func main() {
|
||||
f := NewFoo()
|
||||
b := NewBar(f)
|
||||
s := NewSpam(b)
|
||||
g := NewGrok(b)
|
||||
|
||||
s.SetX(3)
|
||||
if s.Getx() != 3 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
g.SetX(4)
|
||||
if g.Getx() != 4 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
20
Examples/test-suite/go/smart_pointer_multi_typedef_runme.go
Normal file
20
Examples/test-suite/go/smart_pointer_multi_typedef_runme.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import . "./smart_pointer_multi_typedef"
|
||||
|
||||
func main() {
|
||||
f := NewFoo()
|
||||
b := NewBar(f)
|
||||
s := NewSpam(b)
|
||||
g := NewGrok(b)
|
||||
|
||||
s.SetX(3)
|
||||
if s.Getx() != 3 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
g.SetX(4)
|
||||
if g.Getx() != 4 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
28
Examples/test-suite/go/smart_pointer_overload_runme.go
Normal file
28
Examples/test-suite/go/smart_pointer_overload_runme.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import . "./smart_pointer_overload"
|
||||
|
||||
func main() {
|
||||
f := NewFoo()
|
||||
b := NewBar(f)
|
||||
|
||||
if f.Test(3) != 1 {
|
||||
panic(0)
|
||||
}
|
||||
if f.Test(float64(3.5)) != 2 {
|
||||
panic(0)
|
||||
}
|
||||
if f.Test("hello") != 3 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if b.Test(3) != 1 {
|
||||
panic(0)
|
||||
}
|
||||
if b.Test(float64(3.5)) != 2 {
|
||||
panic(0)
|
||||
}
|
||||
if b.Test("hello") != 3 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
20
Examples/test-suite/go/smart_pointer_rename_runme.go
Normal file
20
Examples/test-suite/go/smart_pointer_rename_runme.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import . "./smart_pointer_rename"
|
||||
|
||||
func main() {
|
||||
f := NewFoo()
|
||||
b := NewBar(f)
|
||||
|
||||
if b.Test() != 3 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if b.Ftest1(1) != 1 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
if b.Ftest2(2, 3) != 2 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
19
Examples/test-suite/go/smart_pointer_simple_runme.go
Normal file
19
Examples/test-suite/go/smart_pointer_simple_runme.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import . "./smart_pointer_simple"
|
||||
|
||||
func main() {
|
||||
f := NewFoo()
|
||||
b := NewBar(f)
|
||||
|
||||
b.SetX(3)
|
||||
if b.Getx() != 3 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
fp := b.X__deref__()
|
||||
fp.SetX(4)
|
||||
if fp.Getx() != 4 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import . "./smart_pointer_templatevariables"
|
||||
|
||||
func main() {
|
||||
d := NewDiffImContainerPtr_D(Create(1234, 5678))
|
||||
|
||||
if d.GetId() != 1234 {
|
||||
panic(0)
|
||||
}
|
||||
//if (d.xyz != 5678):
|
||||
// panic(0)
|
||||
|
||||
d.SetId(4321)
|
||||
//d.xyz = 8765
|
||||
|
||||
if d.GetId() != 4321 {
|
||||
panic(0)
|
||||
}
|
||||
//if (d.xyz != 8765):
|
||||
// panic(0)
|
||||
}
|
||||
19
Examples/test-suite/go/smart_pointer_typedef_runme.go
Normal file
19
Examples/test-suite/go/smart_pointer_typedef_runme.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import . "./smart_pointer_typedef"
|
||||
|
||||
func main() {
|
||||
f := NewFoo()
|
||||
b := NewBar(f)
|
||||
|
||||
b.SetX(3)
|
||||
if b.Getx() != 3 {
|
||||
panic(0)
|
||||
}
|
||||
|
||||
fp := b.X__deref__()
|
||||
fp.SetX(4)
|
||||
if fp.Getx() != 4 {
|
||||
panic(0)
|
||||
}
|
||||
}
|
||||
10
Examples/test-suite/go/sneaky1_runme.go
Normal file
10
Examples/test-suite/go/sneaky1_runme.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package main
|
||||
|
||||
import "./sneaky1"
|
||||
|
||||
func main() {
|
||||
_ = sneaky1.Add(3, 4)
|
||||
_ = sneaky1.Subtract(3, 4)
|
||||
_ = sneaky1.Mul(3, 4)
|
||||
_ = sneaky1.Divide(3, 4)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue