summaryrefslogtreecommitdiff
path: root/src/test/DBusPolymorphicTest.cpp
diff options
context:
space:
mode:
authorJürgen Gehring <juergen.gehring@bmw.de>2015-06-01 07:57:07 -0700
committerJürgen Gehring <juergen.gehring@bmw.de>2015-06-01 07:57:07 -0700
commit54982071a99484488207ad3bd5e9391a15bffe02 (patch)
tree479c178ee629947cf0df65fc0e38f986f6ccdbc9 /src/test/DBusPolymorphicTest.cpp
parent45a6f65628a142bb8d37a3b72cb210b1f8c24a5f (diff)
downloadgenivi-common-api-dbus-runtime-54982071a99484488207ad3bd5e9391a15bffe02.tar.gz
CommonAPI-D-Bus 3.1.13.1.1
Diffstat (limited to 'src/test/DBusPolymorphicTest.cpp')
-rw-r--r--src/test/DBusPolymorphicTest.cpp159
1 files changed, 71 insertions, 88 deletions
diff --git a/src/test/DBusPolymorphicTest.cpp b/src/test/DBusPolymorphicTest.cpp
index 0c0dd98..be7082f 100644
--- a/src/test/DBusPolymorphicTest.cpp
+++ b/src/test/DBusPolymorphicTest.cpp
@@ -1,49 +1,50 @@
-/* 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/.
+
#include <gtest/gtest.h>
-#include <commonapi/tests/DerivedTypeCollection.h>
-#include <commonapi/tests/TestInterfaceDBusProxy.h>
-#include <commonapi/tests/TestInterfaceDBusStubAdapter.h>
-#include <commonapi/tests/TestInterfaceStubDefault.h>
-#ifndef COMMONAPI_INTERNAL_COMPILATION
-#define COMMONAPI_INTERNAL_COMPILATION
-#endif
-#include <CommonAPI/DBus/DBusRuntime.h>
+#include "CommonAPI/CommonAPI.hpp"
#ifndef COMMONAPI_INTERNAL_COMPILATION
#define COMMONAPI_INTERNAL_COMPILATION
#endif
+#include "CommonAPI/DBus/DBusConnection.hpp"
+
+#define VERSION v1_0
+
+#include <commonapi/tests/DerivedTypeCollection.hpp>
+#include <v1_0/commonapi/tests/TestInterfaceDBusProxy.hpp>
+#include <v1_0/commonapi/tests/TestInterfaceDBusStubAdapter.hpp>
+#include <v1_0/commonapi/tests/TestInterfaceStubDefault.hpp>
+
static const std::string commonApiAddress =
"local:CommonAPI.DBus.tests.DBusProxyTestInterface:CommonAPI.DBus.tests.DBusProxyTestService";
static const std::string interfaceName = "CommonAPI.DBus.tests.DBusProxyTestInterface";
static const std::string busName = "CommonAPI.DBus.tests.DBusProxyTestService";
static const std::string objectPath = "/CommonAPI/DBus/tests/DBusProxyTestService";
-class PolymorphicTestStub: public commonapi::tests::TestInterfaceStubDefault {
+class PolymorphicTestStub : public VERSION::commonapi::tests::TestInterfaceStubDefault {
public:
void TestArrayOfPolymorphicStructMethod(
const std::shared_ptr<CommonAPI::ClientId> clientId,
- std::vector<std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct>> inArray) {
+ std::vector<std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct>> inArray) {
numberOfContainedElements_ = inArray.size();
if (numberOfContainedElements_ > 0) {
- std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
+ std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
std::dynamic_pointer_cast<
- commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
+ ::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
inArray[0]);
firstElementIsExtended_ = (extended != NULL);
}
if (numberOfContainedElements_ > 1) {
- std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
+ std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
std::dynamic_pointer_cast<
- commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
+ ::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
inArray[1]);
secondElementIsExtended_ = (extended != NULL);
}
@@ -51,38 +52,38 @@ public:
void TestMapOfPolymorphicStructMethod(
const std::shared_ptr<CommonAPI::ClientId> clientId,
- std::unordered_map<uint8_t, std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct>> inMap) {
+ std::unordered_map<uint8_t, std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct>> inMap) {
numberOfContainedElements_ = inMap.size();
auto iteratorFirst = inMap.find(5);
auto iteratorSecond = inMap.find(10);
if (iteratorFirst != inMap.end()) {
- std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
+ std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
std::dynamic_pointer_cast<
- commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
+ ::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
iteratorFirst->second);
firstElementIsExtended_ = (extended != NULL);
}
if (iteratorSecond != inMap.end()) {
- std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
+ std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
std::dynamic_pointer_cast<
- commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
+ ::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
iteratorSecond->second);
secondElementIsExtended_ = (extended != NULL);
}
}
void TestStructWithPolymorphicMemberMethod(const std::shared_ptr<CommonAPI::ClientId> clientId,
- commonapi::tests::DerivedTypeCollection::StructWithPolymorphicMember inStruct) {
- if (inStruct.polymorphicMember != NULL) {
+ ::commonapi::tests::DerivedTypeCollection::StructWithPolymorphicMember inStruct) {
+ if (inStruct.getPolymorphicMember() != NULL) {
numberOfContainedElements_ = 1;
- std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
+ std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extended =
std::dynamic_pointer_cast<
- commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
- inStruct.polymorphicMember);
+ ::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>(
+ inStruct.getPolymorphicMember());
firstElementIsExtended_ = (extended != NULL);
}
}
@@ -95,20 +96,12 @@ public:
class PolymorphicTest: public ::testing::Test {
protected:
void SetUp() {
- auto runtime = std::dynamic_pointer_cast<CommonAPI::DBus::DBusRuntime>(CommonAPI::Runtime::load());
-
- serviceFactory = std::dynamic_pointer_cast<CommonAPI::DBus::DBusFactory>(runtime->createFactory());
+ auto runtime = CommonAPI::Runtime::get();
- proxyDBusConnection_ = CommonAPI::DBus::DBusConnection::getSessionBus();
+ proxyDBusConnection_ = CommonAPI::DBus::DBusConnection::getBus(CommonAPI::DBus::DBusType_t::SESSION);
ASSERT_TRUE(proxyDBusConnection_->connect());
- proxy_ = std::make_shared<commonapi::tests::TestInterfaceDBusProxy>(
- serviceFactory,
- commonApiAddress,
- interfaceName,
- busName,
- objectPath,
- proxyDBusConnection_);
+ proxy_ = std::make_shared<VERSION::commonapi::tests::TestInterfaceDBusProxy>(CommonAPI::DBus::DBusAddress(busName, objectPath, interfaceName), proxyDBusConnection_);
proxy_->init();
registerTestStub();
@@ -118,43 +111,33 @@ protected:
}
ASSERT_TRUE(proxy_->isAvailable());
- baseInstance1_ = std::make_shared<commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct>();
- baseInstance1_->testString = "abc";
+ baseInstance1_ = std::make_shared<::commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct>();
+ baseInstance1_->setTestString("abc");
- extendedInstance1_ = std::make_shared<commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>();
- extendedInstance1_->additionalValue = 7;
+ extendedInstance1_ = std::make_shared<::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct>();
+ extendedInstance1_->setAdditionalValue(7);
}
- std::shared_ptr<CommonAPI::DBus::DBusFactory> serviceFactory;
-
virtual void TearDown() {
deregisterTestStub();
usleep(30000);
}
void registerTestStub() {
- stubDBusConnection_ = CommonAPI::DBus::DBusConnection::getSessionBus();
+ stubDBusConnection_ = CommonAPI::DBus::DBusConnection::getBus(CommonAPI::DBus::DBusType_t::SESSION);
ASSERT_TRUE(stubDBusConnection_->connect());
testStub = std::make_shared<PolymorphicTestStub>();
- stubAdapter_ = std::make_shared<commonapi::tests::TestInterfaceDBusStubAdapter>(
- serviceFactory,
- commonApiAddress,
- interfaceName,
- busName,
- objectPath,
- stubDBusConnection_,
- testStub);
- stubAdapter_->init(stubAdapter_);
-
- const bool isStubAdapterRegistered = CommonAPI::DBus::DBusServicePublisher::getInstance()->registerService(
- stubAdapter_);
+ stubAdapter_ = std::make_shared<VERSION::commonapi::tests::TestInterfaceDBusStubAdapter>(CommonAPI::DBus::DBusAddress(busName, objectPath, interfaceName), stubDBusConnection_, testStub);
+ stubAdapter_->init(stubAdapter_);
+
+ const bool isStubAdapterRegistered = CommonAPI::Runtime::get()->registerService(
+ stubAdapter_->getAddress().getDomain(), stubAdapter_->getAddress().getInstance(), testStub);
ASSERT_TRUE(isStubAdapterRegistered);
}
void deregisterTestStub() {
- const bool isStubAdapterUnregistered = CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterService(
- stubAdapter_->getAddress());
+ const bool isStubAdapterUnregistered = CommonAPI::Runtime::get()->unregisterService(stubAdapter_->getAddress().getDomain(), stubAdapter_->getInterface(), stubAdapter_->getAddress().getInstance());
ASSERT_TRUE(isStubAdapterUnregistered);
stubAdapter_.reset();
@@ -165,48 +148,48 @@ protected:
}
std::shared_ptr<CommonAPI::DBus::DBusConnection> proxyDBusConnection_;
- std::shared_ptr<commonapi::tests::TestInterfaceDBusProxy> proxy_;
+ std::shared_ptr<VERSION::commonapi::tests::TestInterfaceDBusProxy> proxy_;
std::shared_ptr<CommonAPI::DBus::DBusConnection> stubDBusConnection_;
- std::shared_ptr<commonapi::tests::TestInterfaceDBusStubAdapter> stubAdapter_;
+ std::shared_ptr<VERSION::commonapi::tests::TestInterfaceDBusStubAdapter> stubAdapter_;
- std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> baseInstance1_;
- std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extendedInstance1_;
+ std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> baseInstance1_;
+ std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestExtendedPolymorphicStruct> extendedInstance1_;
std::shared_ptr<PolymorphicTestStub> testStub;
};
-TEST_F(PolymorphicTest, SendVectorOfBaseType) {
+TEST_F(PolymorphicTest, DISABLED_SendVectorOfBaseType) {
CommonAPI::CallStatus stat;
- std::vector<std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> > inputArray;
+ std::vector<std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> > inputArray;
inputArray.push_back(baseInstance1_);
- proxy_->TestArrayOfPolymorphicStructMethod(inputArray, stat);
+ proxy_->TestArrayOfPolymorphicStructMethod(inputArray, stat, nullptr);
ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
ASSERT_EQ(testStub->numberOfContainedElements_, 1);
ASSERT_FALSE(testStub->firstElementIsExtended_);
}
-TEST_F(PolymorphicTest, SendVectorOfExtendedType) {
+TEST_F(PolymorphicTest, DISABLED_SendVectorOfExtendedType) {
CommonAPI::CallStatus stat;
- std::vector<std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> > inputArray;
+ std::vector<std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> > inputArray;
inputArray.push_back(extendedInstance1_);
- proxy_->TestArrayOfPolymorphicStructMethod(inputArray, stat);
+ proxy_->TestArrayOfPolymorphicStructMethod(inputArray, stat, nullptr);
ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
ASSERT_EQ(testStub->numberOfContainedElements_, 1);
ASSERT_TRUE(testStub->firstElementIsExtended_);
}
-TEST_F(PolymorphicTest, SendVectorOfBaseAndExtendedType) {
+TEST_F(PolymorphicTest, DISABLED_SendVectorOfBaseAndExtendedType) {
CommonAPI::CallStatus stat;
- std::vector<std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> > inputArray;
+ std::vector<std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> > inputArray;
inputArray.push_back(baseInstance1_);
inputArray.push_back(extendedInstance1_);
- proxy_->TestArrayOfPolymorphicStructMethod(inputArray, stat);
+ proxy_->TestArrayOfPolymorphicStructMethod(inputArray, stat, nullptr);
ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
ASSERT_EQ(testStub->numberOfContainedElements_, 2);
@@ -214,13 +197,13 @@ TEST_F(PolymorphicTest, SendVectorOfBaseAndExtendedType) {
ASSERT_TRUE(testStub->secondElementIsExtended_);
}
-TEST_F(PolymorphicTest, SendMapOfBaseAndExtendedType) {
+TEST_F(PolymorphicTest, DISABLED_SendMapOfBaseAndExtendedType) {
CommonAPI::CallStatus stat;
- std::unordered_map<uint8_t, std::shared_ptr<commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> > inputMap;
+ std::unordered_map<uint8_t, std::shared_ptr<::commonapi::tests::DerivedTypeCollection::TestPolymorphicStruct> > inputMap;
inputMap.insert( {5, baseInstance1_});
inputMap.insert( {10, extendedInstance1_});
- proxy_->TestMapOfPolymorphicStructMethod(inputMap, stat);
+ proxy_->TestMapOfPolymorphicStructMethod(inputMap, stat, nullptr);
ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
ASSERT_EQ(testStub->numberOfContainedElements_, 2);
@@ -228,31 +211,31 @@ TEST_F(PolymorphicTest, SendMapOfBaseAndExtendedType) {
ASSERT_TRUE(testStub->secondElementIsExtended_);
}
-TEST_F(PolymorphicTest, SendStructWithPolymorphicMember) {
+TEST_F(PolymorphicTest, DISABLED_SendStructWithPolymorphicMember) {
CommonAPI::CallStatus stat;
- commonapi::tests::DerivedTypeCollection::StructWithPolymorphicMember inputStruct;
- inputStruct.polymorphicMember = extendedInstance1_;
+ ::commonapi::tests::DerivedTypeCollection::StructWithPolymorphicMember inputStruct;
+ inputStruct.setPolymorphicMember(extendedInstance1_);
- proxy_->TestStructWithPolymorphicMemberMethod(inputStruct, stat);
+ proxy_->TestStructWithPolymorphicMemberMethod(inputStruct, stat, nullptr);
ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
ASSERT_EQ(testStub->numberOfContainedElements_, 1);
ASSERT_TRUE(testStub->firstElementIsExtended_);
}
-TEST_F(PolymorphicTest, SendStructWithMapWithEnumKeyMember) {
+TEST_F(PolymorphicTest, DISABLED_SendStructWithMapWithEnumKeyMember) {
CommonAPI::CallStatus stat;
- commonapi::tests::DerivedTypeCollection::StructWithEnumKeyMap inputStruct;
- inputStruct.testMap.insert( { commonapi::tests::DerivedTypeCollection::TestEnum::E_OK, "test" } );
+ ::commonapi::tests::DerivedTypeCollection::StructWithEnumKeyMap inputStruct;
+ std::get<0>(inputStruct.values_).insert( { commonapi::tests::DerivedTypeCollection::TestEnum::E_OK, "test" } );
- proxy_->TestStructWithEnumKeyMapMember(inputStruct, stat);
+ proxy_->TestStructWithEnumKeyMapMember(inputStruct, stat, nullptr);
ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
}
-#ifndef WIN32
+#ifndef __NO_MAIN__
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
-#endif \ No newline at end of file
+#endif