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 DBusMethodsTests.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;
|
2021-12-20 10:00:29 +01:00
|
|
|
using ::testing::Le;
|
2020-07-18 20:16:57 +02:00
|
|
|
using ::testing::AnyOf;
|
|
|
|
|
using ::testing::ElementsAre;
|
|
|
|
|
using ::testing::SizeIs;
|
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, CallsEmptyMethodSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_NO_THROW(this->m_proxy->noArgNoReturn());
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodsWithBaseTypesSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto resInt = this->m_proxy->getInt();
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(resInt, Eq(INT32_VALUE));
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
auto multiplyRes = this->m_proxy->multiply(INT64_VALUE, DOUBLE_VALUE);
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(multiplyRes, Eq(INT64_VALUE * DOUBLE_VALUE));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodsWithTuplesSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto resTuple = this->m_proxy->getTuple();
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(std::get<0>(resTuple), Eq(UINT32_VALUE));
|
|
|
|
|
ASSERT_THAT(std::get<1>(resTuple), Eq(STRING_VALUE));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodsWithStructSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
sdbus::Struct<uint8_t, int16_t, double, std::string, std::vector<int16_t>> a{};
|
2023-01-25 00:02:51 +01:00
|
|
|
auto vectorRes = this->m_proxy->getInts16FromStruct(a);
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(vectorRes, Eq(std::vector<int16_t>{0})); // because second item is by default initialized to 0
|
|
|
|
|
|
|
|
|
|
sdbus::Struct<uint8_t, int16_t, double, std::string, std::vector<int16_t>> b{
|
|
|
|
|
UINT8_VALUE, INT16_VALUE, DOUBLE_VALUE, STRING_VALUE, {INT16_VALUE, -INT16_VALUE}
|
|
|
|
|
};
|
2023-01-25 00:02:51 +01:00
|
|
|
vectorRes = this->m_proxy->getInts16FromStruct(b);
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(vectorRes, Eq(std::vector<int16_t>{INT16_VALUE, INT16_VALUE, -INT16_VALUE}));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithVariantSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
sdbus::Variant v{DOUBLE_VALUE};
|
2023-01-25 00:02:51 +01:00
|
|
|
sdbus::Variant variantRes = this->m_proxy->processVariant(v);
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(variantRes.get<int32_t>(), Eq(static_cast<int32_t>(DOUBLE_VALUE)));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithStdVariantSuccessfully)
|
2024-04-02 16:44:45 +02:00
|
|
|
{
|
|
|
|
|
std::variant<int32_t, double, std::string> v{DOUBLE_VALUE};
|
2023-01-25 00:02:51 +01:00
|
|
|
auto variantRes = this->m_proxy->processVariant(v);
|
2024-04-02 16:44:45 +02:00
|
|
|
ASSERT_THAT(std::get<int32_t>(variantRes), Eq(static_cast<int32_t>(DOUBLE_VALUE)));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithStructVariantsAndGetMapSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
std::vector<int32_t> x{-2, 0, 2};
|
|
|
|
|
sdbus::Struct<sdbus::Variant, sdbus::Variant> y{false, true};
|
2023-01-25 00:02:51 +01:00
|
|
|
std::map<int32_t, sdbus::Variant> mapOfVariants = this->m_proxy->getMapOfVariants(x, y);
|
2024-04-03 20:40:28 +02:00
|
|
|
decltype(mapOfVariants) res{ {-2, sdbus::Variant{false}}
|
|
|
|
|
, {0, sdbus::Variant{false}}
|
|
|
|
|
, {2, sdbus::Variant{true}}};
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(mapOfVariants[-2].get<bool>(), Eq(res[-2].get<bool>()));
|
|
|
|
|
ASSERT_THAT(mapOfVariants[0].get<bool>(), Eq(res[0].get<bool>()));
|
|
|
|
|
ASSERT_THAT(mapOfVariants[2].get<bool>(), Eq(res[2].get<bool>()));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithStructInStructSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto val = this->m_proxy->getStructInStruct();
|
|
|
|
|
ASSERT_THAT(val.template get<0>(), Eq(STRING_VALUE));
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(std::get<0>(std::get<1>(val))[INT32_VALUE], Eq(INT32_VALUE));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithTwoStructsSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto val = this->m_proxy->sumStructItems({1, 2}, {3, 4});
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(val, Eq(1 + 2 + 3 + 4));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithTwoVectorsSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto val = this->m_proxy->sumArrayItems({1, 7}, {2, 3, 4});
|
2023-08-03 13:55:37 +02:00
|
|
|
ASSERT_THAT(val, Eq(1 + 7 + 2 + 3 + 4));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithSignatureSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto resSignature = this->m_proxy->getSignature();
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(resSignature, Eq(SIGNATURE_VALUE));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithObjectPathSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto resObjectPath = this->m_proxy->getObjPath();
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(resObjectPath, Eq(OBJECT_PATH_VALUE));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithUnixFdSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto resUnixFd = this->m_proxy->getUnixFd();
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(resUnixFd.get(), Gt(UNIX_FD_VALUE));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithComplexTypeSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto resComplex = this->m_proxy->getComplex();
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(resComplex.count(0), Eq(1));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMultiplyMethodWithNoReplyFlag)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_proxy->multiplyWithNoReply(INT64_VALUE, DOUBLE_VALUE);
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_TRUE(waitUntil(this->m_adaptor->m_wasMultiplyCalled));
|
|
|
|
|
ASSERT_THAT(this->m_adaptor->m_multiplyResult, Eq(INT64_VALUE * DOUBLE_VALUE));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithCustomTimeoutSuccessfully)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
auto res = this->m_proxy->doOperationWithTimeout(500ms, (20ms).count()); // The operation will take 20ms, but the timeout is 500ms, so we are fine
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THAT(res, Eq(20));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, ThrowsTimeoutErrorWhenMethodTimesOut)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2021-12-20 10:00:29 +01:00
|
|
|
auto start = std::chrono::steady_clock::now();
|
2020-07-18 20:16:57 +02:00
|
|
|
try
|
|
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_proxy->doOperationWithTimeout(1us, (1s).count()); // The operation will take 1s, but the timeout is 1us, so we should time out
|
2020-07-18 20:16:57 +02:00
|
|
|
FAIL() << "Expected sdbus::Error exception";
|
|
|
|
|
}
|
|
|
|
|
catch (const sdbus::Error& e)
|
|
|
|
|
{
|
|
|
|
|
ASSERT_THAT(e.getName(), AnyOf("org.freedesktop.DBus.Error.Timeout", "org.freedesktop.DBus.Error.NoReply"));
|
2023-10-04 13:48:51 +00:00
|
|
|
ASSERT_THAT(e.getMessage(), AnyOf("Connection timed out", "Operation timed out", "Method call timed out"));
|
2021-12-20 10:00:29 +01:00
|
|
|
auto measuredTimeout = std::chrono::steady_clock::now() - start;
|
|
|
|
|
ASSERT_THAT(measuredTimeout, Le(50ms));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
|
FAIL() << "Expected sdbus::Error exception";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodThatThrowsError)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_proxy->throwError();
|
2020-07-18 20:16:57 +02:00
|
|
|
FAIL() << "Expected sdbus::Error exception";
|
|
|
|
|
}
|
|
|
|
|
catch (const sdbus::Error& e)
|
|
|
|
|
{
|
|
|
|
|
ASSERT_THAT(e.getName(), Eq("org.freedesktop.DBus.Error.AccessDenied"));
|
|
|
|
|
ASSERT_THAT(e.getMessage(), Eq("A test error occurred (Operation not permitted)"));
|
|
|
|
|
}
|
|
|
|
|
catch(...)
|
|
|
|
|
{
|
|
|
|
|
FAIL() << "Expected sdbus::Error exception";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsErrorThrowingMethodWithDontExpectReplySet)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_NO_THROW(this->m_proxy->throwErrorWithNoReply());
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_TRUE(waitUntil(this->m_adaptor->m_wasThrowErrorCalled));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, FailsCallingNonexistentMethod)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THROW(this->m_proxy->callNonexistentMethod(), sdbus::Error);
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, FailsCallingMethodOnNonexistentInterface)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THROW(this->m_proxy->callMethodOnNonexistentInterface(), sdbus::Error);
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, FailsCallingMethodOnNonexistentDestination)
|
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
|
|
|
TestProxy proxy(sdbus::ServiceName{"sdbuscpp.destination.that.does.not.exist"}, OBJECT_PATH);
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THROW(proxy.getInt(), sdbus::Error);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, FailsCallingMethodOnNonexistentObject)
|
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
|
|
|
TestProxy proxy(SERVICE_NAME, sdbus::ObjectPath{"/sdbuscpp/path/that/does/not/exist"});
|
2020-07-18 20:16:57 +02:00
|
|
|
ASSERT_THROW(proxy.getInt(), sdbus::Error);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CanReceiveSignalWhileMakingMethodCall)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_proxy->emitTwoSimpleSignals();
|
2020-07-18 20:16:57 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
EXPECT_TRUE(waitUntil(this->m_proxy->m_gotSimpleSignal));
|
|
|
|
|
EXPECT_TRUE(waitUntil(this->m_proxy->m_gotSignalWithMap));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CanAccessAssociatedMethodCallMessageInMethodCallHandler)
|
2021-06-02 15:17:20 +00:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_proxy->doOperation(10); // This will save pointer to method call message on server side
|
2021-06-02 15:17:20 +00:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THAT(this->m_adaptor->m_methodCallMsg, 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_adaptor->m_methodName, Eq("doOperation"));
|
2021-06-02 15:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CanAccessAssociatedMethodCallMessageInAsyncMethodCallHandler)
|
2021-06-02 15:17:20 +00:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->m_proxy->doOperationAsync(10); // This will save pointer to method call message on server side
|
2021-06-02 15:17:20 +00:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THAT(this->m_adaptor->m_methodCallMsg, 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_adaptor->m_methodName, Eq("doOperationAsync"));
|
2021-06-02 15:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:10:20 +02:00
|
|
|
TYPED_TEST(SdbusTestObject, CallsMethodWithLargeArgument)
|
|
|
|
|
{
|
|
|
|
|
std::map<int, std::string> collection;
|
|
|
|
|
//std::size_t totalSize{};
|
|
|
|
|
for (int i = 0; i < 400'000; i++)
|
|
|
|
|
{
|
|
|
|
|
collection[i] = ("This is a string of fifty characters. This is a string of fifty " + std::to_string(i));
|
|
|
|
|
//totalSize += sizeof(int) + collection[i].size();
|
|
|
|
|
}
|
|
|
|
|
//printf("Sending large message with collection of size %zu bytes\n", totalSize);
|
|
|
|
|
this->m_proxy->sendLargeMessage(collection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TYPED_TEST(SdbusTestObject, CanSendCallsAndReceiveRepliesWithLargeData)
|
|
|
|
|
{
|
|
|
|
|
std::map<int32_t, std::string> largeMap;
|
|
|
|
|
for (int32_t i = 0; i < 40'000; ++i)
|
|
|
|
|
largeMap.emplace(i, "This is string nr. " + std::to_string(i+1));
|
|
|
|
|
|
|
|
|
|
auto returnedMap = this->m_proxy->doOperationWithLargeData(largeMap);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(returnedMap, Eq(largeMap));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 20:16:57 +02:00
|
|
|
#if LIBSYSTEMD_VERSION>=240
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CanSetGeneralMethodTimeoutWithLibsystemdVersionGreaterThan239)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
this->s_adaptorConnection->setMethodCallTimeout(5000000);
|
|
|
|
|
ASSERT_THAT(this->s_adaptorConnection->getMethodCallTimeout(), Eq(5000000));
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
#else
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CannotSetGeneralMethodTimeoutWithLibsystemdVersionLessThan240)
|
2020-07-18 20:16:57 +02:00
|
|
|
{
|
2023-01-25 00:02:51 +01:00
|
|
|
ASSERT_THROW(this->s_adaptorConnection->setMethodCallTimeout(5000000), sdbus::Error);
|
|
|
|
|
ASSERT_THROW(this->s_adaptorConnection->getMethodCallTimeout(), sdbus::Error);
|
2020-07-18 20:16:57 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
2022-08-03 00:38:34 +02:00
|
|
|
|
2023-01-25 00:02:51 +01:00
|
|
|
TYPED_TEST(SdbusTestObject, CanCallMethodSynchronouslyWithoutAnEventLoopThread)
|
2022-08-03 00:38:34 +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 proxy = std::make_unique<TestProxy>(SERVICE_NAME, OBJECT_PATH, sdbus::dont_run_event_loop_thread);
|
2022-08-03 00:38:34 +02:00
|
|
|
|
|
|
|
|
auto multiplyRes = proxy->multiply(INT64_VALUE, DOUBLE_VALUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(multiplyRes, Eq(INT64_VALUE * DOUBLE_VALUE));
|
|
|
|
|
}
|
2023-12-30 18:40:38 +01:00
|
|
|
|
|
|
|
|
TYPED_TEST(SdbusTestObject, CanRegisterAdditionalVTableDynamicallyAtAnyTime)
|
|
|
|
|
{
|
|
|
|
|
auto& object = this->m_adaptor->getObject();
|
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
|
|
|
sdbus::InterfaceName interfaceName{"org.sdbuscpp.integrationtests2"};
|
|
|
|
|
auto vtableSlot = object.addVTable( interfaceName
|
2023-12-30 18:40:38 +01:00
|
|
|
, { sdbus::registerMethod("add").implementedAs([](const int64_t& a, const double& b){ return a + b; })
|
2023-12-30 19:22:45 +01:00
|
|
|
, sdbus::registerMethod("subtract").implementedAs([](const int& a, const int& b){ return a - b; }) }
|
|
|
|
|
, sdbus::return_slot );
|
2023-12-30 18:40:38 +01:00
|
|
|
|
|
|
|
|
// The new remote vtable is registered as long as we keep vtableSlot, so remote method calls now should pass
|
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 proxy = sdbus::createProxy(SERVICE_NAME, OBJECT_PATH, sdbus::dont_run_event_loop_thread);
|
2023-12-30 18:40:38 +01:00
|
|
|
int result{};
|
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
|
|
|
proxy->callMethod("subtract").onInterface(interfaceName).withArguments(10, 2).storeResultsTo(result);
|
2023-12-30 18:40:38 +01:00
|
|
|
|
|
|
|
|
ASSERT_THAT(result, Eq(8));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TYPED_TEST(SdbusTestObject, CanUnregisterAdditionallyRegisteredVTableAtAnyTime)
|
|
|
|
|
{
|
|
|
|
|
auto& object = this->m_adaptor->getObject();
|
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
|
|
|
sdbus::InterfaceName interfaceName{"org.sdbuscpp.integrationtests2"};
|
2023-12-30 18:40:38 +01: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 vtableSlot = object.addVTable( interfaceName
|
2023-12-30 18:40:38 +01:00
|
|
|
, { sdbus::registerMethod("add").implementedAs([](const int64_t& a, const double& b){ return a + b; })
|
2023-12-30 19:22:45 +01:00
|
|
|
, sdbus::registerMethod("subtract").implementedAs([](const int& a, const int& b){ return a - b; }) }
|
|
|
|
|
, sdbus::return_slot );
|
2023-12-30 18:40:38 +01:00
|
|
|
vtableSlot.reset(); // Letting the slot go means letting go the associated vtable registration
|
|
|
|
|
|
|
|
|
|
// No such remote D-Bus method under given interface exists anymore...
|
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 proxy = sdbus::createProxy(SERVICE_NAME, OBJECT_PATH, sdbus::dont_run_event_loop_thread);
|
|
|
|
|
ASSERT_THROW(proxy->callMethod("subtract").onInterface(interfaceName).withArguments(10, 2), sdbus::Error);
|
2023-12-30 18:40:38 +01:00
|
|
|
}
|