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