summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-03-02 09:04:38 +0100
committerLiang Qi <liang.qi@qt.io>2017-03-02 09:04:38 +0100
commit71264bae08d81bdeceb96133fdb01c370504dfcc (patch)
treed5dadaac8209d5ef1857a4d65197b9ee12b39848 /tests/auto/corelib
parent5e785c0b83c9908c665f253c131629ac325a21f5 (diff)
parent6d10f739cd750968d0dd0e9d8fa4b64353a86c6c (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/qdir/tst_qdir.cpp2
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp74
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp1
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.pro2
-rw-r--r--tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.pro2
-rw-r--r--tests/auto/corelib/tools/qdate/tst_qdate.cpp3
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp28
-rw-r--r--tests/auto/corelib/tools/qtime/tst_qtime.cpp16
-rw-r--r--tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp2
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp17
10 files changed, 102 insertions, 45 deletions
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp
index 49ee8eb32c..b64de488ed 100644
--- a/tests/auto/corelib/io/qdir/tst_qdir.cpp
+++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp
@@ -353,7 +353,7 @@ void tst_QDir::mkdir_data()
<< QDir::currentPath() + "/testdir/two/three";
QTest::newRow("data0") << dirs.at(0) << true;
QTest::newRow("data1") << dirs.at(1) << false;
- QTest::newRow("data2") << dirs.at(2) << false;
+ QTest::newRow("data2") << dirs.at(2) << false; // note: requires data1 to have been run!
// Ensure that none of these directories already exist
QDir dir;
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 71a0c943d2..e1a999abfb 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -46,6 +46,7 @@ class tst_QUrl : public QObject
Q_OBJECT
private slots:
+ void initTestCase();
void effectiveTLDs_data();
void effectiveTLDs();
void getSetCheck();
@@ -182,8 +183,15 @@ private slots:
private:
void testThreadingHelper();
+
+ QTemporaryDir m_tempDir;
};
+void tst_QUrl::initTestCase()
+{
+ QVERIFY2(m_tempDir.isValid(), qPrintable(m_tempDir.errorString()));
+}
+
// Testing get/set functions
void tst_QUrl::getSetCheck()
{
@@ -3045,49 +3053,59 @@ void tst_QUrl::fromUserInputWithCwd_data()
// Null
QTest::newRow("null") << QString() << QString() << QUrl() << QUrl();
- // Existing file
- QDirIterator it(QDir::currentPath(), QDir::NoDotDot | QDir::AllEntries);
- int c = 0;
- while (it.hasNext()) {
- it.next();
- QUrl url = QUrl::fromLocalFile(it.filePath());
- if (it.fileName() == QLatin1String(".")) {
- url = QUrl::fromLocalFile(QDir::currentPath()
+ // Use a tempdir with files, for testing specific file names
+ // We use canonicalPath() on the dir path because ::getcwd() canonicalizes,
+ // so we get a canonical base path for URLs with "." as working directory.
+ const QString base = QDir(m_tempDir.path()).canonicalPath();
+ QDir::setCurrent(base); // for the tests that use "." as working dir
+
+ // "."
+ {
+ const QUrl url = QUrl::fromLocalFile(base
#ifdef Q_OS_WINRT
+ QLatin1Char('/')
#endif
); // fromUserInput cleans the path
- }
- QTest::newRow(("file-" + QByteArray::number(c)).constData())
- << it.fileName() << QDir::currentPath() << url << url;
- QTest::newRow(("file-" + QByteArray::number(c) + "-dot").constData())
- << it.fileName() << QStringLiteral(".") << url << url;
- ++c;
+ QTest::newRow("dot-in-path") << "." << base << url << url;
+ QTest::newRow("dot-in-dot") << "." << QStringLiteral(".") << url << url;
+ }
+
+ // Existing files
+ for (const char *fileName : {"file.txt", "file#a.txt", "file .txt", "file.txt "}) {
+ const QString filePath = base + '/' + fileName;
+ QFile file(filePath);
+ QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(filePath));
+ file.write("Hello world\n");
+
+ const QUrl url = QUrl::fromLocalFile(filePath);
+ QTest::newRow(fileName) << fileName << base << url << url;
+ QTest::newRow(QByteArray(fileName) + "-in-dot") << fileName << QStringLiteral(".") << url << url;
}
+
#ifndef Q_OS_WINRT // WinRT cannot cd outside current / sandbox
- QDir parent = QDir::current();
+ QDir parent(base);
QVERIFY(parent.cdUp());
QUrl parentUrl = QUrl::fromLocalFile(parent.path());
- QTest::newRow("dotdot") << ".." << QDir::currentPath() << parentUrl << parentUrl;
+ QTest::newRow("dotdot") << ".." << base << parentUrl << parentUrl;
#endif
- QTest::newRow("nonexisting") << "nonexisting" << QDir::currentPath() << QUrl("http://nonexisting") << QUrl::fromLocalFile(QDir::currentPath() + "/nonexisting");
- QTest::newRow("short-url") << "example.org" << QDir::currentPath() << QUrl("http://example.org") << QUrl::fromLocalFile(QDir::currentPath() + "/example.org");
- QTest::newRow("full-url") << "http://example.org" << QDir::currentPath() << QUrl("http://example.org") << QUrl("http://example.org");
- QTest::newRow("absolute") << "/doesnotexist.txt" << QDir::currentPath() << QUrl("file:///doesnotexist.txt") << QUrl("file:///doesnotexist.txt");
+ QTest::newRow("nonexisting") << "nonexisting" << base << QUrl("http://nonexisting") << QUrl::fromLocalFile(base + "/nonexisting");
+ QTest::newRow("short-url") << "example.org" << base << QUrl("http://example.org") << QUrl::fromLocalFile(base + "/example.org");
+ QTest::newRow("full-url") << "http://example.org" << base << QUrl("http://example.org") << QUrl("http://example.org");
+ QTest::newRow("absolute") << "/doesnotexist.txt" << base << QUrl("file:///doesnotexist.txt") << QUrl("file:///doesnotexist.txt");
#ifdef Q_OS_WIN
- QTest::newRow("windows-absolute") << "c:/doesnotexist.txt" << QDir::currentPath() << QUrl("file:///c:/doesnotexist.txt") << QUrl("file:///c:/doesnotexist.txt");
+ QTest::newRow("windows-absolute") << "c:/doesnotexist.txt" << base << QUrl("file:///c:/doesnotexist.txt") << QUrl("file:///c:/doesnotexist.txt");
#endif
// IPv4 & IPv6
// same as fromUserInput, but needs retesting
- QTest::newRow("ipv4-1") << "127.0.0.1" << QDir::currentPath() << QUrl("http://127.0.0.1") << QUrl::fromLocalFile(QDir::currentPath() + "/127.0.0.1");
- QTest::newRow("ipv6-0") << "::" << QDir::currentPath() << QUrl("http://[::]") << QUrl("http://[::]");
- QTest::newRow("ipv6-1") << "::1" << QDir::currentPath() << QUrl("http://[::1]") << QUrl("http://[::1]");
- QTest::newRow("ipv6-2") << "1::1" << QDir::currentPath() << QUrl("http://[1::1]") << QUrl("http://[1::1]");
- QTest::newRow("ipv6-3") << "1::" << QDir::currentPath() << QUrl("http://[1::]") << QUrl("http://[1::]");
- QTest::newRow("ipv6-4") << "c::" << QDir::currentPath() << QUrl("http://[c::]") << QUrl("http://[c::]");
- QTest::newRow("ipv6-5") << "c:f00:ba4::" << QDir::currentPath() << QUrl("http://[c:f00:ba4::]") << QUrl("http://[c:f00:ba4::]");
+ QTest::newRow("ipv4-1") << "127.0.0.1" << base << QUrl("http://127.0.0.1") << QUrl::fromLocalFile(base + "/127.0.0.1");
+ QTest::newRow("ipv6-0") << "::" << base << QUrl("http://[::]") << QUrl("http://[::]");
+ QTest::newRow("ipv6-1") << "::1" << base << QUrl("http://[::1]") << QUrl("http://[::1]");
+ QTest::newRow("ipv6-2") << "1::1" << base << QUrl("http://[1::1]") << QUrl("http://[1::1]");
+ QTest::newRow("ipv6-3") << "1::" << base << QUrl("http://[1::]") << QUrl("http://[1::]");
+ QTest::newRow("ipv6-4") << "c::" << base << QUrl("http://[c::]") << QUrl("http://[c::]");
+ QTest::newRow("ipv6-5") << "c:f00:ba4::" << base << QUrl("http://[c:f00:ba4::]") << QUrl("http://[c:f00:ba4::]");
}
void tst_QUrl::fromUserInputWithCwd()
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
index 8058d3c897..2edb94d542 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
@@ -307,6 +307,7 @@ void tst_QMimeDatabase::mimeTypesForFileName_data()
QTest::newRow("txtfoobar, 0 hit") << "foo.foobar" << QStringList();
QTest::newRow("m, 2 hits") << "foo.m" << (QStringList() << "text/x-matlab" << "text/x-objcsrc");
QTest::newRow("sub, 3 hits") << "foo.sub" << (QStringList() << "text/x-microdvd" << "text/x-mpsub" << "text/x-subviewer");
+ QTest::newRow("non_ascii") << QString::fromUtf8("AİİA.pdf") << (QStringList() << "application/pdf");
}
void tst_QMimeDatabase::mimeTypesForFileName()
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.pro b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.pro
index 132f01092a..44ef12db29 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.pro
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin1/plugin1.pro
@@ -7,6 +7,8 @@ TARGET = $$qtLibraryTarget(plugin1)
DESTDIR = ../bin
winrt:include(../winrt.pri)
+!qtConfig(library): DEFINES += QT_STATICPLUGIN
+
# This is testdata for the tst_qpluginloader test.
target.path = $$[QT_INSTALL_TESTS]/tst_qfactoryloader/bin
INSTALLS += target
diff --git a/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.pro b/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.pro
index b47ed91535..5689919108 100644
--- a/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.pro
+++ b/tests/auto/corelib/plugin/qfactoryloader/plugin2/plugin2.pro
@@ -7,6 +7,8 @@ TARGET = $$qtLibraryTarget(plugin2)
DESTDIR = ../bin
winrt:include(../winrt.pri)
+!qtConfig(library): DEFINES += QT_STATICPLUGIN
+
# This is testdata for the tst_qpluginloader test.
target.path = $$[QT_INSTALL_TESTS]/tst_qfactoryloader/bin
INSTALLS += target
diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
index 0e189ba7aa..f88eac1a9f 100644
--- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp
+++ b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
@@ -1033,7 +1033,8 @@ void tst_QDate::fromStringFormat_data()
QTest::addColumn<QString>("format");
QTest::addColumn<QDate>("expected");
- //get localized names
+ // Undo this (inline the C-locale versions) for ### Qt 6
+ // Get localized names:
QString january = QDate::longMonthName(1);
QString february = QDate::longMonthName(2);
QString march = QDate::longMonthName(3);
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index b81f3d356d..5eec44dffd 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -31,6 +31,9 @@
#include <time.h>
#include <qdatetime.h>
#include <private/qdatetime_p.h>
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+# include <locale.h>
+#endif
#ifdef Q_OS_WIN
# include <qt_windows.h>
@@ -185,6 +188,14 @@ Q_DECLARE_METATYPE(Qt::DateFormat)
tst_QDateTime::tst_QDateTime()
{
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ // Some tests depend on C locale - BF&I it with belt *and* braces:
+ qputenv("LC_ALL", "C");
+ setlocale(LC_ALL, "C");
+ // Need to do this as early as possible, before anything accesses the
+ // QSystemLocale singleton; once it exists, there's no changing it.
+#endif // remove for ### Qt 6
+
/*
Due to some jurisdictions changing their zones and rules, it's possible
for a non-CET zone to accidentally match CET at a few tested moments but
@@ -2332,13 +2343,6 @@ void tst_QDateTime::fromStringStringFormat_data()
QTest::addColumn<QString>("format");
QTest::addColumn<QDateTime>("expected");
- QString january = QDate::longMonthName(1);
- QString oct = QDate::shortMonthName(10);
- QString december = QDate::longMonthName(12);
- QString thu = QDate::shortDayName(4);
- QString fri = QDate::shortDayName(5);
- QString date = "10 " + oct + " 10";
-
QTest::newRow("data0") << QString("101010") << QString("dMyy") << QDateTime(QDate(1910, 10, 10), QTime());
QTest::newRow("data1") << QString("1020") << QString("sss") << invalidDateTime();
QTest::newRow("data2") << QString("1010") << QString("sss") << QDateTime(defDate(), QTime(0, 0, 10));
@@ -2349,16 +2353,14 @@ void tst_QDateTime::fromStringStringFormat_data()
QTest::newRow("data7") << QString("foo") << QString("ap") << invalidDateTime();
// Day non-conflict should not hide earlier year conflict (1963-03-01 was a
// Friday; asking for Thursday moves this, without conflict, to the 7th):
- QTest::newRow("data8") << QString("77 03 1963 " + thu) << QString("yy MM yyyy ddd") << invalidDateTime();
+ QTest::newRow("data8") << QString("77 03 1963 Thu") << QString("yy MM yyyy ddd") << invalidDateTime();
QTest::newRow("data9") << QString("101010") << QString("dMyy") << QDateTime(QDate(1910, 10, 10), QTime());
QTest::newRow("data10") << QString("101010") << QString("dMyy") << QDateTime(QDate(1910, 10, 10), QTime());
- QTest::newRow("data11") << date << QString("dd MMM yy") << QDateTime(QDate(1910, 10, 10), QTime());
- date = fri + QLatin1Char(' ') + december + " 3 2004";
- QTest::newRow("data12") << date << QString("ddd MMMM d yyyy") << QDateTime(QDate(2004, 12, 3), QTime());
+ QTest::newRow("data11") << QString("10 Oct 10") << QString("dd MMM yy") << QDateTime(QDate(1910, 10, 10), QTime());
+ QTest::newRow("data12") << QString("Fri December 3 2004") << QString("ddd MMMM d yyyy") << QDateTime(QDate(2004, 12, 3), QTime());
QTest::newRow("data13") << QString("30.02.2004") << QString("dd.MM.yyyy") << invalidDateTime();
QTest::newRow("data14") << QString("32.01.2004") << QString("dd.MM.yyyy") << invalidDateTime();
- date = thu + QLatin1Char(' ') + january + " 2004";
- QTest::newRow("data15") << date << QString("ddd MMMM yyyy") << QDateTime(QDate(2004, 1, 1), QTime());
+ QTest::newRow("data15") << QString("Thu January 2004") << QString("ddd MMMM yyyy") << QDateTime(QDate(2004, 1, 1), QTime());
QTest::newRow("data16") << QString("2005-06-28T07:57:30.001Z")
<< QString("yyyy-MM-ddThh:mm:ss.zZ")
<< QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 1));
diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp
index 059e1e519b..71bf39fc4e 100644
--- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp
+++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp
@@ -28,10 +28,26 @@
#include <QtTest/QtTest>
#include "qdatetime.h"
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+# include <locale.h>
+#endif
class tst_QTime : public QObject
{
Q_OBJECT
+
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+public:
+ tst_QTime()
+ {
+ // Some tests depend on C locale - BF&I it with belt *and* braces:
+ qputenv("LC_ALL", "C");
+ setlocale(LC_ALL, "C");
+ // Need to instantiate as early as possible, before anything accesses
+ // the QSystemLocale singleton; once it exists, there's no changing it.
+ }
+#endif // remove for ### Qt 6
+
private slots:
void msecsTo_data();
void msecsTo();
diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp
index abb5b50229..c1f2822b74 100644
--- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp
@@ -346,6 +346,7 @@ void tst_QTimeZone::isTimeZoneIdAvailable()
foreach (const QByteArray &id, available)
QVERIFY(QTimeZone::isTimeZoneIdAvailable(id));
+#ifdef QT_BUILD_INTERNAL
// a-z, A-Z, 0-9, '.', '-', '_' are valid chars
// Can't start with '-'
// Parts separated by '/', each part min 1 and max of 14 chars
@@ -368,6 +369,7 @@ void tst_QTimeZone::isTimeZoneIdAvailable()
QCOMPARE(QTimeZonePrivate::isValidId("123456789012345"), false);
QCOMPARE(QTimeZonePrivate::isValidId("123456789012345/12345678901234"), false);
QCOMPARE(QTimeZonePrivate::isValidId("12345678901234/123456789012345"), false);
+#endif // QT_BUILD_INTERNAL
}
void tst_QTimeZone::transitionEachZone_data()
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
index 280305ddd8..3971353cbb 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -75,8 +75,21 @@ struct Foo
void tst_QVarLengthArray::append()
{
- QVarLengthArray<QString> v;
- v.append(QString("hello"));
+ QVarLengthArray<QString, 2> v;
+ v.append(QString("1"));
+ v.append(v.front());
+ QCOMPARE(v.capacity(), 2);
+ // transition from prealloc to heap:
+ v.append(v.front());
+ QVERIFY(v.capacity() > 2);
+ QCOMPARE(v.front(), v.back());
+ while (v.size() < v.capacity())
+ v.push_back(v[0]);
+ QCOMPARE(v.back(), v.front());
+ QCOMPARE(v.size(), v.capacity());
+ // transition from heap to larger heap:
+ v.push_back(v.front());
+ QCOMPARE(v.back(), v.front());
QVarLengthArray<int> v2; // rocket!
v2.append(5);