summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/ipc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/ipc')
-rw-r--r--tests/auto/corelib/ipc/qnativeipckey/CMakeLists.txt8
-rw-r--r--tests/auto/corelib/ipc/qnativeipckey/tst_qnativeipckey.cpp138
-rw-r--r--tests/auto/corelib/ipc/qsharedmemory/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/ipc/qsharedmemory/producerconsumer/main.cpp2
-rw-r--r--tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp64
-rw-r--r--tests/auto/corelib/ipc/qsystemsemaphore/CMakeLists.txt6
-rw-r--r--tests/auto/corelib/ipc/qsystemsemaphore/acquirerelease/main.cpp2
-rw-r--r--tests/auto/corelib/ipc/qsystemsemaphore/tst_qsystemsemaphore.cpp2
8 files changed, 218 insertions, 10 deletions
diff --git a/tests/auto/corelib/ipc/qnativeipckey/CMakeLists.txt b/tests/auto/corelib/ipc/qnativeipckey/CMakeLists.txt
index c52b5d221a..0cc6a7b18b 100644
--- a/tests/auto/corelib/ipc/qnativeipckey/CMakeLists.txt
+++ b/tests/auto/corelib/ipc/qnativeipckey/CMakeLists.txt
@@ -1,7 +1,15 @@
# Copyright (C) 2022 Intel Corporation.
# 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_qnativeipckey LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qnativeipckey
SOURCES
tst_qnativeipckey.cpp
+ LIBRARIES
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/ipc/qnativeipckey/tst_qnativeipckey.cpp b/tests/auto/corelib/ipc/qnativeipckey/tst_qnativeipckey.cpp
index 6c30f428e9..a01a108591 100644
--- a/tests/auto/corelib/ipc/qnativeipckey/tst_qnativeipckey.cpp
+++ b/tests/auto/corelib/ipc/qnativeipckey/tst_qnativeipckey.cpp
@@ -1,28 +1,51 @@
// Copyright (C) 2022 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QNativeIpcKey>
#include <QtTest/QTest>
+#include <QtTest/private/qcomparisontesthelper_p.h>
#include "../ipctestcommon.h"
+#if QT_CONFIG(sharedmemory)
+# include <qsharedmemory.h>
+#endif
+#if QT_CONFIG(systemsemaphore)
+# include <qsystemsemaphore.h>
+#endif
+
+#if QT_CONFIG(sharedmemory)
+static const auto makeLegacyKey = QSharedMemory::legacyNativeKey;
+#else
+static const auto makeLegacyKey = QSystemSemaphore::legacyNativeKey;
+#endif
+
using namespace Qt::StringLiterals;
class tst_QNativeIpcKey : public QObject
{
Q_OBJECT
private slots:
+ void compareCompiles();
void defaultTypes();
void construct();
void getSetCheck();
void equality();
+ void hash();
void swap();
void toString_data();
void toString();
void fromString_data();
void fromString();
+ void legacyKeys_data();
+ void legacyKeys();
};
+void tst_QNativeIpcKey::compareCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QNativeIpcKey>();
+}
+
void tst_QNativeIpcKey::defaultTypes()
{
auto isKnown = [](QNativeIpcKey::Type t) {
@@ -164,22 +187,51 @@ void tst_QNativeIpcKey::equality()
QNativeIpcKey key1, key2;
QCOMPARE(key1, key2);
QVERIFY(!(key1 != key2));
+ QT_TEST_EQUALITY_OPS(key1, key2, true);
key1.setNativeKey("key1");
QCOMPARE_NE(key1, key2);
QVERIFY(!(key1 == key2));
+ QT_TEST_EQUALITY_OPS(key1, key2, false);
key2.setType({});
QCOMPARE_NE(key1, key2);
QVERIFY(!(key1 == key2));
+ QT_TEST_EQUALITY_OPS(key1, key2, false);
key2.setNativeKey(key1.nativeKey());
QCOMPARE_NE(key1, key2);
QVERIFY(!(key1 == key2));
+ QT_TEST_EQUALITY_OPS(key1, key2, false);
key2.setType(QNativeIpcKey::DefaultTypeForOs);
QCOMPARE(key1, key2);
QVERIFY(!(key1 != key2));
+ QT_TEST_EQUALITY_OPS(key1, key2, true);
+
+ key1 = makeLegacyKey("key1", QNativeIpcKey::DefaultTypeForOs);
+ QCOMPARE_NE(key1, key2);
+ QVERIFY(!(key1 == key2));
+ QT_TEST_EQUALITY_OPS(key1, key2, false);
+
+ key2 = key1;
+ QCOMPARE(key1, key2);
+ QVERIFY(!(key1 != key2));
+ QT_TEST_EQUALITY_OPS(key1, key2, true);
+
+ // just setting the native key won't make them equal again!
+ key2.setNativeKey(key1.nativeKey());
+ QCOMPARE_NE(key1, key2);
+ QVERIFY(!(key1 == key2));
+ QT_TEST_EQUALITY_OPS(key1, key2, false);
+}
+
+void tst_QNativeIpcKey::hash()
+{
+ QNativeIpcKey key1("key1", QNativeIpcKey::DefaultTypeForOs);
+ QNativeIpcKey key2(key1);
+ QCOMPARE_EQ(qHash(key1), qHash(key2));
+ QCOMPARE_EQ(qHash(key1, 123), qHash(key2, 123));
}
void tst_QNativeIpcKey::swap()
@@ -206,6 +258,12 @@ void tst_QNativeIpcKey::swap()
QCOMPARE(key1.type(), QNativeIpcKey::Type::PosixRealtime);
QCOMPARE(key2.nativeKey(), "key2");
QCOMPARE(key2.type(), QNativeIpcKey::Type::Windows);
+
+ key1 = makeLegacyKey("key1", QNativeIpcKey::DefaultTypeForOs);
+ QCOMPARE(key1.type(), QNativeIpcKey::DefaultTypeForOs);
+ key1.swap(key2);
+ QCOMPARE(key1.type(), QNativeIpcKey::Type::Windows);
+ QCOMPARE(key2.type(), QNativeIpcKey::DefaultTypeForOs);
}
void tst_QNativeIpcKey::toString_data()
@@ -228,13 +286,13 @@ void tst_QNativeIpcKey::toString_data()
add("objectlike", "Global\\sometext"_L1);
add("colon-slash", ":/"_L1);
add("slash-colon", "/:"_L1);
- add("non-ascii", "\xa0\xff"_L1);
add("percent", "%"_L1, "%25"_L1);
add("question-hash", "?#"_L1, "%3F%23"_L1);
add("hash-question", "#?"_L1, "%23%3F"_L1);
add("double-slash", "//"_L1, "/%2F"_L1);
add("triple-slash", "///"_L1, "/%2F/"_L1);
- add("non-ascii", "/\xe9"_L1);
+ add("non-ascii", "\xe9"_L1);
+ add("non-utf8", "\xa0\xff"_L1);
QTest::addRow("%s-%s", prefix, "non-latin1")
<< prefix + u":\u0100.\u2000.\U00010000"_s
<< QNativeIpcKey(u"\u0100.\u2000.\U00010000"_s, type);
@@ -271,12 +329,14 @@ void tst_QNativeIpcKey::fromString_data()
<< "posix:%C4%80.%E2%80%80.%F0%90%80%80"
<< QNativeIpcKey(u"\u0100.\u2000.\U00010000"_s, QNativeIpcKey::Type::PosixRealtime);
- // query and fragment are ignored
- QTest::addRow("with-query") << "posix:/foo?bar" << valid;
+ // fragments are ignored
QTest::addRow("with-fragment") << "posix:/foo#bar" << valid;
- QTest::addRow("with-queryfragment") << "posix:/foo?bar#baz" << valid;
QTest::addRow("with-fragmentquery") << "posix:/foo#bar?baz" << valid;
+ // but unknown query items are not
+ QTest::addRow("with-query") << "posix:/foo?bar" << invalid;
+ QTest::addRow("with-queryfragment") << "posix:/foo?bar#baz" << invalid;
+
// add some ones that won't parse well
QTest::addRow("positive-number") << "81" << invalid;
QTest::addRow("negative-number") << "-81" << invalid;
@@ -312,5 +372,71 @@ void tst_QNativeIpcKey::fromString()
QCOMPARE(QNativeIpcKey::fromString(string), key);
}
+void tst_QNativeIpcKey::legacyKeys_data()
+{
+ QTest::addColumn<QNativeIpcKey::Type>("type");
+ QTest::addColumn<QString>("legacyKey");
+ auto addRows = [](QNativeIpcKey::Type type) {
+ const char *label = "<unknown-type>";
+ switch (type) {
+ case QNativeIpcKey::Type::SystemV:
+ label = "systemv";
+ break;
+ case QNativeIpcKey::Type::PosixRealtime:
+ label = "posix";
+ break;
+ case QNativeIpcKey::Type::Windows:
+ label = "windows";
+ break;
+ }
+ auto add = [=](const char *name, const QString &legacyKey) {
+ QTest::addRow("%s-%s", label, name) << type << legacyKey;
+ };
+ add("empty", {});
+ add("text", "foobar"_L1);
+ add("pathlike", "/sometext"_L1);
+ add("objectlike", "Global\\sometext"_L1);
+ add("colon-slash", ":/"_L1);
+ add("slash-colon", "/:"_L1);
+ add("percent", "%"_L1);
+ add("question-hash", "?#"_L1);
+ add("hash-question", "#?"_L1);
+ add("double-slash", "//"_L1);
+ add("triple-slash", "///"_L1);
+ add("non-ascii", "\xe9"_L1);
+ add("non-utf8", "\xa0\xff"_L1);
+ add("non-latin1", u":\u0100.\u2000.\U00010000"_s);
+ };
+
+ addRows(QNativeIpcKey::DefaultTypeForOs);
+ if (auto type = QNativeIpcKey::legacyDefaultTypeForOs();
+ type != QNativeIpcKey::DefaultTypeForOs)
+ addRows(type);
+}
+
+void tst_QNativeIpcKey::legacyKeys()
+{
+ QFETCH(QNativeIpcKey::Type, type);
+ QFETCH(QString, legacyKey);
+
+ QNativeIpcKey key = makeLegacyKey(legacyKey, type);
+ QCOMPARE(key.type(), type);
+
+ QString string = key.toString();
+ QNativeIpcKey key2 = QNativeIpcKey::fromString(string);
+ QCOMPARE(key2, key);
+ QT_TEST_EQUALITY_OPS(key, key2, true);
+
+ if (!legacyKey.isEmpty()) {
+ // confirm it shows up in the encoded form
+ Q_ASSERT(!legacyKey.contains(u'&')); // needs extra encoding
+ QUrl u;
+ u.setQuery("legacyKey="_L1 + legacyKey, QUrl::DecodedMode);
+ QString encodedLegacyKey = u.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority
+ | QUrl::DecodeReserved);
+ QVERIFY2(string.contains(encodedLegacyKey), qPrintable(string));
+ }
+}
+
QTEST_MAIN(tst_QNativeIpcKey)
#include "tst_qnativeipckey.moc"
diff --git a/tests/auto/corelib/ipc/qsharedmemory/CMakeLists.txt b/tests/auto/corelib/ipc/qsharedmemory/CMakeLists.txt
index da87d1c7be..e49c8d7828 100644
--- a/tests/auto/corelib/ipc/qsharedmemory/CMakeLists.txt
+++ b/tests/auto/corelib/ipc/qsharedmemory/CMakeLists.txt
@@ -1,6 +1,12 @@
# 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_qsharedmemory LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qsharedmemory
SOURCES
tst_qsharedmemory.cpp
diff --git a/tests/auto/corelib/ipc/qsharedmemory/producerconsumer/main.cpp b/tests/auto/corelib/ipc/qsharedmemory/producerconsumer/main.cpp
index 4b30c06615..102d505485 100644
--- a/tests/auto/corelib/ipc/qsharedmemory/producerconsumer/main.cpp
+++ b/tests/auto/corelib/ipc/qsharedmemory/producerconsumer/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QSharedMemory>
#include <QStringList>
diff --git a/tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp
index 4c871e0269..73578a3bab 100644
--- a/tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp
+++ b/tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp
@@ -1,6 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// Copyright (C) 2022 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QDebug>
#include <QFile>
@@ -56,6 +56,8 @@ private slots:
void removeWhileAttached();
void emptyMemory();
void readOnly();
+ void attachBeforeCreate_data();
+ void attachBeforeCreate();
// basics all together
void simpleProducerConsumer_data();
@@ -78,6 +80,9 @@ private slots:
void uniqueKey_data();
void uniqueKey();
+ // legacy
+ void createWithSameKey();
+
protected:
void remove(const QNativeIpcKey &key);
@@ -543,11 +548,45 @@ void tst_QSharedMemory::readOnly()
#endif
}
+void tst_QSharedMemory::attachBeforeCreate_data()
+{
+ QTest::addColumn<bool>("legacy");
+
+ QTest::addRow("legacy") << true;
+ QTest::addRow("non-legacy") << false;
+}
+
+void tst_QSharedMemory::attachBeforeCreate()
+{
+ QFETCH_GLOBAL(const QNativeIpcKey::Type, keyType);
+ QFETCH(const bool, legacy);
+ const QString keyStr(u"test"_s);
+ QNativeIpcKey key;
+ if (legacy) {
+ key = QSharedMemory::legacyNativeKey(keyStr, keyType);
+ // same as rememberKey(), but with legacy
+ if (!keys.contains(key)) {
+ keys.append(key);
+ remove(key);
+ }
+ } else {
+ key = rememberKey(keyStr);
+ }
+ const qsizetype sz = 100;
+ QSharedMemory mem(key);
+ QVERIFY(!mem.attach());
+ QVERIFY(mem.create(sz));
+}
+
/*!
Keep making shared memory until the kernel stops us.
*/
void tst_QSharedMemory::useTooMuchMemory()
{
+ if (QSysInfo::productType() == QLatin1String("Debian")
+ || QSysInfo::productType() == QLatin1String("debian"))
+ QSKIP("This test is unstable: QTBUG-119321");
+
#ifdef Q_OS_LINUX
bool success = true;
int count = 0;
@@ -899,6 +938,29 @@ void tst_QSharedMemory::uniqueKey()
QCOMPARE(nativeEqual, setEqual);
}
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
+void tst_QSharedMemory::createWithSameKey()
+{
+ const QString key = u"legacy_key"_s;
+ const qsizetype sz = 100;
+ QSharedMemory mem1(key);
+ QVERIFY(mem1.create(sz));
+
+ {
+ QSharedMemory mem2(key);
+ QVERIFY(!mem2.create(sz));
+ QVERIFY(mem2.attach());
+ }
+ // and the second create() should fail as well, QTBUG-111855
+ {
+ QSharedMemory mem2(key);
+ QVERIFY(!mem2.create(sz));
+ QVERIFY(mem2.attach());
+ }
+}
+QT_WARNING_POP
+
QTEST_MAIN(tst_QSharedMemory)
#include "tst_qsharedmemory.moc"
diff --git a/tests/auto/corelib/ipc/qsystemsemaphore/CMakeLists.txt b/tests/auto/corelib/ipc/qsystemsemaphore/CMakeLists.txt
index db1f136723..a0f29ad18a 100644
--- a/tests/auto/corelib/ipc/qsystemsemaphore/CMakeLists.txt
+++ b/tests/auto/corelib/ipc/qsystemsemaphore/CMakeLists.txt
@@ -5,6 +5,12 @@
## tst_qsystemsemaphore Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsystemsemaphore LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qsystemsemaphore
SOURCES
tst_qsystemsemaphore.cpp
diff --git a/tests/auto/corelib/ipc/qsystemsemaphore/acquirerelease/main.cpp b/tests/auto/corelib/ipc/qsystemsemaphore/acquirerelease/main.cpp
index e170789f75..3cae7ad466 100644
--- a/tests/auto/corelib/ipc/qsystemsemaphore/acquirerelease/main.cpp
+++ b/tests/auto/corelib/ipc/qsystemsemaphore/acquirerelease/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QCoreApplication>
#include <QDebug>
diff --git a/tests/auto/corelib/ipc/qsystemsemaphore/tst_qsystemsemaphore.cpp b/tests/auto/corelib/ipc/qsystemsemaphore/tst_qsystemsemaphore.cpp
index 560f216cf8..2c053b91f6 100644
--- a/tests/auto/corelib/ipc/qsystemsemaphore/tst_qsystemsemaphore.cpp
+++ b/tests/auto/corelib/ipc/qsystemsemaphore/tst_qsystemsemaphore.cpp
@@ -1,6 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// Copyright (C) 2022 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#if QT_CONFIG(process)