summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/qdebug/qdebug.pro2
-rw-r--r--tests/auto/corelib/io/qdebug/tst_qdebug.cpp40
-rw-r--r--tests/auto/corelib/io/qprocess/test/test.pro1
-rw-r--r--tests/auto/corelib/io/qprocess/tst_qprocess.cpp2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro2
-rw-r--r--tests/auto/corelib/tools/qcollator/tst_qcollator.cpp93
-rw-r--r--tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp7
7 files changed, 143 insertions, 4 deletions
diff --git a/tests/auto/corelib/io/qdebug/qdebug.pro b/tests/auto/corelib/io/qdebug/qdebug.pro
index 820c17fc69..5e902bb105 100644
--- a/tests/auto/corelib/io/qdebug/qdebug.pro
+++ b/tests/auto/corelib/io/qdebug/qdebug.pro
@@ -1,5 +1,5 @@
CONFIG += testcase parallel_test
TARGET = tst_qdebug
-QT = core testlib
+QT = core testlib concurrent
SOURCES = tst_qdebug.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
index 07e011f449..3f53ab5f0a 100644
--- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
+++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
@@ -44,6 +44,9 @@
#include <QtCore/QtDebug>
#include <QtTest/QtTest>
+#include <QtConcurrentRun>
+#include <QFutureSynchronizer>
+
class tst_QDebug: public QObject
{
Q_OBJECT
@@ -59,6 +62,7 @@ private slots:
void qDebugQLatin1String() const;
void textStreamModifiers() const;
void defaultMessagehandler() const;
+ void threadSafety() const;
};
void tst_QDebug::assignment() const
@@ -315,5 +319,41 @@ void tst_QDebug::defaultMessagehandler() const
QVERIFY(same);
}
+QMutex s_mutex;
+QStringList s_messages;
+QSemaphore s_sema;
+
+static void threadSafeMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
+{
+ QMutexLocker lock(&s_mutex);
+ s_messages.append(msg);
+ Q_UNUSED(type);
+ Q_UNUSED(context);
+}
+
+static void doDebug() // called in each thread
+{
+ s_sema.acquire();
+ qDebug() << "doDebug";
+}
+
+void tst_QDebug::threadSafety() const
+{
+ MessageHandlerSetter mhs(threadSafeMessageHandler);
+ const int numThreads = 10;
+ QThreadPool::globalInstance()->setMaxThreadCount(numThreads);
+ QFutureSynchronizer<void> sync;
+ for (int i = 0; i < numThreads; ++i) {
+ sync.addFuture(QtConcurrent::run(&doDebug));
+ }
+ s_sema.release(numThreads);
+ sync.waitForFinished();
+ QMutexLocker lock(&s_mutex);
+ QCOMPARE(s_messages.count(), numThreads);
+ for (int i = 0; i < numThreads; ++i) {
+ QCOMPARE(s_messages.at(i), QStringLiteral("doDebug"));
+ }
+}
+
QTEST_MAIN(tst_QDebug);
#include "tst_qdebug.moc"
diff --git a/tests/auto/corelib/io/qprocess/test/test.pro b/tests/auto/corelib/io/qprocess/test/test.pro
index 79ea53cc6b..90afeddaa0 100644
--- a/tests/auto/corelib/io/qprocess/test/test.pro
+++ b/tests/auto/corelib/io/qprocess/test/test.pro
@@ -2,7 +2,6 @@ CONFIG += testcase
CONFIG += parallel_test
CONFIG -= app_bundle debug_and_release_target
QT = core testlib network
-embedded: QT += gui
SOURCES = ../tst_qprocess.cpp
TARGET = ../tst_qprocess
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
index 67cf954f98..1d6418cbc0 100644
--- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
+++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
@@ -1953,7 +1953,7 @@ void tst_QProcess::setStandardOutputFile2()
process.start("testProcessEcho2/testProcessEcho2");
process.write(testdata, sizeof testdata);
QPROCESS_VERIFY(process,waitForFinished());
- QVERIFY(!process.bytesAvailable());
+ QCOMPARE(process.bytesAvailable(), Q_INT64_C(0));
QVERIFY(!QFileInfo(QProcess::nullDevice()).isFile());
}
diff --git a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro
index 8d117793bf..f5d06b3de9 100644
--- a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro
+++ b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro
@@ -4,7 +4,7 @@ CONFIG += ordered
SUBDIRS = lib \
theplugin \
tst
-!win32: !mac: SUBDIRS += almostplugin
+!android: !win32: !mac: SUBDIRS += almostplugin
macx-*: SUBDIRS += machtest
TARGET = tst_qpluginloader
diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
index 3df8422a34..3a00ebd505 100644
--- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
+++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
@@ -52,6 +52,9 @@ class tst_QCollator : public QObject
private Q_SLOTS:
void moveSemantics();
+
+ void compare_data();
+ void compare();
};
#ifdef Q_COMPILER_RVALUE_REFS
@@ -87,6 +90,96 @@ void tst_QCollator::moveSemantics()
#endif
}
+
+void tst_QCollator::compare_data()
+{
+ QTest::addColumn<QString>("locale");
+ QTest::addColumn<QString>("s1");
+ QTest::addColumn<QString>("s2");
+ QTest::addColumn<int>("result");
+ QTest::addColumn<int>("caseInsensitiveResult");
+
+ /*
+ A few tests below are commented out on the mac. It's unclear why they fail,
+ as it looks like the collator for the locale is created correctly.
+ */
+
+ /*
+ It's hard to test English, because it's treated differently
+ on different platforms. For example, on Linux, it uses the
+ iso14651_t1 template file, which happens to provide good
+ defaults for Swedish. Mac OS X seems to do a pure bytewise
+ comparison of Latin-1 values, although I'm not sure. So I
+ just test digits to make sure that it's not totally broken.
+ */
+ QTest::newRow("english1") << QString("en_US") << QString("5") << QString("4") << 1 << 1;
+ QTest::newRow("english2") << QString("en_US") << QString("4") << QString("6") << -1 << -1;
+ QTest::newRow("english3") << QString("en_US") << QString("5") << QString("6") << -1 << -1;
+ QTest::newRow("english4") << QString("en_US") << QString("a") << QString("b") << -1 << -1;
+ /*
+ In Swedish, a with ring above (E5) comes before a with
+ diaresis (E4), which comes before o diaresis (F6), which
+ all come after z.
+ */
+#if !defined(Q_OS_WIN) || defined(QT_USE_ICU)
+ QTest::newRow("swedish1") << QString("sv_SE") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << -1 << -1;
+#endif
+ QTest::newRow("swedish2") << QString("sv_SE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1 << -1;
+ QTest::newRow("swedish3") << QString("sv_SE") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1 << -1;
+#if !defined(Q_OS_OSX) && (!defined(Q_OS_WIN) || defined(QT_USE_ICU))
+ QTest::newRow("swedish4") << QString("sv_SE") << QString::fromLatin1("z") << QString::fromLatin1("\xe5") << -1 << -1;
+#endif
+
+ /*
+ In Norwegian, ae (E6) comes before o with stroke (D8), which
+ comes before a with ring above (E5).
+ */
+ QTest::newRow("norwegian1") << QString("no_NO") << QString::fromLatin1("\xe6") << QString::fromLatin1("\xd8") << -1 << -1;
+#if !defined(Q_OS_WIN) || defined(QT_USE_ICU)
+# ifndef Q_OS_OSX
+ QTest::newRow("norwegian2") << QString("no_NO") << QString::fromLatin1("\xd8") << QString::fromLatin1("\xe5") << -1 << -1;
+# endif
+ QTest::newRow("norwegian3") << QString("no_NO") << QString::fromLatin1("\xe6") << QString::fromLatin1("\xe5") << -1 << -1;
+#endif // !Q_OS_WIN || QT_USE_ICU
+ /*
+ In German, z comes *after* a with diaresis (E4),
+ which comes before o diaresis (F6).
+ */
+ QTest::newRow("german1") << QString("de_DE") << QString::fromLatin1("a") << QString::fromLatin1("\xe4") << -1 << -1;
+ QTest::newRow("german2") << QString("de_DE") << QString::fromLatin1("b") << QString::fromLatin1("\xe4") << 1 << 1;
+ QTest::newRow("german3") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xe4") << 1 << 1;
+ QTest::newRow("german4") << QString("de_DE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1 << -1;
+ QTest::newRow("german5") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1 << 1;
+ QTest::newRow("german6") << QString("de_DE") << QString::fromLatin1("\xc0") << QString::fromLatin1("\xe0") << 1 << 0;
+ QTest::newRow("german7") << QString("de_DE") << QString::fromLatin1("\xd6") << QString::fromLatin1("\xf6") << 1 << 0;
+ QTest::newRow("german8") << QString("de_DE") << QString::fromLatin1("oe") << QString::fromLatin1("\xf6") << 1 << 1;
+ QTest::newRow("german9") << QString("de_DE") << QString("A") << QString("a") << 1 << 0;
+
+ /*
+ French sorting of e and e with accent
+ */
+ QTest::newRow("french1") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("e") << 1 << 1;
+ QTest::newRow("french2") << QString("fr_FR") << QString::fromLatin1("\xe9t") << QString::fromLatin1("et") << 1 << 1;
+ QTest::newRow("french3") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("d") << 1 << 1;
+ QTest::newRow("french4") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("f") << -1 << -1;
+
+}
+
+
+void tst_QCollator::compare()
+{
+ QFETCH(QString, locale);
+ QFETCH(QString, s1);
+ QFETCH(QString, s2);
+ QFETCH(int, result);
+ QFETCH(int, caseInsensitiveResult);
+
+ QCollator collator(locale);
+ QCOMPARE(collator.compare(s1, s2), result);
+ collator.setCaseSensitivity(Qt::CaseInsensitive);
+ QCOMPARE(collator.compare(s1, s2), caseInsensitiveResult);
+}
+
QTEST_APPLESS_MAIN(tst_QCollator)
#include "tst_qcollator.moc"
diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
index 6780493206..285cc3042a 100644
--- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
+++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
@@ -111,6 +111,13 @@ void tst_QRingBuffer::readPointerAtPositionWithHead()
buf2 = ringBuffer.readPointerAtPosition(0, length);
QCOMPARE(length, qint64(0));
QVERIFY(buf2 == 0);
+
+ // check buffer with 2 blocks
+ memcpy(ringBuffer.reserve(4), "0123", 4);
+ ringBuffer.append(QByteArray("45678", 5));
+ ringBuffer.free(3);
+ buf2 = ringBuffer.readPointerAtPosition(1, length);
+ QCOMPARE(length, qint64(5));
}
void tst_QRingBuffer::readPointerAtPositionEmptyRead()