|
| 1 | +/********************************************************************** |
| 2 | +** |
| 3 | +** Copyright (C) 2020 Luxoft Sweden AB |
| 4 | +** |
| 5 | +** This file is part of the FaceLift project |
| 6 | +** |
| 7 | +** Permission is hereby granted, free of charge, to any person |
| 8 | +** obtaining a copy of this software and associated documentation files |
| 9 | +** (the "Software"), to deal in the Software without restriction, |
| 10 | +** including without limitation the rights to use, copy, modify, merge, |
| 11 | +** publish, distribute, sublicense, and/or sell copies of the Software, |
| 12 | +** and to permit persons to whom the Software is furnished to do so, |
| 13 | +** subject to the following conditions: |
| 14 | +** |
| 15 | +** The above copyright notice and this permission notice shall be |
| 16 | +** included in all copies or substantial portions of the Software. |
| 17 | +** |
| 18 | +** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | +** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 22 | +** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 23 | +** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | +** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | +** SOFTWARE. |
| 26 | +** |
| 27 | +** SPDX-License-Identifier: MIT |
| 28 | +** |
| 29 | +**********************************************************************/ |
| 30 | +#include "server.h" |
| 31 | +#include <QCoreApplication> |
| 32 | +#include <QProcess> |
| 33 | + |
| 34 | +namespace tests { |
| 35 | +namespace ipc { |
| 36 | + |
| 37 | +IPCTestInterfaceImpl::IPCTestInterfaceImpl() |
| 38 | +{ |
| 39 | + m_adapter.registerService(this); |
| 40 | + |
| 41 | + connect(&m_timer, &QTimer::timeout, this, &IPCTestInterfaceImpl::toggle); |
| 42 | + m_timer.start(100); |
| 43 | +} |
| 44 | + |
| 45 | +void IPCTestInterfaceImpl::toggle() |
| 46 | +{ |
| 47 | + m_boolProperty = !m_boolProperty; |
| 48 | + boolProperty1Changed(); |
| 49 | + boolProperty2Changed(); |
| 50 | +} |
| 51 | + |
| 52 | +} // end namespace ipc |
| 53 | +} // end namespace tests |
| 54 | + |
| 55 | +int main(int argc, char** argv) { |
| 56 | + |
| 57 | + QCoreApplication app(argc, argv); |
| 58 | + |
| 59 | + tests::ipc::IPCTestInterfaceImpl server; |
| 60 | + QProcess client; |
| 61 | + |
| 62 | + auto exitWithCode = [&app](int code) { |
| 63 | + qCritical() << "Exiting with code" << code; |
| 64 | + app.exit(code); |
| 65 | + }; |
| 66 | + |
| 67 | + // Terminate with error after 10 seconds |
| 68 | + QTimer::singleShot(10000, &app, [&]() { |
| 69 | + qDebug() << "Test failed: timeout"; |
| 70 | + client.close(); |
| 71 | + exitWithCode(1); |
| 72 | + }); |
| 73 | + |
| 74 | + // We terminate if the client process terminates |
| 75 | + QObject::connect(&client, &QProcess::stateChanged, [&] (QProcess::ProcessState state) { |
| 76 | + qWarning() << "Client process state" << state; |
| 77 | + if (state == QProcess::ProcessState::NotRunning) { |
| 78 | + qWarning() << "Client terminated with status" << client.exitStatus() << client.exitCode(); |
| 79 | + if (client.exitStatus() != QProcess::ExitStatus::NormalExit) |
| 80 | + exitWithCode(1); |
| 81 | + else { |
| 82 | + exitWithCode(client.exitCode()); |
| 83 | + } |
| 84 | + |
| 85 | + } |
| 86 | + }); |
| 87 | + |
| 88 | + client.start(CLIENT_EXECUTABLE_LOCATION); |
| 89 | + |
| 90 | + return app.exec(); |
| 91 | +} |
0 commit comments