diff options
author | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2015-01-30 20:40:56 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2015-02-25 13:54:36 +0000 |
commit | 756d5502f9f1eb5dae589e233f427ac48e6e92ed (patch) | |
tree | 02a2529134efbb7716a3f06f3eff772be27005da | |
parent | e507b0148bc2c3159a88f670c826f6f5165606bd (diff) |
add autotest for ioutils
Change-Id: I63700a57e0edf5aec02abfffdc7601743379f12c
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
-rw-r--r-- | tests/auto/tools/qmakelib/qmakelib.pro | 1 | ||||
-rw-r--r-- | tests/auto/tools/qmakelib/tst_qmakelib.cpp | 98 |
2 files changed, 99 insertions, 0 deletions
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 <QtTest/QtTest> +#include <ioutils.h> #include <proitems.h> #include <QObject> +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<QString>("in"); + QTest::addColumn<QString>("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<QString>("in"); + QTest::addColumn<QString>("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" |