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>
9 #include <CommonAPI/DBus/DBusRuntime.h>
10 #include <CommonAPI/DBus/DBusFactory.h>
14 class DBusRuntimeTest: public ::testing::Test {
16 virtual void SetUp() {
19 virtual void TearDown() {
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);
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);
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);
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);
52 ASSERT_TRUE(dbusRuntime1 == dbusRuntime2);
56 TEST_F(DBusRuntimeTest, ReturnsEmptyPointerOnRequestForUnknownMiddleware) {
57 std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load("UnknownMiddlewareId");
58 ASSERT_FALSE((bool)runtime);
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);
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);
75 int main(int argc, char** argv) {
76 ::testing::InitGoogleTest(&argc, argv);
77 return RUN_ALL_TESTS();