Skip to content

Commit a6add5f

Browse files
committed
Add IPC property consistency test
1 parent 6245cee commit a6add5f

File tree

7 files changed

+353
-0
lines changed

7 files changed

+353
-0
lines changed

tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ if(NOT ${FACELIFT_DISABLE_GTEST})
7979
endif()
8080

8181
add_subdirectory(objectregistry)
82+
add_subdirectory(propertyconsistency)
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
if (TARGET FaceliftIPCLibDBus)
2+
3+
facelift_add_interface(property_consistency_gen
4+
INTERFACE_DEFINITION_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/interface)
5+
6+
facelift_add_executable(property-consistency-test-client
7+
HEADERS
8+
client.h
9+
SOURCES
10+
client.cpp
11+
LINK_LIBRARIES
12+
Qt5::Core
13+
property_consistency_gen
14+
)
15+
16+
facelift_add_test(property-consistency-test
17+
HEADERS
18+
server.h
19+
SOURCES
20+
server.cpp
21+
PRIVATE_DEFINITIONS CLIENT_EXECUTABLE_LOCATION="$<TARGET_FILE:property-consistency-test-client>"
22+
LINK_LIBRARIES
23+
Qt5::Core
24+
property_consistency_gen
25+
)
26+
27+
endif()

tests/propertyconsistency/client.cpp

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 "client.h"
31+
#include <QCoreApplication>
32+
33+
void tests::ipc::Tester::start()
34+
{
35+
m_async = std::make_unique<tests::ipc::IPCConsistencyTestInterfaceAsyncIPCProxy>();
36+
37+
auto checkConsistency = [this]() {
38+
if (m_async->boolProperty1() != m_async->boolProperty2()) {
39+
qCritical() << "Inconsistency detected";
40+
qApp->exit(10);
41+
}
42+
};
43+
44+
connect(m_async.get(), &facelift::InterfaceBase::readyChanged, this, [this, checkConsistency]() {
45+
if (m_async->ready()) {
46+
checkConsistency();
47+
m_async->toggle();
48+
}
49+
});
50+
51+
connect(m_async.get(), &IPCConsistencyTestInterfaceAsyncIPCProxy::boolProperty1Changed, this, checkConsistency);
52+
connect(m_async.get(), &IPCConsistencyTestInterfaceAsyncIPCProxy::boolProperty2Changed, this, checkConsistency);
53+
54+
QTimer::singleShot(3000, [&]() {
55+
if (!m_async->ready()) {
56+
qCritical() << "Server not found. path:" << m_async->objectPath();
57+
qApp->exit(2);
58+
} else {
59+
qApp->exit(0);
60+
}
61+
});
62+
63+
m_async->connectToServer();
64+
}
65+
66+
int main(int argc, char** argv)
67+
{
68+
QCoreApplication app(argc, argv);
69+
70+
tests::ipc::Tester tester;
71+
tester.start();
72+
73+
return app.exec();
74+
}

tests/propertyconsistency/client.h

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
#pragma once
31+
32+
#include <memory>
33+
#include <QObject>
34+
#include "tests/ipc/IPCConsistencyTestInterfaceAsyncIPCProxy.h"
35+
36+
namespace tests {
37+
namespace ipc {
38+
39+
class Tester : public QObject {
40+
Q_OBJECT
41+
public:
42+
43+
void start();
44+
45+
std::unique_ptr<IPCConsistencyTestInterfaceAsyncIPCProxy> m_async;
46+
};
47+
48+
} // end namespace ipc
49+
} // end namespace tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
31+
module tests.ipc 1.0
32+
33+
@ipc-async: true
34+
@ipc-sync: true
35+
interface IPCConsistencyTestInterface {
36+
readonly bool boolProperty1;
37+
readonly bool boolProperty2;
38+
void toggle();
39+
}

tests/propertyconsistency/server.cpp

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}

tests/propertyconsistency/server.h

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
#pragma once
31+
32+
#ifndef CLIENT_EXECUTABLE_LOCATION
33+
#error "CLIENT_EXECUTABLE_LOCATION must be be defined! Check CMakeLists.txt"
34+
#endif
35+
36+
#include <memory>
37+
#include <QString>
38+
#include "tests/ipc/IPCConsistencyTestInterfaceIPCAdapter.h"
39+
40+
namespace tests {
41+
namespace ipc {
42+
43+
/**
44+
* This implementation exposes 2 properties which always contain identical values
45+
* The IPC framework ensures that client side proxy objects also provide the same values
46+
*/
47+
class IPCTestInterfaceImpl : public IPCConsistencyTestInterface {
48+
Q_OBJECT
49+
public:
50+
IPCTestInterfaceImpl();
51+
52+
void toggle() override;
53+
54+
const bool& boolProperty1() const override {
55+
return m_boolProperty;
56+
}
57+
58+
const bool& boolProperty2() const override {
59+
return m_boolProperty;
60+
}
61+
62+
bool ready() const override {
63+
return true;
64+
}
65+
66+
IPCConsistencyTestInterfaceIPCAdapter m_adapter;
67+
QTimer m_timer;
68+
bool m_boolProperty = false;
69+
};
70+
71+
} // end namespace ipc
72+
} // end namespace tests

0 commit comments

Comments
 (0)