summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/plugin/quuid
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/plugin/quuid')
-rw-r--r--tests/auto/corelib/plugin/quuid/CMakeLists.txt9
-rw-r--r--tests/auto/corelib/plugin/quuid/quuid.pro6
-rw-r--r--tests/auto/corelib/plugin/quuid/test/.prev_CMakeLists.txt29
-rw-r--r--tests/auto/corelib/plugin/quuid/test/CMakeLists.txt20
-rw-r--r--tests/auto/corelib/plugin/quuid/test/test.pro19
-rw-r--r--tests/auto/corelib/plugin/quuid/testProcessUniqueness/.prev_CMakeLists.txt12
-rw-r--r--tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt5
-rw-r--r--tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp29
-rw-r--r--tests/auto/corelib/plugin/quuid/testProcessUniqueness/testProcessUniqueness.pro9
-rw-r--r--tests/auto/corelib/plugin/quuid/tst_quuid.cpp133
-rw-r--r--tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm33
11 files changed, 120 insertions, 184 deletions
diff --git a/tests/auto/corelib/plugin/quuid/CMakeLists.txt b/tests/auto/corelib/plugin/quuid/CMakeLists.txt
index 91e75fe0ae..be90dc1849 100644
--- a/tests/auto/corelib/plugin/quuid/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/quuid/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from quuid.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_quuid LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
add_subdirectory(testProcessUniqueness)
add_subdirectory(test)
diff --git a/tests/auto/corelib/plugin/quuid/quuid.pro b/tests/auto/corelib/plugin/quuid/quuid.pro
deleted file mode 100644
index 25e24561ae..0000000000
--- a/tests/auto/corelib/plugin/quuid/quuid.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS = testProcessUniqueness
-
-SUBDIRS += test
-
diff --git a/tests/auto/corelib/plugin/quuid/test/.prev_CMakeLists.txt b/tests/auto/corelib/plugin/quuid/test/.prev_CMakeLists.txt
deleted file mode 100644
index 5e0aec0f33..0000000000
--- a/tests/auto/corelib/plugin/quuid/test/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,29 +0,0 @@
-# Generated from test.pro.
-
-#####################################################################
-## tst_quuid Test:
-#####################################################################
-
-qt_internal_add_test(tst_quuid
- SOURCES
- ../tst_quuid.cpp
-)
-
-## Scopes:
-#####################################################################
-
-qt_internal_extend_target(tst_quuid CONDITION APPLE
- SOURCES
- ../tst_quuid_darwin.mm
- PUBLIC_LIBRARIES
- ${FWFoundation}
-)
-
-#### Keys ignored in scope 4:.:.:test.pro:(CMAKE_BUILD_TYPE STREQUAL Debug):
-# DESTDIR = "../debug"
-
-#### Keys ignored in scope 5:.:.:test.pro:else:
-# DESTDIR = "../release"
-
-#### Keys ignored in scope 6:.:.:test.pro:else:
-# DESTDIR = ".."
diff --git a/tests/auto/corelib/plugin/quuid/test/CMakeLists.txt b/tests/auto/corelib/plugin/quuid/test/CMakeLists.txt
index 51712cfc05..1e1e820b14 100644
--- a/tests/auto/corelib/plugin/quuid/test/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/quuid/test/CMakeLists.txt
@@ -1,30 +1,26 @@
-# Generated from test.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_quuid Test:
#####################################################################
qt_internal_add_test(tst_quuid
- OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case
+ OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../"
SOURCES
../tst_quuid.cpp
)
## Scopes:
-#####################################################################
qt_internal_extend_target(tst_quuid CONDITION APPLE
SOURCES
../tst_quuid_darwin.mm
- PUBLIC_LIBRARIES
+ LIBRARIES
+ Qt::CorePrivate
${FWFoundation}
)
-#### Keys ignored in scope 4:.:.:test.pro:(CMAKE_BUILD_TYPE STREQUAL Debug):
-# DESTDIR = "../debug"
-
-#### Keys ignored in scope 5:.:.:test.pro:else:
-# DESTDIR = "../release"
-
-#### Keys ignored in scope 6:.:.:test.pro:else:
-# DESTDIR = ".."
+if(QT_FEATURE_process AND NOT ANDROID)
+ add_dependencies(tst_quuid testProcessUniqueness)
+endif()
diff --git a/tests/auto/corelib/plugin/quuid/test/test.pro b/tests/auto/corelib/plugin/quuid/test/test.pro
deleted file mode 100644
index 562bfbdc25..0000000000
--- a/tests/auto/corelib/plugin/quuid/test/test.pro
+++ /dev/null
@@ -1,19 +0,0 @@
-CONFIG += testcase
-TARGET = tst_quuid
-QT = core testlib
-SOURCES = ../tst_quuid.cpp
-
-darwin {
- OBJECTIVE_SOURCES = ../tst_quuid_darwin.mm
- LIBS += -framework Foundation
-}
-
-CONFIG(debug_and_release_target) {
- CONFIG(debug, debug|release) {
- DESTDIR = ../debug
- } else {
- DESTDIR = ../release
- }
-} else {
- DESTDIR = ..
-}
diff --git a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/.prev_CMakeLists.txt b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/.prev_CMakeLists.txt
deleted file mode 100644
index e1b5814f41..0000000000
--- a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-# Generated from testProcessUniqueness.pro.
-
-#####################################################################
-## testProcessUniqueness Binary:
-#####################################################################
-
-qt_internal_add_executable(testProcessUniqueness
- INSTALL_DIRECTORY "${INSTALL_TESTSDIR}/tst_quuid/testProcessUniqueness"
- OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/"
- SOURCES
- main.cpp
-)
diff --git a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt
index 0bdf32a207..f207cdaa3a 100644
--- a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt
+++ b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from testProcessUniqueness.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## testProcessUniqueness Binary:
@@ -11,6 +12,4 @@ qt_internal_add_executable(testProcessUniqueness
main.cpp
)
-# special case begin
set_target_properties(testProcessUniqueness PROPERTIES MACOSX_BUNDLE TRUE)
-# special case end
diff --git a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
index 126d2bb435..93d1201631 100644
--- a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
+++ b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <stdio.h>
#include <QUuid>
diff --git a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/testProcessUniqueness.pro b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/testProcessUniqueness.pro
deleted file mode 100644
index 5ee7b1a21f..0000000000
--- a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/testProcessUniqueness.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-SOURCES = main.cpp
-QT = core
-CONFIG += console
-
-DESTDIR = ./
-
-# This app is testdata for tst_quuid
-target.path = $$[QT_INSTALL_TESTS]/tst_quuid/$$TARGET
-INSTALLS += target
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");
diff --git a/tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm b/tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm
index 41ccece115..c3fc809b1f 100644
--- a/tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm
+++ b/tests/auto/corelib/plugin/quuid/tst_quuid_darwin.mm
@@ -1,33 +1,10 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QUuid>
-#include <QtTest/QtTest>
+#include <QTest>
+
+#include <QtCore/private/qcore_mac_p.h>
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>