2 * Copyright (c) 2019 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 <gmock/gmock.h>
19 #include "notification-ex/group_item.h"
20 #include "notification-ex/button_item.h"
21 #include "notification-ex/text_item.h"
22 #include "notification-ex/item_inflator.h"
23 #include "mock/app_common.h"
25 using namespace tizen_base;
26 using namespace notification;
27 using namespace notification::item;
32 class GroupItemTest : public ::testing::Test {
34 void SetUp() override {}
35 void TearDown() override {}
38 TEST_F(GroupItemTest, AddChild) {
39 GroupItem item("GROUP1");
40 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
41 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
42 ASSERT_EQ(item.GetChildren().size(), 2);
45 TEST_F(GroupItemTest, RemoveChild) {
46 GroupItem item("GROUP1");
47 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
48 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
49 ASSERT_EQ(item.GetChildren().size(), 2);
51 item.RemoveChild("btn1");
52 ASSERT_EQ(item.GetChildren().size(), 1);
55 int __fake_app_get_name(char** app_name) {
56 *app_name = strdup("unittest_appname");
60 TEST_F(GroupItemTest, SerializeDeserialize) {
61 app_get_name_fake.custom_fake = __fake_app_get_name;
63 GroupItem item("GROUP1");
64 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
65 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
67 Bundle b = item.Serialize();
68 shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
69 ASSERT_EQ(gen_item->GetType(), item.GetType());
71 auto gen_group = static_pointer_cast<GroupItem>(gen_item);
72 list<shared_ptr<AbstractItem>> gen_children_list = gen_group->GetChildren();
73 list<shared_ptr<AbstractItem>> origin_children_list = item.GetChildren();
75 list<shared_ptr<AbstractItem>>::iterator it = origin_children_list.begin();
76 for (auto& i : gen_children_list) {
77 ASSERT_EQ(i->GetType(), (*it)->GetType());
78 if (i->GetType() == AbstractItem::Button) {
79 ButtonItem* btn1 = static_cast<ButtonItem*>(i.get());
80 ButtonItem* btn2 = static_cast<ButtonItem*>((*it).get());
81 ASSERT_EQ(btn1->GetTitle(), btn2->GetTitle());
85 ASSERT_EQ(item.GetChildren().size(), 2);
88 TEST_F(GroupItemTest, FindByID) {
89 GroupItem item("GROUP1");
90 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
91 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
92 ASSERT_EQ(item.GetChildren().size(), 2);
94 AbstractItem& child = item.FindByID("btn2");
95 ButtonItem& btn = static_cast<ButtonItem&>(child);
96 ASSERT_EQ(btn.GetTitle(), "test2");
99 TEST_F(GroupItemTest, FindByIDGroupItem) {
100 GroupItem item("GROUP1");
101 shared_ptr<GroupItem> gr2 = shared_ptr<GroupItem>(new GroupItem("GROUP2"));
102 shared_ptr<GroupItem> gr3 = shared_ptr<GroupItem>(new GroupItem("GROUP3"));
103 gr2->AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
104 gr2->AddChild(std::make_shared<ButtonItem>("btn3", "test3"));
105 gr2->AddChild(std::make_shared<ButtonItem>("btn4", "test4"));
106 gr3->AddChild(std::make_shared<ButtonItem>("btn6", "test6"));
109 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
111 item.AddChild(std::make_shared<ButtonItem>("btn5", "test5"));
112 ASSERT_EQ(item.GetChildren().size(), 3);
114 AbstractItem& child = item.FindByID("btn3");
115 ButtonItem& btn = static_cast<ButtonItem&>(child);
116 ASSERT_EQ(btn.GetTitle(), "test3");
118 AbstractItem& child2 = item.FindByID("GROUP3");
119 GroupItem& ret_gr = static_cast<GroupItem&>(child2);
120 ASSERT_EQ(ret_gr.GetChildren().size(), 1);
124 TEST_F(GroupItemTest, IsItemTypeExist) {
125 GroupItem item("GROUP1");
126 shared_ptr<GroupItem> gr2 = shared_ptr<GroupItem>(new GroupItem("GROUP2"));
127 shared_ptr<GroupItem> gr3 = shared_ptr<GroupItem>(new GroupItem("GROUP3"));
128 gr2->AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
129 gr2->AddChild(std::make_shared<ButtonItem>("btn3", "test3"));
130 gr2->AddChild(std::make_shared<ButtonItem>("btn4", "test4"));
131 gr3->AddChild(std::make_shared<ButtonItem>("btn6", "test6"));
132 gr3->AddChild(std::make_shared<TextItem>("text1", "text1"));
135 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
137 item.AddChild(std::make_shared<ButtonItem>("btn5", "test5"));
138 ASSERT_EQ(item.GetChildren().size(), 3);
140 ASSERT_EQ(item.IsItemTypeExist(AbstractItem::Text), true);
141 ASSERT_EQ(item.IsItemTypeExist(AbstractItem::Image), false);
144 TEST_F(GroupItemTest, FindByIDNullItemReturn) {
145 GroupItem item("GROUP1");
146 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
147 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
148 ASSERT_EQ(item.GetChildren().size(), 2);
150 AbstractItem& child = item.FindByID("not_exist_button");
151 ASSERT_EQ(child.GetType(), AbstractItem::NullObject);
154 TEST_F(GroupItemTest, GetAppLabel) {
155 app_get_name_fake.custom_fake = __fake_app_get_name;
157 GroupItem item("GROUP1");
158 string app_label = item.GetAppLabel();
160 ASSERT_EQ(app_label, "unittest_appname");
163 TEST_F(GroupItemTest, SetAppLabel) {
164 GroupItem item("GROUP1");
165 item.SetAppLabel("test");
166 string app_label = item.GetAppLabel();
168 ASSERT_EQ(app_label, "test");
171 TEST_F(GroupItemTest, SetDirection) {
172 GroupItem item("GROUP1");
173 item.SetDirection(true);
175 ASSERT_TRUE(item.IsVertical());