diff options
Diffstat (limited to 'Examples')
287 files changed, 11074 insertions, 2283 deletions
diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 06965fa29..9641103c4 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -69,7 +69,7 @@ IOBJS = $(IWRAP:.i=.@OBJEXT@) CPP_DLLIBS = #-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \ -L/usr/local/lib -lg++ -lstdc++ -lgcc -# Solaris workshop 5.0 +# Solaris workshop 5.0 # CPP_DLLIBS = -L/opt/SUNWspro/lib -lCrun # Symbols used for using shared libraries @@ -159,7 +159,7 @@ tcl_cpp: $(SRCS) # ----------------------------------------------------------------- tcl_clean: - rm -f *_wrap* *~ .~* mytclsh@EXEEXT@ + rm -f *_wrap* *~ .~* mytclsh@EXEEXT@ rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ @@ -296,9 +296,9 @@ python_static_cpp: $(SRCS) $(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \ $(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET) -# ----------------------------------------------------------------- +# ----------------------------------------------------------------- # Running a Python example -# ----------------------------------------------------------------- +# ----------------------------------------------------------------- ifeq (,$(PY3)) PYSCRIPT = runme.py @@ -313,7 +313,7 @@ python_run: $(PYSCRIPT) runme3.py: runme.py cp $< $@ - $(PY2TO3) -w $@ >/dev/null 2>&1 + $(PY2TO3) -w $@ >/dev/null 2>&1 # ----------------------------------------------------------------- # Cleaning the python examples @@ -332,7 +332,7 @@ python_clean: # Make sure these locate your Octave installation OCTAVE_INCLUDE= $(DEFS) @OCTAVEEXT@ -OCTAVE_LIB = +OCTAVE_LIB = # Extra Octave specific dynamic linking options OCTAVE_DLNK = @OCTAVEDYNAMICLINKING@ @@ -548,14 +548,14 @@ mzscheme: $(SRCS) mzscheme_cpp: $(SRCS) $(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACEPATH) $(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS) - $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) + $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS) # ----------------------------------------------------------------- # Cleaning the mzscheme examples # ----------------------------------------------------------------- mzscheme_clean: - rm -f *_wrap* *~ .~* + rm -f *_wrap* *~ .~* rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ @@ -632,7 +632,7 @@ ocaml_static_cpp: $(SRCS) $(OCAMLCORE) $(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACEPATH) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) - $(OCC) -cc '$(CXX)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ + $(OCC) -cc '$(CXX) -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ $(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS) $(OCC) -g -c $(INTERFACE:%.i=%.mli) $(OCC) -g -c $(INTERFACE:%.i=%.ml) @@ -643,13 +643,13 @@ ocaml_static_cpp: $(SRCS) $(INTERFACE:%.i=%.cmo) \ $(PROGFILE:%.ml=%.cmo) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \ - -cclib "$(LIBS)" -cc '$(CXX)' + -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings' ocaml_static_cpp_toplevel: $(SRCS) $(OCAMLCORE) $(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACEPATH) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) - $(OCC) -cc '$(CXX)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ + $(OCC) -cc '$(CXX) -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ $(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS) $(OCC) -g -c $(INTERFACE:%.i=%.mli) $(OCC) -g -c $(INTERFACE:%.i=%.ml) @@ -657,17 +657,17 @@ ocaml_static_cpp_toplevel: $(SRCS) $(OCC) $(OCAMLPP) -c $(PROGFILE) $(NOLINK) || $(OCAMLMKTOP) \ swig.cmo \ - -I $(OCAMLP4WHERE) camlp4o.cma swigp4.cmo \ + -I $(OCAMLP4WHERE) dynlink.cma camlp4o.cma swigp4.cmo \ -g -ccopt -g -cclib -g -custom -o $(TARGET)_top \ $(INTERFACE:%.i=%.cmo) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \ - -cclib "$(LIBS)" -cc '$(CXX)' + -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings' ocaml_dynamic_cpp: $(SRCS) $(OCAMLCORE) $(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACEPATH) cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c) - $(OCC) -cc '$(CXX)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ + $(OCC) -cc '$(CXX) -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \ $(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS) -ccopt -fPIC $(CXXSHARED) $(CFLAGS) -o $(INTERFACE:%.i=%@SO@) \ $(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \ @@ -684,7 +684,7 @@ ocaml_dynamic_cpp: $(SRCS) $(OCC) -cclib -export-dynamic -g -ccopt -g -cclib -g -custom \ -o $(TARGET) \ -package dl -linkpkg \ - $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX)' + $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX) -Wno-write-strings' ocaml_clean: rm -f *_wrap* *~ .~* *.cmo *.cmi $(MLFILE) $(MLFILE)i swig.mli swig.cmi swig.ml swig.cmo swigp4.ml swigp4.cmo @@ -844,7 +844,7 @@ pike_cpp_static: $(SRCS) # ----------------------------------------------------------------- pike_clean: - rm -f *_wrap* *~ .~* mypike@EXEEXT@ + rm -f *_wrap* *~ .~* mypike@EXEEXT@ rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *@SO@ @@ -861,7 +861,7 @@ CHICKEN_CFLAGS = @CHICKENOPTS@ CHICKENOPTS = -quiet CHICKEN_MAIN = -# SWIG produces $(ISRCS) (the C wrapper file) +# SWIG produces $(ISRCS) (the C wrapper file) # and $(CHICKEN_GENERATED_SCHEME) (the Scheme wrapper file): CHICKEN_GENERATED_SCHEME = $(INTERFACE:.i=.scm) CHICKEN_COMPILED_SCHEME = $(INTERFACE:.i=_chicken.c) @@ -1053,12 +1053,12 @@ lua_clean: allegrocl: $(SRCS) $(SWIG) -allegrocl -cwrap $(SWIGOPT) $(INTERFACEPATH) - $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) + $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) allegrocl_cpp: $(SRCS) $(SWIG) -c++ -allegrocl $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) allegrocl_clean: @@ -1087,12 +1087,12 @@ clisp_clean: cffi: $(SRCS) $(SWIG) -cffi $(SWIGOPT) $(INTERFACEPATH) -# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) +# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) # $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) cffi_cpp: $(SRCS) $(SWIG) -c++ -cffi $(SWIGOPT) $(INTERFACEPATH) - $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) cffi_clean: @@ -1106,12 +1106,12 @@ cffi_clean: uffi: $(SRCS) $(SWIG) -uffi $(SWIGOPT) $(INTERFACEPATH) -# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) +# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS) # $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) uffi_cpp: $(SRCS) $(SWIG) -c++ -uffi $(SWIGOPT) $(INTERFACEPATH) -# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) +# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) # $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) uffi_clean: @@ -1241,3 +1241,69 @@ go_clean: rm -f *_wrap* *_gc* .~* runme rm -f core @EXTRA_CLEAN@ rm -f *.@OBJEXT@ *.[568] *.a *@SO@ + +################################################################## +##### D ###### +################################################################## + +DLIBPREFIX = @DLIBPREFIX@ + +ifeq (,$(D_VERSION)) + D_VERSION = @DDEFAULTVERSION@ +endif + +ifeq (2,$(D_VERSION)) + SWIGD = $(SWIG) -d -d2 + DCOMPILER = @D2COMPILER@ +else + SWIGD = $(SWIG) -d + DCOMPILER = @D1COMPILER@ +endif + +ifeq (dmd,$(DCOMPILER)) + # DMD is 32bit only by now + DCFLAGS = -m32 +endif + +# ---------------------------------------------------------------- +# Build a dynamically loadable D wrapper for a C module +# ---------------------------------------------------------------- + +d: $(SRCS) + $(SWIGD) $(SWIGOPT) $(INTERFACEPATH) + $(CC) -c $(CCSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) + $(LDSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO) + +# ---------------------------------------------------------------- +# Build a dynamically loadable D wrapper for a C++ module +# ---------------------------------------------------------------- + +d_cpp: $(SRCS) + $(SWIGD) -c++ $(SWIGOPT) $(INTERFACEPATH) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) + $(CXXSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO) + +# ---------------------------------------------------------------- +# Compile D files +# ---------------------------------------------------------------- + +# Clear the DFLAGS environment variable for the compiler call itself +# to work around a discrepancy in argument handling between DMD and LDC. +d_compile: $(SRCS) + DFLAGS="" $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS) + +# ----------------------------------------------------------------- +# Run D example +# ----------------------------------------------------------------- + +d_run: + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme + +# ----------------------------------------------------------------- +# Clean the D examples +# ----------------------------------------------------------------- + +d_clean: + rm -f *_wrap* *~ .~* runme runme.exe `find . -name \*.d | grep -v runme.d` + rm -f core @EXTRA_CLEAN@ + rm -f *.@OBJEXT@ *@SO@ diff --git a/Examples/d/callback/Makefile b/Examples/d/callback/Makefile new file mode 100644 index 000000000..b5808cf0d --- /dev/null +++ b/Examples/d/callback/Makefile @@ -0,0 +1,30 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/callback/d1/runme.d b/Examples/d/callback/d1/runme.d new file mode 100644 index 000000000..e34e09603 --- /dev/null +++ b/Examples/d/callback/d1/runme.d @@ -0,0 +1,36 @@ +module runme; + +import tango.io.Stdout; +import example; + +public class DCallback : Callback { + public override void run() { + Stdout( "DCallback.run()" ).newline; + } +} + +void main() { + auto caller = new Caller(); + + Stdout( "Adding and calling a normal C++ callback" ).newline; + Stdout( "----------------------------------------" ).newline; + { + scope auto callback = new Callback(); + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + Stdout.newline; + Stdout( "Adding and calling a D callback" ).newline; + Stdout( "-------------------------------" ).newline; + { + scope auto callback = new DCallback(); + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + Stdout.newline; + Stdout( "D exit" ).newline; +} diff --git a/Examples/d/callback/d2/runme.d b/Examples/d/callback/d2/runme.d new file mode 100644 index 000000000..88ffcdefd --- /dev/null +++ b/Examples/d/callback/d2/runme.d @@ -0,0 +1,36 @@ +module runme; + +import std.stdio; +import example; + +public class DCallback : Callback { + public override void run() { + writeln( "DCallback.run()" ); + } +} + +void main() { + auto caller = new Caller(); + + writeln( "Adding and calling a normal C++ callback" ); + writeln( "----------------------------------------" ); + { + scope auto callback = new Callback(); + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + writeln(); + writeln( "Adding and calling a D callback" ); + writeln( "-------------------------------" ); + { + scope auto callback = new DCallback(); + caller.setCallback(callback); + caller.call(); + caller.resetCallback(); + } + + writeln(); + writeln( "D exit" ); +} diff --git a/Examples/d/callback/example.cxx b/Examples/d/callback/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/d/callback/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/d/callback/example.h b/Examples/d/callback/example.h new file mode 100644 index 000000000..38d25a043 --- /dev/null +++ b/Examples/d/callback/example.h @@ -0,0 +1,24 @@ +/* File : example.h */ + +#include <cstdio> +#include <iostream> + +class Callback { +public: + virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; } + virtual void run() { std::cout << "Callback::run()" << std::endl; } +}; + + +class Caller { +private: + Callback *_callback; +public: + Caller(): _callback(0) {} + ~Caller() { delCallback(); } + void delCallback() { delete _callback; _callback = 0; } + void setCallback(Callback *cb) { delCallback(); _callback = cb; } + void resetCallback() { _callback = 0; } + void call() { if (_callback) _callback->run(); } +}; + diff --git a/Examples/d/callback/example.i b/Examples/d/callback/example.i new file mode 100644 index 000000000..90beda01a --- /dev/null +++ b/Examples/d/callback/example.i @@ -0,0 +1,13 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_string.i" + +/* turn on director wrapping Callback */ +%feature("director") Callback; + +%include "example.h" + diff --git a/Examples/d/check.list b/Examples/d/check.list new file mode 100644 index 000000000..010e7bbfc --- /dev/null +++ b/Examples/d/check.list @@ -0,0 +1,9 @@ +# See top-level Makefile.in. +callback +class +constants +enum +extend +funcptr +simple +variables diff --git a/Examples/d/class/Makefile b/Examples/d/class/Makefile new file mode 100644 index 000000000..b5808cf0d --- /dev/null +++ b/Examples/d/class/Makefile @@ -0,0 +1,30 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/class/d1/runme.d b/Examples/d/class/d1/runme.d new file mode 100644 index 000000000..b0c4263a2 --- /dev/null +++ b/Examples/d/class/d1/runme.d @@ -0,0 +1,58 @@ +// This example illustrates how C++ classes can be used from D using SWIG. +// The D class gets mapped onto the C++ class and behaves as if it is a D class. +module runme; + +import tango.io.Stdout; +import example; + +void main() { + // ----- Object creation ----- + + Stdout( "Creating some objects:" ).newline; + + { + scope Square s = new Square(10); + scope Circle c = new Circle(10); + + // ----- Access a static member ----- + Stdout.format( "{} shapes were created.", Shape.nshapes ).newline; + + // ----- Member data access ----- + + // Notice how we can do this using functions specific to + // the 'Circle' class. + c.x = 20; + c.y = 30; + + // Now use the same functions in the base class + Shape shape = s; + shape.x = -10; + shape.y = 5; + + Stdout( "\nHere is their current position:" ).newline; + Stdout.format( " Circle = ( {}, {} )", c.x, c.y ).newline; + Stdout.format( " Square = ( {}, {} )", s.x, s.y ).newline; + + // ----- Call some methods ----- + + Stdout( "\nHere are some properties of the shapes:" ).newline; + Shape[] shapes = [ cast(Shape) c, cast(Shape) s ]; + foreach ( currentShape; shapes ) + { + Stdout.format( " {}", currentShape.classinfo.name ).newline; + Stdout.format( " area = {}", currentShape.area() ).newline; + Stdout.format( " perimeter = {}", currentShape.perimeter() ).newline; + } + + // Notice how the area() and perimeter() functions really + // invoke the appropriate virtual method on each object. + + // ----- Delete everything ----- + Stdout( "\nGuess I'll clean up now:" ).newline; + // Note: when this using scope is exited the D destructors are called which + // in turn call the C++ destructors. + } + + Stdout.format( "{} shapes remain", Shape.nshapes ).newline; + Stdout( "\nGoodbye!" ).newline; +} diff --git a/Examples/d/class/d2/runme.d b/Examples/d/class/d2/runme.d new file mode 100644 index 000000000..2e86c5fc7 --- /dev/null +++ b/Examples/d/class/d2/runme.d @@ -0,0 +1,58 @@ +// This example illustrates how C++ classes can be used from D using SWIG. +// The D class gets mapped onto the C++ class and behaves as if it is a D class. +module runme; + +import std.stdio; +import example; + +void main() { + // ----- Object creation ----- + + writeln( "Creating some objects:" ); + + { + scope Square s = new Square(10); + scope Circle c = new Circle(10); + + // ----- Access a static member ----- + writefln( "%s shapes were created.", Shape.nshapes ); + + // ----- Member data access ----- + + // Notice how we can do this using functions specific to + // the 'Circle' class. + c.x = 20; + c.y = 30; + + // Now use the same functions in the base class + Shape shape = s; + shape.x = -10; + shape.y = 5; + + writeln( "\nHere is their current position:" ); + writefln( " Circle = ( %s, %s )", c.x, c.y ); + writefln( " Square = ( %s, %s )", s.x, s.y ); + + // ----- Call some methods ----- + + writeln( "\nHere are some properties of the shapes:" ); + Shape[] shapes = [ cast(Shape) c, cast(Shape) s ]; + foreach ( currentShape; shapes ) + { + writefln( " %s", currentShape.classinfo.name ); + writefln( " area = %s", currentShape.area() ); + writefln( " perimeter = %s", currentShape.perimeter() ); + } + + // Notice how the area() and perimeter() functions really + // invoke the appropriate virtual method on each object. + + // ----- Delete everything ----- + writeln( "\nGuess I'll clean up now:" ); + // Note: when this using scope is exited the D destructors are called which + // in turn call the C++ destructors. + } + + writefln( "%s shapes remain", Shape.nshapes ); + writeln( "\nGoodbye!" ); +} diff --git a/Examples/d/class/example.cxx b/Examples/d/class/example.cxx new file mode 100644 index 000000000..1e8e203dd --- /dev/null +++ b/Examples/d/class/example.cxx @@ -0,0 +1,28 @@ +/* File : example.c */ + +#include "example.h" +#define M_PI 3.14159265358979323846 + +/* Move the shape to a new location */ +void Shape::move(double dx, double dy) { + x += dx; + y += dy; +} + +int Shape::nshapes = 0; + +double Circle::area(void) { + return M_PI*radius*radius; +} + +double Circle::perimeter(void) { + return 2*M_PI*radius; +} + +double Square::area(void) { + return width*width; +} + +double Square::perimeter(void) { + return 4*width; +} diff --git a/Examples/d/class/example.h b/Examples/d/class/example.h new file mode 100644 index 000000000..0d4527e92 --- /dev/null +++ b/Examples/d/class/example.h @@ -0,0 +1,34 @@ +/* File : example.h */ + +class Shape { +public: + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + }; + double x, y; + void move(double dx, double dy); + virtual double area(void) = 0; + virtual double perimeter(void) = 0; + static int nshapes; +}; + +class Circle : public Shape { +private: + double radius; +public: + Circle(double r) : radius(r) { }; + virtual double area(void); + virtual double perimeter(void); +}; + +class Square : public Shape { +private: + double width; +public: + Square(double w) : width(w) { }; + virtual double area(void); + virtual double perimeter(void); +}; diff --git a/Examples/d/class/example.i b/Examples/d/class/example.i new file mode 100644 index 000000000..75700b305 --- /dev/null +++ b/Examples/d/class/example.i @@ -0,0 +1,10 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" + diff --git a/Examples/d/constants/Makefile b/Examples/d/constants/Makefile new file mode 100644 index 000000000..412055243 --- /dev/null +++ b/Examples/d/constants/Makefile @@ -0,0 +1,30 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ example_wrap.c +EXTRA_LDFLAGS = example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/constants/d1/runme.d b/Examples/d/constants/d1/runme.d new file mode 100644 index 000000000..47362cbf3 --- /dev/null +++ b/Examples/d/constants/d1/runme.d @@ -0,0 +1,28 @@ +module runme; + +import tango.io.Stdout; +static import example; + +void main() { + Stdout.formatln("ICONST = {} (should be 42)", example.ICONST); + Stdout.formatln("FCONST = {} (should be 2.18)", example.FCONST); + Stdout.formatln("CCONST = {} (should be 'x')", example.CCONST); + Stdout.formatln("CCONST2 = {} (this should be on a new line)", example.CCONST2); + Stdout.formatln("SCONST = {} (should be 'Hello World')", example.SCONST); + Stdout.formatln("SCONST2 = {} (should be '\"Hello World\"')", example.SCONST2); + Stdout.formatln("EXPR = {} (should be 48.55)", example.EXPR); + Stdout.formatln("iconst = {} (should be 37)", example.iconst); + Stdout.formatln("fconst = {} (should be 3.14)", example.fconst); + + static if (is(typeof(example.EXTERN))) { + Stdout.formatln("EXTERN should not be defined, but is: {}.", example.EXTERN ); + } else { + Stdout.formatln("EXTERN isn't defined (good)"); + } + + static if (is(typeof(example.FOO))) { + Stdout.formatln("FOO should not be defined, but is: {}.", example.FOO); + } else { + Stdout.formatln("FOO isn't defined (good)"); + } +} diff --git a/Examples/d/constants/d2/runme.d b/Examples/d/constants/d2/runme.d new file mode 100644 index 000000000..4be510d16 --- /dev/null +++ b/Examples/d/constants/d2/runme.d @@ -0,0 +1,28 @@ +module runme; + +import std.stdio; +static import example; + +void main() { + writefln("ICONST = %s (should be 42)", example.ICONST); + writefln("FCONST = %s (should be 2.1828)", example.FCONST); + writefln("CCONST = %s (should be 'x')", example.CCONST); + writefln("CCONST2 = %s (this should be on a new line)", example.CCONST2); + writefln("SCONST = %s (should be 'Hello World')", example.SCONST); + writefln("SCONST2 = %s (should be '\"Hello World\"')", example.SCONST2); + writefln("EXPR = %s (should be 48.5484)", example.EXPR); + writefln("iconst = %s (should be 37)", example.iconst); + writefln("fconst = %s (should be 3.14)", example.fconst); + + static if (is(typeof(example.EXTERN))) { + writefln("EXTERN should not be defined, but is: %s.", example.EXTERN ); + } else { + writeln("EXTERN isn't defined (good)"); + } + + static if (is(typeof(example.FOO))) { + writefln("FOO should not be defined, but is: %s.", example.FOO); + } else { + writeln("FOO isn't defined (good)"); + } +} diff --git a/Examples/d/constants/example.d b/Examples/d/constants/example.d new file mode 100644 index 000000000..7448d0ad9 --- /dev/null +++ b/Examples/d/constants/example.d @@ -0,0 +1,23 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 1.3.41 + * + * Do not make changes to this file unless you know what you are doing--modify + * the SWIG interface file instead. + * ----------------------------------------------------------------------------- */ + +module example; + +static import example_wrap; + +static import tango.stdc.stringz; + +public const int ICONST = 42; +public const double FCONST = 2.1828; +public const char CCONST = 'x'; +public const char CCONST2 = '\n'; +public const char[] SCONST = "Hello World"; +public const char[] SCONST2 = "\"Hello World\""; +public const double EXPR = 42+3*(2.1828); +public const int iconst = 37; +public const double fconst = 3.14; diff --git a/Examples/d/constants/example.i b/Examples/d/constants/example.i new file mode 100644 index 000000000..edeb258cd --- /dev/null +++ b/Examples/d/constants/example.i @@ -0,0 +1,32 @@ +/* File : example.i */ +%module example + +/* Force the generated D code to use the C constant values rather than + retrieving them at runtime. You can also try disabling the feature and + compare the generated code. */ +%dmanifestconst; + + +/* A few preprocessor macros */ + +#define ICONST 42 +#define FCONST 2.1828 +#define CCONST 'x' +#define CCONST2 '\n' +#define SCONST "Hello World" +#define SCONST2 "\"Hello World\"" + +/* This should work just fine */ +#define EXPR ICONST + 3*(FCONST) + +/* This shouldn't do anything */ +#define EXTERN extern + +/* Neither should this (BAR isn't defined) */ +#define FOO (ICONST + BAR) + + +/* The following directives also produce constants */ + +%constant int iconst = 37; +%constant double fconst = 3.14; diff --git a/Examples/d/enum/Makefile b/Examples/d/enum/Makefile new file mode 100644 index 000000000..b5808cf0d --- /dev/null +++ b/Examples/d/enum/Makefile @@ -0,0 +1,30 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/enum/d1/runme.d b/Examples/d/enum/d1/runme.d new file mode 100644 index 000000000..d986986d1 --- /dev/null +++ b/Examples/d/enum/d1/runme.d @@ -0,0 +1,28 @@ +module runme; + +import tango.io.Stdout; +import example; + +void main() { + Stdout( "Printing out some enum values:" ).newline; + Stdout(" color:").newline; + Stdout.formatln(" {} = {}", color.RED, cast(int)color.RED); + Stdout.formatln(" {} = {}", color.BLUE, cast(int)color.BLUE); + Stdout.formatln(" {} = {}", color.GREEN, cast(int)color.GREEN); + + Stdout("\n Foo.speed:").newline; + Stdout.formatln(" Foo.{} = {}", Foo.speed.IMPULSE, cast(int)Foo.speed.IMPULSE); + Stdout.formatln(" Foo.{} = {}", Foo.speed.WARP, cast(int)Foo.speed.WARP); + Stdout.formatln(" Foo.{} = {}", Foo.speed.LUDICROUS , cast(int)Foo.speed.LUDICROUS); + + Stdout("\nTesting use of enums with functions:").newline; + example.enum_test(color.RED, Foo.speed.IMPULSE); + example.enum_test(color.BLUE, Foo.speed.WARP); + example.enum_test(color.GREEN, Foo.speed.LUDICROUS); + + Stdout( "\nTesting use of enum with class method:" ).newline; + scope f = new Foo(); + f.enum_test(Foo.speed.IMPULSE); + f.enum_test(Foo.speed.WARP); + f.enum_test(Foo.speed.LUDICROUS); +} diff --git a/Examples/d/enum/d2/runme.d b/Examples/d/enum/d2/runme.d new file mode 100644 index 000000000..acaec8ae8 --- /dev/null +++ b/Examples/d/enum/d2/runme.d @@ -0,0 +1,28 @@ +module runme; + +import std.stdio; +import example; + +void main() { + writeln( "Printing out some enum values:" ); + writeln(" color:"); + writefln(" %s = %s", color.RED, cast(int)color.RED); + writefln(" %s = %s", color.BLUE, cast(int)color.BLUE); + writefln(" %s = %s", color.GREEN, cast(int)color.GREEN); + + writeln("\n Foo.speed:"); + writefln(" Foo.%s = %s", Foo.speed.IMPULSE, cast(int)Foo.speed.IMPULSE); + writefln(" Foo.%s = %s", Foo.speed.WARP, cast(int)Foo.speed.WARP); + writefln(" Foo.%s = %s", Foo.speed.LUDICROUS , cast(int)Foo.speed.LUDICROUS); + + writeln("\nTesting use of enums with functions:"); + example.enum_test(color.RED, Foo.speed.IMPULSE); + example.enum_test(color.BLUE, Foo.speed.WARP); + example.enum_test(color.GREEN, Foo.speed.LUDICROUS); + + writeln( "\nTesting use of enum with class method:" ); + scope f = new Foo(); + f.enum_test(Foo.speed.IMPULSE); + f.enum_test(Foo.speed.WARP); + f.enum_test(Foo.speed.LUDICROUS); +} diff --git a/Examples/d/enum/example.cxx b/Examples/d/enum/example.cxx new file mode 100644 index 000000000..df7bb6328 --- /dev/null +++ b/Examples/d/enum/example.cxx @@ -0,0 +1,37 @@ +/* File : example.cxx */ + +#include "example.h" +#include <stdio.h> + +void Foo::enum_test(speed s) { + if (s == IMPULSE) { + printf("IMPULSE speed\n"); + } else if (s == WARP) { + printf("WARP speed\n"); + } else if (s == LUDICROUS) { + printf("LUDICROUS speed\n"); + } else { + printf("Unknown speed\n"); + } +} + +void enum_test(color c, Foo::speed s) { + if (c == RED) { + printf("color = RED, "); + } else if (c == BLUE) { + printf("color = BLUE, "); + } else if (c == GREEN) { + printf("color = GREEN, "); + } else { + printf("color = Unknown color!, "); + } + if (s == Foo::IMPULSE) { + printf("speed = IMPULSE speed\n"); + } else if (s == Foo::WARP) { + printf("speed = WARP speed\n"); + } else if (s == Foo::LUDICROUS) { + printf("speed = LUDICROUS speed\n"); + } else { + printf("speed = Unknown speed!\n"); + } +} diff --git a/Examples/d/enum/example.h b/Examples/d/enum/example.h new file mode 100644 index 000000000..9119cd9fc --- /dev/null +++ b/Examples/d/enum/example.h @@ -0,0 +1,13 @@ +/* File : example.h */ + +enum color { RED, BLUE, GREEN }; + +class Foo { + public: + Foo() { } + enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 }; + void enum_test(speed s); +}; + +void enum_test(color c, Foo::speed s); + diff --git a/Examples/d/enum/example.i b/Examples/d/enum/example.i new file mode 100644 index 000000000..23ee8a822 --- /dev/null +++ b/Examples/d/enum/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ + +%include "example.h" + diff --git a/Examples/d/extend/Makefile b/Examples/d/extend/Makefile new file mode 100644 index 000000000..b5808cf0d --- /dev/null +++ b/Examples/d/extend/Makefile @@ -0,0 +1,30 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/extend/d1/runme.d b/Examples/d/extend/d1/runme.d new file mode 100644 index 000000000..96501d1a4 --- /dev/null +++ b/Examples/d/extend/d1/runme.d @@ -0,0 +1,75 @@ +/// This file illustrates the cross language polymorphism using directors. +module runme; + +import example; +import tango.io.Stdout; + +// CEO class, which overrides Employee.getPosition(). +class CEO : Manager { +public: + this( char[] name ) { + super( name ); + } + + override char[] getPosition() { + return "CEO"; + } + + // Public method to stop the SWIG proxy base class from thinking it owns the underlying C++ memory. + void disownMemory() { + swigCMemOwn = false; + } +} + +void main() { + // Create an instance of CEO, a class derived from the D proxy of the + // underlying C++ class. The calls to getName() and getPosition() are standard, + // the call to getTitle() uses the director wrappers to call CEO.getPosition(). + + auto e = new CEO( "Alice" ); + Stdout.formatln( "{} is a {}.", e.getName(), e.getPosition() ); + Stdout.formatln( "Just call her '{}'.", e.getTitle() ); + Stdout( "----------------------" ).newline; + + { + // Create a new EmployeeList instance. This class does not have a C++ + // director wrapper, but can be used freely with other classes that do. + scope auto list = new EmployeeList(); + + // EmployeeList owns its items, so we must surrender ownership of objects we add. + e.disownMemory(); + list.addEmployee(e); + Stdout( "----------------------" ).newline; + + // Now we access the first four items in list (three are C++ objects that + // EmployeeList's constructor adds, the last is our CEO). The virtual + // methods of all these instances are treated the same. For items 0, 1, and + // 2, all methods resolve in C++. For item 3, our CEO, getTitle calls + // getPosition which resolves in D. The call to getPosition is + // slightly different, however, because of the overidden getPosition() call, since + // now the object reference has been "laundered" by passing through + // EmployeeList as an Employee*. Previously, D resolved the call + // immediately in CEO, but now D thinks the object is an instance of + // class Employee. So the call passes through the + // Employee proxy class and on to the C wrappers and C++ director, + // eventually ending up back at the D CEO implementation of getPosition(). + // The call to getTitle() for item 3 runs the C++ Employee::getTitle() + // method, which in turn calls getPosition(). This virtual method call + // passes down through the C++ director class to the D implementation + // in CEO. All this routing takes place transparently. + + Stdout( "(position, title) for items 0-3:" ).newline; + Stdout.formatln( " {}, '{}'", list.getItem(0).getPosition(), list.getItem(0).getTitle() ); + Stdout.formatln( " {}, '{}'", list.getItem(1).getPosition(), list.getItem(1).getTitle() ); + Stdout.formatln( " {}, '{}'", list.getItem(2).getPosition(), list.getItem(2).getTitle() ); + Stdout.formatln( " {}, '{}'", list.getItem(3).getPosition(), list.getItem(3).getTitle() ); + Stdout( "----------------------" ).newline; + + // All Employees will be destroyed when the EmployeeList goes out of scope, + // including the CEO instance. + } + Stdout( "----------------------" ).newline; + + // All done. + Stdout( "Exiting cleanly from D code." ).newline; +} diff --git a/Examples/d/extend/d2/runme.d b/Examples/d/extend/d2/runme.d new file mode 100644 index 000000000..1ea6dfd21 --- /dev/null +++ b/Examples/d/extend/d2/runme.d @@ -0,0 +1,75 @@ +/// This file illustrates the cross language polymorphism using directors. +module runme; + +import std.stdio; +import example; + +// CEO class, which overrides Employee.getPosition(). +class CEO : Manager { +public: + this( string name ) { + super( name ); + } + + override string getPosition() const { + return "CEO"; + } + + // Public method to stop the SWIG proxy base class from thinking it owns the underlying C++ memory. + void disownMemory() { + swigCMemOwn = false; + } +} + +void main() { + // Create an instance of CEO, a class derived from the D proxy of the + // underlying C++ class. The calls to getName() and getPosition() are standard, + // the call to getTitle() uses the director wrappers to call CEO.getPosition(). + + auto e = new CEO( "Alice" ); + writefln( "%s is a %s.", e.getName(), e.getPosition() ); + writefln( "Just call her '%s'.", e.getTitle() ); + writeln( "----------------------" ); + + { + // Create a new EmployeeList instance. This class does not have a C++ + // director wrapper, but can be used freely with other classes that do. + scope auto list = new EmployeeList(); + + // EmployeeList owns its items, so we must surrender ownership of objects we add. + e.disownMemory(); + list.addEmployee(e); + writeln( "----------------------" ); + + // Now we access the first four items in list (three are C++ objects that + // EmployeeList's constructor adds, the last is our CEO). The virtual + // methods of all these instances are treated the same. For items 0, 1, and + // 2, all methods resolve in C++. For item 3, our CEO, getTitle calls + // getPosition which resolves in D. The call to getPosition is + // slightly different, however, because of the overidden getPosition() call, since + // now the object reference has been "laundered" by passing through + // EmployeeList as an Employee*. Previously, D resolved the call + // immediately in CEO, but now D thinks the object is an instance of + // class Employee. So the call passes through the + // Employee proxy class and on to the C wrappers and C++ director, + // eventually ending up back at the D CEO implementation of getPosition(). + // The call to getTitle() for item 3 runs the C++ Employee::getTitle() + // method, which in turn calls getPosition(). This virtual method call + // passes down through the C++ director class to the D implementation + // in CEO. All this routing takes place transparently. + + writeln( "(position, title) for items 0-3:" ); + writefln( " %s, '%s'", list.getItem(0).getPosition(), list.getItem(0).getTitle() ); + writefln( " %s, '%s'", list.getItem(1).getPosition(), list.getItem(1).getTitle() ); + writefln( " %s, '%s'", list.getItem(2).getPosition(), list.getItem(2).getTitle() ); + writefln( " %s, '%s'", list.getItem(3).getPosition(), list.getItem(3).getTitle() ); + writeln( "----------------------" ); + + // All Employees will be destroyed when the EmployeeList goes out of scope, + // including the CEO instance. + } + writeln( "----------------------" ); + + // All done. + writeln( "Exiting cleanly from D code." ); +} diff --git a/Examples/d/extend/example.cxx b/Examples/d/extend/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/d/extend/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/d/extend/example.h b/Examples/d/extend/example.h new file mode 100644 index 000000000..7ad93fbc1 --- /dev/null +++ b/Examples/d/extend/example.h @@ -0,0 +1,56 @@ +/* File : example.h */ + +#include <cstdio> +#include <iostream> +#include <vector> +#include <string> +#include <cmath> + +class Employee { +private: + std::string name; +public: + Employee(const char* n): name(n) {} + virtual std::string getTitle() { return getPosition() + " " + getName(); } + virtual std::string getName() { return name; } + virtual std::string getPosition() const { return "Employee"; } + virtual ~Employee() { printf("~Employee() @ %p\n", this); } +}; + + +class Manager: public Employee { +public: + Manager(const char* n): Employee(n) {} + virtual std::string getPosition() const { return "Manager"; } +}; + + +class EmployeeList { + std::vector<Employee*> list; +public: + EmployeeList() { + list.push_back(new Employee("Bob")); + list.push_back(new Employee("Jane")); + list.push_back(new Manager("Ted")); + } + void addEmployee(Employee *p) { + list.push_back(p); + std::cout << "New employee added. Current employees are:" << std::endl; + std::vector<Employee*>::iterator i; + for (i=list.begin(); i!=list.end(); i++) { + std::cout << " " << (*i)->getTitle() << std::endl; + } + } + const Employee *getItem(int i) { + return list[i]; + } + ~EmployeeList() { + std::vector<Employee*>::iterator i; + std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; + for (i=list.begin(); i!=list.end(); i++) { + delete *i; + } + std::cout << "~EmployeeList empty." << std::endl; + } +}; + diff --git a/Examples/d/extend/example.i b/Examples/d/extend/example.i new file mode 100644 index 000000000..0647e1319 --- /dev/null +++ b/Examples/d/extend/example.i @@ -0,0 +1,14 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_string.i" + +/* turn on director wrapping for Manager */ +%feature("director") Employee; +%feature("director") Manager; + +%include "example.h" + diff --git a/Examples/d/funcptr/Makefile b/Examples/d/funcptr/Makefile new file mode 100644 index 000000000..09efa8d88 --- /dev/null +++ b/Examples/d/funcptr/Makefile @@ -0,0 +1,30 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.c example_wrap.c +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/funcptr/d1/runme.d b/Examples/d/funcptr/d1/runme.d new file mode 100644 index 000000000..1461c1546 --- /dev/null +++ b/Examples/d/funcptr/d1/runme.d @@ -0,0 +1,42 @@ +module runme; + +import tango.io.Stdout; +static import example; + +extern(C) int add(int a, int b) { + return a + b; +} + +extern(C) int sub(int a, int b) { + return a - b; +} + +extern(C) int mul(int a, int b) { + return a * b; +} + +void main() { + int a = 37; + int b = 42; + + Stdout( "a = " )( a ).newline; + Stdout( "b = " )( b ).newline; + + Stdout( "Trying some C callback functions:" ).newline; + Stdout( " ADD(a,b) = " )( example.do_op( a, b, example.ADD ) ).newline; + Stdout( " SUB(a,b) = " )( example.do_op( a, b, example.SUB ) ).newline; + Stdout( " MUL(a,b) = " )( example.do_op( a, b, example.MUL ) ).newline; + + version (LDC) { + // Currently, there is no way to specify the calling convention for + // function pointer parameters in D, but LDC does strict typechecking for + // them (which is reasonable, but not covered by the language spec yet). + // As a result, there is no way to make the code below compile with LDC at + // the moment, so just skip it. + } else { + Stdout( "Now the same with callback functions defined in D:" ).newline; + Stdout( " add(a,b) = " )( example.do_op( a, b, &add ) ).newline; + Stdout( " sub(a,b) = " )( example.do_op( a, b, &sub ) ).newline; + Stdout( " mul(a,b) = " )( example.do_op( a, b, &mul ) ).newline; + } +} diff --git a/Examples/d/funcptr/d2/runme.d b/Examples/d/funcptr/d2/runme.d new file mode 100644 index 000000000..929911d6c --- /dev/null +++ b/Examples/d/funcptr/d2/runme.d @@ -0,0 +1,34 @@ +module runme; + +import std.stdio; +static import example; + +extern(C) int add(int a, int b) { + return a + b; +} + +extern(C) int sub(int a, int b) { + return a - b; +} + +extern(C) int mul(int a, int b) { + return a * b; +} + +void main() { + int a = 37; + int b = 42; + + writefln( "a = %s", a ); + writefln( "b = %s", b ); + + writeln( "Trying some C callback functions:" ); + writefln( " ADD(a,b) = %s", example.do_op( a, b, example.ADD ) ); + writefln( " SUB(a,b) = %s", example.do_op( a, b, example.SUB ) ); + writefln( " MUL(a,b) = %s", example.do_op( a, b, example.MUL ) ); + + writeln( "Now the same with callback functions defined in D:" ); + writefln( " add(a,b) = %s", example.do_op( a, b, &add ) ); + writefln( " sub(a,b) = %s", example.do_op( a, b, &sub ) ); + writefln( " mul(a,b) = %s", example.do_op( a, b, &mul ) ); +} diff --git a/Examples/d/funcptr/example.c b/Examples/d/funcptr/example.c new file mode 100644 index 000000000..5c4a3dabf --- /dev/null +++ b/Examples/d/funcptr/example.c @@ -0,0 +1,19 @@ +/* File : example.c */ + +int do_op(int a, int b, int (*op)(int,int)) { + return (*op)(a,b); +} + +int add(int a, int b) { + return a+b; +} + +int sub(int a, int b) { + return a-b; +} + +int mul(int a, int b) { + return a*b; +} + +int (*funcvar)(int,int) = add; diff --git a/Examples/d/funcptr/example.h b/Examples/d/funcptr/example.h new file mode 100644 index 000000000..9936e24fc --- /dev/null +++ b/Examples/d/funcptr/example.h @@ -0,0 +1,9 @@ +/* file: example.h */ + +extern int do_op(int,int, int (*op)(int,int)); +extern int add(int,int); +extern int sub(int,int); +extern int mul(int,int); + +extern int (*funcvar)(int,int); + diff --git a/Examples/d/funcptr/example.i b/Examples/d/funcptr/example.i new file mode 100644 index 000000000..8b3bef678 --- /dev/null +++ b/Examples/d/funcptr/example.i @@ -0,0 +1,16 @@ +/* File : example.i */ +%module example +%{ +#include "example.h" +%} + +/* Wrap a function taking a pointer to a function */ +extern int do_op(int a, int b, int (*op)(int, int)); + +/* Now install a bunch of "ops" as constants */ +%constant int (*ADD)(int,int) = add; +%constant int (*SUB)(int,int) = sub; +%constant int (*MUL)(int,int) = mul; + +extern int (*funcvar)(int,int); + diff --git a/Examples/d/simple/Makefile b/Examples/d/simple/Makefile new file mode 100644 index 000000000..ae173a566 --- /dev/null +++ b/Examples/d/simple/Makefile @@ -0,0 +1,30 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.c example_wrap.c +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/simple/d1/runme.d b/Examples/d/simple/d1/runme.d new file mode 100644 index 000000000..1293f1839 --- /dev/null +++ b/Examples/d/simple/d1/runme.d @@ -0,0 +1,27 @@ +module runme; + +import tango.io.Stdout; +static import example; + +void main() { + /* + * Call our gcd() function. + */ + int x = 42; + int y = 105; + int g = example.gcd( x, y ); + Stdout.format( "The gcd of {} and {} is {}.", x, y, g ).newline; + + /* + * Manipulate the Foo global variable. + */ + + // Output its current value + Stdout.format( "Foo = {}", example.Foo ).newline; + + // Change its value + example.Foo = 3.1415926; + + // See if the change took effect + Stdout.format( "Foo = {}", example.Foo ).newline; +} diff --git a/Examples/d/simple/d2/runme.d b/Examples/d/simple/d2/runme.d new file mode 100644 index 000000000..7f278923b --- /dev/null +++ b/Examples/d/simple/d2/runme.d @@ -0,0 +1,27 @@ +module runme; + +import std.stdio; +static import example; + +void main() { + /* + * Call our gcd() function. + */ + int x = 42; + int y = 105; + int g = example.gcd(x, y); + writefln("The gcd of %s and %s is %s.", x, y, g); + + /* + * Manipulate the Foo global variable. + */ + + // Output its current value + writefln("Foo = %s", example.Foo); + + // Change its value + example.Foo = 3.1415926; + + // See if the change took effect + writefln("Foo = %s", example.Foo); +} diff --git a/Examples/d/simple/example.c b/Examples/d/simple/example.c new file mode 100644 index 000000000..1c2af789c --- /dev/null +++ b/Examples/d/simple/example.c @@ -0,0 +1,18 @@ +/* File : example.c */ + +/* A global variable */ +double Foo = 3.0; + +/* Compute the greatest common divisor of positive integers */ +int gcd(int x, int y) { + int g; + g = y; + while (x > 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + + diff --git a/Examples/d/simple/example.i b/Examples/d/simple/example.i new file mode 100644 index 000000000..24093b9bf --- /dev/null +++ b/Examples/d/simple/example.i @@ -0,0 +1,7 @@ +/* File : example.i */ +%module example + +%inline %{ +extern int gcd(int x, int y); +extern double Foo; +%} diff --git a/Examples/d/variables/Makefile b/Examples/d/variables/Makefile new file mode 100644 index 000000000..ae173a566 --- /dev/null +++ b/Examples/d/variables/Makefile @@ -0,0 +1,30 @@ +ifeq (2,$(D_VERSION)) + WORKING_DIR = d2/ +else + WORKING_DIR = d1/ +endif + +TOP = ../../.. +SWIG = $(TOP)/../preinst-swig +EXTRA_CFLAGS = -I../ ../example.c example_wrap.c +EXTRA_LDFLAGS = example.o example_wrap.o +TARGET = example_wrap +SWIGOPT = +DSRCS = *.d +DFLAGS = -ofrunme + + +all:: d + +d:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \ + $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile + +clean:: + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_clean + +check: all + cd $(WORKING_DIR); \ + $(MAKE) -f $(TOP)/Makefile d_run diff --git a/Examples/d/variables/d1/runme.d b/Examples/d/variables/d1/runme.d new file mode 100644 index 000000000..35c896bdc --- /dev/null +++ b/Examples/d/variables/d1/runme.d @@ -0,0 +1,71 @@ +// This example illustrates global variable access from C#. +module runme; + +import tango.io.Stdout; +static import example; + +void main() { + // Try to set the values of some global variables + example.ivar = 42; + example.svar = -31000; + example.lvar = 65537; + example.uivar = 123456; + example.usvar = 61000; + example.ulvar = 654321; + example.scvar = -13; + example.ucvar = 251; + example.cvar = 'S'; + example.fvar = 3.14159f; + example.dvar = 2.1828; + example.strvar = "Hello World"; + example.iptrvar = example.new_int(37); + example.ptptr = example.new_Point(37,42); + example.name = "Bill"; + + // Now print out the values of the variables + Stdout.formatln( "Variables (printed from D):" ); + Stdout.formatln( "ivar = {}", example.ivar ); + Stdout.formatln( "svar = {}", example.svar ); + Stdout.formatln( "lvar = {}", example.lvar ); + Stdout.formatln( "uivar = {}", example.uivar ); + Stdout.formatln( "usvar = {}", example.usvar ); + Stdout.formatln( "ulvar = {}", example.ulvar ); + Stdout.formatln( "scvar = {}", example.scvar ); + Stdout.formatln( "ucvar = {}", example.ucvar ); + Stdout.formatln( "fvar = {}", example.fvar ); + Stdout.formatln( "dvar = {}", example.dvar ); + Stdout.formatln( "cvar = {}", example.cvar ); + Stdout.formatln( "strvar = {}", example.strvar ); + Stdout.formatln( "cstrvar = {}", example.cstrvar ); + Stdout.formatln( "iptrvar = {}", example.iptrvar ); + Stdout.formatln( "name = {}", example.name ); + Stdout.formatln( "ptptr = {} {}", example.ptptr, example.Point_print(example.ptptr) ); + Stdout.formatln( "pt = {} {}", example.pt, example.Point_print(example.pt) ); + Stdout.formatln( "status = {}", example.status ); + + Stdout.formatln( "\nVariables (printed from the C library):" ); + example.print_vars(); + + Stdout.formatln( "\nNow I'm going to try and modify some read only variables:" ); + Stdout.formatln( "Checking that the read only variables are readonly..." ); + + Stdout( " 'path'..." ); + static if ( is( typeof( example.path = "a" ) ) ) + Stdout.formatln("Oh dear, this variable is not read only!"); + else + Stdout.formatln("Good."); + + Stdout( " 'status'..." ); + static if ( is( typeof( example.status = 2 ) ) ) + Stdout.formatln("Oh dear, this variable is not read only!"); + else + Stdout.formatln("Good."); + + Stdout.formatln( "\nI'm going to try and update a structure variable:" ); + + example.pt = example.ptptr; + + Stdout( "The new value is " ).flush; + example.pt_print(); + Stdout.formatln( "You should see the value {}", example.Point_print(example.ptptr) ); +} diff --git a/Examples/d/variables/d2/runme.d b/Examples/d/variables/d2/runme.d new file mode 100644 index 000000000..f80b81819 --- /dev/null +++ b/Examples/d/variables/d2/runme.d @@ -0,0 +1,71 @@ +// This example illustrates global variable access from C#. +module runme; + +import std.stdio; +static import example; + +void main() { + // Try to set the values of some global variables + example.ivar = 42; + example.svar = -31000; + example.lvar = 65537; + example.uivar = 123456; + example.usvar = 61000; + example.ulvar = 654321; + example.scvar = -13; + example.ucvar = 251; + example.cvar = 'S'; + example.fvar = 3.14159f; + example.dvar = 2.1828; + example.strvar = "Hello World"; + example.iptrvar = example.new_int(37); + example.ptptr = example.new_Point(37,42); + example.name = "Bill"; + + // Now print out the values of the variables + writefln( "Variables (printed from D):" ); + writefln( "ivar = %s", example.ivar ); + writefln( "svar = %s", example.svar ); + writefln( "lvar = %s", example.lvar ); + writefln( "uivar = %s", example.uivar ); + writefln( "usvar = %s", example.usvar ); + writefln( "ulvar = %s", example.ulvar ); + writefln( "scvar = %s", example.scvar ); + writefln( "ucvar = %s", example.ucvar ); + writefln( "fvar = %s", example.fvar ); + writefln( "dvar = %s", example.dvar ); + writefln( "cvar = %s", example.cvar ); + writefln( "strvar = %s", example.strvar ); + writefln( "cstrvar = %s", example.cstrvar ); + writefln( "iptrvar = %s", example.iptrvar ); + writefln( "name = %s", example.name ); + writefln( "ptptr = %s %s", example.ptptr, example.Point_print(example.ptptr) ); + writefln( "pt = %s %s", example.pt, example.Point_print(example.pt) ); + writefln( "status = %s", example.status ); + + writefln( "\nVariables (printed from the C library):" ); + example.print_vars(); + + writefln( "\nNow I'm going to try and modify some read only variables:" ); + writefln( "Checking that the read only variables are readonly..." ); + + writeln( " 'path'..." ); + static if ( is( typeof( example.path = "a" ) ) ) + writefln("Oh dear, this variable is not read only!"); + else + writefln("Good."); + + writeln( " 'status'..." ); + static if ( is( typeof( example.status = 2 ) ) ) + writefln("Oh dear, this variable is not read only!"); + else + writefln("Good."); + + writefln( "\nI'm going to try and update a structure variable:" ); + + example.pt = example.ptptr; + + write( "The new value is " ); + example.pt_print(); + writefln( "You should see the value %s", example.Point_print(example.ptptr) ); +} diff --git a/Examples/d/variables/example.c b/Examples/d/variables/example.c new file mode 100644 index 000000000..1bf9c120f --- /dev/null +++ b/Examples/d/variables/example.c @@ -0,0 +1,91 @@ +/* File : example.c */ + +/* I'm a file containing some C global variables */ + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +#include <stdio.h> +#include <stdlib.h> +#include "example.h" + +int ivar = 0; +short svar = 0; +long lvar = 0; +unsigned int uivar = 0; +unsigned short usvar = 0; +unsigned long ulvar = 0; +signed char scvar = 0; +unsigned char ucvar = 0; +char cvar = 0; +float fvar = 0; +double dvar = 0; +char *strvar = 0; +const char cstrvar[] = "Goodbye"; +int *iptrvar = 0; +char name[256] = "Dave"; +char path[256] = "/home/beazley"; + + +/* Global variables involving a structure */ +Point *ptptr = 0; +Point pt = { 10, 20 }; + +/* A variable that we will make read-only in the interface */ +int status = 1; + +/* A debugging function to print out their values */ + +void print_vars() { + printf("ivar = %d\n", ivar); + printf("svar = %d\n", svar); + printf("lvar = %ld\n", lvar); + printf("uivar = %u\n", uivar); + printf("usvar = %u\n", usvar); + printf("ulvar = %lu\n", ulvar); + printf("scvar = %d\n", scvar); + printf("ucvar = %u\n", ucvar); + printf("fvar = %g\n", fvar); + printf("dvar = %g\n", dvar); + printf("cvar = %c\n", cvar); + printf("strvar = %s\n", strvar ? strvar : "(null)"); + printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("iptrvar = %p\n", iptrvar); + printf("name = %s\n", name); + printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + printf("pt = (%d, %d)\n", pt.x, pt.y); + printf("status = %d\n", status); +} + +/* A function to create an integer (to test iptrvar) */ + +int *new_int(int value) { + int *ip = (int *) malloc(sizeof(int)); + *ip = value; + return ip; +} + +/* A function to create a point */ + +Point *new_Point(int x, int y) { + Point *p = (Point *) malloc(sizeof(Point)); + p->x = x; + p->y = y; + return p; +} + +char * Point_print(Point *p) { + static char buffer[256]; + if (p) { + sprintf(buffer,"(%d, %d)", p->x,p->y); + } else { + sprintf(buffer,"null"); + } + return buffer; +} + +void pt_print() { + printf("(%d, %d)\n", pt.x, pt.y); +} diff --git a/Examples/d/variables/example.h b/Examples/d/variables/example.h new file mode 100644 index 000000000..0f7e89594 --- /dev/null +++ b/Examples/d/variables/example.h @@ -0,0 +1,6 @@ +/* File: example.h */ + +typedef struct { + int x,y; +} Point; + diff --git a/Examples/d/variables/example.i b/Examples/d/variables/example.i new file mode 100644 index 000000000..591b871ed --- /dev/null +++ b/Examples/d/variables/example.i @@ -0,0 +1,49 @@ +/* File : example.i */ +%module example +%{ +#include "example.h" +%} + +/* Some global variable declarations */ +%inline %{ +extern int ivar; +extern short svar; +extern long lvar; +extern unsigned int uivar; +extern unsigned short usvar; +extern unsigned long ulvar; +extern signed char scvar; +extern unsigned char ucvar; +extern char cvar; +extern float fvar; +extern double dvar; +extern char *strvar; +extern const char cstrvar[]; +extern int *iptrvar; +extern char name[256]; + +extern Point *ptptr; +extern Point pt; +%} + + +/* Some read-only variables */ + +%immutable; + +%inline %{ +extern int status; +extern char path[256]; +%} + +%mutable; + +/* Some helper functions to make it easier to test */ +%inline %{ +extern void print_vars(); +extern int *new_int(int value); +extern Point *new_Point(int x, int y); +extern char *Point_print(Point *p); +extern void pt_print(); +%} + diff --git a/Examples/go/callback/example.go b/Examples/go/callback/example.go deleted file mode 100644 index 5c0cfb051..000000000 --- a/Examples/go/callback/example.go +++ /dev/null @@ -1,188 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -type _swig_DirectorCallback struct { - SwigcptrCallback - v interface{} -} - -func (p *_swig_DirectorCallback) Swigcptr() uintptr { - return p.SwigcptrCallback.Swigcptr() -} - -func (p *_swig_DirectorCallback) SwigIsCallback() { -} - -func (p *_swig_DirectorCallback) DirectorInterface() interface{} { - return p.v -} - -func _swig_NewDirectorCallbackCallback(*_swig_DirectorCallback) SwigcptrCallback - -func NewDirectorCallback(v interface{}) Callback { - p := &_swig_DirectorCallback{0, v} - p.SwigcptrCallback = _swig_NewDirectorCallbackCallback(p) - return p -} - -func _swig_wrap_DeleteDirectorCallback(uintptr) - -func DeleteDirectorCallback(arg1 Callback) { - _swig_wrap_DeleteDirectorCallback(arg1.Swigcptr()) -} - -func Swiggo_DeleteDirector_Callback(p *_swig_DirectorCallback) { - p.SwigcptrCallback = 0 -} - -type _swig_DirectorInterfaceCallbackRun interface { - Run() -} - -func _swig_wrap__swig_DirectorCallback_upcall_Run(SwigcptrCallback) -func (swig_p *_swig_DirectorCallback) Run() { - if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceCallbackRun); swig_ok { - swig_g.Run() - return - } - _swig_wrap__swig_DirectorCallback_upcall_Run(swig_p.SwigcptrCallback) -} - -func DirectorCallbackRun(p Callback) { - _swig_wrap__swig_DirectorCallback_upcall_Run(p.(*_swig_DirectorCallback).SwigcptrCallback) -} - -func Swig_DirectorCallback_callback_run(p *_swig_DirectorCallback) { - p.Run() -} - -type SwigcptrCallback uintptr - -func (p SwigcptrCallback) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrCallback) SwigIsCallback() { -} - -func (p SwigcptrCallback) DirectorInterface() interface{} { - return nil -} - -func _swig_wrap_delete_Callback(uintptr) - -func DeleteCallback(arg1 Callback) { - _swig_wrap_delete_Callback(arg1.Swigcptr()) -} - -func _swig_wrap_Callback_run(SwigcptrCallback) - -func (arg1 SwigcptrCallback) Run() { - _swig_wrap_Callback_run(arg1) -} - -func _swig_wrap_new_Callback() SwigcptrCallback - -func NewCallback() Callback { - return _swig_wrap_new_Callback() -} - -type Callback interface { - Swigcptr() uintptr - SwigIsCallback() - DirectorInterface() interface{} - Run() -} - -type SwigcptrCaller uintptr - -func (p SwigcptrCaller) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrCaller) SwigIsCaller() { -} - -func _swig_wrap_new_Caller() SwigcptrCaller - -func NewCaller() Caller { - return _swig_wrap_new_Caller() -} - -func _swig_wrap_delete_Caller(uintptr) - -func DeleteCaller(arg1 Caller) { - _swig_wrap_delete_Caller(arg1.Swigcptr()) -} - -func _swig_wrap_Caller_delCallback(SwigcptrCaller) - -func (arg1 SwigcptrCaller) DelCallback() { - _swig_wrap_Caller_delCallback(arg1) -} - -func _swig_wrap_Caller_setCallback(SwigcptrCaller, uintptr) - -func (arg1 SwigcptrCaller) SetCallback(arg2 Callback) { - _swig_wrap_Caller_setCallback(arg1, arg2.Swigcptr()) -} - -func _swig_wrap_Caller_call(SwigcptrCaller) - -func (arg1 SwigcptrCaller) Call() { - _swig_wrap_Caller_call(arg1) -} - -type Caller interface { - Swigcptr() uintptr - SwigIsCaller() - DelCallback() - SetCallback(arg2 Callback) - Call() -} - - -type SwigcptrSwigDirector_Callback uintptr -type SwigDirector_Callback interface { - Swigcptr() uintptr; -} -func (p SwigcptrSwigDirector_Callback) Swigcptr() uintptr { - return uintptr(p) -} - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/class/example.go b/Examples/go/class/example.go deleted file mode 100644 index ec8113ad4..000000000 --- a/Examples/go/class/example.go +++ /dev/null @@ -1,284 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -type SwigcptrShape uintptr - -func (p SwigcptrShape) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrShape) SwigIsShape() { -} - -func _swig_wrap_delete_Shape(uintptr) - -func DeleteShape(arg1 Shape) { - _swig_wrap_delete_Shape(arg1.Swigcptr()) -} - -func _swig_wrap_Shape_x_set(SwigcptrShape, float64) - -func (arg1 SwigcptrShape) SetX(arg2 float64) { - _swig_wrap_Shape_x_set(arg1, arg2) -} - -func _swig_wrap_Shape_x_get(SwigcptrShape) float64 - -func (arg1 SwigcptrShape) GetX() float64 { - return _swig_wrap_Shape_x_get(arg1) -} - -func _swig_wrap_Shape_y_set(SwigcptrShape, float64) - -func (arg1 SwigcptrShape) SetY(arg2 float64) { - _swig_wrap_Shape_y_set(arg1, arg2) -} - -func _swig_wrap_Shape_y_get(SwigcptrShape) float64 - -func (arg1 SwigcptrShape) GetY() float64 { - return _swig_wrap_Shape_y_get(arg1) -} - -func _swig_wrap_Shape_move(SwigcptrShape, float64, float64) - -func (arg1 SwigcptrShape) Move(arg2 float64, arg3 float64) { - _swig_wrap_Shape_move(arg1, arg2, arg3) -} - -func _swig_wrap_Shape_area(SwigcptrShape) float64 - -func (arg1 SwigcptrShape) Area() float64 { - return _swig_wrap_Shape_area(arg1) -} - -func _swig_wrap_Shape_perimeter(SwigcptrShape) float64 - -func (arg1 SwigcptrShape) Perimeter() float64 { - return _swig_wrap_Shape_perimeter(arg1) -} - -func _swig_wrap_Shape_nshapes_set(int) - -func SetShapeNshapes(arg1 int) { - _swig_wrap_Shape_nshapes_set(arg1) -} - -func GetShapeNshapes() int -type Shape interface { - Swigcptr() uintptr - SwigIsShape() - SetX(arg2 float64) - GetX() float64 - SetY(arg2 float64) - GetY() float64 - Move(arg2 float64, arg3 float64) - Area() float64 - Perimeter() float64 -} - -type SwigcptrCircle uintptr - -func (p SwigcptrCircle) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrCircle) SwigIsCircle() { -} - -func _swig_wrap_new_Circle(float64) SwigcptrCircle - -func NewCircle(arg1 float64) Circle { - return _swig_wrap_new_Circle(arg1) -} - -func _swig_wrap_Circle_area(SwigcptrCircle) float64 - -func (arg1 SwigcptrCircle) Area() float64 { - return _swig_wrap_Circle_area(arg1) -} - -func _swig_wrap_Circle_perimeter(SwigcptrCircle) float64 - -func (arg1 SwigcptrCircle) Perimeter() float64 { - return _swig_wrap_Circle_perimeter(arg1) -} - -func _swig_wrap_delete_Circle(uintptr) - -func DeleteCircle(arg1 Circle) { - _swig_wrap_delete_Circle(arg1.Swigcptr()) -} - -func _swig_wrap_SetCircle_X(SwigcptrCircle, float64) - -func (_swig_base SwigcptrCircle) SetX(arg1 float64) { - _swig_wrap_SetCircle_X(_swig_base, arg1) -} - -func _swig_wrap_GetCircle_X(SwigcptrCircle) float64 - -func (_swig_base SwigcptrCircle) GetX() float64 { - return _swig_wrap_GetCircle_X(_swig_base) -} - -func _swig_wrap_SetCircle_Y(SwigcptrCircle, float64) - -func (_swig_base SwigcptrCircle) SetY(arg1 float64) { - _swig_wrap_SetCircle_Y(_swig_base, arg1) -} - -func _swig_wrap_GetCircle_Y(SwigcptrCircle) float64 - -func (_swig_base SwigcptrCircle) GetY() float64 { - return _swig_wrap_GetCircle_Y(_swig_base) -} - -func _swig_wrap_Circle_move(SwigcptrCircle, float64, float64) - -func (_swig_base SwigcptrCircle) Move(arg1 float64, arg2 float64) { - _swig_wrap_Circle_move(_swig_base, arg1, arg2) -} - -func (p SwigcptrCircle) SwigIsShape() { -} - -func (p SwigcptrCircle) SwigGetShape() Shape { - return SwigcptrShape(p.Swigcptr()) -} - -type Circle interface { - Swigcptr() uintptr - SwigIsCircle() - Area() float64 - Perimeter() float64 - SetX(arg1 float64) - GetX() float64 - SetY(arg1 float64) - GetY() float64 - Move(arg1 float64, arg2 float64) - SwigIsShape() - SwigGetShape() Shape -} - -type SwigcptrSquare uintptr - -func (p SwigcptrSquare) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrSquare) SwigIsSquare() { -} - -func _swig_wrap_new_Square(float64) SwigcptrSquare - -func NewSquare(arg1 float64) Square { - return _swig_wrap_new_Square(arg1) -} - -func _swig_wrap_Square_area(SwigcptrSquare) float64 - -func (arg1 SwigcptrSquare) Area() float64 { - return _swig_wrap_Square_area(arg1) -} - -func _swig_wrap_Square_perimeter(SwigcptrSquare) float64 - -func (arg1 SwigcptrSquare) Perimeter() float64 { - return _swig_wrap_Square_perimeter(arg1) -} - -func _swig_wrap_delete_Square(uintptr) - -func DeleteSquare(arg1 Square) { - _swig_wrap_delete_Square(arg1.Swigcptr()) -} - -func _swig_wrap_SetSquare_X(SwigcptrSquare, float64) - -func (_swig_base SwigcptrSquare) SetX(arg1 float64) { - _swig_wrap_SetSquare_X(_swig_base, arg1) -} - -func _swig_wrap_GetSquare_X(SwigcptrSquare) float64 - -func (_swig_base SwigcptrSquare) GetX() float64 { - return _swig_wrap_GetSquare_X(_swig_base) -} - -func _swig_wrap_SetSquare_Y(SwigcptrSquare, float64) - -func (_swig_base SwigcptrSquare) SetY(arg1 float64) { - _swig_wrap_SetSquare_Y(_swig_base, arg1) -} - -func _swig_wrap_GetSquare_Y(SwigcptrSquare) float64 - -func (_swig_base SwigcptrSquare) GetY() float64 { - return _swig_wrap_GetSquare_Y(_swig_base) -} - -func _swig_wrap_Square_move(SwigcptrSquare, float64, float64) - -func (_swig_base SwigcptrSquare) Move(arg1 float64, arg2 float64) { - _swig_wrap_Square_move(_swig_base, arg1, arg2) -} - -func (p SwigcptrSquare) SwigIsShape() { -} - -func (p SwigcptrSquare) SwigGetShape() Shape { - return SwigcptrShape(p.Swigcptr()) -} - -type Square interface { - Swigcptr() uintptr - SwigIsSquare() - Area() float64 - Perimeter() float64 - SetX(arg1 float64) - GetX() float64 - SetY(arg1 float64) - GetY() float64 - Move(arg1 float64, arg2 float64) - SwigIsShape() - SwigGetShape() Shape -} - - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/constants/example.go b/Examples/go/constants/example.go deleted file mode 100644 index 0e5e66418..000000000 --- a/Examples/go/constants/example.go +++ /dev/null @@ -1,44 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -const ICONST int = 42 -const FCONST float64 = 2.1828 -const CCONST byte = 'x' -func _swig_getCCONST2() byte -var CCONST2 byte = _swig_getCCONST2() -const SCONST string = "Hello World" -func _swig_getSCONST2() string -var SCONST2 string = _swig_getSCONST2() -func _swig_getEXPR() float64 -var EXPR float64 = _swig_getEXPR() -const Iconst int = 37 -const Fconst float64 = 3.14 - diff --git a/Examples/go/enum/example.go b/Examples/go/enum/example.go deleted file mode 100644 index 4653ab57a..000000000 --- a/Examples/go/enum/example.go +++ /dev/null @@ -1,93 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -type Color int -func _swig_getRED() Color -var RED Color = _swig_getRED() -func _swig_getBLUE() Color -var BLUE Color = _swig_getBLUE() -func _swig_getGREEN() Color -var GREEN Color = _swig_getGREEN() -type SwigcptrFoo uintptr - -func (p SwigcptrFoo) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrFoo) SwigIsFoo() { -} - -func _swig_wrap_new_Foo() SwigcptrFoo - -func NewFoo() Foo { - return _swig_wrap_new_Foo() -} - -type FooSpeed int -func _swig_getFoo_IMPULSE_Foo() FooSpeed -var FooIMPULSE FooSpeed = _swig_getFoo_IMPULSE_Foo() -func _swig_getFoo_WARP_Foo() FooSpeed -var FooWARP FooSpeed = _swig_getFoo_WARP_Foo() -func _swig_getFoo_LUDICROUS_Foo() FooSpeed -var FooLUDICROUS FooSpeed = _swig_getFoo_LUDICROUS_Foo() -func _swig_wrap_Foo_enum_test(SwigcptrFoo, FooSpeed) - -func (arg1 SwigcptrFoo) Enum_test(arg2 FooSpeed) { - _swig_wrap_Foo_enum_test(arg1, arg2) -} - -func _swig_wrap_delete_Foo(uintptr) - -func DeleteFoo(arg1 Foo) { - _swig_wrap_delete_Foo(arg1.Swigcptr()) -} - -type Foo interface { - Swigcptr() uintptr - SwigIsFoo() - Enum_test(arg2 FooSpeed) -} - -func _swig_wrap_enum_test(Color, FooSpeed) - -func Enum_test(arg1 Color, arg2 FooSpeed) { - _swig_wrap_enum_test(arg1, arg2) -} - - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/extend/example.go b/Examples/go/extend/example.go deleted file mode 100644 index 08f21e6ab..000000000 --- a/Examples/go/extend/example.go +++ /dev/null @@ -1,397 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -type _swig_DirectorEmployee struct { - SwigcptrEmployee - v interface{} -} - -func (p *_swig_DirectorEmployee) Swigcptr() uintptr { - return p.SwigcptrEmployee.Swigcptr() -} - -func (p *_swig_DirectorEmployee) SwigIsEmployee() { -} - -func (p *_swig_DirectorEmployee) DirectorInterface() interface{} { - return p.v -} - -func _swig_NewDirectorEmployeeEmployee(*_swig_DirectorEmployee, string) SwigcptrEmployee - -func NewDirectorEmployee(v interface{}, arg1 string) Employee { - p := &_swig_DirectorEmployee{0, v} - p.SwigcptrEmployee = _swig_NewDirectorEmployeeEmployee(p, arg1) - return p -} - -type _swig_DirectorInterfaceEmployeeGetTitle interface { - GetTitle() string -} - -func _swig_wrap__swig_DirectorEmployee_upcall_GetTitle(SwigcptrEmployee) string -func (swig_p *_swig_DirectorEmployee) GetTitle() string { - if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceEmployeeGetTitle); swig_ok { - return swig_g.GetTitle() - } - return _swig_wrap__swig_DirectorEmployee_upcall_GetTitle(swig_p.SwigcptrEmployee) -} - -func DirectorEmployeeGetTitle(p Employee) string { - return _swig_wrap__swig_DirectorEmployee_upcall_GetTitle(p.(*_swig_DirectorEmployee).SwigcptrEmployee) -} - -func Swig_DirectorEmployee_callback_getTitle(p *_swig_DirectorEmployee) (swig_result string) { - return p.GetTitle() -} - -type _swig_DirectorInterfaceEmployeeGetName interface { - GetName() string -} - -func _swig_wrap__swig_DirectorEmployee_upcall_GetName(SwigcptrEmployee) string -func (swig_p *_swig_DirectorEmployee) GetName() string { - if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceEmployeeGetName); swig_ok { - return swig_g.GetName() - } - return _swig_wrap__swig_DirectorEmployee_upcall_GetName(swig_p.SwigcptrEmployee) -} - -func DirectorEmployeeGetName(p Employee) string { - return _swig_wrap__swig_DirectorEmployee_upcall_GetName(p.(*_swig_DirectorEmployee).SwigcptrEmployee) -} - -func Swig_DirectorEmployee_callback_getName(p *_swig_DirectorEmployee) (swig_result string) { - return p.GetName() -} - -type _swig_DirectorInterfaceEmployeeGetPosition interface { - GetPosition() string -} - -func _swig_wrap__swig_DirectorEmployee_upcall_GetPosition(SwigcptrEmployee) string -func (swig_p *_swig_DirectorEmployee) GetPosition() string { - if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceEmployeeGetPosition); swig_ok { - return swig_g.GetPosition() - } - return _swig_wrap__swig_DirectorEmployee_upcall_GetPosition(swig_p.SwigcptrEmployee) -} - -func DirectorEmployeeGetPosition(p Employee) string { - return _swig_wrap__swig_DirectorEmployee_upcall_GetPosition(p.(*_swig_DirectorEmployee).SwigcptrEmployee) -} - -func Swig_DirectorEmployee_callback_getPosition(p *_swig_DirectorEmployee) (swig_result string) { - return p.GetPosition() -} - -func _swig_wrap_DeleteDirectorEmployee(uintptr) - -func DeleteDirectorEmployee(arg1 Employee) { - _swig_wrap_DeleteDirectorEmployee(arg1.Swigcptr()) -} - -func Swiggo_DeleteDirector_Employee(p *_swig_DirectorEmployee) { - p.SwigcptrEmployee = 0 -} - -type SwigcptrEmployee uintptr - -func (p SwigcptrEmployee) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrEmployee) SwigIsEmployee() { -} - -func (p SwigcptrEmployee) DirectorInterface() interface{} { - return nil -} - -func _swig_wrap_new_Employee(string) SwigcptrEmployee - -func NewEmployee(arg1 string) Employee { - return _swig_wrap_new_Employee(arg1) -} - -func _swig_wrap_Employee_getTitle(SwigcptrEmployee) string - -func (arg1 SwigcptrEmployee) GetTitle() string { - return _swig_wrap_Employee_getTitle(arg1) -} - -func _swig_wrap_Employee_getName(SwigcptrEmployee) string - -func (arg1 SwigcptrEmployee) GetName() string { - return _swig_wrap_Employee_getName(arg1) -} - -func _swig_wrap_Employee_getPosition(SwigcptrEmployee) string - -func (arg1 SwigcptrEmployee) GetPosition() string { - return _swig_wrap_Employee_getPosition(arg1) -} - -func _swig_wrap_delete_Employee(uintptr) - -func DeleteEmployee(arg1 Employee) { - _swig_wrap_delete_Employee(arg1.Swigcptr()) -} - -type Employee interface { - Swigcptr() uintptr - SwigIsEmployee() - DirectorInterface() interface{} - GetTitle() string - GetName() string - GetPosition() string -} - -type _swig_DirectorManager struct { - SwigcptrManager - v interface{} -} - -func (p *_swig_DirectorManager) Swigcptr() uintptr { - return p.SwigcptrManager.Swigcptr() -} - -func (p *_swig_DirectorManager) SwigIsManager() { -} - -func (p *_swig_DirectorManager) DirectorInterface() interface{} { - return p.v -} - -func _swig_NewDirectorManagerManager(*_swig_DirectorManager, string) SwigcptrManager - -func NewDirectorManager(v interface{}, arg1 string) Manager { - p := &_swig_DirectorManager{0, v} - p.SwigcptrManager = _swig_NewDirectorManagerManager(p, arg1) - return p -} - -type _swig_DirectorInterfaceManagerGetTitle interface { - GetTitle() string -} - -func _swig_wrap__swig_DirectorManager_upcall_GetTitle(SwigcptrManager) string -func (swig_p *_swig_DirectorManager) GetTitle() string { - if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceManagerGetTitle); swig_ok { - return swig_g.GetTitle() - } - return _swig_wrap__swig_DirectorManager_upcall_GetTitle(swig_p.SwigcptrManager) -} - -func DirectorManagerGetTitle(p Manager) string { - return _swig_wrap__swig_DirectorManager_upcall_GetTitle(p.(*_swig_DirectorManager).SwigcptrManager) -} - -func Swig_DirectorManager_callback_getTitle(p *_swig_DirectorManager) (swig_result string) { - return p.GetTitle() -} - -type _swig_DirectorInterfaceManagerGetName interface { - GetName() string -} - -func _swig_wrap__swig_DirectorManager_upcall_GetName(SwigcptrManager) string -func (swig_p *_swig_DirectorManager) GetName() string { - if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceManagerGetName); swig_ok { - return swig_g.GetName() - } - return _swig_wrap__swig_DirectorManager_upcall_GetName(swig_p.SwigcptrManager) -} - -func DirectorManagerGetName(p Manager) string { - return _swig_wrap__swig_DirectorManager_upcall_GetName(p.(*_swig_DirectorManager).SwigcptrManager) -} - -func Swig_DirectorManager_callback_getName(p *_swig_DirectorManager) (swig_result string) { - return p.GetName() -} - -type _swig_DirectorInterfaceManagerGetPosition interface { - GetPosition() string -} - -func _swig_wrap__swig_DirectorManager_upcall_GetPosition(SwigcptrManager) string -func (swig_p *_swig_DirectorManager) GetPosition() string { - if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceManagerGetPosition); swig_ok { - return swig_g.GetPosition() - } - return _swig_wrap__swig_DirectorManager_upcall_GetPosition(swig_p.SwigcptrManager) -} - -func DirectorManagerGetPosition(p Manager) string { - return _swig_wrap__swig_DirectorManager_upcall_GetPosition(p.(*_swig_DirectorManager).SwigcptrManager) -} - -func Swig_DirectorManager_callback_getPosition(p *_swig_DirectorManager) (swig_result string) { - return p.GetPosition() -} - -func _swig_wrap_DeleteDirectorManager(uintptr) - -func DeleteDirectorManager(arg1 Manager) { - _swig_wrap_DeleteDirectorManager(arg1.Swigcptr()) -} - -func Swiggo_DeleteDirector_Manager(p *_swig_DirectorManager) { - p.SwigcptrManager = 0 -} - -type SwigcptrManager uintptr - -func (p SwigcptrManager) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrManager) SwigIsManager() { -} - -func (p SwigcptrManager) DirectorInterface() interface{} { - return nil -} - -func _swig_wrap_new_Manager(string) SwigcptrManager - -func NewManager(arg1 string) Manager { - return _swig_wrap_new_Manager(arg1) -} - -func _swig_wrap_Manager_getPosition(SwigcptrManager) string - -func (arg1 SwigcptrManager) GetPosition() string { - return _swig_wrap_Manager_getPosition(arg1) -} - -func _swig_wrap_delete_Manager(uintptr) - -func DeleteManager(arg1 Manager) { - _swig_wrap_delete_Manager(arg1.Swigcptr()) -} - -func _swig_wrap_Manager_getTitle(SwigcptrManager) string - -func (_swig_base SwigcptrManager) GetTitle() string { - return _swig_wrap_Manager_getTitle(_swig_base) -} - -func _swig_wrap_Manager_getName(SwigcptrManager) string - -func (_swig_base SwigcptrManager) GetName() string { - return _swig_wrap_Manager_getName(_swig_base) -} - -func (p SwigcptrManager) SwigIsEmployee() { -} - -func (p SwigcptrManager) SwigGetEmployee() Employee { - return SwigcptrEmployee(p.Swigcptr()) -} - -type Manager interface { - Swigcptr() uintptr - SwigIsManager() - DirectorInterface() interface{} - GetPosition() string - GetTitle() string - GetName() string - SwigIsEmployee() - SwigGetEmployee() Employee -} - -type SwigcptrEmployeeList uintptr - -func (p SwigcptrEmployeeList) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrEmployeeList) SwigIsEmployeeList() { -} - -func _swig_wrap_new_EmployeeList() SwigcptrEmployeeList - -func NewEmployeeList() EmployeeList { - return _swig_wrap_new_EmployeeList() -} - -func _swig_wrap_EmployeeList_addEmployee(SwigcptrEmployeeList, uintptr) - -func (arg1 SwigcptrEmployeeList) AddEmployee(arg2 Employee) { - _swig_wrap_EmployeeList_addEmployee(arg1, arg2.Swigcptr()) -} - -func _swig_wrap_EmployeeList_get_item(SwigcptrEmployeeList, int) SwigcptrEmployee - -func (arg1 SwigcptrEmployeeList) Get_item(arg2 int) Employee { - return _swig_wrap_EmployeeList_get_item(arg1, arg2) -} - -func _swig_wrap_delete_EmployeeList(uintptr) - -func DeleteEmployeeList(arg1 EmployeeList) { - _swig_wrap_delete_EmployeeList(arg1.Swigcptr()) -} - -type EmployeeList interface { - Swigcptr() uintptr - SwigIsEmployeeList() - AddEmployee(arg2 Employee) - Get_item(arg2 int) Employee -} - - -type SwigcptrSwigDirector_Manager uintptr -type SwigDirector_Manager interface { - Swigcptr() uintptr; -} -func (p SwigcptrSwigDirector_Manager) Swigcptr() uintptr { - return uintptr(p) -} - -type SwigcptrSwigDirector_Employee uintptr -type SwigDirector_Employee interface { - Swigcptr() uintptr; -} -func (p SwigcptrSwigDirector_Employee) Swigcptr() uintptr { - return uintptr(p) -} - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/funcptr/example.go b/Examples/go/funcptr/example.go deleted file mode 100644 index b059bae8d..000000000 --- a/Examples/go/funcptr/example.go +++ /dev/null @@ -1,54 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -func Do_op(int, int, _swig_fnptr) int -func _swig_getADD() _swig_fnptr -var ADD _swig_fnptr = _swig_getADD() -func _swig_getSUB() _swig_fnptr -var SUB _swig_fnptr = _swig_getSUB() -func _swig_getMUL() _swig_fnptr -var MUL _swig_fnptr = _swig_getMUL() -func _swig_wrap_funcvar_set(_swig_fnptr) - -func SetFuncvar(arg1 _swig_fnptr) { - _swig_wrap_funcvar_set(arg1) -} - -func GetFuncvar() _swig_fnptr - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/multimap/example.go b/Examples/go/multimap/example.go deleted file mode 100644 index 59ed9eaad..000000000 --- a/Examples/go/multimap/example.go +++ /dev/null @@ -1,55 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -func Gcd(int, int) int -func Gcdmain([]string) int -func Count(string, byte) int -func _swig_wrap_capitalize([]string) - -func Capitalize(arg1 []string) { - _swig_wrap_capitalize(arg1) -} - -func _swig_wrap_circle(float64, float64) - -func Circle(arg1 float64, arg2 float64) { - _swig_wrap_circle(arg1, arg2) -} - - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/pointer/example.go b/Examples/go/pointer/example.go deleted file mode 100644 index 567c41c32..000000000 --- a/Examples/go/pointer/example.go +++ /dev/null @@ -1,68 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -func _swig_wrap_add(*int, *int, *int) - -func Add(arg1 *int, arg2 *int, arg3 *int) { - _swig_wrap_add(arg1, arg2, arg3) -} - -func New_intp() *int -func Copy_intp(int) *int -func _swig_wrap_delete_intp(*int) - -func Delete_intp(arg1 *int) { - _swig_wrap_delete_intp(arg1) -} - -func _swig_wrap_intp_assign(*int, int) - -func Intp_assign(arg1 *int, arg2 int) { - _swig_wrap_intp_assign(arg1, arg2) -} - -func Intp_value(*int) int -func _swig_wrap_sub(int, int, []int) - -func Sub(arg1 int, arg2 int, arg3 []int) { - _swig_wrap_sub(arg1, arg2, arg3) -} - -func Divide(int, int, []int) int - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/reference/example.go b/Examples/go/reference/example.go deleted file mode 100644 index fb98f8a18..000000000 --- a/Examples/go/reference/example.go +++ /dev/null @@ -1,126 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -type SwigcptrVector uintptr - -func (p SwigcptrVector) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrVector) SwigIsVector() { -} - -func _swig_wrap_new_Vector(float64, float64, float64) SwigcptrVector - -func NewVector(arg1 float64, arg2 float64, arg3 float64) Vector { - return _swig_wrap_new_Vector(arg1, arg2, arg3) -} - -func _swig_wrap_delete_Vector(uintptr) - -func DeleteVector(arg1 Vector) { - _swig_wrap_delete_Vector(arg1.Swigcptr()) -} - -func _swig_wrap_Vector_print(SwigcptrVector) string - -func (arg1 SwigcptrVector) Print() string { - return _swig_wrap_Vector_print(arg1) -} - -type Vector interface { - Swigcptr() uintptr - SwigIsVector() - Print() string -} - -func _swig_wrap_addv(uintptr, uintptr) SwigcptrVector - -func Addv(arg1 Vector, arg2 Vector) Vector { - return _swig_wrap_addv(arg1.Swigcptr(), arg2.Swigcptr()) -} - -type SwigcptrVectorArray uintptr - -func (p SwigcptrVectorArray) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrVectorArray) SwigIsVectorArray() { -} - -func _swig_wrap_new_VectorArray(int) SwigcptrVectorArray - -func NewVectorArray(arg1 int) VectorArray { - return _swig_wrap_new_VectorArray(arg1) -} - -func _swig_wrap_delete_VectorArray(uintptr) - -func DeleteVectorArray(arg1 VectorArray) { - _swig_wrap_delete_VectorArray(arg1.Swigcptr()) -} - -func _swig_wrap_VectorArray_size(SwigcptrVectorArray) int - -func (arg1 SwigcptrVectorArray) Size() int { - return _swig_wrap_VectorArray_size(arg1) -} - -func _swig_wrap_VectorArray_get(SwigcptrVectorArray, int) SwigcptrVector - -func (arg1 SwigcptrVectorArray) Get(arg2 int) Vector { - return _swig_wrap_VectorArray_get(arg1, arg2) -} - -func _swig_wrap_VectorArray_set(SwigcptrVectorArray, int, uintptr) - -func (arg1 SwigcptrVectorArray) Set(arg2 int, arg3 Vector) { - _swig_wrap_VectorArray_set(arg1, arg2, arg3.Swigcptr()) -} - -type VectorArray interface { - Swigcptr() uintptr - SwigIsVectorArray() - Size() int - Get(arg2 int) Vector - Set(arg2 int, arg3 Vector) -} - - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/simple/example.go b/Examples/go/simple/example.go deleted file mode 100644 index df0e70564..000000000 --- a/Examples/go/simple/example.go +++ /dev/null @@ -1,48 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -func Gcd(int, int) int -func _swig_wrap_Foo_set(float64) - -func SetFoo(arg1 float64) { - _swig_wrap_Foo_set(arg1) -} - -func GetFoo() float64 - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/template/example.go b/Examples/go/template/example.go deleted file mode 100644 index 671b5c2ba..000000000 --- a/Examples/go/template/example.go +++ /dev/null @@ -1,150 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -func Maxint(int, int) int -func Maxdouble(float64, float64) float64 -type SwigcptrVecint uintptr - -func (p SwigcptrVecint) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrVecint) SwigIsVecint() { -} - -func _swig_wrap_new_vecint(int) SwigcptrVecint - -func NewVecint(arg1 int) Vecint { - return _swig_wrap_new_vecint(arg1) -} - -func _swig_wrap_vecint_get(SwigcptrVecint, int) *int - -func (arg1 SwigcptrVecint) Get(arg2 int) *int { - return _swig_wrap_vecint_get(arg1, arg2) -} - -func _swig_wrap_vecint_set(SwigcptrVecint, int, *int) - -func (arg1 SwigcptrVecint) Set(arg2 int, arg3 *int) { - _swig_wrap_vecint_set(arg1, arg2, arg3) -} - -func _swig_wrap_vecint_getitem(SwigcptrVecint, int) int - -func (arg1 SwigcptrVecint) Getitem(arg2 int) int { - return _swig_wrap_vecint_getitem(arg1, arg2) -} - -func _swig_wrap_vecint_setitem(SwigcptrVecint, int, int) - -func (arg1 SwigcptrVecint) Setitem(arg2 int, arg3 int) { - _swig_wrap_vecint_setitem(arg1, arg2, arg3) -} - -func _swig_wrap_delete_vecint(uintptr) - -func DeleteVecint(arg1 Vecint) { - _swig_wrap_delete_vecint(arg1.Swigcptr()) -} - -type Vecint interface { - Swigcptr() uintptr - SwigIsVecint() - Get(arg2 int) *int - Set(arg2 int, arg3 *int) - Getitem(arg2 int) int - Setitem(arg2 int, arg3 int) -} - -type SwigcptrVecdouble uintptr - -func (p SwigcptrVecdouble) Swigcptr() uintptr { - return (uintptr)(p) -} - -func (p SwigcptrVecdouble) SwigIsVecdouble() { -} - -func _swig_wrap_new_vecdouble(int) SwigcptrVecdouble - -func NewVecdouble(arg1 int) Vecdouble { - return _swig_wrap_new_vecdouble(arg1) -} - -func _swig_wrap_vecdouble_get(SwigcptrVecdouble, int) *float64 - -func (arg1 SwigcptrVecdouble) Get(arg2 int) *float64 { - return _swig_wrap_vecdouble_get(arg1, arg2) -} - -func _swig_wrap_vecdouble_set(SwigcptrVecdouble, int, *float64) - -func (arg1 SwigcptrVecdouble) Set(arg2 int, arg3 *float64) { - _swig_wrap_vecdouble_set(arg1, arg2, arg3) -} - -func _swig_wrap_vecdouble_getitem(SwigcptrVecdouble, int) float64 - -func (arg1 SwigcptrVecdouble) Getitem(arg2 int) float64 { - return _swig_wrap_vecdouble_getitem(arg1, arg2) -} - -func _swig_wrap_vecdouble_setitem(SwigcptrVecdouble, int, float64) - -func (arg1 SwigcptrVecdouble) Setitem(arg2 int, arg3 float64) { - _swig_wrap_vecdouble_setitem(arg1, arg2, arg3) -} - -func _swig_wrap_delete_vecdouble(uintptr) - -func DeleteVecdouble(arg1 Vecdouble) { - _swig_wrap_delete_vecdouble(arg1.Swigcptr()) -} - -type Vecdouble interface { - Swigcptr() uintptr - SwigIsVecdouble() - Get(arg2 int) *float64 - Set(arg2 int, arg3 *float64) - Getitem(arg2 int) float64 - Setitem(arg2 int, arg3 float64) -} - - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/go/variables/example.go b/Examples/go/variables/example.go deleted file mode 100644 index f4f299b73..000000000 --- a/Examples/go/variables/example.go +++ /dev/null @@ -1,198 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 2.0.1 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -package example - - -type _swig_fnptr *byte -type _swig_memberptr *byte - - -func _swig_allocatememory(int) *byte -func _swig_internal_allocate(len int) *byte { - return _swig_allocatememory(len) -} - -func _swig_allocatestring(*byte, int) string -func _swig_internal_makegostring(p *byte, l int) string { - return _swig_allocatestring(p, l) -} - -func _swig_internal_gopanic(p *byte, l int) { - panic(_swig_allocatestring(p, l)) -} - -func _swig_wrap_ivar_set(int) - -func SetIvar(arg1 int) { - _swig_wrap_ivar_set(arg1) -} - -func GetIvar() int -func _swig_wrap_svar_set(int16) - -func SetSvar(arg1 int16) { - _swig_wrap_svar_set(arg1) -} - -func GetSvar() int16 -func _swig_wrap_lvar_set(int32) - -func SetLvar(arg1 int32) { - _swig_wrap_lvar_set(arg1) -} - -func GetLvar() int32 -func _swig_wrap_uivar_set(uint) - -func SetUivar(arg1 uint) { - _swig_wrap_uivar_set(arg1) -} - -func GetUivar() uint -func _swig_wrap_usvar_set(uint16) - -func SetUsvar(arg1 uint16) { - _swig_wrap_usvar_set(arg1) -} - -func GetUsvar() uint16 -func _swig_wrap_ulvar_set(uint32) - -func SetUlvar(arg1 uint32) { - _swig_wrap_ulvar_set(arg1) -} - -func GetUlvar() uint32 -func _swig_wrap_scvar_set(int8) - -func SetScvar(arg1 int8) { - _swig_wrap_scvar_set(arg1) -} - -func GetScvar() int8 -func _swig_wrap_ucvar_set(byte) - -func SetUcvar(arg1 byte) { - _swig_wrap_ucvar_set(arg1) -} - -func GetUcvar() byte -func _swig_wrap_cvar_set(byte) - -func SetCvar(arg1 byte) { - _swig_wrap_cvar_set(arg1) -} - -func GetCvar() byte -func _swig_wrap_fvar_set(float32) - -func SetFvar(arg1 float32) { - _swig_wrap_fvar_set(arg1) -} - -func GetFvar() float32 -func _swig_wrap_dvar_set(float64) - -func SetDvar(arg1 float64) { - _swig_wrap_dvar_set(arg1) -} - -func GetDvar() float64 -func _swig_wrap_strvar_set(string) - -func SetStrvar(arg1 string) { - _swig_wrap_strvar_set(arg1) -} - -func GetStrvar() string -func GetCstrvar() string -func _swig_wrap_iptrvar_set(*int) - -func SetIptrvar(arg1 *int) { - _swig_wrap_iptrvar_set(arg1) -} - -func GetIptrvar() *int -func _swig_wrap_name_set(string) - -func SetName(arg1 string) { - _swig_wrap_name_set(arg1) -} - -func GetName() string -func _swig_wrap_ptptr_set(uintptr) - -func SetPtptr(arg1 Point) { - _swig_wrap_ptptr_set(arg1.Swigcptr()) -} - -func _swig_wrap_ptptr_get() SwigcptrPoint - -func GetPtptr() Point { - return _swig_wrap_ptptr_get() -} - -func _swig_wrap_pt_set(uintptr) - -func SetPt(arg1 Point) { - _swig_wrap_pt_set(arg1.Swigcptr()) -} - -func _swig_wrap_pt_get() SwigcptrPoint - -func GetPt() Point { - return _swig_wrap_pt_get() -} - -func GetStatus() int -func GetPath() string -func _swig_wrap_print_vars() - -func Print_vars() { - _swig_wrap_print_vars() -} - -func New_int(int) *int -func _swig_wrap_new_Point(int, int) SwigcptrPoint - -func New_Point(arg1 int, arg2 int) Point { - return _swig_wrap_new_Point(arg1, arg2) -} - -func _swig_wrap_Point_print(uintptr) string - -func Point_print(arg1 Point) string { - return _swig_wrap_Point_print(arg1.Swigcptr()) -} - -func _swig_wrap_pt_print() - -func Pt_print() { - _swig_wrap_pt_print() -} - - -type SwigcptrPoint uintptr -type Point interface { - Swigcptr() uintptr; -} -func (p SwigcptrPoint) Swigcptr() uintptr { - return uintptr(p) -} - -type SwigcptrVoid uintptr -type Void interface { - Swigcptr() uintptr; -} -func (p SwigcptrVoid) Swigcptr() uintptr { - return uintptr(p) -} - diff --git a/Examples/ocaml/argout_ref/example.i b/Examples/ocaml/argout_ref/example.i index a0be05f24..5ea6777fb 100644 --- a/Examples/ocaml/argout_ref/example.i +++ b/Examples/ocaml/argout_ref/example.i @@ -1,4 +1,8 @@ /* File : example.i */ %module example +%{ +extern "C" void factor(int &x, int &y); +%} + extern "C" void factor(int &x, int &y); diff --git a/Examples/ocaml/shapes/example.c b/Examples/ocaml/shapes/example.c index bf0fff937..26c1b8098 100644 --- a/Examples/ocaml/shapes/example.c +++ b/Examples/ocaml/shapes/example.c @@ -46,3 +46,5 @@ void draw_depth_map( volume *v, int div_x, int div_y ) { } double volume::depth( double x, double y ) { return 0.0; } + +volume::~volume() { } diff --git a/Examples/ocaml/shapes/example.h b/Examples/ocaml/shapes/example.h index 4b1644494..68cb6ee3e 100644 --- a/Examples/ocaml/shapes/example.h +++ b/Examples/ocaml/shapes/example.h @@ -9,7 +9,8 @@ public: class volume { public: - virtual double depth( double x, double y ); + virtual double depth( double x, double y ); + virtual ~volume(); }; extern void draw_shape_coverage( shape *s, int div_x, int div_y ); diff --git a/Examples/ocaml/std_string/README b/Examples/ocaml/std_string/README index 566553083..ccebecbaf 100644 --- a/Examples/ocaml/std_string/README +++ b/Examples/ocaml/std_string/README @@ -1,3 +1,9 @@ +--- New --- + +It's not possible to access std::(w)string at the moment as it breaks other string examples. + +--- Old --- + This example shows how to use both std::string and std::wstring in Ocaml, and also demonstrates that one might use this to make a locale-obedient Ocaml program. diff --git a/Examples/ocaml/strings_test/example.h b/Examples/ocaml/strings_test/example.h index 3417981f0..959404b5d 100644 --- a/Examples/ocaml/strings_test/example.h +++ b/Examples/ocaml/strings_test/example.h @@ -1,14 +1,18 @@ /* -*- mode: c++ -*- */ /* File : example.h -- Tests all string typemaps */ +#include <sys/time.h> +#include <time.h> + void takes_std_string( std::string in ) { cout << "takes_std_string( \"" << in << "\" );" << endl; } std::string gives_std_string() { - time_t t; - - return std::string( asctime( localtime( &t ) ) ); + struct timeval tv; + + gettimeofday(&tv, NULL); + return std::string( asctime( localtime( &tv.tv_sec ) ) ); } void takes_char_ptr( char *p ) { @@ -24,10 +28,10 @@ void takes_and_gives_std_string( std::string &inout ) { inout.insert( inout.end(), ']' ); } -void takes_and_gives_char_ptr( char *&ptr ) { - char *pout = strchr( ptr, '.' ); - if( pout ) ptr = pout + 1; - else ptr = "foo"; +void takes_and_gives_char_ptr( char *&inout ) { + char *pout = strchr( inout, '.' ); + if( pout ) inout = pout + 1; + else inout = "foo"; } /* diff --git a/Examples/php/cpointer/runme.php b/Examples/php/cpointer/runme.php index 48f0ad631..22e8a681a 100644 --- a/Examples/php/cpointer/runme.php +++ b/Examples/php/cpointer/runme.php @@ -6,40 +6,42 @@ print "Testing the pointer library\n"; - $a = new_intp(); - $b = new_intp(); - $c = new_intp(); - intp_assign($a,37); - intp_assign($b,42); + $a = example::new_intp(); + $b = example::new_intp(); + $c = example::new_intp(); + example::intp_assign($a,37); + example::intp_assign($b,42); print " a = $a\n"; print " b = $b\n"; print " c = $c\n"; # Call the add() function wuth some pointers - add($a,$b,$c); + example::add($a,$b,$c); # Now get the result - $r = intp_value($c); + $r = example::intp_value($c); print " 37 + 42 = $r\n"; # Clean up the pointers - delete_intp($a); - delete_intp($b); - delete_intp($c); + example::delete_intp($a); + example::delete_intp($b); + example::delete_intp($c); # Now try the typemap library # This should be much easier. Now how it is no longer # necessary to manufacture pointers. print "Trying the typemap library\n"; - $r = sub(37,42); + $r = example::sub(37,42); print " 37 - 42 = $r\n"; # Now try the version with multiple return values # print "Testing multiple return values\n"; - # ($q,$r) = divide(42,37); + # $a = example::divide(42,37); + # $q = $a[0] + # $r = $a[1] # print " 42/37 = $q remainder $r\n"; ?> diff --git a/Examples/php/overloading/runme.php b/Examples/php/overloading/runme.php index 01044445f..56d515138 100644 --- a/Examples/php/overloading/runme.php +++ b/Examples/php/overloading/runme.php @@ -35,11 +35,10 @@ print " Square = (" . $s->x . "," . $s->y . ")\n"; # ----- Call some methods ----- -print "\nHere are some properties of the shapes:\n"; +print "\nCall some overloaded methods:\n"; foreach (array(1, 2.1, "quick brown fox", $c, $s) as $o) { - print " ".get_class($o)." \$o\n"; - print " overloaded = " . overloaded($o) . "\n"; - } + print " overloaded = " . overloaded($o) . "\n"; +} # Need to unset($o) or else we hang on to a reference to the Square object. unset($o); diff --git a/Examples/test-suite/abstract_virtual.i b/Examples/test-suite/abstract_virtual.i index 2e4d105b1..d8372c936 100644 --- a/Examples/test-suite/abstract_virtual.i +++ b/Examples/test-suite/abstract_virtual.i @@ -2,10 +2,12 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) D; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) D; /* C#, D, Java, PHP multiple inheritance */ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, D, Java, PHP multiple inheritance */ %inline %{ #if defined(_MSC_VER) diff --git a/Examples/test-suite/char_binary.i b/Examples/test-suite/char_binary.i new file mode 100644 index 000000000..778792946 --- /dev/null +++ b/Examples/test-suite/char_binary.i @@ -0,0 +1,29 @@ +/* +A test case for testing non null terminated char pointers. +*/ + +%module char_binary + +%apply (char *STRING, size_t LENGTH) { (const char *str, size_t len) } + +%inline %{ +struct Test { + size_t strlen(const char *str, size_t len) { + return len; + } +}; + +typedef char namet[5]; +namet var_namet; + +typedef char* pchar; +pchar var_pchar; +%} + +// Remove string handling typemaps and treat as pointer +%typemap(freearg) SWIGTYPE * "" +%apply SWIGTYPE * { char * } + +%include "carrays.i" +%array_functions(char, pchar); + diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index c1952543f..5f3012091 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -154,6 +154,7 @@ CPP_TEST_CASES += \ derived_nested \ destructor_reprotected \ director_abstract \ + director_alternating \ director_basic \ director_classes \ director_classic \ @@ -166,6 +167,7 @@ CPP_TEST_CASES += \ director_finalizer \ director_frob \ director_ignore \ + director_keywords \ director_namespace_clash \ director_nested \ director_overload \ @@ -228,9 +230,11 @@ CPP_TEST_CASES += \ li_cpointer \ li_stdint \ li_typemaps \ + li_typemaps_apply \ li_windows \ long_long_apply \ memberin_extend \ + member_funcptr_galore \ member_pointer \ member_template \ minherit \ @@ -283,7 +287,10 @@ CPP_TEST_CASES += \ rename3 \ rename4 \ rename_scope \ + rename_simple \ rename_strip_encoder \ + rename_pcre_encoder \ + rename_pcre_enum \ restrict_cplusplus \ return_const_value \ return_value_scope \ @@ -292,6 +299,7 @@ CPP_TEST_CASES += \ sizet \ smart_pointer_const \ smart_pointer_const2 \ + smart_pointer_const_overload \ smart_pointer_extend \ smart_pointer_member \ smart_pointer_multi \ @@ -315,11 +323,11 @@ CPP_TEST_CASES += \ struct_initialization_cpp \ struct_value \ symbol_clash \ - template \ template_arg_replace \ template_arg_scope \ template_arg_typename \ template_array_numeric \ + template_basic \ template_base_template \ template_classes \ template_const_ref \ @@ -393,6 +401,7 @@ CPP_TEST_CASES += \ typedef_scope \ typedef_sizet \ typedef_struct \ + typemap_arrays \ typemap_delete \ typemap_global_scope \ typemap_namespace \ @@ -463,7 +472,7 @@ C_TEST_CASES += \ extern_declaration \ funcptr \ function_typedef \ - immutable \ + immutable_values \ inctest \ integers \ keyword_rename \ @@ -484,6 +493,9 @@ C_TEST_CASES += \ overload_extendc \ preproc \ preproc_constants_c \ + preproc_defined \ + preproc_include \ + preproc_line_file \ ret_by_value \ simple_array \ sizeof_pointer \ @@ -507,6 +519,7 @@ MULTI_CPP_TEST_CASES += \ # Custom tests - tests with additional commandline options wallkw.cpptest: SWIGOPT += -Wallkw +preproc_include.ctest: SWIGOPT += -includeall NOT_BROKEN_TEST_CASES = $(CPP_TEST_CASES:=.cpptest) \ diff --git a/Examples/test-suite/constant_pointers.i b/Examples/test-suite/constant_pointers.i index 7d46cdb31..388970c4d 100644 --- a/Examples/test-suite/constant_pointers.i +++ b/Examples/test-suite/constant_pointers.i @@ -5,7 +5,8 @@ This testcase primarily test constant pointers, eg int* const. Only a getter is %module constant_pointers %warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */ -%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'Foo' due to Go name ('Foo') conflict with 'foo' */ +%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG); /* Setting a pointer/reference variable may leak memory. */ + %inline %{ @@ -50,7 +51,7 @@ public: private: MemberVariablesTest& operator=(const MemberVariablesTest&); }; -void foo(const int *const i) {} +void foofunction(const int *const i) {} typedef int *typedef1, typedef2, *const typedef3; int int1, int2=2, *int3, *const int4 = &GlobalInt; diff --git a/Examples/test-suite/contract.i b/Examples/test-suite/contract.i index b979ef19e..0ad7e8e7c 100644 --- a/Examples/test-suite/contract.i +++ b/Examples/test-suite/contract.i @@ -3,12 +3,17 @@ %warnfilter(SWIGWARN_RUBY_MULTIPLE_INHERITANCE, SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) C; /* Ruby, C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) C; /* Ruby, C#, D, Java, PHP multiple inheritance */ #ifdef SWIGCSHARP %ignore B::bar; // otherwise get a warning: `C.bar' no suitable methods found to override #endif +#ifdef SWIGD +%ignore B::bar; // Prevents getting an error that C.bar does not override any function because multiple inheritance is not supported. +#endif + %contract test_preassert(int a, int b) { require: a > 0; diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in index 5f50095a1..18f10c567 100644 --- a/Examples/test-suite/csharp/Makefile.in +++ b/Examples/test-suite/csharp/Makefile.in @@ -8,8 +8,8 @@ INTERPRETER = @CSHARPCILINTERPRETER@ CSHARPPATHSEPARATOR = "@CSHARPPATHSEPARATOR@" CSHARPCYGPATH_W = @CSHARPCYGPATH_W@ srcdir = @srcdir@ -top_srcdir = @top_srcdir@/.. -top_builddir = @top_builddir@/.. +top_srcdir = ../@top_srcdir@ +top_builddir = ../@top_builddir@ CPP_TEST_CASES = \ csharp_attributes \ @@ -64,12 +64,13 @@ setup = \ # Compiles C# files then runs the testcase. A testcase is only run if # a file is found which has _runme.cs appended after the testcase name. # Note C# uses LD_LIBRARY_PATH under Unix, PATH under Cygwin/Windows and SHLIB_PATH on HPUX. +# DYLD_FALLBACK_LIBRARY_PATH is cleared for MacOSX. run_testcase = \ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \ CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile && \ - env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \ + env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" DYLD_FALLBACK_LIBRARY_PATH= $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \ else \ cd $* && \ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ diff --git a/Examples/test-suite/csharp/csharp_prepost_runme.cs b/Examples/test-suite/csharp/csharp_prepost_runme.cs index d0bacdaba..f76dae38e 100644 --- a/Examples/test-suite/csharp/csharp_prepost_runme.cs +++ b/Examples/test-suite/csharp/csharp_prepost_runme.cs @@ -55,6 +55,43 @@ public class csharp_prepost_runme { throw new Exception("Expecting CustomInt attribute"); } } + // Dates + { + // pre post typemap attributes example + System.DateTime dateIn = new System.DateTime(2011, 4, 13); + System.DateTime dateOut = new System.DateTime(); + + // Note in calls below, dateIn remains unchanged and dateOut + // is set to a new value by the C++ call + csharp_prepostNamespace.Action action = new csharp_prepostNamespace.Action(dateIn, out dateOut); + if (dateOut != dateIn) + throw new Exception("dates wrong"); + + dateIn = new System.DateTime(2012, 7, 14); + action.doSomething(dateIn, out dateOut); + if (dateOut != dateIn) + throw new Exception("dates wrong"); + + System.DateTime refDate = new System.DateTime(1999, 12, 31); + if (csharp_prepost.ImportantDate != refDate) + throw new Exception("dates wrong"); + + refDate = new System.DateTime(1999, 12, 31); + csharp_prepost.ImportantDate = refDate; + System.DateTime importantDate = csharp_prepost.ImportantDate; + if (importantDate != refDate) + throw new Exception("dates wrong"); + + System.DateTime christmasEve = new System.DateTime(2000, 12, 24); + csharp_prepost.addYears(ref christmasEve, 10); + if (christmasEve != new System.DateTime(2010, 12, 24)) + throw new Exception("dates wrong"); + + Person person = new Person(); + person.Birthday = christmasEve; + if (person.Birthday != christmasEve) + throw new Exception("dates wrong"); + } } private static void Assert(double d1, double d2) { if (d1 != d2) diff --git a/Examples/test-suite/csharp/director_alternating_runme.cs b/Examples/test-suite/csharp/director_alternating_runme.cs new file mode 100644 index 000000000..19365217a --- /dev/null +++ b/Examples/test-suite/csharp/director_alternating_runme.cs @@ -0,0 +1,11 @@ + +using System; +using director_alternatingNamespace; + +public class director_alternating_runme { + public static void Main() { + if (director_alternating.getBar().id() != director_alternating.idFromGetBar()) + throw new Exception("idFromGetBar failed"); + } +} + diff --git a/Examples/test-suite/csharp/director_protected_runme.cs b/Examples/test-suite/csharp/director_protected_runme.cs index ee4697b0e..b44c3b7e9 100644 --- a/Examples/test-suite/csharp/director_protected_runme.cs +++ b/Examples/test-suite/csharp/director_protected_runme.cs @@ -16,6 +16,7 @@ public class runme Foo f = b.create(); FooBar fb = new FooBar(); FooBar2 fb2 = new FooBar2(); + FooBar3 fb3 = new FooBar3(); String s; s = fb.used(); @@ -37,6 +38,21 @@ public class runme s = fb.pong(); if ( s != ("Bar::pong();Foo::pong();FooBar::ping();")) throw new Exception("bad FooBar::pong"); + +// if (fb3.cheer() != "FooBar3::cheer();") +// throw new Exception("bad fb3::cheer"); + + if (fb2.callping() != "FooBar2::ping();") + throw new Exception("bad fb2.callping"); + + if (fb2.callcheer() != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();") + throw new Exception("bad fb2.callcheer"); + + if (fb3.callping() != "Bar::ping();") + throw new Exception("bad fb3.callping"); + + if (fb3.callcheer() != "FooBar3::cheer();") + throw new Exception("bad fb3.callcheer"); } } @@ -69,4 +85,16 @@ class FooBar2 : Bar } } +class FooBar3 : Bar +{ + public FooBar3() : base() + { + } + + protected override String cheer() + { + return "FooBar3::cheer();"; + } +} + } diff --git a/Examples/test-suite/csharp/pointer_reference_runme.cs b/Examples/test-suite/csharp/pointer_reference_runme.cs index d00555199..2b9f526af 100644 --- a/Examples/test-suite/csharp/pointer_reference_runme.cs +++ b/Examples/test-suite/csharp/pointer_reference_runme.cs @@ -12,6 +12,9 @@ public class pointer_reference_runme { Struct ss = new Struct(20); pointer_reference.set(ss); if (Struct.instance.value != 20) throw new Exception("set test failed"); + + if (pointer_reference.overloading(1) != 111) throw new Exception("overload test 1 failed"); + if (pointer_reference.overloading(ss) != 222) throw new Exception("overload test 2 failed"); } } diff --git a/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs b/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs new file mode 100644 index 000000000..f6289e7e2 --- /dev/null +++ b/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs @@ -0,0 +1,12 @@ +using System; +using rename_pcre_encoderNamespace; + +public class runme { + static void Main() { + SomeWidget w = new SomeWidget(); + w.putBorderWidth(17); + if ( w.getBorderWidth() != 17 ) + throw new Exception(String.Format("Border with should be 17, not {0}", + w.getBorderWidth())); + } +} diff --git a/Examples/test-suite/csharp/rename_pcre_enum_runme.cs b/Examples/test-suite/csharp/rename_pcre_enum_runme.cs new file mode 100644 index 000000000..0143eda33 --- /dev/null +++ b/Examples/test-suite/csharp/rename_pcre_enum_runme.cs @@ -0,0 +1,24 @@ +using System; +using rename_pcre_enumNamespace; + +public class runme { + static void Main() { + Foo foo = Foo.First; + if ( foo == Foo.Second ) + throw new Exception("Enum values should be different"); + + // Check that Foo_Max enum element was ignored. + int numFooEnumElements = Enum.GetValues(typeof(Foo)).Length; + if ( numFooEnumElements != 2 ) + throw new Exception(String.Format("Enum should have 2 elements, not {0}", + numFooEnumElements)); + + BoundaryCondition bc = BoundaryCondition.MaxMax; + if ( (int)bc != 2 ) + throw new Exception("Wrong enum value"); + + Colour c = Colour.red; + if ( c == Colour.blue ) + throw new Exception("Enum values should be different"); + } +} diff --git a/Examples/test-suite/csharp/rename_simple_runme.cs b/Examples/test-suite/csharp/rename_simple_runme.cs new file mode 100644 index 000000000..edf05ad24 --- /dev/null +++ b/Examples/test-suite/csharp/rename_simple_runme.cs @@ -0,0 +1,30 @@ + +using System; +using rename_simpleNamespace; + +public class rename_simple_runme { + + public static void Main() { + NewStruct s = new NewStruct(); + check(111, s.NewInstanceVariable, "NewInstanceVariable"); + check(222, s.NewInstanceMethod(), "NewInstanceMethod"); + check(333, NewStruct.NewStaticMethod(), "NewStaticMethod"); + check(444, NewStruct.NewStaticVariable, "NewStaticVariable"); + check(555, rename_simple.NewFunction(), "NewFunction"); + check(666, rename_simple.NewGlobalVariable, "NewGlobalVariable"); + + s.NewInstanceVariable = 1111; + NewStruct.NewStaticVariable = 4444; + rename_simple.NewGlobalVariable = 6666; + + check(1111, s.NewInstanceVariable, "NewInstanceVariable"); + check(4444, NewStruct.NewStaticVariable, "NewStaticVariable"); + check(6666, rename_simple.NewGlobalVariable, "NewGlobalVariable"); + } + + public static void check(int expected, int actual, string msg) { + if (expected != actual) + throw new Exception("Failed: Expected: " + expected + " actual: " + actual + " " + msg); + } +} + diff --git a/Examples/test-suite/csharp_attributes.i b/Examples/test-suite/csharp_attributes.i index bca595d9a..f679d8c08 100644 --- a/Examples/test-suite/csharp_attributes.i +++ b/Examples/test-suite/csharp_attributes.i @@ -56,7 +56,7 @@ double MoreStations::WestonSuperMare = 0.0; %inline %{ struct YetMoreStations { - virtual int Slough(int x) {} + virtual int Slough(int x) { return x; } virtual ~YetMoreStations() {} }; %} diff --git a/Examples/test-suite/csharp_prepost.i b/Examples/test-suite/csharp_prepost.i index 817f5b9b9..31e6ec753 100644 --- a/Examples/test-suite/csharp_prepost.i +++ b/Examples/test-suite/csharp_prepost.i @@ -79,7 +79,7 @@ struct PrePost2 { // Check attributes in the typemaps %typemap(cstype, inattributes="[CustomInt]") int val "int" -%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int "tmp_$csinput" +%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int val "tmp_$csinput" %typemap(imtype, out="IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "HandleRef/*overridden*/" %inline %{ @@ -188,5 +188,8 @@ void subtractYears(CDate *pDate, int years) { %inline %{ CDate ImportantDate = CDate(1999, 12, 31); +struct Person { + CDate Birthday; +}; %} diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in new file mode 100644 index 000000000..0f5bf8cbb --- /dev/null +++ b/Examples/test-suite/d/Makefile.in @@ -0,0 +1,81 @@ +####################################################################### +# Makefile for D test-suite +####################################################################### + +LANGUAGE = d +srcdir = @srcdir@ +top_srcdir = ../@top_srcdir@ +top_builddir = ../@top_builddir@ + +ifeq (2,$(D_VERSION)) + VERSIONSUFFIX = .2 +else + VERSIONSUFFIX = .1 +endif + +TESTSUFFIX = _runme$(VERSIONSUFFIX).d + +CPP_TEST_CASES = \ + d_exception_name \ + d_nativepointers \ + exception_partial_info + +include $(srcdir)/../common.mk + +# Override some variables from common.mk: + +TARGETSUFFIX = _wrap + +SWIGOPT+=-splitproxy -package $* + +# Rules for the different types of tests +%.cpptest: + $(setup) + +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_cpp)) + +$(run_testcase) + +%.ctest: + $(setup) + +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_c)) + +$(run_testcase) + +%.multicpptest: + $(setup) + +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_multi_cpp)) + +$(run_testcase) + +# Makes a directory for the testcase if it does not exist +setup = \ + if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \ + echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ + else \ + echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ + fi; \ + if [ ! -d $*$(VERSIONSUFFIX) ]; then \ + mkdir $*$(VERSIONSUFFIX); \ + fi; \ + if [ ! -d $*$(VERSIONSUFFIX)/$* ]; then \ + mkdir $*$(VERSIONSUFFIX)/$*; \ + fi + +# Compiles D files then runs the testcase. A testcase is only run if +# a file is found which has _runme.d appended after the testcase name. +run_testcase = \ + if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \ + cd $*$(VERSIONSUFFIX) && \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ + DFLAGS='-of$*_runme' \ + DSRCS='../$(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) $*/*.d' d_compile && \ + env LD_LIBRARY_PATH=".:$$LD_LIBRARY_PATH" $(RUNTOOL) ./$*_runme; \ + else \ + cd $*$(VERSIONSUFFIX) && \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ + DFLAGS='-c' \ + DSRCS='$*/*.d' d_compile && cd .. ; \ + fi + +# Clean: remove testcase directories +%.clean: + @if [ -d $*$(VERSIONSUFFIX) ]; then \ + rm -rf $*$(VERSIONSUFFIX); \ + fi diff --git a/Examples/test-suite/d/README b/Examples/test-suite/d/README new file mode 100644 index 000000000..bb5372882 --- /dev/null +++ b/Examples/test-suite/d/README @@ -0,0 +1,7 @@ +D language module testsuite +--------------------------- + +Please see ../README for the common readme file. + +By default the D1 version is built, set D_VERSION=2 (in the environment or at +the make command line) to run it for D2 instead. diff --git a/Examples/test-suite/d/aggregate_runme.1.d b/Examples/test-suite/d/aggregate_runme.1.d new file mode 100644 index 000000000..a00d34c25 --- /dev/null +++ b/Examples/test-suite/d/aggregate_runme.1.d @@ -0,0 +1,25 @@ +module aggregate_runme; + +import aggregate.aggregate; + +void main() { + // Confirm that move() returns correct results under normal use. + int result = move(UP); + if (result != UP) throw new Exception("UP failed"); + + result = move(DOWN); + if (result != DOWN) throw new Exception("DOWN failed"); + + result = move(LEFT); + if (result != LEFT) throw new Exception("LEFT failed"); + + result = move(RIGHT); + if (result != RIGHT) throw new Exception("RIGHT failed"); + + // Confirm that move() raises an exception when the contract is violated. + try { + move(0); + throw new Exception("0 test failed"); + } + catch (Exception e) {} +} diff --git a/Examples/test-suite/d/aggregate_runme.2.d b/Examples/test-suite/d/aggregate_runme.2.d new file mode 100644 index 000000000..a00d34c25 --- /dev/null +++ b/Examples/test-suite/d/aggregate_runme.2.d @@ -0,0 +1,25 @@ +module aggregate_runme; + +import aggregate.aggregate; + +void main() { + // Confirm that move() returns correct results under normal use. + int result = move(UP); + if (result != UP) throw new Exception("UP failed"); + + result = move(DOWN); + if (result != DOWN) throw new Exception("DOWN failed"); + + result = move(LEFT); + if (result != LEFT) throw new Exception("LEFT failed"); + + result = move(RIGHT); + if (result != RIGHT) throw new Exception("RIGHT failed"); + + // Confirm that move() raises an exception when the contract is violated. + try { + move(0); + throw new Exception("0 test failed"); + } + catch (Exception e) {} +} diff --git a/Examples/test-suite/d/allprotected_runme.1.d b/Examples/test-suite/d/allprotected_runme.1.d new file mode 100644 index 000000000..82a180e66 --- /dev/null +++ b/Examples/test-suite/d/allprotected_runme.1.d @@ -0,0 +1,65 @@ +module allprotected_runme; + +import allprotected.Klass; +import allprotected.ProtectedBase; + +void main() { + auto mpb = new MyProtectedBase("MyProtectedBase"); + mpb.accessProtected(); +} + +class MyProtectedBase : ProtectedBase { +public: + this(char[] name) { + super(name); + } + + void accessProtected() { + char[] s = virtualMethod(); + if (s != "ProtectedBase") + throw new Exception("Failed"); + + Klass k = instanceMethod(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = staticMethod(new Klass("abc")); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = staticOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = staticOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + instanceMemberVariable = 30; + int i = instanceMemberVariable; + if (i != 30) + throw new Exception("Failed"); + + staticMemberVariable = 40; + i = staticMemberVariable; + if (i != 40) + throw new Exception("Failed"); + + i = staticConstMemberVariable; + if (i != 20) + throw new Exception("Failed"); + + anEnum = ProtectedBase.AnEnum.EnumVal1; + ProtectedBase.AnEnum ae = anEnum; + if (ae != ProtectedBase.AnEnum.EnumVal1) + throw new Exception("Failed"); + } +} diff --git a/Examples/test-suite/d/allprotected_runme.2.d b/Examples/test-suite/d/allprotected_runme.2.d new file mode 100644 index 000000000..799230291 --- /dev/null +++ b/Examples/test-suite/d/allprotected_runme.2.d @@ -0,0 +1,65 @@ +module allprotected_runme; + +import allprotected.Klass; +import allprotected.ProtectedBase; + +void main() { + auto mpb = new MyProtectedBase("MyProtectedBase"); + mpb.accessProtected(); +} + +class MyProtectedBase : ProtectedBase { +public: + this(string name) { + super(name); + } + + void accessProtected() { + string s = virtualMethod(); + if (s != "ProtectedBase") + throw new Exception("Failed"); + + Klass k = instanceMethod(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = staticMethod(new Klass("abc")); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = staticOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = staticOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + instanceMemberVariable = 30; + int i = instanceMemberVariable; + if (i != 30) + throw new Exception("Failed"); + + staticMemberVariable = 40; + i = staticMemberVariable; + if (i != 40) + throw new Exception("Failed"); + + i = staticConstMemberVariable; + if (i != 20) + throw new Exception("Failed"); + + anEnum = ProtectedBase.AnEnum.EnumVal1; + ProtectedBase.AnEnum ae = anEnum; + if (ae != ProtectedBase.AnEnum.EnumVal1) + throw new Exception("Failed"); + } +} diff --git a/Examples/test-suite/d/apply_strings_runme.1.d b/Examples/test-suite/d/apply_strings_runme.1.d new file mode 100644 index 000000000..960caa4ca --- /dev/null +++ b/Examples/test-suite/d/apply_strings_runme.1.d @@ -0,0 +1,12 @@ +module apply_strings_runme; + +import apply_strings.apply_strings; + +const char[] TEST_MESSAGE = "A message from target language to the C++ world and back again."; + +void main() { + if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed"); + if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed"); + auto pChar = CharFunction(null); + if (pChar !is null) throw new Exception("CharFunction failed"); +} diff --git a/Examples/test-suite/d/apply_strings_runme.2.d b/Examples/test-suite/d/apply_strings_runme.2.d new file mode 100644 index 000000000..86183f8a3 --- /dev/null +++ b/Examples/test-suite/d/apply_strings_runme.2.d @@ -0,0 +1,12 @@ +module apply_strings_runme; + +import apply_strings.apply_strings; + +enum string TEST_MESSAGE = "A message from target language to the C++ world and back again."; + +void main() { + if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed"); + if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed"); + auto pChar = CharFunction(null); + if (pChar !is null) throw new Exception("CharFunction failed"); +} diff --git a/Examples/test-suite/d/bools_runme.1.d b/Examples/test-suite/d/bools_runme.1.d new file mode 100644 index 000000000..f501b0762 --- /dev/null +++ b/Examples/test-suite/d/bools_runme.1.d @@ -0,0 +1,20 @@ +/// This is the bool runtime testcase. It checks that the C++ bool type works. +module bools_runme; + +import bools.bools; + +void main() { + bool t = true; + bool f = false; + + check_bo(f); + check_bo(t); +} + +void check_bo(bool input) { + for (int i = 0; i < 1000; ++i) { + if (bo(input) != input) { + throw new Exception("Runtime test check_bo failed."); + } + } +} diff --git a/Examples/test-suite/d/bools_runme.2.d b/Examples/test-suite/d/bools_runme.2.d new file mode 100644 index 000000000..f501b0762 --- /dev/null +++ b/Examples/test-suite/d/bools_runme.2.d @@ -0,0 +1,20 @@ +/// This is the bool runtime testcase. It checks that the C++ bool type works. +module bools_runme; + +import bools.bools; + +void main() { + bool t = true; + bool f = false; + + check_bo(f); + check_bo(t); +} + +void check_bo(bool input) { + for (int i = 0; i < 1000; ++i) { + if (bo(input) != input) { + throw new Exception("Runtime test check_bo failed."); + } + } +} diff --git a/Examples/test-suite/d/catches_runme.1.d b/Examples/test-suite/d/catches_runme.1.d new file mode 100644 index 000000000..55b18132d --- /dev/null +++ b/Examples/test-suite/d/catches_runme.1.d @@ -0,0 +1,33 @@ +module catches_runme; + +import catches.catches; + +void main() { + test({ test_catches(1); }, "C++ int exception thrown, value: 1"); + test({ test_catches(2); }, "two"); + test({ test_catches(3); }, "C++ ThreeException const & exception thrown"); + + test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1"); + test({ test_exception_specification(2); }, "unknown exception"); + test({ test_exception_specification(3); }, "unknown exception"); + + test({ test_catches_all(1); }, "unknown exception"); +} + +void test(void delegate() command, char[] expectedMessage) { + bool didntThrow; + try { + command(); + didntThrow = true; + } catch (Exception e) { + if (e.msg != expectedMessage) { + throw new Exception("Failed to propagate C++ exception. Expected '" ~ + expectedMessage ~ "', but received '" ~ e.msg ~ "'."); + } + } + + if (didntThrow) { + throw new Exception("Failed to propagate C++ exception. Expected '" ~ + expectedMessage ~ "', but no exception was thrown."); + } +} diff --git a/Examples/test-suite/d/catches_runme.2.d b/Examples/test-suite/d/catches_runme.2.d new file mode 100644 index 000000000..508558485 --- /dev/null +++ b/Examples/test-suite/d/catches_runme.2.d @@ -0,0 +1,33 @@ +module catches_runme; + +import catches.catches; + +void main() { + test({ test_catches(1); }, "C++ int exception thrown, value: 1"); + test({ test_catches(2); }, "two"); + test({ test_catches(3); }, "C++ ThreeException const & exception thrown"); + + test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1"); + test({ test_exception_specification(2); }, "unknown exception"); + test({ test_exception_specification(3); }, "unknown exception"); + + test({ test_catches_all(1); }, "unknown exception"); +} + +void test(void delegate() command, string expectedMessage) { + bool didntThrow; + try { + command(); + didntThrow = true; + } catch (Exception e) { + if (e.msg != expectedMessage) { + throw new Exception("Failed to propagate C++ exception. Expected '" ~ + expectedMessage ~ "', but received '" ~ e.msg ~ "'."); + } + } + + if (didntThrow) { + throw new Exception("Failed to propagate C++ exception. Expected '" ~ + expectedMessage ~ "', but no exception was thrown."); + } +} diff --git a/Examples/test-suite/d/char_strings_runme.1.d b/Examples/test-suite/d/char_strings_runme.1.d new file mode 100644 index 000000000..cde6fe0f7 --- /dev/null +++ b/Examples/test-suite/d/char_strings_runme.1.d @@ -0,0 +1,151 @@ +module char_strings_runme; + +import tango.text.convert.Integer; +import char_strings.char_strings; + +const char[] CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible."; +const char[] OTHERLAND_MSG = "Little message from the safe world."; + +void main() { + const uint count = 10000; + uint i = 0; + + // get functions + for (i=0; i<count; i++) { + char[] str = GetCharHeapString(); + if (str != CPLUSPLUS_MSG) + throw new Exception("Test char get 1 failed, iteration " ~ toString(i)); + DeleteCharHeapString(); + } + + for (i=0; i<count; i++) { + char[] str = GetConstCharProgramCodeString(); + if (str != CPLUSPLUS_MSG) + throw new Exception("Test char get 2 failed, iteration " ~ toString(i)); + DeleteCharHeapString(); + } + + for (i=0; i<count; i++) { + char[] str = GetCharStaticString(); + if (str != CPLUSPLUS_MSG) + throw new Exception("Test char get 3 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + char[] str = GetCharStaticStringFixed(); + if (str != CPLUSPLUS_MSG) + throw new Exception("Test char get 4 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + char[] str = GetConstCharStaticStringFixed(); + if (str != CPLUSPLUS_MSG) + throw new Exception("Test char get 5 failed, iteration " ~ toString(i)); + } + + // set functions + for (i=0; i<count; i++) { + if (!SetCharHeapString(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test char set 1 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (!SetCharStaticString(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test char set 2 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (!SetCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test char set 3 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (!SetConstCharHeapString(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test char set 4 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (!SetConstCharStaticString(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test char set 5 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (!SetConstCharArrayStaticString(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test char set 6 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (!SetCharConstStaticString(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test char set 7 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (!SetConstCharConstStaticString(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test char set 8 failed, iteration " ~ toString(i)); + } + + // get set function + for (i=0; i<count*10; i++) { + char[] ping = OTHERLAND_MSG ~ toString(i); + char[] pong = CharPingPong(ping); + if (ping != pong) + throw new Exception("Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong); + } + + // variables + for (i=0; i<count; i++) { + global_char = OTHERLAND_MSG ~ toString(i); + if (global_char != OTHERLAND_MSG ~ toString(i)) + throw new Exception("Test variables 1 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + global_char_array1 = OTHERLAND_MSG ~ toString(i); + if (global_char_array1 != OTHERLAND_MSG ~ toString(i)) + throw new Exception("Test variables 2 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + global_char_array2 = OTHERLAND_MSG ~ toString(i); + if (global_char_array2 != OTHERLAND_MSG ~ toString(i)) + throw new Exception("Test variables 3 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (global_const_char != CPLUSPLUS_MSG) + throw new Exception("Test variables 4 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (global_const_char_array1 != CPLUSPLUS_MSG) + throw new Exception("Test variables 5 failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (global_const_char_array2 != CPLUSPLUS_MSG) + throw new Exception("Test variables 6 failed, iteration " ~ toString(i)); + } + + // char *& tests + for (i=0; i<count; i++) { + char[] str = GetCharPointerRef(); + if (str != CPLUSPLUS_MSG) + throw new Exception("Test char pointer ref get failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (!SetCharPointerRef(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test char pointer ref set failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + char[] str = GetConstCharPointerRef(); + if (str != CPLUSPLUS_MSG) + throw new Exception("Test const char pointer ref get failed, iteration " ~ toString(i)); + } + + for (i=0; i<count; i++) { + if (!SetConstCharPointerRef(OTHERLAND_MSG ~ toString(i), i)) + throw new Exception("Test const char pointer ref set failed, iteration " ~ toString(i)); + } +} diff --git a/Examples/test-suite/d/char_strings_runme.2.d b/Examples/test-suite/d/char_strings_runme.2.d new file mode 100644 index 000000000..5fe28e995 --- /dev/null +++ b/Examples/test-suite/d/char_strings_runme.2.d @@ -0,0 +1,123 @@ +module char_strings_runme; + +import std.conv; +import std.exception; +import std.range; +import char_strings.char_strings; + +enum CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible."; +enum OTHERLAND_MSG = "Little message from the safe world."; +enum TEST_RANGE = iota(0, 10000); + +void main() { + // get functions + foreach (i; TEST_RANGE) { + enforce(GetCharHeapString() == CPLUSPLUS_MSG, "Test char get 1 failed, iteration " ~ to!string(i)); + DeleteCharHeapString(); + } + + foreach (i; TEST_RANGE) { + enforce(GetConstCharProgramCodeString() == CPLUSPLUS_MSG, "Test char get 2 failed, iteration " ~ to!string(i)); + DeleteCharHeapString(); + } + + foreach (i; TEST_RANGE) { + enforce(GetCharStaticString() == CPLUSPLUS_MSG, "Test char get 3 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(GetCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 4 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(GetConstCharStaticStringFixed() == CPLUSPLUS_MSG, "Test char get 5 failed, iteration " ~ to!string(i)); + } + + // set functions + foreach (i; TEST_RANGE) { + enforce(SetCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 1 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(SetCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 2 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(SetCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 3 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(SetConstCharHeapString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 4 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(SetConstCharStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 5 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(SetConstCharArrayStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 6 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(SetCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 7 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(SetConstCharConstStaticString(OTHERLAND_MSG ~ to!string(i), i), "Test char set 8 failed, iteration " ~ to!string(i)); + } + + // get set function + foreach (i; TEST_RANGE) { + string ping = OTHERLAND_MSG ~ to!string(i); + string pong = CharPingPong(ping); + enforce(ping == pong, "Test PingPong 1 failed.\nExpected:" ~ ping ~ "\nReceived:" ~ pong); + } + + // variables + foreach (i; TEST_RANGE) { + const msg = OTHERLAND_MSG ~ to!string(i); + global_char = msg; + enforce(global_char == msg, "Test variables 1 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + const msg = OTHERLAND_MSG ~ to!string(i); + global_char_array1 = msg; + enforce(global_char_array1 == msg, "Test variables 2 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + const msg = OTHERLAND_MSG ~ to!string(i); + global_char_array2 = msg; + enforce(global_char_array2 == msg, "Test variables 2 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(global_const_char == CPLUSPLUS_MSG, "Test variables 4 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(global_const_char_array1 == CPLUSPLUS_MSG, "Test variables 5 failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(global_const_char_array2 == CPLUSPLUS_MSG, "Test variables 6 failed, iteration " ~ to!string(i)); + } + + // char *& tests + foreach (i; TEST_RANGE) { + enforce(GetCharPointerRef() == CPLUSPLUS_MSG, "Test char pointer ref get failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(SetCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test char pointer ref set failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(GetConstCharPointerRef() == CPLUSPLUS_MSG, "Test const char pointer ref get failed, iteration " ~ to!string(i)); + } + + foreach (i; TEST_RANGE) { + enforce(SetConstCharPointerRef(OTHERLAND_MSG ~ to!string(i), i), "Test const char pointer ref set failed, iteration " ~ to!string(i)); + } +} diff --git a/Examples/test-suite/d/constover_runme.1.d b/Examples/test-suite/d/constover_runme.1.d new file mode 100644 index 000000000..ead67319e --- /dev/null +++ b/Examples/test-suite/d/constover_runme.1.d @@ -0,0 +1,31 @@ +module constover_runme; + +import constover.constover; +import constover.Foo; + +void main() { + char[] p = test("test"); + if (p != "test") + throw new Exception("test failed!"); + + p = test_pconst("test"); + if (p != "test_pconst") + throw new Exception("test_pconst failed!"); + + auto f = new Foo(); + p = f.test("test"); + if (p != "test") + throw new Exception("member-test failed!"); + + p = f.test_pconst("test"); + if (p != "test_pconst") + throw new Exception("member-test_pconst failed!"); + + p = f.test_constm("test"); + if (p != "test_constmethod") + throw new Exception("member-test_constm failed!"); + + p = f.test_pconstm("test"); + if (p != "test_pconstmethod") + throw new Exception("member-test_pconstm failed!"); +} diff --git a/Examples/test-suite/d/constover_runme.2.d b/Examples/test-suite/d/constover_runme.2.d new file mode 100644 index 000000000..68f7f207a --- /dev/null +++ b/Examples/test-suite/d/constover_runme.2.d @@ -0,0 +1,16 @@ +module constover_runme; + +import std.exception; +import constover.constover; +import constover.Foo; + +void main() { + enforce(test("test") == "test", "test failed!"); + enforce(test_pconst("test") == "test_pconst", "test_pconst failed!"); + + auto f = new Foo(); + enforce(f.test("test") == "test", "member-test failed!"); + enforce(f.test_pconst("test") == "test_pconst", "member-test_pconst failed!"); + enforce(f.test_constm("test") == "test_constmethod", "member-test_constm failed!"); + enforce(f.test_pconstm("test") == "test_pconstmethod", "member-test_pconstm failed!"); +} diff --git a/Examples/test-suite/d/d_nativepointers_runme.1.d b/Examples/test-suite/d/d_nativepointers_runme.1.d new file mode 100644 index 000000000..797c057d3 --- /dev/null +++ b/Examples/test-suite/d/d_nativepointers_runme.1.d @@ -0,0 +1,36 @@ +module d_nativepointers_runnme; + +import d_nativepointers.d_nativepointers; +import d_nativepointers.SomeClass; +import d_nativepointers.SWIGTYPE_p_OpaqueClass; +import d_nativepointers.SWIGTYPE_p_p_SomeClass; +import d_nativepointers.SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void; + +void main() { + check!(a, int*); + check!(b, float**); + check!(c, char***); + check!(d, SomeClass); + check!(e, SWIGTYPE_p_p_SomeClass); + check!(f, SWIGTYPE_p_OpaqueClass); + check!(g, void function(int**, char***)); + check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void); + + { + static assert(is(int* function(int*) == typeof(&refA))); + int v = 2; + assert(*refA(&v) == 2); + } + + { + static assert(is(float** function(float**) == typeof(&refB))); + float v = 1.0; + float* p = &v; + assert(**refB(&p) == 1.0); + } +} + +void check(alias F, T)() { + static assert(is(T function(T) == typeof(&F))); + assert(F(null) is null); +} diff --git a/Examples/test-suite/d/d_nativepointers_runme.2.d b/Examples/test-suite/d/d_nativepointers_runme.2.d new file mode 100644 index 000000000..797c057d3 --- /dev/null +++ b/Examples/test-suite/d/d_nativepointers_runme.2.d @@ -0,0 +1,36 @@ +module d_nativepointers_runnme; + +import d_nativepointers.d_nativepointers; +import d_nativepointers.SomeClass; +import d_nativepointers.SWIGTYPE_p_OpaqueClass; +import d_nativepointers.SWIGTYPE_p_p_SomeClass; +import d_nativepointers.SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void; + +void main() { + check!(a, int*); + check!(b, float**); + check!(c, char***); + check!(d, SomeClass); + check!(e, SWIGTYPE_p_p_SomeClass); + check!(f, SWIGTYPE_p_OpaqueClass); + check!(g, void function(int**, char***)); + check!(h, SWIGTYPE_p_p_f_p_p_int_p_SomeClass__void); + + { + static assert(is(int* function(int*) == typeof(&refA))); + int v = 2; + assert(*refA(&v) == 2); + } + + { + static assert(is(float** function(float**) == typeof(&refB))); + float v = 1.0; + float* p = &v; + assert(**refB(&p) == 1.0); + } +} + +void check(alias F, T)() { + static assert(is(T function(T) == typeof(&F))); + assert(F(null) is null); +} diff --git a/Examples/test-suite/d/default_args_runme.1.d b/Examples/test-suite/d/default_args_runme.1.d new file mode 100644 index 000000000..0ad63b7c2 --- /dev/null +++ b/Examples/test-suite/d/default_args_runme.1.d @@ -0,0 +1,127 @@ +module default_args_runme; + +import default_args.default_args; +import default_args.ConstMethods; +import default_args.EnumClass; +import default_args.Except; +import default_args.Foo; +import default_args.Klass; +import default_args.Statics; +import default_args.Tricky; + +void main() { + if (anonymous() != 7771) + throw new Exception("anonymous (1) failed"); + if (anonymous(1234) != 1234) + throw new Exception("anonymous (2) failed"); + + if (booltest() != true) + throw new Exception("booltest (1) failed"); + if (booltest(true) != true) + throw new Exception("booltest (2) failed"); + if (booltest(false) != false) + throw new Exception("booltest (3) failed"); + + auto ec = new EnumClass(); + if (ec.blah() != true) + throw new Exception("EnumClass failed"); + + if (casts1() != null) + throw new Exception("casts1 failed"); + + if (casts2() != "Hello") + throw new Exception("casts2 failed"); + + if (casts1("Ciao") != "Ciao") + throw new Exception("casts1 not default failed"); + + if (chartest1() != 'x') + throw new Exception("chartest1 failed"); + + if (chartest2() != '\0') + throw new Exception("chartest2 failed"); + + if (chartest1('y') != 'y') + throw new Exception("chartest1 not default failed"); + + if (chartest1('y') != 'y') + throw new Exception("chartest1 not default failed"); + + if (reftest1() != 42) + throw new Exception("reftest1 failed"); + + if (reftest1(400) != 400) + throw new Exception("reftest1 not default failed"); + + if (reftest2() != "hello") + throw new Exception("reftest2 failed"); + + // rename + auto foo = new Foo(); + foo.newname(); + foo.newname(10); + foo.renamed3arg(10, 10.0); + foo.renamed2arg(10); + foo.renamed1arg(); + + // exception specifications + testException( { exceptionspec(); }, "exceptionspec 1" ); + testException( { exceptionspec(-1); }, "exceptionspec 2" ); + testException( { exceptionspec(100); }, "exceptionspec 3" ); + + auto ex = new Except(false); + testException( { ex.exspec(); }, "exspec 1" ); + testException( { ex.exspec(-1); }, "exspec 2" ); + testException( { ex.exspec(100); }, "exspec 3" ); + testException( { ex = new Except(true); }, "Except constructor 1" ); + testException( { ex = new Except(true, -2); }, "Except constructor 2" ); + + // Default parameters in static class methods + if (Statics.staticmethod() != 10+20+30) + throw new Exception("staticmethod 1 failed"); + if (Statics.staticmethod(100) != 100+20+30) + throw new Exception("staticmethod 2 failed"); + if (Statics.staticmethod(100,200,300) != 100+200+300) + throw new Exception("staticmethod 3 failed"); + + + auto tricky = new Tricky(); + if (tricky.privatedefault() != 200) + throw new Exception("privatedefault failed"); + if (tricky.protectedint() != 2000) + throw new Exception("protectedint failed"); + if (tricky.protecteddouble() != 987.654) + throw new Exception("protecteddouble failed"); + if (tricky.functiondefault() != 500) + throw new Exception("functiondefault failed"); + if (tricky.contrived() != 'X') + throw new Exception("contrived failed"); + + if (constructorcall().val != -1) + throw new Exception("constructorcall test 1 failed"); + + if (constructorcall(new Klass(2222)).val != 2222) + throw new Exception("constructorcall test 2 failed"); + + if (constructorcall(new Klass()).val != -1) + throw new Exception("constructorcall test 3 failed"); + + // const methods + auto cm = new ConstMethods(); + if (cm.coo() != 20) + throw new Exception("coo test 1 failed"); + if (cm.coo(1.0) != 20) + throw new Exception("coo test 2 failed"); +} + +void testException(void delegate() command, char[] testName) { + bool didntThrow; + try { + command(); + didntThrow = true; + } catch (Exception e) {} + + if (didntThrow) { + throw new Exception(testName ~ " failed"); + } +} diff --git a/Examples/test-suite/d/default_args_runme.2.d b/Examples/test-suite/d/default_args_runme.2.d new file mode 100644 index 000000000..15688aec8 --- /dev/null +++ b/Examples/test-suite/d/default_args_runme.2.d @@ -0,0 +1,84 @@ +module default_args_runme; + +import std.exception; +import default_args.default_args; +import default_args.ConstMethods; +import default_args.EnumClass; +import default_args.Except; +import default_args.Foo; +import default_args.Klass; +import default_args.Statics; +import default_args.Tricky; + +void main() { + enforce(anonymous() == 7771, "anonymous (1) failed"); + enforce(anonymous(1234) == 1234,"anonymous (2) failed"); + enforce(booltest() == true, "booltest (1) failed"); + enforce(booltest(true) == true, "booltest (2) failed"); + enforce(booltest(false) == false, "booltest (3) failed"); + enforce((new EnumClass()).blah() == true, "EnumClass failed"); + enforce(casts1() == null, "casts1 failed"); + enforce(casts2() == "Hello", "casts2 failed"); + enforce(casts1("Ciao") == "Ciao", "casts1 not default failed"); + enforce(chartest1() == 'x', "chartest1 failed"); + enforce(chartest2() == '\0', "chartest2 failed"); + enforce(chartest1('y') == 'y', "chartest1 not default failed"); + enforce(chartest1('y') == 'y', "chartest1 not default failed"); + enforce(reftest1() == 42, "reftest1 failed"); + enforce(reftest1(400) == 400, "reftest1 not default failed"); + enforce(reftest2() == "hello", "reftest2 failed"); + + // rename + auto foo = new Foo(); + foo.newname(); + foo.newname(10); + foo.renamed3arg(10, 10.0); + foo.renamed2arg(10); + foo.renamed1arg(); + + // exception specifications + enforceThrows( (){ exceptionspec(); }, "exceptionspec 1" ); + enforceThrows( (){ exceptionspec(-1); }, "exceptionspec 2" ); + enforceThrows( (){ exceptionspec(100); }, "exceptionspec 3" ); + + auto ex = new Except(false); + enforceThrows( (){ ex.exspec(); }, "exspec 1" ); + enforceThrows( (){ ex.exspec(-1); }, "exspec 2" ); + enforceThrows( (){ ex.exspec(100); }, "exspec 3" ); + enforceThrows( (){ ex = new Except(true); }, "Except constructor 1" ); + enforceThrows( (){ ex = new Except(true, -2); }, "Except constructor 2" ); + + // Default parameters in static class methods + enforce(Statics.staticmethod() == 10+20+30, "staticmethod 1 failed"); + enforce(Statics.staticmethod(100) == 100+20+30, "staticmethod 2 failed"); + enforce(Statics.staticmethod(100,200,300) == 100+200+300, "staticmethod 3 failed"); + + auto tricky = new Tricky(); + enforce(tricky.privatedefault() == 200, "privatedefault failed"); + enforce(tricky.protectedint() == 2000, "protectedint failed"); + enforce(tricky.protecteddouble() == 987.654, "protecteddouble failed"); + enforce(tricky.functiondefault() == 500, "functiondefault failed"); + enforce(tricky.contrived() == 'X', "contrived failed"); + + enforce(constructorcall().val == -1, "constructorcall test 1 failed"); + enforce(constructorcall(new Klass(2222)).val == 2222, "constructorcall test 2 failed"); + enforce(constructorcall(new Klass()).val == -1, "constructorcall test 3 failed"); + + // const methods + const cm = new ConstMethods(); + enforce(cm.coo() == 20, "coo test 1 failed"); + enforce(cm.coo(1.0) == 20, "coo test 2 failed"); +} + +private void enforceThrows(void delegate() dg, string errorMessage) { + bool hasThrown; + try { + dg(); + } catch (Exception) { + hasThrown = true; + } finally { + if (!hasThrown) { + throw new Exception(errorMessage); + } + } +} diff --git a/Examples/test-suite/d/default_constructor_runme.1.d b/Examples/test-suite/d/default_constructor_runme.1.d new file mode 100644 index 000000000..3640218ae --- /dev/null +++ b/Examples/test-suite/d/default_constructor_runme.1.d @@ -0,0 +1,30 @@ +module default_constructor_runme; + +import default_constructor.FFF; +import default_constructor.G; + +void main() { + // Protected destructor test. + try { + { + scope g = new G(); + } + throw new Exception("Protected destructor exception should have been thrown"); + } catch (Exception e) { + if (e.msg != "C++ destructor does not have public access") { + throw e; + } + } + + // Private destructor test. + try { + { + scope f = new FFF(); + } + throw new Exception("Private destructor exception should have been thrown"); + } catch (Exception e) { + if (e.msg != "C++ destructor does not have public access") { + throw e; + } + } +} diff --git a/Examples/test-suite/d/default_constructor_runme.2.d b/Examples/test-suite/d/default_constructor_runme.2.d new file mode 100644 index 000000000..22f5bffd2 --- /dev/null +++ b/Examples/test-suite/d/default_constructor_runme.2.d @@ -0,0 +1,25 @@ +module default_constructor_runme; + +import default_constructor.FFF; +import default_constructor.G; + +void main() { + // D2 does not support something akin to D1/Tango dispose() for deterministic + // destruction yet. + + // enforceThrows((){ scope g = new G(); }, "Protected destructor exception should have been thrown"); + // enforceThrows((){ scope f = new FFF(); }, "Private destructor exception should have been thrown"); +} + +private void enforceThrows(void delegate() dg, string errorMessage) { + bool hasThrown; + try { + dg(); + } catch (Exception) { + hasThrown = true; + } finally { + if (!hasThrown) { + throw new Exception(errorMessage); + } + } +} diff --git a/Examples/test-suite/d/director_alternating_runme.1.d b/Examples/test-suite/d/director_alternating_runme.1.d new file mode 100644 index 000000000..27bd262fd --- /dev/null +++ b/Examples/test-suite/d/director_alternating_runme.1.d @@ -0,0 +1,7 @@ +module director_alternating_runme; + +import director_alternating.director_alternating; + +void main() { + assert(getBar().id() == idFromGetBar()); +} diff --git a/Examples/test-suite/d/director_alternating_runme.2.d b/Examples/test-suite/d/director_alternating_runme.2.d new file mode 100644 index 000000000..27bd262fd --- /dev/null +++ b/Examples/test-suite/d/director_alternating_runme.2.d @@ -0,0 +1,7 @@ +module director_alternating_runme; + +import director_alternating.director_alternating; + +void main() { + assert(getBar().id() == idFromGetBar()); +} diff --git a/Examples/test-suite/d/director_basic_runme.1.d b/Examples/test-suite/d/director_basic_runme.1.d new file mode 100644 index 000000000..58a54835e --- /dev/null +++ b/Examples/test-suite/d/director_basic_runme.1.d @@ -0,0 +1,59 @@ +module director_basic_runme; + +import director_basic.A1; +import director_basic.Bar; +import director_basic.Foo; +import director_basic.MyClass; + +void main() { + auto a = new director_basic_MyFoo(); + if (a.ping() != "director_basic_MyFoo::ping()") { + throw new Exception("a.ping()"); + } + if (a.pong() != "Foo::pong();director_basic_MyFoo::ping()") { + throw new Exception("a.pong()"); + } + + auto b = new Foo(); + if (b.ping() != "Foo::ping()") { + throw new Exception("b.ping()"); + } + if (b.pong() != "Foo::pong();Foo::ping()") { + throw new Exception("b.pong()"); + } + + { + scope a1 = new A1(1, false); + } + + { + auto my = new MyOverriddenClass(); + + my.expectNull = true; + if (MyClass.call_pmethod(my, null) !is null) + throw new Exception("null pointer conversion problem"); + + auto myBar = new Bar(); + my.expectNull = false; + auto myNewBar = MyClass.call_pmethod(my, myBar); + if (myNewBar is null) + throw new Exception("non-null pointer conversion problem"); + myNewBar.x = 10; + } +} + +class director_basic_MyFoo : Foo { + public override char[] ping() { + return "director_basic_MyFoo::ping()"; + } +} + +class MyOverriddenClass : MyClass { + public bool expectNull = false; + public bool nonNullReceived = false; + public override Bar pmethod(Bar b) { + if (expectNull && (b !is null)) + throw new Exception("null not received as expected"); + return b; + } +} diff --git a/Examples/test-suite/d/director_basic_runme.2.d b/Examples/test-suite/d/director_basic_runme.2.d new file mode 100644 index 000000000..877fcbc47 --- /dev/null +++ b/Examples/test-suite/d/director_basic_runme.2.d @@ -0,0 +1,46 @@ +module director_basic_runme; + +import std.exception; +import director_basic.A1; +import director_basic.Bar; +import director_basic.Foo; +import director_basic.MyClass; + +void main() { + auto a = new director_basic_MyFoo(); + enforce(a.ping() == "director_basic_MyFoo::ping()", "a.ping()"); + enforce(a.pong() == "Foo::pong();director_basic_MyFoo::ping()", "a.pong()"); + + auto b = new Foo(); + enforce(b.ping() == "Foo::ping()", "b.ping()"); + enforce(b.pong() == "Foo::pong();Foo::ping()", "b.pong()"); + + { + scope a1 = new A1(1, false); + } + + auto my = new MyOverriddenClass(); + my.expectNull = true; + enforce(MyClass.call_pmethod(my, null) is null, "null pointer conversion problem"); + auto myBar = new Bar(); + my.expectNull = false; + auto myNewBar = MyClass.call_pmethod(my, myBar); + enforce(myNewBar !is null, "non-null pointer conversion problem"); + myNewBar.x = 10; +} + +class director_basic_MyFoo : Foo { + public override string ping() { + return "director_basic_MyFoo::ping()"; + } +} + +class MyOverriddenClass : MyClass { + public bool expectNull = false; + public bool nonNullReceived = false; + public override Bar pmethod(Bar b) { + if (expectNull && (b !is null)) + throw new Exception("null not received as expected"); + return b; + } +} diff --git a/Examples/test-suite/d/director_classes_runme.1.d b/Examples/test-suite/d/director_classes_runme.1.d new file mode 100644 index 000000000..9c34db82a --- /dev/null +++ b/Examples/test-suite/d/director_classes_runme.1.d @@ -0,0 +1,168 @@ +/** + * This test demonstrates director classes when the types are classes. Shown are + * virtual function calls which use classes passed by + * - Value + * - Reference + * - Pointer + * as both parameters and return values + * + * The test also demonstrates directors used with: + * - method overloading + * - default parameters + * + * Note: Methods with default parameters that call up from C++ cannot call the + * overloaded D methods, see DefaultParms method. + + * Expected output if PrintDebug enabled: + * ------------ Start ------------ + * Base - Val(444.555) + * Base - Ref(444.555) + * Base - Ptr(444.555) + * Base - FullyOverloaded(int 10) + * Base - FullyOverloaded(bool 1) + * Base - SemiOverloaded(int -678) + * Base - SemiOverloaded(bool 1) + * Base - DefaultParms(10, 2.2) + * Base - DefaultParms(10, 1.1) + * -------------------------------- + * Derived - Val(444.555) + * Derived - Ref(444.555) + * Derived - Ptr(444.555) + * Derived - FullyOverloaded(int 10) + * Derived - FullyOverloaded(bool 1) + * Derived - SemiOverloaded(int -678) + * Base - SemiOverloaded(bool 1) + * Derived - DefaultParms(10, 2.2) + * Derived - DefaultParms(10, 1.1) + * -------------------------------- + * DDerived - Val(444.555) + * DDerived - Ref(444.555) + * DDerived - Ptr(444.555) + * DDerived - FullyOverloaded(int 10) + * DDerived - FullyOverloaded(bool True) + * DDerived - SemiOverloaded(-678) + * Base - SemiOverloaded(bool 1) + * DDerived - DefaultParms(10, 2.2) + * DDerived - DefaultParms(10, 1.1) + * ------------ Finish ------------ + */ +module director_classes_runme; + +import tango.io.Stdout; +import tango.text.Util; +import director_classes.director_classes; +import director_classes.Caller; +import director_classes.Base; +import director_classes.Derived; +import director_classes.DoubleHolder; + +void main() { + if (PrintDebug) Stdout.formatln("------------ Start ------------ "); + + auto myCaller = new Caller(); + + // Test C++ base class. + { + scope myBase = new Base(100.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) Stdout.formatln("--------------------------------"); + + // Test vanilla C++ wrapped derived class. + { + scope myBase = new Derived(200.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) Stdout.formatln("--------------------------------"); + + // Test director / D derived class. + { + scope myBase = new DDerived(300.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) Stdout.formatln("------------ Finish ------------ "); +} + +void makeCalls(Caller myCaller, Base myBase) { + char[] myBaseType = myBase.classinfo.name.split(".")[$-1]; + myCaller.set(myBase); + + DoubleHolder dh = new DoubleHolder(444.555); + + // Class pointer, reference and pass by value tests + if (myCaller.ValCall(dh).val != dh.val) throw new Exception("[1] failed"); + if (myCaller.RefCall(dh).val != dh.val) throw new Exception("[2] failed"); + if (myCaller.PtrCall(dh).val != dh.val) throw new Exception("[3] failed"); + + // Fully overloaded method test (all methods in base class are overloaded) + if (myCaller.FullyOverloadedCall(10) != myBaseType ~ "::FullyOverloaded(int)") throw new Exception("[4] failed"); + if (myCaller.FullyOverloadedCall(true) != myBaseType ~ "::FullyOverloaded(bool)") throw new Exception("[5] failed"); + + // Semi overloaded method test (some methods in base class are overloaded) + if (myCaller.SemiOverloadedCall(-678) != myBaseType ~ "::SemiOverloaded(int)") throw new Exception("[6] failed"); + if (myCaller.SemiOverloadedCall(true) != "Base" ~ "::SemiOverloaded(bool)") throw new Exception("[7] failed"); + + // Default parameters methods test + if (myCaller.DefaultParmsCall(10, 2.2) != myBaseType ~ "::DefaultParms(int, double)") throw new Exception("[8] failed"); + if (myBase.classinfo == DDerived.classinfo) { // special handling for D derived classes, there is no way to do this any other way + if (myCaller.DefaultParmsCall(10) != myBaseType ~ "::DefaultParms(int, double)") throw new Exception("[9] failed"); + } else { + if (myCaller.DefaultParmsCall(10) != myBaseType ~ "::DefaultParms(int)") throw new Exception("[10] failed"); + } + + myCaller.reset(); +} + +public class DDerived : Base { + public this(double dd) { + super(dd); + } + + public override DoubleHolder Val(DoubleHolder x) { + if (PrintDebug) Stdout.formatln("DDerived - Val({0:d3})", x.val); + return x; + } + + public override DoubleHolder Ref(DoubleHolder x) { + if (PrintDebug) Stdout.formatln("DDerived - Ref({0:d3})", x.val); + return x; + } + + public override DoubleHolder Ptr(DoubleHolder x) { + if (PrintDebug) Stdout.formatln("DDerived - Ptr({0:d3})", x.val); + return x; + } + + public override char[] FullyOverloaded(int x) { + if (PrintDebug) Stdout.formatln("DDerived - FullyOverloaded(int {0})", x); + return "DDerived::FullyOverloaded(int)"; + } + + public override char[] FullyOverloaded(bool x) { + if (PrintDebug) Stdout.formatln("DDerived - FullyOverloaded(bool {0})", x); + return "DDerived::FullyOverloaded(bool)"; + } + + public override char[] SemiOverloaded(int x) { + char[] ret = "DDerived::SemiOverloaded(int)"; + if (PrintDebug) Stdout.formatln("DDerived - SemiOverloaded({0})", x); + return ret; + } + alias Base.SemiOverloaded SemiOverloaded; // Alias in SemiOverloaded(bool x). + + public override char[] DefaultParms(int x, double y) { + char[] ret = "DDerived::DefaultParms(int, double)"; + if (PrintDebug) Stdout.formatln("DDerived - DefaultParms({0}, {1:d1})", x, y); + return ret; + } + // This method will never be called from C++ code because the two-parameter + // DefaultParams() has a default value for the second parameter there. It is + // only here to ensure consistent behavior for calls from C++ and D code. + public override char[] DefaultParms(int x) { + if (PrintDebug) Stdout.formatln("DDerived - DefaultParms({0})", x); + return DefaultParms(x, 1.1/*use C++ default here*/); + } +} diff --git a/Examples/test-suite/d/director_classes_runme.2.d b/Examples/test-suite/d/director_classes_runme.2.d new file mode 100644 index 000000000..98e27b3cd --- /dev/null +++ b/Examples/test-suite/d/director_classes_runme.2.d @@ -0,0 +1,169 @@ +/** + * This test demonstrates director classes when the types are classes. Shown are + * virtual function calls which use classes passed by + * - Value + * - Reference + * - Pointer + * as both parameters and return values + * + * The test also demonstrates directors used with: + * - method overloading + * - default parameters + * + * Note: Methods with default parameters that call up from C++ cannot call the + * overloaded D methods, see DefaultParms method. + + * Expected output if PrintDebug enabled: + * ------------ Start ------------ + * Base - Val(444.555) + * Base - Ref(444.555) + * Base - Ptr(444.555) + * Base - FullyOverloaded(int 10) + * Base - FullyOverloaded(bool 1) + * Base - SemiOverloaded(int -678) + * Base - SemiOverloaded(bool 1) + * Base - DefaultParms(10, 2.2) + * Base - DefaultParms(10, 1.1) + * -------------------------------- + * Derived - Val(444.555) + * Derived - Ref(444.555) + * Derived - Ptr(444.555) + * Derived - FullyOverloaded(int 10) + * Derived - FullyOverloaded(bool 1) + * Derived - SemiOverloaded(int -678) + * Base - SemiOverloaded(bool 1) + * Derived - DefaultParms(10, 2.2) + * Derived - DefaultParms(10, 1.1) + * -------------------------------- + * DDerived - Val(444.555) + * DDerived - Ref(444.555) + * DDerived - Ptr(444.555) + * DDerived - FullyOverloaded(int 10) + * DDerived - FullyOverloaded(bool true) + * DDerived - SemiOverloaded(-678) + * Base - SemiOverloaded(bool 1) + * DDerived - DefaultParms(10, 2.2) + * DDerived - DefaultParms(10, 1.1) + * ------------ Finish ------------ + */ +module director_classes_runme; + +import std.exception; +import std.stdio; +import std.string; +import director_classes.director_classes; +import director_classes.Caller; +import director_classes.Base; +import director_classes.Derived; +import director_classes.DoubleHolder; + +void main() { + if (PrintDebug) writeln("------------ Start ------------ "); + + auto myCaller = new Caller(); + + // Test C++ base class. + { + scope myBase = new Base(100.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) writeln("--------------------------------"); + + // Test vanilla C++ wrapped derived class. + { + scope myBase = new Derived(200.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) writeln("--------------------------------"); + + // Test director / D derived class. + { + scope myBase = new DDerived(300.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) writeln("------------ Finish ------------ "); +} + +void makeCalls(Caller myCaller, Base myBase) { + string myBaseType = myBase.classinfo.name.split(".")[$-1]; + myCaller.set(myBase); + + DoubleHolder dh = new DoubleHolder(444.555); + + // Class pointer, reference and pass by value tests + enforce(myCaller.ValCall(dh).val == dh.val, "[1] failed"); + enforce(myCaller.RefCall(dh).val == dh.val, "[2] failed"); + enforce(myCaller.PtrCall(dh).val == dh.val, "[3] failed"); + + // Fully overloaded method test (all methods in base class are overloaded) + enforce(myCaller.FullyOverloadedCall(10) == myBaseType ~ "::FullyOverloaded(int)", "[4] failed"); + enforce(myCaller.FullyOverloadedCall(true) == myBaseType ~ "::FullyOverloaded(bool)", "[5] failed"); + + // Semi overloaded method test (some methods in base class are overloaded) + enforce(myCaller.SemiOverloadedCall(-678) == myBaseType ~ "::SemiOverloaded(int)", "[6] failed"); + enforce(myCaller.SemiOverloadedCall(true) == "Base" ~ "::SemiOverloaded(bool)", "[7] failed"); + + // Default parameters methods test + enforce(myCaller.DefaultParmsCall(10, 2.2) == myBaseType ~ "::DefaultParms(int, double)", "[8] failed"); + if (myBase.classinfo == DDerived.classinfo) { // special handling for D derived classes, there is no other way to do this + enforce(myCaller.DefaultParmsCall(10) == myBaseType ~ "::DefaultParms(int, double)", "[9] failed"); + } else { + enforce(myCaller.DefaultParmsCall(10) == myBaseType ~ "::DefaultParms(int)", "[10] failed"); + } + + myCaller.reset(); +} + +public class DDerived : Base { + public this(double dd) { + super(dd); + } + + public override DoubleHolder Val(DoubleHolder x) { + if (PrintDebug) writefln("DDerived - Val(%s)", x.val); + return x; + } + + public override DoubleHolder Ref(DoubleHolder x) { + if (PrintDebug) writefln("DDerived - Ref(%s)", x.val); + return x; + } + + public override DoubleHolder Ptr(DoubleHolder x) { + if (PrintDebug) writefln("DDerived - Ptr(%s)", x.val); + return x; + } + + public override string FullyOverloaded(int x) { + if (PrintDebug) writefln("DDerived - FullyOverloaded(int %s)", x); + return "DDerived::FullyOverloaded(int)"; + } + + public override string FullyOverloaded(bool x) { + if (PrintDebug) writefln("DDerived - FullyOverloaded(bool %s)", x); + return "DDerived::FullyOverloaded(bool)"; + } + + public override string SemiOverloaded(int x) { + string ret = "DDerived::SemiOverloaded(int)"; + if (PrintDebug) writefln("DDerived - SemiOverloaded(%s)", x); + return ret; + } + alias Base.SemiOverloaded SemiOverloaded; // Alias in SemiOverloaded(bool x). + + public override string DefaultParms(int x, double y) { + string ret = "DDerived::DefaultParms(int, double)"; + if (PrintDebug) writefln("DDerived - DefaultParms(%s, %s)", x, y); + return ret; + } + // This method will never be called from C++ code because the two-parameter + // DefaultParams() has a default value for the second parameter there. It is + // only here to ensure consistent behavior for calls from C++ and D code. + public override string DefaultParms(int x) { + if (PrintDebug) writefln("DDerived - DefaultParms(%s)", x); + return DefaultParms(x, 1.1/*use C++ default here*/); + } +} diff --git a/Examples/test-suite/d/director_classic_runme.1.d b/Examples/test-suite/d/director_classic_runme.1.d new file mode 100644 index 000000000..33be80618 --- /dev/null +++ b/Examples/test-suite/d/director_classic_runme.1.d @@ -0,0 +1,207 @@ +module director_classic_runme; + +import tango.io.Stdout; +import director_classic.Caller; +import director_classic.Person; +import director_classic.Child; +import director_classic.GrandChild; +import director_classic.OrphanPerson; +import director_classic.OrphanChild; + +const bool TRACE = false; + +void main() { + { + scope person = new Person(); + check(person, "Person"); + } + { + scope person = new Child(); + check(person, "Child"); + } + { + scope person = new GrandChild(); + check(person, "GrandChild"); + } + { + scope person = new TargetLangPerson(); + check(person, "TargetLangPerson"); + } + { + scope person = new TargetLangChild(); + check(person, "TargetLangChild"); + } + { + scope person = new TargetLangGrandChild(); + check(person, "TargetLangGrandChild"); + } + + // Semis - don't override id() in target language + { + scope person = new TargetLangSemiPerson(); + check(person, "Person"); + } + { + scope person = new TargetLangSemiChild(); + check(person, "Child"); + } + { + scope person = new TargetLangSemiGrandChild(); + check(person, "GrandChild"); + } + + // Orphans - don't override id() in C++ + { + scope person = new OrphanPerson(); + check(person, "Person"); + } + { + scope person = new OrphanChild(); + check(person, "Child"); + } + { + scope person = new TargetLangOrphanPerson(); + check(person, "TargetLangOrphanPerson"); + } + { + scope person = new TargetLangOrphanChild(); + check(person, "TargetLangOrphanChild"); + } + + // Duals - id() makes an upcall to the base id() + { + scope person = new TargetLangDualPerson(); + check(person, "TargetLangDualPerson + Person"); + } + { + scope person = new TargetLangDualChild(); + check(person, "TargetLangDualChild + Child"); + } + { + scope person = new TargetLangDualGrandChild(); + check(person, "TargetLangDualGrandChild + GrandChild"); + } + + // Mix Orphans and Duals + { + scope person = new TargetLangDualOrphanPerson(); + check(person, "TargetLangDualOrphanPerson + Person"); + } + { + scope person = new TargetLangDualOrphanChild(); + check(person, "TargetLangDualOrphanChild + Child"); + } +} + +void check(Person person, char[] expected) { + char[] ret; + // Normal D polymorphic call. + ret = person.id(); + if (TRACE) + Stdout(ret).newline; + if (ret != expected) + throw new Exception("Failed. Received: " ~ ret ~ " Expected: " ~ expected); + + // Polymorphic call from C++. + Caller caller = new Caller(); + caller.setCallback(person); + ret = caller.call(); + if (TRACE) + Stdout(ret).newline; + if (ret != expected) + throw new Exception("Failed. Received: " ~ ret ~ " Expected: " ~ expected); + + // Polymorphic call of object created in D and passed to C++ and back again. + Person baseclass = caller.baseClass(); + ret = baseclass.id(); + if (TRACE) + Stdout(ret).newline; + if (ret != expected) + throw new Exception("Failed. Received: " ~ ret ~ " Expected: " ~ expected); + + caller.resetCallback(); + if (TRACE) + Stdout("----------------------------------------").newline; +} + + +// »Full« target language persons. +class TargetLangPerson : Person { + public override char[] id() { + return "TargetLangPerson"; + } +} + +class TargetLangChild : Child { + public override char[] id() { + return "TargetLangChild"; + } +} + +class TargetLangGrandChild : GrandChild { + public override char[] id() { + return "TargetLangGrandChild"; + } +} + + +// Semis - don't override id() in target language +class TargetLangSemiPerson : Person { + // No id() override +} + +class TargetLangSemiChild : Child { + // No id() override +} + +class TargetLangSemiGrandChild : GrandChild { + // No id() override +} + + +// Orphans - don't override id() in C++ +class TargetLangOrphanPerson : OrphanPerson { + public override char[] id() { + return "TargetLangOrphanPerson"; + } +} + +class TargetLangOrphanChild : OrphanChild { + public override char[] id() { + return "TargetLangOrphanChild"; + } +} + + +// Duals - id() makes an upcall to the base id() +class TargetLangDualPerson : Person { + public override char[] id() { + return "TargetLangDualPerson + " ~ super.id(); + } +} + +class TargetLangDualChild : Child { + public override char[] id() { + return "TargetLangDualChild + " ~ super.id(); + } +} + +class TargetLangDualGrandChild : GrandChild { + public override char[] id() { + return "TargetLangDualGrandChild + " ~ super.id(); + } +} + + +// Mix Orphans and Duals +class TargetLangDualOrphanPerson : OrphanPerson { + public override char[] id() { + return "TargetLangDualOrphanPerson + " ~ super.id(); + } +} + +class TargetLangDualOrphanChild : OrphanChild { + public override char[] id() { + return "TargetLangDualOrphanChild + " ~ super.id(); + } +} diff --git a/Examples/test-suite/d/director_classic_runme.2.d b/Examples/test-suite/d/director_classic_runme.2.d new file mode 100644 index 000000000..c50781b07 --- /dev/null +++ b/Examples/test-suite/d/director_classic_runme.2.d @@ -0,0 +1,202 @@ +module director_classic_runme; + +import std.exception; +import std.stdio; +import director_classic.Caller; +import director_classic.Person; +import director_classic.Child; +import director_classic.GrandChild; +import director_classic.OrphanPerson; +import director_classic.OrphanChild; + +enum TRACE = false; + +void main() { + { + scope person = new Person(); + check(person, "Person"); + } + { + scope person = new Child(); + check(person, "Child"); + } + { + scope person = new GrandChild(); + check(person, "GrandChild"); + } + { + scope person = new TargetLangPerson(); + check(person, "TargetLangPerson"); + } + { + scope person = new TargetLangChild(); + check(person, "TargetLangChild"); + } + { + scope person = new TargetLangGrandChild(); + check(person, "TargetLangGrandChild"); + } + + // Semis - don't override id() in target language + { + scope person = new TargetLangSemiPerson(); + check(person, "Person"); + } + { + scope person = new TargetLangSemiChild(); + check(person, "Child"); + } + { + scope person = new TargetLangSemiGrandChild(); + check(person, "GrandChild"); + } + + // Orphans - don't override id() in C++ + { + scope person = new OrphanPerson(); + check(person, "Person"); + } + { + scope person = new OrphanChild(); + check(person, "Child"); + } + { + scope person = new TargetLangOrphanPerson(); + check(person, "TargetLangOrphanPerson"); + } + { + scope person = new TargetLangOrphanChild(); + check(person, "TargetLangOrphanChild"); + } + + // Duals - id() makes an upcall to the base id() + { + scope person = new TargetLangDualPerson(); + check(person, "TargetLangDualPerson + Person"); + } + { + scope person = new TargetLangDualChild(); + check(person, "TargetLangDualChild + Child"); + } + { + scope person = new TargetLangDualGrandChild(); + check(person, "TargetLangDualGrandChild + GrandChild"); + } + + // Mix Orphans and Duals + { + scope person = new TargetLangDualOrphanPerson(); + check(person, "TargetLangDualOrphanPerson + Person"); + } + { + scope person = new TargetLangDualOrphanChild(); + check(person, "TargetLangDualOrphanChild + Child"); + } +} + +void check(Person person, string expected) { + string ret; + // Normal D polymorphic call. + ret = person.id(); + if (TRACE) writeln(ret); + enforce(ret == expected, "Failed. Received: " ~ ret ~ " Expected: " ~ expected); + + // Polymorphic call from C++. + auto caller = new Caller(); + caller.setCallback(person); + ret = caller.call(); + if (TRACE) writeln(ret); + enforce(ret == expected, "Failed. Received: " ~ ret ~ " Expected: " ~ expected); + + // Polymorphic call of object created in D and passed to C++ and back again. + Person baseclass = caller.baseClass(); + ret = baseclass.id(); + if (TRACE) writeln(ret); + enforce(ret == expected, "Failed. Received: " ~ ret ~ " Expected: " ~ expected); + + caller.resetCallback(); + if (TRACE) + writeln("----------------------------------------"); +} + + +// »Full« target language persons. +class TargetLangPerson : Person { + public override string id() { + return "TargetLangPerson"; + } +} + +class TargetLangChild : Child { + public override string id() { + return "TargetLangChild"; + } +} + +class TargetLangGrandChild : GrandChild { + public override string id() { + return "TargetLangGrandChild"; + } +} + + +// Semis - don't override id() in target language +class TargetLangSemiPerson : Person { + // No id() override +} + +class TargetLangSemiChild : Child { + // No id() override +} + +class TargetLangSemiGrandChild : GrandChild { + // No id() override +} + + +// Orphans - don't override id() in C++ +class TargetLangOrphanPerson : OrphanPerson { + public override string id() { + return "TargetLangOrphanPerson"; + } +} + +class TargetLangOrphanChild : OrphanChild { + public override string id() { + return "TargetLangOrphanChild"; + } +} + + +// Duals - id() makes an upcall to the base id() +class TargetLangDualPerson : Person { + public override string id() { + return "TargetLangDualPerson + " ~ super.id(); + } +} + +class TargetLangDualChild : Child { + public override string id() { + return "TargetLangDualChild + " ~ super.id(); + } +} + +class TargetLangDualGrandChild : GrandChild { + public override string id() { + return "TargetLangDualGrandChild + " ~ super.id(); + } +} + + +// Mix Orphans and Duals +class TargetLangDualOrphanPerson : OrphanPerson { + public override string id() { + return "TargetLangDualOrphanPerson + " ~ super.id(); + } +} + +class TargetLangDualOrphanChild : OrphanChild { + public override string id() { + return "TargetLangDualOrphanChild + " ~ super.id(); + } +} diff --git a/Examples/test-suite/d/director_ignore_runme.1.d b/Examples/test-suite/d/director_ignore_runme.1.d new file mode 100644 index 000000000..797d2fddf --- /dev/null +++ b/Examples/test-suite/d/director_ignore_runme.1.d @@ -0,0 +1,39 @@ +module director_ignore_runme; + +import director_ignore.DIgnores; +import director_ignore.DAbstractIgnores; + +void main() { + // Just check the classes can be instantiated and other methods work as expected + auto a = new DIgnoresDerived(); + if (a.Triple(5) != 15) + throw new Exception("Triple failed"); + + auto b = new DAbstractIgnoresDerived(); + if (b.Quadruple(5) != 20) + throw new Exception("Quadruple failed"); +} + +class DIgnoresDerived : DIgnores { +public: + // These will give a warning if the %ignore is not working + int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; } + int OverloadedMethod(int n, int xoffset) { return 0; } + int OverloadedMethod(int n) { return 0; } + + int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; } + int OverloadedProtectedMethod(int n, int xoffset) { return 0; } + int OverloadedProtectedMethod(int n) { return 0; } +} + +class DAbstractIgnoresDerived : DAbstractIgnores { +public: + // These will give a warning if the %ignore is not working + int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; } + int OverloadedMethod(int n, int xoffset) { return 0; } + int OverloadedMethod(int n) { return 0; } + + int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; } + int OverloadedProtectedMethod(int n, int xoffset) { return 0; } + int OverloadedProtectedMethod(int n) { return 0; } +} diff --git a/Examples/test-suite/d/director_ignore_runme.2.d b/Examples/test-suite/d/director_ignore_runme.2.d new file mode 100644 index 000000000..b3e29b48d --- /dev/null +++ b/Examples/test-suite/d/director_ignore_runme.2.d @@ -0,0 +1,38 @@ +module director_ignore_runme; + +import std.exception; +import director_ignore.DIgnores; +import director_ignore.DAbstractIgnores; + +void main() { + // Just check the classes can be instantiated and other methods work as expected + auto a = new DIgnoresDerived(); + enforce(a.Triple(5) == 15, "Triple failed"); + + auto b = new DAbstractIgnoresDerived(); + enforce(b.Quadruple(5) == 20, "Quadruple failed"); +} + +class DIgnoresDerived : DIgnores { +public: + // These will give a warning if the %ignore is not working + int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; } + int OverloadedMethod(int n, int xoffset) { return 0; } + int OverloadedMethod(int n) { return 0; } + + int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; } + int OverloadedProtectedMethod(int n, int xoffset) { return 0; } + int OverloadedProtectedMethod(int n) { return 0; } +} + +class DAbstractIgnoresDerived : DAbstractIgnores { +public: + // These will give a warning if the %ignore is not working + int OverloadedMethod(int n, int xoffset, int yoffset) { return 0; } + int OverloadedMethod(int n, int xoffset) { return 0; } + int OverloadedMethod(int n) { return 0; } + + int OverloadedProtectedMethod(int n, int xoffset, int yoffset) { return 0; } + int OverloadedProtectedMethod(int n, int xoffset) { return 0; } + int OverloadedProtectedMethod(int n) { return 0; } +} diff --git a/Examples/test-suite/d/director_primitives_runme.1.d b/Examples/test-suite/d/director_primitives_runme.1.d new file mode 100644 index 000000000..f19e86f59 --- /dev/null +++ b/Examples/test-suite/d/director_primitives_runme.1.d @@ -0,0 +1,122 @@ +/** + * This test program shows a D class DDerived inheriting from Base. + * + * Three types of classes are created and the virtual methods called to + * demonstrate: + * - Wide variety of primitive types + * - Calling methods with zero, one or more parameters + * - Director methods that are not overridden in D + * - Director classes that are not overridden at all in D, i.e. non-director + * behaviour is as expected for director classes + * - Inheritance hierarchy using director methods + * - Return types working as well as parameters + * + * The Caller class is a tester class which calls the virtual functions from C++. + */ +module director_primitives_runme; + +import tango.io.Stdout; +import director_primitives.director_primitives; +import director_primitives.Base; +import director_primitives.Caller; +import director_primitives.Derived; +import director_primitives.HShadowMode; + +void main() { + PrintDebug = false; + if (PrintDebug) Stdout("------------ Start ------------ ").newline; + + Caller myCaller = new Caller(); + + // Test C++ base class. + { + scope myBase = new Base(100.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) Stdout("--------------------------------").newline; + + // Test vanilla C++ wrapped derived class. + { + scope Base myBase = new Derived(100.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) Stdout("--------------------------------").newline; + + // Test director/D derived class. + { + scope Base myBase = new DDerived(300.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) Stdout("------------ Finish ------------ ").newline; +} + +void makeCalls(Caller myCaller, Base myBase) { + myCaller.set(myBase); + + myCaller.NoParmsMethodCall(); + if (myCaller.BoolMethodCall(true) != true) throw new Exception("failed"); + if (myCaller.BoolMethodCall(false) != false) throw new Exception("failed"); + if (myCaller.IntMethodCall(-123) != -123) throw new Exception("failed"); + if (myCaller.UIntMethodCall(123) != 123) throw new Exception("failed"); + if (myCaller.FloatMethodCall(-123.456f) != -123.456f) throw new Exception("failed"); + if (myCaller.CharPtrMethodCall("test string") != "test string") throw new Exception("failed"); + if (myCaller.ConstCharPtrMethodCall("another string") != "another string") throw new Exception("failed"); + if (myCaller.EnumMethodCall(HShadowMode.HShadowHard) != HShadowMode.HShadowHard) throw new Exception("failed"); + myCaller.ManyParmsMethodCall(true, -123, 123, 123.456f, "test string", "another string", HShadowMode.HShadowHard); + myCaller.NotOverriddenMethodCall(); + + myCaller.reset(); +} + +class DDerived : Base { +public: + this(double dd) { + super(dd); + } + + override void NoParmsMethod() { + if (PrintDebug) Stdout("DDerived - NoParmsMethod()").newline; + } + + override bool BoolMethod(bool x) { + if (PrintDebug) Stdout.formatln("DDerived - BoolMethod({0})", x); + return x; + } + + override int IntMethod(int x) { + if (PrintDebug) Stdout.formatln("DDerived - IntMethod({0})", x); + return x; + } + + override uint UIntMethod(uint x) { + if (PrintDebug) Stdout.formatln("DDerived - UIntMethod({0})", x); + return x; + } + + override float FloatMethod(float x) { + if (PrintDebug) Stdout.formatln("DDerived - FloatMethod({0})", x); + return x; + } + + override char[] CharPtrMethod(char[] x) { + if (PrintDebug) Stdout.formatln("DDerived - CharPtrMethod({0})", x); + return x; + } + + override char[] ConstCharPtrMethod(char[] x) { + if (PrintDebug) Stdout.formatln("DDerived - ConstCharPtrMethod({0})", x); + return x; + } + + override HShadowMode EnumMethod(HShadowMode x) { + if (PrintDebug) Stdout.formatln("DDerived - EnumMethod({0})", x); + return x; + } + + override void ManyParmsMethod(bool b, int i, uint u, float f, char[] c, char[] cc, HShadowMode h) { + if (PrintDebug) Stdout.formatln("DDerived - ManyParmsMethod({0}, {1}, {2}, {3:d3}, {4}, {5}, {6})", b, i, u, f, c, cc, h); + } +} diff --git a/Examples/test-suite/d/director_primitives_runme.2.d b/Examples/test-suite/d/director_primitives_runme.2.d new file mode 100644 index 000000000..e0e307330 --- /dev/null +++ b/Examples/test-suite/d/director_primitives_runme.2.d @@ -0,0 +1,123 @@ +/** + * This test program shows a D class DDerived inheriting from Base. + * + * Three types of classes are created and the virtual methods called to + * demonstrate: + * - Wide variety of primitive types + * - Calling methods with zero, one or more parameters + * - Director methods that are not overridden in D + * - Director classes that are not overridden at all in D, i.e. non-director + * behaviour is as expected for director classes + * - Inheritance hierarchy using director methods + * - Return types working as well as parameters + * + * The Caller class is a tester class which calls the virtual functions from C++. + */ +module director_primitives_runme; + +import std.exception; +import std.stdio; +import director_primitives.director_primitives; +import director_primitives.Base; +import director_primitives.Caller; +import director_primitives.Derived; +import director_primitives.HShadowMode; + +void main() { + PrintDebug = false; + if (PrintDebug) writeln("------------ Start ------------ "); + + auto myCaller = new Caller(); + + // Test C++ base class. + { + scope myBase = new Base(100.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) writeln("--------------------------------"); + + // Test vanilla C++ wrapped derived class. + { + scope Base myBase = new Derived(100.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) writeln("--------------------------------"); + + // Test director/D derived class. + { + scope Base myBase = new DDerived(300.0); + makeCalls(myCaller, myBase); + } + + if (PrintDebug) writeln("------------ Finish ------------ "); +} + +void makeCalls(Caller myCaller, Base myBase) { + myCaller.set(myBase); + + myCaller.NoParmsMethodCall(); + enforce(myCaller.BoolMethodCall(true) == true, "failed"); + enforce(myCaller.BoolMethodCall(false) == false, "failed"); + enforce(myCaller.IntMethodCall(-123) == -123, "failed"); + enforce(myCaller.UIntMethodCall(123) == 123, "failed"); + enforce(myCaller.FloatMethodCall(-123.456f) == -123.456f, "failed"); + enforce(myCaller.CharPtrMethodCall("test string") == "test string", "failed"); + enforce(myCaller.ConstCharPtrMethodCall("another string") == "another string", "failed"); + enforce(myCaller.EnumMethodCall(HShadowMode.HShadowHard) == HShadowMode.HShadowHard, "failed"); + myCaller.ManyParmsMethodCall(true, -123, 123, 123.456f, "test string", "another string", HShadowMode.HShadowHard); + myCaller.NotOverriddenMethodCall(); + + myCaller.reset(); +} + +class DDerived : Base { +public: + this(double dd) { + super(dd); + } + + override void NoParmsMethod() { + if (PrintDebug) writeln("DDerived - NoParmsMethod()"); + } + + override bool BoolMethod(bool x) { + if (PrintDebug) writefln("DDerived - BoolMethod(%s)", x); + return x; + } + + override int IntMethod(int x) { + if (PrintDebug) writefln("DDerived - IntMethod(%s)", x); + return x; + } + + override uint UIntMethod(uint x) { + if (PrintDebug) writefln("DDerived - UIntMethod(%s)", x); + return x; + } + + override float FloatMethod(float x) { + if (PrintDebug) writefln("DDerived - FloatMethod(%s)", x); + return x; + } + + override string CharPtrMethod(string x) { + if (PrintDebug) writefln("DDerived - CharPtrMethod(%s)", x); + return x; + } + + override string ConstCharPtrMethod(string x) { + if (PrintDebug) writefln("DDerived - ConstCharPtrMethod(%s)", x); + return x; + } + + override HShadowMode EnumMethod(HShadowMode x) { + if (PrintDebug) writefln("DDerived - EnumMethod(%s)", x); + return x; + } + + override void ManyParmsMethod(bool b, int i, uint u, float f, string c, string cc, HShadowMode h) { + if (PrintDebug) writefln("DDerived - ManyParmsMethod(%s, %s, %s, %s, %s, %s, %s)", b, i, u, f, c, cc, h); + } +} diff --git a/Examples/test-suite/d/director_protected_runme.1.d b/Examples/test-suite/d/director_protected_runme.1.d new file mode 100644 index 000000000..81447b73b --- /dev/null +++ b/Examples/test-suite/d/director_protected_runme.1.d @@ -0,0 +1,50 @@ +module director_protected_runme; + +import director_protected.Foo; +import director_protected.Bar; + +void main() { + Bar b = new Bar(); + Foo f = b.create(); + auto fb = new FooBar(); + auto fb2 = new FooBar2(); + + char[] s; + s = fb.used(); + if ( s != ("Foo::pang();Bar::pong();Foo::pong();FooBar::ping();")) + throw new Exception("bad FooBar::used" ~ " - " ~ s); + + s = fb2.used(); + if ( s != ("FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();")) + throw new Exception("bad FooBar2::used"); + + s = b.pong(); + if ( s != ("Bar::pong();Foo::pong();Bar::ping();")) + throw new Exception("bad Bar::pong"); + + s = f.pong(); + if ( s != ("Bar::pong();Foo::pong();Bar::ping();")) + throw new Exception("bad Foo::pong"); + + s = fb.pong(); + if ( s != ("Bar::pong();Foo::pong();FooBar::ping();")) + throw new Exception("bad FooBar::pong"); +} + +class FooBar : Bar { +protected: + override char[] ping() { + return "FooBar::ping();"; + } +} + +class FooBar2 : Bar{ +protected: + override char[] ping() { + return "FooBar2::ping();"; + } + + override char[] pang() { + return "FooBar2::pang();"; + } +} diff --git a/Examples/test-suite/d/director_protected_runme.2.d b/Examples/test-suite/d/director_protected_runme.2.d new file mode 100644 index 000000000..9beeecd23 --- /dev/null +++ b/Examples/test-suite/d/director_protected_runme.2.d @@ -0,0 +1,36 @@ +module director_protected_runme; + +import std.exception; +import director_protected.Foo; +import director_protected.Bar; + +void main() { + Bar b = new Bar(); + Foo f = b.create(); + auto fb = new FooBar(); + scope fb2 = new FooBar2(); + + enforce(fb.used() == "Foo::pang();Bar::pong();Foo::pong();FooBar::ping();", "bad FooBar::used" ~ " - " ~ fb.used()); + enforce(fb2.used() == "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();", "bad FooBar2::used"); + enforce(b.pong() == "Bar::pong();Foo::pong();Bar::ping();", "bad Bar::pong"); + enforce(f.pong() == "Bar::pong();Foo::pong();Bar::ping();", "bad Foo::pong"); + enforce(fb.pong() == "Bar::pong();Foo::pong();FooBar::ping();", "bad FooBar::pong"); +} + +class FooBar : Bar { +protected: + override string ping() { + return "FooBar::ping();"; + } +} + +class FooBar2 : Bar { +protected: + override string ping() { + return "FooBar2::ping();"; + } + + override string pang() { + return "FooBar2::pang();"; + } +} diff --git a/Examples/test-suite/d/director_string_runme.1.d b/Examples/test-suite/d/director_string_runme.1.d new file mode 100644 index 000000000..4e750791a --- /dev/null +++ b/Examples/test-suite/d/director_string_runme.1.d @@ -0,0 +1,46 @@ +module director_string_runme; + +import Integer = tango.text.convert.Integer; +import director_string.A; + +void main() { + char[] s; + + auto c = new director_string_A("hi"); + for (int i=0; i<3; ++i) { + s = c.call_get(i); + if (s != Integer.toString(i)) throw new Exception("director_string_A.get(" ~ Integer.toString(i) ~ ") failed. Got:" ~ s); + } + + auto b = new director_string_B("hello"); + + s = b.call_get_first(); + if (s != "director_string_B.get_first") throw new Exception("call_get_first() failed"); + + s = b.call_get(0); + if (s != "director_string_B.get: hello") throw new Exception("get(0) failed"); +} + +class director_string_B : A { +public: + this(char[] first) { + super(first); + } + override char[] get_first() { + return "director_string_B.get_first"; + } + + override char[] get(int n) { + return "director_string_B.get: " ~ super.get(n); + } +} + +class director_string_A : A { +public: + this(char[] first) { + super(first); + } + override char[] get(int n) { + return Integer.toString(n); + } +} diff --git a/Examples/test-suite/d/director_string_runme.2.d b/Examples/test-suite/d/director_string_runme.2.d new file mode 100644 index 000000000..950a34072 --- /dev/null +++ b/Examples/test-suite/d/director_string_runme.2.d @@ -0,0 +1,42 @@ +module director_string_runme; + +import std.conv; +import std.exception; +import director_string.A; + +void main() { + auto c = new director_string_A("hi"); + for (int i=0; i<3; ++i) { + auto s = c.call_get(i); + auto expected = to!string(i); + enforce(s == expected, "director_string_A.get(" ~ expected ~ ") failed. Got:" ~ s); + } + + auto b = new director_string_B("hello"); + enforce(b.call_get_first() == "director_string_B.get_first", "call_get_first() failed"); + enforce(b.call_get(0) == "director_string_B.get: hello", "get(0) failed"); +} + +class director_string_B : A { +public: + this(string first) { + super(first); + } + override string get_first() const { + return "director_string_B.get_first"; + } + + override string get(int n) const { + return "director_string_B.get: " ~ super.get(n); + } +} + +class director_string_A : A { +public: + this(string first) { + super(first); + } + override string get(int n) const { + return to!string(n); + } +} diff --git a/Examples/test-suite/d/enum_thorough_runme.1.d b/Examples/test-suite/d/enum_thorough_runme.1.d new file mode 100644 index 000000000..b76bfdd93 --- /dev/null +++ b/Examples/test-suite/d/enum_thorough_runme.1.d @@ -0,0 +1,424 @@ +module enum_thorough_runme; + +import enum_thorough.enum_thorough; +import enum_thorough.AnonStruct; +import enum_thorough.colour; +import enum_thorough.FirStruct; +import enum_thorough.HairStruct; +import enum_thorough.IgnoreTest; +import enum_thorough.Instances; +import enum_thorough.namedanon; +import enum_thorough.namedanonspace; +import enum_thorough.newname; +import enum_thorough.NewNameStruct; +import enum_thorough.repeat; +import enum_thorough.SpeedClass; +import enum_thorough.TClassInt; +import enum_thorough.TemplateClassInt; +import enum_thorough.TreesClass; +import enum_thorough.twonames; +import enum_thorough.TwoNamesStruct; + +void main() { + { + // Anonymous enums + int i = AnonEnum1; + if (ReallyAnInteger != 200) throw new Exception("Test Anon 1 failed"); + i += AnonSpaceEnum1; + i += AnonStruct.AnonStructEnum1; + } + { + auto red = colour.red; + colourTest1(red); + colourTest2(red); + colourTest3(red); + colourTest4(red); + myColour = red; + } + { + auto s = new SpeedClass(); + auto speed = SpeedClass.speed.slow; + if (s.speedTest1(speed) != speed) throw new Exception("speedTest 1 failed"); + if (s.speedTest2(speed) != speed) throw new Exception("speedTest 2 failed"); + if (s.speedTest3(speed) != speed) throw new Exception("speedTest 3 failed"); + if (s.speedTest4(speed) != speed) throw new Exception("speedTest 4 failed"); + if (s.speedTest5(speed) != speed) throw new Exception("speedTest 5 failed"); + if (s.speedTest6(speed) != speed) throw new Exception("speedTest 6 failed"); + if (s.speedTest7(speed) != speed) throw new Exception("speedTest 7 failed"); + if (s.speedTest8(speed) != speed) throw new Exception("speedTest 8 failed"); + + if (speedTest1(speed) != speed) throw new Exception("speedTest Global 1 failed"); + if (speedTest2(speed) != speed) throw new Exception("speedTest Global 2 failed"); + if (speedTest3(speed) != speed) throw new Exception("speedTest Global 3 failed"); + if (speedTest4(speed) != speed) throw new Exception("speedTest Global 4 failed"); + if (speedTest5(speed) != speed) throw new Exception("speedTest Global 5 failed"); + } + { + auto s = new SpeedClass(); + auto slow = SpeedClass.speed.slow; + auto lightning = SpeedClass.speed.lightning; + + if (s.mySpeedtd1 != slow) throw new Exception("mySpeedtd1 1 failed"); + if (cast(int)s.mySpeedtd1 != 10) throw new Exception("mySpeedtd1 2 failed"); + + s.mySpeedtd1 = lightning; + if (s.mySpeedtd1 != lightning) throw new Exception("mySpeedtd1 3 failed"); + if (cast(int)s.mySpeedtd1 != 31) throw new Exception("mySpeedtd1 4 failed"); + } + { + if (namedanonTest1(namedanon.NamedAnon2) != namedanon.NamedAnon2) throw new Exception("namedanonTest 1 failed"); + } + { + auto val = twonames.TwoNames2; + if (twonamesTest1(val) != val) throw new Exception("twonamesTest 1 failed"); + if (twonamesTest2(val) != val) throw new Exception("twonamesTest 2 failed"); + if (twonamesTest3(val) != val) throw new Exception("twonamesTest 3 failed"); + } + { + auto t = new TwoNamesStruct(); + auto val = TwoNamesStruct.twonames.TwoNamesStruct1; + if (t.twonamesTest1(val) != val) throw new Exception("twonamesTest 1 failed"); + if (t.twonamesTest2(val) != val) throw new Exception("twonamesTest 2 failed"); + if (t.twonamesTest3(val) != val) throw new Exception("twonamesTest 3 failed"); + } + { + auto val = namedanonspace.NamedAnonSpace2; + if (namedanonspaceTest1(val) != val) throw new Exception("namedanonspaceTest 1 failed"); + if (namedanonspaceTest2(val) != val) throw new Exception("namedanonspaceTest 2 failed"); + if (namedanonspaceTest3(val) != val) throw new Exception("namedanonspaceTest 3 failed"); + if (namedanonspaceTest4(val) != val) throw new Exception("namedanonspaceTest 4 failed"); + } + { + auto t = new TemplateClassInt(); + auto galileo = TemplateClassInt.scientists.galileo; + if (t.scientistsTest1(galileo) != galileo) throw new Exception("scientistsTest 1 failed"); + if (t.scientistsTest2(galileo) != galileo) throw new Exception("scientistsTest 2 failed"); + if (t.scientistsTest3(galileo) != galileo) throw new Exception("scientistsTest 3 failed"); + if (t.scientistsTest4(galileo) != galileo) throw new Exception("scientistsTest 4 failed"); + if (t.scientistsTest5(galileo) != galileo) throw new Exception("scientistsTest 5 failed"); + if (t.scientistsTest6(galileo) != galileo) throw new Exception("scientistsTest 6 failed"); + if (t.scientistsTest7(galileo) != galileo) throw new Exception("scientistsTest 7 failed"); + if (t.scientistsTest8(galileo) != galileo) throw new Exception("scientistsTest 8 failed"); + if (t.scientistsTest9(galileo) != galileo) throw new Exception("scientistsTest 9 failed"); +// if (t.scientistsTestA(galileo) != galileo) throw new Exception("scientistsTest A failed"); + if (t.scientistsTestB(galileo) != galileo) throw new Exception("scientistsTest B failed"); +// if (t.scientistsTestC(galileo) != galileo) throw new Exception("scientistsTest C failed"); + if (t.scientistsTestD(galileo) != galileo) throw new Exception("scientistsTest D failed"); + if (t.scientistsTestE(galileo) != galileo) throw new Exception("scientistsTest E failed"); + if (t.scientistsTestF(galileo) != galileo) throw new Exception("scientistsTest F failed"); + if (t.scientistsTestG(galileo) != galileo) throw new Exception("scientistsTest G failed"); + if (t.scientistsTestH(galileo) != galileo) throw new Exception("scientistsTest H failed"); + if (t.scientistsTestI(galileo) != galileo) throw new Exception("scientistsTest I failed"); + if (t.scientistsTestJ(galileo) != galileo) throw new Exception("scientistsTest J failed"); + + if (scientistsTest1(galileo) != galileo) throw new Exception("scientistsTest Global 1 failed"); + if (scientistsTest2(galileo) != galileo) throw new Exception("scientistsTest Global 2 failed"); + if (scientistsTest3(galileo) != galileo) throw new Exception("scientistsTest Global 3 failed"); + if (scientistsTest4(galileo) != galileo) throw new Exception("scientistsTest Global 4 failed"); + if (scientistsTest5(galileo) != galileo) throw new Exception("scientistsTest Global 5 failed"); + if (scientistsTest6(galileo) != galileo) throw new Exception("scientistsTest Global 6 failed"); + if (scientistsTest7(galileo) != galileo) throw new Exception("scientistsTest Global 7 failed"); + if (scientistsTest8(galileo) != galileo) throw new Exception("scientistsTest Global 8 failed"); + } + { + auto t = new TClassInt(); + auto bell = TClassInt.scientists.bell; + auto galileo = TemplateClassInt.scientists.galileo; + if (t.scientistsNameTest1(bell) != bell) throw new Exception("scientistsNameTest 1 failed"); + if (t.scientistsNameTest2(bell) != bell) throw new Exception("scientistsNameTest 2 failed"); + if (t.scientistsNameTest3(bell) != bell) throw new Exception("scientistsNameTest 3 failed"); + if (t.scientistsNameTest4(bell) != bell) throw new Exception("scientistsNameTest 4 failed"); + if (t.scientistsNameTest5(bell) != bell) throw new Exception("scientistsNameTest 5 failed"); + if (t.scientistsNameTest6(bell) != bell) throw new Exception("scientistsNameTest 6 failed"); + if (t.scientistsNameTest7(bell) != bell) throw new Exception("scientistsNameTest 7 failed"); + if (t.scientistsNameTest8(bell) != bell) throw new Exception("scientistsNameTest 8 failed"); + if (t.scientistsNameTest9(bell) != bell) throw new Exception("scientistsNameTest 9 failed"); +// if (t.scientistsNameTestA(bell) != bell) throw new Exception("scientistsNameTest A failed"); + if (t.scientistsNameTestB(bell) != bell) throw new Exception("scientistsNameTest B failed"); +// if (t.scientistsNameTestC(bell) != bell) throw new Exception("scientistsNameTest C failed"); + if (t.scientistsNameTestD(bell) != bell) throw new Exception("scientistsNameTest D failed"); + if (t.scientistsNameTestE(bell) != bell) throw new Exception("scientistsNameTest E failed"); + if (t.scientistsNameTestF(bell) != bell) throw new Exception("scientistsNameTest F failed"); + if (t.scientistsNameTestG(bell) != bell) throw new Exception("scientistsNameTest G failed"); + if (t.scientistsNameTestH(bell) != bell) throw new Exception("scientistsNameTest H failed"); + if (t.scientistsNameTestI(bell) != bell) throw new Exception("scientistsNameTest I failed"); + + if (t.scientistsNameSpaceTest1(bell) != bell) throw new Exception("scientistsNameSpaceTest 1 failed"); + if (t.scientistsNameSpaceTest2(bell) != bell) throw new Exception("scientistsNameSpaceTest 2 failed"); + if (t.scientistsNameSpaceTest3(bell) != bell) throw new Exception("scientistsNameSpaceTest 3 failed"); + if (t.scientistsNameSpaceTest4(bell) != bell) throw new Exception("scientistsNameSpaceTest 4 failed"); + if (t.scientistsNameSpaceTest5(bell) != bell) throw new Exception("scientistsNameSpaceTest 5 failed"); + if (t.scientistsNameSpaceTest6(bell) != bell) throw new Exception("scientistsNameSpaceTest 6 failed"); + if (t.scientistsNameSpaceTest7(bell) != bell) throw new Exception("scientistsNameSpaceTest 7 failed"); + + if (t.scientistsOtherTest1(galileo) != galileo) throw new Exception("scientistsOtherTest 1 failed"); + if (t.scientistsOtherTest2(galileo) != galileo) throw new Exception("scientistsOtherTest 2 failed"); + if (t.scientistsOtherTest3(galileo) != galileo) throw new Exception("scientistsOtherTest 3 failed"); + if (t.scientistsOtherTest4(galileo) != galileo) throw new Exception("scientistsOtherTest 4 failed"); + if (t.scientistsOtherTest5(galileo) != galileo) throw new Exception("scientistsOtherTest 5 failed"); + if (t.scientistsOtherTest6(galileo) != galileo) throw new Exception("scientistsOtherTest 6 failed"); + if (t.scientistsOtherTest7(galileo) != galileo) throw new Exception("scientistsOtherTest 7 failed"); + + if (scientistsNameTest1(bell) != bell) throw new Exception("scientistsNameTest Global 1 failed"); + if (scientistsNameTest2(bell) != bell) throw new Exception("scientistsNameTest Global 2 failed"); + if (scientistsNameTest3(bell) != bell) throw new Exception("scientistsNameTest Global 3 failed"); + if (scientistsNameTest4(bell) != bell) throw new Exception("scientistsNameTest Global 4 failed"); + if (scientistsNameTest5(bell) != bell) throw new Exception("scientistsNameTest Global 5 failed"); + if (scientistsNameTest6(bell) != bell) throw new Exception("scientistsNameTest Global 6 failed"); + if (scientistsNameTest7(bell) != bell) throw new Exception("scientistsNameTest Global 7 failed"); + + if (scientistsNameSpaceTest1(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 1 failed"); + if (scientistsNameSpaceTest2(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 2 failed"); + if (scientistsNameSpaceTest3(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 3 failed"); + if (scientistsNameSpaceTest4(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 4 failed"); + if (scientistsNameSpaceTest5(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 5 failed"); + if (scientistsNameSpaceTest6(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 6 failed"); + if (scientistsNameSpaceTest7(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 7 failed"); + + if (scientistsNameSpaceTest8(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 8 failed"); + if (scientistsNameSpaceTest9(bell) != bell) throw new Exception("scientistsNameSpaceTest Global 9 failed"); + if (scientistsNameSpaceTestA(bell) != bell) throw new Exception("scientistsNameSpaceTest Global A failed"); + if (scientistsNameSpaceTestB(bell) != bell) throw new Exception("scientistsNameSpaceTest Global B failed"); + if (scientistsNameSpaceTestC(bell) != bell) throw new Exception("scientistsNameSpaceTest Global C failed"); + if (scientistsNameSpaceTestD(bell) != bell) throw new Exception("scientistsNameSpaceTest Global D failed"); + if (scientistsNameSpaceTestE(bell) != bell) throw new Exception("scientistsNameSpaceTest Global E failed"); + + if (scientistsNameSpaceTestF(bell) != bell) throw new Exception("scientistsNameSpaceTest Global F failed"); + if (scientistsNameSpaceTestG(bell) != bell) throw new Exception("scientistsNameSpaceTest Global G failed"); + if (scientistsNameSpaceTestH(bell) != bell) throw new Exception("scientistsNameSpaceTest Global H failed"); + if (scientistsNameSpaceTestI(bell) != bell) throw new Exception("scientistsNameSpaceTest Global I failed"); + if (scientistsNameSpaceTestJ(bell) != bell) throw new Exception("scientistsNameSpaceTest Global J failed"); + if (scientistsNameSpaceTestK(bell) != bell) throw new Exception("scientistsNameSpaceTest Global K failed"); + if (scientistsNameSpaceTestL(bell) != bell) throw new Exception("scientistsNameSpaceTest Global L failed"); + } + { + auto val = newname.argh; + if (renameTest1(val) != val) throw new Exception("renameTest Global 1 failed"); + if (renameTest2(val) != val) throw new Exception("renameTest Global 2 failed"); + } + { + auto n = new NewNameStruct(); + if (n.renameTest1(NewNameStruct.enumeration.bang) != NewNameStruct.enumeration.bang) throw new Exception("renameTest 1 failed"); + if (n.renameTest2(NewNameStruct.enumeration.bang) != NewNameStruct.enumeration.bang) throw new Exception("renameTest 2 failed"); + if (n.renameTest3(NewNameStruct.simplerenamed.simple1) != NewNameStruct.simplerenamed.simple1) throw new Exception("renameTest 3 failed"); + if (n.renameTest4(NewNameStruct.doublenamerenamed.doublename1) != NewNameStruct.doublenamerenamed.doublename1) throw new Exception("renameTest 4 failed"); + if (n.renameTest5(NewNameStruct.doublenamerenamed.doublename1) != NewNameStruct.doublenamerenamed.doublename1) throw new Exception("renameTest 5 failed"); + if (n.renameTest6(NewNameStruct.singlenamerenamed.singlename1) != NewNameStruct.singlenamerenamed.singlename1) throw new Exception("renameTest 6 failed"); + } + { + if (renameTest3(NewNameStruct.enumeration.bang) != NewNameStruct.enumeration.bang) throw new Exception("renameTest Global 3 failed"); + if (renameTest4(NewNameStruct.simplerenamed.simple1) != NewNameStruct.simplerenamed.simple1) throw new Exception("renameTest Global 4 failed"); + if (renameTest5(NewNameStruct.doublenamerenamed.doublename1) != NewNameStruct.doublenamerenamed.doublename1) throw new Exception("renameTest Global 5 failed"); + if (renameTest6(NewNameStruct.doublenamerenamed.doublename1) != NewNameStruct.doublenamerenamed.doublename1) throw new Exception("renameTest Global 6 failed"); + if (renameTest7(NewNameStruct.singlenamerenamed.singlename1) != NewNameStruct.singlenamerenamed.singlename1) throw new Exception("renameTest Global 7 failed"); + } + { + auto t = new TreesClass(); + auto pine = TreesClass.trees.pine; + + if (t.treesTest1(pine) != pine) throw new Exception("treesTest 1 failed"); + if (t.treesTest2(pine) != pine) throw new Exception("treesTest 2 failed"); + if (t.treesTest3(pine) != pine) throw new Exception("treesTest 3 failed"); + if (t.treesTest4(pine) != pine) throw new Exception("treesTest 4 failed"); + if (t.treesTest5(pine) != pine) throw new Exception("treesTest 5 failed"); + if (t.treesTest6(pine) != pine) throw new Exception("treesTest 6 failed"); + if (t.treesTest7(pine) != pine) throw new Exception("treesTest 7 failed"); + if (t.treesTest8(pine) != pine) throw new Exception("treesTest 8 failed"); + if (t.treesTest9(pine) != pine) throw new Exception("treesTest 9 failed"); + if (t.treesTestA(pine) != pine) throw new Exception("treesTest A failed"); + if (t.treesTestB(pine) != pine) throw new Exception("treesTest B failed"); + if (t.treesTestC(pine) != pine) throw new Exception("treesTest C failed"); + if (t.treesTestD(pine) != pine) throw new Exception("treesTest D failed"); + if (t.treesTestE(pine) != pine) throw new Exception("treesTest E failed"); + if (t.treesTestF(pine) != pine) throw new Exception("treesTest F failed"); + if (t.treesTestG(pine) != pine) throw new Exception("treesTest G failed"); + if (t.treesTestH(pine) != pine) throw new Exception("treesTest H failed"); + if (t.treesTestI(pine) != pine) throw new Exception("treesTest I failed"); + if (t.treesTestJ(pine) != pine) throw new Exception("treesTest J failed"); + if (t.treesTestK(pine) != pine) throw new Exception("treesTest K failed"); + if (t.treesTestL(pine) != pine) throw new Exception("treesTest L failed"); + if (t.treesTestM(pine) != pine) throw new Exception("treesTest M failed"); + if (t.treesTestN(pine) != pine) throw new Exception("treesTest N failed"); + if (t.treesTestO(pine) != pine) throw new Exception("treesTest O failed"); + + if (treesTest1(pine) != pine) throw new Exception("treesTest Global 1 failed"); + if (treesTest2(pine) != pine) throw new Exception("treesTest Global 2 failed"); + if (treesTest3(pine) != pine) throw new Exception("treesTest Global 3 failed"); + if (treesTest4(pine) != pine) throw new Exception("treesTest Global 4 failed"); + if (treesTest5(pine) != pine) throw new Exception("treesTest Global 5 failed"); + if (treesTest6(pine) != pine) throw new Exception("treesTest Global 6 failed"); + if (treesTest7(pine) != pine) throw new Exception("treesTest Global 7 failed"); + if (treesTest8(pine) != pine) throw new Exception("treesTest Global 8 failed"); + if (treesTest9(pine) != pine) throw new Exception("treesTest Global 9 failed"); + if (treesTestA(pine) != pine) throw new Exception("treesTest Global A failed"); + if (treesTestB(pine) != pine) throw new Exception("treesTest Global B failed"); + if (treesTestC(pine) != pine) throw new Exception("treesTest Global C failed"); + if (treesTestD(pine) != pine) throw new Exception("treesTest Global D failed"); + if (treesTestE(pine) != pine) throw new Exception("treesTest Global E failed"); + if (treesTestF(pine) != pine) throw new Exception("treesTest Global F failed"); + if (treesTestG(pine) != pine) throw new Exception("treesTest Global G failed"); + if (treesTestH(pine) != pine) throw new Exception("treesTest Global H failed"); + if (treesTestI(pine) != pine) throw new Exception("treesTest Global I failed"); + if (treesTestJ(pine) != pine) throw new Exception("treesTest Global J failed"); + if (treesTestK(pine) != pine) throw new Exception("treesTest Global K failed"); + if (treesTestL(pine) != pine) throw new Exception("treesTest Global L failed"); + if (treesTestM(pine) != pine) throw new Exception("treesTest Global M failed"); +// if (treesTestN(pine) != pine) throw new Exception("treesTest Global N failed"); + if (treesTestO(pine) != pine) throw new Exception("treesTest Global O failed"); + if (treesTestP(pine) != pine) throw new Exception("treesTest Global P failed"); + if (treesTestQ(pine) != pine) throw new Exception("treesTest Global Q failed"); + if (treesTestR(pine) != pine) throw new Exception("treesTest Global R failed"); + } + { + auto h = new HairStruct(); + auto ginger = HairStruct.hair.ginger; + + if (h.hairTest1(ginger) != ginger) throw new Exception("hairTest 1 failed"); + if (h.hairTest2(ginger) != ginger) throw new Exception("hairTest 2 failed"); + if (h.hairTest3(ginger) != ginger) throw new Exception("hairTest 3 failed"); + if (h.hairTest4(ginger) != ginger) throw new Exception("hairTest 4 failed"); + if (h.hairTest5(ginger) != ginger) throw new Exception("hairTest 5 failed"); + if (h.hairTest6(ginger) != ginger) throw new Exception("hairTest 6 failed"); + if (h.hairTest7(ginger) != ginger) throw new Exception("hairTest 7 failed"); + if (h.hairTest8(ginger) != ginger) throw new Exception("hairTest 8 failed"); + if (h.hairTest9(ginger) != ginger) throw new Exception("hairTest 9 failed"); + if (h.hairTestA(ginger) != ginger) throw new Exception("hairTest A failed"); + if (h.hairTestB(ginger) != ginger) throw new Exception("hairTest B failed"); + + auto red = colour.red; + if (h.colourTest1(red) != red) throw new Exception("colourTest HairStruct 1 failed"); + if (h.colourTest2(red) != red) throw new Exception("colourTest HairStruct 2 failed"); + if (h.namedanonTest1(namedanon.NamedAnon2) != namedanon.NamedAnon2) throw new Exception("namedanonTest HairStruct 1 failed"); + if (h.namedanonspaceTest1(namedanonspace.NamedAnonSpace2) != namedanonspace.NamedAnonSpace2) throw new Exception("namedanonspaceTest HairStruct 1 failed"); + + auto fir = TreesClass.trees.fir; + if (h.treesGlobalTest1(fir) != fir) throw new Exception("treesGlobalTest1 HairStruct 1 failed"); + if (h.treesGlobalTest2(fir) != fir) throw new Exception("treesGlobalTest1 HairStruct 2 failed"); + if (h.treesGlobalTest3(fir) != fir) throw new Exception("treesGlobalTest1 HairStruct 3 failed"); + if (h.treesGlobalTest4(fir) != fir) throw new Exception("treesGlobalTest1 HairStruct 4 failed"); + } + { + auto blonde = HairStruct.hair.blonde; + if (hairTest1(blonde) != blonde) throw new Exception("hairTest Global 1 failed"); + if (hairTest2(blonde) != blonde) throw new Exception("hairTest Global 2 failed"); + if (hairTest3(blonde) != blonde) throw new Exception("hairTest Global 3 failed"); + if (hairTest4(blonde) != blonde) throw new Exception("hairTest Global 4 failed"); + if (hairTest5(blonde) != blonde) throw new Exception("hairTest Global 5 failed"); + if (hairTest6(blonde) != blonde) throw new Exception("hairTest Global 6 failed"); + if (hairTest7(blonde) != blonde) throw new Exception("hairTest Global 7 failed"); + if (hairTest8(blonde) != blonde) throw new Exception("hairTest Global 8 failed"); + if (hairTest9(blonde) != blonde) throw new Exception("hairTest Global 9 failed"); + if (hairTestA(blonde) != blonde) throw new Exception("hairTest Global A failed"); + if (hairTestB(blonde) != blonde) throw new Exception("hairTest Global B failed"); + if (hairTestC(blonde) != blonde) throw new Exception("hairTest Global C failed"); + + if (hairTestA1(blonde) != blonde) throw new Exception("hairTest Global A1 failed"); + if (hairTestA2(blonde) != blonde) throw new Exception("hairTest Global A2 failed"); + if (hairTestA3(blonde) != blonde) throw new Exception("hairTest Global A3 failed"); + if (hairTestA4(blonde) != blonde) throw new Exception("hairTest Global A4 failed"); + if (hairTestA5(blonde) != blonde) throw new Exception("hairTest Global A5 failed"); + if (hairTestA6(blonde) != blonde) throw new Exception("hairTest Global A6 failed"); + if (hairTestA7(blonde) != blonde) throw new Exception("hairTest Global A7 failed"); + if (hairTestA8(blonde) != blonde) throw new Exception("hairTest Global A8 failed"); + if (hairTestA9(blonde) != blonde) throw new Exception("hairTest Global A9 failed"); + if (hairTestAA(blonde) != blonde) throw new Exception("hairTest Global AA failed"); + if (hairTestAB(blonde) != blonde) throw new Exception("hairTest Global AB failed"); + if (hairTestAC(blonde) != blonde) throw new Exception("hairTest Global AC failed"); + + if (hairTestB1(blonde) != blonde) throw new Exception("hairTest Global B1 failed"); + if (hairTestB2(blonde) != blonde) throw new Exception("hairTest Global B2 failed"); + if (hairTestB3(blonde) != blonde) throw new Exception("hairTest Global B3 failed"); + if (hairTestB4(blonde) != blonde) throw new Exception("hairTest Global B4 failed"); + if (hairTestB5(blonde) != blonde) throw new Exception("hairTest Global B5 failed"); + if (hairTestB6(blonde) != blonde) throw new Exception("hairTest Global B6 failed"); + if (hairTestB7(blonde) != blonde) throw new Exception("hairTest Global B7 failed"); + if (hairTestB8(blonde) != blonde) throw new Exception("hairTest Global B8 failed"); + if (hairTestB9(blonde) != blonde) throw new Exception("hairTest Global B9 failed"); + if (hairTestBA(blonde) != blonde) throw new Exception("hairTest Global BA failed"); + if (hairTestBB(blonde) != blonde) throw new Exception("hairTest Global BB failed"); + if (hairTestBC(blonde) != blonde) throw new Exception("hairTest Global BC failed"); + + if (hairTestC1(blonde) != blonde) throw new Exception("hairTest Global C1 failed"); + if (hairTestC2(blonde) != blonde) throw new Exception("hairTest Global C2 failed"); + if (hairTestC3(blonde) != blonde) throw new Exception("hairTest Global C3 failed"); + if (hairTestC4(blonde) != blonde) throw new Exception("hairTest Global C4 failed"); + if (hairTestC5(blonde) != blonde) throw new Exception("hairTest Global C5 failed"); + if (hairTestC6(blonde) != blonde) throw new Exception("hairTest Global C6 failed"); + if (hairTestC7(blonde) != blonde) throw new Exception("hairTest Global C7 failed"); + if (hairTestC8(blonde) != blonde) throw new Exception("hairTest Global C8 failed"); + if (hairTestC9(blonde) != blonde) throw new Exception("hairTest Global C9 failed"); + if (hairTestCA(blonde) != blonde) throw new Exception("hairTest Global CA failed"); + if (hairTestCB(blonde) != blonde) throw new Exception("hairTest Global CB failed"); + if (hairTestCC(blonde) != blonde) throw new Exception("hairTest Global CC failed"); + } + { + auto f = new FirStruct(); + auto blonde = HairStruct.hair.blonde; + + if (f.hairTestFir1(blonde) != blonde) throw new Exception("hairTestFir 1 failed"); + if (f.hairTestFir2(blonde) != blonde) throw new Exception("hairTestFir 2 failed"); + if (f.hairTestFir3(blonde) != blonde) throw new Exception("hairTestFir 3 failed"); + if (f.hairTestFir4(blonde) != blonde) throw new Exception("hairTestFir 4 failed"); + if (f.hairTestFir5(blonde) != blonde) throw new Exception("hairTestFir 5 failed"); + if (f.hairTestFir6(blonde) != blonde) throw new Exception("hairTestFir 6 failed"); + if (f.hairTestFir7(blonde) != blonde) throw new Exception("hairTestFir 7 failed"); + if (f.hairTestFir8(blonde) != blonde) throw new Exception("hairTestFir 8 failed"); + if (f.hairTestFir9(blonde) != blonde) throw new Exception("hairTestFir 9 failed"); + if (f.hairTestFirA(blonde) != blonde) throw new Exception("hairTestFir A failed"); + } + { + GlobalInstance = globalinstance2; + if (GlobalInstance != globalinstance2) throw new Exception("GlobalInstance 1 failed"); + + auto i = new Instances(); + i.MemberInstance = Instances.memberinstance3; + if (i.MemberInstance != Instances.memberinstance3) throw new Exception("MemberInstance 1 failed"); + } + // ignore enum item tests start + { + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero) != 0) throw new Exception("ignoreATest 0 failed"); + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_three) != 3) throw new Exception("ignoreATest 3 failed"); + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten) != 10) throw new Exception("ignoreATest 10 failed"); + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven) != 11) throw new Exception("ignoreATest 11 failed"); + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen) != 13) throw new Exception("ignoreATest 13 failed"); + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen) != 14) throw new Exception("ignoreATest 14 failed"); + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty) != 20) throw new Exception("ignoreATest 20 failed"); + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty) != 30) throw new Exception("ignoreATest 30 failed"); + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two) != 32) throw new Exception("ignoreATest 32 failed"); + if (cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three) != 33) throw new Exception("ignoreATest 33 failed"); + } + { + if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven) != 11) throw new Exception("ignoreBTest 11 failed"); + if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve) != 12) throw new Exception("ignoreBTest 12 failed"); + if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one) != 31) throw new Exception("ignoreBTest 31 failed"); + if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two) != 32) throw new Exception("ignoreBTest 32 failed"); + if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one) != 41) throw new Exception("ignoreBTest 41 failed"); + if (cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two) != 42) throw new Exception("ignoreBTest 42 failed"); + } + { + if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten) != 10) throw new Exception("ignoreCTest 10 failed"); + if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve) != 12) throw new Exception("ignoreCTest 12 failed"); + if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty) != 30) throw new Exception("ignoreCTest 30 failed"); + if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two) != 32) throw new Exception("ignoreCTest 32 failed"); + if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty) != 40) throw new Exception("ignoreCTest 40 failed"); + if (cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two) != 42) throw new Exception("ignoreCTest 42 failed"); + } + { + if (cast(int)ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one) != 21) throw new Exception("ignoreDTest 21 failed"); + if (cast(int)ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two) != 22) throw new Exception("ignoreDTest 22 failed"); + } + { + if (cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero) != 0) throw new Exception("ignoreETest 0 failed"); + if (cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one) != 21) throw new Exception("ignoreETest 21 failed"); + if (cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two) != 22) throw new Exception("ignoreETest 22 failed"); + } + // ignore enum item tests end + { + if (cast(int)repeatTest(repeat.one) != 1) throw new Exception("repeatTest 1 failed"); + if (cast(int)repeatTest(repeat.initial) != 1) throw new Exception("repeatTest 2 failed"); + if (cast(int)repeatTest(repeat.two) != 2) throw new Exception("repeatTest 3 failed"); + if (cast(int)repeatTest(repeat.three) != 3) throw new Exception("repeatTest 4 failed"); + if (cast(int)repeatTest(repeat.llast) != 3) throw new Exception("repeatTest 5 failed"); + if (cast(int)repeatTest(repeat.end) != 3) throw new Exception("repeatTest 6 failed"); + } +} diff --git a/Examples/test-suite/d/enum_thorough_runme.2.d b/Examples/test-suite/d/enum_thorough_runme.2.d new file mode 100644 index 000000000..d8b2a2ad9 --- /dev/null +++ b/Examples/test-suite/d/enum_thorough_runme.2.d @@ -0,0 +1,425 @@ +module enum_thorough_runme; + +import std.exception; +import enum_thorough.enum_thorough; +import enum_thorough.AnonStruct; +import enum_thorough.colour; +import enum_thorough.FirStruct; +import enum_thorough.HairStruct; +import enum_thorough.IgnoreTest; +import enum_thorough.Instances; +import enum_thorough.namedanon; +import enum_thorough.namedanonspace; +import enum_thorough.newname; +import enum_thorough.NewNameStruct; +import enum_thorough.repeat; +import enum_thorough.SpeedClass; +import enum_thorough.TClassInt; +import enum_thorough.TemplateClassInt; +import enum_thorough.TreesClass; +import enum_thorough.twonames; +import enum_thorough.TwoNamesStruct; + +void main() { + { + // Anonymous enums + int i = AnonEnum1; + enforce(ReallyAnInteger == 200, "Test Anon 1 failed"); + i += AnonSpaceEnum1; + i += AnonStruct.AnonStructEnum1; + } + { + auto red = colour.red; + colourTest1(red); + colourTest2(red); + colourTest3(red); + colourTest4(red); + myColour = red; + } + { + auto s = new SpeedClass(); + auto speed = SpeedClass.speed.slow; + enforce(s.speedTest1(speed) == speed, "speedTest 1 failed"); + enforce(s.speedTest2(speed) == speed, "speedTest 2 failed"); + enforce(s.speedTest3(speed) == speed, "speedTest 3 failed"); + enforce(s.speedTest4(speed) == speed, "speedTest 4 failed"); + enforce(s.speedTest5(speed) == speed, "speedTest 5 failed"); + enforce(s.speedTest6(speed) == speed, "speedTest 6 failed"); + enforce(s.speedTest7(speed) == speed, "speedTest 7 failed"); + enforce(s.speedTest8(speed) == speed, "speedTest 8 failed"); + + enforce(speedTest1(speed) == speed, "speedTest Global 1 failed"); + enforce(speedTest2(speed) == speed, "speedTest Global 2 failed"); + enforce(speedTest3(speed) == speed, "speedTest Global 3 failed"); + enforce(speedTest4(speed) == speed, "speedTest Global 4 failed"); + enforce(speedTest5(speed) == speed, "speedTest Global 5 failed"); + } + { + auto s = new SpeedClass(); + auto slow = SpeedClass.speed.slow; + auto lightning = SpeedClass.speed.lightning; + + enforce(s.mySpeedtd1 == slow, "mySpeedtd1 1 failed"); + enforce(cast(int)s.mySpeedtd1 == 10, "mySpeedtd1 2 failed"); + + s.mySpeedtd1 = lightning; + enforce(s.mySpeedtd1 == lightning, "mySpeedtd1 3 failed"); + enforce(cast(int)s.mySpeedtd1 == 31, "mySpeedtd1 4 failed"); + } + { + enforce(namedanonTest1(namedanon.NamedAnon2) == namedanon.NamedAnon2, "namedanonTest 1 failed"); + } + { + auto val = twonames.TwoNames2; + enforce(twonamesTest1(val) == val, "twonamesTest 1 failed"); + enforce(twonamesTest2(val) == val, "twonamesTest 2 failed"); + enforce(twonamesTest3(val) == val, "twonamesTest 3 failed"); + } + { + auto t = new TwoNamesStruct(); + auto val = TwoNamesStruct.twonames.TwoNamesStruct1; + enforce(t.twonamesTest1(val) == val, "twonamesTest 1 failed"); + enforce(t.twonamesTest2(val) == val, "twonamesTest 2 failed"); + enforce(t.twonamesTest3(val) == val, "twonamesTest 3 failed"); + } + { + auto val = namedanonspace.NamedAnonSpace2; + enforce(namedanonspaceTest1(val) == val, "namedanonspaceTest 1 failed"); + enforce(namedanonspaceTest2(val) == val, "namedanonspaceTest 2 failed"); + enforce(namedanonspaceTest3(val) == val, "namedanonspaceTest 3 failed"); + enforce(namedanonspaceTest4(val) == val, "namedanonspaceTest 4 failed"); + } + { + auto t = new TemplateClassInt(); + auto galileo = TemplateClassInt.scientists.galileo; + enforce(t.scientistsTest1(galileo) == galileo, "scientistsTest 1 failed"); + enforce(t.scientistsTest2(galileo) == galileo, "scientistsTest 2 failed"); + enforce(t.scientistsTest3(galileo) == galileo, "scientistsTest 3 failed"); + enforce(t.scientistsTest4(galileo) == galileo, "scientistsTest 4 failed"); + enforce(t.scientistsTest5(galileo) == galileo, "scientistsTest 5 failed"); + enforce(t.scientistsTest6(galileo) == galileo, "scientistsTest 6 failed"); + enforce(t.scientistsTest7(galileo) == galileo, "scientistsTest 7 failed"); + enforce(t.scientistsTest8(galileo) == galileo, "scientistsTest 8 failed"); + enforce(t.scientistsTest9(galileo) == galileo, "scientistsTest 9 failed"); +// enforce(t.scientistsTestA(galileo) == galileo, "scientistsTest A failed"); + enforce(t.scientistsTestB(galileo) == galileo, "scientistsTest B failed"); +// enforce(t.scientistsTestC(galileo) == galileo, "scientistsTest C failed"); + enforce(t.scientistsTestD(galileo) == galileo, "scientistsTest D failed"); + enforce(t.scientistsTestE(galileo) == galileo, "scientistsTest E failed"); + enforce(t.scientistsTestF(galileo) == galileo, "scientistsTest F failed"); + enforce(t.scientistsTestG(galileo) == galileo, "scientistsTest G failed"); + enforce(t.scientistsTestH(galileo) == galileo, "scientistsTest H failed"); + enforce(t.scientistsTestI(galileo) == galileo, "scientistsTest I failed"); + enforce(t.scientistsTestJ(galileo) == galileo, "scientistsTest J failed"); + + enforce(scientistsTest1(galileo) == galileo, "scientistsTest Global 1 failed"); + enforce(scientistsTest2(galileo) == galileo, "scientistsTest Global 2 failed"); + enforce(scientistsTest3(galileo) == galileo, "scientistsTest Global 3 failed"); + enforce(scientistsTest4(galileo) == galileo, "scientistsTest Global 4 failed"); + enforce(scientistsTest5(galileo) == galileo, "scientistsTest Global 5 failed"); + enforce(scientistsTest6(galileo) == galileo, "scientistsTest Global 6 failed"); + enforce(scientistsTest7(galileo) == galileo, "scientistsTest Global 7 failed"); + enforce(scientistsTest8(galileo) == galileo, "scientistsTest Global 8 failed"); + } + { + auto t = new TClassInt(); + auto bell = TClassInt.scientists.bell; + auto galileo = TemplateClassInt.scientists.galileo; + enforce(t.scientistsNameTest1(bell) == bell, "scientistsNameTest 1 failed"); + enforce(t.scientistsNameTest2(bell) == bell, "scientistsNameTest 2 failed"); + enforce(t.scientistsNameTest3(bell) == bell, "scientistsNameTest 3 failed"); + enforce(t.scientistsNameTest4(bell) == bell, "scientistsNameTest 4 failed"); + enforce(t.scientistsNameTest5(bell) == bell, "scientistsNameTest 5 failed"); + enforce(t.scientistsNameTest6(bell) == bell, "scientistsNameTest 6 failed"); + enforce(t.scientistsNameTest7(bell) == bell, "scientistsNameTest 7 failed"); + enforce(t.scientistsNameTest8(bell) == bell, "scientistsNameTest 8 failed"); + enforce(t.scientistsNameTest9(bell) == bell, "scientistsNameTest 9 failed"); +// enforce(t.scientistsNameTestA(bell) == bell, "scientistsNameTest A failed"); + enforce(t.scientistsNameTestB(bell) == bell, "scientistsNameTest B failed"); +// enforce(t.scientistsNameTestC(bell) == bell, "scientistsNameTest C failed"); + enforce(t.scientistsNameTestD(bell) == bell, "scientistsNameTest D failed"); + enforce(t.scientistsNameTestE(bell) == bell, "scientistsNameTest E failed"); + enforce(t.scientistsNameTestF(bell) == bell, "scientistsNameTest F failed"); + enforce(t.scientistsNameTestG(bell) == bell, "scientistsNameTest G failed"); + enforce(t.scientistsNameTestH(bell) == bell, "scientistsNameTest H failed"); + enforce(t.scientistsNameTestI(bell) == bell, "scientistsNameTest I failed"); + + enforce(t.scientistsNameSpaceTest1(bell) == bell, "scientistsNameSpaceTest 1 failed"); + enforce(t.scientistsNameSpaceTest2(bell) == bell, "scientistsNameSpaceTest 2 failed"); + enforce(t.scientistsNameSpaceTest3(bell) == bell, "scientistsNameSpaceTest 3 failed"); + enforce(t.scientistsNameSpaceTest4(bell) == bell, "scientistsNameSpaceTest 4 failed"); + enforce(t.scientistsNameSpaceTest5(bell) == bell, "scientistsNameSpaceTest 5 failed"); + enforce(t.scientistsNameSpaceTest6(bell) == bell, "scientistsNameSpaceTest 6 failed"); + enforce(t.scientistsNameSpaceTest7(bell) == bell, "scientistsNameSpaceTest 7 failed"); + + enforce(t.scientistsOtherTest1(galileo) == galileo, "scientistsOtherTest 1 failed"); + enforce(t.scientistsOtherTest2(galileo) == galileo, "scientistsOtherTest 2 failed"); + enforce(t.scientistsOtherTest3(galileo) == galileo, "scientistsOtherTest 3 failed"); + enforce(t.scientistsOtherTest4(galileo) == galileo, "scientistsOtherTest 4 failed"); + enforce(t.scientistsOtherTest5(galileo) == galileo, "scientistsOtherTest 5 failed"); + enforce(t.scientistsOtherTest6(galileo) == galileo, "scientistsOtherTest 6 failed"); + enforce(t.scientistsOtherTest7(galileo) == galileo, "scientistsOtherTest 7 failed"); + + enforce(scientistsNameTest1(bell) == bell, "scientistsNameTest Global 1 failed"); + enforce(scientistsNameTest2(bell) == bell, "scientistsNameTest Global 2 failed"); + enforce(scientistsNameTest3(bell) == bell, "scientistsNameTest Global 3 failed"); + enforce(scientistsNameTest4(bell) == bell, "scientistsNameTest Global 4 failed"); + enforce(scientistsNameTest5(bell) == bell, "scientistsNameTest Global 5 failed"); + enforce(scientistsNameTest6(bell) == bell, "scientistsNameTest Global 6 failed"); + enforce(scientistsNameTest7(bell) == bell, "scientistsNameTest Global 7 failed"); + + enforce(scientistsNameSpaceTest1(bell) == bell, "scientistsNameSpaceTest Global 1 failed"); + enforce(scientistsNameSpaceTest2(bell) == bell, "scientistsNameSpaceTest Global 2 failed"); + enforce(scientistsNameSpaceTest3(bell) == bell, "scientistsNameSpaceTest Global 3 failed"); + enforce(scientistsNameSpaceTest4(bell) == bell, "scientistsNameSpaceTest Global 4 failed"); + enforce(scientistsNameSpaceTest5(bell) == bell, "scientistsNameSpaceTest Global 5 failed"); + enforce(scientistsNameSpaceTest6(bell) == bell, "scientistsNameSpaceTest Global 6 failed"); + enforce(scientistsNameSpaceTest7(bell) == bell, "scientistsNameSpaceTest Global 7 failed"); + + enforce(scientistsNameSpaceTest8(bell) == bell, "scientistsNameSpaceTest Global 8 failed"); + enforce(scientistsNameSpaceTest9(bell) == bell, "scientistsNameSpaceTest Global 9 failed"); + enforce(scientistsNameSpaceTestA(bell) == bell, "scientistsNameSpaceTest Global A failed"); + enforce(scientistsNameSpaceTestB(bell) == bell, "scientistsNameSpaceTest Global B failed"); + enforce(scientistsNameSpaceTestC(bell) == bell, "scientistsNameSpaceTest Global C failed"); + enforce(scientistsNameSpaceTestD(bell) == bell, "scientistsNameSpaceTest Global D failed"); + enforce(scientistsNameSpaceTestE(bell) == bell, "scientistsNameSpaceTest Global E failed"); + + enforce(scientistsNameSpaceTestF(bell) == bell, "scientistsNameSpaceTest Global F failed"); + enforce(scientistsNameSpaceTestG(bell) == bell, "scientistsNameSpaceTest Global G failed"); + enforce(scientistsNameSpaceTestH(bell) == bell, "scientistsNameSpaceTest Global H failed"); + enforce(scientistsNameSpaceTestI(bell) == bell, "scientistsNameSpaceTest Global I failed"); + enforce(scientistsNameSpaceTestJ(bell) == bell, "scientistsNameSpaceTest Global J failed"); + enforce(scientistsNameSpaceTestK(bell) == bell, "scientistsNameSpaceTest Global K failed"); + enforce(scientistsNameSpaceTestL(bell) == bell, "scientistsNameSpaceTest Global L failed"); + } + { + auto val = newname.argh; + enforce(renameTest1(val) == val, "renameTest Global 1 failed"); + enforce(renameTest2(val) == val, "renameTest Global 2 failed"); + } + { + auto n = new NewNameStruct(); + enforce(n.renameTest1(NewNameStruct.enumeration.bang) == NewNameStruct.enumeration.bang, "renameTest 1 failed"); + enforce(n.renameTest2(NewNameStruct.enumeration.bang) == NewNameStruct.enumeration.bang, "renameTest 2 failed"); + enforce(n.renameTest3(NewNameStruct.simplerenamed.simple1) == NewNameStruct.simplerenamed.simple1, "renameTest 3 failed"); + enforce(n.renameTest4(NewNameStruct.doublenamerenamed.doublename1) == NewNameStruct.doublenamerenamed.doublename1, "renameTest 4 failed"); + enforce(n.renameTest5(NewNameStruct.doublenamerenamed.doublename1) == NewNameStruct.doublenamerenamed.doublename1, "renameTest 5 failed"); + enforce(n.renameTest6(NewNameStruct.singlenamerenamed.singlename1) == NewNameStruct.singlenamerenamed.singlename1, "renameTest 6 failed"); + } + { + enforce(renameTest3(NewNameStruct.enumeration.bang) == NewNameStruct.enumeration.bang, "renameTest Global 3 failed"); + enforce(renameTest4(NewNameStruct.simplerenamed.simple1) == NewNameStruct.simplerenamed.simple1, "renameTest Global 4 failed"); + enforce(renameTest5(NewNameStruct.doublenamerenamed.doublename1) == NewNameStruct.doublenamerenamed.doublename1, "renameTest Global 5 failed"); + enforce(renameTest6(NewNameStruct.doublenamerenamed.doublename1) == NewNameStruct.doublenamerenamed.doublename1, "renameTest Global 6 failed"); + enforce(renameTest7(NewNameStruct.singlenamerenamed.singlename1) == NewNameStruct.singlenamerenamed.singlename1, "renameTest Global 7 failed"); + } + { + auto t = new TreesClass(); + auto pine = TreesClass.trees.pine; + + enforce(t.treesTest1(pine) == pine, "treesTest 1 failed"); + enforce(t.treesTest2(pine) == pine, "treesTest 2 failed"); + enforce(t.treesTest3(pine) == pine, "treesTest 3 failed"); + enforce(t.treesTest4(pine) == pine, "treesTest 4 failed"); + enforce(t.treesTest5(pine) == pine, "treesTest 5 failed"); + enforce(t.treesTest6(pine) == pine, "treesTest 6 failed"); + enforce(t.treesTest7(pine) == pine, "treesTest 7 failed"); + enforce(t.treesTest8(pine) == pine, "treesTest 8 failed"); + enforce(t.treesTest9(pine) == pine, "treesTest 9 failed"); + enforce(t.treesTestA(pine) == pine, "treesTest A failed"); + enforce(t.treesTestB(pine) == pine, "treesTest B failed"); + enforce(t.treesTestC(pine) == pine, "treesTest C failed"); + enforce(t.treesTestD(pine) == pine, "treesTest D failed"); + enforce(t.treesTestE(pine) == pine, "treesTest E failed"); + enforce(t.treesTestF(pine) == pine, "treesTest F failed"); + enforce(t.treesTestG(pine) == pine, "treesTest G failed"); + enforce(t.treesTestH(pine) == pine, "treesTest H failed"); + enforce(t.treesTestI(pine) == pine, "treesTest I failed"); + enforce(t.treesTestJ(pine) == pine, "treesTest J failed"); + enforce(t.treesTestK(pine) == pine, "treesTest K failed"); + enforce(t.treesTestL(pine) == pine, "treesTest L failed"); + enforce(t.treesTestM(pine) == pine, "treesTest M failed"); + enforce(t.treesTestN(pine) == pine, "treesTest N failed"); + enforce(t.treesTestO(pine) == pine, "treesTest O failed"); + + enforce(treesTest1(pine) == pine, "treesTest Global 1 failed"); + enforce(treesTest2(pine) == pine, "treesTest Global 2 failed"); + enforce(treesTest3(pine) == pine, "treesTest Global 3 failed"); + enforce(treesTest4(pine) == pine, "treesTest Global 4 failed"); + enforce(treesTest5(pine) == pine, "treesTest Global 5 failed"); + enforce(treesTest6(pine) == pine, "treesTest Global 6 failed"); + enforce(treesTest7(pine) == pine, "treesTest Global 7 failed"); + enforce(treesTest8(pine) == pine, "treesTest Global 8 failed"); + enforce(treesTest9(pine) == pine, "treesTest Global 9 failed"); + enforce(treesTestA(pine) == pine, "treesTest Global A failed"); + enforce(treesTestB(pine) == pine, "treesTest Global B failed"); + enforce(treesTestC(pine) == pine, "treesTest Global C failed"); + enforce(treesTestD(pine) == pine, "treesTest Global D failed"); + enforce(treesTestE(pine) == pine, "treesTest Global E failed"); + enforce(treesTestF(pine) == pine, "treesTest Global F failed"); + enforce(treesTestG(pine) == pine, "treesTest Global G failed"); + enforce(treesTestH(pine) == pine, "treesTest Global H failed"); + enforce(treesTestI(pine) == pine, "treesTest Global I failed"); + enforce(treesTestJ(pine) == pine, "treesTest Global J failed"); + enforce(treesTestK(pine) == pine, "treesTest Global K failed"); + enforce(treesTestL(pine) == pine, "treesTest Global L failed"); + enforce(treesTestM(pine) == pine, "treesTest Global M failed"); +// enforce(treesTestN(pine) == pine, "treesTest Global N failed"); + enforce(treesTestO(pine) == pine, "treesTest Global O failed"); + enforce(treesTestP(pine) == pine, "treesTest Global P failed"); + enforce(treesTestQ(pine) == pine, "treesTest Global Q failed"); + enforce(treesTestR(pine) == pine, "treesTest Global R failed"); + } + { + auto h = new HairStruct(); + auto ginger = HairStruct.hair.ginger; + + enforce(h.hairTest1(ginger) == ginger, "hairTest 1 failed"); + enforce(h.hairTest2(ginger) == ginger, "hairTest 2 failed"); + enforce(h.hairTest3(ginger) == ginger, "hairTest 3 failed"); + enforce(h.hairTest4(ginger) == ginger, "hairTest 4 failed"); + enforce(h.hairTest5(ginger) == ginger, "hairTest 5 failed"); + enforce(h.hairTest6(ginger) == ginger, "hairTest 6 failed"); + enforce(h.hairTest7(ginger) == ginger, "hairTest 7 failed"); + enforce(h.hairTest8(ginger) == ginger, "hairTest 8 failed"); + enforce(h.hairTest9(ginger) == ginger, "hairTest 9 failed"); + enforce(h.hairTestA(ginger) == ginger, "hairTest A failed"); + enforce(h.hairTestB(ginger) == ginger, "hairTest B failed"); + + auto red = colour.red; + enforce(h.colourTest1(red) == red, "colourTest HairStruct 1 failed"); + enforce(h.colourTest2(red) == red, "colourTest HairStruct 2 failed"); + enforce(h.namedanonTest1(namedanon.NamedAnon2) == namedanon.NamedAnon2, "namedanonTest HairStruct 1 failed"); + enforce(h.namedanonspaceTest1(namedanonspace.NamedAnonSpace2) == namedanonspace.NamedAnonSpace2, "namedanonspaceTest HairStruct 1 failed"); + + auto fir = TreesClass.trees.fir; + enforce(h.treesGlobalTest1(fir) == fir, "treesGlobalTest1 HairStruct 1 failed"); + enforce(h.treesGlobalTest2(fir) == fir, "treesGlobalTest1 HairStruct 2 failed"); + enforce(h.treesGlobalTest3(fir) == fir, "treesGlobalTest1 HairStruct 3 failed"); + enforce(h.treesGlobalTest4(fir) == fir, "treesGlobalTest1 HairStruct 4 failed"); + } + { + auto blonde = HairStruct.hair.blonde; + enforce(hairTest1(blonde) == blonde, "hairTest Global 1 failed"); + enforce(hairTest2(blonde) == blonde, "hairTest Global 2 failed"); + enforce(hairTest3(blonde) == blonde, "hairTest Global 3 failed"); + enforce(hairTest4(blonde) == blonde, "hairTest Global 4 failed"); + enforce(hairTest5(blonde) == blonde, "hairTest Global 5 failed"); + enforce(hairTest6(blonde) == blonde, "hairTest Global 6 failed"); + enforce(hairTest7(blonde) == blonde, "hairTest Global 7 failed"); + enforce(hairTest8(blonde) == blonde, "hairTest Global 8 failed"); + enforce(hairTest9(blonde) == blonde, "hairTest Global 9 failed"); + enforce(hairTestA(blonde) == blonde, "hairTest Global A failed"); + enforce(hairTestB(blonde) == blonde, "hairTest Global B failed"); + enforce(hairTestC(blonde) == blonde, "hairTest Global C failed"); + + enforce(hairTestA1(blonde) == blonde, "hairTest Global A1 failed"); + enforce(hairTestA2(blonde) == blonde, "hairTest Global A2 failed"); + enforce(hairTestA3(blonde) == blonde, "hairTest Global A3 failed"); + enforce(hairTestA4(blonde) == blonde, "hairTest Global A4 failed"); + enforce(hairTestA5(blonde) == blonde, "hairTest Global A5 failed"); + enforce(hairTestA6(blonde) == blonde, "hairTest Global A6 failed"); + enforce(hairTestA7(blonde) == blonde, "hairTest Global A7 failed"); + enforce(hairTestA8(blonde) == blonde, "hairTest Global A8 failed"); + enforce(hairTestA9(blonde) == blonde, "hairTest Global A9 failed"); + enforce(hairTestAA(blonde) == blonde, "hairTest Global AA failed"); + enforce(hairTestAB(blonde) == blonde, "hairTest Global AB failed"); + enforce(hairTestAC(blonde) == blonde, "hairTest Global AC failed"); + + enforce(hairTestB1(blonde) == blonde, "hairTest Global B1 failed"); + enforce(hairTestB2(blonde) == blonde, "hairTest Global B2 failed"); + enforce(hairTestB3(blonde) == blonde, "hairTest Global B3 failed"); + enforce(hairTestB4(blonde) == blonde, "hairTest Global B4 failed"); + enforce(hairTestB5(blonde) == blonde, "hairTest Global B5 failed"); + enforce(hairTestB6(blonde) == blonde, "hairTest Global B6 failed"); + enforce(hairTestB7(blonde) == blonde, "hairTest Global B7 failed"); + enforce(hairTestB8(blonde) == blonde, "hairTest Global B8 failed"); + enforce(hairTestB9(blonde) == blonde, "hairTest Global B9 failed"); + enforce(hairTestBA(blonde) == blonde, "hairTest Global BA failed"); + enforce(hairTestBB(blonde) == blonde, "hairTest Global BB failed"); + enforce(hairTestBC(blonde) == blonde, "hairTest Global BC failed"); + + enforce(hairTestC1(blonde) == blonde, "hairTest Global C1 failed"); + enforce(hairTestC2(blonde) == blonde, "hairTest Global C2 failed"); + enforce(hairTestC3(blonde) == blonde, "hairTest Global C3 failed"); + enforce(hairTestC4(blonde) == blonde, "hairTest Global C4 failed"); + enforce(hairTestC5(blonde) == blonde, "hairTest Global C5 failed"); + enforce(hairTestC6(blonde) == blonde, "hairTest Global C6 failed"); + enforce(hairTestC7(blonde) == blonde, "hairTest Global C7 failed"); + enforce(hairTestC8(blonde) == blonde, "hairTest Global C8 failed"); + enforce(hairTestC9(blonde) == blonde, "hairTest Global C9 failed"); + enforce(hairTestCA(blonde) == blonde, "hairTest Global CA failed"); + enforce(hairTestCB(blonde) == blonde, "hairTest Global CB failed"); + enforce(hairTestCC(blonde) == blonde, "hairTest Global CC failed"); + } + { + auto f = new FirStruct(); + auto blonde = HairStruct.hair.blonde; + + enforce(f.hairTestFir1(blonde) == blonde, "hairTestFir 1 failed"); + enforce(f.hairTestFir2(blonde) == blonde, "hairTestFir 2 failed"); + enforce(f.hairTestFir3(blonde) == blonde, "hairTestFir 3 failed"); + enforce(f.hairTestFir4(blonde) == blonde, "hairTestFir 4 failed"); + enforce(f.hairTestFir5(blonde) == blonde, "hairTestFir 5 failed"); + enforce(f.hairTestFir6(blonde) == blonde, "hairTestFir 6 failed"); + enforce(f.hairTestFir7(blonde) == blonde, "hairTestFir 7 failed"); + enforce(f.hairTestFir8(blonde) == blonde, "hairTestFir 8 failed"); + enforce(f.hairTestFir9(blonde) == blonde, "hairTestFir 9 failed"); + enforce(f.hairTestFirA(blonde) == blonde, "hairTestFir A failed"); + } + { + GlobalInstance = globalinstance2; + enforce(GlobalInstance == globalinstance2, "GlobalInstance 1 failed"); + + auto i = new Instances(); + i.MemberInstance = Instances.memberinstance3; + enforce(i.MemberInstance == Instances.memberinstance3, "MemberInstance 1 failed"); + } + // ignore enum item tests start + { + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero) == 0, "ignoreATest 0 failed"); + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_three) == 3, "ignoreATest 3 failed"); + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten) == 10, "ignoreATest 10 failed"); + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven) == 11, "ignoreATest 11 failed"); + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen) == 13, "ignoreATest 13 failed"); + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen) == 14, "ignoreATest 14 failed"); + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty) == 20, "ignoreATest 20 failed"); + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty) == 30, "ignoreATest 30 failed"); + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two) == 32, "ignoreATest 32 failed"); + enforce(cast(int)ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three) == 33, "ignoreATest 33 failed"); + } + { + enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven) == 11, "ignoreBTest 11 failed"); + enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve) == 12, "ignoreBTest 12 failed"); + enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one) == 31, "ignoreBTest 31 failed"); + enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two) == 32, "ignoreBTest 32 failed"); + enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one) == 41, "ignoreBTest 41 failed"); + enforce(cast(int)ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two) == 42, "ignoreBTest 42 failed"); + } + { + enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten), "ignoreCTest 10 failed"); + enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve) == 12, "ignoreCTest 12 failed"); + enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty) == 30, "ignoreCTest 30 failed"); + enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two) == 32, "ignoreCTest 32 failed"); + enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty) == 40, "ignoreCTest 40 failed"); + enforce(cast(int)ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two) == 42, "ignoreCTest 42 failed"); + } + { + enforce(cast(int)ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one) == 21, "ignoreDTest 21 failed"); + enforce(cast(int)ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two) == 22, "ignoreDTest 22 failed"); + } + { + enforce(cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero) == 0, "ignoreETest 0 failed"); + enforce(cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one) == 21, "ignoreETest 21 failed"); + enforce(cast(int)ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two) == 22, "ignoreETest 22 failed"); + } + // ignore enum item tests end + { + enforce(cast(int)repeatTest(repeat.one) == 1, "repeatTest 1 failed"); + enforce(cast(int)repeatTest(repeat.initial) == 1, "repeatTest 2 failed"); + enforce(cast(int)repeatTest(repeat.two) == 2, "repeatTest 3 failed"); + enforce(cast(int)repeatTest(repeat.three) == 3, "repeatTest 4 failed"); + enforce(cast(int)repeatTest(repeat.llast) == 3, "repeatTest 5 failed"); + enforce(cast(int)repeatTest(repeat.end) == 3, "repeatTest 6 failed"); + } +} diff --git a/Examples/test-suite/d/inherit_target_language_runme.1.d b/Examples/test-suite/d/inherit_target_language_runme.1.d new file mode 100644 index 000000000..8a13caca4 --- /dev/null +++ b/Examples/test-suite/d/inherit_target_language_runme.1.d @@ -0,0 +1,29 @@ +module inherit_target_language_runme; + +import inherit_target_language.BaseX; +import inherit_target_language.Derived1; +import inherit_target_language.Derived2; +import inherit_target_language.DerivedX; +import inherit_target_language.MultipleDerived1; +import inherit_target_language.MultipleDerived2; +import inherit_target_language.MultipleDerived3; +import inherit_target_language.MultipleDerived4; + +void main() { + (new Derived1()).targetLanguageBaseMethod(); + (new Derived2()).targetLanguageBaseMethod(); + + (new MultipleDerived1()).targetLanguageBaseMethod(); + (new MultipleDerived2()).targetLanguageBaseMethod(); + (new MultipleDerived3()).f(); + (new MultipleDerived4()).g(); + + auto baseX = new BaseX(); + baseX.basex(); + baseX.targetLanguageBase2Method(); + + auto derivedX = new DerivedX(); + derivedX.basex(); + derivedX.derivedx(); + derivedX.targetLanguageBase2Method(); +} diff --git a/Examples/test-suite/d/inherit_target_language_runme.2.d b/Examples/test-suite/d/inherit_target_language_runme.2.d new file mode 100644 index 000000000..8a13caca4 --- /dev/null +++ b/Examples/test-suite/d/inherit_target_language_runme.2.d @@ -0,0 +1,29 @@ +module inherit_target_language_runme; + +import inherit_target_language.BaseX; +import inherit_target_language.Derived1; +import inherit_target_language.Derived2; +import inherit_target_language.DerivedX; +import inherit_target_language.MultipleDerived1; +import inherit_target_language.MultipleDerived2; +import inherit_target_language.MultipleDerived3; +import inherit_target_language.MultipleDerived4; + +void main() { + (new Derived1()).targetLanguageBaseMethod(); + (new Derived2()).targetLanguageBaseMethod(); + + (new MultipleDerived1()).targetLanguageBaseMethod(); + (new MultipleDerived2()).targetLanguageBaseMethod(); + (new MultipleDerived3()).f(); + (new MultipleDerived4()).g(); + + auto baseX = new BaseX(); + baseX.basex(); + baseX.targetLanguageBase2Method(); + + auto derivedX = new DerivedX(); + derivedX.basex(); + derivedX.derivedx(); + derivedX.targetLanguageBase2Method(); +} diff --git a/Examples/test-suite/d/li_attribute_runme.1.d b/Examples/test-suite/d/li_attribute_runme.1.d new file mode 100644 index 000000000..ada3ed8d8 --- /dev/null +++ b/Examples/test-suite/d/li_attribute_runme.1.d @@ -0,0 +1,75 @@ +module li_attribute_runme; + +import li_attribute.A; +import li_attribute.B; +import li_attribute.MyClass; +import li_attribute.MyClassVal; +import li_attribute.MyStringyClass; +import li_attribute.MyFoo; +import li_attribute.Param_i; + +void main() { + auto aa = new A(1,2,3); + + if (aa.a != 1) + throw new Exception("error"); + aa.a = 3; + if (aa.a != 3) + throw new Exception("error"); + + if (aa.b != 2) + throw new Exception("error"); + aa.b = 5; + if (aa.b != 5) + throw new Exception("error"); + + if (aa.d != aa.b) + throw new Exception("error"); + + if (aa.c != 3) + throw new Exception("error"); + + auto pi = new Param_i(7); + if (pi.value != 7) + throw new Exception("error"); + + pi.value=3; + if (pi.value != 3) + throw new Exception("error"); + + auto b = new B(aa); + if (b.a.c != 3) + throw new Exception("error"); + + // class/struct attribute with get/set methods using return/pass by reference + auto myFoo = new MyFoo(); + myFoo.x = 8; + auto myClass = new MyClass(); + myClass.Foo = myFoo; + if (myClass.Foo.x != 8) + throw new Exception("error"); + + // class/struct attribute with get/set methods using return/pass by value + auto myClassVal = new MyClassVal(); + if (myClassVal.ReadWriteFoo.x != -1) + throw new Exception("error"); + if (myClassVal.ReadOnlyFoo.x != -1) + throw new Exception("error"); + myClassVal.ReadWriteFoo = myFoo; + if (myClassVal.ReadWriteFoo.x != 8) + throw new Exception("error"); + if (myClassVal.ReadOnlyFoo.x != 8) + throw new Exception("error"); + + // string attribute with get/set methods using return/pass by value + auto myStringClass = new MyStringyClass("initial string"); + if (myStringClass.ReadWriteString != "initial string") + throw new Exception("error"); + if (myStringClass.ReadOnlyString != "initial string") + throw new Exception("error"); + myStringClass.ReadWriteString = "changed string"; + if (myStringClass.ReadWriteString != "changed string") + throw new Exception("error"); + if (myStringClass.ReadOnlyString != "changed string") + throw new Exception("error"); +} diff --git a/Examples/test-suite/d/li_attribute_runme.2.d b/Examples/test-suite/d/li_attribute_runme.2.d new file mode 100644 index 000000000..4e0ea58ff --- /dev/null +++ b/Examples/test-suite/d/li_attribute_runme.2.d @@ -0,0 +1,58 @@ +module li_attribute_runme; + +import std.exception; +import li_attribute.A; +import li_attribute.B; +import li_attribute.MyClass; +import li_attribute.MyClassVal; +import li_attribute.MyStringyClass; +import li_attribute.MyFoo; +import li_attribute.Param_i; + +void main() { + auto aa = new A(1,2,3); + + enforce(aa.a == 1); + aa.a = 3; + enforce(aa.a == 3); + + enforce(aa.b == 2); + aa.b = 5; + enforce(aa.b == 5); + + enforce(aa.d == aa.b); + + enforce(aa.c == 3); + + auto pi = new Param_i(7); + enforce(pi.value == 7); + + pi.value=3; + enforce(pi.value == 3); + + auto b = new B(aa); + enforce(b.a.c == 3); + + // class/struct attribute with get/set methods using return/pass by reference + auto myFoo = new MyFoo(); + myFoo.x = 8; + auto myClass = new MyClass(); + myClass.Foo = myFoo; + enforce(myClass.Foo.x == 8); + + // class/struct attribute with get/set methods using return/pass by value + auto myClassVal = new MyClassVal(); + enforce(myClassVal.ReadWriteFoo.x == -1); + enforce(myClassVal.ReadOnlyFoo.x == -1); + myClassVal.ReadWriteFoo = myFoo; + enforce(myClassVal.ReadWriteFoo.x == 8); + enforce(myClassVal.ReadOnlyFoo.x == 8); + + // string attribute with get/set methods using return/pass by value + auto myStringClass = new MyStringyClass("initial string"); + enforce(myStringClass.ReadWriteString == "initial string"); + enforce(myStringClass.ReadOnlyString == "initial string"); + myStringClass.ReadWriteString = "changed string"; + enforce(myStringClass.ReadWriteString == "changed string"); + enforce(myStringClass.ReadOnlyString == "changed string"); +} diff --git a/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.1.d b/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.1.d new file mode 100644 index 000000000..098570b95 --- /dev/null +++ b/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.1.d @@ -0,0 +1,21 @@ +module li_boost_shared_ptr_runme_bits; + +import li_boost_shared_ptr_bits.li_boost_shared_ptr_bits; +import li_boost_shared_ptr_bits.HiddenDestructor; +import li_boost_shared_ptr_bits.IntHolder; +import li_boost_shared_ptr_bits.VectorIntHolder; + +void main() { + auto v = new VectorIntHolder(); + v ~= new IntHolder(11); + v ~= new IntHolder(22); + v ~= new IntHolder(33); + + if (sum(v) != 66) { + throw new Exception("sum is wrong"); + } + + { + scope hidden = HiddenDestructor.create(); + } +} diff --git a/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.2.d b/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.2.d new file mode 100644 index 000000000..4891b7673 --- /dev/null +++ b/Examples/test-suite/d/li_boost_shared_ptr_bits_runme.2.d @@ -0,0 +1,19 @@ +module li_boost_shared_ptr_runme_bits; + +import std.exception; +import li_boost_shared_ptr_bits.li_boost_shared_ptr_bits; +import li_boost_shared_ptr_bits.HiddenDestructor; +import li_boost_shared_ptr_bits.IntHolder; +import li_boost_shared_ptr_bits.VectorIntHolder; + +void main() { + auto v = new VectorIntHolder(); + v ~= new IntHolder(11); + v ~= new IntHolder(22); + v ~= new IntHolder(33); + enforce(sum(v) == 66, "sum is wrong"); + + { + scope hidden = HiddenDestructor.create(); + } +} diff --git a/Examples/test-suite/d/li_boost_shared_ptr_runme.1.d b/Examples/test-suite/d/li_boost_shared_ptr_runme.1.d new file mode 100644 index 000000000..ed55cd302 --- /dev/null +++ b/Examples/test-suite/d/li_boost_shared_ptr_runme.1.d @@ -0,0 +1,604 @@ +module li_boost_shared_ptr_runme; + +import tango.io.Stdout; +import tango.core.Exception; +import tango.core.Memory; +import tango.core.Thread; +import tango.text.convert.Integer; +import li_boost_shared_ptr.li_boost_shared_ptr; +import li_boost_shared_ptr.Klass; +import li_boost_shared_ptr.KlassDerived; +import li_boost_shared_ptr.Klass3rdDerived; +import li_boost_shared_ptr.MemberVariables; +import li_boost_shared_ptr.PairIntDouble; + +// Debugging flag +const bool TRACE = false; + +void main() { + if (TRACE) + Stdout("---> STARTED <---").newline; + + debug_shared=TRACE; + + // Change loop count to run for a long time to monitor memory + const int LOOP_COUNT = 1; // 50000; + for (int i = 0; i < LOOP_COUNT; ++i) { + runTest(); + GC.collect(); + } + + if (TRACE) + Stdout("---> NEARLY FINISHED <---").newline; + + // Try to get the GC to collect everything not referenced anymore. + int countdown = 100; + while (--countdown) { + GC.collect(); + if (Klass.getTotal_count() == 1) + break; + Thread.sleep(0.01); + } + + // A single remaining instance expected: the global variable (GlobalValue). + if (Klass.getTotal_count() != 1) + throw new Exception("Klass.total_count=" ~ toString(Klass.getTotal_count())); + + // A single remaining instance expected: the global variable (GlobalSmartValue). + int wrapper_count = shared_ptr_wrapper_count(); + if (wrapper_count != NOT_COUNTING) + if (wrapper_count != 1) + throw new Exception("shared_ptr wrapper count=" ~ toString(wrapper_count)); + + if (TRACE) + Stdout("---> FINISHED <---").newline; +} + +void runTest() { + // simple shared_ptr usage - created in C++ + { + auto k = new Klass("me oh my"); + char[] val = k.getValue(); + verifyValue("me oh my", val); + verifyCount(1, k); + } + + // simple shared_ptr usage - not created in C++ + { + auto k = factorycreate(); + char[] val = k.getValue(); + verifyValue("factorycreate", val); + verifyCount(1, k); + } + + // pass by shared_ptr + { + auto k = new Klass("me oh my"); + auto kret = smartpointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my smartpointertest", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // pass by shared_ptr pointer + { + auto k = new Klass("me oh my"); + auto kret = smartpointerpointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my smartpointerpointertest", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // pass by shared_ptr reference + { + auto k = new Klass("me oh my"); + auto kret = smartpointerreftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my smartpointerreftest", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // pass by shared_ptr pointer reference + { + auto k = new Klass("me oh my"); + auto kret = smartpointerpointerreftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my smartpointerpointerreftest", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // const pass by shared_ptr + { + auto k = new Klass("me oh my"); + auto kret = constsmartpointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // const pass by shared_ptr pointer + { + auto k = new Klass("me oh my"); + auto kret = constsmartpointerpointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // const pass by shared_ptr reference + { + auto k = new Klass("me oh my"); + auto kret = constsmartpointerreftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // pass by value + { + auto k = new Klass("me oh my"); + auto kret = valuetest(k); + char[] val = kret.getValue(); + verifyValue("me oh my valuetest", val); + verifyCount(1, k); + verifyCount(1, kret); + } + + // pass by pointer + { + auto k = new Klass("me oh my"); + auto kret = pointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my pointertest", val); + verifyCount(1, k); + verifyCount(1, kret); + } + + // pass by reference + { + auto k = new Klass("me oh my"); + auto kret = reftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my reftest", val); + verifyCount(1, k); + verifyCount(1, kret); + } + + // pass by pointer reference + { + auto k = new Klass("me oh my"); + auto kret = pointerreftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my pointerreftest", val); + verifyCount(1, k); + verifyCount(1, kret); + } + + // null tests + { + Klass k = null; + + // TODO: add in const versions too + if (smartpointertest(k) !is null) + throw new Exception("return was not null"); + + if (smartpointerpointertest(k) !is null) + throw new Exception("return was not null"); + + if (smartpointerreftest(k) !is null) + throw new Exception("return was not null"); + + if (smartpointerpointerreftest(k) !is null) + throw new Exception("return was not null"); + + if (nullsmartpointerpointertest(null) != "null pointer") + throw new Exception("not null smartpointer pointer"); + + try { valuetest(k); throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {} + + if (pointertest(k) !is null) + throw new Exception("return was not null"); + + try { reftest(k); throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {} + } + + // $owner + { + auto k = pointerownertest(); + char[] val = k.getValue(); + verifyValue("pointerownertest", val); + verifyCount(1, k); + } + { + auto k = smartpointerpointerownertest(); + char[] val = k.getValue(); + verifyValue("smartpointerpointerownertest", val); + verifyCount(1, k); + } + + ////////////////////////////////// Derived classes //////////////////////////////////////// + // derived pass by shared_ptr + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedsmartptrtest(k); + char[] val = kret.getValue(); + verifyValue("me oh my derivedsmartptrtest-Derived", val); + verifyCount(4, k); // includes two extra references for upcasts in the proxy classes + verifyCount(4, kret); + } + // derived pass by shared_ptr pointer + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedsmartptrpointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my derivedsmartptrpointertest-Derived", val); + verifyCount(4, k); // includes two extra references for upcasts in the proxy classes + verifyCount(4, kret); + } + // derived pass by shared_ptr ref + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedsmartptrreftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my derivedsmartptrreftest-Derived", val); + verifyCount(4, k); // includes two extra references for upcasts in the proxy classes + verifyCount(4, kret); + } + // derived pass by shared_ptr pointer ref + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedsmartptrpointerreftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val); + verifyCount(4, k); // includes two extra references for upcasts in the proxy classes + verifyCount(4, kret); + } + // derived pass by pointer + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedpointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my derivedpointertest-Derived", val); + verifyCount(2, k); // includes an extra reference for the upcast in the proxy class + verifyCount(2, kret); + } + // derived pass by ref + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedreftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my derivedreftest-Derived", val); + verifyCount(2, k); // includes an extra reference for the upcast in the proxy class + verifyCount(2, kret); + } + + ////////////////////////////////// Derived and base class mixed //////////////////////////////////////// + // pass by shared_ptr (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = smartpointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my smartpointertest-Derived", val); + verifyCount(3, k); // an extra reference for the upcast in the proxy class + verifyCount(3, kret); + } + + // pass by shared_ptr pointer (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = smartpointerpointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my smartpointerpointertest-Derived", val); + verifyCount(3, k); // an extra reference for the upcast in the proxy class + verifyCount(3, kret); + } + + // pass by shared_ptr reference (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = smartpointerreftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my smartpointerreftest-Derived", val); + verifyCount(3, k); // an extra reference for the upcast in the proxy class + verifyCount(3, kret); + } + + // pass by shared_ptr pointer reference (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = smartpointerpointerreftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my smartpointerpointerreftest-Derived", val); + verifyCount(3, k); // an extra reference for the upcast in the proxy class + verifyCount(3, kret); + } + + // pass by value (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = valuetest(k); + char[] val = kret.getValue(); + verifyValue("me oh my valuetest", val); // note slicing + verifyCount(2, k); // an extra reference for the upcast in the proxy class + verifyCount(1, kret); + } + + // pass by pointer (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = pointertest(k); + char[] val = kret.getValue(); + verifyValue("me oh my pointertest-Derived", val); + verifyCount(2, k); // an extra reference for the upcast in the proxy class + verifyCount(1, kret); + } + + // pass by ref (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = reftest(k); + char[] val = kret.getValue(); + verifyValue("me oh my reftest-Derived", val); + verifyCount(2, k); // an extra reference for the upcast in the proxy class + verifyCount(1, kret); + } + + // 3rd derived class + { + auto k = new Klass3rdDerived("me oh my"); + char[] val = k.getValue(); + verifyValue("me oh my-3rdDerived", val); + verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values + val = test3rdupcast(k); + verifyValue("me oh my-3rdDerived", val); + verifyCount(3, k); + } + + ////////////////////////////////// Member variables //////////////////////////////////////// + // smart pointer by value + { + auto m = new MemberVariables(); + auto k = new Klass("smart member value"); + m.SmartMemberValue = k; + char[] val = k.getValue(); + verifyValue("smart member value", val); + verifyCount(2, k); + + auto kmember = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member value", val); + verifyCount(3, kmember); + verifyCount(3, k); + + delete m; + + verifyCount(2, kmember); + verifyCount(2, k); + } + // smart pointer by pointer + { + auto m = new MemberVariables(); + auto k = new Klass("smart member pointer"); + m.SmartMemberPointer = k; + char[] val = k.getValue(); + verifyValue("smart member pointer", val); + verifyCount(1, k); + + auto kmember = m.SmartMemberPointer; + val = kmember.getValue(); + verifyValue("smart member pointer", val); + verifyCount(2, kmember); + verifyCount(2, k); + + delete m; + + verifyCount(2, kmember); + verifyCount(2, k); + } + // smart pointer by reference + { + auto m = new MemberVariables(); + auto k = new Klass("smart member reference"); + m.SmartMemberReference = k; + char[] val = k.getValue(); + verifyValue("smart member reference", val); + verifyCount(2, k); + + auto kmember = m.SmartMemberReference; + val = kmember.getValue(); + verifyValue("smart member reference", val); + verifyCount(3, kmember); + verifyCount(3, k); + + // The C++ reference refers to SmartMemberValue... + auto kmemberVal = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member reference", val); + verifyCount(4, kmemberVal); + verifyCount(4, kmember); + verifyCount(4, k); + + delete m; + + verifyCount(3, kmember); + verifyCount(3, k); + } + // plain by value + { + auto m = new MemberVariables(); + auto k = new Klass("plain member value"); + m.MemberValue = k; + char[] val = k.getValue(); + verifyValue("plain member value", val); + verifyCount(1, k); + + auto kmember = m.MemberValue; + val = kmember.getValue(); + verifyValue("plain member value", val); + verifyCount(1, kmember); + verifyCount(1, k); + + delete m; + + verifyCount(1, kmember); + verifyCount(1, k); + } + // plain by pointer + { + auto m = new MemberVariables(); + auto k = new Klass("plain member pointer"); + m.MemberPointer = k; + char[] val = k.getValue(); + verifyValue("plain member pointer", val); + verifyCount(1, k); + + auto kmember = m.MemberPointer; + val = kmember.getValue(); + verifyValue("plain member pointer", val); + verifyCount(1, kmember); + verifyCount(1, k); + + delete m; + + verifyCount(1, kmember); + verifyCount(1, k); + } + // plain by reference + { + auto m = new MemberVariables(); + auto k = new Klass("plain member reference"); + m.MemberReference = k; + char[] val = k.getValue(); + verifyValue("plain member reference", val); + verifyCount(1, k); + + auto kmember = m.MemberReference; + val = kmember.getValue(); + verifyValue("plain member reference", val); + verifyCount(1, kmember); + verifyCount(1, k); + + delete m; + + verifyCount(1, kmember); + verifyCount(1, k); + } + + // null member variables + { + auto m = new MemberVariables(); + + // shared_ptr by value + auto k = m.SmartMemberValue; + if (k !is null) + throw new Exception("expected null"); + m.SmartMemberValue = null; + k = m.SmartMemberValue; + if (k !is null) + throw new Exception("expected null"); + verifyCount(0, k); + + // plain by value + try { m.MemberValue = null; throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {} + } + + ////////////////////////////////// Global variables //////////////////////////////////////// + // smart pointer + { + auto kglobal = GlobalSmartValue; + if (kglobal !is null) + throw new Exception("expected null"); + + auto k = new Klass("smart global value"); + GlobalSmartValue = k; + verifyCount(2, k); + + kglobal = GlobalSmartValue; + char[] val = kglobal.getValue(); + verifyValue("smart global value", val); + verifyCount(3, kglobal); + verifyCount(3, k); + verifyValue("smart global value", GlobalSmartValue.getValue()); + GlobalSmartValue = null; + } + // plain value + { + Klass kglobal; + + auto k = new Klass("global value"); + GlobalValue = k; + verifyCount(1, k); + + kglobal = GlobalValue; + char[] val = kglobal.getValue(); + verifyValue("global value", val); + verifyCount(1, kglobal); + verifyCount(1, k); + verifyValue("global value", GlobalValue.getValue()); + + try { GlobalValue = null; throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {} + } + // plain pointer + { + auto kglobal = GlobalPointer; + if (kglobal !is null) + throw new Exception("expected null"); + + auto k = new Klass("global pointer"); + GlobalPointer = k; + verifyCount(1, k); + + kglobal = GlobalPointer; + char[] val = kglobal.getValue(); + verifyValue("global pointer", val); + verifyCount(1, kglobal); + verifyCount(1, k); + GlobalPointer = null; + } + // plain reference + { + Klass kglobal; + + auto k = new Klass("global reference"); + GlobalReference = k; + verifyCount(1, k); + + kglobal = GlobalReference; + char[] val = kglobal.getValue(); + verifyValue("global reference", val); + verifyCount(1, kglobal); + verifyCount(1, k); + + try { GlobalReference = null; throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {} + } + + ////////////////////////////////// Templates //////////////////////////////////////// + { + PairIntDouble pid = new PairIntDouble(10, 20.2); + if (pid.baseVal1 != 20 || pid.baseVal2 != 40.4) + throw new Exception("Base values wrong"); + if (pid.val1 != 10 || pid.val2 != 20.2) + throw new Exception("Derived Values wrong"); + } +} + +private void verifyValue(char[] expected, char[] got) { + if (expected != got) + throw new Exception("verify value failed. Expected: " ~ expected ~ " Got: " ~ got); +} + +private void verifyCount(int expected, Klass k) { + // We deliberately call the use_count(Klass) overload also for objects which + // are instances of a subclass of Klass (due to static dispatch); things still + // have to work. + int got = use_count(k); + if (expected != got) + throw new Exception("verify use_count failed. Expected: " ~ toString(expected) ~ " Got: " ~ toString(got)); +} diff --git a/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d b/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d new file mode 100644 index 000000000..773ae74d5 --- /dev/null +++ b/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d @@ -0,0 +1,602 @@ +module li_boost_shared_ptr_runme; + +import core.memory; +import core.thread; +import std.conv; +import std.exception; +import std.stdio; +import li_boost_shared_ptr.li_boost_shared_ptr; +import li_boost_shared_ptr.Klass; +import li_boost_shared_ptr.KlassDerived; +import li_boost_shared_ptr.Klass3rdDerived; +import li_boost_shared_ptr.MemberVariables; +import li_boost_shared_ptr.PairIntDouble; + +// Debugging flag +enum TRACE = false; + +void main() { + if (TRACE) + writeln("---> STARTED <---"); + + debug_shared = TRACE; + + // Change loop count to run for a long time to monitor memory + enum LOOP_COUNT = 1; // 50000; + for (int i = 0; i < LOOP_COUNT; ++i) { + runTest(); + GC.collect(); + } + + if (TRACE) + writeln("---> NEARLY FINISHED <---"); + + // Try to get the GC to collect everything not referenced anymore. + int countdown = 100; + while (--countdown) { + GC.collect(); + if (Klass.getTotal_count() == 1) + break; + Thread.sleep(100); + } + + // A single remaining instance expected: the global variable (GlobalValue). + if (Klass.getTotal_count() != 1) + throw new Exception("Klass.total_count=" ~ to!string(Klass.getTotal_count())); + + // A single remaining instance expected: the global variable (GlobalSmartValue). + int wrapper_count = shared_ptr_wrapper_count(); + if (wrapper_count != NOT_COUNTING) + if (wrapper_count != 1) + throw new Exception("shared_ptr wrapper count=" ~ to!string(wrapper_count)); + + if (TRACE) + writeln("---> FINISHED <---"); +} + +void runTest() { + // simple shared_ptr usage - created in C++ + { + auto k = new Klass("me oh my"); + string val = k.getValue(); + verifyValue("me oh my", val); + verifyCount(1, k); + } + + // simple shared_ptr usage - not created in C++ + { + auto k = factorycreate(); + string val = k.getValue(); + verifyValue("factorycreate", val); + verifyCount(1, k); + } + + // pass by shared_ptr + { + auto k = new Klass("me oh my"); + auto kret = smartpointertest(k); + string val = kret.getValue(); + verifyValue("me oh my smartpointertest", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // pass by shared_ptr pointer + { + auto k = new Klass("me oh my"); + auto kret = smartpointerpointertest(k); + string val = kret.getValue(); + verifyValue("me oh my smartpointerpointertest", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // pass by shared_ptr reference + { + auto k = new Klass("me oh my"); + auto kret = smartpointerreftest(k); + string val = kret.getValue(); + verifyValue("me oh my smartpointerreftest", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // pass by shared_ptr pointer reference + { + auto k = new Klass("me oh my"); + auto kret = smartpointerpointerreftest(k); + string val = kret.getValue(); + verifyValue("me oh my smartpointerpointerreftest", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // const pass by shared_ptr + { + auto k = new Klass("me oh my"); + auto kret = constsmartpointertest(k); + string val = kret.getValue(); + verifyValue("me oh my", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // const pass by shared_ptr pointer + { + auto k = new Klass("me oh my"); + auto kret = constsmartpointerpointertest(k); + string val = kret.getValue(); + verifyValue("me oh my", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // const pass by shared_ptr reference + { + auto k = new Klass("me oh my"); + auto kret = constsmartpointerreftest(k); + string val = kret.getValue(); + verifyValue("me oh my", val); + verifyCount(2, k); + verifyCount(2, kret); + } + + // pass by value + { + auto k = new Klass("me oh my"); + auto kret = valuetest(k); + string val = kret.getValue(); + verifyValue("me oh my valuetest", val); + verifyCount(1, k); + verifyCount(1, kret); + } + + // pass by pointer + { + auto k = new Klass("me oh my"); + auto kret = pointertest(k); + string val = kret.getValue(); + verifyValue("me oh my pointertest", val); + verifyCount(1, k); + verifyCount(1, kret); + } + + // pass by reference + { + auto k = new Klass("me oh my"); + auto kret = reftest(k); + string val = kret.getValue(); + verifyValue("me oh my reftest", val); + verifyCount(1, k); + verifyCount(1, kret); + } + + // pass by pointer reference + { + auto k = new Klass("me oh my"); + auto kret = pointerreftest(k); + string val = kret.getValue(); + verifyValue("me oh my pointerreftest", val); + verifyCount(1, k); + verifyCount(1, kret); + } + + // null tests + { + Klass k = null; + + // TODO: add in const versions too + enforce(smartpointertest(k) is null, "return was not null"); + enforce(smartpointerpointertest(k) is null, "return was not null"); + enforce(smartpointerreftest(k) is null, "return was not null"); + enforce(smartpointerpointerreftest(k) is null, "return was not null"); + enforce(nullsmartpointerpointertest(null) == "null pointer", + "not null smartpointer pointer"); + + enforceThrows( (){ valuetest(k); }, "Failed to catch null pointer"); + enforce(pointertest(k) is null, "return was not null"); + enforceThrows( (){ reftest(k); }, "Failed to catch null pointer"); + } + + // $owner + { + auto k = pointerownertest(); + string val = k.getValue(); + verifyValue("pointerownertest", val); + verifyCount(1, k); + } + { + auto k = smartpointerpointerownertest(); + string val = k.getValue(); + verifyValue("smartpointerpointerownertest", val); + verifyCount(1, k); + } + + ////////////////////////////////// Derived classes //////////////////////////////////////// + // derived pass by shared_ptr + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedsmartptrtest(k); + string val = kret.getValue(); + verifyValue("me oh my derivedsmartptrtest-Derived", val); + verifyCount(4, k); // includes two extra references for upcasts in the proxy classes + verifyCount(4, kret); + } + // derived pass by shared_ptr pointer + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedsmartptrpointertest(k); + string val = kret.getValue(); + verifyValue("me oh my derivedsmartptrpointertest-Derived", val); + verifyCount(4, k); // includes two extra references for upcasts in the proxy classes + verifyCount(4, kret); + } + // derived pass by shared_ptr ref + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedsmartptrreftest(k); + string val = kret.getValue(); + verifyValue("me oh my derivedsmartptrreftest-Derived", val); + verifyCount(4, k); // includes two extra references for upcasts in the proxy classes + verifyCount(4, kret); + } + // derived pass by shared_ptr pointer ref + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedsmartptrpointerreftest(k); + string val = kret.getValue(); + verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val); + verifyCount(4, k); // includes two extra references for upcasts in the proxy classes + verifyCount(4, kret); + } + // derived pass by pointer + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedpointertest(k); + string val = kret.getValue(); + verifyValue("me oh my derivedpointertest-Derived", val); + verifyCount(2, k); // includes an extra reference for the upcast in the proxy class + verifyCount(2, kret); + } + // derived pass by ref + { + auto k = new KlassDerived("me oh my"); + auto kret = derivedreftest(k); + string val = kret.getValue(); + verifyValue("me oh my derivedreftest-Derived", val); + verifyCount(2, k); // includes an extra reference for the upcast in the proxy class + verifyCount(2, kret); + } + + ////////////////////////////////// Derived and base class mixed //////////////////////////////////////// + // pass by shared_ptr (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = smartpointertest(k); + string val = kret.getValue(); + verifyValue("me oh my smartpointertest-Derived", val); + verifyCount(3, k); // an extra reference for the upcast in the proxy class + verifyCount(3, kret); + } + + // pass by shared_ptr pointer (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = smartpointerpointertest(k); + string val = kret.getValue(); + verifyValue("me oh my smartpointerpointertest-Derived", val); + verifyCount(3, k); // an extra reference for the upcast in the proxy class + verifyCount(3, kret); + } + + // pass by shared_ptr reference (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = smartpointerreftest(k); + string val = kret.getValue(); + verifyValue("me oh my smartpointerreftest-Derived", val); + verifyCount(3, k); // an extra reference for the upcast in the proxy class + verifyCount(3, kret); + } + + // pass by shared_ptr pointer reference (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = smartpointerpointerreftest(k); + string val = kret.getValue(); + verifyValue("me oh my smartpointerpointerreftest-Derived", val); + verifyCount(3, k); // an extra reference for the upcast in the proxy class + verifyCount(3, kret); + } + + // pass by value (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = valuetest(k); + string val = kret.getValue(); + verifyValue("me oh my valuetest", val); // note slicing + verifyCount(2, k); // an extra reference for the upcast in the proxy class + verifyCount(1, kret); + } + + // pass by pointer (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = pointertest(k); + string val = kret.getValue(); + verifyValue("me oh my pointertest-Derived", val); + verifyCount(2, k); // an extra reference for the upcast in the proxy class + verifyCount(1, kret); + } + + // pass by ref (mixed) + { + auto k = new KlassDerived("me oh my"); + auto kret = reftest(k); + string val = kret.getValue(); + verifyValue("me oh my reftest-Derived", val); + verifyCount(2, k); // an extra reference for the upcast in the proxy class + verifyCount(1, kret); + } + + // 3rd derived class + { + auto k = new Klass3rdDerived("me oh my"); + string val = k.getValue(); + verifyValue("me oh my-3rdDerived", val); + verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values + val = test3rdupcast(k); + verifyValue("me oh my-3rdDerived", val); + verifyCount(3, k); + } + + ////////////////////////////////// Member variables //////////////////////////////////////// + // smart pointer by value + { + auto m = new MemberVariables(); + auto k = new Klass("smart member value"); + m.SmartMemberValue = k; + string val = k.getValue(); + verifyValue("smart member value", val); + verifyCount(2, k); + + auto kmember = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member value", val); + verifyCount(3, kmember); + verifyCount(3, k); + + delete m; + + verifyCount(2, kmember); + verifyCount(2, k); + } + // smart pointer by pointer + { + auto m = new MemberVariables(); + auto k = new Klass("smart member pointer"); + m.SmartMemberPointer = k; + string val = k.getValue(); + verifyValue("smart member pointer", val); + verifyCount(1, k); + + auto kmember = m.SmartMemberPointer; + val = kmember.getValue(); + verifyValue("smart member pointer", val); + verifyCount(2, kmember); + verifyCount(2, k); + + delete m; + + verifyCount(2, kmember); + verifyCount(2, k); + } + // smart pointer by reference + { + auto m = new MemberVariables(); + auto k = new Klass("smart member reference"); + m.SmartMemberReference = k; + string val = k.getValue(); + verifyValue("smart member reference", val); + verifyCount(2, k); + + auto kmember = m.SmartMemberReference; + val = kmember.getValue(); + verifyValue("smart member reference", val); + verifyCount(3, kmember); + verifyCount(3, k); + + // The C++ reference refers to SmartMemberValue... + auto kmemberVal = m.SmartMemberValue; + val = kmember.getValue(); + verifyValue("smart member reference", val); + verifyCount(4, kmemberVal); + verifyCount(4, kmember); + verifyCount(4, k); + + delete m; + + verifyCount(3, kmember); + verifyCount(3, k); + } + // plain by value + { + auto m = new MemberVariables(); + auto k = new Klass("plain member value"); + m.MemberValue = k; + string val = k.getValue(); + verifyValue("plain member value", val); + verifyCount(1, k); + + auto kmember = m.MemberValue; + val = kmember.getValue(); + verifyValue("plain member value", val); + verifyCount(1, kmember); + verifyCount(1, k); + + delete m; + + verifyCount(1, kmember); + verifyCount(1, k); + } + // plain by pointer + { + auto m = new MemberVariables(); + auto k = new Klass("plain member pointer"); + m.MemberPointer = k; + string val = k.getValue(); + verifyValue("plain member pointer", val); + verifyCount(1, k); + + auto kmember = m.MemberPointer; + val = kmember.getValue(); + verifyValue("plain member pointer", val); + verifyCount(1, kmember); + verifyCount(1, k); + + delete m; + + verifyCount(1, kmember); + verifyCount(1, k); + } + // plain by reference + { + auto m = new MemberVariables(); + auto k = new Klass("plain member reference"); + m.MemberReference = k; + string val = k.getValue(); + verifyValue("plain member reference", val); + verifyCount(1, k); + + auto kmember = m.MemberReference; + val = kmember.getValue(); + verifyValue("plain member reference", val); + verifyCount(1, kmember); + verifyCount(1, k); + + delete m; + + verifyCount(1, kmember); + verifyCount(1, k); + } + + // null member variables + { + auto m = new MemberVariables(); + + // shared_ptr by value + auto k = m.SmartMemberValue; + if (k !is null) + throw new Exception("expected null"); + m.SmartMemberValue = null; + k = m.SmartMemberValue; + if (k !is null) + throw new Exception("expected null"); + verifyCount(0, k); + + // plain by value + enforceThrows( (){ m.MemberValue = null; }, "Failed to catch null pointer"); + } + + ////////////////////////////////// Global variables //////////////////////////////////////// + // smart pointer + { + auto kglobal = GlobalSmartValue; + enforce(kglobal is null, "expected null"); + + auto k = new Klass("smart global value"); + GlobalSmartValue = k; + verifyCount(2, k); + + kglobal = GlobalSmartValue; + string val = kglobal.getValue(); + verifyValue("smart global value", val); + verifyCount(3, kglobal); + verifyCount(3, k); + verifyValue("smart global value", GlobalSmartValue.getValue()); + GlobalSmartValue = null; + } + // plain value + { + Klass kglobal; + + auto k = new Klass("global value"); + GlobalValue = k; + verifyCount(1, k); + + kglobal = GlobalValue; + string val = kglobal.getValue(); + verifyValue("global value", val); + verifyCount(1, kglobal); + verifyCount(1, k); + verifyValue("global value", GlobalValue.getValue()); + + enforceThrows((){ GlobalValue = null; }, "Failed to catch null pointer"); + } + // plain pointer + { + auto kglobal = GlobalPointer; + enforce(kglobal is null, "expected null"); + + auto k = new Klass("global pointer"); + GlobalPointer = k; + verifyCount(1, k); + + kglobal = GlobalPointer; + string val = kglobal.getValue(); + verifyValue("global pointer", val); + verifyCount(1, kglobal); + verifyCount(1, k); + GlobalPointer = null; + } + // plain reference + { + Klass kglobal; + + auto k = new Klass("global reference"); + GlobalReference = k; + verifyCount(1, k); + + kglobal = GlobalReference; + string val = kglobal.getValue(); + verifyValue("global reference", val); + verifyCount(1, kglobal); + verifyCount(1, k); + + enforceThrows((){ GlobalReference = null; }, "Failed to catch null pointer"); + } + + ////////////////////////////////// Templates //////////////////////////////////////// + { + auto pid = new PairIntDouble(10, 20.2); + enforce(pid.baseVal1 == 20 && pid.baseVal2== 40.4, "Base values wrong"); + enforce(pid.val1 == 10 && pid.val2 == 20.2, "Derived Values wrong"); + } +} + +private void verifyValue(string expected, string got) { + if (expected != got) + throw new Exception("verify value failed. Expected: " ~ expected ~ " Got: " ~ got); +} + +private void verifyCount(int expected, Klass k) { + // We deliberately call the use_count(Klass) overload also for objects which + // are instances of a subclass of Klass (due to static dispatch); things still + // have to work. + int got = use_count(k); + if (expected != got) + throw new Exception("verify use_count failed. Expected: " ~ to!string(expected) ~ " Got: " ~ to!string(got)); +} + +private void enforceThrows(void delegate() dg, string errorMessage) { + bool hasThrown; + try { + dg(); + } catch (Exception) { + hasThrown = true; + } finally { + if (!hasThrown) { + throw new Exception(errorMessage); + } + } +} diff --git a/Examples/test-suite/d/li_std_except_runme.1.d b/Examples/test-suite/d/li_std_except_runme.1.d new file mode 100644 index 000000000..39f3bb202 --- /dev/null +++ b/Examples/test-suite/d/li_std_except_runme.1.d @@ -0,0 +1,40 @@ +module li_std_except_runme; + +import tango.core.Exception; +import tango.io.Console; +import li_std_except.Test; + +void main() { + with (new Test()) { + mixin(test("Exception", "throw_bad_exception")); + mixin(test("Exception", "throw_domain_error")); + mixin(test("Exception", "throw_exception")); + mixin(test("IllegalArgumentException", "throw_invalid_argument")); + mixin(test("NoSuchElementException", "throw_length_error")); + mixin(test("Exception", "throw_logic_error")); + mixin(test("NoSuchElementException", "throw_out_of_range")); + mixin(test("Exception", "throw_overflow_error")); + mixin(test("Exception", "throw_range_error")); + mixin(test("Exception", "throw_runtime_error")); + mixin(test("Exception", "throw_underflow_error")); + } +} + +char[] test(char[] e, char[] f) { + return "if (!works!(" ~ e ~ ")(&" ~ f ~ ")) {\n" ~ + "throw new Exception(\"" ~ f ~ " failed\");\n" ~ + "}"; +} + +bool works(alias E, F)(F f) { + try { + try { + f(); + } catch(E) { + return true; + } + } catch(Exception e) { + Cerr( "Received wrong exception: " ~ e.classinfo.name ).newline; + } + return false; +} diff --git a/Examples/test-suite/d/li_std_except_runme.2.d b/Examples/test-suite/d/li_std_except_runme.2.d new file mode 100644 index 000000000..f2b4b672c --- /dev/null +++ b/Examples/test-suite/d/li_std_except_runme.2.d @@ -0,0 +1,34 @@ +module li_std_except_runme; + +import std.exception; +import std.stdio; +import li_std_except.Test; + +void main() { + with (new Test()) { + enforce(works!(Exception)(&throw_bad_exception)); + enforce(works!(Exception)(&throw_domain_error)); + enforce(works!(Exception)(&throw_exception)); + enforce(works!(Exception)(&throw_invalid_argument)); + enforce(works!(Exception)(&throw_length_error)); + enforce(works!(Exception)(&throw_logic_error)); + enforce(works!(Exception)(&throw_out_of_range)); + enforce(works!(Exception)(&throw_overflow_error)); + enforce(works!(Exception)(&throw_range_error)); + enforce(works!(Exception)(&throw_runtime_error)); + enforce(works!(Exception)(&throw_underflow_error)); + } +} + +bool works(alias E, F)(F f) { + try { + try { + f(); + } catch(E) { + return true; + } + } catch(Exception e) { + writefln( "Received wrong exception: %s", e.classinfo.name ); + } + return false; +} diff --git a/Examples/test-suite/d/li_std_string_runme.1.d b/Examples/test-suite/d/li_std_string_runme.1.d new file mode 100644 index 000000000..b5bbb51c0 --- /dev/null +++ b/Examples/test-suite/d/li_std_string_runme.1.d @@ -0,0 +1,97 @@ +module li_std_string_runme; + +import tango.core.Exception; +import li_std_string.li_std_string; +import li_std_string.Structure; +import li_std_string.SWIGTYPE_p_std__string; + + +void main() { + // Checking expected use of %typemap(in) std::string {} + test_value("Fee"); + + // Checking expected result of %typemap(out) std::string {} + if (test_value("Fi") != "Fi") + throw new Exception("Test 1 failed"); + + // Verify type-checking for %typemap(in) std::string {} + try { + test_value(null); + throw new Exception("Test 2 failed"); + } catch (IllegalArgumentException) { + } + + // Checking expected use of %typemap(in) const std::string & {} + test_const_reference("Fo"); + + // Checking expected result of %typemap(out) const std::string& {} + if (test_const_reference("Fum") != "Fum") + throw new Exception("Test 3 failed"); + + // Verify type-checking for %typemap(in) const std::string & {} + try { + test_const_reference(null); + throw new Exception("Test 4 failed"); + } catch (IllegalArgumentException) { + } + + // Input and output typemaps for pointers and non-const references to + // std::string are *not* supported; the following tests confirm + // that none of these cases are slipping through. + + SWIGTYPE_p_std__string stringPtr = null; + + stringPtr = test_pointer_out(); + test_pointer(stringPtr); + + stringPtr = test_const_pointer_out(); + test_const_pointer(stringPtr); + + stringPtr = test_reference_out(); + test_reference(stringPtr); + + // Check throw exception specification + try { + test_throw(); + throw new Exception("test 5 failed!"); + } catch (Exception e) { + if (e.msg != "test_throw message") + throw new Exception("Test 5 string check: " ~ e.msg); + } + try { + test_const_reference_throw(); + throw new Exception("test 6 failed!"); + } catch (Exception e) { + if (e.msg != "test_const_reference_throw message") + throw new Exception("Test 6 string check: " ~ e.msg); + } + + // Global variables. + const char[] s = "initial string"; + if (GlobalString2 != "global string 2") + throw new Exception("GlobalString2 test 1"); + GlobalString2 = s; + if (GlobalString2 != s) + throw new Exception("GlobalString2 test 2"); + if (ConstGlobalString != "const global string") + throw new Exception("ConstGlobalString test"); + + // Member variables. + auto myStructure = new Structure(); + if (myStructure.MemberString2 != "member string 2") + throw new Exception("MemberString2 test 1"); + myStructure.MemberString2 = s; + if (myStructure.MemberString2 != s) + throw new Exception("MemberString2 test 2"); + if (myStructure.ConstMemberString != "const member string") + throw new Exception("ConstMemberString test"); + + // Static member variables. + if (Structure.StaticMemberString2 != "static member string 2") + throw new Exception("StaticMemberString2 test 1"); + Structure.StaticMemberString2 = s; + if (Structure.StaticMemberString2 != s) + throw new Exception("StaticMemberString2 test 2"); + if (Structure.ConstStaticMemberString != "const static member string") + throw new Exception("ConstStaticMemberString test"); +} diff --git a/Examples/test-suite/d/li_std_string_runme.2.d b/Examples/test-suite/d/li_std_string_runme.2.d new file mode 100644 index 000000000..395c2f7ff --- /dev/null +++ b/Examples/test-suite/d/li_std_string_runme.2.d @@ -0,0 +1,86 @@ +module li_std_string_runme; + +import std.exception; +import li_std_string.li_std_string; +import li_std_string.Structure; +import li_std_string.SWIGTYPE_p_std__string; + +void main() { + // Checking expected use of %typemap(in) std::string {} + test_value("Fee"); + + // Checking expected result of %typemap(out) std::string {} + enforce(test_value("Fi") == "Fi", "Test 1 failed"); + + // Verify type-checking for %typemap(in) std::string {} + enforceThrows( (){ test_value(null); }, "Test 2 failed."); + + // Checking expected use of %typemap(in) const std::string & {} + test_const_reference("Fo"); + + // Checking expected result of %typemap(out) const std::string& {} + enforce(test_const_reference("Fum") == "Fum", "Test 3 failed"); + + // Verify type-checking for %typemap(in) const std::string & {} + enforceThrows( (){ test_const_reference(null); }, "Test 4 failed."); + + // Input and output typemaps for pointers and non-const references to + // std::string are *not* supported; the following tests confirm + // that none of these cases are slipping through. + + SWIGTYPE_p_std__string stringPtr = null; + + stringPtr = test_pointer_out(); + test_pointer(stringPtr); + + stringPtr = test_const_pointer_out(); + test_const_pointer(stringPtr); + + stringPtr = test_reference_out(); + test_reference(stringPtr); + + // Check throw exception specification + try { + test_throw(); + throw new Exception("test 5 failed!"); + } catch (Exception e) { + enforce(e.msg == "test_throw message", "Test 5 string check: " ~ e.msg); + } + try { + test_const_reference_throw(); + throw new Exception("test 6 failed!"); + } catch (Exception e) { + enforce(e.msg == "test_const_reference_throw message", "Test 6 string check: " ~ e.msg); + } + + // Global variables. + const string s = "initial string"; + enforce(GlobalString2 == "global string 2", "GlobalString2 test 1"); + GlobalString2 = s; + enforce(GlobalString2 == s, "GlobalString2 test 2"); + enforce(ConstGlobalString == "const global string", "ConstGlobalString test"); + + // Member variables. + auto myStructure = new Structure(); + enforce(myStructure.MemberString2 == "member string 2", "MemberString2 test 1"); + myStructure.MemberString2 = s; + enforce(myStructure.MemberString2 == s, "MemberString2 test 2"); + enforce(myStructure.ConstMemberString == "const member string", "ConstMemberString test"); + + // Static member variables. + enforce(Structure.StaticMemberString2 == "static member string 2", "StaticMemberString2 test 1"); + Structure.StaticMemberString2 = s; + enforce(Structure.StaticMemberString2 == s, "StaticMemberString2 test 2"); + enforce(Structure.ConstStaticMemberString == "const static member string", "ConstStaticMemberString test"); +} + +private void enforceThrows(void delegate() dg, string errorMessage) { + bool hasThrown; + try { + dg(); + } catch (Exception) { + hasThrown = true; + } finally { + enforce(hasThrown, errorMessage); + } +} diff --git a/Examples/test-suite/d/li_std_vector_runme.1.d b/Examples/test-suite/d/li_std_vector_runme.1.d new file mode 100644 index 000000000..895fb450f --- /dev/null +++ b/Examples/test-suite/d/li_std_vector_runme.1.d @@ -0,0 +1,219 @@ +module li_std_vector_runme; + +import tango.core.Exception; +import tango.io.Stdout; +import Integer = tango.text.convert.Integer; +import li_std_vector.li_std_vector; +import li_std_vector.DoubleVector; +import li_std_vector.IntVector; +import li_std_vector.IntPtrVector; +import li_std_vector.IntConstPtrVector; +import li_std_vector.RealVector; +import li_std_vector.Struct; +import li_std_vector.StructVector; +import li_std_vector.StructPtrVector; +import li_std_vector.StructConstPtrVector; + +const size_t SIZE = 20; + +void main() { + // Basic functionality tests. + { + auto vector = new IntVector(); + for (size_t i = 0; i < SIZE; ++i) { + vector ~= i * 10; + } + + if (vector.length != SIZE) { + throw new Exception("length test failed."); + } + + vector[0] = 200; + if (vector[0] != 200) { + throw new Exception("indexing test failed"); + } + vector[0] = 0 * 10; + + try { + vector[vector.length] = 777; + throw new Exception("out of range test failed"); + } catch (NoSuchElementException) { + } + + foreach (i, value; vector) { + if (value != (i * 10)) { + throw new Exception("foreach test failed, i: " ~ Integer.toString(i)); + } + } + + vector.clear(); + if (vector.size != 0) { + throw new Exception("clear test failed"); + } + } + + // Slice tests. + { + auto dVector = new DoubleVector(); + for (size_t i = 0; i < SIZE; ++i) { + dVector ~= i * 10.1f; + } + + double[] dArray = dVector[]; + foreach (i, value; dArray) { + if (dVector[i] != value) { + throw new Exception("slice test 1 failed, i: " ~ Integer.toString(i)); + } + } + + + auto sVector = new StructVector(); + for (size_t i = 0; i < SIZE; i++) { + sVector ~= new Struct(i / 10.0); + } + + Struct[] array = sVector[]; + + for (size_t i = 0; i < SIZE; i++) { + // Make sure that a shallow copy has been made. + void* aPtr = Struct.swigGetCPtr(array[i]); + void* vPtr = Struct.swigGetCPtr(sVector[i]); + if (aPtr != vPtr) { + throw new Exception("slice test 2 failed, i: " ~ + Integer.toString(i)); + } + } + } + + // remove() tests. + { + auto iVector = new IntVector(); + for (int i = 0; i < SIZE; i++) { + iVector ~= i; + } + + iVector.remove(iVector.length - 1); + iVector.remove(SIZE / 2); + iVector.remove(0); + + try { + iVector.remove(iVector.size); + throw new Exception("remove test failed"); + } catch (NoSuchElementException) { + } + } + + // Capacity tests. + { + auto dv = new DoubleVector(10); + if ((dv.capacity != 10) || (dv.length != 0)) { + throw new Exception("constructor setting capacity test failed"); + } + + // TODO: Is this really required (and spec'ed) behavior? + dv.capacity = 20; + if (dv.capacity != 20) { + throw new Exception("capacity test 1 failed"); + } + + dv ~= 1.11; + try { + dv.capacity = dv.length - 1; + throw new Exception("capacity test 2 failed"); + } catch (IllegalArgumentException) { + } + } + + // Test the methods being wrapped. + { + auto iv = new IntVector(); + for (int i=0; i<4; i++) { + iv ~= i; + } + + double x = average(iv); + x += average(new IntVector([1, 2, 3, 4])); + RealVector rv = half(new RealVector([10.0f, 10.5f, 11.0f, 11.5f])); + + auto dv = new DoubleVector(); + for (size_t i = 0; i < SIZE; i++) { + dv ~= i / 2.0; + } + halve_in_place(dv); + + RealVector v0 = vecreal(new RealVector()); + float flo = 123.456f; + v0 ~= flo; + flo = v0[0]; + + IntVector v1 = vecintptr(new IntVector()); + IntPtrVector v2 = vecintptr(new IntPtrVector()); + IntConstPtrVector v3 = vecintconstptr(new IntConstPtrVector()); + + v1 ~= 123; + v2.clear(); + v3.clear(); + + StructVector v4 = vecstruct(new StructVector()); + StructPtrVector v5 = vecstructptr(new StructPtrVector()); + StructConstPtrVector v6 = vecstructconstptr(new StructConstPtrVector()); + + v4 ~= new Struct(123); + v5 ~= new Struct(123); + v6 ~= new Struct(123); + } + + // Test vectors of pointers. + { + auto vector = new StructPtrVector(); + for (size_t i = 0; i < SIZE; i++) { + vector ~= new Struct(i / 10.0); + } + + Struct[] array = vector[]; + + for (size_t i = 0; i < SIZE; i++) { + // Make sure that a shallow copy has been made. + void* aPtr = Struct.swigGetCPtr(array[i]); + void* vPtr = Struct.swigGetCPtr(vector[i]); + if (aPtr != vPtr) { + throw new Exception("StructPtrVector test 1 failed, i: " ~ + Integer.toString(i)); + } + } + } + + // Test vectors of const pointers. + { + auto vector = new StructConstPtrVector(); + for (size_t i = 0; i < SIZE; i++) { + vector ~= new Struct(i / 10.0); + } + + Struct[] array = vector[]; + + for (size_t i = 0; i < SIZE; i++) { + // Make sure that a shallow copy has been made. + void* aPtr = Struct.swigGetCPtr(array[i]); + void* vPtr = Struct.swigGetCPtr(vector[i]); + if (aPtr != vPtr) { + throw new Exception("StructConstPtrVector test 1 failed, i: " ~ + Integer.toString(i)); + } + } + } + + // Test vectors destroyed via dispose(). + { + { + scope vector = new StructVector(); + vector ~= new Struct(0.0); + vector ~= new Struct(11.1); + } + { + scope vector = new DoubleVector(); + vector ~= 0.0; + vector ~= 11.1; + } + } +} diff --git a/Examples/test-suite/d/li_std_vector_runme.2.d b/Examples/test-suite/d/li_std_vector_runme.2.d new file mode 100644 index 000000000..7860ad6fc --- /dev/null +++ b/Examples/test-suite/d/li_std_vector_runme.2.d @@ -0,0 +1,207 @@ +module li_std_vector_runme; + +import std.algorithm; +import std.array; +import std.conv; +import std.exception; +import std.stdio; +import li_std_vector.li_std_vector; +import li_std_vector.DoubleVector; +import li_std_vector.IntVector; +import li_std_vector.IntPtrVector; +import li_std_vector.IntConstPtrVector; +import li_std_vector.RealVector; +import li_std_vector.Struct; +import li_std_vector.StructVector; +import li_std_vector.StructPtrVector; +import li_std_vector.StructConstPtrVector; + +const size_t SIZE = 20; + +void main() { + // Basic functionality tests. + { + auto vector = new IntVector(); + for (size_t i = 0; i < SIZE; ++i) { + vector ~= i * 10; + } + + enforce(vector.length == SIZE, "length test failed."); + + vector[0] = 200; + enforce(vector[0] == 200, "indexing test failed"); + vector[0] = 0 * 10; + + enforceThrows((){ vector[vector.length] = 777; }, "out of range test failed" ); + + foreach (i, value; vector) { + enforce(value == (i * 10), "foreach test failed, i: " ~ to!string(i)); + } + + enforce(canFind!`a == 0 * 10`(vector[]), "canFind test 1 failed"); + enforce(canFind!`a == 10 * 10`(vector[]), "canFind test 2 failed"); + enforce(canFind!`a == 19 * 10`(vector[]), "canFind test 3 failed"); + enforce(!canFind!`a == 20 * 10`(vector[]), "canFind test 4 failed"); + + foreach (i, _; vector) { + enforce(indexOf(vector[], i * 10) == i, "indexOf test failed, i: " ~ to!string(i)); + } + + enforce(indexOf(vector[], 42) == -1, "non-existant item indexOf test failed"); + + vector.clear(); + enforce(vector.length == 0, "clear test failed"); + } + + // To array conversion tests. + { + auto dVector = new DoubleVector(); + for (size_t i = 0; i < SIZE; ++i) { + dVector ~= i * 10.1f; + } + + double[] dArray = array(dVector[]); + foreach (i, value; dArray) { + enforce(dVector[i] == value, "slice test 1 failed, i: " ~ to!string(i)); + } + + + auto sVector = new StructVector(); + for (size_t i = 0; i < SIZE; i++) { + sVector ~= new Struct(i / 10.0); + } + + Struct[] sArray = array(sVector[]); + + for (size_t i = 0; i < SIZE; i++) { + // Make sure that a shallow copy has been made. + void* aPtr = Struct.swigGetCPtr(sArray[i]); + void* vPtr = Struct.swigGetCPtr(sVector[i]); + enforce(aPtr == vPtr, "slice test 2 failed, i: " ~ to!string(i)); + } + } + + // remove() tests. + { + auto iVector = new IntVector(); + for (int i = 0; i < SIZE; i++) { + iVector ~= i; + } + + iVector.remove(iVector.length - 1); + iVector.remove(SIZE / 2); + iVector.remove(0); + + enforceThrows((){ iVector.remove(iVector.length); }, "remove test failed"); + } + + // Capacity tests. + { + auto dv = new DoubleVector(10); + enforce(dv.capacity == 10, "constructor setting capacity test failed (1)"); + enforce(dv.length == 0, "constructor setting capacity test failed (1)"); + + dv.reserve(20); + enforce(dv.capacity == 20, "capacity test failed"); + } + + // Test the methods being wrapped. + { + auto iv = new IntVector(); + for (int i=0; i<4; i++) { + iv ~= i; + } + + double x = average(iv); + x += average(new IntVector([1, 2, 3, 4])); + RealVector rv = half(new RealVector([10.0f, 10.5f, 11.0f, 11.5f])); + + auto dv = new DoubleVector(); + for (size_t i = 0; i < SIZE; i++) { + dv ~= i / 2.0; + } + halve_in_place(dv); + + RealVector v0 = vecreal(new RealVector()); + float flo = 123.456f; + v0 ~= flo; + flo = v0[0]; + + IntVector v1 = vecintptr(new IntVector()); + IntPtrVector v2 = vecintptr(new IntPtrVector()); + IntConstPtrVector v3 = vecintconstptr(new IntConstPtrVector()); + + v1 ~= 123; + v2.clear(); + v3.clear(); + + StructVector v4 = vecstruct(new StructVector()); + StructPtrVector v5 = vecstructptr(new StructPtrVector()); + StructConstPtrVector v6 = vecstructconstptr(new StructConstPtrVector()); + + v4 ~= new Struct(123); + v5 ~= new Struct(123); + v6 ~= new Struct(123); + } + + // Test vectors of pointers. + { + auto vector = new StructPtrVector(); + for (size_t i = 0; i < SIZE; i++) { + vector ~= new Struct(i / 10.0); + } + + Struct[] array = array(vector[]); + + for (size_t i = 0; i < SIZE; i++) { + // Make sure that a shallow copy has been made. + void* aPtr = Struct.swigGetCPtr(array[i]); + void* vPtr = Struct.swigGetCPtr(vector[i]); + enforce(aPtr == vPtr, "StructConstPtrVector test 1 failed, i: " ~ to!string(i)); + } + } + + // Test vectors of const pointers. + { + auto vector = new StructConstPtrVector(); + for (size_t i = 0; i < SIZE; i++) { + vector ~= new Struct(i / 10.0); + } + + Struct[] array = array(vector[]); + + for (size_t i = 0; i < SIZE; i++) { + // Make sure that a shallow copy has been made. + void* aPtr = Struct.swigGetCPtr(array[i]); + void* vPtr = Struct.swigGetCPtr(vector[i]); + enforce(aPtr == vPtr, "StructConstPtrVector test 1 failed, i: " ~ to!string(i)); + } + } + + // Test vectors destroyed via scope. + { + { + scope vector = new StructVector(); + vector ~= new Struct(0.0); + vector ~= new Struct(11.1); + } + { + scope vector = new DoubleVector(); + vector ~= 0.0; + vector ~= 11.1; + } + } +} + +private void enforceThrows(void delegate() dg, string errorMessage) { + bool hasThrown; + try { + dg(); + } catch (Exception) { + hasThrown = true; + } finally { + if (!hasThrown) { + throw new Exception(errorMessage); + } + } +} diff --git a/Examples/test-suite/d/li_typemaps_runme.1.d b/Examples/test-suite/d/li_typemaps_runme.1.d new file mode 100644 index 000000000..e37b12bc2 --- /dev/null +++ b/Examples/test-suite/d/li_typemaps_runme.1.d @@ -0,0 +1,94 @@ +/// Tests correct handling of a few INPUT/OUTPUT/INOUT-typemapped functions. +module li_typemaps_runme; + +import li_typemaps.li_typemaps; + +void main() { + // Check double INPUT typemaps + if (in_double(22.22) != 22.22) raiseError("in_double"); + if (inr_double(22.22) != 22.22) raiseError("inr_double"); + + // Check double OUTPUT typemaps + { + double var = 44.44; + out_double(22.22, var); + if (var != 22.22) raiseError("out_double"); + } + { + double var = 44.44; + outr_double(22.22, var); + if (var != 22.22) raiseError("outr_double"); + } + + // Check double INOUT typemaps + { + double var = 44.44; + inout_double(var); + if (var != 44.44) raiseError("inout_double"); + } + { + double var = 44.44; + inoutr_double(var); + if (var != 44.44) raiseError("inoutr_double"); + } + + // Check unsigned long long INPUT typemaps + if (in_ulonglong(20) != 20) raiseError("in_ulonglong"); + if (inr_ulonglong(20) != 20) raiseError("inr_ulonglong"); + + // Check unsigned long long OUTPUT typemaps + { + ulong var = 40; + out_ulonglong(20, var); + if (var != 20) raiseError("out_ulonglong"); + } + { + ulong var = 40; + outr_ulonglong(20, var); + if (var != 20) raiseError("outr_ulonglong"); + } + + // Check unsigned long long INOUT typemaps + { + ulong var = 40; + inout_ulonglong(var); + if (var != 40) raiseError("inout_ulonglong"); + } + { + ulong var = 40; + inoutr_ulonglong(var); + if (var != 40) raiseError("inoutr_ulonglong"); + } + + // Check unsigned bool INPUT typemaps + if (in_bool(false) != false) raiseError("in_bool"); + if (inr_bool(false) != false) raiseError("inr_bool"); + + // Check unsigned bool OUTPUT typemaps + { + bool var = false; + out_bool(true, var); + if (var != true) raiseError("out_bool"); + } + { + bool var = false; + outr_bool(true, var); + if (var != true) raiseError("outr_bool"); + } + + // Check unsigned bool INOUT typemaps + { + bool var = false; + inout_bool(var); + if (var != false) raiseError("inout_bool"); + } + { + bool var = false; + inoutr_bool(var); + if (var != false) raiseError("inoutr_bool"); + } +} + +void raiseError(char[] funcName) { + throw new Exception("Test FAILED for function " ~ funcName); +} diff --git a/Examples/test-suite/d/li_typemaps_runme.2.d b/Examples/test-suite/d/li_typemaps_runme.2.d new file mode 100644 index 000000000..de515b0ff --- /dev/null +++ b/Examples/test-suite/d/li_typemaps_runme.2.d @@ -0,0 +1,91 @@ +/// Tests correct handling of a few INPUT/OUTPUT/INOUT-typemapped functions. +module li_typemaps_runme; + +import std.exception; +import li_typemaps.li_typemaps; + +void main() { + // Check double INPUT typemaps + enforce(in_double(22.22) == 22.22, "in_double"); + enforce(inr_double(22.22) == 22.22, "inr_double"); + + // Check double OUTPUT typemaps + { + double var = 44.44; + out_double(22.22, var); + enforce(var == 22.22, "out_double"); + } + { + double var = 44.44; + outr_double(22.22, var); + enforce(var == 22.22, "outr_double"); + } + + // Check double INOUT typemaps + { + double var = 44.44; + inout_double(var); + enforce(var == 44.44, "inout_double"); + } + { + double var = 44.44; + inoutr_double(var); + enforce(var == 44.44, "inoutr_double"); + } + + // Check unsigned long long INPUT typemaps + enforce(in_ulonglong(20) == 20, "in_ulonglong"); + enforce(inr_ulonglong(20) == 20, "inr_ulonglong"); + + // Check unsigned long long OUTPUT typemaps + { + ulong var = 40; + out_ulonglong(20, var); + enforce(var == 20, "out_ulonglong"); + } + { + ulong var = 40; + outr_ulonglong(20, var); + enforce(var == 20, "outr_ulonglong"); + } + + // Check unsigned long long INOUT typemaps + { + ulong var = 40; + inout_ulonglong(var); + enforce(var == 40, "inout_ulonglong"); + } + { + ulong var = 40; + inoutr_ulonglong(var); + enforce(var == 40, "inoutr_ulonglong"); + } + + // Check unsigned bool INPUT typemaps + enforce(in_bool(false) == false, "in_bool"); + enforce(inr_bool(false) == false, "inr_bool"); + + // Check unsigned bool OUTPUT typemaps + { + bool var = false; + out_bool(true, var); + enforce(var == true, "out_bool"); + } + { + bool var = false; + outr_bool(true, var); + enforce(var == true, "outr_bool"); + } + + // Check unsigned bool INOUT typemaps + { + bool var = false; + inout_bool(var); + enforce(var == false, "inout_bool"); + } + { + bool var = false; + inoutr_bool(var); + enforce(var == false, "inoutr_bool"); + } +} diff --git a/Examples/test-suite/d/long_long_runme.1.d b/Examples/test-suite/d/long_long_runme.1.d new file mode 100644 index 000000000..a6d5448bc --- /dev/null +++ b/Examples/test-suite/d/long_long_runme.1.d @@ -0,0 +1,35 @@ +// Checks if the long long and unsigned long long types work. +module long_long_runme; + +import Integer = tango.text.convert.Integer; +import long_long.long_long; + +void main() { + check_ll(0L); + check_ll(0x7FFFFFFFFFFFFFFFL); + check_ll(-10L); + + check_ull(0u); + check_ull(127u); + check_ull(128u); + check_ull(9223372036854775807u); //0x7FFFFFFFFFFFFFFFL + check_ull(18446744073709551615u); //0xFFFFFFFFFFFFFFFFL +} + +void check_ll(long value) { + ll = value; + long value_check = ll; + if (value != value_check) { + throw new Exception("Runtime test using long long failed: expected: " ~ + Integer.toString(value) ~ ", got: " ~ Integer.toString(value_check)); + } +} + +void check_ull(ulong value) { + ull = value; + ulong value_check = ull; + if (value != value_check) { + throw new Exception( "Runtime test using unsigned long long failed: expected: " ~ + Integer.toString(value) ~ ", ll_check=" ~ Integer.toString(value_check)); + } +} diff --git a/Examples/test-suite/d/long_long_runme.2.d b/Examples/test-suite/d/long_long_runme.2.d new file mode 100644 index 000000000..a082171b4 --- /dev/null +++ b/Examples/test-suite/d/long_long_runme.2.d @@ -0,0 +1,32 @@ +// Checks if the long long and unsigned long long types work. +module long_long_runme; + +import std.conv; +import std.exception; +import long_long.long_long; + +void main() { + check_ll(0L); + check_ll(0x7FFFFFFFFFFFFFFFL); + check_ll(-10L); + + check_ull(0u); + check_ull(127u); + check_ull(128u); + check_ull(9223372036854775807u); //0x7FFFFFFFFFFFFFFFL + check_ull(18446744073709551615u); //0xFFFFFFFFFFFFFFFFL +} + +void check_ll(long value) { + ll = value; + long value_check = ll; + enforce(value == value_check, "Runtime test using long long failed: expected: " ~ + to!string(value) ~ ", got: " ~ to!string(value_check)); +} + +void check_ull(ulong value) { + ull = value; + ulong value_check = ull; + enforce(value == value_check, "Runtime test using unsigned long long failed: expected: " ~ + to!string(value) ~ ", ll_check=" ~ to!string(value_check)); +} diff --git a/Examples/test-suite/d/member_pointer_runme.1.d b/Examples/test-suite/d/member_pointer_runme.1.d new file mode 100644 index 000000000..c1f8d33b8 --- /dev/null +++ b/Examples/test-suite/d/member_pointer_runme.1.d @@ -0,0 +1,43 @@ +module member_pointer_runme; + +import Float = tango.text.convert.Float; +import member_pointer.member_pointer; +import member_pointer.Square; +import member_pointer.SWIGTYPE_m_Shape__f_void__double; + +void main() { + auto s = new Square(10); + + // Do some calculations + auto area_pt = areapt(); + auto perim_pt = perimeterpt(); + check("Square area ", 100.0, do_op(s, area_pt)); + check("Square perim", 40.0, do_op(s, perim_pt)); + + SWIGTYPE_m_Shape__f_void__double memberPtr = null; + memberPtr = areavar; + memberPtr = perimetervar; + + // Try the variables + check("Square area ", 100.0, do_op(s, areavar)); + check("Square perim", 40.0, do_op(s, perimetervar)); + + // Modify one of the variables + areavar = perim_pt; + check("Square perimeter", 40.0, do_op(s,areavar)); + + // Try the constants + memberPtr = AREAPT; + memberPtr = PERIMPT; + memberPtr = NULLPT; + + check("Square area", 100.0, do_op(s, AREAPT)); + check("Square perim", 40.0, do_op(s, PERIMPT)); +} + +void check(char[] what, double expected, double actual) { + if (expected != actual) { + throw new Exception("Failed: " ~ what ~ ": expected " + ~ Float.toString(expected) ~ ", but got " ~ Float.toString(actual)); + } +} diff --git a/Examples/test-suite/d/member_pointer_runme.2.d b/Examples/test-suite/d/member_pointer_runme.2.d new file mode 100644 index 000000000..a5c293cd0 --- /dev/null +++ b/Examples/test-suite/d/member_pointer_runme.2.d @@ -0,0 +1,42 @@ +module member_pointer_runme; + +import std.conv; +import std.exception; +import member_pointer.member_pointer; +import member_pointer.Square; +import member_pointer.SWIGTYPE_m_Shape__f_void__double; + +void main() { + auto s = new Square(10); + + // Do some calculations + auto area_pt = areapt(); + auto perim_pt = perimeterpt(); + check("Square area", 100.0, do_op(s, area_pt)); + check("Square perim", 40.0, do_op(s, perim_pt)); + + SWIGTYPE_m_Shape__f_void__double memberPtr = null; + memberPtr = areavar; + memberPtr = perimetervar; + + // Try the variables + check("Square area", 100.0, do_op(s, areavar)); + check("Square perim", 40.0, do_op(s, perimetervar)); + + // Modify one of the variables + areavar = perim_pt; + check("Square perimeter", 40.0, do_op(s,areavar)); + + // Try the constants + memberPtr = AREAPT; + memberPtr = PERIMPT; + memberPtr = NULLPT; + + check("Square area", 100.0, do_op(s, AREAPT)); + check("Square perim", 40.0, do_op(s, PERIMPT)); +} + +void check(string what, double expected, double actual) { + enforce(expected == actual, "Failed: " ~ what ~ ": expected " ~ + to!string(expected) ~ ", but got " ~ to!string(actual)); +} diff --git a/Examples/test-suite/d/operator_overload_runme.1.d b/Examples/test-suite/d/operator_overload_runme.1.d new file mode 100644 index 000000000..18a24b91f --- /dev/null +++ b/Examples/test-suite/d/operator_overload_runme.1.d @@ -0,0 +1,89 @@ +module operator_overload_runme; + +import operator_overload.Op; + +void main() { + // Invoke the C++ sanity check first. + Op.sanity_check(); + + auto a = new Op(); + auto b = new Op(5); + auto c = b; + auto d = new Op(2); + auto dd = d; + + // test equality + assert(a != b); + assert(b == c); + assert(a != d); + assert(d == dd); + + // test < + assert(a < b); + assert(a <= b); + assert(b <= c); + assert(b >= c); + assert(b > d); + assert(b >= d); + + // test += + auto e = new Op(3); + e += d; + assert(e == b); + e -= c; + assert(e == a); + e = new Op(1); + e *= b; + assert(e == c); + e /= d; + assert(e == d); + e %= c; + assert(e == d); + + // test + + auto f = new Op(1); + auto g = new Op(1); + assert(f + g == new Op(2)); + assert(f - g == new Op(0)); + assert(f * g == new Op(1)); + assert(f / g == new Op(1)); + assert(f % g == new Op(0)); + + // test unary operators + assert(-a == a); + assert(-b == new Op(-5)); + // The unary ! operator is not overloadable in D1. + + // test [] + auto h = new Op(3); + assert(h[0]==3); + assert(h[1]==0); + // Generation of opIndexAssign is not supported yet. + + // test () + auto i = new Op(3); + assert(i()==3); + assert(i(1)==4); + assert(i(1,2)==6); + + // test ++ and -- + auto j = new Op(100); + int original = j.i; + { + Op newOp = j++; + int newInt = original++; + assert(j.i == original); + assert(newOp.i == newInt); + } + { + Op newOp = j--; + int newInt = original--; + assert(j.i == original); + assert(newOp.i == newInt); + } + // Prefix increment/decrement operators are lowered to (foo +=/-= 1) in D1, + // but the test case does not define an integer overload for operator += + // respectively -=. + + // Implicit casting is not overloadable in D1. +}
\ No newline at end of file diff --git a/Examples/test-suite/d/operator_overload_runme.2.d b/Examples/test-suite/d/operator_overload_runme.2.d new file mode 100644 index 000000000..2ff61cd56 --- /dev/null +++ b/Examples/test-suite/d/operator_overload_runme.2.d @@ -0,0 +1,91 @@ +module operator_overload_runme; + +import operator_overload.Op; + +void main() { + // Invoke the C++ sanity check first. + Op.sanity_check(); + + auto a = new Op(); + auto b = new Op(5); + auto c = b; + auto d = new Op(2); + auto dd = d; + + // test equality + assert(a != b); + assert(b == c); + assert(a != d); + assert(d == dd); + + // test < + assert(a < b); + assert(a <= b); + assert(b <= c); + assert(b >= c); + assert(b > d); + assert(b >= d); + + // test += + auto e = new Op(3); + e += d; + assert(e == b); + e -= c; + assert(e == a); + e = new Op(1); + e *= b; + assert(e == c); + e /= d; + assert(e == d); + e %= c; + assert(e == d); + + // test + + auto f = new Op(1); + auto g = new Op(1); + assert(f + g == new Op(2)); + assert(f - g == new Op(0)); + assert(f * g == new Op(1)); + assert(f / g == new Op(1)); + assert(f % g == new Op(0)); + + // test unary operators + assert(-a == a); + assert(-b == new Op(-5)); + + // Unfortunaly, there is no way to override conversion to boolean for + // classes in D, opCast!("bool") is only used for structs. + + // test [] + auto h = new Op(3); + assert(h[0]==3); + assert(h[1]==0); + // Generation of opIndexAssign is not supported yet. + + // test () + auto i = new Op(3); + assert(i()==3); + assert(i(1)==4); + assert(i(1,2)==6); + + // test ++ and -- + auto j = new Op(100); + int original = j.i; + // The prefix increment/decrement operators are not directly overloadable in + // D2, and because the proxy classes are reference types, the lowering + // yields the same value as the postfix operators. + { + Op newOp = ++j; + int newInt = ++original; + assert(j.i == original); + assert(newOp.i == newInt); + } + { + Op newOp = --j; + int newInt = --original; + assert(j.i == original); + assert(newOp.i == newInt); + } + + // Implicit casting via alias this is not supported yet. +}
\ No newline at end of file diff --git a/Examples/test-suite/d/overload_complicated_runme.1.d b/Examples/test-suite/d/overload_complicated_runme.1.d new file mode 100644 index 000000000..03d1bf1e6 --- /dev/null +++ b/Examples/test-suite/d/overload_complicated_runme.1.d @@ -0,0 +1,50 @@ +module overload_complicated_runme; + +import overload_complicated; + +void main() { + SWIGTYPE_p_int pInt = null; + + // Check the correct constructors are available + Pop p = new Pop(pInt); + + p = new Pop(pInt, false); + + // Check overloaded in const only and pointers/references which target languages cannot disambiguate + if (p.hip(false) != 701) + throw new Exception("Test 1 failed"); + + if (p.hip(pInt) != 702) + throw new Exception("Test 2 failed"); + + // Reverse the order for the above + if (p.hop(pInt) != 805) + throw new Exception("Test 3 failed"); + + if (p.hop(false) != 801) + throw new Exception("Test 4 failed"); + + // Few more variations and order shuffled + if (p.pop(false) != 901) + throw new Exception("Test 5 failed"); + + if (p.pop(pInt) != 902) + throw new Exception("Test 6 failed"); + + if (p.pop() != 905) + throw new Exception("Test 7 failed"); + + // Overload on const only + if (p.bop(pInt) != 1001) + throw new Exception("Test 8 failed"); + + if (p.bip(pInt) != 2001) + throw new Exception("Test 9 failed"); + + // Globals + if (muzak(false) != 3001) + throw new Exception("Test 10 failed"); + + if (muzak(pInt) != 3002) + throw new Exception("Test 11 failed"); +} diff --git a/Examples/test-suite/d/overload_complicated_runme.2.d b/Examples/test-suite/d/overload_complicated_runme.2.d new file mode 100644 index 000000000..9d03ec5e6 --- /dev/null +++ b/Examples/test-suite/d/overload_complicated_runme.2.d @@ -0,0 +1,34 @@ +module overload_complicated_runme; + +import std.exception; +import overload_complicated.overload_complicated; +import overload_complicated.Pop; + +void main() { + int* pInt = new int; + + // Check the correct constructors are available + auto p = new Pop(pInt); + p = new Pop(pInt, false); + + // Check overloaded in const only and pointers/references which target languages cannot disambiguate + enforce(p.hip(false) == 701, "Test 1 failed"); + enforce(p.hip(pInt) == 702, "Test 2 failed"); + + // Reverse the order for the above + enforce(p.hop(pInt) == 805, "Test 3 failed"); + enforce(p.hop(false) == 801, "Test 4 failed"); + + // Few more variations and order shuffled + enforce(p.pop(false) == 901, "Test 5 failed"); + enforce(p.pop(pInt) == 902, "Test 6 failed"); + enforce(p.pop() == 905, "Test 7 failed"); + + // Overload on const only + enforce(p.bop(pInt) == 1001, "Test 8 failed"); + enforce(p.bip(pInt) == 2001, "Test 9 failed"); + + // Globals + enforce(muzak(false) == 3001, "Test 10 failed"); + enforce(muzak(pInt) == 3002, "Test 11 failed"); +} diff --git a/Examples/test-suite/d/overload_template_runme.1.d b/Examples/test-suite/d/overload_template_runme.1.d new file mode 100644 index 000000000..a1fe8012f --- /dev/null +++ b/Examples/test-suite/d/overload_template_runme.1.d @@ -0,0 +1,146 @@ +module overload_template_runme; + +import overload_template.overload_template; +import overload_template.Klass; + +void main() { + int f = foo(); + + f += maximum(3,4); + double b = maximum(3.4,5.2); + b++; // warning suppression + + // mix 1 + if (mix1("hi") != 101) + throw new Exception ("mix1(const char*)"); + + if (mix1(1.0, 1.0) != 102) + throw new Exception ("mix1(double, const double &)"); + + if (mix1(1.0) != 103) + throw new Exception ("mix1(double)"); + + // mix 2 + if (mix2("hi") != 101) + throw new Exception ("mix2(const char*)"); + + if (mix2(1.0, 1.0) != 102) + throw new Exception ("mix2(double, const double &)"); + + if (mix2(1.0) != 103) + throw new Exception ("mix2(double)"); + + // mix 3 + if (mix3("hi") != 101) + throw new Exception ("mix3(const char*)"); + + if (mix3(1.0, 1.0) != 102) + throw new Exception ("mix3(double, const double &)"); + + if (mix3(1.0) != 103) + throw new Exception ("mix3(double)"); + + // Combination 1 + if (overtparams1(100) != 10) + throw new Exception ("overtparams1(int)"); + + if (overtparams1(100.0, 100) != 20) + throw new Exception ("overtparams1(double, int)"); + + // Combination 2 + if (overtparams2(100.0, 100) != 40) + throw new Exception ("overtparams2(double, int)"); + + // Combination 3 + if (overloaded() != 60) + throw new Exception ("overloaded()"); + + if (overloaded(100.0, 100) != 70) + throw new Exception ("overloaded(double, int)"); + + // Combination 4 + if (overloadedagain("hello") != 80) + throw new Exception ("overloadedagain(const char *)"); + + if (overloadedagain() != 90) + throw new Exception ("overloadedagain(double)"); + + // specializations + if (specialization(10) != 202) + throw new Exception ("specialization(int)"); + + if (specialization(10.0) != 203) + throw new Exception ("specialization(double)"); + + if (specialization(10, 10) != 204) + throw new Exception ("specialization(int, int)"); + + if (specialization(10.0, 10.0) != 205) + throw new Exception ("specialization(double, double)"); + + if (specialization("hi", "hi") != 201) + throw new Exception ("specialization(const char *, const char *)"); + + // simple specialization + xyz(); + xyz_int(); + xyz_double(); + + // a bit of everything + if (overload("hi") != 0) + throw new Exception ("overload()"); + + if (overload(1) != 10) + throw new Exception ("overload(int t)"); + + if (overload(1, 1) != 20) + throw new Exception ("overload(int t, const int &)"); + + if (overload(1, "hello") != 30) + throw new Exception ("overload(int t, const char *)"); + + auto k = new Klass(); + if (overload(k) != 10) + throw new Exception ("overload(Klass t)"); + + if (overload(k, k) != 20) + throw new Exception ("overload(Klass t, const Klass &)"); + + if (overload(k, "hello") != 30) + throw new Exception ("overload(Klass t, const char *)"); + + if (overload(10.0, "hi") != 40) + throw new Exception ("overload(double t, const char *)"); + + if (overload() != 50) + throw new Exception ("overload(const char *)"); + + + // everything put in a namespace + if (nsoverload("hi") != 1000) + throw new Exception ("nsoverload()"); + + if (nsoverload(1) != 1010) + throw new Exception ("nsoverload(int t)"); + + if (nsoverload(1, 1) != 1020) + throw new Exception ("nsoverload(int t, const int &)"); + + if (nsoverload(1, "hello") != 1030) + throw new Exception ("nsoverload(int t, const char *)"); + + if (nsoverload(k) != 1010) + throw new Exception ("nsoverload(Klass t)"); + + if (nsoverload(k, k) != 1020) + throw new Exception ("nsoverload(Klass t, const Klass &)"); + + if (nsoverload(k, "hello") != 1030) + throw new Exception ("nsoverload(Klass t, const char *)"); + + if (nsoverload(10.0, "hi") != 1040) + throw new Exception ("nsoverload(double t, const char *)"); + + if (nsoverload() != 1050) + throw new Exception ("nsoverload(const char *)"); +} diff --git a/Examples/test-suite/d/overload_template_runme.2.d b/Examples/test-suite/d/overload_template_runme.2.d new file mode 100644 index 000000000..9fe6eb2cf --- /dev/null +++ b/Examples/test-suite/d/overload_template_runme.2.d @@ -0,0 +1,80 @@ +module overload_template_runme; + +import std.exception; +import overload_template.overload_template; +import overload_template.Klass; + +void main() { + int f = foo(); + + f += maximum(3,4); + double b = maximum(3.4,5.2); + b++; // warning suppression + + // mix 1 + enforce(mix1("hi") == 101, "mix1(const char*)"); + enforce(mix1(1.0, 1.0) == 102, "mix1(double, const double &)"); + enforce(mix1(1.0) == 103, "mix1(double)"); + + // mix 2 + enforce(mix2("hi") == 101, "mix2(const char*)"); + enforce(mix2(1.0, 1.0) == 102, "mix2(double, const double &)"); + enforce(mix2(1.0) == 103, "mix2(double)"); + + // mix 3 + enforce(mix3("hi") == 101, "mix3(const char*)"); + enforce(mix3(1.0, 1.0) == 102, "mix3(double, const double &)"); + enforce(mix3(1.0) == 103, "mix3(double)"); + + // Combination 1 + enforce(overtparams1(100) == 10, "overtparams1(int)"); + enforce(overtparams1(100.0, 100) == 20, "overtparams1(double, int)"); + + // Combination 2 + enforce(overtparams2(100.0, 100) == 40, "overtparams2(double, int)"); + + // Combination 3 + enforce(overloaded() == 60, "overloaded()"); + enforce(overloaded(100.0, 100) == 70, "overloaded(double, int)"); + + // Combination 4 + enforce(overloadedagain("hello") == 80, "overloadedagain(const char *)"); + enforce(overloadedagain() == 90, "overloadedagain(double)"); + + // specializations + enforce(specialization(10) == 202, "specialization(int)"); + enforce(specialization(10.0) == 203, "specialization(double)"); + enforce(specialization(10, 10) == 204, "specialization(int, int)"); + enforce(specialization(10.0, 10.0) == 205, "specialization(double, double)"); + enforce(specialization("hi", "hi") == 201, "specialization(const char *, const char *)"); + + // simple specialization + xyz(); + xyz_int(); + xyz_double(); + + // a bit of everything + enforce(overload("hi") == 0, "overload()"); + enforce(overload(1) == 10, "overload(int t)"); + enforce(overload(1, 1) == 20, "overload(int t, const int &)"); + enforce(overload(1, "hello") == 30, "overload(int t, const char *)"); + + auto k = new Klass(); + enforce(overload(k) == 10, "overload(Klass t)"); + enforce(overload(k, k) == 20, "overload(Klass t, const Klass &)"); + enforce(overload(k, "hello") == 30, "overload(Klass t, const char *)"); + enforce(overload(10.0, "hi") == 40, "overload(double t, const char *)"); + enforce(overload() == 50, "overload(const char *)"); + + + // everything put in a namespace + enforce(nsoverload("hi") == 1000, "nsoverload()"); + enforce(nsoverload(1) == 1010, "nsoverload(int t)"); + enforce(nsoverload(1, 1) == 1020, "nsoverload(int t, const int &)"); + enforce(nsoverload(1, "hello") == 1030, "nsoverload(int t, const char *)"); + enforce(nsoverload(k) == 1010, "nsoverload(Klass t)"); + enforce(nsoverload(k, k) == 1020, "nsoverload(Klass t, const Klass &)"); + enforce(nsoverload(k, "hello") == 1030, "nsoverload(Klass t, const char *)"); + enforce(nsoverload(10.0, "hi") == 1040, "nsoverload(double t, const char *)"); + enforce(nsoverload() == 1050, "nsoverload(const char *)"); +} diff --git a/Examples/test-suite/d/pointer_reference_runme.1.d b/Examples/test-suite/d/pointer_reference_runme.1.d new file mode 100644 index 000000000..c593b939c --- /dev/null +++ b/Examples/test-suite/d/pointer_reference_runme.1.d @@ -0,0 +1,13 @@ +module pointer_reference_runme; + +import pointer_reference.pointer_reference; +import pointer_reference.Struct; + +void main() { + Struct s = get(); + if (s.value != 10) throw new Exception("get test failed"); + + Struct ss = new Struct(20); + set(ss); + if (Struct.instance.value != 20) throw new Exception("set test failed"); +} diff --git a/Examples/test-suite/d/pointer_reference_runme.2.d b/Examples/test-suite/d/pointer_reference_runme.2.d new file mode 100644 index 000000000..8f287dfbd --- /dev/null +++ b/Examples/test-suite/d/pointer_reference_runme.2.d @@ -0,0 +1,14 @@ +module pointer_reference_runme; + +import std.exception; +import pointer_reference.pointer_reference; +import pointer_reference.Struct; + +void main() { + Struct s = get(); + enforce(s.value == 10, "get test failed"); + + auto ss = new Struct(20); + set(ss); + enforce(Struct.instance.value == 20, "set test failed"); +} diff --git a/Examples/test-suite/d/preproc_constants_c_runme.1.d b/Examples/test-suite/d/preproc_constants_c_runme.1.d new file mode 100644 index 000000000..f25bbfdee --- /dev/null +++ b/Examples/test-suite/d/preproc_constants_c_runme.1.d @@ -0,0 +1,63 @@ +module preproc_constants_c_runme; + +import preproc_constants_c.preproc_constants_c; + +// Same as preproc_constants.i testcase, but bool types are int instead. +void main() { + static assert(is(int == typeof(CONST_INT1()))); + static assert(is(int == typeof(CONST_INT2()))); + static assert(is(uint == typeof(CONST_UINT1()))); + static assert(is(uint == typeof(CONST_UINT2()))); + static assert(is(uint == typeof(CONST_UINT3()))); + static assert(is(uint == typeof(CONST_UINT4()))); + static assert(is(int == typeof(CONST_LONG1()))); + static assert(is(int == typeof(CONST_LONG2()))); + static assert(is(int == typeof(CONST_LONG3()))); + static assert(is(int == typeof(CONST_LONG4()))); + static assert(is(long == typeof(CONST_LLONG1()))); + static assert(is(long == typeof(CONST_LLONG2()))); + static assert(is(long == typeof(CONST_LLONG3()))); + static assert(is(long == typeof(CONST_LLONG4()))); + static assert(is(ulong == typeof(CONST_ULLONG1()))); + static assert(is(ulong == typeof(CONST_ULLONG2()))); + static assert(is(ulong == typeof(CONST_ULLONG3()))); + static assert(is(ulong == typeof(CONST_ULLONG4()))); + static assert(is(double == typeof(CONST_DOUBLE1()))); + static assert(is(double == typeof(CONST_DOUBLE2()))); + static assert(is(double == typeof(CONST_DOUBLE3()))); + static assert(is(double == typeof(CONST_DOUBLE4()))); + static assert(is(double == typeof(CONST_DOUBLE5()))); + static assert(is(double == typeof(CONST_DOUBLE6()))); + static assert(is(int == typeof(CONST_BOOL1()))); + static assert(is(int == typeof(CONST_BOOL2()))); + static assert(is(char == typeof(CONST_CHAR()))); + static assert(is(char[] == typeof(CONST_STRING1()))); + static assert(is(char[] == typeof(CONST_STRING2()))); + + static assert(is(int == typeof(INT_AND_BOOL()))); +// static assert(is(int == typeof(INT_AND_CHAR()))); + static assert(is(int == typeof(INT_AND_INT()))); + static assert(is(uint == typeof(INT_AND_UINT()))); + static assert(is(int == typeof(INT_AND_LONG()))); + static assert(is(uint == typeof(INT_AND_ULONG()))); + static assert(is(long == typeof(INT_AND_LLONG()))); + static assert(is(ulong == typeof(INT_AND_ULLONG()))); + static assert(is(int == typeof(BOOL_AND_BOOL()))); + + static assert(is(int == typeof(EXPR_MULTIPLY()))); + static assert(is(int == typeof(EXPR_DIVIDE()))); + static assert(is(int == typeof(EXPR_PLUS()))); + static assert(is(int == typeof(EXPR_MINUS()))); + static assert(is(int == typeof(EXPR_LSHIFT()))); + static assert(is(int == typeof(EXPR_RSHIFT()))); + static assert(is(int == typeof(EXPR_LTE()))); + static assert(is(int == typeof(EXPR_GTE()))); + static assert(is(int == typeof(EXPR_INEQUALITY()))); + static assert(is(int == typeof(EXPR_EQUALITY()))); + static assert(is(int == typeof(EXPR_AND()))); + static assert(is(int == typeof(EXPR_XOR()))); + static assert(is(int == typeof(EXPR_OR()))); + static assert(is(int == typeof(EXPR_LAND()))); + static assert(is(int == typeof(EXPR_LOR()))); + static assert(is(double == typeof(EXPR_CONDITIONAL()))); +} diff --git a/Examples/test-suite/d/preproc_constants_c_runme.2.d b/Examples/test-suite/d/preproc_constants_c_runme.2.d new file mode 100644 index 000000000..07d6ac53d --- /dev/null +++ b/Examples/test-suite/d/preproc_constants_c_runme.2.d @@ -0,0 +1,63 @@ +module preproc_constants_c_runme; + +import preproc_constants_c.preproc_constants_c; + +// Same as preproc_constants.i testcase, but bool types are int instead. +void main() { + static assert(is(int == typeof(CONST_INT1()))); + static assert(is(int == typeof(CONST_INT2()))); + static assert(is(uint == typeof(CONST_UINT1()))); + static assert(is(uint == typeof(CONST_UINT2()))); + static assert(is(uint == typeof(CONST_UINT3()))); + static assert(is(uint == typeof(CONST_UINT4()))); + static assert(is(int == typeof(CONST_LONG1()))); + static assert(is(int == typeof(CONST_LONG2()))); + static assert(is(int == typeof(CONST_LONG3()))); + static assert(is(int == typeof(CONST_LONG4()))); + static assert(is(long == typeof(CONST_LLONG1()))); + static assert(is(long == typeof(CONST_LLONG2()))); + static assert(is(long == typeof(CONST_LLONG3()))); + static assert(is(long == typeof(CONST_LLONG4()))); + static assert(is(ulong == typeof(CONST_ULLONG1()))); + static assert(is(ulong == typeof(CONST_ULLONG2()))); + static assert(is(ulong == typeof(CONST_ULLONG3()))); + static assert(is(ulong == typeof(CONST_ULLONG4()))); + static assert(is(double == typeof(CONST_DOUBLE1()))); + static assert(is(double == typeof(CONST_DOUBLE2()))); + static assert(is(double == typeof(CONST_DOUBLE3()))); + static assert(is(double == typeof(CONST_DOUBLE4()))); + static assert(is(double == typeof(CONST_DOUBLE5()))); + static assert(is(double == typeof(CONST_DOUBLE6()))); + static assert(is(int == typeof(CONST_BOOL1()))); + static assert(is(int == typeof(CONST_BOOL2()))); + static assert(is(char == typeof(CONST_CHAR()))); + static assert(is(string == typeof(CONST_STRING1()))); + static assert(is(string == typeof(CONST_STRING2()))); + + static assert(is(int == typeof(INT_AND_BOOL()))); +// static assert(is(int == typeof(INT_AND_CHAR()))); + static assert(is(int == typeof(INT_AND_INT()))); + static assert(is(uint == typeof(INT_AND_UINT()))); + static assert(is(int == typeof(INT_AND_LONG()))); + static assert(is(uint == typeof(INT_AND_ULONG()))); + static assert(is(long == typeof(INT_AND_LLONG()))); + static assert(is(ulong == typeof(INT_AND_ULLONG()))); + static assert(is(int == typeof(BOOL_AND_BOOL()))); + + static assert(is(int == typeof(EXPR_MULTIPLY()))); + static assert(is(int == typeof(EXPR_DIVIDE()))); + static assert(is(int == typeof(EXPR_PLUS()))); + static assert(is(int == typeof(EXPR_MINUS()))); + static assert(is(int == typeof(EXPR_LSHIFT()))); + static assert(is(int == typeof(EXPR_RSHIFT()))); + static assert(is(int == typeof(EXPR_LTE()))); + static assert(is(int == typeof(EXPR_GTE()))); + static assert(is(int == typeof(EXPR_INEQUALITY()))); + static assert(is(int == typeof(EXPR_EQUALITY()))); + static assert(is(int == typeof(EXPR_AND()))); + static assert(is(int == typeof(EXPR_XOR()))); + static assert(is(int == typeof(EXPR_OR()))); + static assert(is(int == typeof(EXPR_LAND()))); + static assert(is(int == typeof(EXPR_LOR()))); + static assert(is(double == typeof(EXPR_CONDITIONAL()))); +} diff --git a/Examples/test-suite/d/preproc_constants_runme.1.d b/Examples/test-suite/d/preproc_constants_runme.1.d new file mode 100644 index 000000000..a2aaa8fcd --- /dev/null +++ b/Examples/test-suite/d/preproc_constants_runme.1.d @@ -0,0 +1,62 @@ +module preproc_constants_runme; + +import preproc_constants.preproc_constants; + +void main() { + static assert(is(int == typeof(CONST_INT1()))); + static assert(is(int == typeof(CONST_INT2()))); + static assert(is(uint == typeof(CONST_UINT1()))); + static assert(is(uint == typeof(CONST_UINT2()))); + static assert(is(uint == typeof(CONST_UINT3()))); + static assert(is(uint == typeof(CONST_UINT4()))); + static assert(is(int == typeof(CONST_LONG1()))); + static assert(is(int == typeof(CONST_LONG2()))); + static assert(is(int == typeof(CONST_LONG3()))); + static assert(is(int == typeof(CONST_LONG4()))); + static assert(is(long == typeof(CONST_LLONG1()))); + static assert(is(long == typeof(CONST_LLONG2()))); + static assert(is(long == typeof(CONST_LLONG3()))); + static assert(is(long == typeof(CONST_LLONG4()))); + static assert(is(ulong == typeof(CONST_ULLONG1()))); + static assert(is(ulong == typeof(CONST_ULLONG2()))); + static assert(is(ulong == typeof(CONST_ULLONG3()))); + static assert(is(ulong == typeof(CONST_ULLONG4()))); + static assert(is(double == typeof(CONST_DOUBLE1()))); + static assert(is(double == typeof(CONST_DOUBLE2()))); + static assert(is(double == typeof(CONST_DOUBLE3()))); + static assert(is(double == typeof(CONST_DOUBLE4()))); + static assert(is(double == typeof(CONST_DOUBLE5()))); + static assert(is(double == typeof(CONST_DOUBLE6()))); + static assert(is(bool == typeof(CONST_BOOL1()))); + static assert(is(bool == typeof(CONST_BOOL2()))); + static assert(is(char == typeof(CONST_CHAR()))); + static assert(is(char[] == typeof(CONST_STRING1()))); + static assert(is(char[] == typeof(CONST_STRING2()))); + + static assert(is(int == typeof(INT_AND_BOOL()))); +// static assert(is(int == typeof(INT_AND_CHAR()))); + static assert(is(int == typeof(INT_AND_INT()))); + static assert(is(uint == typeof(INT_AND_UINT()))); + static assert(is(int == typeof(INT_AND_LONG()))); + static assert(is(uint == typeof(INT_AND_ULONG()))); + static assert(is(long == typeof(INT_AND_LLONG()))); + static assert(is(ulong == typeof(INT_AND_ULLONG()))); + static assert(is(int == typeof(BOOL_AND_BOOL()))); + + static assert(is(int == typeof(EXPR_MULTIPLY()))); + static assert(is(int == typeof(EXPR_DIVIDE()))); + static assert(is(int == typeof(EXPR_PLUS()))); + static assert(is(int == typeof(EXPR_MINUS()))); + static assert(is(int == typeof(EXPR_LSHIFT()))); + static assert(is(int == typeof(EXPR_RSHIFT()))); + static assert(is(bool == typeof(EXPR_LTE()))); + static assert(is(bool == typeof(EXPR_GTE()))); + static assert(is(bool == typeof(EXPR_INEQUALITY()))); + static assert(is(bool == typeof(EXPR_EQUALITY()))); + static assert(is(int == typeof(EXPR_AND()))); + static assert(is(int == typeof(EXPR_XOR()))); + static assert(is(int == typeof(EXPR_OR()))); + static assert(is(bool == typeof(EXPR_LAND()))); + static assert(is(bool == typeof(EXPR_LOR()))); + static assert(is(double == typeof(EXPR_CONDITIONAL()))); +} diff --git a/Examples/test-suite/d/preproc_constants_runme.2.d b/Examples/test-suite/d/preproc_constants_runme.2.d new file mode 100644 index 000000000..e2eab2c46 --- /dev/null +++ b/Examples/test-suite/d/preproc_constants_runme.2.d @@ -0,0 +1,62 @@ +module preproc_constants_runme; + +import preproc_constants.preproc_constants; + +void main() { + static assert(is(int == typeof(CONST_INT1()))); + static assert(is(int == typeof(CONST_INT2()))); + static assert(is(uint == typeof(CONST_UINT1()))); + static assert(is(uint == typeof(CONST_UINT2()))); + static assert(is(uint == typeof(CONST_UINT3()))); + static assert(is(uint == typeof(CONST_UINT4()))); + static assert(is(int == typeof(CONST_LONG1()))); + static assert(is(int == typeof(CONST_LONG2()))); + static assert(is(int == typeof(CONST_LONG3()))); + static assert(is(int == typeof(CONST_LONG4()))); + static assert(is(long == typeof(CONST_LLONG1()))); + static assert(is(long == typeof(CONST_LLONG2()))); + static assert(is(long == typeof(CONST_LLONG3()))); + static assert(is(long == typeof(CONST_LLONG4()))); + static assert(is(ulong == typeof(CONST_ULLONG1()))); + static assert(is(ulong == typeof(CONST_ULLONG2()))); + static assert(is(ulong == typeof(CONST_ULLONG3()))); + static assert(is(ulong == typeof(CONST_ULLONG4()))); + static assert(is(double == typeof(CONST_DOUBLE1()))); + static assert(is(double == typeof(CONST_DOUBLE2()))); + static assert(is(double == typeof(CONST_DOUBLE3()))); + static assert(is(double == typeof(CONST_DOUBLE4()))); + static assert(is(double == typeof(CONST_DOUBLE5()))); + static assert(is(double == typeof(CONST_DOUBLE6()))); + static assert(is(bool == typeof(CONST_BOOL1()))); + static assert(is(bool == typeof(CONST_BOOL2()))); + static assert(is(char == typeof(CONST_CHAR()))); + static assert(is(string == typeof(CONST_STRING1()))); + static assert(is(string == typeof(CONST_STRING2()))); + + static assert(is(int == typeof(INT_AND_BOOL()))); +// static assert(is(int == typeof(INT_AND_CHAR()))); + static assert(is(int == typeof(INT_AND_INT()))); + static assert(is(uint == typeof(INT_AND_UINT()))); + static assert(is(int == typeof(INT_AND_LONG()))); + static assert(is(uint == typeof(INT_AND_ULONG()))); + static assert(is(long == typeof(INT_AND_LLONG()))); + static assert(is(ulong == typeof(INT_AND_ULLONG()))); + static assert(is(int == typeof(BOOL_AND_BOOL()))); + + static assert(is(int == typeof(EXPR_MULTIPLY()))); + static assert(is(int == typeof(EXPR_DIVIDE()))); + static assert(is(int == typeof(EXPR_PLUS()))); + static assert(is(int == typeof(EXPR_MINUS()))); + static assert(is(int == typeof(EXPR_LSHIFT()))); + static assert(is(int == typeof(EXPR_RSHIFT()))); + static assert(is(bool == typeof(EXPR_LTE()))); + static assert(is(bool == typeof(EXPR_GTE()))); + static assert(is(bool == typeof(EXPR_INEQUALITY()))); + static assert(is(bool == typeof(EXPR_EQUALITY()))); + static assert(is(int == typeof(EXPR_AND()))); + static assert(is(int == typeof(EXPR_XOR()))); + static assert(is(int == typeof(EXPR_OR()))); + static assert(is(bool == typeof(EXPR_LAND()))); + static assert(is(bool == typeof(EXPR_LOR()))); + static assert(is(double == typeof(EXPR_CONDITIONAL()))); +} diff --git a/Examples/test-suite/d/sizet_runme.1.d b/Examples/test-suite/d/sizet_runme.1.d new file mode 100644 index 000000000..ae42e20e5 --- /dev/null +++ b/Examples/test-suite/d/sizet_runme.1.d @@ -0,0 +1,15 @@ +module sizet_runme; + +import sizet.sizet; + +void main() { + size_t s = 2000; + s = test1(s+1); + s = test2(s+1); + s = test3(s+1); + s = test4(s+1); + + if (s != 2004) { + throw new Exception("failed"); + } +} diff --git a/Examples/test-suite/d/sizet_runme.2.d b/Examples/test-suite/d/sizet_runme.2.d new file mode 100644 index 000000000..63eb03b21 --- /dev/null +++ b/Examples/test-suite/d/sizet_runme.2.d @@ -0,0 +1,14 @@ +module sizet_runme; + +import std.exception; +import sizet.sizet; + +void main() { + size_t s = 2000; + s = test1(s+1); + s = test2(s+1); + s = test3(s+1); + s = test4(s+1); + + enforce(s == 2004, "failed"); +} diff --git a/Examples/test-suite/d/sneaky1_runme.1.d b/Examples/test-suite/d/sneaky1_runme.1.d new file mode 100644 index 000000000..b293b4972 --- /dev/null +++ b/Examples/test-suite/d/sneaky1_runme.1.d @@ -0,0 +1,21 @@ +module sneaky1_runme; + +import sneaky1.sneaky1; + +void main() { + if (add(30, 2) != 32) { + throw new Exception("add test failed"); + } + + if (subtract(20, 2) != 18) { + throw new Exception("subtract test failed"); + } + + if (mul(20, 2) != 40) { + throw new Exception("mul test failed"); + } + + if (divide(20, 2) != 10) { + throw new Exception("div test failed"); + } +} diff --git a/Examples/test-suite/d/sneaky1_runme.2.d b/Examples/test-suite/d/sneaky1_runme.2.d new file mode 100644 index 000000000..84e51e74d --- /dev/null +++ b/Examples/test-suite/d/sneaky1_runme.2.d @@ -0,0 +1,11 @@ +module sneaky1_runme; + +import std.exception; +import sneaky1.sneaky1; + +void main() { + enforce(add(30, 2) == 32, "add test failed"); + enforce(subtract(20, 2) == 18, "subtract test failed"); + enforce(mul(20, 2) == 40, "mul test failed"); + enforce(divide(20, 2) == 10, "div test failed"); +} diff --git a/Examples/test-suite/d/special_variable_macros_runme.1.d b/Examples/test-suite/d/special_variable_macros_runme.1.d new file mode 100644 index 000000000..12491eef5 --- /dev/null +++ b/Examples/test-suite/d/special_variable_macros_runme.1.d @@ -0,0 +1,39 @@ +module special_variable_macros_runme; + +import special_variable_macros.special_variable_macros; +import special_variable_macros.Name; +import special_variable_macros.NewName; +import special_variable_macros.PairIntBool; + +void main() { + auto name = new Name(); + + if (testFred(name) != "none") { + throw new Exception("test failed"); + } + + if (testJack(name) != "$specialname") { + throw new Exception("test failed"); + } + + if (testJill(name) != "jilly") { + throw new Exception("test failed"); + } + + if (testMary(name) != "SWIGTYPE_p_NameWrap") { + throw new Exception("test failed"); + } + + if (testJim(name) != "multiname num") { + throw new Exception("test failed"); + } + + if (testJohn(new PairIntBool(10, false)) != 123) { + throw new Exception("test failed"); + } + + auto newName = NewName.factory("factoryname"); + if (newName.getStoredName().getName() != "factoryname") { + throw new Exception("test failed"); + } +} diff --git a/Examples/test-suite/d/special_variable_macros_runme.2.d b/Examples/test-suite/d/special_variable_macros_runme.2.d new file mode 100644 index 000000000..128e5870f --- /dev/null +++ b/Examples/test-suite/d/special_variable_macros_runme.2.d @@ -0,0 +1,21 @@ +module special_variable_macros_runme; + +import std.exception; +import special_variable_macros.special_variable_macros; +import special_variable_macros.Name; +import special_variable_macros.NewName; +import special_variable_macros.PairIntBool; + +void main() { + auto name = new Name(); + enforce(testFred(name) == "none"); + enforce(testJack(name) == "$specialname"); + enforce(testJill(name) == "jilly"); + enforce(testMary(name) == "SWIGTYPE_p_NameWrap"); + enforce(testJim(name) == "multiname num"); + + enforce(testJohn(new PairIntBool(10, false)) == 123); + + auto newName = NewName.factory("factoryname"); + enforce(newName.getStoredName().getName() == "factoryname"); +} diff --git a/Examples/test-suite/d/threads_runme.1.d b/Examples/test-suite/d/threads_runme.1.d new file mode 100644 index 000000000..206875824 --- /dev/null +++ b/Examples/test-suite/d/threads_runme.1.d @@ -0,0 +1,70 @@ +module threads_runme; + +import tango.core.Thread; +import tango.io.Console; +import Integer = tango.text.convert.Integer; +import threads.Kerfuffle; + +// Spawn 8 threads. +const uint NUM_THREADS = 8; + +// Run test for a few seconds on a 1GHz machine. +const uint WORKER_LOOP_PASSES = 30000; + +void main() { + auto kerf = new Kerfuffle(); + TestThread[] threads; + + // Invoke the threads. + for (uint i = 0; i < NUM_THREADS; i++) { + auto thread = new TestThread(kerf); + threads ~= thread; + thread.name = Integer.toString(i); + thread.start(); + } + + // Wait for the threads to finish. + foreach(thread; threads) { + thread.join(); + } + + // Check if any thread has failed. + foreach(thread; threads) { + if (thread.failed) throw new Exception("Test failed."); + } +} + +class TestThread : Thread { +public: + this(Kerfuffle kerf) { + super(&run); + m_kerf = kerf; + } + + void run() { + failed = false; + try { + for (uint i = 0; i < WORKER_LOOP_PASSES; i++) { + char[] given = "This is the test char[] that should come back. A number: " ~ Integer.toString(i); + char[] received = m_kerf.StdString(given); + if (received != given) { + throw new Exception("StdString char[] does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'."); + } + } + for (uint i = 0; i < WORKER_LOOP_PASSES; i++) { + char[] given = "This is the test char[] that should come back. A number: " ~ Integer.toString(i); + char[] received = m_kerf.CharString(given); + if (received != given) { + throw new Exception("StdString char[] does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'."); + } + } + } catch (Exception e) { + Cerr("Test failed (thread " ~ name() ~ "): " ~ e.msg).newline; + failed = true; + } + } + + bool failed; +private: + Kerfuffle m_kerf; +} diff --git a/Examples/test-suite/d/threads_runme.2.d b/Examples/test-suite/d/threads_runme.2.d new file mode 100644 index 000000000..3ac27a5a8 --- /dev/null +++ b/Examples/test-suite/d/threads_runme.2.d @@ -0,0 +1,55 @@ +module threads_runme; + +import core.thread; +import std.conv; +import std.exception; +import std.range; +import std.stdio; +import threads.Kerfuffle; + +// Spawn 8 threads. +enum THREADS = iota(0, 9); + +// Run test for a few seconds on a 1GHz machine. +enum WORK_RANGE = iota(0, 30000); + +void main() { + auto kerf = new Kerfuffle(); + TestThread[] threads; + + // Invoke the threads. + foreach (i; THREADS) { + auto thread = new TestThread(kerf); + threads ~= thread; + thread.name = to!string(i); + thread.start(); + } + + // Wait for the threads to finish. + foreach (i, thread; threads) { + thread.join(true); + } +} + +class TestThread : Thread { + this(Kerfuffle kerf) { + super(&run); + m_kerf = kerf; + } + + void run() { + foreach (i; WORK_RANGE) { + string given = "This is the test string that should come back. A number: " ~ to!string(i); + string received = m_kerf.StdString(given); + enforce(received == given, "StdString string does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'."); + } + foreach (i; WORK_RANGE) { + string given = "This is the test string that should come back. A number: " ~ to!string(i); + string received = m_kerf.CharString(given); + enforce(received == given, "CharString string does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'."); + } + } + +private: + Kerfuffle m_kerf; +} diff --git a/Examples/test-suite/d/throw_exception_runme.1.d b/Examples/test-suite/d/throw_exception_runme.1.d new file mode 100644 index 000000000..f2397a202 --- /dev/null +++ b/Examples/test-suite/d/throw_exception_runme.1.d @@ -0,0 +1,30 @@ +module throw_exception_runme; + +import throw_exception.Foo; + +void main() { + test!("test_int"); + test!("test_msg"); + test!("test_cls"); + test!("test_cls_ptr"); + test!("test_cls_ref"); + test!("test_cls_td"); + test!("test_cls_ptr_td"); + test!("test_cls_ref_td"); + test!("test_array"); + test!("test_enum"); +} + +void test(char[] methodName)() { + auto foo = new Foo(); + + bool didntThrow; + try { + mixin("foo." ~ methodName ~ "();"); + didntThrow = true; + } catch (Exception) {} + + if (didntThrow) { + throw new Exception(methodName ~ " failed"); + } +} diff --git a/Examples/test-suite/d/throw_exception_runme.2.d b/Examples/test-suite/d/throw_exception_runme.2.d new file mode 100644 index 000000000..6fc82a93d --- /dev/null +++ b/Examples/test-suite/d/throw_exception_runme.2.d @@ -0,0 +1,30 @@ +module throw_exception_runme; + +import throw_exception.Foo; + +void main() { + test!("test_int"); + test!("test_msg"); + test!("test_cls"); + test!("test_cls_ptr"); + test!("test_cls_ref"); + test!("test_cls_td"); + test!("test_cls_ptr_td"); + test!("test_cls_ref_td"); + test!("test_array"); + test!("test_enum"); +} + +void test(string methodName)() { + auto foo = new Foo(); + + bool didntThrow; + try { + mixin("foo." ~ methodName ~ "();"); + didntThrow = true; + } catch (Exception) {} + + if (didntThrow) { + throw new Exception(methodName ~ " failed"); + } +} diff --git a/Examples/test-suite/d/typemap_namespace_runme.1.d b/Examples/test-suite/d/typemap_namespace_runme.1.d new file mode 100644 index 000000000..3a5ca1a9f --- /dev/null +++ b/Examples/test-suite/d/typemap_namespace_runme.1.d @@ -0,0 +1,13 @@ +module typemap_namespace_runme; + +import typemap_namespace.typemap_namespace; + +void main() { + if (test1("hello") != "hello") { + throw new Exception("test1 failed"); + } + + if (test2("hello") != "hello") { + throw new Exception("test2 failed"); + } +} diff --git a/Examples/test-suite/d/typemap_namespace_runme.2.d b/Examples/test-suite/d/typemap_namespace_runme.2.d new file mode 100644 index 000000000..2281e403b --- /dev/null +++ b/Examples/test-suite/d/typemap_namespace_runme.2.d @@ -0,0 +1,9 @@ +module typemap_namespace_runme; + +import std.exception; +import typemap_namespace.typemap_namespace; + +void main() { + enforce(test1("hello") == "hello", "test1 failed"); + enforce(test2("hello") == "hello", "test2 failed"); +} diff --git a/Examples/test-suite/d/typemap_out_optimal_runme.1.d b/Examples/test-suite/d/typemap_out_optimal_runme.1.d new file mode 100644 index 000000000..16aab3cff --- /dev/null +++ b/Examples/test-suite/d/typemap_out_optimal_runme.1.d @@ -0,0 +1,9 @@ +module typemap_out_optimal_runme; + +import typemap_out_optimal.XX; + +void main() { + XX x; + XX.trace = false; + x = XX.create(); +} diff --git a/Examples/test-suite/d/typemap_out_optimal_runme.2.d b/Examples/test-suite/d/typemap_out_optimal_runme.2.d new file mode 100644 index 000000000..16aab3cff --- /dev/null +++ b/Examples/test-suite/d/typemap_out_optimal_runme.2.d @@ -0,0 +1,9 @@ +module typemap_out_optimal_runme; + +import typemap_out_optimal.XX; + +void main() { + XX x; + XX.trace = false; + x = XX.create(); +} diff --git a/Examples/test-suite/d/varargs_runme.1.d b/Examples/test-suite/d/varargs_runme.1.d new file mode 100644 index 000000000..53f76d075 --- /dev/null +++ b/Examples/test-suite/d/varargs_runme.1.d @@ -0,0 +1,20 @@ +module varargs_runme; + +import varargs.varargs; +import varargs.Foo; + +void main() { + if (test("Hello") != "Hello") { + throw new Exception("Test 1 failed"); + } + + auto f = new Foo("Greetings"); + + if (f.str != "Greetings") { + throw new Exception("Test 2 failed"); + } + + if (f.test("Hello") != "Hello") { + throw new Exception("Test 3 failed"); + } +} diff --git a/Examples/test-suite/d/varargs_runme.2.d b/Examples/test-suite/d/varargs_runme.2.d new file mode 100644 index 000000000..b2b5ceddc --- /dev/null +++ b/Examples/test-suite/d/varargs_runme.2.d @@ -0,0 +1,13 @@ +module varargs_runme; + +import std.exception; +import varargs.varargs; +import varargs.Foo; + +void main() { + enforce(test("Hello") == "Hello", "Test 1 failed"); + + auto f = new Foo("Greetings"); + enforce(f.str == "Greetings", "Test 2 failed"); + enforce(f.test("Hello") == "Hello", "Test 3 failed"); +} diff --git a/Examples/test-suite/d/virtual_poly_runme.1.d b/Examples/test-suite/d/virtual_poly_runme.1.d new file mode 100644 index 000000000..fb2e7814d --- /dev/null +++ b/Examples/test-suite/d/virtual_poly_runme.1.d @@ -0,0 +1,27 @@ +module virtual_poly_runme; + +import virtual_poly.NDouble; +import virtual_poly.NInt; +import virtual_poly.NNumber; + +void main() { + // D supports covariant (polymorphic) return types, so this should work like + // in C++. + auto d = new NDouble(3.5); + NDouble dc = d.copy(); + if (d.get() != dc.get()) { + throw new Exception("Test 1 failed."); + } + + auto i = new NInt(2); + NInt ic = i.copy(); + if (i.get() != ic.get()) { + throw new Exception("Test 2 failed."); + } + + NNumber n = d; + auto nd = cast(NDouble) n.copy(); + if (nd.get() != d.get()) { + throw new Exception("Test 3 failed."); + } +} diff --git a/Examples/test-suite/d/virtual_poly_runme.2.d b/Examples/test-suite/d/virtual_poly_runme.2.d new file mode 100644 index 000000000..f749ee236 --- /dev/null +++ b/Examples/test-suite/d/virtual_poly_runme.2.d @@ -0,0 +1,22 @@ +module virtual_poly_runme; + +import std.exception; +import virtual_poly.NDouble; +import virtual_poly.NInt; +import virtual_poly.NNumber; + +void main() { + // D supports covariant (polymorphic) return types, so this should work like + // in C++. + auto d = new NDouble(3.5); + NDouble dc = d.copy(); + enforce(d.get() == dc.get(), "Test 1 failed."); + + auto i = new NInt(2); + NInt ic = i.copy(); + enforce(i.get() == ic.get(), "Test 2 failed."); + + NNumber n = d; + auto nd = cast(NDouble) n.copy(); + enforce(nd.get() == d.get(), "Test 3 failed."); +} diff --git a/Examples/test-suite/d_exception_name.i b/Examples/test-suite/d_exception_name.i new file mode 100644 index 000000000..23f338a73 --- /dev/null +++ b/Examples/test-suite/d_exception_name.i @@ -0,0 +1,15 @@ +// Tests if exception handling still works in the presence of a wrapped C++ +// class called »Exception«, which could shadow the built-in Exception class. +%module d_exception_name + +%inline %{ + class Exception { + Exception(int i) {} + }; + + class Foo { + ~Foo() {} + public: + void bar(Exception *e) {} + }; +%} diff --git a/Examples/test-suite/d_nativepointers.i b/Examples/test-suite/d_nativepointers.i new file mode 100644 index 000000000..fdf3f1669 --- /dev/null +++ b/Examples/test-suite/d_nativepointers.i @@ -0,0 +1,21 @@ +%module d_nativepointers; + +%inline %{ + class SomeClass { + }; + class OpaqueClass; + typedef void (*FuncA)(int **x, char ***y); + typedef void (*FuncB)(int **x, SomeClass *y); + + int *a( int *value ){ return value; } + float **b( float **value ){ return value; } + char ***c( char ***value ){ return value; } + SomeClass *d( SomeClass *value ){ return value; } + SomeClass **e( SomeClass **value ){ return value; } + OpaqueClass *f( OpaqueClass *value ){ return value; } + FuncA g( FuncA value ){ return value; } + FuncB* h( FuncB* value ){ return value; } + + int &refA( int &value ){ return value; } + float *&refB( float *&value ){ return value; } +%} diff --git a/Examples/test-suite/default_constructor.i b/Examples/test-suite/default_constructor.i index ff22c7834..091adff20 100644 --- a/Examples/test-suite/default_constructor.i +++ b/Examples/test-suite/default_constructor.i @@ -5,11 +5,13 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) EB; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) EB; /* C#, D, Java, PHP multiple inheritance */ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) AD; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) AD; /* C#, D, Java, PHP multiple inheritance */ %warnfilter(SWIGWARN_LANG_FRIEND_IGNORE) F; /* friend function */ diff --git a/Examples/test-suite/director_alternating.i b/Examples/test-suite/director_alternating.i new file mode 100644 index 000000000..6e3ef4f24 --- /dev/null +++ b/Examples/test-suite/director_alternating.i @@ -0,0 +1,36 @@ +// Checks if calls to a method being defined in the base class, not +// overridden in the subclass, but again overridden in a class derived from +// the first subclass are dispatched correctly. +%module(directors="1") director_alternating; + +%feature("director") Foo; + +%inline %{ +struct Foo { + virtual ~Foo() {} + virtual int id() { + return 0; + } +}; + +struct Bar : Foo {}; + +struct Baz : Bar { + virtual int id() { + return 2; + } +}; + +// Note that even though the return value is of type Bar*, it really points to +// an instance of Baz (in which id() has been overridden). +Bar *getBar() { + static Baz baz; + return &baz; +} + +// idFromGetBar() obviously is equivalent to getBar()->id() in C++ – this +// should be true from the target language as well. +int idFromGetBar() { + return getBar()->id(); +} +%} diff --git a/Examples/test-suite/director_keywords.i b/Examples/test-suite/director_keywords.i new file mode 100644 index 000000000..473786c00 --- /dev/null +++ b/Examples/test-suite/director_keywords.i @@ -0,0 +1,13 @@ +// Checks if collisions of argument names with target language keywords are +// resolved properly when directors are used (currently only »abstract« for +// C#, D and Java is checked). +%module(directors="1") director_keywords + +%feature("director") Foo; + +%inline %{ +struct Foo { + virtual ~Foo() {} + virtual void bar(int abstract) {} +}; +%} diff --git a/Examples/test-suite/director_protected.i b/Examples/test-suite/director_protected.i index fee45b4a6..0299b238d 100644 --- a/Examples/test-suite/director_protected.i +++ b/Examples/test-suite/director_protected.i @@ -53,6 +53,10 @@ protected: virtual std::string used() { return pang() + pong(); } + + virtual std::string cheer() { + return pang() + pong(); + } }; class Bar : public Foo @@ -63,6 +67,14 @@ public: return new Bar(); } + std::string callping() { + return ping(); + } + + std::string callcheer() { + return cheer(); + } + std::string pong() { return "Bar::pong();" + Foo::pong(); } @@ -75,6 +87,7 @@ protected: std::string ping() { return "Bar::ping();"; }; + using Foo::cheer; enum Hello {hola, chao}; diff --git a/Examples/test-suite/director_using.i b/Examples/test-suite/director_using.i index 9001ffbb9..d86546e86 100644 --- a/Examples/test-suite/director_using.i +++ b/Examples/test-suite/director_using.i @@ -59,9 +59,22 @@ public: virtual C get_value() const = 0; using Bar::do_advance; - }; + } %template(FooBar_int) FooBar<int>; +%inline %{ + struct SomeBase { + virtual ~SomeBase() {} + virtual void method1() {} + virtual void method2() {} + }; + + struct PrivateDerived : SomeBase { + private: + virtual void method1() {} + using SomeBase::method2; + }; +%} diff --git a/Examples/test-suite/dynamic_cast.i b/Examples/test-suite/dynamic_cast.i index ccbaa5b47..392b3bfd1 100644 --- a/Examples/test-suite/dynamic_cast.i +++ b/Examples/test-suite/dynamic_cast.i @@ -1,7 +1,7 @@ /* File : example.i */ %module dynamic_cast -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) %apply SWIGTYPE *DYNAMIC { Foo * }; #endif @@ -17,7 +17,7 @@ public: }; %} -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGD) %typemap(out) Foo *blah { Bar *downcast = dynamic_cast<Bar *>($1); *(Bar **)&$result = downcast; @@ -37,6 +37,13 @@ public: } #endif +#if defined(SWIGD) +%typemap(dout, excode=SWIGEXCODE) Foo * { + Bar ret = new Bar($imcall, $owner);$excode + return ret; +} +#endif + #if defined(SWIGGO) %insert(go_runtime) %{ func FooToBar(f Foo) Bar { @@ -62,7 +69,7 @@ char *do_test(Bar *b) { } %} -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) // A general purpose function for dynamic casting of a Foo * %{ static swig_type_info * diff --git a/Examples/test-suite/enum_rename.i b/Examples/test-suite/enum_rename.i index 455826f8b..0cab4d0d8 100644 --- a/Examples/test-suite/enum_rename.i +++ b/Examples/test-suite/enum_rename.i @@ -2,7 +2,7 @@ %warnfilter(SWIGWARN_PARSE_REDEFINED) S_May; -// %rename with rxspencer can do the equivalent of these two renames, which was resulting in uncompileable code +// %rename using regex can do the equivalent of these two renames, which was resulting in uncompileable code %rename(May) M_May; %rename(May) S_May; diff --git a/Examples/test-suite/enums.i b/Examples/test-suite/enums.i index 5632b5e97..14c6efbba 100644 --- a/Examples/test-suite/enums.i +++ b/Examples/test-suite/enums.i @@ -58,6 +58,11 @@ typedef struct _Foo { %warnfilter(SWIGWARN_RUBY_WRONG_NAME) _iFoo; +#ifdef SWIGD +/* Work around missing support for proper char quoting due to parser shortcomings. */ +%dconstvalue("'a'") _iFoo::Char; +#endif + #ifndef __cplusplus %inline %{ typedef struct _iFoo diff --git a/Examples/test-suite/errors/cpp_inherit.i b/Examples/test-suite/errors/cpp_inherit.i new file mode 100644 index 000000000..fdc77d1d5 --- /dev/null +++ b/Examples/test-suite/errors/cpp_inherit.i @@ -0,0 +1,47 @@ +%module xxx + +%inline %{ +struct A5; +int A6; +template<typename T> struct A7 +{ +}; +template<typename T> struct A8 +{ +}; + +struct A0 +: + public A1 + , + A2, + private A3 + , + private A4 + , + A5 + , + A6 + , + A7<int> + , + protected A8<double> +{ +}; + +struct A1 +{ +}; + +class B1 {}; + +class B0 : + B1, + B2<int> +{ +}; + +struct Recursive : Recursive +{ +}; +%} diff --git a/Examples/test-suite/errors/cpp_macro_locator.i b/Examples/test-suite/errors/cpp_macro_locator.i new file mode 100644 index 000000000..bd441a121 --- /dev/null +++ b/Examples/test-suite/errors/cpp_macro_locator.i @@ -0,0 +1,103 @@ +%module xxx + +// Test the SWIG preprocessor locator effects on reporting line numbers in warnings when processing SWIG (multiline) macros + +// The ignored overloaded methods warnings should have the correct line number reporting +// {} blocks are tested, where the preprocessor expands the macros + +%define CLASSMACRO(KLASS) +class KLASS +{ +public: + KLASS() {} + void methodX(int *) {} + void methodX(const int *) {} +}; +%enddef + +%{ +#define CLASSMACRO(KLASS) \ +class KLASS \ +{ \ +public: \ + KLASS() {} \ + void methodX(int *) {} \ + void methodX(const int *) {} \ +}; +%} + +%{ +#define VARIABLEMACRO(NAME) double NAME; +struct Outer { + struct Inner { + VARIABLEMACRO(MyInnerVar) + }; +}; +void overload1(int *) {} +void overload1(const int *) {} +void overload2(int *) {} +void overload2(const int *) {} +void overload3(int *) {} +void overload3(const int *) {} +%} + +%define VARIABLEMACRO(NAME) +double NAME; +%enddef +struct Outer { + struct Inner { + VARIABLEMACRO(MyInnerVar) + }; +}; +void overload1(int *) {} +void overload1(const int *) {} + +%fragment("FragmentMethod", "header") { +void fragmentMethod() { +} +VARIABLEMACRO(fragVar) +} +void overload2(int *) {} +void overload2(const int *) {} + +%inline { +CLASSMACRO(Klass1) +} +#warning inline warning message one +void overload3(int *) {} +void overload3(const int *) {} + +%{ +struct Classic { + Classic() { + VARIABLEMACRO(inconstructor) + } + double value; +}; +void overload4(int *) {} +void overload4(const int *) {} +void overload5(int *) {} +void overload5(const int *) {} +%} + +struct Classic { + Classic() { + VARIABLEMACRO(inconstructor) + } + double value; +}; +void overload4(int *) {} +void overload4(const int *) {} + +%inline { +void overloadinline1(int *) {} +void overloadinline1(const int *) {} +CLASSMACRO(Klass2) +#warning an inline warning message 2 +void overloadinline2(int *) {} +void overloadinline2(const int *) {} +} +void overload5(int *) {} +void overload5(const int *) {} + + diff --git a/Examples/test-suite/errors/cpp_recursive_typedef.i b/Examples/test-suite/errors/cpp_recursive_typedef.i new file mode 100644 index 000000000..3d65a8817 --- /dev/null +++ b/Examples/test-suite/errors/cpp_recursive_typedef.i @@ -0,0 +1,4 @@ +%module cpp_recursive_typedef + +typedef std::set<pds> pds; + diff --git a/Examples/test-suite/errors/cpp_shared_ptr.i b/Examples/test-suite/errors/cpp_shared_ptr.i new file mode 100644 index 000000000..edbd0cf87 --- /dev/null +++ b/Examples/test-suite/errors/cpp_shared_ptr.i @@ -0,0 +1,29 @@ +%module cpp_shared_ptr + +%include <boost_shared_ptr.i> + +%shared_ptr(B); +%shared_ptr(C); + +%inline %{ + #include <stdio.h> + #include <boost/shared_ptr.hpp> + + struct A { + virtual ~A() {} + }; + + struct B { + virtual ~B() {} + }; + + struct C : B, A { + virtual ~C() {} + }; + + struct D : C { + virtual ~D() {} + }; +%} + + diff --git a/Examples/test-suite/errors/expected.log b/Examples/test-suite/errors/expected.log new file mode 100644 index 000000000..f9210226d --- /dev/null +++ b/Examples/test-suite/errors/expected.log @@ -0,0 +1,314 @@ +SWIG error and warning test. opts= +----------------------------------------------------------- + +:::::::::::::::::::::::::::::::: c_bad_name.i ::::::::::::::::::::::::::::::::::: +c_bad_name.i:3: Warning 121: %name is deprecated. Use %rename instead. +c_bad_name.i:3: Error: Missing argument to %name directive. + +:::::::::::::::::::::::::::::::: c_bad_native.i ::::::::::::::::::::::::::::::::::: +c_bad_native.i:3: Error: %native declaration 'foo' is not a function. + +:::::::::::::::::::::::::::::::: c_class.i ::::::::::::::::::::::::::::::::::: +c_class.i:3: Warning 301: class keyword used, but not in C++ mode. +c_class.i:3: Warning 314: 'class' is a python keyword, renaming to '_class' + +:::::::::::::::::::::::::::::::: c_default_error.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: c_deprecated.i ::::::::::::::::::::::::::::::::::: +c_deprecated.i:3: Warning 102: %val directive deprecated (ignored). +c_deprecated.i:3: Warning 103: %out directive deprecated (ignored). + +:::::::::::::::::::::::::::::::: c_empty_char.i ::::::::::::::::::::::::::::::::::: +c_empty_char.i:3: Error: Empty character constant +0 + +:::::::::::::::::::::::::::::::: c_enum_badvalue.i ::::::::::::::::::::::::::::::::::: +c_enum_badvalue.i:6: Error: Type error. Expecting an integral type + +:::::::::::::::::::::::::::::::: c_extra_rblock.i ::::::::::::::::::::::::::::::::::: +c_extra_rblock.i:5: Error: Syntax error in input(1). + +:::::::::::::::::::::::::::::::: c_extra_rbrace.i ::::::::::::::::::::::::::::::::::: +c_extra_rbrace.i:5: Error: Syntax error. Extraneous '}' + +:::::::::::::::::::::::::::::::: c_extra_unsigned.i ::::::::::::::::::::::::::::::::::: +c_extra_unsigned.i:3: Error: Extra unsigned specifier. +c_extra_unsigned.i:4: Error: Extra signed specifier. +c_extra_unsigned.i:5: Error: Extra signed specifier. + +:::::::::::::::::::::::::::::::: c_insert_missing.i ::::::::::::::::::::::::::::::::::: +c_insert_missing.i:3: Error: Couldn't find 'missing_file.i'. + +:::::::::::::::::::::::::::::::: c_long_short.i ::::::::::::::::::::::::::::::::::: +c_long_short.i:3: Error: Extra long specifier. +c_long_short.i:4: Error: Extra short specifier. +c_long_short.i:5: Error: Extra long specifier. +c_long_short.i:6: Error: Extra short specifier. + +:::::::::::::::::::::::::::::::: c_missing_rbrace.i ::::::::::::::::::::::::::::::::::: +:168430090: Error: Missing '}'. Reached end of input. +c_missing_rbrace.i:3: Error: Syntax error in input(1). + +:::::::::::::::::::::::::::::::: c_missing_semi.i ::::::::::::::::::::::::::::::::::: +c_missing_semi.i:3: Error: Syntax error in input(1). + +:::::::::::::::::::::::::::::::: c_redefine.i ::::::::::::::::::::::::::::::::::: +c_redefine.i:4: Warning 302: Identifier 'foo' redefined (ignored), +c_redefine.i:3: Warning 302: previous definition of 'foo'. +c_redefine.i:8: Warning 302: Identifier 'bar' redefined (ignored), +c_redefine.i:6: Warning 302: previous definition of 'bar'. +c_redefine.i:14: Warning 322: Redundant redeclaration of 'bar' (Renamed from 'spam'), +c_redefine.i:6: Warning 322: previous declaration of 'bar'. + +:::::::::::::::::::::::::::::::: c_varargs.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: c_varargs_neg.i ::::::::::::::::::::::::::::::::::: +c_varargs_neg.i:3: Error: Argument count in %varargs must be positive. + +:::::::::::::::::::::::::::::::: nomodule.i ::::::::::::::::::::::::::::::::::: +No module name specified using %module or -module. + +:::::::::::::::::::::::::::::::: pp_badeval.i ::::::::::::::::::::::::::::::::::: +pp_badeval.i:4: Warning 202: Could not evaluate 'FOO==4+' +pp_badeval.i:4: Warning 202: Error: 'Expected an expression' + +:::::::::::::::::::::::::::::::: pp_constant.i ::::::::::::::::::::::::::::::::::: +pp_constant.i:9: Warning 305: Bad constant value (ignored). +pp_constant.i:15: Warning 305: Bad constant value (ignored). +pp_constant.i:23: Warning 305: Bad constant value (ignored). +pp_constant.i:29: Warning 305: Bad constant value (ignored). +pp_constant.i:35: Warning 305: Bad constant value (ignored). +pp_constant.i:42: Warning 305: Bad constant value (ignored). +pp_constant.i:46: Warning 305: Bad constant value (ignored). +pp_constant.i:49: Warning 305: Bad constant value (ignored). + +:::::::::::::::::::::::::::::::: pp_defined.i ::::::::::::::::::::::::::::::::::: +pp_defined.i:6: Error: No arguments given to defined() +pp_defined.i:6: Warning 202: Could not evaluate 'defined' +pp_defined.i:6: Warning 202: Error: 'Expected an expression' + +:::::::::::::::::::::::::::::::: pp_deprecated.i ::::::::::::::::::::::::::::::::::: +pp_deprecated.i:4: Warning 101: %extern is deprecated. Use %import instead. +pp_deprecated.i:4: Error: Unable to find 'ext;' +pp_deprecated.i:6: Warning 204: CPP #warning, Print this warning +pp_deprecated.i:8: Error: CPP #error "This is an error". Use the -cpperraswarn option to continue swig processing. + +:::::::::::::::::::::::::::::::: pp_illegal_argument.i ::::::::::::::::::::::::::::::::::: +pp_illegal_argument.i:6: Error: Illegal macro argument name '..' +pp_illegal_argument.i:10: Error: Illegal macro argument name '..' +pp_illegal_argument.i:16: Error: Illegal character in macro argument name + +:::::::::::::::::::::::::::::::: pp_macro_args.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: pp_macro_badchar.i ::::::::::::::::::::::::::::::::::: +pp_macro_badchar.i:4: Error: Illegal character in macro argument name + +:::::::::::::::::::::::::::::::: pp_macro_defined_unterminated.i ::::::::::::::::::::::::::::::::::: +pp_macro_defined_unterminated.i:4: Error: Unterminated call to 'defined' + +:::::::::::::::::::::::::::::::: pp_macro_expansion.i ::::::::::::::::::::::::::::::::::: +pp_macro_expansion.i:9: Error: Macro 'MACRO2' expects 2 arguments + +:::::::::::::::::::::::::::::::: pp_macro_expansion_multiline.i ::::::::::::::::::::::::::::::::::: +pp_macro_expansion_multiline.i:13: Warning 509: Overloaded method foo(int const *) effectively ignored, +pp_macro_expansion_multiline.i:12: Warning 509: as it is shadowed by foo(int *). +pp_macro_expansion_multiline.i:31: Warning 509: Overloaded method bar(int const *) effectively ignored, +pp_macro_expansion_multiline.i:30: Warning 509: as it is shadowed by bar(int *). + +:::::::::::::::::::::::::::::::: pp_macro_inline_unterminated.i ::::::::::::::::::::::::::::::::::: +pp_macro_inline_unterminated.i:9: Error: Unterminated call invoking macro 'foo' +pp_macro_inline_unterminated.i:12: Error: Syntax error in input(3). + +:::::::::::::::::::::::::::::::: pp_macro_nargs.i ::::::::::::::::::::::::::::::::::: +pp_macro_nargs.i:7: Error: Macro 'foo' expects 2 arguments +pp_macro_nargs.i:8: Error: Macro 'foo' expects 2 arguments +pp_macro_nargs.i:10: Error: Macro 'bar' expects 1 argument +pp_macro_nargs.i:11: Error: Macro 'spam' expects no arguments + +:::::::::::::::::::::::::::::::: pp_macro_redef.i ::::::::::::::::::::::::::::::::::: +pp_macro_redef.i:4: Error: Macro 'foo' redefined, +pp_macro_redef.i:3: Error: previous definition of 'foo'. +pp_macro_redef.i:7: Error: Macro 'foo' redefined, +pp_macro_redef.i:3: Error: previous definition of 'foo'. + +:::::::::::::::::::::::::::::::: pp_macro_rparen.i ::::::::::::::::::::::::::::::::::: +pp_macro_rparen.i:3: Error: Missing ')' in macro parameters + +:::::::::::::::::::::::::::::::: pp_macro_unterminated.i ::::::::::::::::::::::::::::::::::: +pp_macro_unterminated.i:5: Error: Unterminated call invoking macro 'foo' + +:::::::::::::::::::::::::::::::: pp_misplaced_elif.i ::::::::::::::::::::::::::::::::::: +pp_misplaced_elif.i:4: Error: Misplaced #elif. +pp_misplaced_elif.i:6: Error: Extraneous #endif. + +:::::::::::::::::::::::::::::::: pp_misplaced_else.i ::::::::::::::::::::::::::::::::::: +pp_misplaced_else.i:4: Error: Misplaced #else. +pp_misplaced_else.i:6: Error: Extraneous #endif. + +:::::::::::::::::::::::::::::::: pp_missing_enddef.i ::::::::::::::::::::::::::::::::::: +pp_missing_enddef.i:EOF: Error: Missing %enddef for macro starting on line 3 + +:::::::::::::::::::::::::::::::: pp_missing_endif.i ::::::::::::::::::::::::::::::::::: +pp_missing_endif.i:EOF: Error: Missing #endif for conditional starting on line 3 + +:::::::::::::::::::::::::::::::: pp_missing_file.i ::::::::::::::::::::::::::::::::::: +pp_missing_file.i:3: Error: Unable to find 'missing_filename.i' + +:::::::::::::::::::::::::::::::: pp_missing_rblock.i ::::::::::::::::::::::::::::::::::: +pp_missing_rblock.i:EOF: Error: Unterminated %{ ... %} block starting on line 3 + +:::::::::::::::::::::::::::::::: pp_pragma.i ::::::::::::::::::::::::::::::::::: +pp_pragma.i:4: Error: Unknown SWIG pragma: rubbish() + +:::::::::::::::::::::::::::::::: pp_unterm_char.i ::::::::::::::::::::::::::::::::::: +pp_unterm_char.i:EOF: Error: Unterminated character constant starting at line 4 + +:::::::::::::::::::::::::::::::: pp_unterm_comment.i ::::::::::::::::::::::::::::::::::: +pp_unterm_comment.i:EOF: Error: Unterminated comment starting on line 3 + +:::::::::::::::::::::::::::::::: pp_unterm_string.i ::::::::::::::::::::::::::::::::::: +pp_unterm_string.i:EOF: Error: Unterminated string constant starting at line 4 + +:::::::::::::::::::::::::::::::: pp_variable_args.i ::::::::::::::::::::::::::::::::::: +pp_variable_args.i:6: Error: Variable length macro argument must be last parameter + +:::::::::::::::::::::::::::::::: swig_apply_nargs.i ::::::::::::::::::::::::::::::::::: +swig_apply_nargs.i:6: Error: Can't apply (char *str,int len) to (int x). Number of arguments don't match. + +:::::::::::::::::::::::::::::::: swig_identifier.i ::::::::::::::::::::::::::::::::::: +swig_identifier.i:5: Warning 503: Can't wrap 'foo bar' unless renamed to a valid identifier. + +:::::::::::::::::::::::::::::::: swig_insert_bad.i ::::::::::::::::::::::::::::::::::: +swig_insert_bad.i:5: Error: Unknown target 'foobar' for %insert directive. + +:::::::::::::::::::::::::::::::: swig_typemap_copy.i ::::::::::::::::::::::::::::::::::: +swig_typemap_copy.i:3: Error: Can't copy typemap (in) blah = int + +:::::::::::::::::::::::::::::::: swig_typemap_old.i ::::::::::::::::::::::::::::::::::: +swig_typemap_old.i:6: Warning 450: Deprecated typemap feature ($source/$target). +swig_typemap_old.i:6: Warning 450: The use of $source and $target in a typemap declaration is deprecated. +For typemaps related to argument input (in,ignore,default,arginit,check), replace +$source by $input and $target by $1. For typemaps related to return values (out, +argout,ret,except), replace $source by $1 and $target by $result. See the file +Doc/Manual/Typemaps.html for complete details. + +:::::::::::::::::::::::::::::::: cpp_bad_extern.i ::::::::::::::::::::::::::::::::::: +cpp_bad_extern.i:5: Warning 313: Unrecognized extern type "INTERCAL". +cpp_bad_extern.i:7: Warning 313: Unrecognized extern type "INTERCAL". + +:::::::::::::::::::::::::::::::: cpp_extend_redefine.i ::::::::::::::::::::::::::::::::::: +cpp_extend_redefine.i:9: Warning 302: Identifier 'bar' redefined by %extend (ignored), +cpp_extend_redefine.i:5: Warning 302: %extend definition of 'bar'. +cpp_extend_redefine.i:14: Warning 322: Redundant redeclaration of 'spam', +cpp_extend_redefine.i:10: Warning 322: previous declaration of 'spam'. + +:::::::::::::::::::::::::::::::: cpp_extend_undefined.i ::::::::::::::::::::::::::::::::::: +cpp_extend_undefined.i:6: Warning 303: %extend defined for an undeclared class foo. + +:::::::::::::::::::::::::::::::: cpp_inline_namespace.i ::::::::::::::::::::::::::::::::::: +cpp_inline_namespace.i:4: Error: %inline directive inside a namespace is disallowed. + +:::::::::::::::::::::::::::::::: cpp_inherit.i ::::::::::::::::::::::::::::::::::: +cpp_inherit.i:18: Warning 309: private inheritance from base 'A3' (ignored). +cpp_inherit.i:20: Warning 309: private inheritance from base 'A4' (ignored). +cpp_inherit.i:28: Warning 309: protected inheritance from base 'A8< double >' (ignored). +cpp_inherit.i:39: Warning 319: No access specifier given for base class 'B1' (ignored). +cpp_inherit.i:40: Warning 319: No access specifier given for base class 'B2< int >' (ignored). +cpp_inherit.i:15: Warning 401: Base class 'A1' undefined. +cpp_inherit.i:33: Warning 401: 'A1' must be defined before it is used as a base class. +cpp_inherit.i:17: Warning 401: Nothing known about base class 'A2'. Ignored. +cpp_inherit.i:22: Warning 402: Base class 'A5' is incomplete. +cpp_inherit.i:4: Warning 402: Only forward declaration 'A5' was found. +cpp_inherit.i:24: Error: 'A6' is not a valid base class. +cpp_inherit.i:5: Error: See definition of 'A6'. +cpp_inherit.i:24: Warning 401: Nothing known about base class 'A6'. Ignored. +cpp_inherit.i:26: Warning 401: Nothing known about base class 'A7< int >'. Ignored. +cpp_inherit.i:26: Warning 401: Maybe you forgot to instantiate 'A7< int >' using %template. +cpp_inherit.i:45: Warning 323: Recursive scope inheritance of 'Recursive'. + +:::::::::::::::::::::::::::::::: cpp_macro_locator.i ::::::::::::::::::::::::::::::::::: +cpp_macro_locator.i:66: Warning 204: CPP #warning, inline warning message one +cpp_macro_locator.i:96: Warning 204: CPP #warning, an inline warning message 2 +cpp_macro_locator.i:50: Warning 325: Nested struct not currently supported (Inner ignored) +cpp_macro_locator.i:53: Warning 509: Overloaded method overload1(int const *) effectively ignored, +cpp_macro_locator.i:52: Warning 509: as it is shadowed by overload1(int *). +cpp_macro_locator.i:61: Warning 509: Overloaded method overload2(int const *) effectively ignored, +cpp_macro_locator.i:60: Warning 509: as it is shadowed by overload2(int *). +cpp_macro_locator.i:64: Warning 509: Overloaded method Klass1::methodX(int const *) effectively ignored, +cpp_macro_locator.i:64: Warning 509: as it is shadowed by Klass1::methodX(int *). +cpp_macro_locator.i:68: Warning 509: Overloaded method overload3(int const *) effectively ignored, +cpp_macro_locator.i:67: Warning 509: as it is shadowed by overload3(int *). +cpp_macro_locator.i:90: Warning 509: Overloaded method overload4(int const *) effectively ignored, +cpp_macro_locator.i:89: Warning 509: as it is shadowed by overload4(int *). +cpp_macro_locator.i:94: Warning 509: Overloaded method overloadinline1(int const *) effectively ignored, +cpp_macro_locator.i:93: Warning 509: as it is shadowed by overloadinline1(int *). +cpp_macro_locator.i:95: Warning 509: Overloaded method Klass2::methodX(int const *) effectively ignored, +cpp_macro_locator.i:95: Warning 509: as it is shadowed by Klass2::methodX(int *). +cpp_macro_locator.i:98: Warning 509: Overloaded method overloadinline2(int const *) effectively ignored, +cpp_macro_locator.i:97: Warning 509: as it is shadowed by overloadinline2(int *). +cpp_macro_locator.i:101: Warning 509: Overloaded method overload5(int const *) effectively ignored, +cpp_macro_locator.i:100: Warning 509: as it is shadowed by overload5(int *). + +:::::::::::::::::::::::::::::::: cpp_missing_rtemplate.i ::::::::::::::::::::::::::::::::::: +cpp_missing_rtemplate.i:4: Error: Syntax error in input(1). + +:::::::::::::::::::::::::::::::: cpp_namespace_alias.i ::::::::::::::::::::::::::::::::::: +cpp_namespace_alias.i:8: Warning 308: Namespace alias 'B' not allowed here. Assuming 'blah' + +:::::::::::::::::::::::::::::::: cpp_namespace_aliasnot.i ::::::::::::::::::::::::::::::::::: +cpp_namespace_aliasnot.i:4: Error: 'blah' is not a namespace + +:::::::::::::::::::::::::::::::: cpp_namespace_aliasundef.i ::::::::::::::::::::::::::::::::::: +cpp_namespace_aliasundef.i:3: Error: Unknown namespace 'blah' + +:::::::::::::::::::::::::::::::: cpp_nested.i ::::::::::::::::::::::::::::::::::: +cpp_nested.i:6: Warning 325: Nested class not currently supported (Bar ignored) +cpp_nested.i:12: Warning 325: Nested class not currently supported (Grok ignored) + +:::::::::::::::::::::::::::::::: cpp_no_access.i ::::::::::::::::::::::::::::::::::: +cpp_no_access.i:3: Warning 319: No access specifier given for base class 'foo' (ignored). + +:::::::::::::::::::::::::::::::: cpp_nobase.i ::::::::::::::::::::::::::::::::::: +cpp_nobase.i:3: Warning 401: Nothing known about base class 'Bar'. Ignored. +cpp_nobase.i:6: Warning 401: Nothing known about base class 'Bar< int >'. Ignored. +cpp_nobase.i:6: Warning 401: Maybe you forgot to instantiate 'Bar< int >' using %template. + +:::::::::::::::::::::::::::::::: cpp_overload.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: cpp_private_defvalue.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: cpp_private_inherit.i ::::::::::::::::::::::::::::::::::: +cpp_private_inherit.i:6: Warning 309: private inheritance from base 'Foo' (ignored). +cpp_private_inherit.i:9: Warning 309: protected inheritance from base 'Foo' (ignored). + +:::::::::::::::::::::::::::::::: cpp_recursive_typedef.i ::::::::::::::::::::::::::::::::::: +:1: Error: Recursive typedef detected resolving 'pds *' to 'std::set< pds > *' to 'std::set< std::set< pds > > *' and so on... + +:::::::::::::::::::::::::::::::: cpp_shared_ptr.i ::::::::::::::::::::::::::::::::::: +cpp_shared_ptr.i:20: Warning 520: Base class 'A' of 'C' is not similarly marked as a smart pointer. +cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'C' is not similarly marked as a smart pointer. +cpp_shared_ptr.i:24: Warning 520: Derived class 'D' of 'B' is not similarly marked as a smart pointer. + +:::::::::::::::::::::::::::::::: cpp_template_argname.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: cpp_template_nargs.i ::::::::::::::::::::::::::::::::::: +cpp_template_nargs.i:5: Error: Template 'blah' undefined. +cpp_template_nargs.i:6: Error: Template 'blah' undefined. + +:::::::::::::::::::::::::::::::: cpp_template_not.i ::::::::::::::::::::::::::::::::::: +cpp_template_not.i:5: Error: 'blah' is not defined as a template. (cdecl) + +:::::::::::::::::::::::::::::::: cpp_template_partial.i ::::::::::::::::::::::::::::::::::: +cpp_template_partial.i:3: Warning 317: Specialization of non-template 'vector'. + +:::::::::::::::::::::::::::::::: cpp_template_repeat.i ::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::: cpp_template_undef.i ::::::::::::::::::::::::::::::::::: +cpp_template_undef.i:3: Error: Template 'blah' undefined. + +:::::::::::::::::::::::::::::::: cpp_using_not.i ::::::::::::::::::::::::::::::::::: +cpp_using_not.i:4: Error: 'blah' is not a namespace. + +:::::::::::::::::::::::::::::::: cpp_using_undef.i ::::::::::::::::::::::::::::::::::: +cpp_using_undef.i:4: Error: Nothing known about namespace 'foo' +cpp_using_undef.i:3: Warning 315: Nothing known about 'foo::bar'. diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh index ae38ca879..474c79b2d 100755 --- a/Examples/test-suite/errors/make.sh +++ b/Examples/test-suite/errors/make.sh @@ -24,11 +24,18 @@ c_missing_semi c_redefine c_varargs c_varargs_neg -nomodule +nomodule pp_badeval +pp_constant pp_defined +pp_deprecated +pp_illegal_argument pp_macro_args pp_macro_badchar +pp_macro_defined_unterminated +pp_macro_expansion +pp_macro_expansion_multiline +pp_macro_inline_unterminated pp_macro_nargs pp_macro_redef pp_macro_rparen @@ -39,9 +46,11 @@ pp_missing_enddef pp_missing_endif pp_missing_file pp_missing_rblock +pp_pragma pp_unterm_char pp_unterm_comment pp_unterm_string +pp_variable_args swig_apply_nargs swig_identifier swig_insert_bad @@ -55,6 +64,8 @@ cpp_bad_extern cpp_extend_redefine cpp_extend_undefined cpp_inline_namespace +cpp_inherit +cpp_macro_locator cpp_missing_rtemplate cpp_namespace_alias cpp_namespace_aliasnot @@ -65,6 +76,8 @@ cpp_nobase cpp_overload cpp_private_defvalue cpp_private_inherit +cpp_recursive_typedef +cpp_shared_ptr cpp_template_argname cpp_template_nargs cpp_template_not @@ -87,14 +100,14 @@ for i in ${CFILES}; do echo " Testing : ${i}.i"; echo "" >> ${LOGFILE}; echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE}; - ${SWIG} -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 + ${SWIG} -python -Wall ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 done for i in ${CPPFILES}; do echo " Testing : ${i}.i"; echo "" >> ${LOGFILE} echo ":::::::::::::::::::::::::::::::: ${i}.i :::::::::::::::::::::::::::::::::::" >> ${LOGFILE}; - ${SWIG} -Wall -c++ ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 + ${SWIG} -python -Wall -c++ ${SWIGOPT} ${i}.i >>${LOGFILE} 2>&1 done echo "" diff --git a/Examples/test-suite/errors/pp_constant.i b/Examples/test-suite/errors/pp_constant.i new file mode 100644 index 000000000..2be108e83 --- /dev/null +++ b/Examples/test-suite/errors/pp_constant.i @@ -0,0 +1,50 @@ +%module xxx + +/* Test preprocessor comments and their effect on line number reporting on later errors */ + +#define A1 1234 +#define A2 1234 /*C comment*/ +#define A3 1234 + +%constant int aaa=; + +#define B1 1234 +#define B2 1234 //C++ comment +#define B3 1234 + +%constant int bbb=; + +#define C1 1234 +#define C2 1234 /*multiline +C +comment */ +#define C3 1234 + +%constant int ccc=; + +#define D1 1234 +#define /*C Comment*/ D2 1234 +#define D3 1234 + +%constant int ddd=; + +#define E1 1234 +#/*C comment*/define E2 1234 +#define E3 1234 + +%constant int eee=; + +#define F1 1234 +#define F2 1234 \ +// C comment +#define F3 1234 + +%constant int fff=; + +// Test macro ending in /, that is not a C comment terminator +#define G1 1234 +#define G2 1234 / +#define G3 1234 + +%constant int ggg=; + diff --git a/Examples/test-suite/errors/pp_deprecated.i b/Examples/test-suite/errors/pp_deprecated.i new file mode 100644 index 000000000..68f81317b --- /dev/null +++ b/Examples/test-suite/errors/pp_deprecated.i @@ -0,0 +1,9 @@ +%module xxx + + +%extern ext; + +#warning Print this warning + +#error This is an error + diff --git a/Examples/test-suite/errors/pp_illegal_argument.i b/Examples/test-suite/errors/pp_illegal_argument.i new file mode 100644 index 000000000..13ffa4559 --- /dev/null +++ b/Examples/test-suite/errors/pp_illegal_argument.i @@ -0,0 +1,20 @@ +%module xxx + + +%define MISSING_DOT1(a, +b, +..) +xxx +%enddef + +%define MISSING_DOT2(..) +xxx +%enddef + +%define BAD_ARGNAME( +a, +b{c +) +xxx +%enddef + diff --git a/Examples/test-suite/errors/pp_macro_defined_unterminated.i b/Examples/test-suite/errors/pp_macro_defined_unterminated.i new file mode 100644 index 000000000..bc44d07c6 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_defined_unterminated.i @@ -0,0 +1,6 @@ +%module xxx + + +#if defined(a +#endif + diff --git a/Examples/test-suite/errors/pp_macro_expansion.i b/Examples/test-suite/errors/pp_macro_expansion.i new file mode 100644 index 000000000..e23a0da01 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_expansion.i @@ -0,0 +1,10 @@ +%module xxx + +/* Test line number reporting for multiple macro expansions */ + +#define MACRO2(a, b) + +#define MACRO1(NAME) MACRO2(NAME,2,3) + +MACRO1(abc) + diff --git a/Examples/test-suite/errors/pp_macro_expansion_multiline.i b/Examples/test-suite/errors/pp_macro_expansion_multiline.i new file mode 100644 index 000000000..b0777de60 --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_expansion_multiline.i @@ -0,0 +1,32 @@ +%module xxx +// Testing macros split over multiple lines - ensure the warning message for the ignored functions contain the correct line numbering + +#define MYMACRO(NAME, A, B, C) void NAME(int A, int B, int C); + +MYMACRO(funk, x, +y, + +z +) + +void foo(int *); +void foo(const int *); + +%define MYSWIGMACRO(A, B, C) +MYMACRO(funk1, + AA, + BB, + CC) +MYMACRO(funk2, + AA, + BB, + CC) +%enddef + +MYSWIGMACRO(xx, + yy, + zz) + +void bar(int *); +void bar(const int *); + diff --git a/Examples/test-suite/errors/pp_macro_inline_unterminated.i b/Examples/test-suite/errors/pp_macro_inline_unterminated.i new file mode 100644 index 000000000..67de0942c --- /dev/null +++ b/Examples/test-suite/errors/pp_macro_inline_unterminated.i @@ -0,0 +1,11 @@ +%module xxx + +%define foo(a,x) +int ii; +%enddef + +%inline %{ +struct Struct { +foo(2, +}; +%} diff --git a/Examples/test-suite/errors/pp_pragma.i b/Examples/test-suite/errors/pp_pragma.i new file mode 100644 index 000000000..8d928690c --- /dev/null +++ b/Examples/test-suite/errors/pp_pragma.i @@ -0,0 +1,6 @@ +%module xxx + + +#pragma SWIG rubbish() + + diff --git a/Examples/test-suite/errors/pp_variable_args.i b/Examples/test-suite/errors/pp_variable_args.i new file mode 100644 index 000000000..c5f72fff9 --- /dev/null +++ b/Examples/test-suite/errors/pp_variable_args.i @@ -0,0 +1,10 @@ +%module xxx + + +%define VARARGS_WRONG(a, +x, +..., + b) +xxx +%enddef + diff --git a/Examples/test-suite/evil_diamond.i b/Examples/test-suite/evil_diamond.i index 7b2e9152f..a8d48b30b 100644 --- a/Examples/test-suite/evil_diamond.i +++ b/Examples/test-suite/evil_diamond.i @@ -6,7 +6,8 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME, SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) spam; // Ruby, wrong class name - C# & Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) spam; // Ruby, wrong class name - C#, D & Java, PHP multiple inheritance %inline %{ diff --git a/Examples/test-suite/evil_diamond_ns.i b/Examples/test-suite/evil_diamond_ns.i index 515044007..0227b31ee 100644 --- a/Examples/test-suite/evil_diamond_ns.i +++ b/Examples/test-suite/evil_diamond_ns.i @@ -6,7 +6,8 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME, SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) Blah::spam; // Ruby, wrong class name - C# & Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) Blah::spam; // Ruby, wrong class name - C#, D & Java, PHP multiple inheritance %inline %{ namespace Blah { diff --git a/Examples/test-suite/evil_diamond_prop.i b/Examples/test-suite/evil_diamond_prop.i index 804ea66b4..2dac6eab7 100644 --- a/Examples/test-suite/evil_diamond_prop.i +++ b/Examples/test-suite/evil_diamond_prop.i @@ -6,6 +6,7 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME, SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, + SWIGWARN_D_MULTIPLE_INHERITANCE, SWIGWARN_PHP_MULTIPLE_INHERITANCE) spam; // Ruby, wrong class name - C# & Java, PHP multiple inheritance %inline %{ diff --git a/Examples/test-suite/exception_order.i b/Examples/test-suite/exception_order.i index 45a87e0c5..4dd13858a 100644 --- a/Examples/test-suite/exception_order.i +++ b/Examples/test-suite/exception_order.i @@ -2,6 +2,14 @@ %warnfilter(SWIGWARN_RUBY_WRONG_NAME); +#if defined(SWIGGO) && defined(SWIGGO_GCCGO) +%{ +#ifdef __GNUC__ +#include <cxxabi.h> +#endif +%} +#endif + %include "exception.i" %{ @@ -23,6 +31,18 @@ SWIG_exception_fail(SWIG_RuntimeError,"postcatch unknown"); } } +#elif defined(SWIGGO) && defined(SWIGGO_GCCGO) +%exception %{ + try { + $action +#ifdef __GNUC__ + } catch (__cxxabiv1::__foreign_exception&) { + throw; +#endif + } catch(...) { + SWIG_exception(SWIG_RuntimeError,"postcatch unknown"); + } +%} #else %exception { try { diff --git a/Examples/test-suite/global_namespace.i b/Examples/test-suite/global_namespace.i index 7b575614f..37195c76b 100644 --- a/Examples/test-suite/global_namespace.i +++ b/Examples/test-suite/global_namespace.i @@ -58,3 +58,25 @@ struct TheEnumMethods { } %} +%inline %{ +Klass1 getKlass1A() { return ::Klass1(); } +::Klass1 getKlass1B() { return ::Klass1(); } + +Klass2 getKlass2A() { return ::Klass2(); } +::Klass2 getKlass2B() { return ::Klass2(); } + +Klass3 getKlass3A() { return ::Klass3(); } +::Klass3 getKlass3B() { return ::Klass3(); } + +Klass4 getKlass4A() { return ::Klass4(); } +::Klass4 getKlass4B() { return ::Klass4(); } + +Klass5 getKlass5A() { return ::Klass5(); } +::Klass5 getKlass5B() { return ::Klass5(); } + +Klass6 getKlass6A() { return ::Klass6(); } +::Klass6 getKlass6B() { return ::Klass6(); } + +Klass7 getKlass7A() { return ::Klass7(); } +::Klass7 getKlass7B() { return ::Klass7(); } +%} diff --git a/Examples/test-suite/go/char_binary_runme.go b/Examples/test-suite/go/char_binary_runme.go new file mode 100644 index 000000000..50f2e121d --- /dev/null +++ b/Examples/test-suite/go/char_binary_runme.go @@ -0,0 +1,25 @@ +package main + +import . "./char_binary" + +func main() { + t := NewTest() + if t.Strlen("hile") != 4 { + print(t.Strlen("hile")) + panic("bad multi-arg typemap") + } + + if t.Strlen("hil\000") != 4 { + panic("bad multi-arg typemap") + } + + // creating a raw char* + pc := New_pchar(5) + Pchar_setitem(pc, 0, 'h') + Pchar_setitem(pc, 1, 'o') + Pchar_setitem(pc, 2, 'l') + Pchar_setitem(pc, 3, 'a') + Pchar_setitem(pc, 4, 0) + + Delete_pchar(pc) +} diff --git a/Examples/test-suite/guilescm/ext_test_external.cxx b/Examples/test-suite/guilescm/ext_test_external.cxx index 4b65f4953..713e5d2d0 100644 --- a/Examples/test-suite/guilescm/ext_test_external.cxx +++ b/Examples/test-suite/guilescm/ext_test_external.cxx @@ -10,7 +10,7 @@ SCM test_create() newobj = new A(); type = SWIG_TypeQuery("A *"); - result = SWIG_NewPointerObj(result, type, 1); + result = SWIG_NewPointerObj(newobj, type, 1); return result; #undef FUNC_NAME diff --git a/Examples/test-suite/immutable.i b/Examples/test-suite/immutable_values.i index ff5081e9c..1c1978661 100644 --- a/Examples/test-suite/immutable.i +++ b/Examples/test-suite/immutable_values.i @@ -1,6 +1,6 @@ // test to make sure setters are not generated for constants -%module immutable +%module immutable_values %immutable; diff --git a/Examples/test-suite/import_nomodule.i b/Examples/test-suite/import_nomodule.i index a1ba9ad7a..4fd5cbf65 100644 --- a/Examples/test-suite/import_nomodule.i +++ b/Examples/test-suite/import_nomodule.i @@ -8,16 +8,16 @@ %import "import_nomodule.h" -#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP) +#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP) && !defined(SWIGD) /** * The proxy class does not have Bar derived from Foo, yet an instance of Bar * can successfully be passed to a proxy function taking a Foo pointer (for some * language modules). * - * This violation of the type system is not possible in Java and C# due to static - * type checking. It's also not (currently) possible in Ruby, but this may be - * fixable (needs more investigation). + * This violation of the type system is not possible in Java, C# and D due to + * static type checking. It's also not (currently) possible in Ruby, but this may + * be fixable (needs more investigation). */ %newobject create_Foo; diff --git a/Examples/test-suite/inherit_target_language.i b/Examples/test-suite/inherit_target_language.i index 20fb93fda..88801f3f6 100644 --- a/Examples/test-suite/inherit_target_language.i +++ b/Examples/test-suite/inherit_target_language.i @@ -1,4 +1,4 @@ -// Test using a target language specified base class, primarily for Java/C# and possibly other single inheritance languages +// Test using a target language specified base class, primarily for Java/C#/D and possibly other single inheritance languages // Note the multiple inheritance warnings don't appear because of the two techniques used in here: typemaps and %ignore @@ -6,6 +6,8 @@ #if defined(SWIGJAVA) # define csbase javabase +#elif defined(SWIGD) +# define csbase dbase #endif %pragma(csharp) moduleimports=%{ @@ -20,6 +22,10 @@ class TargetLanguageBase { public void targetLanguageBaseMethod() {} }; class TargetLanguageBase2 { public void targetLanguageBase2Method() {} }; %} +%pragma(d) globalproxyimports=%{ +private class TargetLanguageBase { public void targetLanguageBaseMethod() {} }; +private class TargetLanguageBase2 { public void targetLanguageBase2Method() {} }; +%} %typemap(csbase) SWIGTYPE "TargetLanguageBase" diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index ba225f6e9..1ba888fc1 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -7,8 +7,8 @@ JAVA = java JAVAC = javac SCRIPTSUFFIX = _runme.java srcdir = @srcdir@ -top_srcdir = @top_srcdir@/.. -top_builddir = @top_builddir@/.. +top_srcdir = ../@top_srcdir@ +top_builddir = ../@top_builddir@ C_TEST_CASES = \ java_lib_arrays \ diff --git a/Examples/test-suite/java/char_binary_runme.java b/Examples/test-suite/java/char_binary_runme.java new file mode 100644 index 000000000..9227f8617 --- /dev/null +++ b/Examples/test-suite/java/char_binary_runme.java @@ -0,0 +1,24 @@ +import char_binary.*; + +public class char_binary_runme { + + static { + try { + System.loadLibrary("char_binary"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + Test t = new Test(); + byte[] hile = "hile".getBytes(); + byte[] hil0 = "hil\0".getBytes(); + if (t.strlen(hile) != 4) + throw new RuntimeException("bad multi-arg typemap"); + + if (t.strlen(hil0) != 4) + throw new RuntimeException("bad multi-arg typemap"); + } +} diff --git a/Examples/test-suite/java/director_protected_runme.java b/Examples/test-suite/java/director_protected_runme.java index 464b4d4d9..63ac03502 100644 --- a/Examples/test-suite/java/director_protected_runme.java +++ b/Examples/test-suite/java/director_protected_runme.java @@ -19,6 +19,7 @@ public class director_protected_runme { Foo f = b.create(); director_protected_FooBar fb = new director_protected_FooBar(); director_protected_FooBar2 fb2 = new director_protected_FooBar2(); + director_protected_FooBar3 fb3 = new director_protected_FooBar3(); { String s = fb.used(); @@ -60,11 +61,34 @@ public class director_protected_runme { if ( !Modifier.isProtected(method.getModifiers()) ) throw new RuntimeException("Foo::ping should be protected" ); + method = b.getClass().getDeclaredMethod("cheer", (java.lang.Class[])null); + if ( !Modifier.isProtected(method.getModifiers()) ) + throw new RuntimeException("Bar::cheer should be protected" ); + + method = f.getClass().getDeclaredMethod("cheer", (java.lang.Class[])null); + if ( !Modifier.isProtected(method.getModifiers()) ) + throw new RuntimeException("Foo::cheer should be protected" ); + } catch (NoSuchMethodException n) { - throw new RuntimeException("NoSuchmethodException caught. Test failed."); + throw new RuntimeException(n); } catch (SecurityException s) { throw new RuntimeException("SecurityException caught. Test failed."); } + + if (!fb3.cheer().equals("director_protected_FooBar3::cheer();")) + throw new RuntimeException("bad fb3::cheer"); + + if (!fb2.callping().equals("director_protected_FooBar2::ping();")) + throw new RuntimeException("bad fb2.callping"); + + if (!fb2.callcheer().equals("director_protected_FooBar2::pang();Bar::pong();Foo::pong();director_protected_FooBar2::ping();")) + throw new RuntimeException("bad fb2.callcheer"); + + if (!fb3.callping().equals("Bar::ping();")) + throw new RuntimeException("bad fb3.callping"); + + if (!fb3.callcheer().equals("director_protected_FooBar3::cheer();")) + throw new RuntimeException("bad fb3.callcheer"); } } @@ -83,3 +107,9 @@ class director_protected_FooBar2 extends Bar { } } +class director_protected_FooBar3 extends Bar { + public String cheer() { + return "director_protected_FooBar3::cheer();"; + } +} + diff --git a/Examples/test-suite/java/global_namespace_runme.java b/Examples/test-suite/java/global_namespace_runme.java index faab7d4ba..205e149b0 100644 --- a/Examples/test-suite/java/global_namespace_runme.java +++ b/Examples/test-suite/java/global_namespace_runme.java @@ -13,8 +13,38 @@ public class global_namespace_runme { public static void main(String argv[]) { - KlassMethods.methodA(new Klass1(), new Klass2(), new Klass3(), new Klass4(), new Klass5(), new Klass6(), new Klass7()); - KlassMethods.methodB(new Klass1(), new Klass2(), new Klass3(), new Klass4(), new Klass5(), new Klass6(), new Klass7()); + Klass1 k1 = new Klass1(); + Klass2 k2 = new Klass2(); + Klass3 k3 = new Klass3(); + Klass4 k4 = new Klass4(); + Klass5 k5 = new Klass5(); + Klass6 k6 = new Klass6(); + Klass7 k7 = new Klass7(); + + KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7); + KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7); + + k1 = global_namespace.getKlass1A(); + k2 = global_namespace.getKlass2A(); + k3 = global_namespace.getKlass3A(); + k4 = global_namespace.getKlass4A(); + k5 = global_namespace.getKlass5A(); + k6 = global_namespace.getKlass6A(); + k7 = global_namespace.getKlass7A(); + + KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7); + KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7); + + k1 = global_namespace.getKlass1B(); + k2 = global_namespace.getKlass2B(); + k3 = global_namespace.getKlass3B(); + k4 = global_namespace.getKlass4B(); + k5 = global_namespace.getKlass5B(); + k6 = global_namespace.getKlass6B(); + k7 = global_namespace.getKlass7B(); + + KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7); + KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7); XYZMethods.methodA(new XYZ1(), new XYZ2(), new XYZ3(), new XYZ4(), new XYZ5(), new XYZ6(), new XYZ7()); XYZMethods.methodB(new XYZ1(), new XYZ2(), new XYZ3(), new XYZ4(), new XYZ5(), new XYZ6(), new XYZ7()); diff --git a/Examples/test-suite/java/pointer_reference_runme.java b/Examples/test-suite/java/pointer_reference_runme.java index e8bd6800e..284951611 100644 --- a/Examples/test-suite/java/pointer_reference_runme.java +++ b/Examples/test-suite/java/pointer_reference_runme.java @@ -19,5 +19,8 @@ public class pointer_reference_runme { Struct ss = new Struct(20); pointer_reference.set(ss); if (Struct.getInstance().getValue() != 20) throw new RuntimeException("set test failed"); + + if (pointer_reference.overloading(1) != 111) throw new RuntimeException("overload test 1 failed"); + if (pointer_reference.overloading(ss) != 222) throw new RuntimeException("overload test 2 failed"); } } diff --git a/Examples/test-suite/java/preproc_line_file_runme.java b/Examples/test-suite/java/preproc_line_file_runme.java new file mode 100644 index 000000000..c29cef680 --- /dev/null +++ b/Examples/test-suite/java/preproc_line_file_runme.java @@ -0,0 +1,68 @@ +import preproc_line_file.*; + +public class preproc_line_file_runme { + + static { + try { + System.loadLibrary("preproc_line_file"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static String FILENAME_WINDOWS = "..\\..\\..\\..\\Examples\\test-suite\\preproc_line_file.i"; + public static String FILENAME_UNIX = "../../../../Examples/test-suite/preproc_line_file.i"; + public static void main(String argv[]) throws Throwable + { + int myline = preproc_line_file.MYLINE; + int myline_adjusted = preproc_line_file.MYLINE_ADJUSTED; + if (myline != 4) + throw new RuntimeException("preproc failure"); + if (myline + 100 + 1 != myline_adjusted) + throw new RuntimeException("preproc failure"); + + String myfile = preproc_line_file.MYFILE; + String myfile_adjusted = preproc_line_file.MYFILE_ADJUSTED; + if (!(myfile.equals(FILENAME_UNIX) || myfile.equals(FILENAME_WINDOWS))) + throw new RuntimeException("preproc failure"); + + if (!(myfile_adjusted.equals(FILENAME_UNIX + ".bak") || myfile_adjusted.equals(FILENAME_WINDOWS + ".bak"))) + throw new RuntimeException("preproc failure"); + + if (!preproc_line_file.MY_STRINGNUM_A.equals("my15")) + throw new RuntimeException("preproc failed MY_STRINGNUM_A"); + + if (!preproc_line_file.MY_STRINGNUM_B.equals("my16")) + throw new RuntimeException("preproc failed MY_STRINGNUM_B"); + + if (preproc_line_file.getThing27() != -1) + throw new RuntimeException("preproc failure"); + + if (preproc_line_file.getThing28() != -2) + throw new RuntimeException("preproc failure"); + + if (preproc_line_file.MYLINE2 != 30) + throw new RuntimeException("preproc failure"); + + if (SillyStruct.LINE_NUMBER != 52) + throw new RuntimeException("preproc failure"); + + if (SillyMacroClass.LINE_NUM != 56) + throw new RuntimeException("preproc failure"); + + if (SillyMultipleMacroStruct.LINE_NUM != 81) + throw new RuntimeException("preproc failure"); + + if (preproc_line_file.INLINE_LINE != 87) + throw new RuntimeException("preproc failure"); + + String inlineFile = preproc_line_file.INLINE_FILE; + if (!(inlineFile.equals(FILENAME_UNIX) || inlineFile.equals(FILENAME_WINDOWS))) + throw new RuntimeException("preproc failure"); + + if (Slash.LINE_NUM != 93) + throw new RuntimeException("preproc failure"); + + } +} diff --git a/Examples/test-suite/java/rename_pcre_encoder_runme.java b/Examples/test-suite/java/rename_pcre_encoder_runme.java new file mode 100644 index 000000000..cb843338b --- /dev/null +++ b/Examples/test-suite/java/rename_pcre_encoder_runme.java @@ -0,0 +1,14 @@ +import rename_pcre_encoder.*; + +public class rename_pcre_encoder_runme { + static { System.loadLibrary("rename_pcre_encoder"); } + + public static void main(String argv[]) + { + SomeWidget w = new SomeWidget(); + w.putBorderWidth(17); + if ( w.getBorderWidth() != 17 ) + throw new RuntimeException(String.format("Border with should be 17, not %d", + w.getBorderWidth())); + } +} diff --git a/Examples/test-suite/java/rename_pcre_enum_runme.java b/Examples/test-suite/java/rename_pcre_enum_runme.java new file mode 100644 index 000000000..a8bfef46a --- /dev/null +++ b/Examples/test-suite/java/rename_pcre_enum_runme.java @@ -0,0 +1,26 @@ +import rename_pcre_enum.*; + +public class rename_pcre_enum_runme { + static { System.loadLibrary("rename_pcre_enum"); } + + public static void main(String argv[]) + { + Foo foo = Foo.First; + if ( foo == Foo.Second ) + throw new RuntimeException("Enum values should be different"); + + // Check that Foo_Max enum element was ignored. + int numFooEnumElements = Foo.values().length; + if ( numFooEnumElements != 2 ) + throw new RuntimeException(String.format("Enum should have 2 elements, not %d", + numFooEnumElements)); + + BoundaryCondition bc = BoundaryCondition.MaxMax; + if ( bc.ordinal() != 2 ) + throw new RuntimeException("Wrong enum value"); + + Colour c = Colour.red; + if ( c == Colour.blue ) + throw new RuntimeException("Enum values should be different"); + } +} diff --git a/Examples/test-suite/java/rname_runme.java b/Examples/test-suite/java/rname_runme.java index 7f2ab2f75..dac0a1ecf 100644 --- a/Examples/test-suite/java/rname_runme.java +++ b/Examples/test-suite/java/rname_runme.java @@ -30,7 +30,7 @@ public class rname_runme { throw new RuntimeException("base.newname"); RenamedDerived derived = new RenamedDerived(); - derived.func(base, base, base); + derived.Xfunc(base, base, base); if (!derived.newname(10.0).equals("Derived")) throw new RuntimeException("derived.newname"); } diff --git a/Examples/test-suite/java/smart_pointer_const_overload_runme.java b/Examples/test-suite/java/smart_pointer_const_overload_runme.java new file mode 100644 index 000000000..bb4ae2c8f --- /dev/null +++ b/Examples/test-suite/java/smart_pointer_const_overload_runme.java @@ -0,0 +1,99 @@ +import smart_pointer_const_overload.*; + +public class smart_pointer_const_overload_runme { + static int CONST_ACCESS = 1; + static int MUTABLE_ACCESS = 2; + + static { + System.loadLibrary("smart_pointer_const_overload"); + } + + public static void test(Bar b, Foo f) { + Assert(f.getX() == 0); + + // Test member variable get + Assert(b.getX() == 0); + Assert(f.getAccess() == CONST_ACCESS); + + // Test member variable set + b.setX(1); + Assert(f.getX() == 1); + Assert(f.getAccess() == MUTABLE_ACCESS); + + // Test const method + Assert(b.getx() == 1); + Assert(f.getAccess() == CONST_ACCESS); + + // Test mutable method + b.setx(2); + + Assert(f.getX() == 2); + Assert(f.getAccess() == MUTABLE_ACCESS); + + // Test extended const method + Assert(b.getx2() == 2); + Assert(f.getAccess() == CONST_ACCESS); + + // Test extended mutable method + b.setx2(3); + + Assert(f.getX() == 3); + Assert(f.getAccess() == MUTABLE_ACCESS); + + // Test static method + b.stat(); + + Assert(f.getAccess() == CONST_ACCESS); + + // Test const member + f.setAccess(MUTABLE_ACCESS); + + Assert(b.getY() == 0); + Assert(f.getAccess() == CONST_ACCESS); + + // Test get through mutable pointer to const member + f.setAccess(MUTABLE_ACCESS); + + Assert(smart_pointer_const_overload.get_int(b.getYp()) == 0); + Assert(f.getAccess() == CONST_ACCESS); + + // Test get through const pointer to mutable member + f.setX(4); + f.setAccess(MUTABLE_ACCESS); + + Assert(smart_pointer_const_overload.get_int(b.getXp()) == 4); + Assert(f.getAccess() == CONST_ACCESS); + + // Test set through const pointer to mutable member + f.setAccess(MUTABLE_ACCESS); + smart_pointer_const_overload.set_int(b.getXp(), 5); + + Assert(f.getX() == 5); + Assert(f.getAccess() == CONST_ACCESS); + + // Test set pointer to const member + b.setYp(smart_pointer_const_overload.new_int(6)); + + Assert(f.getY() == 0); + Assert(smart_pointer_const_overload.get_int(f.getYp()) == 6); + Assert(f.getAccess() == MUTABLE_ACCESS); + + smart_pointer_const_overload.delete_int(f.getYp()); + } + + public static void main(String argv[]) { + Foo f = new Foo(); + Bar b = new Bar(f); + + //Foo f2 = new Foo(); + //Bar b2 = new Bar2(f2); + + test(b, f); + //test(b2, f2); + } + + public static void Assert(boolean b) { + if (!b) + throw new RuntimeException("Assertion failed"); + } +} diff --git a/Examples/test-suite/java/typemap_arrays_runme.java b/Examples/test-suite/java/typemap_arrays_runme.java new file mode 100644 index 000000000..1ca062f78 --- /dev/null +++ b/Examples/test-suite/java/typemap_arrays_runme.java @@ -0,0 +1,19 @@ +import typemap_arrays.*; + +public class typemap_arrays_runme { + + static { + try { + System.loadLibrary("typemap_arrays"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + if (typemap_arrays.sumA(null) != 60) + throw new RuntimeException("Sum is wrong"); + } +} + diff --git a/Examples/test-suite/java/wallkw_runme.java b/Examples/test-suite/java/wallkw_runme.java index 028c2a32f..7695cda24 100644 --- a/Examples/test-suite/java/wallkw_runme.java +++ b/Examples/test-suite/java/wallkw_runme.java @@ -19,7 +19,9 @@ public class wallkw_runme { throw new RuntimeException("delegate keyword fail"); if (!wallkw._pass().equals("pass")) throw new RuntimeException("pass keyword fail"); - if (!wallkw.C_alias().equals("alias")) + if (!wallkw._alias().equals("alias")) throw new RuntimeException("alias keyword fail"); + if (!wallkw.C_rescue().equals("rescue")) + throw new RuntimeException("rescue keyword fail"); } } diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index f92df23a9..3d474ec00 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -34,7 +34,7 @@ # define SWIG_SHARED_PTR_NAMESPACE SwigBoost #endif -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif @@ -45,6 +45,7 @@ %shared_ptr(Space::KlassDerived) %shared_ptr(Space::Klass2ndDerived) %shared_ptr(Space::Klass3rdDerived) +%shared_ptr(IgnoredMultipleInheritBase) // IgnoredMultipleInheritBase not actually used in any wrapped functions, so this isn't entirely necessary and warning 520 could instead have been suppressed. #endif diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i index 610edb4b4..2232b6cf6 100644 --- a/Examples/test-suite/li_boost_shared_ptr_bits.i +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i @@ -1,6 +1,6 @@ %module li_boost_shared_ptr_bits -#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD) #define SHARED_PTR_WRAPPERS_IMPLEMENTED #endif diff --git a/Examples/test-suite/li_std_combinations.i b/Examples/test-suite/li_std_combinations.i index 9acc8f23d..57f945bcd 100644 --- a/Examples/test-suite/li_std_combinations.i +++ b/Examples/test-suite/li_std_combinations.i @@ -14,7 +14,7 @@ %template(VectorVectorString) std::vector< std::vector<std::string> >; %template(PairIntPairIntString) std::pair< int, std::pair<int, std::string> >; -#if defined(SWIGCSHARP) +#if defined(SWIGCSHARP) || defined(SWIGD) // Checks macro containing a type with a comma SWIG_STD_VECTOR_ENHANCED(std::pair< double, std::string >) #endif diff --git a/Examples/test-suite/li_typemaps_apply.i b/Examples/test-suite/li_typemaps_apply.i new file mode 100644 index 000000000..ecb3f87b6 --- /dev/null +++ b/Examples/test-suite/li_typemaps_apply.i @@ -0,0 +1,46 @@ +%module li_typemaps_apply + +// Test %apply to global primitive type references/pointers to make sure the return types are still okay... mainly for the strongly typed languages. + +%include "typemaps.i" + +#if !defined(SWIGJAVA) // Needs asymmetric type marshalling support for this testcase to work + +%define TMAPS(PRIMTYPE, NAME) +%apply PRIMTYPE *INPUT { PRIMTYPE * } +%apply PRIMTYPE &INPUT { PRIMTYPE & } +%inline %{ +PRIMTYPE *input_ptr_##NAME(PRIMTYPE *v) { static PRIMTYPE stat; stat = *v; return &stat; } +PRIMTYPE &input_ref_##NAME(PRIMTYPE &v) { static PRIMTYPE stat; stat = v; return stat; } +%} + +%apply PRIMTYPE *OUTPUT { PRIMTYPE * } +%apply PRIMTYPE &OUTPUT { PRIMTYPE & } +%inline %{ +PRIMTYPE *output_ptr_##NAME(PRIMTYPE x, PRIMTYPE *v) { static PRIMTYPE stat; stat = x; *v = x; return &stat; } +PRIMTYPE &output_ref_##NAME(PRIMTYPE x, PRIMTYPE &v) { static PRIMTYPE stat; stat = x; v = x; return stat; } +%} + +%apply PRIMTYPE *INOUT { PRIMTYPE * } +%apply PRIMTYPE &INOUT { PRIMTYPE & } +%inline %{ +PRIMTYPE *inout_ptr_##NAME(PRIMTYPE *v) { static PRIMTYPE stat; stat = *v; *v = *v; return &stat; } +PRIMTYPE &inout_ref_##NAME(PRIMTYPE &v) { static PRIMTYPE stat; stat = v; v = v; return stat; } +%} +%enddef + +TMAPS(bool, bool) +TMAPS(int, int) +TMAPS(short, short) +TMAPS(long, long) +TMAPS(unsigned int, uint) +TMAPS(unsigned short, ushort) +TMAPS(unsigned long, ulong) +TMAPS(unsigned char, uchar) +TMAPS(signed char, schar) +TMAPS(float, float) +TMAPS(double, double) +TMAPS(long long, longlong) +TMAPS(unsigned long long, ulonglong) + +#endif diff --git a/Examples/test-suite/lua/pointer_reference_runme.lua b/Examples/test-suite/lua/pointer_reference_runme.lua index 959d5a2a3..428c76998 100644 --- a/Examples/test-suite/lua/pointer_reference_runme.lua +++ b/Examples/test-suite/lua/pointer_reference_runme.lua @@ -9,3 +9,5 @@ ss = pointer_reference.Struct(20); pointer_reference.set(ss); assert(pointer_reference.Struct_instance.value == 20) +assert(pointer_reference.overloading(1) == 111) +assert(pointer_reference.overloading(ss) == 222) diff --git a/Examples/test-suite/member_funcptr_galore.i b/Examples/test-suite/member_funcptr_galore.i new file mode 100644 index 000000000..cc626bfc4 --- /dev/null +++ b/Examples/test-suite/member_funcptr_galore.i @@ -0,0 +1,83 @@ +%module member_funcptr_galore + +%inline %{ + +namespace FunkSpace { +struct Funktions { + int addByValue(const int &a, int b) { return a+b; } + int * addByPointer(const int &a, int b) { static int val; val = a+b; return &val; } + int & addByReference(const int &a, int b) { static int val; val = a+b; return val; } +}; +} + +template <typename T> struct Thing {}; +namespace Space { +class Shape { +public: + double x, y; + double *z; + + void move(double dx, double dy); + virtual double area(Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int)) { return 0.0; } + virtual double abc(Thing<short> ts, Thing< const Space::Shape * > tda[]) { return 0.0; } +}; +} + +extern double do_op(Space::Shape *s, double (Space::Shape::*m)(void)); + +/* Functions that return member pointers */ + +extern double (Space::Shape::*areapt())(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)); +extern double (Space::Shape::*abcpt())(Thing<short>, Thing< const Space::Shape * > tda[]); + +/* Global variables that are member pointers */ +extern double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)); +extern double (Space::Shape::*abcvar)(Thing<short>, Thing< const Space::Shape * >[]); + +%} + +%{ +void Space::Shape::move(double dx, double dy) { + x += dx; + y += dy; +} + +double do_op(Space::Shape *s, double (Space::Shape::*m)(void)) { + return (s->*m)(); +} + +double (Space::Shape::*areapt(Space::Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int)))(Space::Shape &, int & (FunkSpace::Funktions::*d)(const int &, int)) { + return &Space::Shape::area; +} + +double (Space::Shape::*abcpt())(Thing<short>, Thing< const Space::Shape * >[]) { + return &Space::Shape::abc; +} + +/* Member pointer variables */ +double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area; +double (Space::Shape::*abcvar)(Thing<short>, Thing< const Space::Shape * >[]) = &Space::Shape::abc; +%} + + +/* Some constants */ +%constant double (Space::Shape::*AREAPT)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area; +%constant double (Space::Shape::*PERIMPT)(Thing<short>, Thing< const Space::Shape * >[]) = &Space::Shape::abc; +%constant double (Space::Shape::*NULLPT)(void) = 0; + +%inline %{ + +int call1(int (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); } +int call2(int * (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return *(f.*d)(a, b); } +int call3(int & (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); } +%} + +%constant int (FunkSpace::Funktions::*ADD_BY_VALUE)(const int &, int) = &FunkSpace::Funktions::addByValue; +%constant int * (FunkSpace::Funktions::*ADD_BY_POINTER)(const int &, int) = &FunkSpace::Funktions::addByPointer; +%constant int & (FunkSpace::Funktions::*ADD_BY_REFERENCE)(const int &, int) = &FunkSpace::Funktions::addByReference; + +%inline %{ +// parameter that is a member pointer containing a function ptr, urgh :) +int unreal1(double (Space::Shape::*memptr)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int))) { return 0; } +int unreal2(double (Space::Shape::*memptr)(Thing<short>)) { return 0; } +%} diff --git a/Examples/test-suite/minherit2.i b/Examples/test-suite/minherit2.i index 1bca4fc48..7d470d30e 100644 --- a/Examples/test-suite/minherit2.i +++ b/Examples/test-suite/minherit2.i @@ -1,16 +1,18 @@ %module minherit2 -// A multiple inheritance example, mainly for Java and C#. -// The example shows how it is possible to turn C++ abstract base classes into Java/C# interface. +// A multiple inheritance example, mainly for Java, C# and D. +// The example shows how it is possible to turn C++ abstract base classes into +// Java/C#/D interfaces. // In the future, all this trouble might be more automated. %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, + SWIGWARN_D_MULTIPLE_INHERITANCE, SWIGWARN_RUBY_MULTIPLE_INHERITANCE, SWIGWARN_PHP_MULTIPLE_INHERITANCE) RemoteMpe; -#if defined(SWIGJAVA) || defined(SWIGCSHARP) +#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) #if defined(SWIGCSHARP) #define javaclassmodifiers csclassmodifiers @@ -22,6 +24,21 @@ #define javabase csbase #endif +#if defined(SWIGD) +#define javaclassmodifiers dclassmodifiers +#define javabody dbody +#define javafinalize ddestructor +#define javadestruct ddispose +#define javaout dout +#define javainterfaces dinterfaces +#define javabase dbase + +%typemap(dimports) RemoteMpe %{ +$importtype(IRemoteSyncIO) +$importtype(IRemoteAsyncIO) +%} +#endif + // Modify multiple inherited base classes into inheriting interfaces %typemap(javainterfaces) RemoteMpe "IRemoteSyncIO, IRemoteAsyncIO"; %typemap(javabase, replace="1") RemoteMpe ""; @@ -51,6 +68,12 @@ // Features are inherited by derived classes, so override this %csmethodmodifiers RemoteMpe::syncmethod "public" %csmethodmodifiers RemoteMpe::asyncmethod "public" +#elif defined(SWIGD) +%dmethodmodifiers IRemoteSyncIO::syncmethod ""; +%dmethodmodifiers IRemoteAsyncIO::asyncmethod ""; +// Features are inherited by derived classes, so override this +%dmethodmodifiers RemoteMpe::syncmethod "public" +%dmethodmodifiers RemoteMpe::asyncmethod "public" #endif #endif diff --git a/Examples/test-suite/multiple_inheritance.i b/Examples/test-suite/multiple_inheritance.i index 1fc68eef9..044345020 100644 --- a/Examples/test-suite/multiple_inheritance.i +++ b/Examples/test-suite/multiple_inheritance.i @@ -5,11 +5,13 @@ It tests basic multiple inheritance */ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; /* C#, D, Java, PHP multiple inheritance */ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBarSpam; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBarSpam; /* C#, D, Java, PHP multiple inheritance */ %inline %{ diff --git a/Examples/test-suite/namespace_class.i b/Examples/test-suite/namespace_class.i index 7dc9139cd..aea5362d1 100644 --- a/Examples/test-suite/namespace_class.i +++ b/Examples/test-suite/namespace_class.i @@ -2,6 +2,10 @@ %warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Ala::Ola; +#ifdef SWIGD +%warnfilter(SWIGWARN_IGNORE_OPERATOR_LT); +#endif + %inline %{ template<class T> void foobar(T t) {} namespace test { diff --git a/Examples/test-suite/octave/primitive_types_runme.m b/Examples/test-suite/octave/primitive_types_runme.m deleted file mode 100644 index 568e3511e..000000000 --- a/Examples/test-suite/octave/primitive_types_runme.m +++ /dev/null @@ -1,402 +0,0 @@ -primitive_types - -var_init(); - -# assigning globals calls -cvar.var_bool = sct_bool; -cvar.var_schar = sct_schar; -cvar.var_uchar = sct_uchar; -cvar.var_int = sct_int; -cvar.var_uint = sct_uint; -cvar.var_short = sct_short; -cvar.var_ushort = sct_ushort; -cvar.var_long = sct_long; -cvar.var_ulong = sct_ulong; -cvar.var_llong = sct_llong; -cvar.var_ullong = sct_ullong; -cvar.var_char = sct_char; -cvar.var_pchar = sct_pchar; -cvar.var_pcharc = sct_pcharc; -cvar.var_pint = sct_pint; -cvar.var_sizet = sct_sizet; -cvar.var_hello = sct_hello; -cvar.var_myint = sct_myint; -cvar.var_namet = def_namet; -cvar.var_parami = sct_parami; -cvar.var_paramd = sct_paramd; -cvar.var_paramc = sct_paramc; - -v_check(); - -function octerror(name, val, cte) - name, val, cte - error -endfunction - -if cvar.var_bool != cct_bool: -octerror("bool", cvar.var_bool, cct_bool) -endif -if cvar.var_schar != cct_schar: -octerror("schar", cvar.var_schar, cct_schar) -endif -if cvar.var_uchar != cct_uchar: - octerror("uchar", cvar.var_uchar, cct_uchar) -endif -if cvar.var_int != cct_int: - octerror("int", cvar.var_int, cct_int) -endif -if cvar.var_uint != cct_uint: - octerror("uint", cvar.var_uint, cct_uint) -endif -if cvar.var_short != cct_short: - octerror("short", cvar.var_short, cct_short) -endif -if cvar.var_ushort != cct_ushort: - octerror("ushort", cvar.var_ushort, cct_ushort) -endif -if cvar.var_long != cct_long: - octerror("long", cvar.var_long, cct_long) -endif -if cvar.var_ulong != cct_ulong: - octerror("ulong", cvar.var_ulong, cct_ulong) -endif -if cvar.var_llong != cct_llong: - octerror("llong", cvar.var_llong, cct_llong) -endif -if cvar.var_ullong != cct_ullong: - octerror("ullong", cvar.var_ullong, cct_ullong) -endif -if cvar.var_char != cct_char: - octerror("char", cvar.var_char, cct_char) -endif -if cvar.var_pchar != cct_pchar: - octerror("pchar", cvar.var_pchar, cct_pchar) -endif -if cvar.var_pcharc != cct_pcharc: - octerror("pchar", cvar.var_pcharc, cct_pcharc) -endif -if cvar.var_pint != cct_pint: - octerror("pint", cvar.var_pint, cct_pint) -endif -if cvar.var_sizet != cct_sizet: - octerror("sizet", cvar.var_sizet, cct_sizet) -endif -if cvar.var_hello != cct_hello: - octerror("hello", cvar.var_hello, cct_hello) -endif -if cvar.var_myint != cct_myint: - octerror("myint", cvar.var_myint, cct_myint) -endif -if cvar.var_namet != def_namet: - octerror("name", cvar.var_namet, def_namet) -endif - - -function OctTest() - self=subclass(TestDirector); - self.ident=@(self,x) x; - - self.vval_bool=@(self, x) self.ident(x); - self.vval_schar=@(self, x) self.ident(x); - self.vval_uchar=@(self, x) self.ident(x); - self.vval_int=@(self, x) self.ident(x); - self.vval_uint=@(self, x) self.ident(x); - self.vval_short=@(self, x) self.ident(x); - self.vval_ushort=@(self, x) self.ident(x); - self.vval_long=@(self, x) self.ident(x); - self.vval_ulong=@(self, x) self.ident(x); - self.vval_llong=@(self, x) self.ident(x); - self.vval_ullong=@(self, x) self.ident(x); - self.vval_float=@(self, x) self.ident(x); - self.vval_double=@(self, x) self.ident(x); - self.vval_char=@(self, x) self.ident(x); - self.vval_pchar=@(self, x) self.ident(x); - self.vval_pcharc=@(self, x) self.ident(x); - self.vval_pint=@(self, x) self.ident(x); - self.vval_sizet=@(self, x) self.ident(x); - self.vval_hello=@(self, x) self.ident(x); - self.vval_myint=@(self, x) self.ident(x); - - self.vref_bool=@(self, x) self.ident(x); - self.vref_schar=@(self, x) self.ident(x); - self.vref_uchar=@(self, x) self.ident(x); - self.vref_int=@(self, x) self.ident(x); - self.vref_uint=@(self, x) self.ident(x); - self.vref_short=@(self, x) self.ident(x); - self.vref_ushort=@(self, x) self.ident(x); - self.vref_long=@(self, x) self.ident(x); - self.vref_ulong=@(self, x) self.ident(x); - self.vref_llong=@(self, x) self.ident(x); - self.vref_ullong=@(self, x) self.ident(x); - self.vref_float=@(self, x) self.ident(x); - self.vref_double=@(self, x) self.ident(x); - self.vref_char=@(self, x) self.ident(x); - self.vref_pchar=@(self, x) self.ident(x); - self.vref_pcharc=@(self, x) self.ident(x); - self.vref_pint=@(self, x) self.ident(x); - self.vref_sizet=@(self, x) self.ident(x); - self.vref_hello=@(self, x) self.ident(x); - self.vref_myint=@(self, x) self.ident(x); -endfunction - - -t = Test(); -p = OctTest(); - - -# internal call check -if (t.c_check() != p.c_check()) - error, "bad director" -endif - -p.var_bool = p.stc_bool; -p.var_schar = p.stc_schar; -p.var_uchar = p.stc_uchar; -p.var_int = p.stc_int; -p.var_uint = p.stc_uint; -p.var_short = p.stc_short; -p.var_ushort = p.stc_ushort; -p.var_long = p.stc_long; -p.var_ulong = p.stc_ulong; -p.var_llong = p.stc_llong; -p.var_ullong = p.stc_ullong; -p.var_char = p.stc_char; -p.var_pchar = sct_pchar; -p.var_pcharc = sct_pcharc; -p.var_pint = sct_pint; -p.var_sizet = sct_sizet; -p.var_hello = sct_hello; -p.var_myint = sct_myint; -p.var_namet = def_namet; -p.var_parami = sct_parami; -p.var_paramd = sct_paramd; -p.var_paramc = sct_paramc; - -p.v_check(); - -t.var_bool = t.stc_bool; -t.var_schar = t.stc_schar; -t.var_uchar = t.stc_uchar; -t.var_int = t.stc_int; -t.var_uint = t.stc_uint; -t.var_short = t.stc_short; -t.var_ushort = t.stc_ushort; -t.var_long = t.stc_long; -t.var_ulong = t.stc_ulong; -t.var_llong = t.stc_llong; -t.var_ullong = t.stc_ullong; -t.var_char = t.stc_char; -t.var_pchar = sct_pchar; -t.var_pcharc = sct_pcharc; -t.var_pint = sct_pint; -t.var_sizet = sct_sizet; -t.var_hello = sct_hello; -t.var_myint = sct_myint; -t.var_namet = def_namet; -t.var_parami = sct_parami; -t.var_paramd = sct_paramd; -t.var_paramc = sct_paramc; - -t.v_check(); - -# this value contains a '0' char! -if (def_namet != 'ho\0la') - error -endif - -t.var_namet = def_namet; -if (t.var_namet != def_namet) - error -endif - -t.var_namet = 'holac'; - -if (t.var_namet != 'holac') - error -endif - -t.var_namet = 'hol'; - -if (t.var_namet != 'hol') - error -endif - -if (t.strlen('hile') != 4) - error -endif - -if (t.strlen('hil\0') != 4) - error -endif - -cvar.var_char = '\0'; -if (cvar.var_char != '\0') - error -endif - -cvar.var_char = 0; -if (cvar.var_char != '\0') - error -endif - -cvar.var_namet = '\0'; -if (cvar.var_namet != '') - error -endif - -cvar.var_namet = ''; -if (cvar.var_namet != '') - error, "bad char empty case" -endif - -cvar.var_pchar = None; -if (cvar.var_pchar != None) - error, "bad None case" -endif - -cvar.var_pchar = ''; -if (cvar.var_pchar != '') - error -endif - -cvar.var_pcharc = None; -if (cvar.var_pcharc != None) - error -endif - -cvar.var_pcharc = ''; -if (cvar.var_pcharc != '') - error -endif - -# -# creating a raw char* -# -pc = new_pchar(5); -pchar_setitem(pc, 0, 'h'); -pchar_setitem(pc, 1, 'o'); -pchar_setitem(pc, 2, 'l'); -pchar_setitem(pc, 3, 'a'); -pchar_setitem(pc, 4, 0); - - -if (t.strlen(pc) != 4) - error -endif - -cvar.var_pchar = pc; -if (cvar.var_pchar != "hola") - error -endif - -cvar.var_namet = pc; -if (cvar.var_namet != "hola") - error -endif - -delete_pchar(pc); - -# -# Now when things should fail -# - -try - error = 0; - a = t.var_uchar; - t.var_uchar = 10000; - err = 1; -catch - if (a != t.var_uchar) - err = 1; - endif -end_try_catch - -if (err) - error -endif - -try - err = 0; - a = t.var_char; - t.var_char = '23'; - err = 1; -catch - if (a != t.var_char) - error = 1 - endif -end_try_catch -if (err) - error -endif - -try - err = 0 - a = t.var_uint - t.var_uint = -1 - err = 1; -catch - if a != t.var_uint: - err = 1; - endif -end_try_catch -if (err) - error -endif - -# -# -try - err = 0; - a = t.var_namet; - t.var_namet = '123456'; - err = 1; -catch - if (a != t.var_namet) - err = 1; - endif -end_try_catch -if (err) - error -endif - -# -# -# -t2 = p.vtest(t); -if (t.var_namet != t2.var_namet) - error -endif - - -if (cvar.fixsize != 'ho\0la\0\0\0') - error -endif - -cvar.fixsize = 'ho'; -if (cvar.fixsize != 'ho\0\0\0\0\0\0') - error -endif - - -f = Foo(3); -f1 = fptr_val(f); -f2 = fptr_ref(f); -if (f1._a != f2._a) - error -endif - -v = char_foo(1,3); -if (v !=3) - error -endif - -s = char_foo(1,"hello"); -if (s !="hello") - error -endif - - -v = SetPos(1,3); -if (v !=4) - error -endif diff --git a/Examples/test-suite/samename_runme.m b/Examples/test-suite/octave/samename_runme.m index a3864cfc8..a3864cfc8 100644 --- a/Examples/test-suite/samename_runme.m +++ b/Examples/test-suite/octave/samename_runme.m diff --git a/Examples/test-suite/operator_overload.i b/Examples/test-suite/operator_overload.i index 80facff76..006662109 100644 --- a/Examples/test-suite/operator_overload.i +++ b/Examples/test-suite/operator_overload.i @@ -79,6 +79,12 @@ see bottom for a set of possible tests %} #endif +#ifdef SWIGD +// Due to the way operator overloading is implemented in D1 and D2, the prefix +// increment/decrement operators (D1) resp. the postfix ones (D2) are ignored. +%warnfilter(SWIGWARN_IGNORE_OPERATOR_PLUSPLUS, SWIGWARN_IGNORE_OPERATOR_MINUSMINUS); +#endif + %rename(IntCast) operator int(); %rename(DoubleCast) operator double(); diff --git a/Examples/test-suite/operator_overload_break.i b/Examples/test-suite/operator_overload_break.i index 9c6927bb0..f5f3c1a46 100644 --- a/Examples/test-suite/operator_overload_break.i +++ b/Examples/test-suite/operator_overload_break.i @@ -1,6 +1,6 @@ %module operator_overload_break -#if defined(SWIGPYTHON) +#if defined(SWIGPYTHON) || defined(SWIGD) %warnfilter(SWIGWARN_IGNORE_OPERATOR_PLUSPLUS); #endif diff --git a/Examples/test-suite/operbool.i b/Examples/test-suite/operbool.i index 793c0174e..ee8c889e9 100644 --- a/Examples/test-suite/operbool.i +++ b/Examples/test-suite/operbool.i @@ -1,6 +1,6 @@ %module operbool -%rename(operbool) operator bool(); +%rename(operator_bool) operator bool(); %inline %{ class Test { diff --git a/Examples/test-suite/perl5/char_binary_runme.pl b/Examples/test-suite/perl5/char_binary_runme.pl new file mode 100755 index 000000000..4c50ee700 --- /dev/null +++ b/Examples/test-suite/perl5/char_binary_runme.pl @@ -0,0 +1,32 @@ +use strict; +use warnings; +use Test::More tests => 7; +BEGIN { use_ok('char_binary') } +require_ok('char_binary'); + +my $t = char_binary::Test->new(); + +is($t->strlen('hile'), 4, "string typemap"); + +is($t->strlen("hil\0"), 4, "string typemap"); + +# +# creating a raw char* +# +my $pc = char_binary::new_pchar(5); +char_binary::pchar_setitem($pc, 0, 'h'); +char_binary::pchar_setitem($pc, 1, 'o'); +char_binary::pchar_setitem($pc, 2, 'l'); +char_binary::pchar_setitem($pc, 3, 'a'); +char_binary::pchar_setitem($pc, 4, 0); + + +is($t->strlen($pc), 4, "string typemap"); + +$char_binary::var_pchar = $pc; +is($char_binary::var_pchar, "hola", "pointer case"); + +$char_binary::var_namet = $pc; +is($char_binary::var_namet, "hola", "pointer case"); + +char_binary::delete_pchar($pc); diff --git a/Examples/test-suite/perl5/primitive_types_runme.pl b/Examples/test-suite/perl5/primitive_types_runme.pl index 6d7b05d8d..31604ad06 100755 --- a/Examples/test-suite/perl5/primitive_types_runme.pl +++ b/Examples/test-suite/perl5/primitive_types_runme.pl @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 54; +use Test::More tests => 51; BEGIN { use_ok('primitive_types') } require_ok('primitive_types'); @@ -179,11 +179,6 @@ $t->{var_namet} = 'hol'; is($t->{var_namet}, 'hol', "namet"); -is($t->strlen('hile'), 4, "string typemap"); - -is($t->strlen("hil\0"), 4, "string typemap"); - - $primitive_types::var_char = "\0"; is($primitive_types::var_char, "\0", "char '0' case"); @@ -220,8 +215,6 @@ primitive_types::pchar_setitem($pc, 3, 'a'); primitive_types::pchar_setitem($pc, 4, 0); -is($t->strlen($pc), 4, "string typemap"); - $primitive_types::var_pchar = $pc; is($primitive_types::var_pchar, "hola", "pointer case"); diff --git a/Examples/test-suite/php/director_protected_runme.php b/Examples/test-suite/php/director_protected_runme.php index 73bcba1fd..9d47ef658 100644 --- a/Examples/test-suite/php/director_protected_runme.php +++ b/Examples/test-suite/php/director_protected_runme.php @@ -26,10 +26,17 @@ class FooBar2 extends Bar { } } +class FooBar3 extends Bar { + function cheer() { + return "FooBar3::cheer();"; + } +} + $b = new Bar(); $f = $b->create(); $fb = new FooBar(); $fb2 = new FooBar2(); +$fb3 = new FooBar3(); check::equal($fb->used(), "Foo::pang();Bar::pong();Foo::pong();FooBar::ping();", "bad FooBar::used"); @@ -42,7 +49,7 @@ check::equal($f->pong(), "Bar::pong();Foo::pong();Bar::ping();", "bad Foo::pong" check::equal($fb->pong(), "Bar::pong();Foo::pong();FooBar::ping();", "bad FooBar::pong"); $method = new ReflectionMethod('Bar', 'ping'); -check::equal($method->isProtected(), true, "Boo::ping should be protected"); +check::equal($method->isProtected(), true, "Foo::ping should be protected"); $method = new ReflectionMethod('Foo', 'ping'); check::equal($method->isProtected(), true, "Foo::ping should be protected"); @@ -50,5 +57,17 @@ check::equal($method->isProtected(), true, "Foo::ping should be protected"); $method = new ReflectionMethod('FooBar', 'pang'); check::equal($method->isProtected(), true, "FooBar::pang should be protected"); +$method = new ReflectionMethod('Bar', 'cheer'); +check::equal($method->isProtected(), true, "Bar::cheer should be protected"); + +$method = new ReflectionMethod('Foo', 'cheer'); +check::equal($method->isProtected(), true, "Foo::cheer should be protected"); + +check::equal($fb3->cheer(), "FooBar3::cheer();", "bad fb3::pong"); +check::equal($fb2->callping(), "FooBar2::ping();", "bad fb2::callping"); +check::equal($fb2->callcheer(), "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();", "bad fb2::callcheer"); +check::equal($fb3->callping(), "Bar::ping();", "bad fb3::callping"); +check::equal($fb3->callcheer(), "FooBar3::cheer();", "bad fb3::callcheer"); + check::done(); ?> diff --git a/Examples/test-suite/php/pointer_reference_runme.php b/Examples/test-suite/php/pointer_reference_runme.php index 782760a37..52946177e 100644 --- a/Examples/test-suite/php/pointer_reference_runme.php +++ b/Examples/test-suite/php/pointer_reference_runme.php @@ -11,5 +11,8 @@ pointer_reference::set($ss); $i = Struct::instance(); check::equal($i->value, 20, "pointer_reference::set() failed"); +check::equal(pointer_reference::overloading(1), 111, "overload test 1 failed"); +check::equal(pointer_reference::overloading($ss), 222, "overload test 2 failed"); + check::done(); ?> diff --git a/Examples/test-suite/pointer_reference.i b/Examples/test-suite/pointer_reference.i index c57a32374..b9e126fd4 100644 --- a/Examples/test-suite/pointer_reference.i +++ b/Examples/test-suite/pointer_reference.i @@ -35,6 +35,12 @@ void set(Struct *const& s) { Struct *const& get() { return Struct::pInstance; } +int overloading(int i) { + return 111; +} +int overloading(Struct *const& s) { + return 222; +} %} %{ diff --git a/Examples/test-suite/preproc_defined.i b/Examples/test-suite/preproc_defined.i new file mode 100644 index 000000000..2fa2f9856 --- /dev/null +++ b/Examples/test-suite/preproc_defined.i @@ -0,0 +1,108 @@ +%module preproc_defined + +// Check 'defined' passes through the preprocessor without being processed like '#if defined(ABC)' would be (SF bug #1940536) + +%define DEFINED_MACRO +%{ + int defined(int b) { + return b > 10; + } + int vvv = -1; + void fn(int val) { + if (defined(val)) + vvv = 1; + else + vvv = 0; + } +%} +%enddef + +DEFINED_MACRO + +%{ +int checking(void) { + fn(11); + int okay = (vvv == 1); + fn(9); + okay = okay && (vvv == 0); + return okay; /* should be 1 */ +} +%} + +%inline %{ +int call_checking(void) { + return checking(); +} +%} + +/*****************************************************************************/ +/* Check #if/#elif defined() macro expansions + Also checks #if/#elif defined() works correctly within macros... this is not + standard C, but is now relied on in the SWIG library. */ +/*****************************************************************************/ + +#define AAA +#define BBB +#define CCC + +#if defined(AAA)\ +&& defined(BBB) \ +&& defined(CCC) +%{ +void thing(int i) {} +void stuff(int i) {} +struct Defined { + int defined; +}; +void bumpf(int i) {} +%} +#else +#endif + +%define ANOTHER_MACRO(TYPE) + +#if defined(AAA) && defined(BBB) && defined(CCC) +void thing(TYPE) {} +#else +void thing_not(TYPE) {} +#endif + +#if defined(AAA) &&\ + defined(BBB) \\ +&& defined(CCC) +void stuff(TYPE) {} +#else +void stuff_not(TYPE); +#endif + +#if defined(0) +void defined_not(TYPE); +#elif defined(AAA) && defined( BBB ) && defined(CCC) +struct Defined { + int defined; +}; +#else +void defined_not(TYPE); +#endif + +#if !( defined(AAA) \ + defined(BBB) \\ +&& defined(CCC) ) +void bumpf_not(TYPE); +#else +void bumpf(TYPE) {} +#endif + +%enddef + +ANOTHER_MACRO(int) + +%{ +void another_macro_checking(void) { + struct Defined d; + d.defined = 10; + thing(10); + stuff(10); + bumpf(10); +} +%} diff --git a/Examples/test-suite/preproc_include.i b/Examples/test-suite/preproc_include.i new file mode 100644 index 000000000..c6b08b5fd --- /dev/null +++ b/Examples/test-suite/preproc_include.i @@ -0,0 +1,18 @@ +%module preproc_include + +%{ +#include "preproc_include_a.h" +#include "preproc_include_b.h" +int multiply10(int a) { return a*10; } +int multiply20(int a) { return a*20; } +int multiply30(int a) { return a*30; } +%} + +#define INCLUDE_B preproc_include_b.h +#define FILE_INCLUDE(FNAME) #FNAME + +%include FILE_INCLUDE(preproc_include_a.h) + +// Note that this test uses -includeall, so including preproc_include_b.h also includes preproc_include_c.h +%include INCLUDE_B + diff --git a/Examples/test-suite/preproc_include_a.h b/Examples/test-suite/preproc_include_a.h new file mode 100644 index 000000000..b6b55d90d --- /dev/null +++ b/Examples/test-suite/preproc_include_a.h @@ -0,0 +1,3 @@ + +int multiply10(int a); + diff --git a/Examples/test-suite/preproc_include_b.h b/Examples/test-suite/preproc_include_b.h new file mode 100644 index 000000000..b7cfd530e --- /dev/null +++ b/Examples/test-suite/preproc_include_b.h @@ -0,0 +1,7 @@ + +int multiply20(int a); + +#define PREPROC_INCLUDE_C "preproc_include_c.h" + +#include PREPROC_INCLUDE_C + diff --git a/Examples/test-suite/preproc_include_c.h b/Examples/test-suite/preproc_include_c.h new file mode 100644 index 000000000..18f9084a4 --- /dev/null +++ b/Examples/test-suite/preproc_include_c.h @@ -0,0 +1,3 @@ + +int multiply30(int a); + diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i new file mode 100644 index 000000000..b221b7728 --- /dev/null +++ b/Examples/test-suite/preproc_line_file.i @@ -0,0 +1,95 @@ +%module preproc_line_file + +// Test __LINE__ and __FILE__ (don't change line numbering in here else runtime tests will need modifying) +#define MYLINE __LINE__ +#define MYLINE_ADJUSTED __LINE__ + 100 + +#define MYFILE __FILE__ +#define MYFILE_ADJUSTED __FILE__ ".bak" + + +#define STRINGNUM_HELP(a,b) #a#b +#define STRINGNUM(a,b) STRINGNUM_HELP(a,b) +#define STRINGNUM_UNIQUE(a) STRINGNUM(a,__LINE__) + +#define MY_STRINGNUM_A STRINGNUM_UNIQUE(my) +#define MY_STRINGNUM_B STRINGNUM_UNIQUE(my) + + +#define NUMBER_HELP(a,b) a##b +#define NUMBER(a,b) NUMBER_HELP(a,b) +#define NUMBER_UNIQUE(a) NUMBER(a,__LINE__) + +%{ +const int thing27 = -1; +const int thing28 = -2; +%} +const int NUMBER_UNIQUE(thing) = -1; /* resolves to thing27 */ +const int NUMBER_UNIQUE(thing) = -2; /* resolves to thing28 */ + +#define MYLINE2 __LINE__ + +#if defined (SWIGJAVA) +%javaconst(1); +#elif defined(SWIGCSHARP) +%csconst(1); +#elif defined(SWIGD) +%dmanifestconst; +#else +%ignore LINE_NUMBER; +%ignore LINE_NUM; +/* spare space */ +#endif + +%{ +struct SillyStruct { + int num; + /* static const int line_num = __LINE__; */ +}; +%} +struct SillyStruct { + int num; + static const int LINE_NUMBER = __LINE__; /* This is a C test case, but we can still use a C++ feature to wrap a constant to test __LINE__ here */ +}; + +#define SILLY_CLASS struct SillyMacroClass { int num; static const int LINE_NUM = __LINE__; }; +SILLY_CLASS + +%{ +#define SILLY_CLASS struct SillyMacroClass { int num; }; +SILLY_CLASS +%} + + +%inline %{ +#ifdef SWIG +%define BODY + int num; + static const int LINE_NUM = __LINE__; +%enddef +%define KLASS(NAME) +struct NAME { + BODY +}; +%enddef +#else +#define KLASS(NAME) \ +struct NAME { \ + int num; \ +}; +#endif +KLASS(SillyMultipleMacroStruct) +%} + +%inline %{ + +#define INLINE_FILE __FILE__ +#define INLINE_LINE __LINE__ +%} + +#define MACRO_END_WITH_SLASH ABCD/ + +%inline %{ +KLASS(Slash) +%} + diff --git a/Examples/test-suite/primitive_types.i b/Examples/test-suite/primitive_types.i index e00108b93..f912bd77c 100644 --- a/Examples/test-suite/primitive_types.i +++ b/Examples/test-suite/primitive_types.i @@ -355,8 +355,6 @@ macro(size_t, pfx, sizet) %enddef -%apply (char *STRING, int LENGTH) { (const char *str, size_t len) } - %inline { struct Foo { @@ -464,15 +462,8 @@ macro(size_t, pfx, sizet) %test_prim_types_ovr(ovr_decl, ovr) - size_t strlen(const char *str, size_t len) - { - return len; - } - static const double stc_double; static const double stc_float; - - }; struct TestDirector diff --git a/Examples/test-suite/pure_virtual.i b/Examples/test-suite/pure_virtual.i index 5bda283cf..9e345e2a4 100644 --- a/Examples/test-suite/pure_virtual.i +++ b/Examples/test-suite/pure_virtual.i @@ -9,7 +9,8 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, D, Java, PHP multiple inheritance */ %nodefaultctor C; %nodefaultdtor C; @@ -65,7 +66,7 @@ public: %} /* Fill in method from AA. This class should be constructable */ -#ifdef SWIGCSHARP +#if defined(SWIGCSHARP) || defined(SWIGD) %ignore F::method2(); // Work around for lack of multiple inheritance support - base AA is ignored. #endif diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 4938ddc27..a05542b70 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -117,7 +117,7 @@ VALGRIND_OPT += --suppressions=pythonswig.supp # Runs the testcase. A testcase is only run if # a file is found which has _runme.py (or _runme3.py for Python 3) appended after the testcase name. -run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) +run_python = env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=.:$(srcdir):$$PYTHONPATH $(RUNTOOL) $(PYTHON) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) py2_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY2SCRIPTSUFFIX) py3_runme = $(srcdir)/$(SCRIPTPREFIX)$*$(PY3SCRIPTSUFFIX) diff --git a/Examples/test-suite/python/char_binary_runme.py b/Examples/test-suite/python/char_binary_runme.py new file mode 100644 index 000000000..b6d9c81c8 --- /dev/null +++ b/Examples/test-suite/python/char_binary_runme.py @@ -0,0 +1,36 @@ +from char_binary import * + +t = Test() +if t.strlen('hile') != 4: + print t.strlen('hile') + raise RuntimeError, "bad multi-arg typemap" + +if t.strlen('hil\0') != 4: + raise RuntimeError, "bad multi-arg typemap" + +# +# creating a raw char* +# +pc = new_pchar(5) +pchar_setitem(pc, 0, 'h') +pchar_setitem(pc, 1, 'o') +pchar_setitem(pc, 2, 'l') +pchar_setitem(pc, 3, 'a') +pchar_setitem(pc, 4, 0) + + +if t.strlen(pc) != 4: + raise RuntimeError, "bad multi-arg typemap" + +cvar.var_pchar = pc +if cvar.var_pchar != "hola": + print cvar.var_pchar + raise RuntimeError, "bad pointer case" + +cvar.var_namet = pc +#if cvar.var_namet != "hola\0": +if cvar.var_namet != "hola": + raise RuntimeError, "bad pointer case" + +delete_pchar(pc) + diff --git a/Examples/test-suite/python/director_alternating_runme.py b/Examples/test-suite/python/director_alternating_runme.py new file mode 100644 index 000000000..a92ae1c5c --- /dev/null +++ b/Examples/test-suite/python/director_alternating_runme.py @@ -0,0 +1,5 @@ +from director_alternating import * + +id = getBar().id() +if id != idFromGetBar(): + raise RuntimeError, "Got wrong id: " + str(id) diff --git a/Examples/test-suite/python/director_protected_runme.py b/Examples/test-suite/python/director_protected_runme.py index 9d565a1b4..fd3c868a1 100644 --- a/Examples/test-suite/python/director_protected_runme.py +++ b/Examples/test-suite/python/director_protected_runme.py @@ -12,11 +12,16 @@ class FooBar2(Bar): def pang(self): return "FooBar2::pang();" +class FooBar3(Bar): + def cheer(self): + return "FooBar3::cheer();" + b = Bar() f = b.create() fb = FooBar() fb2 = FooBar2() +fb3 = FooBar3() try: @@ -66,7 +71,7 @@ try: except: pass if not protected: - raise RuntimeError,"Boo::ping is protected" + raise RuntimeError,"Foo::ping is protected" protected=1 try: @@ -86,3 +91,39 @@ except: pass if not protected: raise RuntimeError,"FooBar::pang is protected" + + +protected=1 +try: + b.cheer() + protected=0 +except: + pass +if not protected: + raise RuntimeError,"Bar::cheer is protected" + +protected=1 +try: + f.cheer() + protected=0 +except: + pass +if not protected: + raise RuntimeError,"Foo::cheer is protected" + +if fb3.cheer() != "FooBar3::cheer();": + raise RuntimeError, "bad fb3::cheer" + +if fb2.callping() != "FooBar2::ping();": + raise RuntimeError, "bad fb2.callping" + +if fb2.callcheer() != "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();": + raise RuntimeError, "bad fb2.callcheer" + +if fb3.callping() != "Bar::ping();": + raise RuntimeError, "bad fb3.callping" + +if fb3.callcheer() != "FooBar3::cheer();": + raise RuntimeError, "bad fb3.callcheer" + + diff --git a/Examples/test-suite/python/global_namespace_runme.py b/Examples/test-suite/python/global_namespace_runme.py new file mode 100644 index 000000000..b64e75ca1 --- /dev/null +++ b/Examples/test-suite/python/global_namespace_runme.py @@ -0,0 +1,40 @@ +from global_namespace import * + +k1 = Klass1() +k2 = Klass2() +k3 = Klass3() +k4 = Klass4() +k5 = Klass5() +k6 = Klass6() +k7 = Klass7() + +KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) + +k1 = getKlass1A() +k2 = getKlass2A() +k3 = getKlass3A() +k4 = getKlass4A() +k5 = getKlass5A() +k6 = getKlass6A() +k7 = getKlass7A() + +KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) + +k1 = getKlass1B() +k2 = getKlass2B() +k3 = getKlass3B() +k4 = getKlass4B() +k5 = getKlass5B() +k6 = getKlass6B() +k7 = getKlass7B() + +KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7) +KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7) + +XYZMethods.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) +XYZMethods.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7()) + +TheEnumMethods.methodA(theenum1, theenum2, theenum3) +TheEnumMethods.methodA(theenum1, theenum2, theenum3) diff --git a/Examples/test-suite/python/pointer_reference_runme.py b/Examples/test-suite/python/pointer_reference_runme.py new file mode 100644 index 000000000..e1a1a1f4b --- /dev/null +++ b/Examples/test-suite/python/pointer_reference_runme.py @@ -0,0 +1,16 @@ +import pointer_reference + +s = pointer_reference.get() +if s.value != 10: + raise RuntimeError, "get test failed" + +ss = pointer_reference.Struct(20) +pointer_reference.set(ss) +if pointer_reference.cvar.Struct_instance.value != 20: + raise RuntimeError, "set test failed" + +if pointer_reference.overloading(1) != 111: + raise RuntimeError, "overload test 1 failed" + +if pointer_reference.overloading(ss) != 222: + raise RuntimeError, "overload test 2 failed" diff --git a/Examples/test-suite/python/preproc_defined_runme.py b/Examples/test-suite/python/preproc_defined_runme.py new file mode 100644 index 000000000..9a295533a --- /dev/null +++ b/Examples/test-suite/python/preproc_defined_runme.py @@ -0,0 +1,11 @@ +import preproc_defined + +if preproc_defined.call_checking() != 1: + raise RuntimeError + +d = preproc_defined.Defined() +d.defined = 10 + +preproc_defined.thing(10) +preproc_defined.stuff(10) +preproc_defined.bumpf(10) diff --git a/Examples/test-suite/python/preproc_include_runme.py b/Examples/test-suite/python/preproc_include_runme.py new file mode 100644 index 000000000..e15606581 --- /dev/null +++ b/Examples/test-suite/python/preproc_include_runme.py @@ -0,0 +1,11 @@ +import preproc_include + +if preproc_include.multiply10(10) != 100: + raise RuntimeError + +if preproc_include.multiply20(10) != 200: + raise RuntimeError + +if preproc_include.multiply30(10) != 300: + raise RuntimeError + diff --git a/Examples/test-suite/python/primitive_types_runme.py b/Examples/test-suite/python/primitive_types_runme.py index 02cc21763..2495cd60d 100644 --- a/Examples/test-suite/python/primitive_types_runme.py +++ b/Examples/test-suite/python/primitive_types_runme.py @@ -188,14 +188,6 @@ if t.var_namet != 'hol': raise RuntimeError -if t.strlen('hile') != 4: - print t.strlen('hile') - raise RuntimeError, "bad string typemap" - -if t.strlen('hil\0') != 4: - raise RuntimeError, "bad string typemap" - - cvar.var_char = '\0' if cvar.var_char != '\0': raise RuntimeError, "bad char '0' case" @@ -244,9 +236,6 @@ pchar_setitem(pc, 3, 'a') pchar_setitem(pc, 4, 0) -if t.strlen(pc) != 4: - raise RuntimeError, "bad string typemap" - cvar.var_pchar = pc if cvar.var_pchar != "hola": print cvar.var_pchar diff --git a/Examples/test-suite/python/rename_pcre_encoder_runme.py b/Examples/test-suite/python/rename_pcre_encoder_runme.py new file mode 100644 index 000000000..1186703a0 --- /dev/null +++ b/Examples/test-suite/python/rename_pcre_encoder_runme.py @@ -0,0 +1,13 @@ +from rename_pcre_encoder import * + +s = SomeWidget() +s.putBorderWidth(3) +if s.getBorderWidth() != 3: + raise RuntimeError("Border should be 3, not %d" % (s.getBorderWidth(),)) + +s.putSize(4, 5) +a = AnotherWidget() +a.DoSomething() + +evt = wxEVTSomeEvent() +t = xUnchangedName() diff --git a/Examples/test-suite/python/smart_pointer_const_overload_runme.py b/Examples/test-suite/python/smart_pointer_const_overload_runme.py new file mode 100644 index 000000000..f1be315a5 --- /dev/null +++ b/Examples/test-suite/python/smart_pointer_const_overload_runme.py @@ -0,0 +1,123 @@ +from smart_pointer_const_overload import * + +CONST_ACCESS = 1 +MUTABLE_ACCESS = 2 + +def test(b, f): + if f.x != 0: + raise RuntimeError + + # Test member variable get + if b.x != 0: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test member variable set + b.x = 1 + + if f.x != 1: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + # Test const method + if b.getx() != 1: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test mutable method + b.setx(2) + + if f.x != 2: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + # Test extended const method + if b.getx2() != 2: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test extended mutable method + b.setx2(3) + + if f.x != 3: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + # Test static method + b.stat() + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test const member + f.access = MUTABLE_ACCESS + + if b.y != 0: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test get through mutable pointer to const member + f.access = MUTABLE_ACCESS + + if get_int(b.yp) != 0: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test get through const pointer to mutable member + f.x = 4 + f.access = MUTABLE_ACCESS + + if get_int(b.xp) != 4: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test set through const pointer to mutable member + f.access = MUTABLE_ACCESS + set_int(b.xp, 5) + + if f.x != 5: + raise RuntimeError + + if f.access != CONST_ACCESS: + raise RuntimeError + + # Test set pointer to const member + b.yp = new_int(6) + + if f.y != 0: + raise RuntimeError + + if get_int(f.yp) != 6: + raise RuntimeError + + if f.access != MUTABLE_ACCESS: + raise RuntimeError + + delete_int(f.yp); + +f = Foo() +b = Bar(f) + +f2 = Foo() +b2 = Bar2(f2) + +test(b, f) +test(b2, f2) diff --git a/Examples/test-suite/python/typemap_arrays_runme.py b/Examples/test-suite/python/typemap_arrays_runme.py new file mode 100644 index 000000000..c23222c63 --- /dev/null +++ b/Examples/test-suite/python/typemap_arrays_runme.py @@ -0,0 +1,5 @@ +from typemap_arrays import * + +if sumA(None) != 60: + raise RuntimeError, "Sum is wrong" + diff --git a/Examples/test-suite/r/rename_simple_runme.R b/Examples/test-suite/r/rename_simple_runme.R new file mode 100644 index 000000000..b25aeb844 --- /dev/null +++ b/Examples/test-suite/r/rename_simple_runme.R @@ -0,0 +1,20 @@ +source("unittest.R") +dyn.load(paste("rename_simple", .Platform$dynlib.ext, sep="")) +source("rename_simple.R") +cacheMetaData(1) + +s <- NewStruct(); +unittest(111, s$NewInstanceVariable) +unittest(222, s$NewInstanceMethod()) +unittest(333, NewStruct_NewStaticMethod()) +unittest(444, NewStruct_NewStaticVariable()) +unittest(555, NewFunction()) +unittest(666, NewGlobalVariable()) + +s$NewInstanceVariable <- 1111 +NewStruct_NewStaticVariable(4444) +NewGlobalVariable(6666) + +unittest(1111, s$NewInstanceVariable) +unittest(4444, NewStruct_NewStaticVariable()) +unittest(6666, NewGlobalVariable()) diff --git a/Examples/test-suite/r/unittest.R b/Examples/test-suite/r/unittest.R index 81c590a3f..0633c7715 100644 --- a/Examples/test-suite/r/unittest.R +++ b/Examples/test-suite/r/unittest.R @@ -1,9 +1,17 @@ unittest <- function (x,y) { -if (x==y) print("PASS") -else print("FAIL") + if (x==y) { + print("PASS") + } else { + print("FAIL") + stop("Test failed") + } } unittesttol <- function(x,y,z) { -if (abs(x-y) < z) print("PASS") -else print("FAIL") -}
\ No newline at end of file + if (abs(x-y) < z) { + print("PASS") + } else { + print("FAIL") + stop("Test failed") + } +} diff --git a/Examples/test-suite/rename_camel.i b/Examples/test-suite/rename_camel.i index 54f06f967..970bb9215 100644 --- a/Examples/test-suite/rename_camel.i +++ b/Examples/test-suite/rename_camel.i @@ -33,7 +33,7 @@ %rename(awk_cmd) ""; -%rename("%(title)s",rxsmatch$parentNode$type="enum .*") ""; +%rename("%(title)s",regexmatch$parentNode$type="enum .*") ""; %inline { @@ -59,7 +59,7 @@ } -%rename("%(lowercase)s",sourcefmt="%(rxspencer:[GSL_(.*)][@1])s",%$isfunction) ""; +%rename("%(lowercase)s",sourcefmt="%(regex:/GSL_(.*)/\\1/)s",%$isfunction) ""; %inline { void GSL_Hello() {} } diff --git a/Examples/test-suite/rename_pcre_encoder.i b/Examples/test-suite/rename_pcre_encoder.i new file mode 100644 index 000000000..66f30c7bc --- /dev/null +++ b/Examples/test-suite/rename_pcre_encoder.i @@ -0,0 +1,31 @@ +%module rename_pcre_encoder + +// strip the wx prefix from all identifiers except those starting with wxEVT +%rename("%(regex:/wx(?!EVT)(.*)/\\1/)s") ""; + +// Replace "Set" and "Get" prefixes with "put" and "get" respectively. +%rename("%(regex:/^Set(.*)/put\\1/)s", %$isfunction) ""; +%rename("%(regex:/^Get(.*)/get\\1/)s", %$isfunction) ""; + +%inline %{ + +struct wxSomeWidget { + void SetBorderWidth(int width) { m_width = width; } + int GetBorderWidth() const { return m_width; } + + void SetSize(int, int) {} + + int m_width; +}; + +struct wxAnotherWidget { + void DoSomething() {} +}; + +class wxEVTSomeEvent { +}; + +class xUnchangedName { +}; + +%} diff --git a/Examples/test-suite/rename_pcre_enum.i b/Examples/test-suite/rename_pcre_enum.i new file mode 100644 index 000000000..1bb7c1b8b --- /dev/null +++ b/Examples/test-suite/rename_pcre_enum.i @@ -0,0 +1,49 @@ +%module rename_pcre_enum + +// This file is needed for proper enum support in C#/Java backends +#if defined(SWIGCSHARP) || defined(SWIGJAVA) +%include "enums.swg" +#endif + +// Apply a rule for renaming the enum elements to avoid the common prefixes +// redundant in C#/Java +%rename("%(regex:/([A-Z][a-z]+)+_(.*)/\\2/)s",%$isenumitem) ""; + +// Also don't export special end of enum markers which are often used in C++ +// code to just have a symbolic name for the number of enum elements but are +// not needed in target language. +%rename("$ignore", regexmatch$name="([A-Z][a-z]+)+_Max$",%$isenumitem) ""; + +// Test another way of doing the same thing with regextarget: +%rename("$ignore", %$isenumitem, regextarget=1) "([A-Z][a-z]+)+_Internal$"; + +// Apply this renaming rule to all enum elements that don't contain more than +// one capital letter. +%rename("%(lower)s", notregexmatch$name="[A-Z]\\w*[A-Z]", %$isenumitem) ""; + +%inline %{ + +// Foo_Internal and Foo_Max won't be exported. +enum Foo { + Foo_Internal = -1, + Foo_First, + Foo_Second, + Foo_Max +}; + +// All elements of this enum will be exported because they do not match the +// excluding regex. +enum BoundaryCondition { + BoundaryCondition_MinMax, + BoundaryCondition_MaxMin, + BoundaryCondition_MaxMax +}; + +// The elements of this enum will have lower-case names. +enum Colour { + Red, + Blue, + Green +}; + +%} diff --git a/Examples/test-suite/rename_simple.i b/Examples/test-suite/rename_simple.i new file mode 100644 index 000000000..feba53fa1 --- /dev/null +++ b/Examples/test-suite/rename_simple.i @@ -0,0 +1,24 @@ +%module rename_simple + +%rename(NewStruct) OldStruct; +%rename(NewVariable) OldVariable; +%rename(NewInstanceMethod) OldInstanceMethod; +%rename(NewInstanceVariable) OldInstanceVariable; +%rename(NewStaticMethod) OldStaticMethod; +%rename(NewStaticVariable) OldStaticVariable; +%rename(NewFunction) OldFunction; +%rename(NewGlobalVariable) OldGlobalVariable; + +%inline %{ +struct OldStruct { + OldStruct() : OldInstanceVariable(111) {} + int OldInstanceVariable; + int OldInstanceMethod() { return 222; } + static int OldStaticVariable; + static int OldStaticMethod() { return 333; } +}; +int OldStruct::OldStaticVariable = 444; + +int OldFunction() { return 555; } +int OldGlobalVariable = 666; +%} diff --git a/Examples/test-suite/restrict_cplusplus.i b/Examples/test-suite/restrict_cplusplus.i index 4e4bfc277..62abffa52 100644 --- a/Examples/test-suite/restrict_cplusplus.i +++ b/Examples/test-suite/restrict_cplusplus.i @@ -1,7 +1,15 @@ %module restrict_cplusplus -%inline %{ +%{ +// For PHP 5.3 / gcc-4.4 +#ifdef restrict +#undef restrict +#endif struct Foo { int restrict; }; %} + +struct Foo { + int restrict; +}; diff --git a/Examples/test-suite/return_const_value.i b/Examples/test-suite/return_const_value.i index 473878521..6be5760c1 100644 --- a/Examples/test-suite/return_const_value.i +++ b/Examples/test-suite/return_const_value.i @@ -42,6 +42,7 @@ public: _ptr = f._ptr; _own = f._own; f._own = 0; + return *this; } ~Foo_ptr() { diff --git a/Examples/test-suite/rname.i b/Examples/test-suite/rname.i index 31b99833d..09d6e3e3b 100644 --- a/Examples/test-suite/rname.i +++ b/Examples/test-suite/rname.i @@ -15,19 +15,14 @@ %rename(foo_u) *::foo(unsigned); /* Rename classes in a class hierarchy */ -%rename (RenamedBase) Base; -%rename (RenamedDerived) Derived; +%rename (RenamedBase) Space::Base; +%rename (RenamedDerived) Space::Derived; /* Rename base class method applies to derived classes too */# -%rename (newname) Base::oldname(double d) const; +%rename (newname) Space::Base::oldname(double d) const; /* Rename derived class method only */ -#ifndef SWIGGO -%rename (func) Derived::fn(Base baseValue, Base* basePtr, Base& baseRef); -#else -/* func is a keyword in Go. */ -%rename (Xfunc) Derived::fn(Base baseValue, Base* basePtr, Base& baseRef); -#endif +%rename (Xfunc) Space::Derived::fn(Base baseValue, Base* basePtr, Base& baseRef); %inline %{ class Bar { @@ -43,20 +38,22 @@ char *foo(double) { return (char *) "foo-double"; } char *foo(short) { return (char *) "foo-short"; } char *foo(unsigned) { return (char *) "foo-unsigned"; } +namespace Space { class Base { public: Base(){}; virtual ~Base(){}; void fn(Base baseValue, Base* basePtr, Base& baseRef){} - virtual const char * oldname(double d) const { return (char*) "Base"; } + virtual const char * oldname(double d) const { return "Base"; } }; class Derived : public Base { public: Derived(){} ~Derived(){} void fn(Base baseValue, Base* basePtr, Base& baseRef){} - virtual const char * oldname(double d) const { return (char*) "Derived"; } + virtual const char * oldname(double d) const { return "Derived"; } }; +} %} diff --git a/Examples/test-suite/samename.i b/Examples/test-suite/samename.i index 819cb4abd..cc03995bc 100644 --- a/Examples/test-suite/samename.i +++ b/Examples/test-suite/samename.i @@ -1,6 +1,6 @@ %module samename -#if !(defined(SWIGCSHARP) || defined(SWIGJAVA)) +#if !(defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGD)) class samename { public: void do_something() { diff --git a/Examples/test-suite/smart_pointer_const_overload.i b/Examples/test-suite/smart_pointer_const_overload.i new file mode 100644 index 000000000..e3b000b52 --- /dev/null +++ b/Examples/test-suite/smart_pointer_const_overload.i @@ -0,0 +1,74 @@ +%module smart_pointer_const_overload + +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar::operator->; // Overloaded method Bar::operator ->() ignored +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar2::operator->; // Overloaded method Bar2::operator ->() ignored + +%inline %{ +int CONST_ACCESS = 1; +int MUTABLE_ACCESS = 2; + +int *new_int(int ivalue) { + int *i = (int *) malloc(sizeof(ivalue)); + *i = ivalue; + return i; +} + +int get_int(int *i) { + return *i; +} + +void set_int(int *i, int ivalue) { + *i = ivalue; +} + +void delete_int(int *i) { + free(i); +} + +struct Foo { + int x; + int * const xp; + const int y; + const int *yp; + int access; + Foo() : x(0), xp(&x), y(0), yp(&y), access(0) { } + int getx() const { return x; } + void setx(int x_) { x = x_; } + static void stat() {} +}; +%} + +%extend Foo { + int getx2() const { return self->x; } + void setx2(int x_) { self->x = x_; } +}; + +%inline %{ +class Bar { + Foo *f; +public: + Bar(Foo *f) : f(f) { } + const Foo *operator->() const { + f->access = CONST_ACCESS; + return f; + } + Foo *operator->() { + f->access = MUTABLE_ACCESS; + return f; + } +}; + +class Bar2 { + Foo *f; +public: + Bar2(Foo *f) : f(f) { } + Foo *operator->() { + f->access = MUTABLE_ACCESS; + return f; + } + const Foo *operator->() const { + f->access = CONST_ACCESS; + return f; + } +}; +%} diff --git a/Examples/test-suite/smart_pointer_templatemethods.i b/Examples/test-suite/smart_pointer_templatemethods.i index 7baa6386a..f79bbcc9d 100644 --- a/Examples/test-suite/smart_pointer_templatemethods.i +++ b/Examples/test-suite/smart_pointer_templatemethods.i @@ -1,4 +1,3 @@ - %module smart_pointer_templatemethods %inline %{ @@ -29,21 +28,21 @@ public: void DisposeObjekt (void) {} }; -class Object +class Objct { public: - Object () {} - virtual ~Object () {} + Objct () {} + virtual ~Objct () {} template <typename T> Ptr<T> QueryInterface (InterfaceId iid) const { return Ptr<T>(); } - void DisposeObject (void) {} + void DisposeObjct (void) {} }; #ifdef SWIG -%template(PtrObject) Ptr<Object>; +%template(PtrObjct) Ptr<Objct>; %template(PtrInt) Ptr<int>; %template(ObjektInt) Objekt<int>; %template(PtrObjektInt) Ptr<Objekt<int> >; -%template(QueryInterfaceObject) Object::QueryInterface<Object>; +%template(QueryInterfaceObjct) Objct::QueryInterface<Objct>; #endif }; // namespace diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i index c168b4747..1ad673b41 100644 --- a/Examples/test-suite/special_variable_macros.i +++ b/Examples/test-suite/special_variable_macros.i @@ -165,6 +165,20 @@ namespace Space { return new $typemap(jstype, Space::RenameMe)( new $typemap(jstype, Name)(s) ); } %} +#elif defined(SWIGD) +#if (SWIG_D_VERSION == 1) +%typemap(dcode) Space::RenameMe %{ + public static NewName factory(char[] s) { + return new $typemap(dtype, Space::RenameMe)( new $typemap(dtype, Name)(s) ); + } +%} +#else +%typemap(dcode) Space::RenameMe %{ + public static NewName factory(string s) { + return new $typemap(dtype, Space::RenameMe)( new $typemap(dtype, Name)(s) ); + } +%} +#endif #endif %rename(NewName) Space::RenameMe; diff --git a/Examples/test-suite/static_const_member.i b/Examples/test-suite/static_const_member.i index 3db60b4c2..a8d119b81 100644 --- a/Examples/test-suite/static_const_member.i +++ b/Examples/test-suite/static_const_member.i @@ -11,6 +11,9 @@ #elif SWIGCSHARP %csconst(1) EN; %csconst(1) CHARTEST; +#elif SWIGD +%dmanifestconst EN; +%dmanifestconst CHARTEST; #endif %inline %{ diff --git a/Examples/test-suite/template.i b/Examples/test-suite/template_basic.i index d2c7a91ed..570392bf6 100644 --- a/Examples/test-suite/template.i +++ b/Examples/test-suite/template_basic.i @@ -1,5 +1,5 @@ -/* File : example.i */ -%module "template" +/* File: template_basic.i */ +%module "template_basic" %warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<int>; /* Ruby, wrong class name */ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector<double>; /* Ruby, wrong class name */ @@ -31,7 +31,7 @@ template<class T> class vector { void set(int index, T &val) { v[index] = val; } - // This really doesn't do anything except test const handling + // This really doesn't do anything except test const handling void testconst(const T x) { } }; diff --git a/Examples/test-suite/template_enum.i b/Examples/test-suite/template_enum.i index 0d6fbf5b9..f36d5dc40 100644 --- a/Examples/test-suite/template_enum.i +++ b/Examples/test-suite/template_enum.i @@ -13,6 +13,10 @@ public: %template(foo_i) foo<int>; %template(foo_d) foo<double>; +#ifdef SWIGD +// Workaround for the D module which uses the literal value in the generated wrapper code. +%dconstvalue("3") Manta::ColorSpace<Manta::RGBTraits>::NumComponents; +#endif %inline { diff --git a/Examples/test-suite/template_inherit_abstract.i b/Examples/test-suite/template_inherit_abstract.i index 2f83433a5..87c921eab 100644 --- a/Examples/test-suite/template_inherit_abstract.i +++ b/Examples/test-suite/template_inherit_abstract.i @@ -4,7 +4,8 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) oss::Module; /* C#, Java, PHP multiple inheritance */ + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) oss::Module; /* C#, D, Java, PHP multiple inheritance */ %inline %{ @@ -56,7 +57,7 @@ namespace oss %inline %{ namespace oss { -#if defined(SWIG) && defined(SWIGCSHARP) +#if defined(SWIG) && (defined(SWIGCSHARP) || defined(SWIGD)) %ignore HModule<B>::get(); // Work around for lack of multiple inheritance support - base ModuleBase is ignored. #endif struct test : HModule<B> diff --git a/Examples/test-suite/threads_exception.i b/Examples/test-suite/threads_exception.i index 9f275bd6a..9f275bd6a 100755..100644 --- a/Examples/test-suite/threads_exception.i +++ b/Examples/test-suite/threads_exception.i diff --git a/Examples/test-suite/typemap_arrays.i b/Examples/test-suite/typemap_arrays.i new file mode 100644 index 000000000..dd7994405 --- /dev/null +++ b/Examples/test-suite/typemap_arrays.i @@ -0,0 +1,30 @@ +%module typemap_arrays + +// Test that previously non-working array typemaps special variables are working + +%typemap(in) SWIGTYPE[ANY] { + _should_not_be_used_and_will_not_compile_ +} + +// Check $basemangle expands to _p_int and $basetype expands to int * +%typemap(in) int *nums[3] (int *temp[3]) { + $basetype var1$basemangle = new int(10); + $basetype var2$basemangle = new int(20); + $basetype var3$basemangle = new int(30); + temp[0] = var1_p_int; + temp[1] = var2_p_int; + temp[2] = var3_p_int; + $1 = temp; +} + +%inline %{ +int sumA(int *nums[3]) { + int sum = 0; + for (int i=0; i<3; ++i) { + int *p = nums[i]; + if (p) + sum += *p; + } + return sum; +} +%} diff --git a/Examples/test-suite/typemap_namespace.i b/Examples/test-suite/typemap_namespace.i index 6614e0372..1fd7ce718 100644 --- a/Examples/test-suite/typemap_namespace.i +++ b/Examples/test-suite/typemap_namespace.i @@ -29,8 +29,15 @@ namespace Foo { #ifdef SWIGGO %typemap(gotype) Str1 * = char *; #endif +#ifdef SWIGD + %typemap(ctype) Str1 * = char *; + %typemap(imtype) Str1 * = char *; + %typemap(dtype) Str1 * = char *; + %typemap(din) Str1 * = char *; + %typemap(dout) Str1 * = char *; +#endif %typemap(in) Str1 * = char *; -#if !(defined(SWIGCSHARP) || defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGMZSCHEME) || defined(SWIGOCAML) || defined(SWIGGO)) +#if !(defined(SWIGCSHARP) || defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGMZSCHEME) || defined(SWIGOCAML) || defined(SWIGGO) || defined(SWIGD)) %typemap(freearg) Str1 * = char *; #endif %typemap(typecheck) Str1 * = char *; diff --git a/Examples/test-suite/typemap_out_optimal.i b/Examples/test-suite/typemap_out_optimal.i index 23cd2ad3f..d707ed2d5 100644 --- a/Examples/test-suite/typemap_out_optimal.i +++ b/Examples/test-suite/typemap_out_optimal.i @@ -2,7 +2,7 @@ %module typemap_out_optimal // Just the following languages tested -#if defined (SWIGCSHARP) +#if defined (SWIGCSHARP) || defined (SWIGD) %typemap(out, optimal="1") SWIGTYPE %{ $result = new $1_ltype((const $1_ltype &)$1); %} @@ -18,6 +18,10 @@ %ignore XX::operator=; +#ifdef SWIGD +%rename(trace) XX::debug; +#endif + %inline %{ #include <iostream> using namespace std; diff --git a/Examples/test-suite/typemap_subst.i b/Examples/test-suite/typemap_subst.i index 1b1f8a3f4..91ac62020 100644 --- a/Examples/test-suite/typemap_subst.i +++ b/Examples/test-suite/typemap_subst.i @@ -61,8 +61,8 @@ $1 = ($ltype) temp; } -/* Java, C# and Go modules don't use SWIG's runtime type system */ -#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) +/* Java, C#, Go and D modules don't use SWIG's runtime type system */ +#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD) %inline %{ void foo(const struct xyzzy **TEST) {} %} diff --git a/Examples/test-suite/using_composition.i b/Examples/test-suite/using_composition.i index bd0f712b5..052412b5f 100644 --- a/Examples/test-suite/using_composition.i +++ b/Examples/test-suite/using_composition.i @@ -2,13 +2,16 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, D, Java, PHP multiple inheritance %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar2; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar2; // C#, D, Java, PHP multiple inheritance %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar3; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar3; // C#, D, Java, PHP multiple inheritance #ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) blah; #endif diff --git a/Examples/test-suite/using_extend.i b/Examples/test-suite/using_extend.i index e14cc28e8..c52f65c23 100644 --- a/Examples/test-suite/using_extend.i +++ b/Examples/test-suite/using_extend.i @@ -2,7 +2,8 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, D, Java, PHP multiple inheritance #ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) blah; #endif diff --git a/Examples/test-suite/using_namespace.i b/Examples/test-suite/using_namespace.i index ce02e9a87..1119b46f7 100644 --- a/Examples/test-suite/using_namespace.i +++ b/Examples/test-suite/using_namespace.i @@ -5,7 +5,8 @@ %warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE, SWIGWARN_CSHARP_MULTIPLE_INHERITANCE, - SWIGWARN_PHP_MULTIPLE_INHERITANCE) Hi<hello::Hello, hi::hi0>; // C#, Java, PHP multiple inheritance + SWIGWARN_D_MULTIPLE_INHERITANCE, + SWIGWARN_PHP_MULTIPLE_INHERITANCE) Hi<hello::Hello, hi::hi0>; // C#, D, Java, PHP multiple inheritance %inline %{ namespace hello diff --git a/Examples/test-suite/using_protected.i b/Examples/test-suite/using_protected.i index 23adfdbba..402a7c8da 100644 --- a/Examples/test-suite/using_protected.i +++ b/Examples/test-suite/using_protected.i @@ -3,14 +3,23 @@ %inline %{ class Foo { protected: - int x; - int blah(int xx) { return xx; } + int x; + int blah(int xx) { return xx; } + virtual int vmethod(int xx) { return xx; } }; class FooBar : public Foo { public: - using Foo::blah; - using Foo::x; + using Foo::blah; + using Foo::x; + using Foo::vmethod; +}; + +class FooBaz : public Foo { +protected: + using Foo::blah; + using Foo::x; + using Foo::vmethod; }; %} diff --git a/Examples/test-suite/varargs.i b/Examples/test-suite/varargs.i index 41e4903f0..c7931fed2 100644 --- a/Examples/test-suite/varargs.i +++ b/Examples/test-suite/varargs.i @@ -1,4 +1,5 @@ -// Tests SWIG's *default* handling of varargs. The default behavior is to simply ignore the varargs. +// Tests SWIG's *default* handling of varargs (function varargs, not preprocessor varargs). +// The default behavior is to simply ignore the varargs. %module varargs %varargs(int mode = 0) test_def; diff --git a/Examples/test-suite/wallkw.i b/Examples/test-suite/wallkw.i index 0ac383bcd..1a5866088 100644 --- a/Examples/test-suite/wallkw.i +++ b/Examples/test-suite/wallkw.i @@ -5,12 +5,14 @@ %warnfilter(SWIGWARN_PARSE_KEYWORD) clone; // 'clone' is a php keyword, renamed as 'c_clone' %warnfilter(SWIGWARN_PARSE_KEYWORD) delegate; // 'delegate' is a C# keyword, renaming to '_delegate' %warnfilter(SWIGWARN_PARSE_KEYWORD) pass; // 'pass' is a python keyword, renaming to '_pass' -%warnfilter(SWIGWARN_PARSE_KEYWORD) alias; // 'alias' is a ruby keyword, renaming to 'C_alias' +%warnfilter(SWIGWARN_PARSE_KEYWORD) alias; // 'alias' is a D keyword, renaming to '_alias' +%warnfilter(SWIGWARN_PARSE_KEYWORD) rescue; // 'rescue' is a ruby keyword, renaming to 'C_rescue' %inline %{ const char * clone() { return "clone"; } const char * delegate() { return "delegate"; } const char * pass() { return "pass"; } const char * alias() { return "alias"; } +const char * rescue() { return "rescue"; } %} diff --git a/Examples/test-suite/wrapmacro.i b/Examples/test-suite/wrapmacro.i index bd5e48b15..4d2cd67be 100644 --- a/Examples/test-suite/wrapmacro.i +++ b/Examples/test-suite/wrapmacro.i @@ -1,7 +1,7 @@ %module wrapmacro #ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings -%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) SWIGMACRO_max; +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) SWIGMACRO_maximum; #endif /* Testing technique for wrapping macros */ |