aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-08-17 17:32:08 -0300
committerHugo Lima <hugo.lima@openbossa.org>2009-08-17 17:32:08 -0300
commit9732e0c744e45a67094fc6ce08bdadb1f9a08d4a (patch)
tree566e389f406515b040317bffa075f4e5021020f7 /tests
The genesis...
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt6
-rw-r--r--tests/testabstractmetaclass.cpp86
-rw-r--r--tests/testabstractmetaclass.h47
3 files changed, 139 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 000000000..8517a28a9
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,6 @@
+
+qt4_automoc(testabstractmetaclass.cpp)
+add_executable(testabstractmetaclass testabstractmetaclass.cpp)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${apiextractor_SOURCE_DIR})
+target_link_libraries(testabstractmetaclass ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} apiextractor)
+add_test("AbstractMetaClass" testabstractmetaclass)
diff --git a/tests/testabstractmetaclass.cpp b/tests/testabstractmetaclass.cpp
new file mode 100644
index 000000000..d7eb77ca2
--- /dev/null
+++ b/tests/testabstractmetaclass.cpp
@@ -0,0 +1,86 @@
+/*
+* This file is part of the API Extractor 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 "testabstractmetaclass.h"
+#include "abstractmetabuilder.h"
+#include <QtTest/QTest>
+#include <QBuffer>
+
+
+TestAbstractMetaClass::TestAbstractMetaClass() : m_builder(0)
+{
+}
+
+void TestAbstractMetaClass::init()
+{
+ m_builder = new AbstractMetaBuilder;
+}
+
+void TestAbstractMetaClass::cleanup()
+{
+ delete m_builder;
+ m_builder = 0;
+}
+
+void TestAbstractMetaClass::processCode (const char* cppCode, const char* xmlCode )
+{
+ QBuffer buffer;
+ // parse typesystem
+ buffer.setData(xmlCode);
+ TypeDatabase::instance()->parseFile(&buffer);
+ buffer.close();
+ // parse C++ code
+ buffer.setData(cppCode);
+ m_builder->build(&buffer);
+}
+
+void TestAbstractMetaClass::testClassName()
+{
+ const char* cppCode ="class ClassName {};";
+ const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"ClassName\"/></typesystem>";
+ processCode(cppCode, xmlCode);
+ AbstractMetaClassList classes = m_builder->classes();
+ QCOMPARE(classes.count(), 1);
+ QCOMPARE(classes[0]->name(), QString("ClassName"));
+}
+
+void TestAbstractMetaClass::testClassNameUnderNamespace()
+{
+ const char* cppCode ="namespace Namespace { class ClassName {}; }";
+ const char* xmlCode = "\
+ <typesystem package=\"Foo\"> \
+ <namespace-type name=\"Namespace\"/> \
+ <value-type name=\"Namespace::ClassName\"/> \
+ </typesystem>";
+ processCode(cppCode, xmlCode);
+ AbstractMetaClassList classes = m_builder->classes();
+ QCOMPARE(classes.count(), 2); // 1 namespace + 1 class
+ QCOMPARE(classes[0]->name(), QString("ClassName"));
+ QCOMPARE(classes[0]->qualifiedCppName(), QString("Namespace::ClassName"));
+ QCOMPARE(classes[1]->name(), QString("Namespace"));
+}
+
+
+QTEST_APPLESS_MAIN(TestAbstractMetaClass)
+
+#include "testabstractmetaclass.moc"
diff --git a/tests/testabstractmetaclass.h b/tests/testabstractmetaclass.h
new file mode 100644
index 000000000..a15061bbe
--- /dev/null
+++ b/tests/testabstractmetaclass.h
@@ -0,0 +1,47 @@
+/*
+* This file is part of the API Extractor 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 TESTABSTRACTMETACLASS_H
+#define TESTABSTRACTMETACLASS_H
+
+#include <QtCore/QObject>
+
+class AbstractMetaBuilder;
+
+class TestAbstractMetaClass : public QObject
+{
+ Q_OBJECT
+public:
+ TestAbstractMetaClass();
+private slots:
+ void init();
+ void cleanup();
+ void testClassName();
+ void testClassNameUnderNamespace();
+private:
+ AbstractMetaBuilder* m_builder;
+
+ void processCode(const char* cppCode, const char* xmlCode);
+};
+
+#endif // TESTABSTRACTMETACLASS_H