summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp56
-rw-r--r--tests/auto/corelib/io/qdir/tst_qdir.cpp4
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp12
-rw-r--r--tests/auto/corelib/kernel/kernel.pro3
-rw-r--r--tests/auto/corelib/thread/qmutex/tst_qmutex.cpp3
-rw-r--r--tests/auto/corelib/tools/qmacautoreleasepool/qmacautoreleasepool.pro4
-rw-r--r--tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm111
-rw-r--r--tests/auto/corelib/tools/qstringview/tst_qstringview.cpp44
-rw-r--r--tests/auto/corelib/tools/tools.pro1
9 files changed, 204 insertions, 34 deletions
diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
index 71c6c4e9cd..bf43f6d710 100644
--- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
+++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
@@ -73,37 +73,37 @@ public slots:
void cleanup() { setRNGControl(0); }
private slots:
- void get32_data();
- void get32();
- void get64_data() { get32_data(); }
- void get64();
- void quality_data() { get32_data(); }
+ void generate32_data();
+ void generate32();
+ void generate64_data() { generate32_data(); }
+ void generate64();
+ void quality_data() { generate32_data(); }
void quality();
- void fillRangeUInt_data() { get32_data(); }
+ void fillRangeUInt_data() { generate32_data(); }
void fillRangeUInt();
- void fillRangeULong_data() { get32_data(); }
+ void fillRangeULong_data() { generate32_data(); }
void fillRangeULong();
- void fillRangeULLong_data() { get32_data(); }
+ void fillRangeULLong_data() { generate32_data(); }
void fillRangeULLong();
- void generateUInt_data() { get32_data(); }
+ void generateUInt_data() { generate32_data(); }
void generateUInt();
- void generateULLong_data() { get32_data(); }
+ void generateULLong_data() { generate32_data(); }
void generateULLong();
- void generateNonContiguous_data() { get32_data(); }
+ void generateNonContiguous_data() { generate32_data(); }
void generateNonContiguous();
void bounded_data();
void bounded();
- void boundedQuality_data() { get32_data(); }
+ void boundedQuality_data() { generate32_data(); }
void boundedQuality();
- void getReal_data() { get32_data(); }
- void getReal();
+ void generateReal_data() { generate32_data(); }
+ void generateReal();
void seedStdRandomEngines();
void stdUniformIntDistribution_data();
void stdUniformIntDistribution();
- void stdGenerateCanonical_data() { getReal_data(); }
+ void stdGenerateCanonical_data() { generateReal_data(); }
void stdGenerateCanonical();
void stdUniformRealDistribution_data();
void stdUniformRealDistribution();
@@ -114,7 +114,7 @@ using namespace std;
QT_WARNING_DISABLE_GCC("-Wfloat-equal")
QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
-void tst_QRandomGenerator::get32_data()
+void tst_QRandomGenerator::generate32_data()
{
QTest::addColumn<uint>("control");
QTest::newRow("default") << 0U;
@@ -127,42 +127,42 @@ void tst_QRandomGenerator::get32_data()
#endif
}
-void tst_QRandomGenerator::get32()
+void tst_QRandomGenerator::generate32()
{
QFETCH(uint, control);
setRNGControl(control);
for (int i = 0; i < 4; ++i) {
QVERIFY_3TIMES([] {
- quint32 value = QRandomGenerator::get32();
+ quint32 value = QRandomGenerator::generate();
return value != 0 && value != RandomValue32;
}());
}
// and should hopefully be different from repeated calls
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::get32() != QRandomGenerator::get32());
+ QVERIFY_3TIMES(QRandomGenerator::generate() != QRandomGenerator::generate());
}
-void tst_QRandomGenerator::get64()
+void tst_QRandomGenerator::generate64()
{
QFETCH(uint, control);
setRNGControl(control);
for (int i = 0; i < 4; ++i) {
QVERIFY_3TIMES([] {
- quint64 value = QRandomGenerator::get32();
+ quint64 value = QRandomGenerator::generate();
return value != 0 && value != RandomValue32 && value != RandomValue64;
}());
}
// and should hopefully be different from repeated calls
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::get64() != QRandomGenerator::get64());
+ QVERIFY_3TIMES(QRandomGenerator::generate64() != QRandomGenerator::generate64());
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::get32() != quint32(QRandomGenerator::get64()));
+ QVERIFY_3TIMES(QRandomGenerator::generate() != quint32(QRandomGenerator::generate64()));
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::get32() != (QRandomGenerator::get64() >> 32));
+ QVERIFY_3TIMES(QRandomGenerator::generate() != (QRandomGenerator::generate64() >> 32));
}
void tst_QRandomGenerator::quality()
@@ -200,7 +200,7 @@ void tst_QRandomGenerator::quality()
// test the quality of the generator
quint32 buffer[BufferCount];
memset(buffer, 0xcc, sizeof(buffer));
- generate_n(buffer, +BufferCount, [] { return QRandomGenerator::get32(); });
+ generate_n(buffer, +BufferCount, [] { return QRandomGenerator::generate(); });
quint8 *ptr = reinterpret_cast<quint8 *>(buffer);
quint8 *end = ptr + sizeof(buffer);
@@ -439,21 +439,21 @@ void tst_QRandomGenerator::boundedQuality()
<< "at" << std::min_element(begin(histogram), end(histogram)) - histogram;
}
-void tst_QRandomGenerator::getReal()
+void tst_QRandomGenerator::generateReal()
{
QFETCH(uint, control);
setRNGControl(control);
for (int i = 0; i < 4; ++i) {
QVERIFY_3TIMES([] {
- qreal value = QRandomGenerator::getReal();
+ qreal value = QRandomGenerator::generateDouble();
return value > 0 && value < 1 && value != RandomValueFP;
}());
}
// and should hopefully be different from repeated calls
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::getReal() != QRandomGenerator::getReal());
+ QVERIFY_3TIMES(QRandomGenerator::generateDouble() != QRandomGenerator::generateDouble());
}
template <typename Engine> void seedStdRandomEngine()
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp
index e6bad9a8ef..8dbac28183 100644
--- a/tests/auto/corelib/io/qdir/tst_qdir.cpp
+++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp
@@ -394,7 +394,7 @@ void tst_QDir::mkdirRmdir()
void tst_QDir::mkdirOnSymlink()
{
-#ifndef Q_OS_UNIX
+#if !defined(Q_OS_UNIX) || defined(Q_NO_SYMLINKS)
QSKIP("Test only valid on an OS that supports symlinks");
#else
// Create the structure:
@@ -1662,9 +1662,7 @@ void tst_QDir::homePath()
QVERIFY(!strHome.endsWith('/'));
QByteArray envHome = qgetenv("HOME");
-#if !defined(_WRS_KERNEL) // unsetenv is not available on VxWorks DKM mode
unsetenv("HOME");
-#endif
QCOMPARE(QDir::homePath(), QDir::rootPath());
qputenv("HOME", envHome);
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index a7dc869805..8945daff4a 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -1491,21 +1491,27 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data()
QVERIFY2(file.exists(), msgDoesNotExist(file.fileName()).constData());
QTest::newRow("absolute dir symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalPath();
- QTest::newRow("relative dir symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalPath();
+ QTest::newRow("relative dir symlink") << relSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalPath();
QTest::newRow("file in symlink dir") << fileInSymlink << false << "" << target.canonicalPath().append("/file");
}
{
//File symlinks
+ pwd.mkdir("relative");
+ QDir relativeDir("relative");
QFileInfo target(m_sourceFile);
QString absTarget = QDir::toNativeSeparators(target.absoluteFilePath());
QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink.cpp");
QString relTarget = QDir::toNativeSeparators(pwd.relativeFilePath(target.absoluteFilePath()));
QString relSymlink = "rel_symlink.cpp";
+ QString relToRelTarget = QDir::toNativeSeparators(relativeDir.relativeFilePath(target.absoluteFilePath()));
+ QString relToRelSymlink = "relative/rel_symlink";
QVERIFY(pwd.exists("abs_symlink.cpp") || createSymbolicLinkW((wchar_t*)absSymlink.utf16(),(wchar_t*)absTarget.utf16(),0x0));
QVERIFY(pwd.exists(relSymlink) || createSymbolicLinkW((wchar_t*)relSymlink.utf16(),(wchar_t*)relTarget.utf16(),0x0));
-
+ QVERIFY(pwd.exists(relToRelSymlink)
+ || createSymbolicLinkW((wchar_t*)relToRelSymlink.utf16(), (wchar_t*)relToRelTarget.utf16(),0x0));
QTest::newRow("absolute file symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalFilePath();
- QTest::newRow("relative file symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalFilePath();
+ QTest::newRow("relative file symlink") << relSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalFilePath();
+ QTest::newRow("relative to relative file symlink") << relToRelSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalFilePath();
}
//Junctions
diff --git a/tests/auto/corelib/kernel/kernel.pro b/tests/auto/corelib/kernel/kernel.pro
index 75b98bcd09..b5b64973d3 100644
--- a/tests/auto/corelib/kernel/kernel.pro
+++ b/tests/auto/corelib/kernel/kernel.pro
@@ -41,3 +41,6 @@ SUBDIRS=\
!win32*|winrt: SUBDIRS -= qwineventnotifier
android|uikit: SUBDIRS -= qclipboard qobject qsharedmemory qsystemsemaphore
+
+!qtConfig(systemsemaphore): SUBDIRS -= \
+ qsystemsemaphore
diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp
index 0962001741..7fb9a861d7 100644
--- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp
+++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp
@@ -99,6 +99,9 @@ void tst_QMutex::convertToMilliseconds_data()
QTest::addColumn<qint64>("intValue");
QTest::addColumn<qint64>("expected");
+#if !QT_HAS_INCLUDE(<chrono>)
+ QSKIP("This test requires <chrono>");
+#endif
auto add = [](TimeUnit unit, double d, long long i, qint64 expected) {
const QScopedArrayPointer<char> enumName(QTest::toString(unit));
diff --git a/tests/auto/corelib/tools/qmacautoreleasepool/qmacautoreleasepool.pro b/tests/auto/corelib/tools/qmacautoreleasepool/qmacautoreleasepool.pro
new file mode 100644
index 0000000000..26b3a47472
--- /dev/null
+++ b/tests/auto/corelib/tools/qmacautoreleasepool/qmacautoreleasepool.pro
@@ -0,0 +1,4 @@
+CONFIG += testcase
+TARGET = tst_qmacautoreleasepool
+QT = core testlib
+SOURCES = tst_qmacautoreleasepool.mm
diff --git a/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm b/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm
new file mode 100644
index 0000000000..8f1069f419
--- /dev/null
+++ b/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <Foundation/Foundation.h>
+
+class tst_QMacAutoreleasePool : public QObject
+{
+ Q_OBJECT
+private slots:
+ void noPool();
+ void rootLevelPool();
+ void stackAllocatedPool();
+ void heapAllocatedPool();
+};
+
+static id lastDeallocedObject = nil;
+
+@interface DeallocTracker : NSObject @end
+@implementation DeallocTracker
+-(void)dealloc
+{
+ lastDeallocedObject = self;
+ [super dealloc];
+}
+@end
+
+void tst_QMacAutoreleasePool::noPool()
+{
+ // No pool, will not be released, but should not crash
+
+ [[[DeallocTracker alloc] init] autorelease];
+}
+
+void tst_QMacAutoreleasePool::rootLevelPool()
+{
+ // The root level case, no NSAutoreleasePool since we're not in the main
+ // runloop, and objects autoreleased as part of main.
+
+ NSObject *allocedObject = nil;
+ {
+ QMacAutoReleasePool qtPool;
+ allocedObject = [[[DeallocTracker alloc] init] autorelease];
+ }
+ QCOMPARE(lastDeallocedObject, allocedObject);
+}
+
+void tst_QMacAutoreleasePool::stackAllocatedPool()
+{
+ // The normal case, other pools surrounding our pool, draining
+ // our pool before any other pool.
+
+ NSObject *allocedObject = nil;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ {
+ QMacAutoReleasePool qtPool;
+ allocedObject = [[[DeallocTracker alloc] init] autorelease];
+ }
+ QCOMPARE(lastDeallocedObject, allocedObject);
+ [pool drain];
+}
+
+void tst_QMacAutoreleasePool::heapAllocatedPool()
+{
+ // The special case, a pool allocated on the heap, or as a member of a
+ // heap allocated object. This is not a supported use of QMacAutoReleasePool,
+ // and will result in warnings if the pool is prematurely drained.
+
+ NSObject *allocedObject = nil;
+ {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ QMacAutoReleasePool *qtPool = nullptr;
+ {
+ qtPool = new QMacAutoReleasePool;
+ allocedObject = [[[DeallocTracker alloc] init] autorelease];
+ }
+ [pool drain];
+ delete qtPool;
+ }
+ QCOMPARE(lastDeallocedObject, allocedObject);
+}
+
+QTEST_APPLESS_MAIN(tst_QMacAutoreleasePool)
+
+#include "tst_qmacautoreleasepool.moc"
diff --git a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp
index 9617afb651..48ea5a794c 100644
--- a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp
+++ b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp
@@ -136,6 +136,7 @@ class tst_QStringView : public QObject
private Q_SLOTS:
void constExpr() const;
void basics() const;
+ void literals() const;
void at() const;
void fromQString() const;
@@ -305,6 +306,12 @@ void tst_QStringView::constExpr() const
Q_STATIC_ASSERT(!sv2.isNull());
Q_STATIC_ASSERT(!sv2.empty());
Q_STATIC_ASSERT(sv2.size() == 5);
+
+ constexpr char16_t *null = nullptr;
+ constexpr QStringView sv3(null);
+ Q_STATIC_ASSERT(sv3.isNull());
+ Q_STATIC_ASSERT(sv3.isEmpty());
+ Q_STATIC_ASSERT(sv3.size() == 0);
}
#else // storage_type is wchar_t
{
@@ -328,6 +335,12 @@ void tst_QStringView::constExpr() const
Q_STATIC_ASSERT(!sv2.isNull());
Q_STATIC_ASSERT(!sv2.empty());
Q_STATIC_ASSERT(sv2.size() == 5);
+
+ constexpr wchar_t *null = nullptr;
+ constexpr QStringView sv3(null);
+ Q_STATIC_ASSERT(sv3.isNull());
+ Q_STATIC_ASSERT(sv3.isEmpty());
+ Q_STATIC_ASSERT(sv3.size() == 0);
}
#endif
#endif
@@ -348,6 +361,37 @@ void tst_QStringView::basics() const
QVERIFY(!(sv2 != sv1));
}
+void tst_QStringView::literals() const
+{
+#if !defined(Q_OS_WIN) || defined(Q_COMPILER_UNICODE_STRINGS)
+ // the + ensures it's a pointer, not an array
+ QCOMPARE(QStringView(+u"Hello").size(), 5);
+ QStringView sv = u"Hello";
+#else // storage_type is wchar_t
+ // the + ensures it's a pointer, not an array
+ QCOMPARE(QStringView(+L"Hello").size(), 5);
+ QStringView sv = L"Hello";
+#endif
+ QCOMPARE(sv.size(), 5);
+ QVERIFY(!sv.empty());
+ QVERIFY(!sv.isEmpty());
+ QVERIFY(!sv.isNull());
+ QCOMPARE(*sv.utf16(), 'H');
+ QCOMPARE(sv[0], QLatin1Char('H'));
+ QCOMPARE(sv.at(0), QLatin1Char('H'));
+ QCOMPARE(sv.front(), QLatin1Char('H'));
+ QCOMPARE(sv.first(), QLatin1Char('H'));
+ QCOMPARE(sv[4], QLatin1Char('o'));
+ QCOMPARE(sv.at(4), QLatin1Char('o'));
+ QCOMPARE(sv.back(), QLatin1Char('o'));
+ QCOMPARE(sv.last(), QLatin1Char('o'));
+
+ QStringView sv2(sv.utf16(), sv.utf16() + sv.size());
+ QVERIFY(!sv2.isNull());
+ QVERIFY(!sv2.empty());
+ QCOMPARE(sv2.size(), 5);
+}
+
void tst_QStringView::at() const
{
QString hello("Hello");
diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro
index 6720307d59..f35ed026ac 100644
--- a/tests/auto/corelib/tools/tools.pro
+++ b/tests/auto/corelib/tools/tools.pro
@@ -67,3 +67,4 @@ SUBDIRS=\
qvector_strictiterators \
qversionnumber
+darwin: SUBDIRS += qmacautoreleasepool