temp: all

This commit is contained in:
Stanislav Angelovic
2023-01-21 01:16:51 +01:00
parent 3acd20c2fd
commit 7589ed1d83
113 changed files with 19998 additions and 465 deletions
@@ -69,7 +69,7 @@ TYPED_TEST(AsyncSdbusTestObject, ThrowsTimeoutErrorWhenClientSideAsyncMethodTime
});
start = std::chrono::steady_clock::now();
this->m_proxy->doOperationClientSideAsyncWithTimeout(1us, 1000); // The operation will take 1s, but the timeout is 1us, so we should time out
this->m_proxy->doOperationClientSideAsyncWithTimeout(1us, (1s).count()); // The operation will take 1s, but the timeout is 1us, so we should time out
future.get();
FAIL() << "Expected sdbus::Error exception";
+1 -43
View File
@@ -41,7 +41,6 @@
using ::testing::Eq;
using namespace sdbus::test;
using namespace std::chrono_literals;
/*-------------------------------------*/
/* -- TEST CASES -- */
@@ -80,7 +79,7 @@ TEST(Connection, CannotReleaseNonrequestedName)
ASSERT_THROW(connection->releaseName("some.random.nonrequested.name"), sdbus::Error);
}
TEST(Connection, CanEnterAndLeaveEventLoop)
TEST(Connection, CanEnterAndLeaveInternalEventLoop)
{
auto connection = sdbus::createConnection();
connection->requestName(BUS_NAME);
@@ -90,44 +89,3 @@ TEST(Connection, CanEnterAndLeaveEventLoop)
t.join();
}
TEST(Connection, PollDataGetZeroTimeout)
{
sdbus::IConnection::PollData pd{};
pd.timeout_usec = 0;
ASSERT_TRUE(pd.getRelativeTimeout().has_value());
EXPECT_THAT(pd.getRelativeTimeout().value(), Eq(std::chrono::microseconds::zero()));
EXPECT_THAT(pd.getPollTimeout(), Eq(0));
}
TEST(Connection, PollDataGetInfiniteTimeout)
{
sdbus::IConnection::PollData pd{};
pd.timeout_usec = UINT64_MAX;
ASSERT_FALSE(pd.getRelativeTimeout().has_value());
EXPECT_THAT(pd.getPollTimeout(), Eq(-1));
}
TEST(Connection, PollDataGetZeroRelativeTimeoutForPast)
{
sdbus::IConnection::PollData pd{};
auto past = std::chrono::steady_clock::now() - 10s;
pd.timeout_usec = std::chrono::duration_cast<std::chrono::microseconds>(past.time_since_epoch()).count();
ASSERT_TRUE(pd.getRelativeTimeout().has_value());
EXPECT_THAT(pd.getRelativeTimeout().value(), Eq(0us));
EXPECT_THAT(pd.getPollTimeout(), Eq(0));
}
TEST(Connection, PollDataGetRelativeTimeoutInTolerance)
{
sdbus::IConnection::PollData pd{};
constexpr auto TIMEOUT = 1s;
constexpr auto TOLERANCE = 100ms;
auto future = std::chrono::steady_clock::now() + TIMEOUT;
pd.timeout_usec = std::chrono::duration_cast<std::chrono::microseconds>(future.time_since_epoch()).count();
ASSERT_TRUE(pd.getRelativeTimeout().has_value());
EXPECT_GE(pd.getRelativeTimeout().value(), TIMEOUT - TOLERANCE);
EXPECT_LE(pd.getRelativeTimeout().value(), TIMEOUT + TOLERANCE);
EXPECT_GE(pd.getPollTimeout(), 900);
EXPECT_LE(pd.getPollTimeout(), 1100);
}
+2 -2
View File
@@ -98,7 +98,7 @@ TYPED_TEST(AConnection, WillUnsubscribeMatchRuleWhenClientDestroysTheAssociatedS
this->m_adaptor->emitSimpleSignal();
ASSERT_FALSE(this->waitUntil(matchingMessageReceived, 2s));
ASSERT_FALSE(this->waitUntil(matchingMessageReceived, 1s));
}
TYPED_TEST(AConnection, CanAddFloatingMatchRule)
@@ -121,7 +121,7 @@ TYPED_TEST(AConnection, CanAddFloatingMatchRule)
con.reset();
this->m_adaptor->emitSimpleSignal();
ASSERT_FALSE(this->waitUntil(matchingMessageReceived, 2s));
ASSERT_FALSE(this->waitUntil(matchingMessageReceived, 1s));
}
TYPED_TEST(AConnection, WillNotPassToMatchCallbackMessagesThatDoNotMatchTheRule)
+4 -4
View File
@@ -161,7 +161,7 @@ TYPED_TEST(SdbusTestObject, CallsMultiplyMethodWithNoReplyFlag)
TYPED_TEST(SdbusTestObject, CallsMethodWithCustomTimeoutSuccessfully)
{
auto res = this->m_proxy->doOperationWithTimeout(500ms, 20); // The operation will take 20ms, but the timeout is 500ms, so we are fine
auto res = this->m_proxy->doOperationWithTimeout(500ms, (20ms).count()); // The operation will take 20ms, but the timeout is 500ms, so we are fine
ASSERT_THAT(res, Eq(20));
}
@@ -170,7 +170,7 @@ TYPED_TEST(SdbusTestObject, ThrowsTimeoutErrorWhenMethodTimesOut)
auto start = std::chrono::steady_clock::now();
try
{
this->m_proxy->doOperationWithTimeout(1us, 1000); // The operation will take 1s, but the timeout is 1us, so we should time out
this->m_proxy->doOperationWithTimeout(1us, (1s).count()); // The operation will take 1s, but the timeout is 1us, so we should time out
FAIL() << "Expected sdbus::Error exception";
}
catch (const sdbus::Error& e)
@@ -237,8 +237,8 @@ TYPED_TEST(SdbusTestObject, CanReceiveSignalWhileMakingMethodCall)
{
this->m_proxy->emitTwoSimpleSignals();
ASSERT_TRUE(this->waitUntil(this->m_proxy->m_gotSimpleSignal));
ASSERT_TRUE(this->waitUntil(this->m_proxy->m_gotSignalWithMap));
EXPECT_TRUE(this->waitUntil(this->m_proxy->m_gotSimpleSignal));
EXPECT_TRUE(this->waitUntil(this->m_proxy->m_gotSignalWithMap));
}
TYPED_TEST(SdbusTestObject, CanAccessAssociatedMethodCallMessageInMethodCallHandler)
+4 -4
View File
@@ -75,7 +75,7 @@ TYPED_TEST(SdbusTestObject, ProxyDoesNotReceiveSignalFromOtherBusName)
adaptor2->emitSimpleSignal();
ASSERT_FALSE(this->waitUntil(this->m_proxy->m_gotSimpleSignal, 2s));
ASSERT_FALSE(this->waitUntil(this->m_proxy->m_gotSimpleSignal, 1s));
}
TYPED_TEST(SdbusTestObject, EmitsSignalWithMapSuccesfully)
@@ -132,7 +132,7 @@ TYPED_TEST(SdbusTestObject, UnregistersSignalHandler)
this->m_adaptor->emitSimpleSignal();
ASSERT_FALSE(this->waitUntil(this->m_proxy->m_gotSimpleSignal, 2s));
ASSERT_FALSE(this->waitUntil(this->m_proxy->m_gotSimpleSignal, 1s));
}
TYPED_TEST(SdbusTestObject, UnregistersSignalHandlerForSomeProxies)
@@ -146,7 +146,7 @@ TYPED_TEST(SdbusTestObject, UnregistersSignalHandlerForSomeProxies)
ASSERT_TRUE(this->waitUntil(proxy1->m_gotSimpleSignal));
ASSERT_TRUE(this->waitUntil(proxy2->m_gotSimpleSignal));
ASSERT_FALSE(this->waitUntil(this->m_proxy->m_gotSimpleSignal, 2s));
ASSERT_FALSE(this->waitUntil(this->m_proxy->m_gotSimpleSignal, 1s));
}
TYPED_TEST(SdbusTestObject, ReRegistersSignalHandler)
@@ -156,7 +156,7 @@ TYPED_TEST(SdbusTestObject, ReRegistersSignalHandler)
this->m_adaptor->emitSimpleSignal();
ASSERT_FALSE(this->waitUntil(this->m_proxy->m_gotSimpleSignal, 2s));
ASSERT_FALSE(this->waitUntil(this->m_proxy->m_gotSimpleSignal, 1s));
// re-register simple-signal handler
ASSERT_NO_THROW(this->m_proxy->reRegisterSimpleSignalHandler());
+4 -2
View File
@@ -31,8 +31,10 @@ namespace sdbus { namespace test {
std::unique_ptr<sdbus::IConnection> BaseTestFixture::s_adaptorConnection = sdbus::createSystemBusConnection();
std::unique_ptr<sdbus::IConnection> BaseTestFixture::s_proxyConnection = sdbus::createSystemBusConnection();
std::thread TestFixture<SdEventLoop>::s_eventLoopThread{};
sd_event *TestFixture<SdEventLoop>::s_sdEvent{};
std::thread TestFixture<SdEventLoop>::s_adaptorEventLoopThread{};
std::thread TestFixture<SdEventLoop>::s_proxyEventLoopThread{};
sd_event *TestFixture<SdEventLoop>::s_adaptorSdEvent{};
sd_event *TestFixture<SdEventLoop>::s_proxySdEvent{};
int TestFixture<SdEventLoop>::s_eventExitFd{-1};
}}
+20 -10
View File
@@ -137,18 +137,24 @@ class TestFixture<SdEventLoop> : public BaseTestFixture
public:
static void SetUpTestCase()
{
sd_event_new(&s_sdEvent);
sd_event_new(&s_adaptorSdEvent);
sd_event_new(&s_proxySdEvent);
s_proxyConnection->attachSdEventLoop(s_sdEvent);
s_adaptorConnection->attachSdEventLoop(s_sdEvent);
s_adaptorConnection->attachSdEventLoop(s_adaptorSdEvent);
s_proxyConnection->attachSdEventLoop(s_proxySdEvent);
s_eventExitFd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
// No callback means that the event loop will exit when this event source triggers
sd_event_add_io(s_sdEvent, nullptr, s_eventExitFd, EPOLLIN, nullptr, NULL);
sd_event_add_io(s_adaptorSdEvent, nullptr, s_eventExitFd, EPOLLIN, nullptr, NULL);
sd_event_add_io(s_proxySdEvent, nullptr, s_eventExitFd, EPOLLIN, nullptr, NULL);
s_eventLoopThread = std::thread([]()
s_adaptorEventLoopThread = std::thread([]()
{
sd_event_loop(s_sdEvent);
sd_event_loop(s_adaptorSdEvent);
});
s_proxyEventLoopThread = std::thread([]()
{
sd_event_loop(s_proxySdEvent);
});
BaseTestFixture::SetUpTestCase();
@@ -160,17 +166,21 @@ public:
uint64_t value = 1;
write(s_eventExitFd, &value, sizeof(value));
s_eventLoopThread.join();
s_adaptorEventLoopThread.join();
s_proxyEventLoopThread.join();
sd_event_unref(s_sdEvent);
sd_event_unref(s_adaptorSdEvent);
sd_event_unref(s_proxySdEvent);
close(s_eventExitFd);
BaseTestFixture::TearDownTestCase();
}
private:
static std::thread s_eventLoopThread;
static sd_event *s_sdEvent;
static std::thread s_adaptorEventLoopThread;
static std::thread s_proxyEventLoopThread;
static sd_event *s_adaptorSdEvent;
static sd_event *s_proxySdEvent;
static int s_eventExitFd;
};
@@ -43,7 +43,7 @@ protected:
object_->registerMethod("throwError").onInterface(INTERFACE_NAME).implementedAs([this](){ return this->throwError(); });
object_->registerMethod("throwErrorWithNoReply").onInterface(INTERFACE_NAME).implementedAs([this](){ return this->throwErrorWithNoReply(); }).withNoReply();
object_->registerMethod("doPrivilegedStuff").onInterface(INTERFACE_NAME).implementedAs([this](){ return this->doPrivilegedStuff(); }).markAsPrivileged();
object_->registerMethod("emitTwoSimpleSignals").onInterface(INTERFACE_NAME).implementedAs([this](){ return this->emitTwoSimpleSignals(); });
object_->registerMethod("emitTwoSimpleSignals").onInterface(INTERFACE_NAME).implementedAs([this](){ return this->emitTwoSimpleSignals(); })/*.withNoReply()*/;
object_->registerSignal("simpleSignal").onInterface(INTERFACE_NAME).markAsDeprecated();
object_->registerSignal("signalWithMap").onInterface(INTERFACE_NAME).withParameters<std::map<int32_t, std::string>>("aMap");
object_->registerSignal("signalWithVariant").onInterface(INTERFACE_NAME).withParameters<sdbus::Variant>("aVariant");
@@ -171,7 +171,7 @@ public:
void emitTwoSimpleSignals()
{
proxy_->callMethod("emitTwoSimpleSignals").onInterface(INTERFACE_NAME);
proxy_->callMethod("emitTwoSimpleSignals").onInterface(INTERFACE_NAME)/*.dontExpectReply()*/;
}
void unregisterSimpleSignalHandler()