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/AttributeExtension.h>
20 #include <CommonAPI/Runtime.h>
22 #include <CommonAPI/DBus/DBusConnection.h>
23 #include <CommonAPI/DBus/DBusProxy.h>
24 #include <CommonAPI/DBus/DBusRuntime.h>
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"
32 #include "commonapi/tests/TestInterfaceDBusProxy.h"
35 class DBusCommunicationTest: public ::testing::Test {
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);
44 virtual void TearDown() {
47 std::shared_ptr<CommonAPI::Runtime> runtime_;
49 static const std::string serviceAddress_;
52 const std::string DBusCommunicationTest::serviceAddress_ = "local:commonapi.tests.TestInterface:commonapi.tests.TestInterface";
56 namespace myExtensions {
58 template<typename _AttributeType>
59 class AttributeTestExtension: public CommonAPI::AttributeExtension<_AttributeType> {
60 typedef CommonAPI::AttributeExtension<_AttributeType> __baseClass_t;
63 typedef typename _AttributeType::ValueType ValueType;
64 typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
66 AttributeTestExtension(_AttributeType& baseAttribute) :
67 CommonAPI::AttributeExtension<_AttributeType>(baseAttribute) {}
69 ~AttributeTestExtension() {}
71 bool testExtensionMethod() const {
76 } // namespace myExtensions
78 //####################################################################################################################
81 TEST_F(DBusCommunicationTest, RemoteMethodCallSucceeds) {
82 std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime_->createFactory();
83 ASSERT_TRUE((bool)proxyFactory);
85 auto defaultTestProxy = proxyFactory->buildProxy<commonapi::tests::TestInterfaceProxy>(serviceAddress_);
86 ASSERT_TRUE((bool)defaultTestProxy);
88 std::shared_ptr<CommonAPI::Factory> stubFactory = runtime_->createFactory();
89 ASSERT_TRUE((bool)stubFactory);
91 auto stub = std::make_shared<commonapi::tests::TestInterfaceStubDefault>();
92 bool success = stubFactory->registerService(stub, serviceAddress_);
96 std::string v2 = "Hai :)";
97 CommonAPI::CallStatus stat;
98 defaultTestProxy->testVoidPredefinedTypeMethod(v1, v2, stat);
100 ASSERT_EQ(stat, CommonAPI::CallStatus::SUCCESS);
104 int main(int argc, char** argv) {
105 ::testing::InitGoogleTest(&argc, argv);
106 return RUN_ALL_TESTS();