Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPC property consistency test #305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ if(NOT ${FACELIFT_DISABLE_GTEST})
endif()

add_subdirectory(objectregistry)
add_subdirectory(propertyconsistency)
27 changes: 27 additions & 0 deletions tests/propertyconsistency/CMakeLists.txt
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()
74 changes: 74 additions & 0 deletions tests/propertyconsistency/client.cpp
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, [this, checkConsistency]() {
if (m_async->ready()) {
checkConsistency();
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();
}
49 changes: 49 additions & 0 deletions tests/propertyconsistency/client.h
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
39 changes: 39 additions & 0 deletions tests/propertyconsistency/interface/interfaces.qface
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();
}
91 changes: 91 additions & 0 deletions tests/propertyconsistency/server.cpp
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();
}
72 changes: 72 additions & 0 deletions tests/propertyconsistency/server.h
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