1 // Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include <gmock/gmock.h>
7 #include "notification-ex/group_item.h"
8 #include "notification-ex/button_item.h"
9 #include "notification-ex/item_inflator.h"
10 #include "unittest/mock/app_common.h"
12 using namespace tizen_base;
13 using namespace notification;
14 using namespace notification::item;
19 class GroupItemTest : public ::testing::Test {
21 void SetUp() override {}
22 void TearDown() override {}
25 TEST_F(GroupItemTest, AddChild) {
26 GroupItem item("GROUP1");
27 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
28 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
29 ASSERT_EQ(item.GetChildren().size(), 2);
32 TEST_F(GroupItemTest, RemoveChild) {
33 GroupItem item("GROUP1");
34 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
35 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
36 ASSERT_EQ(item.GetChildren().size(), 2);
38 item.RemoveChild("btn1");
39 ASSERT_EQ(item.GetChildren().size(), 1);
42 TEST_F(GroupItemTest, SerializeDeserialize) {
43 GroupItem item("GROUP1");
44 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
45 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
47 Bundle b = item.Serialize();
48 shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
49 ASSERT_EQ(gen_item->GetType(), item.GetType());
51 auto gen_group = static_pointer_cast<GroupItem>(gen_item);
52 list<shared_ptr<AbstractItem>> gen_children_list = gen_group->GetChildren();
53 list<shared_ptr<AbstractItem>> origin_children_list = item.GetChildren();
55 list<shared_ptr<AbstractItem>>::iterator it = origin_children_list.begin();
56 for (auto& i : gen_children_list) {
57 ASSERT_EQ(i->GetType(), (*it)->GetType());
58 if (i->GetType() == AbstractItem::Button) {
59 ButtonItem* btn1 = static_cast<ButtonItem*>(i.get());
60 ButtonItem* btn2 = static_cast<ButtonItem*>((*it).get());
61 ASSERT_EQ(btn1->GetTitle(), btn2->GetTitle());
65 ASSERT_EQ(item.GetChildren().size(), 2);
68 TEST_F(GroupItemTest, FindByID) {
69 GroupItem item("GROUP1");
70 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
71 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
72 ASSERT_EQ(item.GetChildren().size(), 2);
74 AbstractItem& child = item.FindByID("btn2");
75 ButtonItem& btn = static_cast<ButtonItem&>(child);
76 ASSERT_EQ(btn.GetTitle(), "test2");
79 TEST_F(GroupItemTest, FindByIDNullItemReturn) {
80 GroupItem item("GROUP1");
81 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
82 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
83 ASSERT_EQ(item.GetChildren().size(), 2);
85 AbstractItem& child = item.FindByID("not_exist_button");
86 ASSERT_EQ(child.GetType(), AbstractItem::NullObject);
89 int __fake_app_get_name(char** app_name) {
90 *app_name = (char*)"unittest_appname";
94 TEST_F(GroupItemTest, GetAppLabel) {
95 app_get_name_fake.custom_fake = __fake_app_get_name;
97 GroupItem item("GROUP1");
98 string app_label = item.GetAppLabel();
100 ASSERT_EQ(app_label, "unittest_appname");
103 TEST_F(GroupItemTest, SetDirection) {
104 GroupItem item("GROUP1");
105 item.SetDirection(true);
107 ASSERT_TRUE(item.IsVertical());