summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/codecs/utf8/tst_utf8.cpp36
-rw-r--r--tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp31
-rw-r--r--tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp7
-rw-r--r--tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp2
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp8
5 files changed, 57 insertions, 27 deletions
diff --git a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp
index b00fd0dfd4..d1aadab7d8 100644
--- a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp
+++ b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp
@@ -53,11 +53,7 @@ public:
// test data:
QTextCodec *codec;
QString (*from8BitPtr)(const char *, int);
-#ifdef Q_COMPILER_REF_QUALIFIERS
- QByteArray (QString:: *to8Bit)() const &;
-#else
- QByteArray (QString:: *to8Bit)() const;
-#endif
+ static QByteArray to8Bit(const QString &);
inline QString from8Bit(const QByteArray &ba)
{ return from8BitPtr(ba.constData(), ba.length()); }
@@ -97,14 +93,21 @@ void tst_Utf8::init()
if (useLocale) {
codec = QTextCodec::codecForLocale();
from8BitPtr = &QString::fromLocal8Bit;
- to8Bit = &QString::toLocal8Bit;
} else {
codec = QTextCodec::codecForMib(106);
from8BitPtr = &QString::fromUtf8;
- to8Bit = &QString::toUtf8;
}
}
+QByteArray tst_Utf8::to8Bit(const QString &s)
+{
+ QFETCH_GLOBAL(bool, useLocale);
+ if (useLocale)
+ return s.toLocal8Bit();
+ else
+ return s.toUtf8();
+}
+
void tst_Utf8::roundTrip_data()
{
QTest::addColumn<QByteArray>("utf8");
@@ -114,10 +117,10 @@ void tst_Utf8::roundTrip_data()
QTest::newRow("nul") << QByteArray("", 1) << QString(QChar(QChar::Null));
static const char ascii[] = "This is a standard US-ASCII message";
- QTest::newRow("ascii") << QByteArray(ascii) << ascii;
+ QTest::newRow("ascii") << QByteArray(ascii) << QString::fromLatin1(ascii);
static const char ascii2[] = "\1This\2is\3an\4US-ASCII\020 message interspersed with control chars";
- QTest::newRow("ascii2") << QByteArray(ascii2) << ascii2;
+ QTest::newRow("ascii2") << QByteArray(ascii2) << QString::fromLatin1(ascii2);
static const char utf8_1[] = "\302\240"; // NBSP
QTest::newRow("utf8_1") << QByteArray(utf8_1) << QString(QChar(QChar::Nbsp));
@@ -161,11 +164,20 @@ void tst_Utf8::roundTrip()
QFETCH(QByteArray, utf8);
QFETCH(QString, utf16);
- QCOMPARE((utf16.*to8Bit)(), utf8);
+ QCOMPARE(to8Bit(utf16), utf8);
+ QCOMPARE(from8Bit(utf8), utf16);
+
+ QCOMPARE(to8Bit(from8Bit(utf8)), utf8);
+ QCOMPARE(from8Bit(to8Bit(utf16)), utf16);
+
+ // repeat with a longer message
+ utf8.prepend("12345678901234");
+ utf16.prepend(QLatin1String("12345678901234"));
+ QCOMPARE(to8Bit(utf16), utf8);
QCOMPARE(from8Bit(utf8), utf16);
- QCOMPARE((from8Bit(utf8).*to8Bit)(), utf8);
- QCOMPARE(from8Bit((utf16.*to8Bit)()), utf16);
+ QCOMPARE(to8Bit(from8Bit(utf8)), utf8);
+ QCOMPARE(from8Bit(to8Bit(utf16)), utf16);
}
void tst_Utf8::charByChar_data()
diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
index a58c7dfb4b..4f7ddce9c3 100644
--- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
+++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -405,6 +405,13 @@ void tst_QFileSystemWatcher::removePaths()
watcher.removePaths(paths);
}
+static QByteArray msgFileOperationFailed(const char *what, const QFile &f)
+{
+ return what + QByteArrayLiteral(" failed on \"")
+ + QDir::toNativeSeparators(f.fileName()).toLocal8Bit()
+ + QByteArrayLiteral("\": ") + f.errorString().toLocal8Bit();
+}
+
void tst_QFileSystemWatcher::watchFileAndItsDirectory()
{
QFETCH(QString, backend);
@@ -420,14 +427,10 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory()
QString testFileName = testDir.filePath("testFile.txt");
QString secondFileName = testDir.filePath("testFile2.txt");
- QFile::remove(secondFileName);
QFile testFile(testFileName);
- testFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
- testFile.remove();
-
- QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Truncate));
- testFile.write(QByteArray("hello"));
+ QVERIFY2(testFile.open(QIODevice::WriteOnly | QIODevice::Truncate), msgFileOperationFailed("open", testFile));
+ QVERIFY2(testFile.write(QByteArrayLiteral("hello")) > 0, msgFileOperationFailed("write", testFile));
testFile.close();
QFileSystemWatcher watcher;
@@ -449,8 +452,8 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory()
// wait before modifying the directory...
QTest::qWait(2000);
- QVERIFY(testFile.open(QIODevice::WriteOnly | QIODevice::Truncate));
- testFile.write(QByteArray("hello again"));
+ QVERIFY2(testFile.open(QIODevice::WriteOnly | QIODevice::Truncate), msgFileOperationFailed("open", testFile));
+ QVERIFY2(testFile.write(QByteArrayLiteral("hello again")), msgFileOperationFailed("write", testFile));
testFile.close();
#ifdef Q_OS_MAC
@@ -472,8 +475,8 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory()
fileChangedSpy.clear();
dirChangedSpy.clear();
QFile secondFile(secondFileName);
- secondFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
- secondFile.write("Foo");
+ QVERIFY2(secondFile.open(QIODevice::WriteOnly | QIODevice::Truncate), msgFileOperationFailed("open", secondFile));
+ QVERIFY2(secondFile.write(QByteArrayLiteral("Foo")) > 0, msgFileOperationFailed("write", secondFile));
secondFile.close();
timer.start(3000);
@@ -491,17 +494,17 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory()
dirChangedSpy.clear();
- QFile::remove(testFileName);
+ QVERIFY(QFile::remove(testFileName));
QTRY_VERIFY(fileChangedSpy.count() > 0);
- QCOMPARE(dirChangedSpy.count(), 1);
+ QTRY_COMPARE(dirChangedSpy.count(), 1);
fileChangedSpy.clear();
dirChangedSpy.clear();
// removing a deleted file should fail
QVERIFY(!watcher.removePath(testFileName));
- QFile::remove(secondFileName);
+ QVERIFY(QFile::remove(secondFileName));
timer.start(3000);
eventLoop.exec();
diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp
index c19e80bff3..2ae085cb0b 100644
--- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp
+++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp
@@ -247,6 +247,13 @@ private:
QString testFileName;
};
+void runOnExit()
+{
+ QByteArray buffer;
+ QTextStream(&buffer) << "This will try to use QTextCodec::codecForLocale" << endl;
+}
+Q_DESTRUCTOR_FUNCTION(runOnExit)
+
tst_QTextStream::tst_QTextStream()
: tempDir(QDir::tempPath() + "/tst_qtextstream.XXXXXX")
{
diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
index 6e183f3212..cdcbd19ae8 100644
--- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
@@ -1863,7 +1863,7 @@ void tst_QByteArray::reserve()
QCOMPARE(qba.capacity(), capacity);
QCOMPARE(copy.capacity(), capacity);
- copy = qba;
+ qba = copy;
qba.reserve(capacity * 2);
QCOMPARE(qba.size(), capacity);
QCOMPARE(qba.capacity(), capacity * 2);
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index bda5fc707a..8f9376f8b6 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -715,6 +715,10 @@ void tst_QDateTime::toString_isoDate_data()
QTest::newRow("negative OffsetFromUTC")
<< dt
<< QString("1978-11-09T13:28:34-02:00");
+ dt.setUtcOffset(-900);
+ QTest::newRow("negative non-integral OffsetFromUTC")
+ << dt
+ << QString("1978-11-09T13:28:34-00:15");
QTest::newRow("invalid")
<< QDateTime(QDate(-1, 11, 9), QTime(13, 28, 34), Qt::UTC)
<< QString();
@@ -1895,8 +1899,12 @@ void tst_QDateTime::fromStringDateFormat_data()
// Test Qt::ISODate format.
QTest::newRow("ISO +01:00") << QString::fromLatin1("1987-02-13T13:24:51+01:00")
<< Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
+ QTest::newRow("ISO +00:01") << QString::fromLatin1("1987-02-13T13:24:51+00:01")
+ << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(13, 23, 51), Qt::UTC);
QTest::newRow("ISO -01:00") << QString::fromLatin1("1987-02-13T13:24:51-01:00")
<< Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC);
+ QTest::newRow("ISO -00:01") << QString::fromLatin1("1987-02-13T13:24:51-00:01")
+ << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(13, 25, 51), Qt::UTC);
QTest::newRow("ISO +0000") << QString::fromLatin1("1970-01-01T00:12:34+0000")
<< Qt::ISODate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
QTest::newRow("ISO +00:00") << QString::fromLatin1("1970-01-01T00:12:34+00:00")