1 /* Copyright (C) 2013 BMW Group
2 * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
3 * Author: Juergen Gehring (juergen.gehring@bmw.de)
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include <gtest/gtest.h>
18 #include <type_traits>
20 #include <CommonAPI/types.h>
21 #include <CommonAPI/Runtime.h>
23 #include "commonapi/tests/TestInterfaceProxy.h"
24 #include "commonapi/tests/TestInterfaceStubDefault.h"
27 const std::string serviceAddress = "local:commonapi.tests.TestInterface:commonapi.tests.TestInterface";
29 class DBusMultipleConnectionTest: public ::testing::Test {
31 virtual void SetUp() {
32 proxyFactory = CommonAPI::Runtime::load()->createFactory();
33 stubFactory = CommonAPI::Runtime::load()->createFactory();
34 ASSERT_TRUE((bool)proxyFactory);
35 ASSERT_TRUE((bool)stubFactory);
37 stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
38 bool success = stubFactory->registerService(stub, serviceAddress);
41 proxy = proxyFactory->buildProxy<commonapi::tests::TestInterfaceProxy>(serviceAddress);
42 ASSERT_TRUE((bool)proxy);
45 virtual void TearDown() {
48 std::shared_ptr<CommonAPI::Factory> proxyFactory;
49 std::shared_ptr<CommonAPI::Factory> stubFactory;
50 std::shared_ptr<commonapi::tests::TestInterfaceStubDefault> stub;
51 std::shared_ptr<commonapi::tests::TestInterfaceProxy<> > proxy;
56 TEST_F(DBusMultipleConnectionTest, RemoteMethodCall) {
58 std::string v2 = "Hai :)";
59 CommonAPI::CallStatus stat;
60 proxy->testVoidPredefinedTypeMethod(v1, v2, stat);
61 ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, stat);
64 TEST_F(DBusMultipleConnectionTest, Broadcast) {
67 std::string v2 = "Hai :)";
69 std::promise<bool> promise;
70 auto future = promise.get_future();
72 proxy->getTestPredefinedTypeBroadcastEvent().subscribe([&](
73 const uint32_t intVal, const std::string& strVal) {
75 promise.set_value(true);
78 stub->fireTestPredefinedTypeBroadcastEvent(v1, v2);
80 ASSERT_TRUE(future.get());
84 TEST_F(DBusMultipleConnectionTest, SetAttribute) {
87 CommonAPI::CallStatus stat;
88 proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
89 ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, stat);
93 TEST_F(DBusMultipleConnectionTest, SetAttributeBroadcast) {
98 std::promise<bool> promise;
99 auto future = promise.get_future();
101 proxy->getTestPredefinedTypeAttributeAttribute().getChangedEvent().subscribe([&](
102 const uint32_t intVal) {
104 promise.set_value(true);
107 CommonAPI::CallStatus stat;
108 proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
109 ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, stat);
112 ASSERT_TRUE(future.get());
118 TEST_F(DBusMultipleConnectionTest, GetAttribute) {
120 CommonAPI::CallStatus stat = proxy->getTestPredefinedTypeAttributeAttribute().getValue(v1);
121 ASSERT_EQ(CommonAPI::CallStatus::SUCCESS, stat);
125 int main(int argc, char** argv) {
126 ::testing::InitGoogleTest(&argc, argv);
127 return RUN_ALL_TESTS();