Initial import to Git
[profile/ivi/common-api-dbus-runtime.git] / src / test / DBusRuntimeTest.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 <cstring>
8
9 #include <CommonAPI/DBus/DBusRuntime.h>
10 #include <CommonAPI/DBus/DBusFactory.h>
11
12
13
14 class DBusRuntimeTest: public ::testing::Test {
15  protected:
16         virtual void SetUp() {
17         }
18
19         virtual void TearDown() {
20         }
21 };
22
23
24
25 TEST_F(DBusRuntimeTest, LoadsDefaultStaticallyLinkedDBusLibrary) {
26     std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
27     ASSERT_TRUE((bool)runtime);
28     CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime));
29     ASSERT_TRUE(dbusRuntime != NULL);
30 }
31
32
33 TEST_F(DBusRuntimeTest, LoadsSpecifiedStaticallyLinkedDBusLibrary) {
34     std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("DBus");
35     ASSERT_TRUE((bool)runtime);
36     CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime));
37     ASSERT_TRUE(dbusRuntime != NULL);
38 }
39
40
41 TEST_F(DBusRuntimeTest, LoadsDBusLibraryAsSingleton) {
42     std::shared_ptr<CommonAPI::Runtime> runtime1 = CommonAPI::Runtime::load("DBus");
43     std::shared_ptr<CommonAPI::Runtime> runtime2 = CommonAPI::Runtime::load("DBus");
44     ASSERT_TRUE((bool)runtime1);
45     ASSERT_TRUE((bool)runtime2);
46
47     CommonAPI::DBus::DBusRuntime* dbusRuntime1 = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime1));
48     CommonAPI::DBus::DBusRuntime* dbusRuntime2 = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime2));
49     ASSERT_TRUE(dbusRuntime1 != NULL);
50     ASSERT_TRUE(dbusRuntime2 != NULL);
51
52     ASSERT_TRUE(dbusRuntime1 == dbusRuntime2);
53 }
54
55
56 TEST_F(DBusRuntimeTest, ReturnsEmptyPointerOnRequestForUnknownMiddleware) {
57     std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("UnknownMiddlewareId");
58     ASSERT_FALSE((bool)runtime);
59 }
60
61
62 TEST_F(DBusRuntimeTest, DBusRuntimeLoadsDBusFactory) {
63     std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("DBus");
64     ASSERT_TRUE((bool)runtime);
65     CommonAPI::DBus::DBusRuntime* dbusRuntime = dynamic_cast<CommonAPI::DBus::DBusRuntime*>(&(*runtime));
66     ASSERT_TRUE(dbusRuntime != NULL);
67
68     std::shared_ptr<CommonAPI::Factory> proxyFactory = runtime->createFactory();
69     ASSERT_TRUE((bool)proxyFactory);
70     CommonAPI::DBus::DBusFactory* dbusProxyFactory = dynamic_cast<CommonAPI::DBus::DBusFactory*>(&(*proxyFactory));
71     ASSERT_TRUE(dbusProxyFactory != NULL);
72 }
73
74
75 int main(int argc, char** argv) {
76     ::testing::InitGoogleTest(&argc, argv);
77     return RUN_ALL_TESTS();
78 }