aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/tools/tst_tools.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2013-02-07 17:31:59 +0100
committerJoerg Bornemann <joerg.bornemann@digia.com>2013-02-08 17:29:16 +0100
commita0442f40968da79b4b0e50e665a8885b78769df7 (patch)
tree019f0f27456b57e49079221adaf3d48e277e2674 /tests/auto/tools/tst_tools.cpp
parenta9f9ea2dbfa327b7bf5e4247c073d2ba6eaef30b (diff)
Build a shared library.
We don't want our code to be duplicated in memory for each application that uses it, so the library should not be linked statically. Some ramifications worth mentioning: - The unit tests had to be moved into the library, because otherwise we would need to export random internal symbols. This is why the patch appears so big. A follow-up patch should probably make compilation of tests optional, so the library can be deployed without unneeded code. - The DESTDIR of the auto test executables is now the same as the one of all other executables, so they can all use the dll on Windows without additional setup. - Some internal symbols were exported, namely: a) Logging-related stuff. This allows us to use a uniform logging approach in the library and in our command-line tools; I consider this acceptable. b) A handful of classes and functions currently needed by certain command-line tools. These seem more questionable to me and we should probably find a different way to implement the respective functionality. Change-Id: I9cd21e12cd622b55cf62f5e04ad398734410ede1 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'tests/auto/tools/tst_tools.cpp')
-rw-r--r--tests/auto/tools/tst_tools.cpp187
1 files changed, 9 insertions, 178 deletions
diff --git a/tests/auto/tools/tst_tools.cpp b/tests/auto/tools/tst_tools.cpp
index 3bd21f990..f0c446fb8 100644
--- a/tests/auto/tools/tst_tools.cpp
+++ b/tests/auto/tools/tst_tools.cpp
@@ -27,185 +27,16 @@
**
****************************************************************************/
-#include <app/qbs/parser/commandlineparser.h>
-#include <app/shared/logging/consolelogger.h>
#include <app/shared/qbssettings.h>
-#include <tools/buildoptions.h>
-#include <tools/error.h>
-#include <tools/fileinfo.h>
-#include <tools/hostosinfo.h>
-#include <tools/profile.h>
-#include <tools/settings.h>
-#include <QDir>
-#include <QTemporaryFile>
-#include <QtTest>
+#include <tools/tst_tools.h>
-using namespace qbs;
-using namespace Internal;
+#include <QCoreApplication>
+#include <QTest>
-static SettingsPtr settings = qbsSettings();
-
-class TestTools : public QObject
+int main(int argc, char *argv[])
{
- Q_OBJECT
-public:
- TestTools()
- {
- ConsoleLogger::instance().logSink()->setEnabled(false);
- }
-
-private slots:
- void testValidCommandLine()
- {
- QTemporaryFile projectFile;
- QVERIFY(projectFile.open());
- const QStringList fileArgs = QStringList() << "-f" << projectFile.fileName();
- QStringList args;
- args.append("-vvk");
- args.append("-v");
- args << "--products" << "blubb";
- args << "--changed-files" << "foo,bar" << fileArgs;
- args << "--force";
- CommandLineParser parser;
-
- QVERIFY(parser.parseCommandLine(args, settings.data()));
- QCOMPARE(ConsoleLogger::instance().logSink()->logLevel(), LoggerTrace);
- QCOMPARE(parser.command(), BuildCommandType);
- QCOMPARE(parser.products(), QStringList() << "blubb");
- QCOMPARE(parser.buildOptions().changedFiles.count(), 2);
- QVERIFY(parser.buildOptions().keepGoing);
- QVERIFY(parser.force());
-
- QVERIFY(parser.parseCommandLine(QStringList() << "-vvvqqq" << fileArgs, settings.data()));
- QCOMPARE(ConsoleLogger::instance().logSink()->logLevel(), defaultLogLevel());
- QVERIFY(!parser.force());
-
- QVERIFY(parser.parseCommandLine(QStringList() << "-vvqqq" << fileArgs, settings.data()));
- QCOMPARE(ConsoleLogger::instance().logSink()->logLevel(), LoggerWarning);
-
- QVERIFY(parser.parseCommandLine(QStringList() << "-vvvqq" << fileArgs, settings.data()));
- QCOMPARE(ConsoleLogger::instance().logSink()->logLevel(), LoggerDebug);
-
- QVERIFY(parser.parseCommandLine(QStringList() << "--log-level" << "trace" << fileArgs,
- settings.data()));
- QCOMPARE(ConsoleLogger::instance().logSink()->logLevel(), LoggerTrace);
- }
-
- void testInvalidCommandLine()
- {
- QTemporaryFile projectFile;
- QVERIFY(projectFile.open());
- const QStringList fileArgs = QStringList() << "-f" << projectFile.fileName();
- CommandLineParser parser;
- QVERIFY(!parser.parseCommandLine(QStringList() << "-x" << fileArgs, settings.data())); // Unknown short option.
- QVERIFY(!parser.parseCommandLine(QStringList() << "--xyz" << fileArgs, settings.data())); // Unknown long option.
- QVERIFY(!parser.parseCommandLine(QStringList() << "-vjv" << fileArgs, settings.data())); // Invalid position.
- QVERIFY(!parser.parseCommandLine(QStringList() << "-j" << fileArgs, settings.data())); // Missing argument.
- QVERIFY(!parser.parseCommandLine(QStringList() << "-j" << "0" << fileArgs,
- settings.data())); // Wrong argument.
- QVERIFY(!parser.parseCommandLine(QStringList() << "--products" << fileArgs,
- settings.data())); // Missing argument.
- QVERIFY(!parser.parseCommandLine(QStringList() << "--changed-files" << "," << fileArgs,
- settings.data())); // Wrong argument.
- QVERIFY(!parser.parseCommandLine(QStringList() << "--log-level" << "blubb" << fileArgs,
- settings.data())); // Wrong argument.
- QVERIFY(!parser.parseCommandLine(QStringList("properties") << fileArgs << "--force",
- settings.data())); // Invalid option for command.
- }
-
- void testFileInfo()
- {
- QCOMPARE(FileInfo::fileName("C:/waffl/copter.exe"), QString("copter.exe"));
- QCOMPARE(FileInfo::baseName("C:/waffl/copter.exe.lib"), QString("copter"));
- QCOMPARE(FileInfo::completeBaseName("C:/waffl/copter.exe.lib"), QString("copter.exe"));
- QCOMPARE(FileInfo::path("abc"), QString("."));
- QCOMPARE(FileInfo::path("/abc/lol"), QString("/abc"));
- QVERIFY(!FileInfo::isAbsolute("bla/lol"));
- QVERIFY(FileInfo::isAbsolute("/bla/lol"));
- if (HostOsInfo::isWindowsHost())
- QVERIFY(FileInfo::isAbsolute("C:\\bla\\lol"));
- QCOMPARE(FileInfo::resolvePath("/abc/lol", "waffl"), QString("/abc/lol/waffl"));
- QCOMPARE(FileInfo::resolvePath("/abc/def/ghi/jkl/", "../foo/bar"), QString("/abc/def/ghi/foo/bar"));
- QCOMPARE(FileInfo::resolvePath("/abc/def/ghi/jkl/", "../../foo/bar"), QString("/abc/def/foo/bar"));
- QCOMPARE(FileInfo::resolvePath("/abc", "../../../foo/bar"), QString("/foo/bar"));
- QCOMPARE(FileInfo("/does/not/exist").lastModified(), FileTime());
- }
-
- void testProjectFileLookup()
- {
- const QString srcDir = QLatin1String(SRCDIR);
- const QString noProjectsDir = srcDir + QLatin1String("data/dirwithnoprojects");
- const QString oneProjectDir = srcDir + QLatin1String("data/dirwithoneproject");
- const QString multiProjectsDir = srcDir + QLatin1String("data/dirwithmultipleprojects");
- Q_ASSERT(QDir(noProjectsDir).exists() && QDir(oneProjectDir).exists()
- && QDir(multiProjectsDir).exists());
- CommandLineParser parser;
- const QStringList args(QLatin1String("-f"));
- QString projectFilePath = multiProjectsDir + QLatin1String("/project.qbs");
- QVERIFY(parser.parseCommandLine(args + QStringList(projectFilePath), settings.data()));
- QCOMPARE(projectFilePath, parser.projectFilePath());
- projectFilePath = oneProjectDir + QLatin1String("/project.qbs");
- QVERIFY(parser.parseCommandLine(args + QStringList(oneProjectDir), settings.data()));
- QCOMPARE(projectFilePath, parser.projectFilePath());
- QVERIFY(!parser.parseCommandLine(args + QStringList(noProjectsDir), settings.data()));
- QVERIFY(!parser.parseCommandLine(args + QStringList(multiProjectsDir), settings.data()));
- }
-
- void testProfiles()
- {
- bool exceptionCaught;
- Profile parentProfile("parent", settings.data());
- Profile childProfile("child", settings.data());
- try {
- parentProfile.removeBaseProfile();
- parentProfile.remove("testKey");
- QCOMPARE(parentProfile.value("testKey", "none").toString(), QLatin1String("none"));
- parentProfile.setValue("testKey", "testValue");
- QCOMPARE(parentProfile.value("testKey").toString(), QLatin1String("testValue"));
-
- childProfile.remove("testKey");
- childProfile.removeBaseProfile();
- QCOMPARE(childProfile.value("testKey", "none").toString(), QLatin1String("none"));
- childProfile.setBaseProfile("blubb");
- QCOMPARE(childProfile.value("testKey", "none").toString(), QLatin1String("none"));
- childProfile.setBaseProfile("parent");
- QCOMPARE(childProfile.value("testKey").toString(), QLatin1String("testValue"));
- childProfile.setBaseProfile("foo");
- QCOMPARE(childProfile.value("testKey", "none").toString(), QLatin1String("none"));
- exceptionCaught = false;
- } catch (Error &) {
- exceptionCaught = true;
- }
- QVERIFY(!exceptionCaught);
-
- try {
- childProfile.setBaseProfile("parent");
- parentProfile.setBaseProfile("child");
- QVERIFY(!childProfile.value("blubb").isValid());
- exceptionCaught = false;
- } catch (Error &) {
- exceptionCaught = true;
- }
- QVERIFY(exceptionCaught);
-
- try {
- QVERIFY(!childProfile.allKeys(Profile::KeySelectionNonRecursive).isEmpty());
- exceptionCaught = false;
- } catch (Error &) {
- exceptionCaught = true;
- }
- QVERIFY(!exceptionCaught);
-
- try {
- QVERIFY(!childProfile.allKeys(Profile::KeySelectionRecursive).isEmpty());
- exceptionCaught = false;
- } catch (Error &) {
- exceptionCaught = true;
- }
- QVERIFY(exceptionCaught);
- }
-};
-
-QTEST_MAIN(TestTools)
-
-#include "tst_tools.moc"
+ QCoreApplication app(argc, argv);
+ SettingsPtr settings = qbsSettings();
+ qbs::Internal::TestTools tt(settings.data());
+ return QTest::qExec(&tt, argc, argv);
+}