summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-01-24 21:17:27 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-01-25 08:32:20 -0300
commit5f6d08e17f214d7d3a41a1cbdfb2d975e02a33cd (patch)
tree4287dc5ba6eafe5db035ea661ef3133a67aa196c /tests
parent13480bf7867bed1cfa64613fddb0d6e53aa36b9e (diff)
downloadgeneratorrunner-5f6d08e17f214d7d3a41a1cbdfb2d975e02a33cd.tar.gz
generatorrunner-5f6d08e17f214d7d3a41a1cbdfb2d975e02a33cd.tar.xz
generatorrunner-5f6d08e17f214d7d3a41a1cbdfb2d975e02a33cd.zip
Modified GeneratorRunner to support a simpler format of project file.
The project file are now just a text file containing key/value pairs. The documentation was updated accordingly, including the man page.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_generator/CMakeLists.txt6
-rw-r--r--tests/test_generator/dummygenerator.cpp22
-rw-r--r--tests/test_generator/dummygenerator.h2
-rw-r--r--tests/test_generator/dummygentest-project.txt.in20
-rw-r--r--tests/test_generator/dummygentest.cpp102
-rw-r--r--tests/test_generator/dummygentest.h9
-rw-r--r--tests/test_generator/test_global.h1
-rw-r--r--tests/test_generator/test_typesystem.xml3
8 files changed, 113 insertions, 52 deletions
diff --git a/tests/test_generator/CMakeLists.txt b/tests/test_generator/CMakeLists.txt
index c8dd017..180bba2 100644
--- a/tests/test_generator/CMakeLists.txt
+++ b/tests/test_generator/CMakeLists.txt
@@ -40,6 +40,12 @@ macro(declare_test testname)
set_property(TEST ${testname} PROPERTY ENVIRONMENT "PATH=${ENV_PATH}" "QT_PLUGIN_PATH=${ENV_QT_PLUGIN_PATH}")
endmacro(declare_test testname)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/test_global.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/test_global.h" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/test_typesystem.xml"
+ "${CMAKE_CURRENT_BINARY_DIR}/test_typesystem.xml" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/dummygentest-project.txt.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/dummygentest-project.txt" @ONLY)
declare_test(dummygentest)
add_dependencies(dummygenerator generatorrunner)
diff --git a/tests/test_generator/dummygenerator.cpp b/tests/test_generator/dummygenerator.cpp
index fc3912f..795d7af 100644
--- a/tests/test_generator/dummygenerator.cpp
+++ b/tests/test_generator/dummygenerator.cpp
@@ -40,3 +40,25 @@ DummyGenerator::generateClass(QTextStream& s, const AbstractMetaClass* metaClass
s << "// Generated code for class: " << qPrintable(metaClass->name()) << endl;
}
+bool
+DummyGenerator::doSetup(const QMap<QString, QString>& args)
+{
+ if (args.contains("dump-arguments") && !args["dump-arguments"].isEmpty()) {
+ QFile logFile(args["dump-arguments"]);
+ logFile.open(QIODevice::WriteOnly | QIODevice::Text);
+ QTextStream out(&logFile);
+ foreach (const QString& key, args.keys()) {
+ if (key == "arg-1")
+ out << "header-file";
+ else if (key == "arg-2")
+ out << "typesystem-file";
+ else
+ out << key;
+ if (!args[key].isEmpty())
+ out << " = " << args[key];
+ out << endl;
+ }
+ }
+ return true;
+}
+
diff --git a/tests/test_generator/dummygenerator.h b/tests/test_generator/dummygenerator.h
index 154dc25..079c1d5 100644
--- a/tests/test_generator/dummygenerator.h
+++ b/tests/test_generator/dummygenerator.h
@@ -30,7 +30,7 @@ class GENRUNNER_API DummyGenerator : public Generator
public:
DummyGenerator() {}
~DummyGenerator() {}
- bool doSetup(const QMap<QString, QString>& args) { return true; }
+ bool doSetup(const QMap<QString, QString>& args);
const char* name() const { return "DummyGenerator"; }
protected:
diff --git a/tests/test_generator/dummygentest-project.txt.in b/tests/test_generator/dummygentest-project.txt.in
new file mode 100644
index 0000000..0a076d8
--- /dev/null
+++ b/tests/test_generator/dummygentest-project.txt.in
@@ -0,0 +1,20 @@
+[generator-project]
+
+generator-set = dummy
+header-file = @CMAKE_CURRENT_BINARY_DIR@/test_global.h
+typesystem-file = @CMAKE_CURRENT_BINARY_DIR@/test_typesystem.xml
+output-directory = /tmp/output
+
+dump-arguments = @CMAKE_CURRENT_BINARY_DIR@/dummygen-args.log
+
+include-path = /include/path/location1
+include-path = /include/path/location2
+
+typesystem-path = /typesystem/path/location1
+typesystem-path = /typesystem/path/location2
+
+api-version = 1.2.3
+debug = sparse
+
+no-suppress-warnings
+
diff --git a/tests/test_generator/dummygentest.cpp b/tests/test_generator/dummygentest.cpp
index 55fe3b4..3261a3c 100644
--- a/tests/test_generator/dummygentest.cpp
+++ b/tests/test_generator/dummygentest.cpp
@@ -28,35 +28,32 @@
#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()
+void DummyGenTest::initTestCase()
{
- 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);
+ int argc = 0;
+ char* argv[] = {NULL};
+ QCoreApplication app(argc, argv);
+ workDir = QCoreApplication::applicationDirPath();
+
+ headerFilePath = workDir + "/test_global.h";
+ typesystemFilePath = workDir + "/test_typesystem.xml";
+ projectFilePath = workDir + "/dummygentest-project.txt";
+ generatedFilePath = QString("%1/dummy/dummy_generated.txt").arg(QDir::tempPath());
+}
+void DummyGenTest::testCallGenRunnerWithFullPathToDummyGenModule()
+{
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());
+ args.append(headerFilePath);
+ args.append(typesystemFilePath);
int result = QProcess::execute("generatorrunner", args);
QCOMPARE(result, 0);
- QFile generatedFile(generatedFileName);
+ QFile generatedFile(generatedFilePath);
generatedFile.open(QIODevice::ReadOnly);
QCOMPARE(generatedFile.readAll().trimmed(), QByteArray(GENERATED_CONTENTS).trimmed());
generatedFile.close();
@@ -66,28 +63,15 @@ void DummyGenTest::testCallGenRunnerWithFullPathToDummyGenModule()
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());
+ args.append(headerFilePath);
+ args.append(typesystemFilePath);
int result = QProcess::execute("generatorrunner", args);
QCOMPARE(result, 0);
- QFile generatedFile(generatedFileName);
+ QFile generatedFile(generatedFilePath);
generatedFile.open(QIODevice::ReadOnly);
QCOMPARE(generatedFile.readAll().trimmed(), QByteArray(GENERATED_CONTENTS).trimmed());
generatedFile.close();
@@ -97,27 +81,14 @@ void DummyGenTest::testCallGenRunnerWithNameOfDummyGenModule()
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());
+ args.append(headerFilePath);
+ args.append(typesystemFilePath);
int result = QProcess::execute(DUMMYGENERATOR_BINARY, args);
QCOMPARE(result, 0);
- QFile generatedFile(generatedFileName);
+ QFile generatedFile(generatedFilePath);
generatedFile.open(QIODevice::ReadOnly);
QCOMPARE(generatedFile.readAll().trimmed(), QByteArray(GENERATED_CONTENTS).trimmed());
generatedFile.close();
@@ -125,6 +96,35 @@ void DummyGenTest::testCallDummyGeneratorExecutable()
QVERIFY(generatedFile.remove());
}
+void DummyGenTest::testProjectFileArgumentsReading()
+{
+ QStringList args(QString("--project-file=%1/dummygentest-project.txt").arg(workDir));
+ int result = QProcess::execute("generatorrunner", args);
+ QCOMPARE(result, 0);
+
+ QFile logFile(workDir + "/dummygen-args.log");
+ logFile.open(QIODevice::ReadOnly);
+ QStringList logContents;
+ while (!logFile.atEnd())
+ logContents << logFile.readLine().trimmed();
+ logContents.sort();
+ QCOMPARE(logContents[0], QString("api-version = 1.2.3"));
+ QCOMPARE(logContents[1], QString("debug = sparse"));
+ QVERIFY(logContents[2].startsWith("dump-arguments = "));
+ QVERIFY(logContents[2].endsWith("dummygen-args.log"));
+ QCOMPARE(logContents[3], QString("generator-set = dummy"));
+ QVERIFY(logContents[4].startsWith("header-file = "));
+ QVERIFY(logContents[4].endsWith("test_global.h"));
+ QCOMPARE(logContents[5], QString("include-paths = /include/path/location1:/include/path/location2"));
+ QCOMPARE(logContents[6], QString("no-suppress-warnings"));
+ QCOMPARE(logContents[7], QString("output-directory = /tmp/output"));
+ QVERIFY(logContents[8].startsWith("project-file = "));
+ QVERIFY(logContents[8].endsWith("dummygentest-project.txt"));
+ QVERIFY(logContents[9].startsWith("typesystem-file = "));
+ QVERIFY(logContents[9].endsWith("test_typesystem.xml"));
+ QCOMPARE(logContents[10], QString("typesystem-paths = /typesystem/path/location1:/typesystem/path/location2"));
+}
+
QTEST_APPLESS_MAIN(DummyGenTest)
#include "dummygentest.moc"
diff --git a/tests/test_generator/dummygentest.h b/tests/test_generator/dummygentest.h
index 0bfab2a..0f485ae 100644
--- a/tests/test_generator/dummygentest.h
+++ b/tests/test_generator/dummygentest.h
@@ -32,10 +32,19 @@ class DummyGenTest : public QObject
{
Q_OBJECT
+private:
+ QString workDir;
+ QString headerFilePath;
+ QString typesystemFilePath;
+ QString generatedFilePath;
+ QString projectFilePath;
+
private slots:
+ void initTestCase();
void testCallGenRunnerWithFullPathToDummyGenModule();
void testCallGenRunnerWithNameOfDummyGenModule();
void testCallDummyGeneratorExecutable();
+ void testProjectFileArgumentsReading();
};
#endif
diff --git a/tests/test_generator/test_global.h b/tests/test_generator/test_global.h
new file mode 100644
index 0000000..6a95200
--- /dev/null
+++ b/tests/test_generator/test_global.h
@@ -0,0 +1 @@
+struct Dummy {};
diff --git a/tests/test_generator/test_typesystem.xml b/tests/test_generator/test_typesystem.xml
new file mode 100644
index 0000000..c19a4e9
--- /dev/null
+++ b/tests/test_generator/test_typesystem.xml
@@ -0,0 +1,3 @@
+<typesystem package='dummy'>
+ <value-type name='Dummy'/>
+</typesystem>