-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
if (TARGET FaceliftIPCLibDBus) | ||
|
||
facelift_add_interface(property_consistency_gen | ||
INTERFACE_DEFINITION_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/interface) | ||
|
||
facelift_add_executable(property-consistency-test-client | ||
HEADERS | ||
client.h | ||
SOURCES | ||
client.cpp | ||
LINK_LIBRARIES | ||
Qt5::Core | ||
property_consistency_gen | ||
) | ||
|
||
facelift_add_test(property-consistency-test | ||
HEADERS | ||
server.h | ||
SOURCES | ||
server.cpp | ||
PRIVATE_DEFINITIONS CLIENT_EXECUTABLE_LOCATION="$<TARGET_FILE:property-consistency-test-client>" | ||
LINK_LIBRARIES | ||
Qt5::Core | ||
property_consistency_gen | ||
) | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/********************************************************************** | ||
** | ||
** Copyright (C) 2020 Luxoft Sweden AB | ||
** | ||
** This file is part of the FaceLift project | ||
** | ||
** Permission is hereby granted, free of charge, to any person | ||
** obtaining a copy of this software and associated documentation files | ||
** (the "Software"), to deal in the Software without restriction, | ||
** including without limitation the rights to use, copy, modify, merge, | ||
** publish, distribute, sublicense, and/or sell copies of the Software, | ||
** and to permit persons to whom the Software is furnished to do so, | ||
** subject to the following conditions: | ||
** | ||
** The above copyright notice and this permission notice shall be | ||
** included in all copies or substantial portions of the Software. | ||
** | ||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
** SOFTWARE. | ||
** | ||
** SPDX-License-Identifier: MIT | ||
** | ||
**********************************************************************/ | ||
#include "client.h" | ||
#include <QCoreApplication> | ||
|
||
void tests::ipc::Tester::start() | ||
{ | ||
m_async = std::make_unique<tests::ipc::IPCConsistencyTestInterfaceAsyncIPCProxy>(); | ||
|
||
auto checkConsistency = [this]() { | ||
if (m_async->boolProperty1() != m_async->boolProperty2()) { | ||
qCritical() << "Inconsistency detected"; | ||
qApp->exit(10); | ||
} | ||
}; | ||
|
||
connect(m_async.get(), &facelift::InterfaceBase::readyChanged, this, [&]() { | ||
if (m_async->ready()) { | ||
// checkConsistency(); // TODO: check why this call causes a segfault | ||
m_async->toggle(); | ||
} | ||
}); | ||
|
||
connect(m_async.get(), &IPCConsistencyTestInterfaceAsyncIPCProxy::boolProperty1Changed, this, checkConsistency); | ||
connect(m_async.get(), &IPCConsistencyTestInterfaceAsyncIPCProxy::boolProperty2Changed, this, checkConsistency); | ||
|
||
QTimer::singleShot(3000, [&]() { | ||
if (!m_async->ready()) { | ||
qCritical() << "Server not found. path:" << m_async->objectPath(); | ||
qApp->exit(2); | ||
} else { | ||
qApp->exit(0); | ||
} | ||
}); | ||
|
||
m_async->connectToServer(); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
QCoreApplication app(argc, argv); | ||
|
||
tests::ipc::Tester tester; | ||
tester.start(); | ||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/********************************************************************** | ||
** | ||
** Copyright (C) 2020 Luxoft Sweden AB | ||
** | ||
** This file is part of the FaceLift project | ||
** | ||
** Permission is hereby granted, free of charge, to any person | ||
** obtaining a copy of this software and associated documentation files | ||
** (the "Software"), to deal in the Software without restriction, | ||
** including without limitation the rights to use, copy, modify, merge, | ||
** publish, distribute, sublicense, and/or sell copies of the Software, | ||
** and to permit persons to whom the Software is furnished to do so, | ||
** subject to the following conditions: | ||
** | ||
** The above copyright notice and this permission notice shall be | ||
** included in all copies or substantial portions of the Software. | ||
** | ||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
** SOFTWARE. | ||
** | ||
** SPDX-License-Identifier: MIT | ||
** | ||
**********************************************************************/ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <QObject> | ||
#include "tests/ipc/IPCConsistencyTestInterfaceAsyncIPCProxy.h" | ||
|
||
namespace tests { | ||
namespace ipc { | ||
|
||
class Tester : public QObject { | ||
Q_OBJECT | ||
public: | ||
|
||
void start(); | ||
|
||
std::unique_ptr<IPCConsistencyTestInterfaceAsyncIPCProxy> m_async; | ||
}; | ||
|
||
} // end namespace ipc | ||
} // end namespace tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/********************************************************************** | ||
** | ||
** Copyright (C) 2020 Luxoft Sweden AB | ||
** | ||
** This file is part of the FaceLift project | ||
** | ||
** Permission is hereby granted, free of charge, to any person | ||
** obtaining a copy of this software and associated documentation files | ||
** (the "Software"), to deal in the Software without restriction, | ||
** including without limitation the rights to use, copy, modify, merge, | ||
** publish, distribute, sublicense, and/or sell copies of the Software, | ||
** and to permit persons to whom the Software is furnished to do so, | ||
** subject to the following conditions: | ||
** | ||
** The above copyright notice and this permission notice shall be | ||
** included in all copies or substantial portions of the Software. | ||
** | ||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
** SOFTWARE. | ||
** | ||
** SPDX-License-Identifier: MIT | ||
** | ||
**********************************************************************/ | ||
|
||
module tests.ipc 1.0 | ||
|
||
@ipc-async: true | ||
@ipc-sync: true | ||
interface IPCConsistencyTestInterface { | ||
readonly bool boolProperty1; | ||
readonly bool boolProperty2; | ||
void toggle(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/********************************************************************** | ||
** | ||
** Copyright (C) 2020 Luxoft Sweden AB | ||
** | ||
** This file is part of the FaceLift project | ||
** | ||
** Permission is hereby granted, free of charge, to any person | ||
** obtaining a copy of this software and associated documentation files | ||
** (the "Software"), to deal in the Software without restriction, | ||
** including without limitation the rights to use, copy, modify, merge, | ||
** publish, distribute, sublicense, and/or sell copies of the Software, | ||
** and to permit persons to whom the Software is furnished to do so, | ||
** subject to the following conditions: | ||
** | ||
** The above copyright notice and this permission notice shall be | ||
** included in all copies or substantial portions of the Software. | ||
** | ||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
** SOFTWARE. | ||
** | ||
** SPDX-License-Identifier: MIT | ||
** | ||
**********************************************************************/ | ||
#include "server.h" | ||
#include <QCoreApplication> | ||
#include <QProcess> | ||
|
||
namespace tests { | ||
namespace ipc { | ||
|
||
IPCTestInterfaceImpl::IPCTestInterfaceImpl() | ||
{ | ||
m_adapter.registerService(this); | ||
|
||
connect(&m_timer, &QTimer::timeout, this, &IPCTestInterfaceImpl::toggle); | ||
m_timer.start(100); | ||
} | ||
|
||
void IPCTestInterfaceImpl::toggle() | ||
{ | ||
m_boolProperty = !m_boolProperty; | ||
boolProperty1Changed(); | ||
boolProperty2Changed(); | ||
} | ||
|
||
} // end namespace ipc | ||
} // end namespace tests | ||
|
||
int main(int argc, char** argv) { | ||
|
||
QCoreApplication app(argc, argv); | ||
|
||
tests::ipc::IPCTestInterfaceImpl server; | ||
QProcess client; | ||
|
||
auto exitWithCode = [&app](int code) { | ||
qCritical() << "Exiting with code" << code; | ||
app.exit(code); | ||
}; | ||
|
||
// Terminate with error after 10 seconds | ||
QTimer::singleShot(10000, &app, [&]() { | ||
qDebug() << "Test failed: timeout"; | ||
client.close(); | ||
exitWithCode(1); | ||
}); | ||
|
||
// We terminate if the client process terminates | ||
QObject::connect(&client, &QProcess::stateChanged, [&] (QProcess::ProcessState state) { | ||
qWarning() << "Client process state" << state; | ||
if (state == QProcess::ProcessState::NotRunning) { | ||
qWarning() << "Client terminated with status" << client.exitStatus() << client.exitCode(); | ||
if (client.exitStatus() != QProcess::ExitStatus::NormalExit) | ||
exitWithCode(1); | ||
else { | ||
exitWithCode(client.exitCode()); | ||
} | ||
|
||
} | ||
}); | ||
|
||
client.start(CLIENT_EXECUTABLE_LOCATION); | ||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/********************************************************************** | ||
** | ||
** Copyright (C) 2020 Luxoft Sweden AB | ||
** | ||
** This file is part of the FaceLift project | ||
** | ||
** Permission is hereby granted, free of charge, to any person | ||
** obtaining a copy of this software and associated documentation files | ||
** (the "Software"), to deal in the Software without restriction, | ||
** including without limitation the rights to use, copy, modify, merge, | ||
** publish, distribute, sublicense, and/or sell copies of the Software, | ||
** and to permit persons to whom the Software is furnished to do so, | ||
** subject to the following conditions: | ||
** | ||
** The above copyright notice and this permission notice shall be | ||
** included in all copies or substantial portions of the Software. | ||
** | ||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
** ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
** SOFTWARE. | ||
** | ||
** SPDX-License-Identifier: MIT | ||
** | ||
**********************************************************************/ | ||
#pragma once | ||
|
||
#ifndef CLIENT_EXECUTABLE_LOCATION | ||
#error "CLIENT_EXECUTABLE_LOCATION must be be defined! Check CMakeLists.txt" | ||
#endif | ||
|
||
#include <memory> | ||
#include <QString> | ||
#include "tests/ipc/IPCConsistencyTestInterfaceIPCAdapter.h" | ||
|
||
namespace tests { | ||
namespace ipc { | ||
|
||
/** | ||
* This implementation exposes 2 properties which always contain identical values | ||
* The IPC framework ensures that client side proxy objects also provide the same values | ||
*/ | ||
class IPCTestInterfaceImpl : public IPCConsistencyTestInterface { | ||
Q_OBJECT | ||
public: | ||
IPCTestInterfaceImpl(); | ||
|
||
void toggle() override; | ||
|
||
const bool& boolProperty1() const override { | ||
return m_boolProperty; | ||
} | ||
|
||
const bool& boolProperty2() const override { | ||
return m_boolProperty; | ||
} | ||
|
||
bool ready() const override { | ||
return true; | ||
} | ||
|
||
IPCConsistencyTestInterfaceIPCAdapter m_adapter; | ||
QTimer m_timer; | ||
bool m_boolProperty = false; | ||
}; | ||
|
||
} // end namespace ipc | ||
} // end namespace tests |