summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp')
-rw-r--r--tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp64
1 files changed, 63 insertions, 1 deletions
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"