2020-07-18 20:16:57 +02:00
|
|
|
/**
|
2022-07-05 17:08:35 +02:00
|
|
|
* (C) 2016 - 2021 KISTLER INSTRUMENTE AG, Winterthur, Switzerland
|
2026-01-15 14:38:33 +01:00
|
|
|
* (C) 2016 - 2026 Stanislav Angelovic <stanislav.angelovic@protonmail.com>
|
2020-07-18 20:16:57 +02:00
|
|
|
*
|
|
|
|
|
* @file AdaptorAndProxy_test.cpp
|
|
|
|
|
*
|
|
|
|
|
* Created on: Jan 2, 2017
|
|
|
|
|
* Project: sdbus-c++
|
|
|
|
|
* Description: High-level D-Bus IPC C++ library based on sd-bus
|
|
|
|
|
*
|
|
|
|
|
* This file is part of sdbus-c++.
|
|
|
|
|
*
|
|
|
|
|
* sdbus-c++ is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2.1 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* sdbus-c++ is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
* along with sdbus-c++. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "TestFixture.h"
|
|
|
|
|
#include "TestAdaptor.h"
|
|
|
|
|
#include "TestProxy.h"
|
2026-01-15 14:38:33 +01:00
|
|
|
#include "Defs.h"
|
|
|
|
|
#include <sdbus-c++/sdbus-c++.h>
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2026-01-15 14:38:33 +01:00
|
|
|
#include <cstdint>
|
2020-07-18 20:16:57 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include <gmock/gmock.h>
|
2026-01-15 14:38:33 +01:00
|
|
|
#include <map>
|
2020-07-18 20:16:57 +02:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using ::testing::Eq;
|
|
|
|
|
using ::testing::DoubleEq;
|
2021-06-02 15:17:20 +00:00
|
|
|
using ::testing::NotNull;
|
2020-07-18 20:16:57 +02:00
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
using namespace sdbus::test;
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------*/
|
|
|
|
|
/* -- TEST CASES -- */
|
|
|
|
|
/*-------------------------------------*/
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsSimpleSignalSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitSimpleSignal();
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_TRUE(waitUntil(this->m_proxy->m_gotSimpleSignal));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsSimpleSignalToMultipleProxiesSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
auto proxy1 = std::make_unique<TestProxy>(*this->s_adaptorConnection, SERVICE_NAME, OBJECT_PATH);
|
|
|
|
|
auto proxy2 = std::make_unique<TestProxy>(*this->s_adaptorConnection, SERVICE_NAME, OBJECT_PATH);
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitSimpleSignal();
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_TRUE(waitUntil(this->m_proxy->m_gotSimpleSignal));
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_TRUE(waitUntil(proxy1->m_gotSimpleSignal));
|
|
|
|
|
ASSERT_TRUE(waitUntil(proxy2->m_gotSimpleSignal));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, ProxyDoesNotReceiveSignalFromOtherBusName)
|
2021-03-30 10:53:53 +02:00
|
|
|
{
|
2026-01-15 14:38:33 +01:00
|
|
|
sdbus::ServiceName const otherBusName{SERVICE_NAME + "2"};
|
2024-02-16 18:57:51 +01:00
|
|
|
auto connection2 = sdbus::createBusConnection(otherBusName);
|
2021-10-14 15:53:51 +02:00
|
|
|
auto adaptor2 = std::make_unique<TestAdaptor>(*connection2, OBJECT_PATH);
|
2021-03-30 10:53:53 +02:00
|
|
|
|
|
|
|
|
adaptor2->emitSimpleSignal();
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_FALSE(waitUntil(this->m_proxy->m_gotSimpleSignal, 1s));
|
2021-03-30 10:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsSignalWithMapSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitSignalWithMap({{0, "zero"}, {1, "one"}});
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_TRUE(waitUntil(this->m_proxy->m_gotSignalWithMap));
|
|
|
|
|
ASSERT_THAT(this->m_proxy->m_mapFromSignal[0], Eq("zero"));
|
|
|
|
|
ASSERT_THAT(this->m_proxy->m_mapFromSignal[1], Eq("one"));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsSignalWithLargeMapSuccessfully)
|
2023-01-04 23:11:00 +01:00
|
|
|
{
|
2024-10-10 16:10:20 +02:00
|
|
|
std::map<int32_t, std::string> largeMap;
|
|
|
|
|
for (int32_t i = 0; i < 20'000; ++i)
|
|
|
|
|
largeMap.emplace(i, "This is string nr. " + std::to_string(i+1));
|
|
|
|
|
this->m_adaptor->emitSignalWithMap(largeMap);
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(waitUntil(this->m_proxy->m_gotSignalWithMap));
|
|
|
|
|
ASSERT_THAT(this->m_proxy->m_mapFromSignal[0], Eq("This is string nr. 1"));
|
|
|
|
|
ASSERT_THAT(this->m_proxy->m_mapFromSignal[1], Eq("This is string nr. 2"));
|
2023-01-04 23:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsSignalWithVariantSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2026-01-15 14:38:33 +01:00
|
|
|
double const val = 3.14;
|
|
|
|
|
this->m_adaptor->emitSignalWithVariant(sdbus::Variant{val});
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_TRUE(waitUntil(this->m_proxy->m_gotSignalWithVariant));
|
2026-01-15 14:38:33 +01:00
|
|
|
ASSERT_THAT(this->m_proxy->m_variantFromSignal, DoubleEq(val));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsSignalWithoutRegistrationSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
this->m_adaptor->emitSignalWithoutRegistration({"platform", sdbus::Signature{"av"}});
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_TRUE(waitUntil(this->m_proxy->m_gotSignalWithSignature));
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
ASSERT_THAT(this->m_proxy->m_signatureFromSignal["platform"], Eq(sdbus::Signature{"av"}));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
2021-06-02 15:17:20 +00:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CanAccessAssociatedSignalMessageInSignalHandler)
|
2021-06-02 15:17:20 +00:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitSimpleSignal();
|
2021-06-02 15:17:20 +00:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
waitUntil(this->m_proxy->m_gotSimpleSignal);
|
2021-06-02 15:17:20 +00:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THAT(this->m_proxy->m_signalMsg, NotNull());
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
ASSERT_THAT(this->m_proxy->m_signalName, Eq(std::string("simpleSignal")));
|
2021-06-02 15:17:20 +00:00
|
|
|
}
|
2021-11-28 16:30:49 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, UnregistersSignalHandler)
|
2021-11-28 16:30:49 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_NO_THROW(this->m_proxy->unregisterSimpleSignalHandler());
|
2021-11-28 16:30:49 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitSimpleSignal();
|
2021-11-28 16:30:49 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_FALSE(waitUntil(this->m_proxy->m_gotSimpleSignal, 1s));
|
2021-11-28 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, UnregistersSignalHandlerForSomeProxies)
|
2021-11-28 16:30:49 +02:00
|
|
|
{
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
auto proxy1 = std::make_unique<TestProxy>(*this->s_adaptorConnection, SERVICE_NAME, OBJECT_PATH);
|
|
|
|
|
auto proxy2 = std::make_unique<TestProxy>(*this->s_adaptorConnection, SERVICE_NAME, OBJECT_PATH);
|
2021-11-28 16:30:49 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_NO_THROW(this->m_proxy->unregisterSimpleSignalHandler());
|
2021-11-28 16:30:49 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitSimpleSignal();
|
2021-11-28 16:30:49 +02:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(waitUntil(proxy1->m_gotSimpleSignal));
|
|
|
|
|
ASSERT_TRUE(waitUntil(proxy2->m_gotSimpleSignal));
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_FALSE(waitUntil(this->m_proxy->m_gotSimpleSignal, 1s));
|
2021-11-28 16:30:49 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, ReRegistersSignalHandler)
|
2021-11-28 16:30:49 +02:00
|
|
|
{
|
|
|
|
|
// unregister simple-signal handler
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_NO_THROW(this->m_proxy->unregisterSimpleSignalHandler());
|
2021-11-28 16:30:49 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitSimpleSignal();
|
2021-11-28 16:30:49 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_FALSE(waitUntil(this->m_proxy->m_gotSimpleSignal, 1s));
|
2021-11-28 16:30:49 +02:00
|
|
|
|
|
|
|
|
// re-register simple-signal handler
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_NO_THROW(this->m_proxy->reRegisterSimpleSignalHandler());
|
2021-11-28 16:30:49 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitSimpleSignal();
|
2021-11-28 16:30:49 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_TRUE(waitUntil(this->m_proxy->m_gotSimpleSignal));
|
2021-11-28 16:30:49 +02:00
|
|
|
}
|