From 212c3c4f122ea921336137c7987a9c866c5cc347 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Tue, 7 Dec 2021 19:02:41 +0200 Subject: RemoteObject: Fix warning on calling QLocalSocket::waitForDisconnected() Change-Id: I1d5fdfedaee35c530b383951e6fc69b75bd67d64 Reviewed-by: Katja Marttila --- .../installer/clientserver/tst_clientserver.cpp | 47 +++++++++++++++++++++- tests/auto/installer/shared/packagemanager.h | 13 +++++- 2 files changed, 57 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/installer/clientserver/tst_clientserver.cpp b/tests/auto/installer/clientserver/tst_clientserver.cpp index 7b9971056..bcd87815d 100644 --- a/tests/auto/installer/clientserver/tst_clientserver.cpp +++ b/tests/auto/installer/clientserver/tst_clientserver.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -27,6 +27,7 @@ **************************************************************************/ #include "../shared/verifyinstaller.h" +#include "../shared/packagemanager.h" #include #include @@ -51,6 +52,17 @@ using namespace QInstaller; +class MyRemoteObject : public RemoteObject +{ +public: + MyRemoteObject() + : RemoteObject(QLatin1String("MyRemoteObject")) {}; + + ~MyRemoteObject() = default; + + bool connectToServer() { return RemoteObject::connectToServer(); } +}; + class tst_ClientServer : public QObject { Q_OBJECT @@ -78,7 +90,7 @@ private: } private slots: - void initTestCase() + void init() { RemoteClient::instance().setActive(true); } @@ -269,6 +281,37 @@ private slots: } } + void testCreateDestroyRemoteObject() + { + RemoteServer server; + QString socketName = QUuid::createUuid().toString(); + server.init(socketName, QLatin1String("SomeKey"), Protocol::Mode::Production); + server.start(); + + RemoteClient::instance().init(socketName, QLatin1String("SomeKey"), Protocol::Mode::Debug, + Protocol::StartAs::User); + + // Look for warnings on connection and disconnection.. + qInstallMessageHandler(exitOnWarningMessageHandler); + + MyRemoteObject *object = new MyRemoteObject; + QVERIFY(!object->isConnectedToServer()); + delete object; + + object = new MyRemoteObject; + QVERIFY(object->connectToServer()); + QVERIFY(object->isConnectedToServer()); + delete object; + + object = new MyRemoteObject; + QVERIFY(object->connectToServer()); + QVERIFY(object->isConnectedToServer()); + + RemoteClient::instance().setActive(false); + QVERIFY(!object->isConnectedToServer()); + delete object; + } + void testQSettingsWrapper() { RemoteServer server; diff --git a/tests/auto/installer/shared/packagemanager.h b/tests/auto/installer/shared/packagemanager.h index c4d86cf32..a95dd4442 100644 --- a/tests/auto/installer/shared/packagemanager.h +++ b/tests/auto/installer/shared/packagemanager.h @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -35,12 +35,23 @@ #include #include #include +#include #include using namespace QInstaller; void silentTestMessageHandler(QtMsgType, const QMessageLogContext &, const QString &) {} +void exitOnWarningMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + const QByteArray localMsg = msg.toLocal8Bit(); + const char *file = context.file ? context.file : ""; + const char *function = context.function ? context.function : ""; + if (!(type == QtDebugMsg) && !(type == QtInfoMsg)) { + fprintf(stderr, "Caught message: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function); + exit(1); + } +} struct PackageManager { -- cgit v1.2.3