summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-10-15 21:05:08 +0200
committerOrgad Shaneh <orgad.shaneh@audiocodes.com>2017-10-16 22:21:52 +0300
commit01afc8c810201b93a12fe7030344e03566d99001 (patch)
tree27727b38370209dc158856b4bb4d32ccd2e49fbe /tests/auto/corelib
parenta090076e93487f8e461d9b866b9da1c0c21cb59b (diff)
parent49da5ce10034161017b261e000d4e9063d962401 (diff)
Merge remote-tracking branch 'origin/5.9' into 5.10
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp17
-rw-r--r--tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp64
2 files changed, 78 insertions, 3 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 7eeaea564f..400a89c03f 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -2058,6 +2058,14 @@ void tst_QUrl::isValid()
}
{
+ QUrl url("http:");
+ url.setPath("//example.com");
+ QVERIFY(!url.isValid());
+ QVERIFY(url.toString().isEmpty());
+ QVERIFY(url.errorString().contains("Path component starts with '//' and authority is absent"));
+ }
+
+ {
QUrl url;
url.setPath("http://example.com");
QVERIFY(!url.isValid());
@@ -3632,12 +3640,12 @@ void tst_QUrl::setComponents_data()
QTest::newRow("path-%3A-before-slash") << QUrl()
<< int(Path) << "c%3A/" << Tolerant << true
<< PrettyDecoded << "c%3A/" << "c%3A/";
- QTest::newRow("path-doubleslash") << QUrl("trash:/")
+ QTest::newRow("path-doubleslash") << QUrl("http://example.com")
<< int(Path) << "//path" << Tolerant << true
- << PrettyDecoded << "/path" << "trash:/path";
+ << PrettyDecoded << "//path" << "http://example.com//path";
QTest::newRow("path-withdotdot") << QUrl("file:///tmp")
<< int(Path) << "//tmp/..///root/." << Tolerant << true
- << PrettyDecoded << "/tmp/..///root/." << "file:///tmp/..///root/.";
+ << PrettyDecoded << "//tmp/..///root/." << "file:////tmp/..///root/.";
// the other fields can be present and be empty
// that is, their delimiters would be present, but there would be nothing to one side
@@ -3760,6 +3768,9 @@ void tst_QUrl::setComponents_data()
QTest::newRow("invalid-path-2") << QUrl("http://example.com")
<< int(Path) << "relative" << Strict << false
<< PrettyDecoded << "relative" << "";
+ QTest::newRow("invalid-path-3") << QUrl("trash:/")
+ << int(Path) << "//path" << Tolerant << false
+ << PrettyDecoded << "//path" << "";
// -- test bad percent encoding --
// unnecessary to test the scheme, since percent-decoding is not performed in it;
diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
index 782eed03e8..094c6ed0a5 100644
--- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
+++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
@@ -94,6 +94,7 @@ private slots:
void destroyingWaitsForTasksToFinish();
void stackSize();
void stressTest();
+ void takeAllAndIncreaseMaxThreadCount();
private:
QMutex m_functionTestMutex;
@@ -1203,5 +1204,68 @@ void tst_QThreadPool::stressTest()
}
}
+void tst_QThreadPool::takeAllAndIncreaseMaxThreadCount() {
+ class Task : public QRunnable
+ {
+ public:
+ Task(QSemaphore *mainBarrier, QSemaphore *threadBarrier)
+ : m_mainBarrier(mainBarrier)
+ , m_threadBarrier(threadBarrier)
+ {
+ setAutoDelete(false);
+ }
+
+ void run() {
+ m_mainBarrier->release();
+ m_threadBarrier->acquire();
+ }
+ private:
+ QSemaphore *m_mainBarrier;
+ QSemaphore *m_threadBarrier;
+ };
+
+ QSemaphore mainBarrier;
+ QSemaphore taskBarrier;
+
+ QThreadPool threadPool;
+ threadPool.setMaxThreadCount(1);
+
+ Task *task1 = new Task(&mainBarrier, &taskBarrier);
+ Task *task2 = new Task(&mainBarrier, &taskBarrier);
+ Task *task3 = new Task(&mainBarrier, &taskBarrier);
+
+ threadPool.start(task1);
+ threadPool.start(task2);
+ threadPool.start(task3);
+
+ mainBarrier.acquire(1);
+
+ QCOMPARE(threadPool.activeThreadCount(), 1);
+
+ QVERIFY(!threadPool.tryTake(task1));
+ QVERIFY(threadPool.tryTake(task2));
+ QVERIFY(threadPool.tryTake(task3));
+
+ // A bad queue implementation can segfault here because two consecutive items in the queue
+ // have been taken
+ threadPool.setMaxThreadCount(4);
+
+ // Even though we increase the max thread count, there should only be one job to run
+ QCOMPARE(threadPool.activeThreadCount(), 1);
+
+ // Make sure jobs 2 and 3 never started
+ QCOMPARE(mainBarrier.available(), 0);
+
+ taskBarrier.release(1);
+
+ threadPool.waitForDone();
+
+ QCOMPARE(threadPool.activeThreadCount(), 0);
+
+ delete task1;
+ delete task2;
+ delete task3;
+}
+
QTEST_MAIN(tst_QThreadPool);
#include "tst_qthreadpool.moc"