2020-07-18 20:16:57 +02:00
|
|
|
/**
|
2022-07-05 17:08:35 +02:00
|
|
|
* (C) 2016 - 2021 KISTLER INSTRUMENTE AG, Winterthur, Switzerland
|
2024-04-16 22:48:34 +02:00
|
|
|
* (C) 2016 - 2024 Stanislav Angelovic <stanislav.angelovic@protonmail.com>
|
2020-07-18 20:16:57 +02:00
|
|
|
*
|
|
|
|
|
* @file DBusStandardInterfacesTests.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"
|
|
|
|
|
#include "sdbus-c++/sdbus-c++.h"
|
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <tuple>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <future>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
using ::testing::Eq;
|
|
|
|
|
using ::testing::DoubleEq;
|
|
|
|
|
using ::testing::Gt;
|
|
|
|
|
using ::testing::AnyOf;
|
|
|
|
|
using ::testing::ElementsAre;
|
|
|
|
|
using ::testing::SizeIs;
|
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
using namespace sdbus::test;
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------*/
|
|
|
|
|
/* -- TEST CASES -- */
|
|
|
|
|
/*-------------------------------------*/
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, PingsViaPeerInterface)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_NO_THROW(this->m_proxy->Ping());
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, AnswersMachineUuidViaPeerInterface)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-09-16 14:28:58 +00:00
|
|
|
if (::access("/etc/machine-id", F_OK) == -1 &&
|
|
|
|
|
::access("/var/lib/dbus/machine-id", F_OK) == -1)
|
|
|
|
|
GTEST_SKIP() << "/etc/machine-id and /var/lib/dbus/machine-id files do not exist, GetMachineId() will not work";
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_NO_THROW(this->m_proxy->GetMachineId());
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Adjust expected xml and uncomment this test
|
2023-01-25 00:02:51 +01:00
|
|
|
//TYPED_TEST(SdbusTestObject, AnswersXmlApiDescriptionViaIntrospectableInterface)
|
2020-07-18 20:16:57 +02:00
|
|
|
//{
|
2023-01-25 00:02:51 +01:00
|
|
|
// ASSERT_THAT(this->m_proxy->Introspect(), Eq(this->m_adaptor->getExpectedXmlApiDescription()));
|
2020-07-18 20:16:57 +02:00
|
|
|
//}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, GetsPropertyViaPropertiesInterface)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THAT(this->m_proxy->Get(INTERFACE_NAME, "state").template get<std::string>(), Eq(DEFAULT_STATE_VALUE));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, GetsPropertyAsynchronouslyViaPropertiesInterface)
|
2023-09-14 10:54:57 +02:00
|
|
|
{
|
|
|
|
|
std::promise<std::string> promise;
|
|
|
|
|
auto future = promise.get_future();
|
|
|
|
|
|
2024-01-10 15:43:37 +01:00
|
|
|
this->m_proxy->GetAsync(INTERFACE_NAME, "state", [&](std::optional<sdbus::Error> err, sdbus::Variant value)
|
2023-09-14 10:54:57 +02:00
|
|
|
{
|
2024-01-10 15:43:37 +01:00
|
|
|
if (!err)
|
2023-09-14 10:54:57 +02:00
|
|
|
promise.set_value(value.get<std::string>());
|
|
|
|
|
else
|
2024-01-10 15:43:37 +01:00
|
|
|
promise.set_exception(std::make_exception_ptr(*std::move(err)));
|
2023-09-14 10:54:57 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(future.get(), Eq(DEFAULT_STATE_VALUE));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, GetsPropertyAsynchronouslyViaPropertiesInterfaceWithFuture)
|
2023-09-14 10:54:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto future = this->m_proxy->GetAsync(INTERFACE_NAME, "state", sdbus::with_future);
|
2023-09-14 10:54:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THAT(future.get().template get<std::string>(), Eq(DEFAULT_STATE_VALUE));
|
2023-09-14 10:54:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, SetsPropertyViaPropertiesInterface)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
uint32_t newActionValue = 2345;
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_proxy->Set(INTERFACE_NAME, "action", sdbus::Variant{newActionValue});
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THAT(this->m_proxy->action(), Eq(newActionValue));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, SetsPropertyAsynchronouslyViaPropertiesInterface)
|
2023-09-14 10:54:57 +02:00
|
|
|
{
|
|
|
|
|
uint32_t newActionValue = 2346;
|
|
|
|
|
std::promise<void> promise;
|
|
|
|
|
auto future = promise.get_future();
|
|
|
|
|
|
2024-01-10 15:43:37 +01:00
|
|
|
this->m_proxy->SetAsync(INTERFACE_NAME, "action", sdbus::Variant{newActionValue}, [&](std::optional<sdbus::Error> err)
|
2023-09-14 10:54:57 +02:00
|
|
|
{
|
2024-01-10 15:43:37 +01:00
|
|
|
if (!err)
|
2023-09-14 10:54:57 +02:00
|
|
|
promise.set_value();
|
|
|
|
|
else
|
2024-01-10 15:43:37 +01:00
|
|
|
promise.set_exception(std::make_exception_ptr(*std::move(err)));
|
2023-09-14 10:54:57 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ASSERT_NO_THROW(future.get());
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THAT(this->m_proxy->action(), Eq(newActionValue));
|
2023-09-14 10:54:57 +02:00
|
|
|
}
|
|
|
|
|
|
2025-05-05 11:18:00 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CancelsAsynchronousPropertySettingViaPropertiesInterface)
|
|
|
|
|
{
|
|
|
|
|
uint32_t newActionValue = 2346;
|
|
|
|
|
std::promise<void> promise;
|
|
|
|
|
auto future = promise.get_future();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto slot = this->m_proxy->SetAsync(INTERFACE_NAME, "action", sdbus::Variant{newActionValue}, [&](std::optional<sdbus::Error> err)
|
|
|
|
|
{
|
|
|
|
|
if (!err)
|
|
|
|
|
promise.set_value();
|
|
|
|
|
else
|
|
|
|
|
promise.set_exception(std::make_exception_ptr(*std::move(err)));
|
|
|
|
|
}, sdbus::return_slot);
|
|
|
|
|
// Now the slot is destroyed, cancelling the async call
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(future.wait_for(300ms), Eq(std::future_status::timeout));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, SetsPropertyAsynchronouslyViaPropertiesInterfaceWithFuture)
|
2023-09-14 10:54:57 +02:00
|
|
|
{
|
|
|
|
|
uint32_t newActionValue = 2347;
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
auto future = this->m_proxy->SetAsync(INTERFACE_NAME, "action", sdbus::Variant{newActionValue}, sdbus::with_future);
|
2023-09-14 10:54:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_NO_THROW(future.get());
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THAT(this->m_proxy->action(), Eq(newActionValue));
|
2023-09-14 10:54:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, GetsAllPropertiesViaPropertiesInterface)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
const auto properties = this->m_proxy->GetAll(INTERFACE_NAME);
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2024-11-20 23:40:30 +01:00
|
|
|
ASSERT_THAT(properties, SizeIs(4));
|
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
|
|
|
EXPECT_THAT(properties.at(STATE_PROPERTY).template get<std::string>(), Eq(DEFAULT_STATE_VALUE));
|
|
|
|
|
EXPECT_THAT(properties.at(ACTION_PROPERTY).template get<uint32_t>(), Eq(DEFAULT_ACTION_VALUE));
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_THAT(properties.at(ACTION_VARIANT_PROPERTY).template get<sdbus::Variant>().template get<std::string>(), Eq(DEFAULT_ACTION_VARIANT_VALUE));
|
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
|
|
|
EXPECT_THAT(properties.at(BLOCKING_PROPERTY).template get<bool>(), Eq(DEFAULT_BLOCKING_VALUE));
|
2023-09-14 10:54:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, GetsAllPropertiesAsynchronouslyViaPropertiesInterface)
|
2023-09-14 10:54: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
|
|
|
std::promise<std::map<sdbus::PropertyName, sdbus::Variant>> promise;
|
2023-09-14 10:54:57 +02:00
|
|
|
auto future = promise.get_future();
|
|
|
|
|
|
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_proxy->GetAllAsync(INTERFACE_NAME, [&](std::optional<sdbus::Error> err, std::map<sdbus::PropertyName, sdbus::Variant> value)
|
2023-09-14 10:54:57 +02:00
|
|
|
{
|
2024-01-10 15:43:37 +01:00
|
|
|
if (!err)
|
2023-09-14 10:54:57 +02:00
|
|
|
promise.set_value(std::move(value));
|
|
|
|
|
else
|
2024-01-10 15:43:37 +01:00
|
|
|
promise.set_exception(std::make_exception_ptr(*std::move(err)));
|
2023-09-14 10:54:57 +02:00
|
|
|
});
|
|
|
|
|
const auto properties = future.get();
|
|
|
|
|
|
2024-11-20 23:40:30 +01:00
|
|
|
ASSERT_THAT(properties, SizeIs(4));
|
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
|
|
|
EXPECT_THAT(properties.at(STATE_PROPERTY).get<std::string>(), Eq(DEFAULT_STATE_VALUE));
|
|
|
|
|
EXPECT_THAT(properties.at(ACTION_PROPERTY).get<uint32_t>(), Eq(DEFAULT_ACTION_VALUE));
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_THAT(properties.at(ACTION_VARIANT_PROPERTY).template get<sdbus::Variant>().template get<std::string>(), Eq(DEFAULT_ACTION_VARIANT_VALUE));
|
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
|
|
|
EXPECT_THAT(properties.at(BLOCKING_PROPERTY).get<bool>(), Eq(DEFAULT_BLOCKING_VALUE));
|
2023-09-14 10:54:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, GetsAllPropertiesAsynchronouslyViaPropertiesInterfaceWithFuture)
|
2023-09-14 10:54:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto future = this->m_proxy->GetAllAsync(INTERFACE_NAME, sdbus::with_future);
|
2023-09-14 10:54:57 +02:00
|
|
|
|
|
|
|
|
auto properties = future.get();
|
|
|
|
|
|
2024-11-20 23:40:30 +01:00
|
|
|
ASSERT_THAT(properties, SizeIs(4));
|
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
|
|
|
EXPECT_THAT(properties.at(STATE_PROPERTY).template get<std::string>(), Eq(DEFAULT_STATE_VALUE));
|
|
|
|
|
EXPECT_THAT(properties.at(ACTION_PROPERTY).template get<uint32_t>(), Eq(DEFAULT_ACTION_VALUE));
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_THAT(properties.at(ACTION_VARIANT_PROPERTY).template get<sdbus::Variant>().template get<std::string>(), Eq(DEFAULT_ACTION_VARIANT_VALUE));
|
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
|
|
|
EXPECT_THAT(properties.at(BLOCKING_PROPERTY).template get<bool>(), Eq(DEFAULT_BLOCKING_VALUE));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsPropertyChangedSignalForSelectedProperties)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
std::atomic<bool> signalReceived{false};
|
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_proxy->m_onPropertiesChangedHandler = [&signalReceived]( const sdbus::InterfaceName& interfaceName
|
|
|
|
|
, const std::map<sdbus::PropertyName, sdbus::Variant>& changedProperties
|
|
|
|
|
, const std::vector<sdbus::PropertyName>& /*invalidatedProperties*/ )
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
EXPECT_THAT(interfaceName, Eq(INTERFACE_NAME));
|
|
|
|
|
EXPECT_THAT(changedProperties, SizeIs(1));
|
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
|
|
|
EXPECT_THAT(changedProperties.at(BLOCKING_PROPERTY).get<bool>(), Eq(!DEFAULT_BLOCKING_VALUE));
|
2020-07-18 20:16:57 +02:00
|
|
|
signalReceived = true;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_proxy->blocking(!DEFAULT_BLOCKING_VALUE);
|
|
|
|
|
this->m_proxy->action(DEFAULT_ACTION_VALUE*2);
|
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->emitPropertiesChangedSignal(INTERFACE_NAME, {BLOCKING_PROPERTY});
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(waitUntil(signalReceived));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsPropertyChangedSignalForAllProperties)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
std::atomic<bool> signalReceived{false};
|
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_proxy->m_onPropertiesChangedHandler = [&signalReceived]( const sdbus::InterfaceName& interfaceName
|
|
|
|
|
, const std::map<sdbus::PropertyName, sdbus::Variant>& changedProperties
|
|
|
|
|
, const std::vector<sdbus::PropertyName>& invalidatedProperties )
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
EXPECT_THAT(interfaceName, Eq(INTERFACE_NAME));
|
|
|
|
|
EXPECT_THAT(changedProperties, SizeIs(1));
|
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
|
|
|
EXPECT_THAT(changedProperties.at(BLOCKING_PROPERTY).get<bool>(), Eq(DEFAULT_BLOCKING_VALUE));
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(invalidatedProperties, SizeIs(1));
|
|
|
|
|
EXPECT_THAT(invalidatedProperties[0], Eq("action"));
|
|
|
|
|
signalReceived = true;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitPropertiesChangedSignal(INTERFACE_NAME);
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(waitUntil(signalReceived));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, GetsZeroManagedObjectsIfHasNoSubPathObjects)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor.reset();
|
|
|
|
|
const auto objectsInterfacesAndProperties = this->m_objectManagerProxy->GetManagedObjects();
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(objectsInterfacesAndProperties, SizeIs(0));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, GetsManagedObjectsSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto adaptor2 = std::make_unique<TestAdaptor>(*this->s_adaptorConnection, OBJECT_PATH_2);
|
|
|
|
|
const auto objectsInterfacesAndProperties = this->m_objectManagerProxy->GetManagedObjects();
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(objectsInterfacesAndProperties, SizeIs(2));
|
2021-10-14 15:53:51 +02:00
|
|
|
EXPECT_THAT(objectsInterfacesAndProperties.at(OBJECT_PATH)
|
2024-04-16 22:28:42 +02:00
|
|
|
.at(sdbus::InterfaceName{org::sdbuscpp::integrationtests_adaptor::INTERFACE_NAME})
|
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
|
|
|
.at(ACTION_PROPERTY).template get<uint32_t>(), Eq(DEFAULT_ACTION_VALUE));
|
2021-10-14 15:53:51 +02:00
|
|
|
EXPECT_THAT(objectsInterfacesAndProperties.at(OBJECT_PATH_2)
|
2024-04-16 22:28:42 +02:00
|
|
|
.at(sdbus::InterfaceName{org::sdbuscpp::integrationtests_adaptor::INTERFACE_NAME})
|
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
|
|
|
.at(ACTION_PROPERTY).template get<uint32_t>(), Eq(DEFAULT_ACTION_VALUE));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2025-05-05 04:31:44 -07:00
|
|
|
TYPED_TEST(SdbusTestObject, GetsManagedObjectsAsynchronously)
|
|
|
|
|
{
|
|
|
|
|
std::promise<size_t> promise;
|
|
|
|
|
auto future = promise.get_future();
|
|
|
|
|
auto adaptor2 = std::make_unique<TestAdaptor>(*this->s_adaptorConnection, OBJECT_PATH_2);
|
|
|
|
|
|
|
|
|
|
this->m_objectManagerProxy->GetManagedObjectsAsync([&](std::optional<sdbus::Error> /*err*/, const std::map<sdbus::ObjectPath, std::map<sdbus::InterfaceName, std::map<sdbus::PropertyName, sdbus::Variant>>>& objectsInterfacesAndProperties)
|
|
|
|
|
{
|
|
|
|
|
promise.set_value(objectsInterfacesAndProperties.size());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(future.get(), Eq(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TYPED_TEST(SdbusTestObject, GetsManagedObjectsAsynchronouslyViaSlotReturningOverload)
|
|
|
|
|
{
|
|
|
|
|
std::promise<size_t> promise;
|
|
|
|
|
auto future = promise.get_future();
|
|
|
|
|
auto adaptor2 = std::make_unique<TestAdaptor>(*this->s_adaptorConnection, OBJECT_PATH_2);
|
|
|
|
|
|
|
|
|
|
auto slot = this->m_objectManagerProxy->GetManagedObjectsAsync([&](std::optional<sdbus::Error> /*err*/, const std::map<sdbus::ObjectPath, std::map<sdbus::InterfaceName, std::map<sdbus::PropertyName, sdbus::Variant>>>& objectsInterfacesAndProperties)
|
|
|
|
|
{
|
|
|
|
|
promise.set_value(objectsInterfacesAndProperties.size());
|
|
|
|
|
}, sdbus::return_slot);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(future.get(), Eq(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TYPED_TEST(SdbusTestObject, GetsManagedObjectsAsynchronouslyViaFutureOverload)
|
|
|
|
|
{
|
|
|
|
|
auto adaptor2 = std::make_unique<TestAdaptor>(*this->s_adaptorConnection, OBJECT_PATH_2);
|
|
|
|
|
|
|
|
|
|
auto future = this->m_objectManagerProxy->GetManagedObjectsAsync(sdbus::with_future);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(future.get().size(), Eq(2));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsInterfacesAddedSignalForSelectedObjectInterfaces)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
std::atomic<bool> signalReceived{false};
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_objectManagerProxy->m_onInterfacesAddedHandler = [&signalReceived]( const sdbus::ObjectPath& objectPath
|
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
|
|
|
, const std::map<sdbus::InterfaceName, std::map<sdbus::PropertyName, sdbus::Variant>>& interfacesAndProperties )
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
EXPECT_THAT(objectPath, Eq(OBJECT_PATH));
|
|
|
|
|
EXPECT_THAT(interfacesAndProperties, SizeIs(1));
|
|
|
|
|
EXPECT_THAT(interfacesAndProperties.count(INTERFACE_NAME), Eq(1));
|
|
|
|
|
#if LIBSYSTEMD_VERSION<=244
|
|
|
|
|
// Up to sd-bus v244, all properties are added to the list, i.e. `state', `action', and `blocking' in this case.
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_THAT(interfacesAndProperties.at(INTERFACE_NAME), SizeIs(4));
|
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
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(STATE_PROPERTY));
|
|
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(ACTION_PROPERTY));
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(ACTION_VARIANT_PROPERTY));
|
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
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(BLOCKING_PROPERTY));
|
2020-07-18 20:16:57 +02:00
|
|
|
#else
|
|
|
|
|
// Since v245 sd-bus does not add to the InterfacesAdded signal message the values of properties marked only
|
|
|
|
|
// for invalidation on change, which makes the behavior consistent with the PropertiesChangedSignal.
|
|
|
|
|
// So in this specific instance, `action' property is no more added to the list.
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_THAT(interfacesAndProperties.at(INTERFACE_NAME), SizeIs(3));
|
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
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(STATE_PROPERTY));
|
|
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(BLOCKING_PROPERTY));
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(ACTION_VARIANT_PROPERTY));
|
2020-07-18 20:16:57 +02:00
|
|
|
#endif
|
|
|
|
|
signalReceived = true;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitInterfacesAddedSignal({INTERFACE_NAME});
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(waitUntil(signalReceived));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsInterfacesAddedSignalForAllObjectInterfaces)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
std::atomic<bool> signalReceived{false};
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_objectManagerProxy->m_onInterfacesAddedHandler = [&signalReceived]( const sdbus::ObjectPath& objectPath
|
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
|
|
|
, const std::map<sdbus::InterfaceName, std::map<sdbus::PropertyName, sdbus::Variant>>& interfacesAndProperties )
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
EXPECT_THAT(objectPath, Eq(OBJECT_PATH));
|
2023-01-02 15:05:57 +01:00
|
|
|
#if LIBSYSTEMD_VERSION<=250
|
2020-07-18 20:16:57 +02:00
|
|
|
EXPECT_THAT(interfacesAndProperties, SizeIs(5)); // INTERFACE_NAME + 4 standard interfaces
|
2023-01-02 15:05:57 +01:00
|
|
|
#else
|
|
|
|
|
// Since systemd v251, ObjectManager standard interface is not listed among the interfaces
|
|
|
|
|
// if the object does not have object manager functionality explicitly enabled.
|
|
|
|
|
EXPECT_THAT(interfacesAndProperties, SizeIs(4)); // INTERFACE_NAME + 3 standard interfaces
|
|
|
|
|
#endif
|
2020-07-18 20:16:57 +02:00
|
|
|
#if LIBSYSTEMD_VERSION<=244
|
|
|
|
|
// Up to sd-bus v244, all properties are added to the list, i.e. `state', `action', and `blocking' in this case.
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_THAT(interfacesAndProperties.at(INTERFACE_NAME), SizeIs(4));
|
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
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(STATE_PROPERTY));
|
|
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(ACTION_PROPERTY));
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(ACTION_VARIANT_PROPERTY));
|
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
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(BLOCKING_PROPERTY));
|
2020-07-18 20:16:57 +02:00
|
|
|
#else
|
|
|
|
|
// Since v245 sd-bus does not add to the InterfacesAdded signal message the values of properties marked only
|
|
|
|
|
// for invalidation on change, which makes the behavior consistent with the PropertiesChangedSignal.
|
|
|
|
|
// So in this specific instance, `action' property is no more added to the list.
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_THAT(interfacesAndProperties.at(INTERFACE_NAME), SizeIs(3));
|
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
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(STATE_PROPERTY));
|
|
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(BLOCKING_PROPERTY));
|
2024-11-20 23:40:30 +01:00
|
|
|
EXPECT_TRUE(interfacesAndProperties.at(INTERFACE_NAME).count(ACTION_VARIANT_PROPERTY));
|
2020-07-18 20:16:57 +02:00
|
|
|
#endif
|
|
|
|
|
signalReceived = true;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitInterfacesAddedSignal();
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(waitUntil(signalReceived));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsInterfacesRemovedSignalForSelectedObjectInterfaces)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
std::atomic<bool> signalReceived{false};
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_objectManagerProxy->m_onInterfacesRemovedHandler = [&signalReceived]( const sdbus::ObjectPath& objectPath
|
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
|
|
|
, const std::vector<sdbus::InterfaceName>& interfaces )
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
EXPECT_THAT(objectPath, Eq(OBJECT_PATH));
|
|
|
|
|
ASSERT_THAT(interfaces, SizeIs(1));
|
|
|
|
|
EXPECT_THAT(interfaces[0], Eq(INTERFACE_NAME));
|
|
|
|
|
signalReceived = true;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitInterfacesRemovedSignal({INTERFACE_NAME});
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(waitUntil(signalReceived));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, EmitsInterfacesRemovedSignalForAllObjectInterfaces)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
std::atomic<bool> signalReceived{false};
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_objectManagerProxy->m_onInterfacesRemovedHandler = [&signalReceived]( const sdbus::ObjectPath& objectPath
|
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
|
|
|
, const std::vector<sdbus::InterfaceName>& interfaces )
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
EXPECT_THAT(objectPath, Eq(OBJECT_PATH));
|
2023-01-02 15:05:57 +01:00
|
|
|
#if LIBSYSTEMD_VERSION<=250
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(interfaces, SizeIs(5)); // INTERFACE_NAME + 4 standard interfaces
|
2023-01-02 15:05:57 +01:00
|
|
|
#else
|
|
|
|
|
// Since systemd v251, ObjectManager standard interface is not listed among the interfaces
|
|
|
|
|
// if the object does not have object manager functionality explicitly enabled.
|
|
|
|
|
ASSERT_THAT(interfaces, SizeIs(4)); // INTERFACE_NAME + 3 standard interfaces
|
|
|
|
|
#endif
|
2020-07-18 20:16:57 +02:00
|
|
|
signalReceived = true;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_adaptor->emitInterfacesRemovedSignal();
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_TRUE(waitUntil(signalReceived));
|
|
|
|
|
}
|