summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-08-17 17:36:11 -0300
committerHugo Lima <hugo.lima@openbossa.org>2009-08-17 17:36:11 -0300
commitcbac30b07bae6c72be5eefd5e47fe83650a16acd (patch)
tree5fa8211c6f880c6777188934bd994d1f4359fe5c /tests
downloadgeneratorrunner-cbac30b07bae6c72be5eefd5e47fe83650a16acd.tar.gz
generatorrunner-cbac30b07bae6c72be5eefd5e47fe83650a16acd.tar.xz
generatorrunner-cbac30b07bae6c72be5eefd5e47fe83650a16acd.zip
The genesis...
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt9
-rw-r--r--tests/Makefile12
-rw-r--r--tests/foo_test.py105
-rw-r--r--tests/foobinding/Makefile13
-rw-r--r--tests/foobinding/foo/Makefile21
-rw-r--r--tests/foobinding/global.h2
-rw-r--r--tests/foobinding/typesystem_foo.xml6
-rw-r--r--tests/libfoo/Makefile15
-rw-r--r--tests/libfoo/bar.cpp15
-rw-r--r--tests/libfoo/bar.h15
-rw-r--r--tests/libfoo/foo.cpp17
-rw-r--r--tests/libfoo/foo.h14
-rw-r--r--tests/libfoo/main.cpp15
-rw-r--r--tests/sphinxtabletest.cpp269
-rw-r--r--tests/sphinxtabletest.h48
15 files changed, 576 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..9099adf
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,9 @@
+project(sphinxtabletest)
+
+# TODO
+set(sphinxtabletest_SRC sphinxtabletest.cpp)
+qt4_automoc(${sphinxtabletest_SRC})
+include_directories(${QT_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${boostpythongenerator_SOURCE_DIR})
+add_executable(sphinxtabletest ${sphinxtabletest_SRC})
+target_link_libraries(sphinxtabletest ${QT_QTTEST_LIBRARY} ${APIEXTRACTOR_LIBRARY} libboostpythongenerator)
+add_test("sphinxtable" sphinxtabletest)
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..054d6f5
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,12 @@
+all:
+ (cd libfoo; $(MAKE))
+ (cd foobinding; $(MAKE))
+
+
+test:
+ LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(PWD)/libfoo PYTHONPATH=$(PYTHONPATH):$(PWD)/foobinding/foo python foo_test.py
+
+clean:
+ (cd libfoo; $(MAKE) clean)
+ (cd foobinding; $(MAKE) clean)
+
diff --git a/tests/foo_test.py b/tests/foo_test.py
new file mode 100644
index 0000000..45b7e80
--- /dev/null
+++ b/tests/foo_test.py
@@ -0,0 +1,105 @@
+
+'''Test cases for virtual methods called through generated bindings'''
+
+import unittest
+try:
+ from foo import Foo, Bar
+except:
+ import sys
+ print 'You need to set correct paths for libfoo and foo bindings'
+ import os
+ sys.exit(1)
+
+
+class DerivedFoo(Foo):
+
+ def __init__(self):
+ Foo.__init__(self)
+
+ def pureVirtual(self):
+ print 'DerivedFoo.pureVirtual'
+
+
+class VirtualMethods(unittest.TestCase):
+ '''Test case for virtual methods'''
+
+ def setUp(self):
+ self.foo = Foo()
+ self.bar = Bar()
+ self.derivedfoo = DerivedFoo()
+
+ def tearDown(self):
+ self.foo = None
+ self.bar = None
+ self.derivedfoo = None
+
+ def testDerivedClassVirtualMethod(self):
+ '''Test reinplemented virtual methods from derived class'''
+ called = True
+ try:
+ self.bar.unpureVirtual()
+ self.bar.pureVirtual()
+ except:
+ called = False
+ self.assertTrue(called)
+
+ def testBaseClassVirtualMethod(self):
+ '''Test virtual method from base class'''
+ called = True
+ try:
+ self.foo.unpureVirtual()
+ except:
+ called = False
+ self.assertTrue(called)
+
+
+ def testBaseClassPureVirtualMethod(self):
+ '''Test pure virtual method from base class'''
+ called = False
+ try:
+ self.foo.pureVirtual()
+ except:
+ called = False
+ self.assertFalse(called)
+
+ def testBaseClassIndirectCallToUnpureVirtualMethod(self):
+ '''Test call to unpure virtual method from C++ to Python'''
+ called = True
+ try:
+ self.foo.unpureVirtual()
+ except:
+ called = False
+ self.assertTrue(called)
+
+ def testDerivedClassIndirectCallToUnpureVirtualMethod(self):
+ '''Test call to unpure virtual method from C++ to Python'''
+ called = True
+ try:
+ self.bar.unpureVirtual()
+ except:
+ called = False
+ self.assertTrue(called)
+
+ def testCppDerivedClassIndirectCallToPureVirtualMethod(self):
+ '''Test call to pure virtual method from C++ to Python'''
+ called = False
+ try:
+ self.bar.callPureVirtual()
+ except:
+ called = False
+ self.assertFalse(called)
+
+
+ def testDerivedClassIndirectCallToPureVirtualMethod(self):
+ '''Test call to pure virtual method from C++ to Python'''
+ called = False
+ try:
+ self.derivedfoo.callPureVirtual()
+ except:
+ called = False
+ self.assertFalse(called)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/foobinding/Makefile b/tests/foobinding/Makefile
new file mode 100644
index 0000000..30909ae
--- /dev/null
+++ b/tests/foobinding/Makefile
@@ -0,0 +1,13 @@
+all: generate
+ (cd foo; $(MAKE))
+
+generate:
+ boostpythongenerator --disable-named-arg global.h \
+ --include-paths=`pwd`/../libfoo \
+ --typesystem-paths=. --output-directory=. \
+ typesystem_foo.xml
+
+clean:
+ rm *.log .preprocessed.tmp foo/*.hpp foo/*.cpp -rf
+ (cd foo; $(MAKE) clean)
+
diff --git a/tests/foobinding/foo/Makefile b/tests/foobinding/foo/Makefile
new file mode 100644
index 0000000..4f6896f
--- /dev/null
+++ b/tests/foobinding/foo/Makefile
@@ -0,0 +1,21 @@
+CXX_FLAGS=-DBOOST_PYTHON_NO_PY_SIGNATURES -g -fPIC -I/usr/include/python2.5 -I../../libfoo `pkg-config pyside --cflags`
+CXX_LDFLAGS=-DBOOST_PYTHON_NO_PY_SIGNATURES -fPIC -shared -L../../libfoo -lfoo `pkg-config pyside --libs`
+
+all: foo_wrapper.o bar_wrapper.o foo_globals_wrapper.o foo_module_wrapper.o
+ g++ $(CXX_LDFLAGS) bar_wrapper.o foo_wrapper.o foo_globals_wrapper.o foo_module_wrapper.o -Wl,-soname,foo.so -o foo.so
+
+foo_wrapper.o: foo_wrapper.cpp foo_wrapper.hpp
+ g++ $(CXX_FLAGS) foo_wrapper.cpp -c
+
+bar_wrapper.o: bar_wrapper.cpp bar_wrapper.hpp
+ g++ $(CXX_FLAGS) bar_wrapper.cpp -c
+
+foo_globals_wrapper.o: foo_globals_wrapper.cpp
+ g++ $(CXX_FLAGS) foo_globals_wrapper.cpp -c
+
+foo_module_wrapper.o: foo_module_wrapper.cpp
+ g++ $(CXX_FLAGS) foo_module_wrapper.cpp -c
+
+clean:
+ rm *.o *.so -rf
+
diff --git a/tests/foobinding/global.h b/tests/foobinding/global.h
new file mode 100644
index 0000000..a23601a
--- /dev/null
+++ b/tests/foobinding/global.h
@@ -0,0 +1,2 @@
+#include "foo.h"
+#include "bar.h"
diff --git a/tests/foobinding/typesystem_foo.xml b/tests/foobinding/typesystem_foo.xml
new file mode 100644
index 0000000..e4289e4
--- /dev/null
+++ b/tests/foobinding/typesystem_foo.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<typesystem package="foo">
+ <object-type name="Foo"/>
+ <object-type name="Bar"/>
+</typesystem>
+
diff --git a/tests/libfoo/Makefile b/tests/libfoo/Makefile
new file mode 100644
index 0000000..eaf8f62
--- /dev/null
+++ b/tests/libfoo/Makefile
@@ -0,0 +1,15 @@
+all: foo.o bar.o
+ g++ -fPIC -shared foo.o bar.o -o libfoo.so
+
+foo.o: foo.h foo.cpp
+ g++ -fPIC foo.cpp -c
+
+bar.o: bar.h bar.cpp
+ g++ -fPIC bar.cpp -c
+
+test: main.cpp
+ g++ main.cpp -L. -lfoo -I. -o footest
+
+clean:
+ rm *.o *.so footest -rf
+
diff --git a/tests/libfoo/bar.cpp b/tests/libfoo/bar.cpp
new file mode 100644
index 0000000..a8f9712
--- /dev/null
+++ b/tests/libfoo/bar.cpp
@@ -0,0 +1,15 @@
+#include <iostream>
+#include "bar.h"
+
+using namespace std;
+
+void Bar::pureVirtual()
+{
+ cout << "Bar::pureVirtual()" << endl;
+}
+
+void Bar::unpureVirtual()
+{
+ cout << "Bar::unpureVirtual()" << endl;
+}
+
diff --git a/tests/libfoo/bar.h b/tests/libfoo/bar.h
new file mode 100644
index 0000000..4a73c2d
--- /dev/null
+++ b/tests/libfoo/bar.h
@@ -0,0 +1,15 @@
+#ifndef BAR_H
+#define BAR_H
+
+#include "foo.h"
+
+class Bar : public Foo
+{
+public:
+ Bar() {}
+ virtual ~Bar() {}
+ virtual void pureVirtual();
+ virtual void unpureVirtual();
+};
+#endif // BAR_H
+
diff --git a/tests/libfoo/foo.cpp b/tests/libfoo/foo.cpp
new file mode 100644
index 0000000..22be350
--- /dev/null
+++ b/tests/libfoo/foo.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+#include "foo.h"
+
+using namespace std;
+
+void Foo::unpureVirtual()
+{
+ cout << "Foo::unpureVirtual()" << endl;
+}
+
+void Foo::callPureVirtual()
+{
+ cout << "Foo::callPureVirtual() -- calling pureVirtual..." << endl;
+ this->pureVirtual();
+ cout << " -- pureVirtual called." << endl;
+}
+
diff --git a/tests/libfoo/foo.h b/tests/libfoo/foo.h
new file mode 100644
index 0000000..585b844
--- /dev/null
+++ b/tests/libfoo/foo.h
@@ -0,0 +1,14 @@
+#ifndef FOO_H
+#define FOO_H
+
+class Foo
+{
+public:
+ Foo() {}
+ virtual ~Foo() {}
+ virtual void pureVirtual() = 0;
+ virtual void unpureVirtual();
+ virtual void callPureVirtual();
+};
+#endif // FOO_H
+
diff --git a/tests/libfoo/main.cpp b/tests/libfoo/main.cpp
new file mode 100644
index 0000000..6f410ad
--- /dev/null
+++ b/tests/libfoo/main.cpp
@@ -0,0 +1,15 @@
+#include "foo.h"
+#include "bar.h"
+
+int
+main(int argv, char **argc)
+{
+ Bar bar;
+
+ bar.unpureVirtual();
+ bar.pureVirtual();
+ bar.callPureVirtual();
+
+ return 0;
+}
+
diff --git a/tests/sphinxtabletest.cpp b/tests/sphinxtabletest.cpp
new file mode 100644
index 0000000..058a3b5
--- /dev/null
+++ b/tests/sphinxtabletest.cpp
@@ -0,0 +1,269 @@
+/*
+* This file is part of the Boost Python Generator project.
+*
+* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#include "sphinxtabletest.h"
+#include "docgenerator.h"
+#include <QtTest/QTest>
+#include <QDebug>
+
+QString SphinxTableTest::transformXml(const char* xml)
+{
+ return QtXmlToSphinx(m_generator, xml).result();
+}
+
+void SphinxTableTest::setUp()
+{
+ m_generator = new DocGenerator;
+}
+
+void SphinxTableTest::tearDown()
+{
+ delete m_generator;
+}
+
+void SphinxTableTest::testEmptyString()
+{
+ const char* xml = "";
+ QCOMPARE(transformXml(xml), QString());
+}
+
+void SphinxTableTest::testSimpleTable()
+{
+ const char* xml = "\
+<table>\
+ <header>\
+ <item>\
+ <para>Header 1</para>\
+ </item>\
+ <item>\
+ <para>Header 2</para>\
+ </item>\
+ </header>\
+ <row>\
+ <item>\
+ <para>1 1</para>\
+ </item>\
+ <item>\
+ <para>1 2</para>\
+ </item>\
+ </row>\
+ <row>\
+ <item>\
+ <para>2 1</para>\
+ </item>\
+ <item>\
+ <para>2 2</para>\
+ </item>\
+ </row>\
+</table>";
+ QCOMPARE(transformXml(xml), QString("\
+ +--------+--------+\n\
+ |Header 1|Header 2|\n\
+ +--------+--------+\n\
+ |1 1 |1 2 |\n\
+ +--------+--------+\n\
+ |2 1 |2 2 |\n\
+ +--------+--------+\n\
+\n"));
+}
+
+void SphinxTableTest::testColSpan()
+{
+ const char* xml = "\
+<table>\
+ <header>\
+ <item>\
+ <para>Header 1</para>\
+ </item>\
+ <item>\
+ <para>Header 2</para>\
+ </item>\
+ </header>\
+ <row>\
+ <item colspan=\"2\">\
+ <para>I'm a big text!</para>\
+ </item>\
+ </row>\
+ <row>\
+ <item>\
+ <para>2 1</para>\
+ </item>\
+ <item>\
+ <para>2 2</para>\
+ </item>\
+ </row>\
+</table>";
+ QCOMPARE(transformXml(xml), QString("\
+ +---------------+--------+\n\
+ |Header 1 |Header 2|\n\
+ +---------------+--------+\n\
+ |I'm a big text! |\n\
+ +---------------+--------+\n\
+ |2 1 |2 2 |\n\
+ +---------------+--------+\n\
+\n"));
+}
+
+
+void SphinxTableTest::testRowSpan()
+{
+ const char* xml = "\
+<table>\
+ <header>\
+ <item>\
+ <para>Header 1</para>\
+ </item>\
+ <item>\
+ <para>Header 2</para>\
+ </item>\
+ </header>\
+ <row>\
+ <item rowspan=\"2\">\
+ <para>1.1</para>\
+ </item>\
+ <item>\
+ <para>1.2</para>\
+ </item>\
+ </row>\
+ <row>\
+ <item>\
+ <para>2 2</para>\
+ </item>\
+ </row>\
+</table>";
+ QCOMPARE(transformXml(xml), QString("\
+ +--------+--------+\n\
+ |Header 1|Header 2|\n\
+ +--------+--------+\n\
+ |1.1 |1.2 |\n\
+ + +--------+\n\
+ | |2 2 |\n\
+ +--------+--------+\n\
+\n"));
+}
+
+
+void SphinxTableTest::testComplexTable()
+{
+ const char* xml = "\
+<table>\
+ <header>\
+ <item>\
+ <para>Header 1</para>\
+ </item>\
+ <item>\
+ <para>Header 2</para>\
+ </item>\
+ <item>\
+ <para>Header 3</para>\
+ </item>\
+ </header>\
+ <row>\
+ <item rowspan=\"2\">\
+ <para>1.1</para>\
+ </item>\
+ <item colspan=\"2\">\
+ <para>1.2</para>\
+ </item>\
+ </row>\
+ <row>\
+ <item>\
+ <para>2 2</para>\
+ </item>\
+ <item>\
+ <para>2 3</para>\
+ </item>\
+ </row>\
+</table>";
+ QCOMPARE(transformXml(xml), QString("\
+ +--------+--------+--------+\n\
+ |Header 1|Header 2|Header 3|\n\
+ +--------+--------+--------+\n\
+ |1.1 |1.2 |\n\
+ + +--------+--------+\n\
+ | |2 2 |2 3 |\n\
+ +--------+--------+--------+\n\
+\n"));
+}
+
+void SphinxTableTest::testRowSpan2()
+{
+ const char* xml = "\
+<table>\
+ <header>\
+ <item><para>h1</para></item>\
+ <item><para>h2</para></item>\
+ <item><para>h3</para></item>\
+ <item><para>h4</para></item>\
+ </header>\
+ <row>\
+ <item rowspan=\"6\"><para>A</para></item>\
+ <item rowspan=\"6\"><para>B</para></item>\
+ <item><para>C</para></item>\
+ <item><para>D</para></item>\
+ </row>\
+ <row>\
+ <item><para>E</para></item>\
+ <item><para>F</para></item>\
+ </row>\
+ <row>\
+ <item><para>E</para></item>\
+ <item><para>F</para></item>\
+ </row>\
+ <row>\
+ <item><para>E</para></item>\
+ <item><para>F</para></item>\
+ </row>\
+ <row>\
+ <item><para>E</para></item>\
+ <item><para>F</para></item>\
+ </row>\
+ <row>\
+ <item><para>E</para></item>\
+ <item><para>F</para></item>\
+ </row>\
+</table>";
+ QCOMPARE(transformXml(xml), QString("\
+ +--+--+--+--+\n\
+ |h1|h2|h3|h4|\n\
+ +--+--+--+--+\n\
+ |A |B |C |D |\n\
+ + + +--+--+\n\
+ | | |E |F |\n\
+ + + +--+--+\n\
+ | | |E |F |\n\
+ + + +--+--+\n\
+ | | |E |F |\n\
+ + + +--+--+\n\
+ | | |E |F |\n\
+ + + +--+--+\n\
+ | | |E |F |\n\
+ +--+--+--+--+\n\
+\n"));
+}
+
+
+
+QTEST_APPLESS_MAIN( SphinxTableTest )
+
+#include "sphinxtabletest.moc"
diff --git a/tests/sphinxtabletest.h b/tests/sphinxtabletest.h
new file mode 100644
index 0000000..163cc53
--- /dev/null
+++ b/tests/sphinxtabletest.h
@@ -0,0 +1,48 @@
+/*
+* This file is part of the Boost Python Generator project.
+*
+* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#ifndef SPHINXTABLETEST_H
+#define SPHINXTABLETEST_H
+
+#include <QObject>
+
+class DocGenerator;
+class SphinxTableTest : public QObject {
+ Q_OBJECT
+
+private slots:
+ void setUp();
+ void tearDown();
+ void testEmptyString();
+ void testSimpleTable();
+ void testRowSpan();
+ void testColSpan();
+ void testComplexTable();
+ void testRowSpan2();
+private:
+ DocGenerator* m_generator;
+
+ QString transformXml(const char* xml);
+};
+
+#endif