summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-10-13 10:52:34 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-01-22 13:02:11 -0300
commit0740ab56d7c3b540677e33e28924d47bce87c1cf (patch)
treebf97368db9572596a6865ff42286fe0fbd119f86 /tests
parent32a06e983073080d939b4742996a3dc9cd75bb83 (diff)
IPC: add support for multiple backends to QSharedMemory
Simultaneously. Change-Id: If4c23ea3719947d790d4fffd17152760989b9bc6 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp71
1 files changed, 56 insertions, 15 deletions
diff --git a/tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp
index 44f5cee82d..4c871e0269 100644
--- a/tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp
+++ b/tests/auto/corelib/ipc/qsharedmemory/tst_qsharedmemory.cpp
@@ -19,6 +19,7 @@
#endif
#include "private/qtcore-config_p.h"
+#include "../ipctestcommon.h"
#define EXISTING_SIZE 1024
@@ -31,15 +32,11 @@ class tst_QSharedMemory : public QObject
{
Q_OBJECT
-public:
- tst_QSharedMemory();
- virtual ~tst_QSharedMemory();
-
public Q_SLOTS:
+ void initTestCase();
void init();
void cleanup();
-
private slots:
// basics
void constructor();
@@ -51,6 +48,8 @@ private slots:
void create();
void attach_data();
void attach();
+ void changeKeyType_data() { attach_data(); }
+ void changeKeyType();
void lock();
// custom edge cases
@@ -92,7 +91,7 @@ protected:
QNativeIpcKey platformSafeKey(const QString &key)
{
- QNativeIpcKey::Type keyType = QNativeIpcKey::DefaultTypeForOs;
+ QFETCH_GLOBAL(QNativeIpcKey::Type, keyType);
return QSharedMemory::platformSafeKey(mangleKey(key), keyType);
}
@@ -108,21 +107,16 @@ protected:
QList<QNativeIpcKey> keys;
QList<QSharedMemory*> jail;
- QSharedMemory *existingSharedMemory;
+ QSharedMemory *existingSharedMemory = nullptr;
int seq = 0;
private:
- const QString m_helperBinary;
+ const QString m_helperBinary = "./producerconsumer_helper";
};
-tst_QSharedMemory::tst_QSharedMemory()
- : existingSharedMemory(0)
- , m_helperBinary("./producerconsumer_helper")
-{
-}
-
-tst_QSharedMemory::~tst_QSharedMemory()
+void tst_QSharedMemory::initTestCase()
{
+ IpcTestCommon::addGlobalTestRows<QSharedMemory>();
}
void tst_QSharedMemory::init()
@@ -285,6 +279,25 @@ void tst_QSharedMemory::nativeKey()
QCOMPARE(sm.size(), 0);
QCOMPARE(sm.detach(), false);
+
+ // change the key type
+ QNativeIpcKey::Type nextKeyType = IpcTestCommon::nextKeyType(setIpcKey.type());
+ if (nextKeyType != setIpcKey.type()) {
+ QNativeIpcKey setIpcKey2 = QSharedMemory::platformSafeKey(setKey, nextKeyType);
+ sm.setNativeKey(setIpcKey2);
+
+ QCOMPARE(sm.nativeIpcKey(), setIpcKey2);
+ QCOMPARE(sm.nativeKey(), setIpcKey2.nativeKey());
+
+ QCOMPARE(sm.isAttached(), false);
+
+ QCOMPARE(sm.error(), QSharedMemory::NoError);
+ QCOMPARE(sm.errorString(), QString());
+ QVERIFY(!sm.data());
+ QCOMPARE(sm.size(), 0);
+
+ QCOMPARE(sm.detach(), false);
+ }
}
QT_WARNING_PUSH
@@ -408,6 +421,34 @@ void tst_QSharedMemory::attach()
}
}
+void tst_QSharedMemory::changeKeyType()
+{
+ QFETCH(QString, key);
+ QFETCH(bool, exists);
+ QFETCH(QSharedMemory::SharedMemoryError, error);
+
+ QNativeIpcKey nativeKey = platformSafeKey(key);
+ QNativeIpcKey::Type nextKeyType = IpcTestCommon::nextKeyType(nativeKey.type());
+ if (nextKeyType == nativeKey.type())
+ QSKIP("System only supports one key type");
+// qDebug() << "Changing from" << nativeKey.type() << "to" << nextKeyType;
+
+ QSharedMemory sm(nativeKey);
+ QCOMPARE(sm.attach(), exists);
+ QCOMPARE(sm.error(), error);
+
+ QNativeIpcKey nextKey =
+ QSharedMemory::platformSafeKey(mangleKey(key), nextKeyType);
+ sm.setNativeKey(nextKey);
+ QCOMPARE(sm.isAttached(), false);
+ QVERIFY(!sm.attach());
+
+ if (exists)
+ QCOMPARE(sm.error(), QSharedMemory::NotFound);
+ else
+ QCOMPARE(sm.error(), error);
+}
+
void tst_QSharedMemory::lock()
{
QSharedMemory shm;