summaryrefslogtreecommitdiff
path: root/src/test/DBusServiceRegistryTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/DBusServiceRegistryTest.cpp')
-rw-r--r--src/test/DBusServiceRegistryTest.cpp107
1 files changed, 38 insertions, 69 deletions
diff --git a/src/test/DBusServiceRegistryTest.cpp b/src/test/DBusServiceRegistryTest.cpp
index bad8181..53620bd 100644
--- a/src/test/DBusServiceRegistryTest.cpp
+++ b/src/test/DBusServiceRegistryTest.cpp
@@ -1,38 +1,38 @@
-/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+// Copyright (C) 2013-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
#ifndef _GLIBCXX_USE_NANOSLEEP
#define _GLIBCXX_USE_NANOSLEEP
#endif
#include <fstream>
-#include <CommonAPI/CommonAPI.h>
+#include <CommonAPI/CommonAPI.hpp>
#ifndef COMMONAPI_INTERNAL_COMPILATION
#define COMMONAPI_INTERNAL_COMPILATION
#endif
-#include <CommonAPI/DBus/DBusServiceRegistry.h>
-#include <CommonAPI/DBus/DBusServicePublisher.h>
-#include <CommonAPI/DBus/DBusConnection.h>
-#include <CommonAPI/DBus/DBusUtils.h>
-#include <CommonAPI/DBus/DBusRuntime.h>
+#include <CommonAPI/Utils.hpp>
+
+#include <CommonAPI/DBus/DBusServiceRegistry.hpp>
+#include <CommonAPI/DBus/DBusConnection.hpp>
+#include <CommonAPI/DBus/DBusUtils.hpp>
-#include <commonapi/tests/TestInterfaceStub.h>
-#include <commonapi/tests/TestInterfaceStubDefault.h>
-#include <commonapi/tests/TestInterfaceDBusStubAdapter.h>
+#include <v1_0/commonapi/tests/TestInterfaceStub.hpp>
+#include <v1_0/commonapi/tests/TestInterfaceStubDefault.hpp>
+#include <v1_0/commonapi/tests/TestInterfaceDBusStubAdapter.hpp>
#include <gtest/gtest.h>
-#include "DemoMainLoop.h"
+#include "DemoMainLoop.hpp"
#include <fstream>
#include <chrono>
+static const char DBUS_CONFIG_SUFFIX[] = "_dbus.conf";
// all predefinedInstances will be added for this service
static const std::string dbusServiceName = "DBusServiceRegistryTest.Predefined.Service";
@@ -52,7 +52,7 @@ public:
virtual void SetUp() {
configFileName_ = CommonAPI::getCurrentBinaryFileFQN();
- configFileName_ += CommonAPI::DBus::DBUS_CONFIG_SUFFIX;
+ configFileName_ += DBUS_CONFIG_SUFFIX;
std::ofstream configFile(configFileName_);
ASSERT_TRUE(configFile.is_open());
@@ -92,8 +92,7 @@ struct TestDBusServiceListener {
const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection):
availabilityStatusCount(0),
isSubscribed(false),
- commonApiAddress_(commonApiAddress),
- dbusServiceRegistry_(dbusConnection->getDBusServiceRegistry()) {
+ commonApiAddress_(commonApiAddress) {
}
~TestDBusServiceListener() {
@@ -140,17 +139,12 @@ struct TestDBusServiceListener {
class DBusServiceRegistryTestDBusStubAdapter: public CommonAPI::DBus::DBusStubAdapter {
public:
- DBusServiceRegistryTestDBusStubAdapter(const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory,
- const std::string& commonApiAddress,
+ DBusServiceRegistryTestDBusStubAdapter(const std::string& commonApiAddress,
const std::string& dbusInterfaceName,
const std::string& dbusBusName,
const std::string& dbusObjectPath,
const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection) :
- DBusStubAdapter(factory,
- commonApiAddress,
- dbusInterfaceName,
- dbusBusName,
- dbusObjectPath,
+ DBusStubAdapter(CommonAPI::DBus::DBusAddress(dbusBusName, dbusObjectPath, dbusInterfaceName),
dbusConnection,
false),
introspectionCount(0) {
@@ -179,10 +173,7 @@ class DBusServiceRegistryTest: public ::testing::Test {
protected:
virtual void SetUp() {
- auto runtime = std::dynamic_pointer_cast<CommonAPI::DBus::DBusRuntime>(CommonAPI::Runtime::load());
-
- clientFactory = std::dynamic_pointer_cast<CommonAPI::DBus::DBusFactory>(runtime->createFactory());
- serviceFactory = std::dynamic_pointer_cast<CommonAPI::DBus::DBusFactory>(runtime->createFactory());
+ auto runtime = CommonAPI::Runtime::get();
clientDBusConnection = clientFactory->getDbusConnection();
clientConnectionRegistry = clientDBusConnection->getDBusServiceRegistry();
@@ -210,9 +201,6 @@ class DBusServiceRegistryTest: public ::testing::Test {
return waitResult;
}
- std::shared_ptr<CommonAPI::DBus::DBusFactory> clientFactory;
- std::shared_ptr<CommonAPI::DBus::DBusFactory> serviceFactory;
-
std::shared_ptr<CommonAPI::DBus::DBusConnection> clientDBusConnection;
std::shared_ptr<CommonAPI::DBus::DBusConnection> serviceDBusConnection;
@@ -243,13 +231,12 @@ TEST_F(DBusServiceRegistryTest, SubscribeBeforeConnectWorks) {
ASSERT_TRUE(serviceDBusConnection->connect());
ASSERT_TRUE(serviceDBusConnection->requestServiceNameAndBlock(dbusServiceName));
auto testDBusStubAdapter = std::make_shared<DBusServiceRegistryTestDBusStubAdapter>(
- serviceFactory,
"local:Interface1:predefined.Instance1",
"tests.Interface1",
dbusServiceName,
"/tests/predefined/Object1",
serviceDBusConnection);
- CommonAPI::DBus::DBusServicePublisher::getInstance()->registerService(testDBusStubAdapter);
+ CommonAPI::Runtime::get()->registerService("local", "predefined.Instance1", testDBusStubAdapter);
EXPECT_TRUE(waitForAvailabilityStatusChanged(
testDBusServiceListener,
@@ -258,24 +245,23 @@ TEST_F(DBusServiceRegistryTest, SubscribeBeforeConnectWorks) {
EXPECT_LE(testDBusServiceListener.availabilityStatusCount, 3);
EXPECT_EQ(testDBusStubAdapter->introspectionCount, 1);
- CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterService(testDBusStubAdapter->getAddress());
+ //CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterService(testDBusStubAdapter->getAddress());
- EXPECT_TRUE(waitForAvailabilityStatusChanged(
- testDBusServiceListener,
- CommonAPI::AvailabilityStatus::NOT_AVAILABLE));
- EXPECT_LE(testDBusServiceListener.availabilityStatusCount, 4);
+ //EXPECT_TRUE(waitForAvailabilityStatusChanged(
+ // testDBusServiceListener,
+ // CommonAPI::AvailabilityStatus::NOT_AVAILABLE));
+ //EXPECT_LE(testDBusServiceListener.availabilityStatusCount, 4);
}
TEST_F(DBusServiceRegistryTest, SubscribeBeforeConnectWithServiceWorks) {
ASSERT_TRUE(serviceDBusConnection->connect());
auto testDBusStubAdapter = std::make_shared<DBusServiceRegistryTestDBusStubAdapter>(
- serviceFactory,
"local:Interface1:predefined.Instance1",
"tests.Interface1",
dbusServiceName,
"/tests/predefined/Object1",
serviceDBusConnection);
- CommonAPI::DBus::DBusServicePublisher::getInstance()->registerService(testDBusStubAdapter);
+ CommonAPI::Runtime::get()->registerService("local", "predefined.Instance1", testDBusStubAdapter);
TestDBusServiceListener testDBusServiceListener("local:Interface1:predefined.Instance1", clientDBusConnection);
testDBusServiceListener.subscribe();
@@ -295,19 +281,18 @@ TEST_F(DBusServiceRegistryTest, SubscribeBeforeConnectWithServiceWorks) {
usleep(300 * 1000);
EXPECT_EQ(testDBusServiceListener.availabilityStatusCount, 2);
- CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterService(testDBusStubAdapter->getAddress());
+ //CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterService(testDBusStubAdapter->getAddress());
}
TEST_F(DBusServiceRegistryTest, SubscribeAfterConnectWithServiceWorks) {
ASSERT_TRUE(serviceDBusConnection->connect());
auto testDBusStubAdapter = std::make_shared<DBusServiceRegistryTestDBusStubAdapter>(
- serviceFactory,
"local:Interface1:predefined.Instance1",
"tests.Interface1",
dbusServiceName,
"/tests/predefined/Object1",
serviceDBusConnection);
- CommonAPI::DBus::DBusServicePublisher::getInstance()->registerService(testDBusStubAdapter);
+ CommonAPI::Runtime::get()->registerService("local", "predefined.Interface1", testDBusStubAdapter);
ASSERT_TRUE(clientDBusConnection->connect());
TestDBusServiceListener testDBusServiceListener("local:Interface1:predefined.Instance1", clientDBusConnection);
@@ -321,7 +306,7 @@ TEST_F(DBusServiceRegistryTest, SubscribeAfterConnectWithServiceWorks) {
EXPECT_EQ(testDBusServiceListener.availabilityStatusCount, 1);
EXPECT_EQ(testDBusStubAdapter->introspectionCount, 1);
- CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterService(testDBusStubAdapter->getAddress());
+ //CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterService(testDBusStubAdapter->getAddress());
EXPECT_TRUE(waitForAvailabilityStatusChanged(
testDBusServiceListener,
@@ -331,7 +316,7 @@ TEST_F(DBusServiceRegistryTest, SubscribeAfterConnectWithServiceWorks) {
}
TEST_F(DBusServiceRegistryTest, DBusAddressTranslatorPredefinedWorks) {
- std::vector<CommonAPI::DBus::DBusServiceAddress> loadedPredefinedInstances;
+ std::vector<CommonAPI::DBus::DBusAddress> loadedPredefinedInstances;
CommonAPI::DBus::DBusAddressTranslator::getInstance().getPredefinedInstances(dbusServiceName, loadedPredefinedInstances);
@@ -491,7 +476,7 @@ TEST_F(DBusServiceRegistryTest, DISABLED_PredefinedInstances) {
// }
}
-
+const char domain[] = "local";
const char serviceAddress_[] = "local:test.service.name:test.instance.name";
const char serviceName_[] = "test.service.name";
const char nonexistingServiceAddress_[] = "local:nonexisting.service.name:nonexisting.instance.name";
@@ -503,37 +488,21 @@ const char nonexistingServiceName_[] = "nonexisting.service.name";
class DBusServiceDiscoveryTestWithPredefinedRemote: public ::testing::Test {
protected:
virtual void SetUp() {
- runtime_ = CommonAPI::Runtime::load();
- auto serviceFactory = runtime_->createFactory();
- servicePublisher_ = runtime_->getServicePublisher();
- auto stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
- servicePublisher_->registerService(stub, serviceAddress_, serviceFactory);
- clientFactory_ = runtime_->createFactory();
+ runtime_ = CommonAPI::Runtime::get();
+ auto stub = std::make_shared<v1_0::commonapi::tests::TestInterfaceStubDefault>();
+ runtime_->registerService(domain, serviceAddress_, stub);
usleep(500 * 1000);
}
virtual void TearDown() {
- servicePublisher_->unregisterService(serviceAddress_);
+ //runtime_->unregisterService(serviceAddress_);
usleep(500 * 1000);
}
- std::shared_ptr<CommonAPI::Factory> clientFactory_;
-
private:
std::shared_ptr<CommonAPI::Runtime> runtime_;
- std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher_;
};
-TEST_F(DBusServiceDiscoveryTestWithPredefinedRemote, RecognizesInstanceOfExistingServiceAsAlive) {
- bool result = clientFactory_->isServiceInstanceAlive(serviceAddress_);
- EXPECT_TRUE(result);
-}
-
-TEST_F(DBusServiceDiscoveryTestWithPredefinedRemote, RecognizesInstanceOfNonexistingServiceAsDead) {
- bool result = clientFactory_->isServiceInstanceAlive(nonexistingServiceAddress_);
- EXPECT_FALSE(result);
-}
-
TEST_F(DBusServiceDiscoveryTestWithPredefinedRemote, RecognizesInstanceOfExistingServiceAsAliveAsync) {
//Wait for synchronous availability of the service, then verify the async version gets the same result
@@ -661,7 +630,7 @@ TEST_F(DBusServiceDiscoveryTestWithPredefinedRemote, DISABLED_ServiceRegistryUse
}
-#ifndef WIN32
+#ifndef __NO_MAIN__
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
::testing::AddGlobalTestEnvironment(new Environment());