Dev for variant
[profile/ivi/common-api-dbus-runtime.git] / src / test / DBusCommunicationTest.cpp
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
8 #include <gtest/gtest.h>
9
10 #include <cassert>
11 #include <cstdint>
12 #include <iostream>
13 #include <functional>
14 #include <memory>
15 #include <stdint.h>
16 #include <string>
17 #include <utility>
18 #include <tuple>
19 #include <type_traits>
20
21 #include <CommonAPI/types.h>
22 #include <CommonAPI/AttributeExtension.h>
23 #include <CommonAPI/Runtime.h>
24
25 #include <CommonAPI/DBus/DBusConnection.h>
26 #include <CommonAPI/DBus/DBusProxy.h>
27 #include <CommonAPI/DBus/DBusRuntime.h>
28
29 #include "commonapi/tests/PredefinedTypeCollection.h"
30 #include "commonapi/tests/DerivedTypeCollection.h"
31 #include "commonapi/tests/TestInterfaceProxy.h"
32 #include "commonapi/tests/TestInterfaceStubDefault.h"
33 #include "commonapi/tests/TestInterfaceDBusStubAdapter.h"
34
35 #include "commonapi/tests/TestInterfaceDBusProxy.h"
36
37
38 class DBusCommunicationTest: public ::testing::Test {
39  protected:
40     virtual void SetUp() {
41         runtime_ = CommonAPI::Runtime::load();
42         ASSERT_TRUE((bool)runtime_);
43         CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime_));
44         ASSERT_TRUE(dbusRuntime != NULL);
45     }
46
47     virtual void TearDown() {
48     }
49
50     std::shared_ptr<CommonAPI::Runtime> runtime_;
51
52     static const std::string serviceAddress_;
53 };
54
55 const std::string DBusCommunicationTest::serviceAddress_ = "local:commonapi.tests.TestInterface:commonapi.tests.TestInterface";
56
57
58
59 namespace myExtensions {
60
61 template<typename _AttributeType>
62 class AttributeTestExtension: public CommonAPI::AttributeExtension<_AttributeType> {
63     typedef CommonAPI::AttributeExtension<_AttributeType> __baseClass_t;
64
65 public:
66     typedef typename _AttributeType::ValueType ValueType;
67     typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
68
69     AttributeTestExtension(_AttributeType& baseAttribute) :
70                     CommonAPI::AttributeExtension<_AttributeType>(baseAttribute) {}
71
72    ~AttributeTestExtension() {}
73
74    bool testExtensionMethod() const {
75        return true;
76    }
77 };
78
79 } // namespace myExtensions
80
81 //####################################################################################################################
82
83
84 TEST_F(DBusCommunicationTest, RemoteMethodCallSucceeds) {
85     std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime_->createFactory();
86     ASSERT_TRUE((bool)proxyFactory);
87
88     auto defaultTestProxy = proxyFactory->buildProxy<commonapi::tests::TestInterfaceProxy>(serviceAddress_);
89     ASSERT_TRUE((bool)defaultTestProxy);
90
91     std::shared_ptr<CommonAPI::Factory> stubFactory = runtime_->createFactory();
92     ASSERT_TRUE((bool)stubFactory);
93
94     auto stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
95     bool success = stubFactory->registerService(stub, serviceAddress_);
96     ASSERT_TRUE(success);
97
98     uint32_t v1 = 5;
99     std::string v2 = "Hai :)";
100     CommonAPI::CallStatus stat;
101     defaultTestProxy->testVoidPredefinedTypeMethod(v1, v2, stat);
102
103     ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
104 }
105
106
107 int main(int argc, char** argv) {
108     ::testing::InitGoogleTest(&argc, argv);
109     return RUN_ALL_TESTS();
110 }