summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/plugin/quuid/tst_quuid.cpp')
-rw-r--r--tests/auto/corelib/plugin/quuid/tst_quuid.cpp133
1 files changed, 95 insertions, 38 deletions
diff --git a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
index 6ebf4a7c33..c5ce490b61 100644
--- a/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
+++ b/tests/auto/corelib/plugin/quuid/tst_quuid.cpp
@@ -1,33 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
+#if QT_CONFIG(process)
+#include <QProcess>
+#endif
#include <qcoreapplication.h>
#include <quuid.h>
@@ -47,6 +25,8 @@ private slots:
void fromByteArray();
void toRfc4122();
void fromRfc4122();
+ void id128();
+ void uint128();
void createUuidV3OrV5();
void check_QDataStream();
void isNull();
@@ -120,7 +100,7 @@ void tst_QUuid::fromChar()
QCOMPARE(QUuid(), QUuid("fc69b59e-cc34-"));
QCOMPARE(QUuid(), QUuid("fc69b59e-cc34"));
QCOMPARE(QUuid(), QUuid("cc34"));
- QCOMPARE(QUuid(), QUuid(NULL));
+ QCOMPARE(QUuid(), QUuid(nullptr));
QCOMPARE(uuidB, QUuid(QString("{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b}")));
}
@@ -157,7 +137,7 @@ void tst_QUuid::fromString_data()
ROW(uuidA, "{fc69b59e-cc34-4436-a43c-ee95d128b8c56"); // too long (not an error!)
ROW(invalid, "{fc69b59e-cc34-4436-a43c-ee95d128b8c" ); // premature end (within length limits)
ROW(invalid, " fc69b59e-cc34-4436-a43c-ee95d128b8c5}"); // leading space
- ROW(uuidA, "{fc69b59e-cc34-4436-a43c-ee95d128b8c5 "); // trailing space (not an error!)
+ ROW(uuidB, "{1ab6e93a-b1cb-4a87-ba47-ec7e99039a7b "); // trailing space (not an error!)
ROW(invalid, "{gc69b59e-cc34-4436-a43c-ee95d128b8c5}"); // non-hex digit in 1st group
ROW(invalid, "{fc69b59e-cp34-4436-a43c-ee95d128b8c5}"); // non-hex digit in 2nd group
ROW(invalid, "{fc69b59e-cc34-44r6-a43c-ee95d128b8c5}"); // non-hex digit in 3rd group
@@ -192,6 +172,11 @@ void tst_QUuid::fromString()
const auto longerInputL1 = inputL1 + '5'; // the '5' makes the premature end check incorrectly succeed
const auto inputL1S = QLatin1String(longerInputL1.data(), inputL1.size());
QCOMPARE(expected, QUuid::fromString(inputL1S));
+
+ // for QUtf8StringView, too:
+ const auto longerInputU8 = inputU8 + '5'; // the '5' makes the premature end check incorrectly succeed
+ const auto inputU8S = QUtf8StringView(longerInputU8.data(), inputU8.size());
+ QCOMPARE(expected, QUuid::fromString(inputU8S));
}
void tst_QUuid::toByteArray()
@@ -234,6 +219,78 @@ void tst_QUuid::fromRfc4122()
QCOMPARE(uuidB, QUuid::fromRfc4122(QByteArray::fromHex("1ab6e93ab1cb4a87ba47ec7e99039a7b")));
}
+void tst_QUuid::id128()
+{
+ constexpr QUuid::Id128Bytes bytesA = { {
+ 0xfc, 0x69, 0xb5, 0x9e,
+ 0xcc, 0x34,
+ 0x44, 0x36,
+ 0xa4, 0x3c, 0xee, 0x95, 0xd1, 0x28, 0xb8, 0xc5,
+ } };
+ constexpr QUuid::Id128Bytes bytesB = { {
+ 0x1a, 0xb6, 0xe9, 0x3a,
+ 0xb1, 0xcb,
+ 0x4a, 0x87,
+ 0xba, 0x47, 0xec, 0x7e, 0x99, 0x03, 0x9a, 0x7b,
+ } };
+
+ QCOMPARE(QUuid(bytesA), uuidA);
+ QCOMPARE(QUuid(bytesB), uuidB);
+ QVERIFY(memcmp(uuidA.toBytes().data, bytesA.data, sizeof(QUuid::Id128Bytes)) == 0);
+ QVERIFY(memcmp(uuidB.toBytes().data, bytesB.data, sizeof(QUuid::Id128Bytes)) == 0);
+
+ QUuid::Id128Bytes leBytesA = {};
+ for (int i = 0; i < 16; i++)
+ leBytesA.data[15 - i] = bytesA.data[i];
+ QCOMPARE(QUuid(leBytesA, QSysInfo::LittleEndian), uuidA);
+ QVERIFY(memcmp(uuidA.toBytes(QSysInfo::LittleEndian).data, leBytesA.data, sizeof(leBytesA)) == 0);
+
+ // check the new q{To,From}{Big,Little}Endian() overloads
+ QUuid::Id128Bytes roundtrip = qFromLittleEndian(qToLittleEndian(bytesA));
+ QVERIFY(memcmp(roundtrip.data, bytesA.data, sizeof(bytesA)) == 0);
+ roundtrip = qFromBigEndian(qToBigEndian(bytesA));
+ QVERIFY(memcmp(roundtrip.data, bytesA.data, sizeof(bytesA)) == 0);
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ const QUuid::Id128Bytes beBytesA = qToBigEndian(leBytesA);
+ QVERIFY(memcmp(beBytesA.data, bytesA.data, sizeof(beBytesA)) == 0);
+ const QUuid::Id128Bytes otherLeBytesA = qFromBigEndian(bytesA);
+ QVERIFY(memcmp(otherLeBytesA.data, leBytesA.data, sizeof(leBytesA)) == 0);
+#else // Q_BIG_ENDIAN
+ const QUuid::Id128Bytes otherLeBytesA = qToLittleEndian(bytesA);
+ QVERIFY(memcmp(otherLeBytesA.data, leBytesA.data, sizeof(leBytesA)) == 0);
+ const QUuid::Id128Bytes beBytesA = qFromLittleEndian(leBytesA);
+ QVERIFY(memcmp(beBytesA.data, bytesA.data, sizeof(beBytesA)) == 0);
+#endif // Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+}
+
+void tst_QUuid::uint128()
+{
+#ifdef QT_SUPPORTS_INT128
+ constexpr quint128 u = Q_UINT128_C(0xfc69b59e'cc344436'a43cee95'd128b8c5); // This is LE
+ constexpr quint128 be = qToBigEndian(u);
+ constexpr QUuid uuid = QUuid::fromUInt128(be);
+ static_assert(uuid.toUInt128() == be, "Round-trip through QUuid failed");
+
+ QCOMPARE(uuid, uuidA);
+ QCOMPARE(uuid.toUInt128(), be);
+
+ quint128 le = qFromBigEndian(be);
+ QCOMPARE(uuid.toUInt128(QSysInfo::LittleEndian), le);
+ QCOMPARE(QUuid::fromUInt128(le, QSysInfo::LittleEndian), uuidA);
+
+ QUuid::Id128Bytes bytes = { .data128 = { qToBigEndian(u) } };
+ QUuid uuid2(bytes);
+ QCOMPARE(uuid2, uuid);
+
+ // verify that toBytes() and toUInt128() provide bytewise similar result
+ constexpr quint128 val = uuid.toUInt128();
+ bytes = uuid.toBytes();
+ QVERIFY(memcmp(&val, bytes.data, sizeof(val)) == 0);
+#else
+ QSKIP("This platform has no support for 128-bit integer");
+#endif
+}
+
void tst_QUuid::createUuidV3OrV5()
{
//"www.widgets.com" is also from RFC4122
@@ -389,13 +446,13 @@ public:
void tst_QUuid::threadUniqueness()
{
QList<UuidThread *> threads(qMax(2, QThread::idealThreadCount()));
- for (int i = 0; i < threads.count(); ++i)
+ for (int i = 0; i < threads.size(); ++i)
threads[i] = new UuidThread;
- for (int i = 0; i < threads.count(); ++i)
+ for (int i = 0; i < threads.size(); ++i)
threads[i]->start();
- for (int i = 0; i < threads.count(); ++i)
+ for (int i = 0; i < threads.size(); ++i)
QVERIFY(threads[i]->wait(1000));
- for (int i = 1; i < threads.count(); ++i)
+ for (int i = 1; i < threads.size(); ++i)
QVERIFY(threads[0]->uuid != threads[i]->uuid);
qDeleteAll(threads);
}
@@ -413,7 +470,7 @@ void tst_QUuid::processUniqueness()
QString processTwoOutput;
// Start it once
-#ifdef Q_OS_MAC
+#ifdef Q_OS_DARWIN
process.start("testProcessUniqueness/testProcessUniqueness.app");
#elif defined(Q_OS_ANDROID)
process.start("libtestProcessUniqueness.so");
@@ -424,7 +481,7 @@ void tst_QUuid::processUniqueness()
processOneOutput = process.readAllStandardOutput();
// Start it twice
-#ifdef Q_OS_MAC
+#ifdef Q_OS_DARWIN
process.start("testProcessUniqueness/testProcessUniqueness.app");
#elif defined(Q_OS_ANDROID)
process.start("libtestProcessUniqueness.so");