From 756d5502f9f1eb5dae589e233f427ac48e6e92ed Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 30 Jan 2015 20:40:56 +0100 Subject: add autotest for ioutils Change-Id: I63700a57e0edf5aec02abfffdc7601743379f12c Reviewed-by: Joerg Bornemann --- tests/auto/tools/qmakelib/qmakelib.pro | 1 + tests/auto/tools/qmakelib/tst_qmakelib.cpp | 98 ++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) (limited to 'tests/auto/tools/qmakelib') diff --git a/tests/auto/tools/qmakelib/qmakelib.pro b/tests/auto/tools/qmakelib/qmakelib.pro index df13670438..3381d3bcb7 100644 --- a/tests/auto/tools/qmakelib/qmakelib.pro +++ b/tests/auto/tools/qmakelib/qmakelib.pro @@ -8,4 +8,5 @@ VPATH += ../../../../qmake/library SOURCES += \ tst_qmakelib.cpp \ + ioutils.cpp \ proitems.cpp diff --git a/tests/auto/tools/qmakelib/tst_qmakelib.cpp b/tests/auto/tools/qmakelib/tst_qmakelib.cpp index e7bfa8e814..4c7aac1c48 100644 --- a/tests/auto/tools/qmakelib/tst_qmakelib.cpp +++ b/tests/auto/tools/qmakelib/tst_qmakelib.cpp @@ -33,10 +33,13 @@ #include +#include #include #include +using namespace QMakeInternal; + class tst_qmakelib : public QObject { Q_OBJECT @@ -46,6 +49,12 @@ public: virtual ~tst_qmakelib() {} private slots: + void quoteArgUnix_data(); + void quoteArgUnix(); + void quoteArgWin_data(); + void quoteArgWin(); + void pathUtils(); + void proStringList(); }; @@ -68,5 +77,94 @@ void tst_qmakelib::proStringList() QVERIFY(sl1.contains("COOL", Qt::CaseInsensitive)); } +void tst_qmakelib::quoteArgUnix_data() +{ + QTest::addColumn("in"); + QTest::addColumn("out"); + + static const struct { + const char * const in; + const char * const out; + } vals[] = { + { "", "''" }, + { "hallo", "hallo" }, + { "hallo du", "'hallo du'" }, + { "ha'llo", "'ha'\\''llo'" }, + }; + + for (unsigned i = 0; i < sizeof(vals)/sizeof(vals[0]); i++) + QTest::newRow(vals[i].in) << QString::fromLatin1(vals[i].in) + << QString::fromLatin1(vals[i].out); +} + +void tst_qmakelib::quoteArgUnix() +{ + QFETCH(QString, in); + QFETCH(QString, out); + + QCOMPARE(IoUtils::shellQuoteUnix(in), out); +} + +void tst_qmakelib::quoteArgWin_data() +{ + QTest::addColumn("in"); + QTest::addColumn("out"); + + static const struct { + const char * const in; + const char * const out; + } vals[] = { + { "", "\"\"" }, + { "hallo", "hallo" }, + { "hallo du", "\"hallo du\"" }, + { "hallo\\", "hallo\\" }, + { "hallo du\\", "\"hallo du\\\\\"" }, + { "ha\"llo", "\"ha\\\"llo^\"" }, + { "ha\\\"llo", "\"ha\\\\\\\"llo^\"" }, + }; + + for (unsigned i = 0; i < sizeof(vals)/sizeof(vals[0]); i++) + QTest::newRow(vals[i].in) << QString::fromLatin1(vals[i].in) + << QString::fromLatin1(vals[i].out); +} + +void tst_qmakelib::quoteArgWin() +{ + QFETCH(QString, in); + QFETCH(QString, out); + + QCOMPARE(IoUtils::shellQuoteWin(in), out); +} + +void tst_qmakelib::pathUtils() +{ + QString afp = QCoreApplication::applicationFilePath(); + QVERIFY(IoUtils::exists(afp)); + QVERIFY(!IoUtils::exists(afp + "-tehfail")); + QCOMPARE(IoUtils::fileType(afp), IoUtils::FileIsRegular); + QString adp = QCoreApplication::applicationDirPath(); + QCOMPARE(IoUtils::fileType(adp), IoUtils::FileIsDir); + + QString fn0 = "file/path"; + QVERIFY(IoUtils::isRelativePath(fn0)); + + QString fn1 = "/a/unix/file/path"; + QVERIFY(IoUtils::isAbsolutePath(fn1)); + QCOMPARE(IoUtils::pathName(fn1).toString(), QStringLiteral("/a/unix/file/")); + QCOMPARE(IoUtils::fileName(fn1).toString(), QStringLiteral("path")); + +#ifdef Q_OS_WIN + QString fn0a = "c:file/path"; + QVERIFY(IoUtils::isRelativePath(fn0a)); + + QString fn1a = "c:\\file\\path"; + QVERIFY(IoUtils::isAbsolutePath(fn1a)); +#endif + + QString fnbase = "/another/dir"; + QCOMPARE(IoUtils::resolvePath(fnbase, fn0), QStringLiteral("/another/dir/file/path")); + QCOMPARE(IoUtils::resolvePath(fnbase, fn1), QStringLiteral("/a/unix/file/path")); +} + QTEST_MAIN(tst_qmakelib) #include "tst_qmakelib.moc" -- cgit v1.2.3