2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <bundle_cpp.h>
19 #include <gtest/gtest.h>
20 #include <gmock/gmock.h>
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"
32 using namespace ttm::loader;
34 using ::testing::Return;
35 using ::testing::SetArgPointee;
36 using ::testing::StrEq;
38 class ThemeEvent : public IThemeEvent {
40 void OnThemeLoaded(const ThemeInfo* theme,
41 const tizen_base::Bundle& args) override {
44 void OnThemeUnloaded(const std::string& id) override {
48 class Mocks : public ::testing::NiceMock<GioMock>,
49 public ::testing::NiceMock<GlibMock> {};
51 class ThemeInfoLoaderTest : public TestFixture {
53 ThemeInfoLoaderTest() : TestFixture(std::make_unique<Mocks>()) {}
55 virtual void SetUp() {
58 virtual void TearDown() {
61 std::shared_ptr<ThemeInfoLoader> loader_ =
62 std::make_shared<ThemeInfoLoader>();
65 TEST_F(ThemeInfoLoaderTest, AddEvent) {
66 std::shared_ptr<IThemeEvent> handler;
67 std::string id(loader_->AddEvent(handler));
68 EXPECT_NE(0, id.size());
71 TEST_F(ThemeInfoLoaderTest, RemoveEvent) {
72 std::shared_ptr<IThemeEvent> handler;
73 std::string id(loader_->AddEvent(handler));
74 int ret = loader_->RemoveEvent(id);
78 TEST_F(ThemeInfoLoaderTest, RemoveEvent_N) {
80 int ret = loader_->RemoveEvent(id);
84 TEST_F(ThemeInfoLoaderTest, QueryThemeId_N) {
85 EXPECT_CALL(GetMock<GioMock>(), g_dbus_message_new_method_call(_, _, _, _)).
86 WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
88 std::vector<std::string> ids_vec;
89 b.Add("ids", ids_vec);
91 char* b_raw = reinterpret_cast<char*>(br.first.get());
92 EXPECT_CALL(GetMock<GlibMock>(), g_variant_get(_, _, _, _)).
93 WillOnce(SetArgPointee<3>(b_raw));
95 std::vector<std::string> ids = loader_->QueryThemeId();
96 EXPECT_EQ(0, ids.size());
99 TEST_F(ThemeInfoLoaderTest, SetCurrent) {
100 loader_->SetCurrent(std::string("id"));
103 TEST_F(ThemeInfoLoaderTest, LoadCurrent) {
104 std::shared_ptr<ThemeInfo> info = loader_->LoadCurrent();
105 EXPECT_NE(nullptr, info);
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);
114 std::shared_ptr<ThemeInfo> info = loader_->Load(std::string("id"));
115 EXPECT_NE(nullptr, info);