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"
25 const std::string serviceAddress = "local:commonapi.tests.TestInterface:commonapi.tests.TestInterface";
27 class DBusMultipleConnectionTest: public ::testing::Test {
29 virtual void SetUp() {
30 proxyFactory = CommonAPI::Runtime::load()->createFactory();
31 stubFactory = CommonAPI::Runtime::load()->createFactory();
32 ASSERT_TRUE((bool)proxyFactory);
33 ASSERT_TRUE((bool)stubFactory);
35 stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
36 bool success = stubFactory->registerService(stub, serviceAddress);
39 proxy = proxyFactory->buildProxy<commonapi::tests::TestInterfaceProxy>(serviceAddress);
40 ASSERT_TRUE((bool)proxy);
43 virtual void TearDown() {
46 std::shared_ptr<CommonAPI::Factory> proxyFactory;
47 std::shared_ptr<CommonAPI::Factory> stubFactory;
48 std::shared_ptr<commonapi::tests::TestInterfaceStubDefault> stub;
49 std::shared_ptr<commonapi::tests::TestInterfaceProxy<> > proxy;
54 TEST_F(DBusMultipleConnectionTest, SetAttribute) {
57 CommonAPI::CallStatus stat;
58 proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
59 ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
63 TEST_F(DBusMultipleConnectionTest, SetAttributeBroadcast) {
68 std::promise<bool> promise;
69 auto future = promise.get_future();
71 proxy->getTestPredefinedTypeAttributeAttribute().getChangedEvent().subscribe([&](
72 const uint32_t intVal) {
74 promise.set_value(true);
77 CommonAPI::CallStatus stat;
78 proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
79 ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
82 ASSERT_TRUE(future.get());
88 TEST_F(DBusMultipleConnectionTest, GetAttribute) {
90 CommonAPI::CallStatus stat = proxy->getTestPredefinedTypeAttributeAttribute().getValue(v1);
91 ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
94 TEST_F(DBusMultipleConnectionTest, RemoteMethodCall) {
96 std::string v2 = "Hai :)";
97 CommonAPI::CallStatus stat;
98 proxy->testVoidPredefinedTypeMethod(v1, v2, stat);
99 ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
102 TEST_F(DBusMultipleConnectionTest, Broadcast) {
105 std::string v2 = "Hai :)";
107 std::promise<bool> promise;
108 auto future = promise.get_future();
110 proxy->getTestPredefinedTypeBroadcastEvent().subscribe([&](
111 const uint32_t intVal, const std::string& strVal) {
113 promise.set_value(true);
116 stub->firePredefinedBroadcast(v1, v2);
118 ASSERT_TRUE(future.get());
123 int main(int argc, char** argv) {
124 ::testing::InitGoogleTest(&argc, argv);
125 return RUN_ALL_TESTS();