aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-08-17 19:31:37 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-08-17 19:31:37 -0300
commite0c29962e6f334452f0c9db2caaf6ed18065de85 (patch)
treecee27801c196fbcacf6130ad64216af133b555dd /tests
The End Is the Beginning Is the End
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt20
-rw-r--r--tests/libsample/CMakeLists.txt22
-rw-r--r--tests/libsample/abstract.cpp64
-rw-r--r--tests/libsample/abstract.h37
-rw-r--r--tests/libsample/complex.cpp27
-rw-r--r--tests/libsample/complex.h25
-rw-r--r--tests/libsample/derived.cpp80
-rw-r--r--tests/libsample/derived.h46
-rw-r--r--tests/libsample/functions.cpp85
-rw-r--r--tests/libsample/functions.h36
-rw-r--r--tests/libsample/implicitconv.cpp38
-rw-r--r--tests/libsample/implicitconv.h44
-rw-r--r--tests/libsample/kindergarten.cpp64
-rw-r--r--tests/libsample/kindergarten.h29
-rw-r--r--tests/libsample/listuser.cpp47
-rw-r--r--tests/libsample/listuser.h23
-rw-r--r--tests/libsample/main.cpp216
-rw-r--r--tests/libsample/modifications.cpp68
-rw-r--r--tests/libsample/modifications.h73
-rw-r--r--tests/libsample/pairuser.cpp32
-rw-r--r--tests/libsample/pairuser.h19
-rw-r--r--tests/libsample/point.cpp111
-rw-r--r--tests/libsample/point.h51
-rw-r--r--tests/libsample/reference.cpp11
-rw-r--r--tests/libsample/reference.h24
-rw-r--r--tests/libsample/samplenamespace.cpp48
-rw-r--r--tests/libsample/samplenamespace.h36
-rw-r--r--tests/libsample/size.cpp11
-rw-r--r--tests/libsample/size.h152
-rwxr-xr-xtests/run_test.sh13
-rw-r--r--tests/samplebinding/CMakeLists.txt44
-rwxr-xr-xtests/samplebinding/abstract_test.py62
-rw-r--r--tests/samplebinding/complex_conversions.h23
-rwxr-xr-xtests/samplebinding/complex_test.py42
-rwxr-xr-xtests/samplebinding/derived_test.py113
-rwxr-xr-xtests/samplebinding/enum_test.py36
-rw-r--r--tests/samplebinding/global.h14
-rwxr-xr-xtests/samplebinding/implicitconv_test.py27
-rw-r--r--tests/samplebinding/list_conversions.h29
-rwxr-xr-xtests/samplebinding/modifications_test.py115
-rw-r--r--tests/samplebinding/pair_conversions.h25
-rwxr-xr-xtests/samplebinding/point_test.py42
-rwxr-xr-xtests/samplebinding/reference_test.py28
-rwxr-xr-xtests/samplebinding/sample_test.py37
-rwxr-xr-xtests/samplebinding/size_test.py83
-rw-r--r--tests/samplebinding/typesystem_sample.xml216
46 files changed, 2488 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 000000000..c1569517e
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,20 @@
+add_subdirectory(libsample)
+add_subdirectory(samplebinding)
+
+file(GLOB TEST_FILES samplebinding/*_test.py)
+
+foreach(test_file ${TEST_FILES})
+ string(REGEX MATCH "/([^/]+)_test.py" test_name ${test_file})
+ add_test(${CMAKE_MATCH_1} sh
+ ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh
+ "${libsample_BINARY_DIR}:${libshiboken_BINARY_DIR}"
+ "${sample_BINARY_DIR}"
+ ${PYTHON_EXECUTABLE}
+ ${test_file})
+ set_tests_properties(${CMAKE_MATCH_1} PROPERTIES TIMEOUT 5)
+
+# Should set python path here
+# Looks like it's fixed in 2.8:
+# http://www.vtk.org/Bug/print_bug_page.php?bug_id=7885
+endforeach(test_file ${TEST_FILES})
+
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt
new file mode 100644
index 000000000..a630b3cb4
--- /dev/null
+++ b/tests/libsample/CMakeLists.txt
@@ -0,0 +1,22 @@
+project(libsample)
+
+set(libsample_SRC
+abstract.cpp
+complex.cpp
+derived.cpp
+functions.cpp
+implicitconv.cpp
+kindergarten.cpp
+listuser.cpp
+modifications.cpp
+pairuser.cpp
+point.cpp
+reference.cpp
+samplenamespace.cpp
+size.cpp
+)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+add_library(libsample SHARED ${libsample_SRC})
+set_property(TARGET libsample PROPERTY PREFIX "")
+
diff --git a/tests/libsample/abstract.cpp b/tests/libsample/abstract.cpp
new file mode 100644
index 000000000..8b49f37f8
--- /dev/null
+++ b/tests/libsample/abstract.cpp
@@ -0,0 +1,64 @@
+#include <iostream>
+#include "abstract.h"
+
+using namespace std;
+
+Abstract::Abstract(int id) : m_id(id)
+{
+ cout << __PRETTY_FUNCTION__;
+ show();
+ cout << endl;
+}
+
+Abstract::~Abstract()
+{
+ cout << __PRETTY_FUNCTION__;
+ show();
+ cout << endl;
+}
+
+void
+Abstract::unpureVirtual()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+}
+
+void
+Abstract::callUnpureVirtual()
+{
+ cout << __PRETTY_FUNCTION__ << " --- BEGIN" << endl;
+ this->unpureVirtual();
+ cout << __PRETTY_FUNCTION__ << " --- END" << endl;
+}
+
+
+void
+Abstract::callPureVirtual()
+{
+ cout << __PRETTY_FUNCTION__ << " --- BEGIN" << endl;
+ this->pureVirtual();
+ cout << __PRETTY_FUNCTION__ << " --- END" << endl;
+}
+
+void
+Abstract::show(PrintFormat format)
+{
+ cout << '<';
+ switch(format) {
+ case Short:
+ cout << this;
+ break;
+ case Verbose:
+ cout << "class " << className() << " | cptr: " << this;
+ cout << ", id: " << m_id;
+ break;
+ case OnlyId:
+ cout << "id: " << m_id;
+ break;
+ case ClassNameAndId:
+ cout << className() << " - id: " << m_id;
+ break;
+ }
+ cout << '>';
+}
+
diff --git a/tests/libsample/abstract.h b/tests/libsample/abstract.h
new file mode 100644
index 000000000..19e3a9dbf
--- /dev/null
+++ b/tests/libsample/abstract.h
@@ -0,0 +1,37 @@
+#ifndef ABSTRACT_H
+#define ABSTRACT_H
+
+class Abstract
+{
+public:
+ enum PrintFormat {
+ Short,
+ Verbose,
+ OnlyId,
+ ClassNameAndId
+ };
+
+ Abstract(int id = -1);
+ virtual ~Abstract();
+
+ int id() { return m_id; }
+
+ // factory method
+ static Abstract* createObject() { return 0; }
+
+ virtual void pureVirtual() = 0;
+ virtual void unpureVirtual();
+
+ void callPureVirtual();
+ void callUnpureVirtual();
+
+ void show(PrintFormat format = Verbose);
+
+protected:
+ virtual const char* className() { return "Abstract"; }
+
+private:
+ int m_id;
+};
+#endif // ABSTRACT_H
+
diff --git a/tests/libsample/complex.cpp b/tests/libsample/complex.cpp
new file mode 100644
index 000000000..9e93c961c
--- /dev/null
+++ b/tests/libsample/complex.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+#include "complex.h"
+
+using namespace std;
+
+Complex::Complex(double real, double imag)
+ : m_real(real), m_imag(imag)
+{
+ // cout << __PRETTY_FUNCTION__ << "[real=0.0, imag=0.0]" << endl;
+}
+
+Complex
+Complex::operator+(Complex& other)
+{
+ Complex result;
+ result.setReal(m_real + other.real());
+ result.setImaginary(m_imag + other.imag());
+ return result;
+}
+
+void
+Complex::show()
+{
+ cout << "(real: " << m_real << ", imag: " << m_imag << ")";
+}
+
+
diff --git a/tests/libsample/complex.h b/tests/libsample/complex.h
new file mode 100644
index 000000000..f8efb790c
--- /dev/null
+++ b/tests/libsample/complex.h
@@ -0,0 +1,25 @@
+#ifndef COMPLEX_H
+#define COMPLEX_H
+
+class Complex
+{
+public:
+ Complex(double real = 0.0, double imag = 0.0);
+ ~Complex() {}
+
+ double real() const { return m_real; }
+ void setReal(double real) { m_real = real; }
+ double imag() const { return m_imag; }
+ void setImaginary(double imag) { m_imag = imag; }
+
+ Complex operator+(Complex& other);
+
+ void show();
+
+private:
+ double m_real;
+ double m_imag;
+};
+
+#endif // COMPLEX_H
+
diff --git a/tests/libsample/derived.cpp b/tests/libsample/derived.cpp
new file mode 100644
index 000000000..9a86a9c94
--- /dev/null
+++ b/tests/libsample/derived.cpp
@@ -0,0 +1,80 @@
+#include <iostream>
+#include "derived.h"
+
+using namespace std;
+
+Derived::Derived(int id) : Abstract(id)
+{
+ cout << __PRETTY_FUNCTION__;
+ show();
+ cout << endl;
+}
+
+Derived::~Derived()
+{
+ cout << __PRETTY_FUNCTION__;
+ show();
+ cout << endl;
+}
+
+Abstract*
+Derived::createObject()
+{
+ static int id = 100;
+ return new Derived(id++);
+}
+
+void
+Derived::pureVirtual()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+}
+
+void
+Derived::unpureVirtual()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+}
+
+bool
+Derived::singleArgument(bool b)
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ return !b;
+}
+
+double
+Derived::defaultValue(int n)
+{
+ cout << __PRETTY_FUNCTION__ << "[n = 0]" << endl;
+ return ((double) n) + 0.1;
+}
+
+PolymorphicFuncEnum
+Derived::polymorphic(int i, int d)
+{
+ cout << __PRETTY_FUNCTION__ << "[i = 0, d = 0]" << endl;
+ return PolymorphicFunc_ii;
+}
+
+PolymorphicFuncEnum
+Derived::polymorphic(double n)
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ return PolymorphicFunc_d;
+}
+
+Derived::OtherPolymorphicFuncEnum
+Derived::otherPolymorphic(int a, int b, bool c, double d)
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ return OtherPolymorphicFunc_iibd;
+}
+
+Derived::OtherPolymorphicFuncEnum
+Derived::otherPolymorphic(int a, double b)
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ return OtherPolymorphicFunc_id;
+}
+
diff --git a/tests/libsample/derived.h b/tests/libsample/derived.h
new file mode 100644
index 000000000..5efc7c4b4
--- /dev/null
+++ b/tests/libsample/derived.h
@@ -0,0 +1,46 @@
+#ifndef DERIVED_H
+#define DERIVED_H
+
+#include "abstract.h"
+
+enum PolymorphicFuncEnum {
+ PolymorphicFunc_ii,
+ PolymorphicFunc_d
+};
+
+class Derived : public Abstract
+{
+public:
+ enum OtherPolymorphicFuncEnum {
+ OtherPolymorphicFunc_iibd,
+ OtherPolymorphicFunc_id
+ };
+
+ Derived(int id = -1);
+ virtual ~Derived();
+ virtual void pureVirtual();
+ virtual void unpureVirtual();
+
+ // factory method
+ static Abstract* createObject();
+
+ // single argument
+ bool singleArgument(bool b);
+
+ // method with default value
+ double defaultValue(int n = 0);
+
+ // overloads
+ PolymorphicFuncEnum polymorphic(int i = 0, int d = 0);
+ PolymorphicFuncEnum polymorphic(double n);
+
+ // more overloads
+ OtherPolymorphicFuncEnum otherPolymorphic(int a, int b, bool c, double d);
+ OtherPolymorphicFuncEnum otherPolymorphic(int a, double b);
+
+protected:
+ const char* getClassName() { return className(); }
+ virtual const char* className() { return "Derived"; }
+};
+#endif // DERIVED_H
+
diff --git a/tests/libsample/functions.cpp b/tests/libsample/functions.cpp
new file mode 100644
index 000000000..c35bc5be3
--- /dev/null
+++ b/tests/libsample/functions.cpp
@@ -0,0 +1,85 @@
+#include "functions.h"
+#include <string.h>
+#include <iostream>
+
+using namespace std;
+
+void
+printSomething()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+}
+
+int
+gimmeInt()
+{
+ static int val = 2;
+ val = val * 1.3;
+ return val;
+}
+
+double
+gimmeDouble()
+{
+ static double val = 7.77;
+ val = val * 1.3;
+ return val;
+}
+
+std::list<Complex>
+gimmeComplexList()
+{
+ std::list<Complex> lst;
+ lst.push_back(Complex());
+ lst.push_back(Complex(1.1, 2.2));
+ lst.push_back(Complex(1.3, 2.4));
+ return lst;
+}
+
+Complex
+sumComplexPair(std::pair<Complex, Complex> cpx_pair)
+{
+ return cpx_pair.first + cpx_pair.second;
+}
+
+double
+multiplyPair(std::pair<double, double> pair)
+{
+ return pair.first * pair.second;
+}
+
+int
+countCharacters(const char* text)
+{
+ int count;
+ for(count = 0; text[count] != '\0'; count++)
+ ;
+ return count;
+}
+
+char*
+makeCString()
+{
+ char* string = new char[strlen(__FUNCTION__) + 1];
+ strcpy(string, __FUNCTION__);
+ return string;
+}
+
+const char*
+returnCString()
+{
+ return __PRETTY_FUNCTION__;
+}
+
+GlobalPolyFuncEnum
+polymorphicFunc(int val)
+{
+ return GlobalPolyFunc_i;
+}
+
+GlobalPolyFuncEnum
+polymorphicFunc(double val)
+{
+ return GlobalPolyFunc_d;
+}
+
diff --git a/tests/libsample/functions.h b/tests/libsample/functions.h
new file mode 100644
index 000000000..77b2cb68f
--- /dev/null
+++ b/tests/libsample/functions.h
@@ -0,0 +1,36 @@
+#ifndef FUNCTIONS_H
+#define FUNCTIONS_H
+
+#include <list>
+#include <utility>
+#include "complex.h"
+
+enum GlobalEnum {
+ NoThing,
+ FirstThing,
+ SecondThing,
+ ThirdThing
+};
+
+enum GlobalPolyFuncEnum {
+ GlobalPolyFunc_i,
+ GlobalPolyFunc_d
+};
+
+void printSomething();
+int gimmeInt();
+double gimmeDouble();
+double multiplyPair(std::pair<double, double> pair);
+std::list<Complex> gimmeComplexList();
+Complex sumComplexPair(std::pair<Complex, Complex> cpx_pair);
+
+int countCharacters(const char* text);
+char* makeCString();
+const char* returnCString();
+
+// Tests polymorphism on functions (!methods)
+GlobalPolyFuncEnum polymorphicFunc(int val);
+GlobalPolyFuncEnum polymorphicFunc(double val);
+
+#endif // FUNCTIONS_H
+
diff --git a/tests/libsample/implicitconv.cpp b/tests/libsample/implicitconv.cpp
new file mode 100644
index 000000000..902707e18
--- /dev/null
+++ b/tests/libsample/implicitconv.cpp
@@ -0,0 +1,38 @@
+#include "implicitconv.h"
+
+ImplicitConv
+ImplicitConv::implicitConvCommon(ImplicitConv implicit)
+{
+ return implicit;
+}
+
+ImplicitConv
+ImplicitConv::implicitConvDefault(ImplicitConv implicit)
+{
+ return implicit;
+}
+
+ImplicitConv::ICPolymorphicFuncEnum
+ImplicitConv::implicitConvPolymorphism(ImplicitConv implicit, int dummyArg)
+{
+ return ImplicitConv::PolyFunc_Ii;
+}
+
+ImplicitConv::ICPolymorphicFuncEnum
+ImplicitConv::implicitConvPolymorphism(ImplicitConv implicit, bool dummyArg)
+{
+ return ImplicitConv::PolyFunc_Ib;
+}
+
+ImplicitConv::ICPolymorphicFuncEnum
+ImplicitConv::implicitConvPolymorphism(int dummyArg)
+{
+ return ImplicitConv::PolyFunc_i;
+}
+
+ImplicitConv::ICPolymorphicFuncEnum
+ImplicitConv::implicitConvPolymorphism(CtorEnum dummyArg)
+{
+ return ImplicitConv::PolyFunc_C;
+}
+
diff --git a/tests/libsample/implicitconv.h b/tests/libsample/implicitconv.h
new file mode 100644
index 000000000..538150870
--- /dev/null
+++ b/tests/libsample/implicitconv.h
@@ -0,0 +1,44 @@
+#ifndef IMPLICITCONV_H
+#define IMPLICITCONV_H
+
+class ImplicitConv
+{
+public:
+ enum CtorEnum {
+ CtorNone,
+ CtorOne,
+ CtorTwo,
+ CtorThree
+ };
+
+ enum ICPolymorphicFuncEnum {
+ PolyFunc_Ii,
+ PolyFunc_Ib,
+ PolyFunc_i,
+ PolyFunc_C
+ };
+
+ ImplicitConv() : m_ctorEnum(CtorNone), m_objId(-1) {}
+ ImplicitConv(int objId) : m_ctorEnum(CtorOne), m_objId(objId) {}
+ ImplicitConv(CtorEnum ctorEnum) : m_ctorEnum(ctorEnum), m_objId(-1) {}
+ ~ImplicitConv() {}
+
+ CtorEnum ctorEnum() { return m_ctorEnum; }
+ int objId() { return m_objId; }
+
+ static ImplicitConv implicitConvCommon(ImplicitConv implicit);
+
+ static ImplicitConv implicitConvDefault(ImplicitConv implicit = CtorTwo);
+
+ static ICPolymorphicFuncEnum implicitConvPolymorphism(ImplicitConv implicit, int dummyArg);
+ static ICPolymorphicFuncEnum implicitConvPolymorphism(ImplicitConv implicit, bool dummyArg);
+ static ICPolymorphicFuncEnum implicitConvPolymorphism(int dummyArg);
+ static ICPolymorphicFuncEnum implicitConvPolymorphism(CtorEnum dummyArg);
+
+private:
+ CtorEnum m_ctorEnum;
+ int m_objId;
+};
+
+#endif // IMPLICITCONV_H
+
diff --git a/tests/libsample/kindergarten.cpp b/tests/libsample/kindergarten.cpp
new file mode 100644
index 000000000..8332e4fe7
--- /dev/null
+++ b/tests/libsample/kindergarten.cpp
@@ -0,0 +1,64 @@
+#include <iostream>
+#include "kindergarten.h"
+
+using namespace std;
+
+KinderGarten::~KinderGarten()
+{
+ cout << __PRETTY_FUNCTION__ << " ---- BEGIN" << endl;
+ killChildren();
+ cout << __PRETTY_FUNCTION__ << " ---- END" << endl;
+}
+
+void
+KinderGarten::addChild(Abstract* child)
+{
+ m_children.push_back(child);
+}
+
+void
+KinderGarten::killChildren()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ while (!m_children.empty()) {
+ m_children.back()->show();
+ cout << endl;
+ delete m_children.back();
+ m_children.pop_back();
+ }
+}
+
+void
+KinderGarten::killChild(Abstract* child)
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ if (child) {
+ m_children.remove(child);
+// delete child;
+ }
+}
+
+Abstract*
+KinderGarten::releaseChild(Abstract* child)
+{
+ for(ChildList::iterator child_iter = m_children.begin();
+ child_iter != m_children.end(); child_iter++) {
+ if (child == *child_iter) {
+ m_children.erase(child_iter);
+ return child;
+ }
+ }
+}
+
+void
+KinderGarten::show()
+{
+ cout << "[";
+ for(ChildList::iterator child_iter = m_children.begin();
+ child_iter != m_children.end(); child_iter++) {
+ if (child_iter != m_children.begin())
+ cout << ", ";
+ (*child_iter)->show();
+ }
+ cout << "]";
+}
diff --git a/tests/libsample/kindergarten.h b/tests/libsample/kindergarten.h
new file mode 100644
index 000000000..b0a083dce
--- /dev/null
+++ b/tests/libsample/kindergarten.h
@@ -0,0 +1,29 @@
+#ifndef KINDERGARTEN_H
+#define KINDERGARTEN_H
+
+#include <list>
+#include "abstract.h"
+
+class KinderGarten
+{
+public:
+ typedef std::list<Abstract*> ChildList;
+
+ KinderGarten() {}
+ ~KinderGarten();
+
+ void addChild(Abstract* child);
+ Abstract* releaseChild(Abstract* child);
+ ChildList children() { return m_children; }
+
+ void killChildren();
+ void killChild(Abstract* child);
+
+ void show();
+
+private:
+ ChildList m_children;
+};
+
+#endif // KINDERGARTEN_H
+
diff --git a/tests/libsample/listuser.cpp b/tests/libsample/listuser.cpp
new file mode 100644
index 000000000..0b9a14ff5
--- /dev/null
+++ b/tests/libsample/listuser.cpp
@@ -0,0 +1,47 @@
+#include <iostream>
+#include <numeric>
+#include <cstdlib>
+#include "listuser.h"
+
+using namespace std;
+
+std::list<int>
+ListUser::callCreateList()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ return createList();
+}
+
+std::list<int>
+ListUser::createList()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ std::list<int> retval;
+ for (int i = 0; i < 4; i++)
+ retval.push_front(rand());
+ return retval;
+}
+
+std::list<Complex>
+ListUser::createComplexList(Complex cpx0, Complex cpx1)
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ std::list<Complex> retval;
+ retval.push_back(cpx0);
+ retval.push_back(cpx1);
+ return retval;
+}
+
+double
+ListUser::sumList(std::list<int> vallist)
+{
+ return std::accumulate(vallist.begin(), vallist.end(), 0.0);
+}
+
+double
+ListUser::sumList(std::list<double> vallist)
+{
+ return std::accumulate(vallist.begin(), vallist.end(), 0.0);
+}
+
+
diff --git a/tests/libsample/listuser.h b/tests/libsample/listuser.h
new file mode 100644
index 000000000..c1ea7091e
--- /dev/null
+++ b/tests/libsample/listuser.h
@@ -0,0 +1,23 @@
+#ifndef LISTUSER_H
+#define LISTUSER_H
+
+#include <list>
+#include "complex.h"
+
+class ListUser
+{
+public:
+ ListUser() {}
+ ~ListUser() {}
+
+ virtual std::list<int> createList();
+ std::list<int> callCreateList();
+
+ static std::list<Complex> createComplexList(Complex cpx0, Complex cpx1);
+
+ double sumList(std::list<int> vallist);
+ double sumList(std::list<double> vallist);
+};
+
+#endif // LISTUSER_H
+
diff --git a/tests/libsample/main.cpp b/tests/libsample/main.cpp
new file mode 100644
index 000000000..7fc563679
--- /dev/null
+++ b/tests/libsample/main.cpp
@@ -0,0 +1,216 @@
+#include <iostream>
+#include <list>
+#include "abstract.h"
+#include "derived.h"
+#include "kindergarten.h"
+#include "complex.h"
+#include "point.h"
+#include "size.h"
+#include "listuser.h"
+#include "samplenamespace.h"
+
+using namespace std;
+
+int
+main(int argv, char **argc)
+{
+ cout << endl;
+
+ Derived derived;
+
+ cout << endl;
+
+ derived.unpureVirtual();
+ derived.pureVirtual();
+ derived.callPureVirtual();
+
+ cout << endl;
+ Abstract* abs;
+ abs = Abstract::createObject();
+ cout << "Abstract::createObject(): " << abs << endl << endl;
+ delete abs;
+
+ abs = Derived::createObject();
+ cout << "Derived::createObject() : ";
+ abs->show();
+ cout << endl;
+ delete abs;
+ cout << endl;
+
+ abs = Derived::createObject();
+ cout << "Derived::createObject() : ";
+ abs->show();
+ cout << endl;
+ delete abs;
+ cout << endl;
+
+ cout << endl << "-----------------------------------------" << endl;
+
+ KinderGarten kg;
+ Derived* d[] = { 0, 0, 0 };
+
+ for (int i = 0; i < 3; i++) {
+ d[i] = new Derived(i);
+ d[i]->show();
+ cout << endl;
+ kg.addChild(d[i]);
+ }
+
+ kg.show();
+ cout << endl;
+
+ cout << endl << "* kill child ";
+ d[2]->show();
+ cout << " ----------------" << endl;
+ kg.killChild(d[2]);
+ kg.show();
+ cout << endl;
+
+ cout << endl << "* release child ";
+ d[1]->show();
+ cout << " -------------" << endl;
+ Abstract* released = kg.releaseChild(d[1]);
+ cout << "released: ";
+ released->show();
+ cout << endl;
+ kg.show();
+ cout << endl;
+
+ cout << endl << "* kill children ------------------------------------" << endl;
+ kg.killChildren();
+ kg.show();
+ cout << endl << endl;
+
+ cout << "-----------------------------------------" << endl;
+ ListUser lu;
+ cout << "ListUser::createList()" << endl;
+ std::list<int> intlist = lu.createList();
+ for (std::list<int>::iterator it = intlist.begin(); it != intlist.end(); it++) {
+ cout << "* " << *it << endl;
+ }
+
+ cout << "ListUser::createComplexList" << endl;
+ std::list<Complex> cpxlist = ListUser::createComplexList(Complex(1.1, 2.2), Complex(3.3, 4.4));
+ for (std::list<Complex>::iterator it = cpxlist.begin(); it != cpxlist.end(); it++) {
+ cout << "* ";
+ (*it).show();
+ cout << endl;
+ }
+ cout << endl;
+
+ cout << "-----------------------------------------" << endl;
+ cout << "SampleNamespace" << endl;
+
+ cout << "SampleNamespace::RandomNumber: ";
+ cout << SampleNamespace::getNumber(SampleNamespace::RandomNumber);
+ cout << endl;
+ cout << "SampleNamespace::UnixTime: ";
+ cout << SampleNamespace::getNumber(SampleNamespace::UnixTime);
+ cout << endl;
+ double val_d = 1.3;
+ cout << "SampleNamespace::powerOfTwo(" << val_d << "): ";
+ cout << SampleNamespace::powerOfTwo(val_d) << endl;
+ int val_i = 7;
+ cout << "SampleNamespace::powerOfTwo(" << val_i << "): ";
+ cout << SampleNamespace::powerOfTwo(val_i) << endl;
+ cout << endl;
+
+ cout << "-----------------------------------------" << endl;
+ cout << "Point" << endl;
+
+ Point p1(1.1, 2.2);
+ cout << "p1: ";
+ p1.show();
+ cout << endl;
+
+ Point p2(3.4, 5.6);
+ cout << "p2: ";
+ p2.show();
+ cout << endl;
+
+ cout << "p1 + p2 == ";
+ (p1 + p2).show();
+ cout << endl;
+
+ cout << "p1 * 2.0 == ";
+ (p1 * 2.0).show();
+ cout << endl;
+
+ cout << "1.5 * p2 == ";
+ (1.5 * p2).show();
+ cout << endl;
+
+ cout << "p1: ";
+ p1.show();
+ cout << endl << "p2: ";
+ p2.show();
+ cout << endl << "p1 += p2" << endl;
+ p1 += p2;
+ cout << "p1: ";
+ p1.show();
+ cout << endl;
+
+ cout << "p1 == p2 ? " << ((p1 == p2) ? "true" : "false") << endl;
+ cout << "p1 == p1 ? " << ((p1 == p1) ? "true" : "false") << endl;
+ cout << "p2 == p2 ? " << ((p2 == p2) ? "true" : "false") << endl;
+
+ cout << "-----------------------------------------" << endl;
+ cout << "Size" << endl;
+
+ Size s1(2, 2);
+ cout << "s1: ";
+ s1.show();
+ cout << ", area: " << s1.calculateArea();
+ cout << endl;
+
+ Size s2(3, 5);
+ cout << "s2: ";
+ s2.show();
+ cout << ", area: " << s2.calculateArea();
+ cout << endl;
+
+ cout << endl;
+
+ cout << "s1 == s2 ? " << ((s1 == s2) ? "true" : "false") << endl;
+ cout << "s1 != s2 ? " << ((s1 != s2) ? "true" : "false") << endl;
+
+ cout << "s1 < s2 ? " << ((s1 < s2) ? "true" : "false") << endl;
+ cout << "s1 <= s2 ? " << ((s1 <= s2) ? "true" : "false") << endl;
+ cout << "s1 > s2 ? " << ((s1 > s2) ? "true" : "false") << endl;
+ cout << "s1 >= s2 ? " << ((s1 >= s2) ? "true" : "false") << endl;
+
+ cout << "s1 < 10 ? " << ((s1 < 10) ? "true" : "false") << endl;
+ cout << "s1 <= 10 ? " << ((s1 <= 10) ? "true" : "false") << endl;
+ cout << "s1 > 10 ? " << ((s1 > 10) ? "true" : "false") << endl;
+ cout << "s1 >= 10 ? " << ((s1 >= 10) ? "true" : "false") << endl;
+ cout << "s2 < 10 ? " << ((s2 < 10) ? "true" : "false") << endl;
+ cout << "s2 <= 10 ? " << ((s2 <= 10) ? "true" : "false") << endl;
+ cout << "s2 > 10 ? " << ((s2 > 10) ? "true" : "false") << endl;
+ cout << "s2 >= 10 ? " << ((s2 >= 10) ? "true" : "false") << endl;
+ cout << endl;
+
+ cout << "s1: ";
+ s1.show();
+ cout << endl << "s2: ";
+ s2.show();
+ cout << endl << "s1 += s2" << endl;
+ s1 += s2;
+ cout << "s1: ";
+ s1.show();
+ cout << endl;
+
+ cout << endl;
+
+ cout << "s1: ";
+ s1.show();
+ cout << endl << "s1 *= 2.0" << endl;
+ s1 *= 2.0;
+ cout << "s1: ";
+ s1.show();
+ cout << endl;
+
+ cout << endl;
+
+ return 0;
+}
+
diff --git a/tests/libsample/modifications.cpp b/tests/libsample/modifications.cpp
new file mode 100644
index 000000000..68cf6fe6c
--- /dev/null
+++ b/tests/libsample/modifications.cpp
@@ -0,0 +1,68 @@
+#include <iostream>
+#include "modifications.h"
+
+using namespace std;
+
+std::pair<double, double>
+Modifications::pointToPair(Point pt, bool* ok)
+{
+ std::pair<double, double> retval(pt.x(), pt.y());
+ *ok = true;
+ return retval;
+}
+
+double
+Modifications::multiplyPointCoordsPlusValue(bool* ok, Point pt, double value)
+{
+ double retval = (pt.x() * pt.y()) + value;
+ *ok = true;
+ return retval;
+}
+
+int
+Modifications::doublePlus(int value, int plus)
+{
+ return (2 * value) + plus;
+}
+
+int
+Modifications::power(int base, int exponent)
+{
+ if (exponent == 0)
+ return 1;
+ int retval = base;
+ for (int i = 1; i < exponent; i++)
+ retval = retval * base;
+ return retval;
+}
+
+int
+Modifications::timesTen(int number)
+{
+ return number * 10;
+}
+
+int
+Modifications::increment(int number)
+{
+ return ++number;
+}
+
+void
+Modifications::exclusiveCppStuff()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+}
+
+int
+Modifications::cppMultiply(int a, int b)
+{
+ return a * b;
+}
+
+const char*
+Modifications::className()
+{
+ return "Modifications";
+}
+
diff --git a/tests/libsample/modifications.h b/tests/libsample/modifications.h
new file mode 100644
index 000000000..793808161
--- /dev/null
+++ b/tests/libsample/modifications.h
@@ -0,0 +1,73 @@
+#ifndef MODIFICATIONS_H
+#define MODIFICATIONS_H
+
+#include <utility>
+#include "point.h"
+
+class Modifications
+{
+public:
+ Modifications() {}
+ ~Modifications() {}
+
+ enum PolymorphicModFunc {
+ PolymorphicNone,
+ Polymorphic_ibid,
+ Polymorphic_ibib,
+ Polymorphic_ibiP,
+ Polymorphic_ibii,
+ Polymorphic_ibPP
+ };
+
+ // those polymorphic methods should be heavily modified
+ // to push the overload decisor to its limits
+ PolymorphicModFunc polymorphic(int a0, bool b0, int c0, double d0) { return Polymorphic_ibid; }
+ PolymorphicModFunc polymorphic(int a1, bool b1, int c1, bool d1) { return Polymorphic_ibib; }
+ PolymorphicModFunc polymorphic(int a2, bool b2, int c2, Point d2) { return Polymorphic_ibiP; }
+ PolymorphicModFunc polymorphic(int a3, bool b3, int c3 = 123, int d3 = 456) { return Polymorphic_ibii; }
+ PolymorphicModFunc polymorphic(int a4, bool b4, Point c4, Point d4) { return Polymorphic_ibPP; }
+
+ // 'ok' must be removed and the return value will be changed
+ // to a tuple (PyObject*) containing the expected result plus
+ // the 'ok' value as a Python boolean
+ std::pair<double, double> pointToPair(Point pt, bool* ok);
+
+ // same as 'pointToPair' except that this time 'ok' is the first argument
+ double multiplyPointCoordsPlusValue(bool* ok, Point pt, double value);
+
+ // completely remove 'plus' from the Python side
+ int doublePlus(int value, int plus = 0);
+
+ // the default value for both arguments must be changed in Python
+ int power(int base = 1, int exponent = 0);
+
+ // in Python set argument default value to 10
+ int timesTen(int number);
+
+ // in Python remove the argument default value
+ int increment(int number = 0);
+
+ // don't export this method to Python
+ void exclusiveCppStuff();
+
+ // change the name of this regular method
+ int cppMultiply(int a, int b);
+
+ // change the name of this virtual method
+ virtual const char* className();
+};
+
+class AbstractModifications : public Modifications
+{
+public:
+ AbstractModifications() {}
+ ~AbstractModifications() {}
+
+ bool invert(bool value) { return !value; }
+
+ // completely remove this method in Python
+ virtual void pointlessPureVirtualMethod() = 0;
+};
+
+#endif // MODIFICATIONS_H
+
diff --git a/tests/libsample/pairuser.cpp b/tests/libsample/pairuser.cpp
new file mode 100644
index 000000000..8983630e2
--- /dev/null
+++ b/tests/libsample/pairuser.cpp
@@ -0,0 +1,32 @@
+#include <iostream>
+#include "pairuser.h"
+
+using namespace std;
+
+std::pair<int, int>
+PairUser::callCreatePair()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ return createPair();
+}
+
+std::pair<int, int>
+PairUser::createPair()
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ return std::pair<int, int>(10, 20);
+}
+
+std::pair<Complex, Complex>
+PairUser::createComplexPair(Complex cpx0, Complex cpx1)
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+ return std::pair<Complex, Complex>(cpx0, cpx1);
+}
+
+double
+PairUser::sumPair(std::pair<int, double> pair)
+{
+ return ((double) pair.first) + pair.second;
+}
+
diff --git a/tests/libsample/pairuser.h b/tests/libsample/pairuser.h
new file mode 100644
index 000000000..27cf76681
--- /dev/null
+++ b/tests/libsample/pairuser.h
@@ -0,0 +1,19 @@
+#ifndef PAIRUSER_H
+#define PAIRUSER_H
+
+#include <utility>
+#include "complex.h"
+
+class PairUser
+{
+public:
+ PairUser() {}
+ ~PairUser() {}
+
+ virtual std::pair<int, int> createPair();
+ std::pair<int, int> callCreatePair();
+ static std::pair<Complex, Complex> createComplexPair(Complex cpx0, Complex cpx1);
+ double sumPair(std::pair<int, double> pair);
+};
+#endif // PAIRUSER_H
+
diff --git a/tests/libsample/point.cpp b/tests/libsample/point.cpp
new file mode 100644
index 000000000..ad816025e
--- /dev/null
+++ b/tests/libsample/point.cpp
@@ -0,0 +1,111 @@
+#include <iostream>
+#include "point.h"
+
+using namespace std;
+
+Point::Point(int x, int y) : m_x(x), m_y(y)
+{
+ // cout << __PRETTY_FUNCTION__ << " [x=0, y=0]" << endl;
+}
+
+Point::Point(double x, double y) : m_x(x), m_y(y)
+{
+ // cout << __PRETTY_FUNCTION__ << endl;
+}
+
+void
+Point::show()
+{
+ cout << "(x: " << m_x << ", y: " << m_y << ")";
+}
+
+bool
+Point::operator==(const Point& other)
+{
+ return m_x == other.m_x && m_y == other.m_y;
+}
+
+Point
+Point::operator+(const Point& other)
+{
+ return Point(m_x + other.m_x, m_y + other.m_y);
+}
+
+Point
+Point::operator-(const Point& other)
+{
+ return Point(m_x - other.m_x, m_y - other.m_y);
+}
+
+Point&
+Point::operator+=(Point &other)
+{
+ m_x += other.m_x;
+ m_y += other.m_y;
+ return *this;
+}
+
+Point&
+Point::operator-=(Point &other)
+{
+ m_x -= other.m_x;
+ m_y -= other.m_y;
+ return *this;
+}
+
+Point
+operator*(Point& pt, double mult)
+{
+ return Point(pt.m_x * mult, pt.m_y * mult);
+}
+
+Point
+operator*(Point& pt, int mult)
+{
+ return Point(((int) pt.m_x) * mult, ((int) pt.m_y) * mult);
+}
+
+Point
+operator*(double mult, Point& pt)
+{
+ return Point(pt.m_x * mult, pt.m_y * mult);
+}
+
+Point
+operator*(int mult, Point& pt)
+{
+ return Point(((int) pt.m_x) * mult, ((int) pt.m_y) * mult);
+}
+
+Point
+operator-(const Point& pt)
+{
+ return Point(-pt.m_x, -pt.m_y);
+}
+
+bool
+operator!(const Point& pt)
+{
+ return (pt.m_x == 0.0 && pt.m_y == 0.0);
+}
+
+Complex
+transmutePointIntoComplex(Point point)
+{
+ Complex cpx(point.x(), point.y());
+ // cout << __PRETTY_FUNCTION__ << " ";
+ // point.show();
+ // cout << endl;
+ return cpx;
+}
+
+Point
+transmuteComplexIntoPoint(Complex cpx)
+{
+ Point pt(cpx.real(), cpx.imag());
+ // cout << __PRETTY_FUNCTION__ << " ";
+ // cpx.show();
+ // cout << endl;
+ return pt;
+}
+
diff --git a/tests/libsample/point.h b/tests/libsample/point.h
new file mode 100644
index 000000000..e5ec9c1bc
--- /dev/null
+++ b/tests/libsample/point.h
@@ -0,0 +1,51 @@
+#ifndef POINT_H
+#define POINT_H
+
+#include "complex.h"
+#include <utility>
+
+class Point
+{
+public:
+ Point(int x = 0, int y = 0);
+ Point(double x, double y);
+ ~Point() {}
+
+ double x() const { return m_x; }
+ double y() const { return m_y; }
+
+ bool operator==(const Point& other);
+ Point operator+(const Point& other);
+ Point operator-(const Point& other);
+
+ friend Point operator*(Point& pt, double mult);
+ friend Point operator*(Point& pt, int mult);
+ friend Point operator*(double mult, Point& pt);
+ friend Point operator*(int mult, Point& pt);
+ friend Point operator-(const Point& pt);
+ friend bool operator!(const Point& pt);
+
+ Point& operator+=(Point &other);
+ Point& operator-=(Point &other);
+
+ void show();
+
+private:
+ double m_x;
+ double m_y;
+};
+
+Point operator*(Point& pt, double mult);
+Point operator*(Point& pt, int mult);
+Point operator*(double mult, Point& pt);
+Point operator*(int mult, Point& pt);
+Point operator-(const Point& pt);
+bool operator!(const Point& pt);
+
+Complex transmutePointIntoComplex(Point point);
+Point transmuteComplexIntoPoint(Complex cpx);
+
+Point operator*(Point& pt, double multiplier);
+
+#endif // POINT_H
+
diff --git a/tests/libsample/reference.cpp b/tests/libsample/reference.cpp
new file mode 100644
index 000000000..fb3e78e49
--- /dev/null
+++ b/tests/libsample/reference.cpp
@@ -0,0 +1,11 @@
+#include <iostream>
+#include "reference.h"
+
+using namespace std;
+
+void
+Reference::show() const
+{
+ cout << "Reference.objId: " << m_objId;
+}
+
diff --git a/tests/libsample/reference.h b/tests/libsample/reference.h
new file mode 100644
index 000000000..bafd2492a
--- /dev/null
+++ b/tests/libsample/reference.h
@@ -0,0 +1,24 @@
+#ifndef REFERENCE_H
+#define REFERENCE_H
+
+class Reference
+{
+public:
+ explicit Reference(int objId = -1)
+ : m_objId(objId) {}
+ ~Reference() {}
+
+ double objId() { return m_objId; }
+ void setObjId(int objId) { m_objId = objId; }
+
+ static int usesReference(Reference& r) { return r.m_objId; }
+ static int usesConstReference(const Reference& r) { return r.m_objId; }
+
+ void show() const;
+
+private:
+ int m_objId;
+};
+
+#endif // REFERENCE_H
+
diff --git a/tests/libsample/samplenamespace.cpp b/tests/libsample/samplenamespace.cpp
new file mode 100644
index 000000000..ebf2ff74d
--- /dev/null
+++ b/tests/libsample/samplenamespace.cpp
@@ -0,0 +1,48 @@
+#include <iostream>
+#include <cstdlib>
+#include <time.h>
+#include "samplenamespace.h"
+
+using namespace std;
+
+namespace SampleNamespace
+{
+
+OutValue
+enumInEnumOut(InValue in)
+{
+ OutValue retval;
+ switch(in) {
+ case ZeroIn:
+ retval = ZeroOut;
+ break;
+ case OneIn:
+ retval = OneOut;
+ break;
+ case TwoIn:
+ retval = TwoOut;
+ break;
+ default:
+ retval = (OutValue) -1;
+ }
+ return retval;
+}
+
+int
+getNumber(Option opt)
+{
+ int retval;
+ switch(opt) {
+ case RandomNumber:
+ retval = rand() % 100;
+ break;
+ case UnixTime:
+ retval = (int) time(0);
+ break;
+ default:
+ retval = 0;
+ }
+ return retval;
+}
+
+} // namespace SampleNamespace
diff --git a/tests/libsample/samplenamespace.h b/tests/libsample/samplenamespace.h
new file mode 100644
index 000000000..2c65aeab0
--- /dev/null
+++ b/tests/libsample/samplenamespace.h
@@ -0,0 +1,36 @@
+#ifndef SAMPLENAMESPACE_H
+#define SAMPLENAMESPACE_H
+
+namespace SampleNamespace
+{
+
+enum Option {
+ None,
+ RandomNumber,
+ UnixTime
+};
+
+enum InValue {
+ ZeroIn,
+ OneIn,
+ TwoIn
+};
+
+enum OutValue {
+ ZeroOut,
+ OneOut,
+ TwoOut
+};
+
+OutValue enumInEnumOut(InValue in);
+
+int getNumber(Option opt);
+
+inline double powerOfTwo(double num) {
+ return num * num;
+}
+
+} // namespace SampleNamespace
+
+#endif // SAMPLENAMESPACE_H
+
diff --git a/tests/libsample/size.cpp b/tests/libsample/size.cpp
new file mode 100644
index 000000000..63af9c828
--- /dev/null
+++ b/tests/libsample/size.cpp
@@ -0,0 +1,11 @@
+#include <iostream>
+#include "size.h"
+
+using namespace std;
+
+void
+Size::show() const
+{
+ cout << "(width: " << m_width << ", height: " << m_height << ")";
+}
+
diff --git a/tests/libsample/size.h b/tests/libsample/size.h
new file mode 100644
index 000000000..48f0d772a
--- /dev/null
+++ b/tests/libsample/size.h
@@ -0,0 +1,152 @@
+#ifndef SIZE_H
+#define SIZE_H
+
+class Size
+{
+public:
+ Size(double width = 0.0, double height = 0.0) : m_width(width), m_height(height) {}
+ ~Size() {}
+
+ double width() { return m_width; }
+ void setWidth(double width) { m_width = width; }
+ double height() { return m_height; }
+ void setHeight(double height) { m_height = height; }
+
+ double calculateArea() const { return m_width * m_height; }
+
+ // Comparison Operators
+ inline bool operator==(const Size& other)
+ {
+ return m_width == other.m_width && m_height == other.m_height;
+ }
+
+ inline bool operator<(const Size& other)
+ {
+ return calculateArea() < other.calculateArea();
+ }
+
+ inline bool operator>(const Size& other)
+ {
+ return calculateArea() > other.calculateArea();
+ }
+
+ inline bool operator<=(const Size& other)
+ {
+ return calculateArea() <= other.calculateArea();
+ }
+
+ inline bool operator>=(const Size& other)
+ {
+ return calculateArea() >= other.calculateArea();
+ }
+
+ inline bool operator<(double area) { return calculateArea() < area; }
+ inline bool operator>(double area) { return calculateArea() > area; }
+ inline bool operator<=(double area) { return calculateArea() <= area; }
+ inline bool operator>=(double area) { return calculateArea() >= area; }
+
+ // Arithmetic Operators
+ Size& operator+=(const Size& s)
+ {
+ m_width += s.m_width;
+ m_height += s.m_height;
+ return *this;
+ }
+
+ Size& operator-=(const Size& s)
+ {
+ m_width -= s.m_width;
+ m_height -= s.m_height;
+ return *this;
+ }
+
+ Size& operator*=(double mult)
+ {
+ m_width *= mult;
+ m_height *= mult;
+ return *this;
+ }
+
+ Size& operator/=(double div)
+ {
+ m_width /= div;
+ m_height /= div;
+ return *this;
+ }
+
+ // TODO: add ++size, size++, --size, size--
+
+ // External operators
+ friend inline bool operator!=(const Size&, const Size&);
+ friend inline const Size operator+(const Size&, const Size&);
+ friend inline const Size operator-(const Size&, const Size&);
+ friend inline const Size operator*(const Size&, double);
+ friend inline const Size operator*(double, const Size&);
+ friend inline const Size operator/(const Size&, double);
+
+ friend inline bool operator<(double, const Size&);
+ friend inline bool operator>(double, const Size&);
+ friend inline bool operator<=(double, const Size&);
+ friend inline bool operator>=(double, const Size&);
+
+ void show() const;
+
+private:
+ double m_width;
+ double m_height;
+};
+
+// Comparison Operators
+inline bool operator!=(const Size& s1, const Size& s2)
+{
+ return s1.m_width != s2.m_width || s1.m_height != s2.m_height;
+}
+
+inline bool operator<(double area, const Size& s)
+{
+ return area < s.calculateArea();
+}
+
+inline bool operator>(double area, const Size& s)
+{
+ return area > s.calculateArea();
+}
+
+inline bool operator<=(double area, const Size& s)
+{
+ return area <= s.calculateArea();
+}
+
+inline bool operator>=(double area, const Size& s)
+{
+ return area >= s.calculateArea();
+}
+
+// Arithmetic Operators
+inline const Size operator+(const Size& s1, const Size& s2)
+{
+ return Size(s1.m_width + s2.m_width, s1.m_height + s2.m_height);
+}
+
+inline const Size operator-(const Size& s1, const Size& s2)
+{
+ return Size(s1.m_width - s2.m_width, s1.m_height - s2.m_height);
+}
+
+inline const Size operator*(const Size& s, double mult)
+{
+ return Size(s.m_width * mult, s.m_height * mult);
+}
+
+inline const Size operator*(double mult, const Size& s)
+{
+ return Size(s.m_width * mult, s.m_height * mult);
+}
+
+inline const Size operator/(const Size& s, double div)
+{
+ return Size(s.m_width / div, s.m_height / div);
+}
+
+#endif // SIZE_H
+
diff --git a/tests/run_test.sh b/tests/run_test.sh
new file mode 100755
index 000000000..ed86ea30c
--- /dev/null
+++ b/tests/run_test.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+
+# This is a nasty workaround of a CTest limitation
+# of setting the environment variables for the test.
+
+
+LIB_PATH=$LD_LIBRARY_PATH:$1
+PYTHON_PATH=$PYTHONPATH:$2
+PYTHON_EXEC=$3
+TEST_FILE=$4
+
+LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_PATH PYTHONPATH=$PYTHON_PATH $PYTHON_EXEC $TEST_FILE
+
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt
new file mode 100644
index 000000000..e89d7d765
--- /dev/null
+++ b/tests/samplebinding/CMakeLists.txt
@@ -0,0 +1,44 @@
+project(sample)
+
+set(sample_TYPESYSTEM
+${CMAKE_CURRENT_SOURCE_DIR}/typesystem_sample.xml
+)
+
+set(sample_SRC
+${CMAKE_CURRENT_BINARY_DIR}/sample/abstractmodifications_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/abstract_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/derived_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/implicitconv_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/listuser_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/modifications_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/point_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/reference_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/sample_module_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/size_wrapper.cpp
+)
+
+add_custom_command(OUTPUT ${sample_SRC}
+COMMAND ${CMAKE_BINARY_DIR}/shiboken
+ ${CMAKE_CURRENT_SOURCE_DIR}/global.h
+ --include-paths=${libsample_SOURCE_DIR}
+ --typesystem-paths=${CMAKE_CURRENT_SOURCE_DIR}
+ --output-directory=${CMAKE_CURRENT_BINARY_DIR}
+ ${sample_TYPESYSTEM}
+WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+COMMENT "Running generator for test binding..."
+)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}
+ ${PYTHON_INCLUDE_PATH}
+ ${libsample_SOURCE_DIR}
+ ${libshiboken_SOURCE_DIR})
+add_library(sample MODULE ${sample_SRC})
+set_property(TARGET sample PROPERTY PREFIX "")
+target_link_libraries(sample
+ libsample
+ ${PYTHON_LIBRARIES}
+ libshiboken)
+
diff --git a/tests/samplebinding/abstract_test.py b/tests/samplebinding/abstract_test.py
new file mode 100755
index 000000000..9d4c51f2c
--- /dev/null
+++ b/tests/samplebinding/abstract_test.py
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+
+'''Test cases for Abstract class'''
+
+import sys
+import unittest
+
+from sample import Abstract
+
+class Incomplete(Abstract):
+ def __init__(self):
+ Abstract.__init__(self)
+
+class Concrete(Abstract):
+ def __init__(self):
+ Abstract.__init__(self)
+ self.pure_virtual_called = False
+ self.unpure_virtual_called = False
+
+ def pureVirtual(self):
+ self.pure_virtual_called = True
+
+ def unpureVirtual(self):
+ self.unpure_virtual_called = True
+
+
+class AbstractTest(unittest.TestCase):
+ '''Test case for Abstract class'''
+
+ def testAbstractPureVirtualMethodAvailability(self):
+ '''Test if Abstract class pure virtual method was properly wrapped.'''
+ self.assert_('pureVirtual' in dir(Abstract))
+
+ def testAbstractInstanciation(self):
+ '''Test if instanciation of an abstract class raises the correct exception.'''
+ self.assertRaises(NotImplementedError, Abstract)
+
+ def testUnimplementedPureVirtualMethodCall(self):
+ '''Test if calling a pure virtual method raises the correct exception.'''
+ i = Incomplete()
+ self.assertRaises(NotImplementedError, i.pureVirtual)
+
+ def testReimplementedVirtualMethodCall(self):
+ '''Test if instanciation of an abstract class raises the correct exception.'''
+ i = Concrete()
+ self.assertRaises(NotImplementedError, i.callPureVirtual)
+
+ def testReimplementedVirtualMethodCall(self):
+ '''Test if a Python override of a virtual method is correctly called from C++.'''
+ c = Concrete()
+ c.callUnpureVirtual()
+ self.assert_(c.unpure_virtual_called)
+
+ def testImplementedPureVirtualMethodCall(self):
+ '''Test if a Python override of a pure virtual method is correctly called from C++.'''
+ c = Concrete()
+ c.callPureVirtual()
+ self.assert_(c.pure_virtual_called)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/complex_conversions.h b/tests/samplebinding/complex_conversions.h
new file mode 100644
index 000000000..8caaef03b
--- /dev/null
+++ b/tests/samplebinding/complex_conversions.h
@@ -0,0 +1,23 @@
+template<>
+struct Converter<Complex>
+{
+ static PyObject* toPython(ValueHolder<Complex> cpx)
+ {
+ /*
+ fprintf(stderr, "[%s:%d] cpx.real: %f, cpx.imag: %f\n",
+ __PRETTY_FUNCTION__, __LINE__, cpx.value.real(), cpx.value.imag());
+ PyObject* result = PyComplex_FromDoubles(cpx.value.real(), cpx.value.imag());
+ fprintf(stderr, "[%s:%d]", __PRETTY_FUNCTION__, __LINE__);
+ PyObject_Print(result, stderr, 0);
+ fprintf(stderr, "\n");
+ return result;
+ */
+ return PyComplex_FromDoubles(cpx.value.real(), cpx.value.imag());
+ }
+ static Complex toCpp(PyObject* pyobj)
+ {
+ double real = PyComplex_RealAsDouble(pyobj);
+ double imag = PyComplex_ImagAsDouble(pyobj);
+ return Complex(real, imag);
+ }
+};
diff --git a/tests/samplebinding/complex_test.py b/tests/samplebinding/complex_test.py
new file mode 100755
index 000000000..92da61090
--- /dev/null
+++ b/tests/samplebinding/complex_test.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+
+'''Test cases for Complex class'''
+
+import sys
+import unittest
+
+import sample
+from sample import Point
+
+class ComplexTest(unittest.TestCase):
+ '''Test case for conversions between C++ Complex class to Python complex class'''
+
+ def testFunctionReturningComplexObject(self):
+ '''Test function returning a C++ Complex object.'''
+ cpx = sample.transmutePointIntoComplex(Point(5.0, 2.3))
+ self.assertEqual(cpx, complex(5.0, 2.3))
+
+ def testFunctionReceivingComplexObjectAsArgument(self):
+ '''Test function returning a C++ Complex object.'''
+ pt = sample.transmuteComplexIntoPoint(complex(1.2, 3.4))
+ # these assertions intentionally avoids to test the == operator,
+ # it should have its own test cases.
+ self.assertEqual(pt.x(), 1.2)
+ self.assertEqual(pt.y(), 3.4)
+
+ def testComplexList(self):
+ '''Test list of C++ Complex objects conversion to a list of Python complex objects.'''
+ # the global function gimmeComplexList() is expected to return a list
+ # containing the following Complex values: [0j, 1.1+2.2j, 1.3+2.4j]
+ cpxlist = sample.gimmeComplexList()
+ self.assertEqual(cpxlist, [complex(), complex(1.1, 2.2), complex(1.3, 2.4)])
+
+ def testSumComplexPair(self):
+ '''Test sum of a tuple containing two complex objects.'''
+ cpx1 = complex(1.2, 3.4)
+ cpx2 = complex(5.6, 7.8)
+ self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), cpx1 + cpx2)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/derived_test.py b/tests/samplebinding/derived_test.py
new file mode 100755
index 000000000..22d49470f
--- /dev/null
+++ b/tests/samplebinding/derived_test.py
@@ -0,0 +1,113 @@
+#!/usr/bin/python
+
+'''Test cases for Derived class'''
+
+import sys
+import unittest
+
+import sample
+from sample import Abstract, Derived, PolymorphicFuncEnum
+
+class Deviant(Derived):
+ def __init__(self):
+ Derived.__init__(self)
+ self.pure_virtual_called = False
+ self.unpure_virtual_called = False
+
+ def pureVirtual(self):
+ self.pure_virtual_called = True
+
+ def unpureVirtual(self):
+ self.unpure_virtual_called = True
+
+ def className(self):
+ return 'Deviant'
+
+class DerivedTest(unittest.TestCase):
+ '''Test case for Derived class'''
+
+ def testParentClassMethodsAvailability(self):
+ '''Test if Derived class really inherits its methods from parent.'''
+ inherited_methods = set(['callPureVirtual', 'callUnpureVirtual',
+ 'id_', 'pureVirtual', 'unpureVirtual'])
+ self.assert_(inherited_methods.issubset(dir(Derived)))
+
+ def testPolymorphicMethodCall(self):
+ '''Test if the correct polymorphic method is being called.'''
+ derived = Derived()
+
+ result = derived.polymorphic(1, 2)
+ self.assertEqual(type(result), PolymorphicFuncEnum)
+ self.assertEqual(result, sample.PolymorphicFunc_ii)
+
+ result = derived.polymorphic(3)
+ self.assertEqual(type(result), PolymorphicFuncEnum)
+ self.assertEqual(result, sample.PolymorphicFunc_ii)
+
+ result = derived.polymorphic(4.4)
+ self.assertEqual(type(result), PolymorphicFuncEnum)
+ self.assertEqual(result, sample.PolymorphicFunc_d)
+
+ def testOtherPolymorphicMethodCall(self):
+ '''Another test to check polymorphic method calling, just to double check.'''
+ derived = Derived()
+
+ result = derived.otherPolymorphic(1, 2, True, 3.3)
+ self.assertEqual(type(result), Derived.OtherPolymorphicFuncEnum)
+ self.assertEqual(result, sample.Derived.OtherPolymorphicFunc_iibd)
+
+ result = derived.otherPolymorphic(1, 2.2)
+ self.assertEqual(type(result), Derived.OtherPolymorphicFuncEnum)
+ self.assertEqual(result, Derived.OtherPolymorphicFunc_id)
+
+ def testPolymorphicMethodCallWithDifferentNumericTypes(self):
+ '''Test if the correct polymorphic method accepts a different numeric type as argument.'''
+ derived = Derived()
+ result = derived.polymorphic(1.1, 2.2)
+ self.assertEqual(type(result), PolymorphicFuncEnum)
+ self.assertEqual(result, sample.PolymorphicFunc_ii)
+
+ def testPolymorphicMethodCallWithWrongNumberOfArguments(self):
+ '''Test if a call to a polymorphic method with the wrong number of arguments raises an exception.'''
+ derived = Derived()
+ self.assertRaises(TypeError, lambda : derived.otherPolymorphic(1, 2, True))
+
+ def testReimplementedPureVirtualMethodCall(self):
+ '''Test if a Python override of a implemented pure virtual method is correctly called from C++.'''
+ d = Deviant()
+ d.callPureVirtual()
+ self.assert_(d.pure_virtual_called)
+
+ def testReimplementedVirtualMethodCall(self):
+ '''Test if a Python override of a reimplemented virtual method is correctly called from C++.'''
+ d = Deviant()
+ d.callUnpureVirtual()
+ self.assert_(d.unpure_virtual_called)
+
+ def testVirtualMethodCallString(self):
+ '''Test virtual method call returning string.'''
+ d = Derived()
+ self.assertEqual(d.className(), 'Derived')
+ self.assertEqual(d.getClassName(), 'Derived')
+
+ def testReimplementedVirtualMethodCallReturningString(self):
+ '''Test if a Python override of a reimplemented virtual method is correctly called from C++.'''
+ d = Deviant()
+ self.assertEqual(d.className(), 'Deviant')
+ self.assertEqual(d.getClassName(), 'Deviant')
+
+ def testSingleArgument(self):
+ '''Test singleArgument call.'''
+ d = Derived()
+ self.assert_(d.singleArgument(False))
+ self.assert_(not d.singleArgument(True))
+
+ def testMethodCallWithDefaultValue(self):
+ '''Test method call with default value.'''
+ d = Derived()
+ self.assertEqual(d.defaultValue(3), 3.1)
+ self.assertEqual(d.defaultValue(), 0.1)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/enum_test.py b/tests/samplebinding/enum_test.py
new file mode 100755
index 000000000..699adceda
--- /dev/null
+++ b/tests/samplebinding/enum_test.py
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+
+'''Test cases for Python representation of C++ enums'''
+
+import sys
+import unittest
+
+from sample import SampleNamespace
+
+class EnumTest(unittest.TestCase):
+ '''Test case for Abstract class'''
+
+ def testPassingIntegerOnEnumArgument(self):
+ '''Test if replacing an enum argument with an integer raises an exception.'''
+ self.assertRaises(TypeError, lambda : SampleNamespace.getNumber(1))
+
+ def testExtendingEnum(self):
+ '''Test if can create new items for an enum declared as extensible on the typesystem file.'''
+ name, value = 'NewItem', 13
+ enumitem = SampleNamespace.Option(name, value)
+ self.assert_(type(enumitem), SampleNamespace.Option)
+ self.assert_(enumitem.name, name)
+ self.assert_(int(enumitem), value)
+
+ def testExtendingNonExtensibleEnum(self):
+ '''Test if trying to create a new enum item for an unextensible enum raises an exception.'''
+ self.assertRaises(TypeError, lambda : SampleNamespace.InValue(13))
+
+ def testEnumConversionToAndFromPython(self):
+ '''Test conversion of enum objects to Python and C++ in both directions.'''
+ enumout = SampleNamespace.enumInEnumOut(SampleNamespace.TwoIn)
+ self.assert_(enumout, SampleNamespace.TwoOut)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h
new file mode 100644
index 000000000..b5ae6a8a0
--- /dev/null
+++ b/tests/samplebinding/global.h
@@ -0,0 +1,14 @@
+#include "abstract.h"
+#include "derived.h"
+#include "point.h"
+#include "size.h"
+#include "complex.h"
+#include "functions.h"
+#include "kindergarten.h"
+#include "pairuser.h"
+#include "listuser.h"
+#include "samplenamespace.h"
+#include "modifications.h"
+#include "implicitconv.h"
+#include "reference.h"
+
diff --git a/tests/samplebinding/implicitconv_test.py b/tests/samplebinding/implicitconv_test.py
new file mode 100755
index 000000000..30dd870e3
--- /dev/null
+++ b/tests/samplebinding/implicitconv_test.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+'''Test cases for implicit conversions'''
+
+import sys
+import unittest
+
+from sample import ImplicitConv
+
+class ImplicitConvTest(unittest.TestCase):
+ '''Test case for implicit conversions'''
+
+ def testImplicitConversions(self):
+ '''Test if polymorphic function call decisor takes implicit conversions into account.'''
+ ic = ImplicitConv.implicitConvCommon(ImplicitConv())
+ self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorNone)
+
+ ic = ImplicitConv.implicitConvCommon(3)
+ self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorOne)
+ self.assertEqual(ic.objId(), 3)
+
+ ic = ImplicitConv.implicitConvCommon(ImplicitConv.CtorThree)
+ self.assertEqual(ic.ctorEnum(), ImplicitConv.CtorThree)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/list_conversions.h b/tests/samplebinding/list_conversions.h
new file mode 100644
index 000000000..f512f98ad
--- /dev/null
+++ b/tests/samplebinding/list_conversions.h
@@ -0,0 +1,29 @@
+template <typename StdList>
+struct Converter_std_list
+{
+ static PyObject* toPython(ValueHolder<StdList> holder)
+ {
+ PyObject* result = PyList_New((int) holder.value.size());
+ typedef typename StdList::iterator IT;
+ IT it;
+ int idx = 0;
+ for (it = holder.value.begin(); it != holder.value.end(); it++) {
+ ValueHolder<typename StdList::value_type> vh(*it);
+ PyList_SET_ITEM(result, idx, Converter<typename StdList::value_type>::toPython(vh));
+ idx++;
+ }
+ return result;
+ }
+ static StdList toCpp(PyObject* pyobj)
+ {
+ StdList result;
+ for (int i = 0; i < PyTuple_GET_SIZE(pyobj); i++) {
+ PyObject* pyItem = PyTuple_GET_ITEM(pyobj, i);
+ result.push_back(Converter<typename StdList::value_type>::toCpp(pyItem));
+ }
+ return result;
+ }
+};
+
+template<typename T>
+struct Converter<std::list<T> > : Converter_std_list<std::list<T> > {};
diff --git a/tests/samplebinding/modifications_test.py b/tests/samplebinding/modifications_test.py
new file mode 100755
index 000000000..33d420f37
--- /dev/null
+++ b/tests/samplebinding/modifications_test.py
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+
+'''Test cases for method modifications performed as described on typesystem. '''
+
+import sys
+import unittest
+
+from sample import Modifications, Point
+
+class ExtModifications(Modifications):
+ def __init__(self):
+ Modifications.__init__(self)
+
+ def name(self):
+ return 'ExtModifications'
+
+
+class ModificationsTest(unittest.TestCase):
+ '''Test cases for method modifications performed as described on typesystem. '''
+
+ def setUp(self):
+ self.mods = Modifications()
+
+ def tearDown(self):
+ del self.mods
+
+ def testClassMembersAvailability(self):
+ '''Test if Modified class really have the expected members.'''
+ expected_members = set(['PolymorphicModFunc', 'PolymorphicNone',
+ 'Polymorphic_ibiP', 'Polymorphic_ibib',
+ 'Polymorphic_ibid', 'Polymorphic_ibii',
+ 'calculateArea', 'doublePlus', 'increment',
+ 'multiplyPointCoordsPlusValue', 'name',
+ 'pointToPair', 'polymorphic', 'power',
+ 'timesTen'])
+ self.assert_(expected_members.issubset(dir(Modifications)))
+
+ def testRenamedMethodAvailability(self):
+ '''Test if Modification class really have renamed the 'className' virtual method to 'name'.'''
+ self.assert_('className' not in dir(Modifications))
+ self.assert_('name' in dir(Modifications))
+
+ def testReimplementationOfRenamedVirtualMethod(self):
+ '''Test if class inheriting from Modification class have the reimplementation of renamed virtual method called.'''
+ em = ExtModifications()
+ self.assertEqual(self.mods.name(), 'Modifications')
+ self.assertEqual(em.name(), 'ExtModifications')
+
+ def testRegularMethodRenaming(self):
+ '''Test if Modifications::cppMultiply was correctly renamed to calculateArea.'''
+ self.assert_('cppMultiply' not in dir(Modifications))
+ self.assert_('calculateArea' in dir(Modifications))
+ self.assertEqual(self.mods.calculateArea(3, 6), 3 * 6)
+
+ def testRegularMethodRemoval(self):
+ '''Test if 'Modifications::exclusiveCppStuff' was removed from Python bindings.'''
+ self.assert_('exclusiveCppStuff' not in dir(Modifications))
+
+ def testArgumentRemoval(self):
+ '''Test if second argument of Modifications::doublePlus(int, int) was removed.'''
+ self.assertRaises(TypeError, lambda : self.mods.doublePlus(3, 7))
+ self.assertEqual(self.mods.doublePlus(7), 14)
+
+ def testDefaultValueRemoval(self):
+ '''Test if default value was removed from first argument of Modifications::increment(int).'''
+ self.assertRaises(TypeError, self.mods.increment)
+ self.assertEqual(self.mods.increment(7), 8)
+
+ def testDefaultValueReplacement(self):
+ '''Test if default values for both arguments of Modifications::power(int, int) were modified.'''
+ # original default values: int power(int base = 1, int exponent = 0);
+ self.assertNotEqual(self.mods.power(4), 1)
+ # modified default values: int power(int base = 2, int exponent = 1);
+ self.assertEqual(self.mods.power(), 2)
+ self.assertEqual(self.mods.power(3), 3)
+ self.assertEqual(self.mods.power(5, 3), 5**3)
+
+ def testSetNewDefaultValue(self):
+ '''Test if default value was correctly set to 10 for first argument of Modifications::timesTen(int).'''
+ self.assertEqual(self.mods.timesTen(7), 70)
+ self.assertEqual(self.mods.timesTen(), 100)
+
+ def testArgumentRemovalAndReturnTypeModificationWithTypesystemTemplates1(self):
+ '''Test modifications to method signature and return value using typesystem templates (case 1).'''
+ result, ok = self.mods.pointToPair(Point(2, 5))
+ self.assertEqual(type(ok), bool)
+ self.assertEqual(type(result), tuple)
+ self.assertEqual(len(result), 2)
+ self.assertEqual(type(result[0]), float)
+ self.assertEqual(type(result[1]), float)
+ self.assertEqual(result[0], 2.0)
+ self.assertEqual(result[1], 5.0)
+
+ def testArgumentRemovalAndReturnTypeModificationWithTypesystemTemplates2(self):
+ '''Test modifications to method signature and return value using typesystem templates (case 2).'''
+ result, ok = self.mods.multiplyPointCoordsPlusValue(Point(2, 5), 4.1)
+ self.assertEqual(type(ok), bool)
+ self.assertEqual(type(result), float)
+ self.assertEqual(result, 14.1)
+
+ def testPolymorphicMethodModifications(self):
+ '''Tests modifications to a polymorphic method'''
+ # polymorphic(int, bool[removed], int, double)
+ self.assertEqual(self.mods.polymorphic(1, 2, 3.1), Modifications.Polymorphic_ibid)
+ # polymorphic(int, bool, int[removed,default=321], int)
+ self.assertEqual(self.mods.polymorphic(1, True, 2), Modifications.Polymorphic_ibii)
+ # the others weren't modified
+ self.assertEqual(self.mods.polymorphic(1, True, 2, False), Modifications.Polymorphic_ibib)
+ self.assertEqual(self.mods.polymorphic(1, False, 2, Point(3, 4)), Modifications.Polymorphic_ibiP)
+ self.assertRaises(TypeError, lambda : self.mods.polymorphic(1, True, Point(2, 3), Point(4, 5)))
+ self.assertEqual(self.mods.poly(1, True, Point(2, 3), Point(4, 5)), Modifications.Polymorphic_ibPP)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/pair_conversions.h b/tests/samplebinding/pair_conversions.h
new file mode 100644
index 000000000..8adf2f6f3
--- /dev/null
+++ b/tests/samplebinding/pair_conversions.h
@@ -0,0 +1,25 @@
+template <typename StdPair>
+struct Converter_std_pair
+{
+ static PyObject* toPython(ValueHolder<StdPair> holder)
+ {
+ ValueHolder<typename StdPair::first_type> first(holder.value.first);
+ ValueHolder<typename StdPair::second_type> second(holder.value.second);
+ PyObject* tuple = PyTuple_New(2);
+ PyTuple_SET_ITEM(tuple, 0, Converter<typename StdPair::first_type>::toPython(first));
+ PyTuple_SET_ITEM(tuple, 1, Converter<typename StdPair::second_type>::toPython(second));
+ return tuple;
+ }
+ static StdPair toCpp(PyObject* pyobj)
+ {
+ StdPair result;
+ PyObject* pyFirst = PyTuple_GET_ITEM(pyobj, 0);
+ PyObject* pySecond = PyTuple_GET_ITEM(pyobj, 1);
+ result.first = Converter<typename StdPair::first_type>::toCpp(pyFirst);
+ result.second = Converter<typename StdPair::second_type>::toCpp(pySecond);
+ return result;
+ }
+};
+
+template<typename FT, typename ST>
+struct Converter<std::pair<FT, ST> > : Converter_std_pair<std::pair<FT, ST> > {};
diff --git a/tests/samplebinding/point_test.py b/tests/samplebinding/point_test.py
new file mode 100755
index 000000000..69ef1eefb
--- /dev/null
+++ b/tests/samplebinding/point_test.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+
+'''Test cases for Point class'''
+
+import sys
+import unittest
+
+from sample import Point
+
+class PointTest(unittest.TestCase):
+ '''Test case for Point class, including operator overloads.'''
+
+ def testConstructor(self):
+ '''Test Point class constructor.'''
+ pt = Point(5.0, 2.3)
+ self.assertEqual(pt.x(), 5.0)
+ self.assertEqual(pt.y(), 2.3)
+
+ def testPlusOperator(self):
+ '''Test Point class + operator.'''
+ pt1 = Point(5.0, 2.3)
+ pt2 = Point(0.5, 3.2)
+ self.assertEqual(pt1 + pt2, Point(5.0 + 0.5, 2.3 + 3.2))
+
+ def testEqualOperator(self):
+ '''Test Point class == operator.'''
+ pt1 = Point(5.0, 2.3)
+ pt2 = Point(5.0, 2.3)
+ pt3 = Point(0.5, 3.2)
+ self.assertTrue(pt1 == pt1)
+ self.assertTrue(pt1 == pt2)
+ self.assertFalse(pt1 == pt3)
+
+ def testNotEqualOperator(self):
+ '''Test Point class != operator.'''
+ pt1 = Point(5.0, 2.3)
+ pt2 = Point(5.0, 2.3)
+ self.assertRaises(NotImplementedError, lambda : pt1.__ne__(pt2))
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/reference_test.py b/tests/samplebinding/reference_test.py
new file mode 100755
index 000000000..ed4c5cbc8
--- /dev/null
+++ b/tests/samplebinding/reference_test.py
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+'''Test cases for methods that receive references to objects.'''
+
+import sys
+import unittest
+
+from sample import Reference
+
+class ReferenceTest(unittest.TestCase):
+ '''Test case for methods that receive references to objects.'''
+
+ def testMethodThatReceivesReference(self):
+ '''Test a method that receives a reference to an object as argument.'''
+ objId = 123
+ r = Reference(objId)
+ self.assertEqual(Reference.usesReference(r), objId)
+
+ def testMethodThatReceivesConstReference(self):
+ '''Test a method that receives a const reference to an object as argument.'''
+ objId = 123
+ r = Reference(objId)
+ self.assertEqual(Reference.usesConstReference(r), objId)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/sample_test.py b/tests/samplebinding/sample_test.py
new file mode 100755
index 000000000..9de201a24
--- /dev/null
+++ b/tests/samplebinding/sample_test.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+'''Test cases for libsample bindings module'''
+
+import sys
+import unittest
+
+import sample
+
+class ModuleTest(unittest.TestCase):
+ '''Test case for module and global functions'''
+
+ def testModuleMembers(self):
+ '''Test availability of classes, global functions and other members on binding'''
+ expected_members = set(['Abstract', 'Derived', 'ListUser', 'PairUser',
+ 'Point', 'gimmeComplexList', 'gimmeDouble',
+ 'gimmeInt', 'makeCString', 'multiplyPair',
+ 'returnCString', 'transmuteComplexIntoPoint',
+ 'transmutePointIntoComplex', 'sumComplexPair',
+ 'SampleNamespace', 'GlobalEnum', 'NoThing',
+ 'FirstThing', 'SecondThing', 'ThirdThing'])
+ self.assert_(expected_members.issubset(dir(sample)))
+
+ def testAbstractPrintFormatEnum(self):
+ '''Test availability of PrintFormat enum from Abstract class'''
+ enum_members = set(['PrintFormat', 'Short', 'Verbose',
+ 'OnlyId', 'ClassNameAndId'])
+ self.assert_(enum_members.issubset(dir(sample.Abstract)))
+
+ def testSampleNamespaceOptionEnum(self):
+ '''Test availability of Option enum from SampleNamespace namespace'''
+ enum_members = set(['Option', 'None', 'RandomNumber', 'UnixTime'])
+ self.assert_(enum_members.issubset(dir(sample.SampleNamespace)))
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/size_test.py b/tests/samplebinding/size_test.py
new file mode 100755
index 000000000..dcfc9d9d3
--- /dev/null
+++ b/tests/samplebinding/size_test.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python
+
+'''Test cases for operator overloads on Size class'''
+
+import sys
+import unittest
+
+from sample import Size
+
+class PointTest(unittest.TestCase):
+ '''Test case for Size class, including operator overloads.'''
+
+ def testConstructor(self):
+ '''Test Size class constructor.'''
+ width, height = (5.0, 2.3)
+ size = Size(width, height)
+ self.assertEqual(size.width(), width)
+ self.assertEqual(size.height(), height)
+ self.assertEqual(size.calculateArea(), width * height)
+
+ def testPlusOperator(self):
+ '''Test Size class + operator.'''
+ s1 = Size(5.0, 2.3)
+ s2 = Size(0.5, 3.2)
+ self.assertEqual(s1 + s2, Size(5.0 + 0.5, 2.3 + 3.2))
+
+ def testEqualOperator(self):
+ '''Test Size class == operator.'''
+ s1 = Size(5.0, 2.3)
+ s2 = Size(5.0, 2.3)
+ s3 = Size(0.5, 3.2)
+ self.assertTrue(s1 == s1)
+ self.assertTrue(s1 == s2)
+ self.assertFalse(s1 == s3)
+
+ def testNotEqualOperator(self):
+ '''Test Size class != operator.'''
+ s1 = Size(5.0, 2.3)
+ s2 = Size(5.0, 2.3)
+ s3 = Size(0.5, 3.2)
+ self.assertFalse(s1 != s1)
+ self.assertFalse(s1 != s2)
+ self.assertTrue(s1 != s3)
+
+ def testMinorEqualOperator(self):
+ '''Test Size class <= operator.'''
+ s1 = Size(5.0, 2.3)
+ s2 = Size(5.0, 2.3)
+ s3 = Size(0.5, 3.2)
+ self.assertTrue(s1 <= s1)
+ self.assertTrue(s1 <= s2)
+ self.assertTrue(s3 <= s1)
+ self.assertFalse(s1 <= s3)
+
+ def testMinorOperator(self):
+ '''Test Size class < operator.'''
+ s1 = Size(5.0, 2.3)
+ s2 = Size(0.5, 3.2)
+ self.assertFalse(s1 < s1)
+ self.assertFalse(s1 < s2)
+ self.assertTrue(s2 < s1)
+
+ def testMajorEqualOperator(self):
+ '''Test Size class >= operator.'''
+ s1 = Size(5.0, 2.3)
+ s2 = Size(5.0, 2.3)
+ s3 = Size(0.5, 3.2)
+ self.assertTrue(s1 >= s1)
+ self.assertTrue(s1 >= s2)
+ self.assertTrue(s1 >= s3)
+ self.assertFalse(s3 >= s1)
+
+ def testMajorOperator(self):
+ '''Test Size class > operator.'''
+ s1 = Size(5.0, 2.3)
+ s2 = Size(0.5, 3.2)
+ self.assertFalse(s1 > s1)
+ self.assertTrue(s1 > s2)
+ self.assertFalse(s2 > s1)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
new file mode 100644
index 000000000..c049ea9eb
--- /dev/null
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -0,0 +1,216 @@
+<?xml version="1.0"?>
+<typesystem package="sample">
+ <primitive-type name="bool"/>
+ <primitive-type name="double"/>
+ <primitive-type name="int"/>
+ <primitive-type name="char"/>
+
+ <primitive-type name="Complex" target-lang-api-name="PyComplex">
+ <conversion-rule file="complex_conversions.h"/>
+ </primitive-type>
+
+ <container-type name="std::pair" type="pair">
+ <conversion-rule file="pair_conversions.h"/>
+ <include file-name="utility" location="global"/>
+ </container-type>
+ <container-type name="std::list" type="list">
+ <conversion-rule file="list_conversions.h"/>
+ <include file-name="list" location="global"/>
+ </container-type>
+
+ <enum-type name="Abstract::PrintFormat"/>
+ <enum-type name="PolymorphicFuncEnum"/>
+ <enum-type name="Derived::OtherPolymorphicFuncEnum"/>
+ <enum-type name="Modifications::PolymorphicModFunc"/>
+ <enum-type name="ImplicitConv::CtorEnum"/>
+ <!-- BUG:
+ renaming the ICPolymorphicFuncEnum to the same name
+ of a global enum causes the generator to confuse the
+ two types.
+ -->
+ <enum-type name="ImplicitConv::ICPolymorphicFuncEnum"/>
+ <enum-type name="SampleNamespace::Option" extensible="yes"/>
+ <enum-type name="SampleNamespace::InValue"/>
+ <enum-type name="SampleNamespace::OutValue"/>
+ <enum-type name="GlobalEnum"/>
+ <enum-type name="GlobalPolyFuncEnum"/>
+
+ <namespace-type name="SampleNamespace"/>
+
+ <object-type name="Abstract">
+ <modify-function signature="id()" rename="id_"/>
+ </object-type>
+
+ <object-type name="Derived"/>
+
+ <template name="boolptr_at_end_fix_beginning">
+ bool __ok__;
+ %0 = ((%TYPE*) ((Shiboken::PyBaseWrapper*) self)->cptr)->
+ %TYPE::%FUNCTION_NAME(%ARGUMENT_NAMES, &amp;__ok__);
+ </template>
+
+ <template name="boolptr_at_start_fix_beginning">
+ bool __ok__;
+ %0 = ((%TYPE*) ((Shiboken::PyBaseWrapper*) self)->cptr)->
+ %TYPE::%FUNCTION_NAME(&amp;__ok__, %ARGUMENT_NAMES);
+ </template>
+
+ <template name="boolptr_fix_end">
+ PyObject* _item_;
+ PyObject* _tuple_ = PyTuple_New(2);
+ _item_ = Shiboken::Converter&lt; %RETURN_TYPE &gt;::toPython(Shiboken::ValueHolder&lt; %RETURN_TYPE &gt;(%0));
+ PyTuple_SET_ITEM(_tuple_, 0, _item_);
+ _item_ = Shiboken::Converter&lt;bool&gt;::toPython(Shiboken::ValueHolder&lt;bool&gt;(__ok__));
+ PyTuple_SET_ITEM(_tuple_, 1, _item_);
+ return _tuple_;
+ </template>
+
+ <object-type name="Modifications">
+
+ <modify-function signature="polymorphic(int, bool, int, double)">
+ <modify-argument index="2">
+ <remove-argument/>
+ </modify-argument>
+ <inject-code class="native" position="beginning">
+ %0 = ((%TYPE*) ((Shiboken::PyBaseWrapper*) self)->cptr)->
+ %TYPE::%FUNCTION_NAME(%1, true, %3, %4);
+ </inject-code>
+ </modify-function>
+
+ <modify-function signature="polymorphic(int, bool, int, int)">
+ <modify-argument index="3">
+ <remove-argument/>
+ <replace-default-expression with="321"/>
+ </modify-argument>
+ <!--
+ <modify-argument index="4">
+ <remove-default-expression/>
+ </modify-argument>
+ -->
+ </modify-function>
+
+ <!--
+ this alteration will trigger an interesting
+ compile time error on the binding
+ -->
+ <!--
+ <modify-function signature="polymorphic(int, bool, Point, Point)">
+ <modify-argument index="3">
+ <remove-argument/>
+ </modify-argument>
+ </modify-function>
+ -->
+
+ <!--
+ renaming this signature should remove it from the other
+ polymorphic methods decision tree
+ -->
+ <modify-function signature="polymorphic(int, bool, Point, Point)" rename="poly"/>
+
+ <!--
+ 'ok' must be removed and the return value will be changed
+ to a tuple (PyObject*) containing the expected result plus
+ the 'ok' value as a Python boolean
+ -->
+ <modify-function signature="pointToPair(Point, bool*)">
+ <modify-argument index="2">
+ <remove-argument/>
+ </modify-argument>
+ <modify-argument index="return">
+ <replace-type modified-type="PyObject*"/>
+ </modify-argument>
+ <inject-code class="native" position="beginning">
+ <insert-template name="boolptr_at_end_fix_beginning"/>
+ </inject-code>
+ <inject-code class="native" position="end">
+ <insert-template name="boolptr_fix_end"/>
+ </inject-code>
+ </modify-function>
+
+ <!-- same as 'pointToPair' except that this time 'ok' is the first argument -->
+ <modify-function signature="multiplyPointCoordsPlusValue(bool*, Point, double)">
+ <modify-argument index="1">
+ <remove-argument/>
+ </modify-argument>
+ <modify-argument index="return">
+ <replace-type modified-type="PyObject*"/>
+ </modify-argument>
+ <inject-code class="native" position="beginning">
+ <insert-template name="boolptr_at_start_fix_beginning"/>
+ </inject-code>
+ <inject-code class="native" position="end">
+ <insert-template name="boolptr_fix_end"/>
+ </inject-code>
+ </modify-function>
+
+ <!-- completely remove 'plus' from the Python side -->
+ <modify-function signature="doublePlus(int, int)">
+ <modify-argument index="2">
+ <remove-argument/>
+ </modify-argument>
+ </modify-function>
+
+ <!-- the default value for both arguments must be changed in Python -->
+ <modify-function signature="power(int, int)">
+ <modify-argument index="1">
+ <replace-default-expression with="2"/>
+ </modify-argument>
+ <modify-argument index="2">
+ <replace-default-expression with="1"/>
+ </modify-argument>
+ </modify-function>
+
+ <!-- in Python set argument default value to 10 -->
+ <modify-function signature="timesTen(int)">
+ <modify-argument index="1">
+ <replace-default-expression with="10"/>
+ </modify-argument>
+ </modify-function>
+
+ <!-- in Python remove the argument default value -->
+ <modify-function signature="increment(int)">
+ <modify-argument index="1">
+ <remove-default-expression/>
+ </modify-argument>
+ </modify-function>
+
+ <!-- don't export this method to Python -->
+ <modify-function signature="exclusiveCppStuff()" remove="all"/>
+
+ <!-- change the name of this regular method -->
+ <modify-function signature="cppMultiply(int, int)" rename="calculateArea"/>
+
+ <!-- change the name of this virtual method -->
+ <modify-function signature="className()" rename="name"/>
+ </object-type>
+
+ <object-type name="AbstractModifications">
+ <!--
+ completely removing the pure virtual method from this
+ class will generate an #error directive.
+ -->
+ <!--
+ <modify-function signature="pointlessPureVirtualMethod()" remove="all"/>
+ -->
+ </object-type>
+
+ <value-type name="Reference"/>
+
+ <value-type name="ImplicitConv"/>
+
+ <value-type name="Point"/>
+ <value-type name="Size"/>
+ <value-type name="PairUser"/>
+ <value-type name="ListUser"/>
+
+ <rejection class="ListUser" function-name="createList()"/>
+ <rejection class="ListUser" function-name="callCreateList()"/>
+ <rejection class="ListUser" function-name="createComplexList(Complex, Complex)"/>
+ <rejection class="ListUser" function-name="sumList(std::list&lt;int&gt;)"/>
+ <rejection class="ListUser" function-name="sumList(std::list&lt;double&gt;)"/>
+
+ <rejection class="" function-name="gimmeComplexList()"/>
+ <rejection class="" function-name="makeCString()"/>
+ <rejection class="" function-name="returnCString()"/>
+</typesystem>
+