1f6d4dd12a79744f7aa80ab3e777f2da0b82c7ad
[platform/core/appfw/tizen-theme-manager.git] / test / unit_tests / test_theme_info_loader.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <bundle_cpp.h>
18 #include <gio/gio.h>
19 #include <gtest/gtest.h>
20 #include <gmock/gmock.h>
21
22 #include <memory>
23 #include <string>
24
25 #include "theme/loader/theme_event.h"
26 #include "theme/loader/theme_info.h"
27 #include "theme/loader/theme_info_loader.h"
28 #include "unit_tests/mock/gio_mock.h"
29 #include "unit_tests/mock/glib_mock.h"
30 #include "unit_tests/mock/test_fixture.h"
31
32 using namespace ttm::loader;
33 using ::testing::_;
34 using ::testing::Return;
35 using ::testing::SetArgPointee;
36 using ::testing::StrEq;
37
38 class ThemeEvent : public IThemeEvent {
39  public:
40   void OnThemeLoaded(const ThemeInfo* theme,
41       const tizen_base::Bundle& args) override {
42   }
43
44   void OnThemeUnloaded(const std::string& id) override {
45   }
46 };
47
48 class Mocks : public ::testing::NiceMock<GioMock>,
49               public ::testing::NiceMock<GlibMock> {};
50
51 class ThemeInfoLoaderTest : public TestFixture {
52  public:
53   ThemeInfoLoaderTest() : TestFixture(std::make_unique<Mocks>()) {}
54
55   virtual void SetUp() {
56   }
57
58   virtual void TearDown() {
59   }
60
61   std::shared_ptr<ThemeInfoLoader> loader_ =
62     std::make_shared<ThemeInfoLoader>();
63 };
64
65 TEST_F(ThemeInfoLoaderTest, AddEvent) {
66   std::shared_ptr<IThemeEvent> handler;
67   std::string id(loader_->AddEvent(handler));
68   EXPECT_NE(0, id.size());
69 }
70
71 TEST_F(ThemeInfoLoaderTest, RemoveEvent) {
72   std::shared_ptr<IThemeEvent> handler;
73   std::string id(loader_->AddEvent(handler));
74   int ret = loader_->RemoveEvent(id);
75   EXPECT_EQ(0, ret);
76 }
77
78 TEST_F(ThemeInfoLoaderTest, RemoveEvent_N) {
79   std::string id("id");
80   int ret = loader_->RemoveEvent(id);
81   EXPECT_NE(0, ret);
82 }
83
84 TEST_F(ThemeInfoLoaderTest, QueryThemeId_N) {
85   EXPECT_CALL(GetMock<GioMock>(), g_dbus_message_new_method_call(_, _, _, _)).
86       WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
87   tizen_base::Bundle b;
88   std::vector<std::string> ids_vec;
89   b.Add("ids", ids_vec);
90   auto br = b.ToRaw();
91   char* b_raw = reinterpret_cast<char*>(br.first.get());
92   EXPECT_CALL(GetMock<GlibMock>(), g_variant_get(_, _, _, _)).
93       WillOnce(SetArgPointee<3>(b_raw));
94
95   std::vector<std::string> ids = loader_->QueryThemeId();
96   EXPECT_EQ(0, ids.size());
97 }
98
99 TEST_F(ThemeInfoLoaderTest, SetCurrent) {
100   loader_->SetCurrent(std::string("id"));
101 }
102
103 TEST_F(ThemeInfoLoaderTest, LoadCurrent) {
104   std::shared_ptr<ThemeInfo> info = loader_->LoadCurrent();
105   EXPECT_NE(nullptr, info);
106 }
107
108 TEST_F(ThemeInfoLoaderTest, Load) {
109   EXPECT_CALL(GetMock<GioMock>(),
110       g_dbus_message_new_method_call(StrEq("org.tizen.theme_manager"),
111           StrEq("/org/tizen/theme_manager"), StrEq("org.tizen.theme_manager"),
112           StrEq("SendData"))).Times(1);
113
114   std::shared_ptr<ThemeInfo> info = loader_->Load(std::string("id"));
115   EXPECT_NE(nullptr, info);
116 }