diff options
author | Stefan Laner <laner@itestra.de> | 2014-04-09 15:53:09 +0200 |
---|---|---|
committer | Stefan Laner <laner@itestra.de> | 2014-04-09 15:57:04 +0200 |
commit | cfa691dead04acffe08155733689f1932054f425 (patch) | |
tree | 7d237f3b9ed72b8ef6c5701669dea05e5099b4f7 | |
parent | c65f551cd7ed799d0aafd5de8584c98236f65de6 (diff) | |
download | genivi-common-api-dbus-runtime-cfa691dead04acffe08155733689f1932054f425.tar.gz |
improved DBusBroadcastTest and DBusLoadTest
Change-Id: I413fd262a1c965f8c915180d092408f56f57356e
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | src/test/DBusBroadcastTest.cpp | 43 | ||||
-rw-r--r-- | src/test/DBusLoadTest.cpp | 10 |
3 files changed, 50 insertions, 6 deletions
@@ -56,3 +56,6 @@ /DBusSelectiveBroadcastTest /DBusManagedTest /DBusPolymorphicTest +/DBusBroadcastTest +/DBusFreedesktopPropertiesTest +/DBusLoadTest diff --git a/src/test/DBusBroadcastTest.cpp b/src/test/DBusBroadcastTest.cpp index 9905155..646e663 100644 --- a/src/test/DBusBroadcastTest.cpp +++ b/src/test/DBusBroadcastTest.cpp @@ -170,7 +170,8 @@ TEST_F(DBusBroadcastTest, ProxysCanHandleBroadcast) { bool callbackArrived = false; broadcastEvent.subscribeCancellableListener([&](uint32_t intParam, std::string stringParam) -> CommonAPI::SubscriptionStatus { - callbackArrived = true; return CommonAPI::SubscriptionStatus::RETAIN; + callbackArrived = true; + return CommonAPI::SubscriptionStatus::RETAIN; }); stub->fireTestPredefinedTypeBroadcastEvent(2, "xyz"); @@ -235,6 +236,43 @@ TEST_F(DBusBroadcastTest, ProxysCanUnsubscribeFromBroadcastAndSubscribeAgain) { broadcastEvent.unsubscribe(broadcastSubscription2); } +TEST_F(DBusBroadcastTest, ProxysCanUnsubscribeFromBroadcastAndSubscribeAgainInALoop) { + auto stub = std::make_shared<SelectiveBroadcastSender>(); + + bool serviceRegistered = servicePublisher_->registerService(stub, serviceAddress_, stubFactory_); + for (unsigned int i = 0; !serviceRegistered && i < 100; ++i) { + serviceRegistered = servicePublisher_->registerService(stub, serviceAddress_, stubFactory_); + usleep(10000); + } + ASSERT_TRUE(serviceRegistered); + + + auto proxy = proxyFactory_->buildProxy<commonapi::tests::TestInterfaceProxy>(serviceAddress_); + + commonapi::tests::TestInterfaceProxyDefault::TestPredefinedTypeBroadcastEvent& broadcastEvent = + proxy->getTestPredefinedTypeBroadcastEvent(); + + for(unsigned int i=0; i<10; i++) { + bool callbackArrived = false; + + auto broadcastSubscription = broadcastEvent.subscribe([&,i](uint32_t intParam, std::string stringParam) -> CommonAPI::SubscriptionStatus { + EXPECT_EQ(intParam, i); + callbackArrived = true; + return CommonAPI::SubscriptionStatus::RETAIN; + }); + + stub->fireTestPredefinedTypeBroadcastEvent(i, "xyz"); + + for(unsigned int j=0; j<100 && !callbackArrived; j++) { + usleep(10000); + } + + ASSERT_TRUE(callbackArrived); + + broadcastEvent.unsubscribe(broadcastSubscription); + } +} + TEST_F(DBusBroadcastTest, ProxysCanUnsubscribeFromBroadcastAndSubscribeAgainWithOtherProxy) { auto stub = std::make_shared<SelectiveBroadcastSender>(); @@ -346,7 +384,8 @@ TEST_F(DBusBroadcastTest, ProxysCanCancelSubscriptionAndSubscribeAgainWithOtherP ASSERT_TRUE(callbackArrived); - broadcastEvent.unsubscribe(broadcastSubscription2); + broadcastEvent.unsubscribe(broadcastSubscription); + broadcastEvent2.unsubscribe(broadcastSubscription2); } diff --git a/src/test/DBusLoadTest.cpp b/src/test/DBusLoadTest.cpp index 94090d3..e5e26bc 100644 --- a/src/test/DBusLoadTest.cpp +++ b/src/test/DBusLoadTest.cpp @@ -42,6 +42,7 @@ public: std::string stringInValue, uint32_t& uint32OutValue, std::string& stringOutValue) { + uint32OutValue = uint32InValue; stringOutValue = stringInValue; } @@ -82,10 +83,10 @@ public: EXPECT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); EXPECT_EQ(out1, in1); EXPECT_EQ(out2, in2); - if (callStatus == CommonAPI::CallStatus::SUCCESS) { - ASSERT_FALSE(callSucceeded_[callId]); - callSucceeded_[callId] = true; - } + mutexCallSucceeded_.lock(); + ASSERT_FALSE(callSucceeded_[callId]); + callSucceeded_[callId] = true; + mutexCallSucceeded_.unlock(); } std::shared_ptr<CommonAPI::Runtime> runtime_; @@ -93,6 +94,7 @@ public: std::shared_ptr<CommonAPI::Factory> stubFactory_; std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher_; std::vector<bool> callSucceeded_; + std::mutex mutexCallSucceeded_; static const std::string serviceAddress_; static const uint32_t numCallsPerProxy_; |