tests: fix blocking semantic in DBusProxyTest
[profile/ivi/common-api-dbus-runtime.git] / src / test / DBusRuntimeTest.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 #include <gtest/gtest.h>
8
9 #include <cstring>
10
11 #include <CommonAPI/DBus/DBusRuntime.h>
12 #include <CommonAPI/DBus/DBusFactory.h>
13
14
15
16 class DBusRuntimeTest: public ::testing::Test {
17  protected:
18         virtual void SetUp() {
19         }
20
21         virtual void TearDown() {
22         }
23 };
24
25
26
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);
32 }
33
34
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);
40 }
41
42
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);
48
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);
53
54     ASSERT_TRUE(dbusRuntime1 == dbusRuntime2);
55 }
56
57
58 TEST_F(DBusRuntimeTest, ReturnsEmptyPointerOnRequestForUnknownMiddleware) {
59     std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("UnknownMiddlewareId");
60     ASSERT_FALSE((bool)runtime);
61 }
62
63
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);
69
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);
74 }
75
76
77 int main(int argc, char** argv) {
78     ::testing::InitGoogleTest(&argc, argv);
79     return RUN_ALL_TESTS();
80 }