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/. */
5 #include <gtest/gtest.h>
16 #include <type_traits>
18 #include <CommonAPI/types.h>
19 #include <CommonAPI/Runtime.h>
21 #include "commonapi/tests/TestInterfaceProxy.h"
22 #include "commonapi/tests/TestInterfaceStubDefault.h"
23 const std::string serviceAddress = "local:commonapi.tests.TestInterface:commonapi.tests.TestInterface";
25 class DBusMultipleConnectionTest: public ::testing::Test {
27 virtual void SetUp() {
28 proxyFactory = CommonAPI::Runtime::load()->createFactory();
29 stubFactory = CommonAPI::Runtime::load()->createFactory();
30 ASSERT_TRUE((bool)proxyFactory);
31 ASSERT_TRUE((bool)stubFactory);
33 stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
34 bool success = stubFactory->registerService(stub, serviceAddress);
37 proxy = proxyFactory->buildProxy<commonapi::tests::TestInterfaceProxy>(serviceAddress);
38 ASSERT_TRUE((bool)proxy);
41 virtual void TearDown() {
44 std::shared_ptr<CommonAPI::Factory> proxyFactory;
45 std::shared_ptr<CommonAPI::Factory> stubFactory;
46 std::shared_ptr<commonapi::tests::TestInterfaceStubDefault> stub;
47 std::shared_ptr<commonapi::tests::TestInterfaceProxy<> > proxy;
52 TEST_F(DBusMultipleConnectionTest, SetAttribute) {
55 CommonAPI::CallStatus stat;
56 proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
57 ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
61 TEST_F(DBusMultipleConnectionTest, SetAttributeBroadcast) {
66 std::promise<bool> promise;
67 auto future = promise.get_future();
69 proxy->getTestPredefinedTypeAttributeAttribute().getChangedEvent().subscribe([&](
70 const uint32_t intVal) {
72 promise.set_value(true);
75 CommonAPI::CallStatus stat;
76 proxy->getTestPredefinedTypeAttributeAttribute().setValue(v1, stat, v2);
77 ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
80 ASSERT_TRUE(future.get());
86 TEST_F(DBusMultipleConnectionTest, GetAttribute) {
88 CommonAPI::CallStatus stat = proxy->getTestPredefinedTypeAttributeAttribute().getValue(v1);
89 ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
92 TEST_F(DBusMultipleConnectionTest, RemoteMethodCall) {
94 std::string v2 = "Hai :)";
95 CommonAPI::CallStatus stat;
96 proxy->testVoidPredefinedTypeMethod(v1, v2, stat);
97 ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
100 TEST_F(DBusMultipleConnectionTest, Broadcast) {
103 std::string v2 = "Hai :)";
105 std::promise<bool> promise;
106 auto future = promise.get_future();
108 proxy->getTestPredefinedTypeBroadcastEvent().subscribe([&](
109 const uint32_t intVal, const std::string& strVal) {
111 promise.set_value(true);
114 stub->firePredefinedBroadcast(v1, v2);
116 ASSERT_TRUE(future.get());
121 int main(int argc, char** argv) {
122 ::testing::InitGoogleTest(&argc, argv);
123 return RUN_ALL_TESTS();