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>
11 #include <CommonAPI/DBus/DBusRuntime.h>
12 #include <CommonAPI/DBus/DBusFactory.h>
16 class DBusRuntimeTest: public ::testing::Test {
18 virtual void SetUp() {
21 virtual void TearDown() {
27 TEST_F(DBusRuntimeTest, LoadsDefaultStaticallyLinkedDBusLibrary) {
28 std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
29 ASSERT_TRUE((bool)runtime);
30 CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime));
31 ASSERT_TRUE(dbusRuntime != NULL);
35 TEST_F(DBusRuntimeTest, LoadsSpecifiedStaticallyLinkedDBusLibrary) {
36 std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("DBus");
37 ASSERT_TRUE((bool)runtime);
38 CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime));
39 ASSERT_TRUE(dbusRuntime != NULL);
43 TEST_F(DBusRuntimeTest, LoadsDBusLibraryAsSingleton) {
44 std::shared_ptr<CommonAPI::Runtime> runtime1 = CommonAPI::Runtime::load("DBus");
45 std::shared_ptr<CommonAPI::Runtime> runtime2 = CommonAPI::Runtime::load("DBus");
46 ASSERT_TRUE((bool)runtime1);
47 ASSERT_TRUE((bool)runtime2);
49 CommonAPI::DBus::DBusRuntime* dbusRuntime1 = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime1));
50 CommonAPI::DBus::DBusRuntime* dbusRuntime2 = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime2));
51 ASSERT_TRUE(dbusRuntime1 != NULL);
52 ASSERT_TRUE(dbusRuntime2 != NULL);
54 ASSERT_TRUE(dbusRuntime1 == dbusRuntime2);
58 TEST_F(DBusRuntimeTest, ReturnsEmptyPointerOnRequestForUnknownMiddleware) {
59 std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("UnknownMiddlewareId");
60 ASSERT_FALSE((bool)runtime);
64 TEST_F(DBusRuntimeTest, DBusRuntimeLoadsDBusFactory) {
65 std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("DBus");
66 ASSERT_TRUE((bool)runtime);
67 CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime));
68 ASSERT_TRUE(dbusRuntime != NULL);
70 std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime->createFactory();
71 ASSERT_TRUE((bool)proxyFactory);
72 CommonAPI::DBus::DBusFactory* dbusProxyFactory = dynamic_cast<CommonAPI::DBus::DBusFactory*>(&(*proxyFactory));
73 ASSERT_TRUE(dbusProxyFactory != NULL);
77 int main(int argc, char** argv) {
78 ::testing::InitGoogleTest(&argc, argv);
79 return RUN_ALL_TESTS();