aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-01-13 10:48:43 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-01-25 08:32:20 -0300
commite674a8ddbc11e51f3f701e8ab7783aefec8cfeec (patch)
tree1565cc7b8a5990bdf7a647ed7372d869f152d88a
parentb5e32ea4f620a0f7e3e2ee6bba741b0f08686312 (diff)
Added a dummy generator as a source of test cases.
Unit tests were added as well.
-rw-r--r--tests/CMakeLists.txt7
-rw-r--r--tests/test_generator/CMakeLists.txt46
-rw-r--r--tests/test_generator/dummygenerator.cpp42
-rw-r--r--tests/test_generator/dummygenerator.h44
-rw-r--r--tests/test_generator/dummygentest.cpp131
-rw-r--r--tests/test_generator/dummygentest.h42
-rw-r--r--tests/test_generator/dummygentestconfig.h.in9
-rw-r--r--tests/test_generator/main.cpp34
8 files changed, 355 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 1f123bf72..b8facb001 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,3 +1,10 @@
+if(CMAKE_VERSION VERSION_LESS 2.8)
+ # Versions lesser than 2.8 can not set environment variables for tests.
+ message("CMake version greater than 2.8 necessary to run certain tests.")
+else()
+ add_subdirectory(test_generator)
+endif()
+
if (NOT APIEXTRACTOR_DOCSTRINGS_DISABLED)
project(sphinxtabletest)
diff --git a/tests/test_generator/CMakeLists.txt b/tests/test_generator/CMakeLists.txt
new file mode 100644
index 000000000..c8dd017e4
--- /dev/null
+++ b/tests/test_generator/CMakeLists.txt
@@ -0,0 +1,46 @@
+project(test_generator)
+
+set(dummy_generator_SRC dummygenerator.cpp)
+add_library(dummy_generator SHARED ${dummy_generator_SRC})
+target_link_libraries(dummy_generator ${APIEXTRACTOR_LIBRARY} ${QT_QTCORE_LIBRARY} genrunner)
+set_property(TARGET dummy_generator PROPERTY PREFIX "")
+
+add_executable(dummygenerator main.cpp)
+set(DUMMYGENERATOR_EXECUTABLE dummygenerator${generator_SUFFIX})
+set_target_properties(dummygenerator PROPERTIES OUTPUT_NAME ${DUMMYGENERATOR_EXECUTABLE})
+target_link_libraries(dummygenerator ${QT_QTCORE_LIBRARY})
+
+configure_file(dummygentestconfig.h.in "${CMAKE_CURRENT_BINARY_DIR}/dummygentestconfig.h" @ONLY)
+
+get_filename_component(APIEXTRACTOR_LIBRARY_DIRS ${APIEXTRACTOR_LIBRARY} PATH)
+if(WIN32)
+ set(PATH_SEP ";")
+ find_program(APIEXTRACTOR_BINARY apiextractor.dll HINTS ${APIEXTRACTOR_LIBRARY_DIRS})
+ get_filename_component(APIEXTRACTOR_BINARY_DIR ${APIEXTRACTOR_BINARY} PATH)
+ set(APIEXTRACTOR_LIBRARY_DIRS "${APIEXTRACTOR_LIBRARY_DIRS}${PATH_SEP}${APIEXTRACTOR_BINARY_DIR}")
+else()
+ set(PATH_SEP ":")
+endif()
+
+set(ENV_PATH "${generatorrunner_BINARY_DIR}${PATH_SEP}${CMAKE_CURRENT_BINARY_DIR}${PATH_SEP}$ENV{PATH}${PATH_SEP}${APIEXTRACTOR_LIBRARY_DIRS}")
+set(ENV_QT_PLUGIN_PATH "${CMAKE_CURRENT_BINARY_DIR}${PATH_SEP}$ENV{QT_PLUGIN_PATH}")
+if(WIN32)
+ string(REPLACE "\\;" ";" ENV_PATH "${ENV_PATH}")
+ string(REPLACE ";" "\\;" ENV_PATH "${ENV_PATH}")
+ string(REPLACE "\\;" ";" ENV_QT_PLUGIN_PATH "${ENV_QT_PLUGIN_PATH}")
+ string(REPLACE ";" "\\;" ENV_QT_PLUGIN_PATH "${ENV_QT_PLUGIN_PATH}")
+endif()
+
+macro(declare_test testname)
+ qt4_automoc("${testname}.cpp")
+ add_executable(${testname} "${testname}.cpp")
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
+ target_link_libraries(${testname} ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY})
+ add_test(${testname} ${testname})
+ set_property(TEST ${testname} PROPERTY ENVIRONMENT "PATH=${ENV_PATH}" "QT_PLUGIN_PATH=${ENV_QT_PLUGIN_PATH}")
+endmacro(declare_test testname)
+
+declare_test(dummygentest)
+
+add_dependencies(dummygenerator generatorrunner)
+
diff --git a/tests/test_generator/dummygenerator.cpp b/tests/test_generator/dummygenerator.cpp
new file mode 100644
index 000000000..fc3912fe6
--- /dev/null
+++ b/tests/test_generator/dummygenerator.cpp
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the PySide project.
+ *
+ * Copyright (C) 2011 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 <iostream>
+#include "dummygenerator.h"
+
+EXPORT_GENERATOR_PLUGIN(new DummyGenerator)
+
+using namespace std;
+
+QString
+DummyGenerator::fileNameForClass(const AbstractMetaClass* metaClass) const
+{
+ return QString("%1_generated.txt").arg(metaClass->name().toLower());
+}
+
+void
+DummyGenerator::generateClass(QTextStream& s, const AbstractMetaClass* metaClass)
+{
+ s << "// Generated code for class: " << qPrintable(metaClass->name()) << endl;
+}
+
diff --git a/tests/test_generator/dummygenerator.h b/tests/test_generator/dummygenerator.h
new file mode 100644
index 000000000..154dc2579
--- /dev/null
+++ b/tests/test_generator/dummygenerator.h
@@ -0,0 +1,44 @@
+/*
+ * This file is part of the PySide project.
+ *
+ * Copyright (C) 2011 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 DUMMYGENERATOR_H
+#define DUMMYGENERATOR_H
+
+#include "generator.h"
+
+class GENRUNNER_API DummyGenerator : public Generator
+{
+public:
+ DummyGenerator() {}
+ ~DummyGenerator() {}
+ bool doSetup(const QMap<QString, QString>& args) { return true; }
+ const char* name() const { return "DummyGenerator"; }
+
+protected:
+ void writeFunctionArguments(QTextStream&, const AbstractMetaFunction*, Options) const {}
+ void writeArgumentNames(QTextStream&, const AbstractMetaFunction*, Options) const {}
+ QString fileNameForClass(const AbstractMetaClass* metaClass) const;
+ void generateClass(QTextStream& s, const AbstractMetaClass* metaClass);
+ void finishGeneration() {}
+};
+
+#endif // DUMMYGENERATOR_H
diff --git a/tests/test_generator/dummygentest.cpp b/tests/test_generator/dummygentest.cpp
new file mode 100644
index 000000000..55fe3b45f
--- /dev/null
+++ b/tests/test_generator/dummygentest.cpp
@@ -0,0 +1,131 @@
+/*
+ * This file is part of the PySide project.
+ *
+ * Copyright (C) 2011 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 "dummygentest.h"
+#include "dummygenerator.h"
+#include "dummygentestconfig.h"
+#include <QTemporaryFile>
+#include <QtTest/QTest>
+#include <QProcess>
+
+#define HEADER_CONTENTS "struct Dummy {};"
+#define TYPESYSTEM_CONTENTS "<typesystem package='dummy'><value-type name='Dummy'/></typesystem>"
+#define GENERATED_CONTENTS "// Generated code for class: Dummy"
+#define GENERATED_FILE "dummy/dummy_generated.txt"
+
+void DummyGenTest::testCallGenRunnerWithFullPathToDummyGenModule()
+{
+ QTemporaryFile headerFile;
+ headerFile.open();
+ QCOMPARE(headerFile.write(HEADER_CONTENTS), qint64(sizeof(HEADER_CONTENTS)-1));
+ headerFile.close();
+
+ QTemporaryFile typesystemFile;
+ typesystemFile.open();
+ QCOMPARE(typesystemFile.write(TYPESYSTEM_CONTENTS), qint64(sizeof(TYPESYSTEM_CONTENTS)-1));
+ typesystemFile.close();
+
+ QString generatedFileName = QString("%1/" GENERATED_FILE).arg(QDir::tempPath());
+ QFile::remove(generatedFileName);
+
+ QStringList args;
+ args.append("--generator-set=" DUMMYGENERATOR_BINARY_DIR "/dummy_generator" MODULE_EXTENSION);
+ args.append(QString("--output-directory=%1").arg(QDir::tempPath()));
+ args.append(headerFile.fileName());
+ args.append(typesystemFile.fileName());
+ int result = QProcess::execute("generatorrunner", args);
+ QCOMPARE(result, 0);
+
+ QFile generatedFile(generatedFileName);
+ generatedFile.open(QIODevice::ReadOnly);
+ QCOMPARE(generatedFile.readAll().trimmed(), QByteArray(GENERATED_CONTENTS).trimmed());
+ generatedFile.close();
+
+ QVERIFY(generatedFile.remove());
+}
+
+void DummyGenTest::testCallGenRunnerWithNameOfDummyGenModule()
+{
+ QTemporaryFile headerFile;
+ headerFile.open();
+ QCOMPARE(headerFile.write(HEADER_CONTENTS), qint64(sizeof(HEADER_CONTENTS)-1));
+ headerFile.close();
+
+ QTemporaryFile typesystemFile;
+ typesystemFile.open();
+ QCOMPARE(typesystemFile.write(TYPESYSTEM_CONTENTS), qint64(sizeof(TYPESYSTEM_CONTENTS)-1));
+ typesystemFile.close();
+
+ QString generatedFileName = QString("%1/" GENERATED_FILE).arg(QDir::tempPath());
+ QFile::remove(generatedFileName);
+
+ QStringList args;
+ args.append("--generator-set=dummy");
+ args.append(QString("--output-directory=%1").arg(QDir::tempPath()));
+ args.append(headerFile.fileName());
+ args.append(typesystemFile.fileName());
+ int result = QProcess::execute("generatorrunner", args);
+ QCOMPARE(result, 0);
+
+ QFile generatedFile(generatedFileName);
+ generatedFile.open(QIODevice::ReadOnly);
+ QCOMPARE(generatedFile.readAll().trimmed(), QByteArray(GENERATED_CONTENTS).trimmed());
+ generatedFile.close();
+
+ QVERIFY(generatedFile.remove());
+}
+
+void DummyGenTest::testCallDummyGeneratorExecutable()
+{
+ QTemporaryFile headerFile;
+ headerFile.open();
+ QCOMPARE(headerFile.write(HEADER_CONTENTS), qint64(sizeof(HEADER_CONTENTS)-1));
+ headerFile.close();
+
+ QTemporaryFile typesystemFile;
+ typesystemFile.open();
+ QCOMPARE(typesystemFile.write(TYPESYSTEM_CONTENTS), qint64(sizeof(TYPESYSTEM_CONTENTS)-1));
+ typesystemFile.close();
+
+ QString generatedFileName = QString("%1/" GENERATED_FILE).arg(QDir::tempPath());
+ QFile::remove(generatedFileName);
+
+ QStringList args;
+ args.append(QString("--output-directory=%1").arg(QDir::tempPath()));
+ args.append(headerFile.fileName());
+ args.append(typesystemFile.fileName());
+ int result = QProcess::execute(DUMMYGENERATOR_BINARY, args);
+ QCOMPARE(result, 0);
+
+ QFile generatedFile(generatedFileName);
+ generatedFile.open(QIODevice::ReadOnly);
+ QCOMPARE(generatedFile.readAll().trimmed(), QByteArray(GENERATED_CONTENTS).trimmed());
+ generatedFile.close();
+
+ QVERIFY(generatedFile.remove());
+}
+
+QTEST_APPLESS_MAIN(DummyGenTest)
+
+#include "dummygentest.moc"
+
diff --git a/tests/test_generator/dummygentest.h b/tests/test_generator/dummygentest.h
new file mode 100644
index 000000000..0bfab2a0d
--- /dev/null
+++ b/tests/test_generator/dummygentest.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the PySide project.
+ *
+ * Copyright (C) 2011 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 DUMMYGENTABLETEST_H
+#define DUMMYGENTABLETEST_H
+
+#include <QObject>
+
+class DummyGenerator;
+
+class DummyGenTest : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testCallGenRunnerWithFullPathToDummyGenModule();
+ void testCallGenRunnerWithNameOfDummyGenModule();
+ void testCallDummyGeneratorExecutable();
+};
+
+#endif
+
diff --git a/tests/test_generator/dummygentestconfig.h.in b/tests/test_generator/dummygentestconfig.h.in
new file mode 100644
index 000000000..e472804dc
--- /dev/null
+++ b/tests/test_generator/dummygentestconfig.h.in
@@ -0,0 +1,9 @@
+#ifndef DUMMYGENTESTCONFIG_H
+#define DUMMYGENTESTCONFIG_H
+
+#define MODULE_EXTENSION "@CMAKE_SHARED_LIBRARY_SUFFIX@"
+#define DUMMYGENERATOR_BINARY "@DUMMYGENERATOR_EXECUTABLE@"
+#define DUMMYGENERATOR_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@"
+
+#endif // DUMMYGENTESTCONFIG_H
+
diff --git a/tests/test_generator/main.cpp b/tests/test_generator/main.cpp
new file mode 100644
index 000000000..47ad4d0a5
--- /dev/null
+++ b/tests/test_generator/main.cpp
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the PySide project.
+ *
+ * Copyright (C) 2011 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 <QtCore>
+
+int main(int argc, char *argv[])
+{
+ QStringList args;
+ args.append("--generator-set=dummy");
+ for (int i = 1; i < argc; i++)
+ args.append(argv[i]);
+ return QProcess::execute("generatorrunner", args);
+}
+