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 notification;
13 using namespace notification::item;
18 class GroupItemTest : public ::testing::Test {
20 void SetUp() override {}
21 void TearDown() override {}
24 TEST_F(GroupItemTest, AddChild) {
25 GroupItem item("GROUP1");
26 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
27 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
28 ASSERT_EQ(item.GetChildren().size(), 2);
31 TEST_F(GroupItemTest, RemoveChild) {
32 GroupItem item("GROUP1");
33 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
34 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
35 ASSERT_EQ(item.GetChildren().size(), 2);
37 item.RemoveChild("btn1");
38 ASSERT_EQ(item.GetChildren().size(), 1);
41 TEST_F(GroupItemTest, SerializeDeserialize) {
42 GroupItem item("GROUP1");
43 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
44 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
46 Bundle b = item.Serialize();
47 shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
48 ASSERT_EQ(gen_item->GetType(), item.GetType());
50 auto gen_group = static_pointer_cast<GroupItem>(gen_item);
51 list<shared_ptr<AbstractItem>> gen_children_list = gen_group->GetChildren();
52 list<shared_ptr<AbstractItem>> origin_children_list = item.GetChildren();
54 list<shared_ptr<AbstractItem>>::iterator it = origin_children_list.begin();
55 for (auto& i : gen_children_list) {
56 ASSERT_EQ(i->GetType(), (*it)->GetType());
57 if (i->GetType() == AbstractItem::Button) {
58 ButtonItem* btn1 = static_cast<ButtonItem*>(i.get());
59 ButtonItem* btn2 = static_cast<ButtonItem*>((*it).get());
60 ASSERT_EQ(btn1->GetTitle(), btn2->GetTitle());
64 ASSERT_EQ(item.GetChildren().size(), 2);
67 TEST_F(GroupItemTest, FindByID) {
68 GroupItem item("GROUP1");
69 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
70 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
71 ASSERT_EQ(item.GetChildren().size(), 2);
73 AbstractItem& child = item.FindByID("btn2");
74 ButtonItem& btn = static_cast<ButtonItem&>(child);
75 ASSERT_EQ(btn.GetTitle(), "test2");
78 TEST_F(GroupItemTest, FindByIDNullItemReturn) {
79 GroupItem item("GROUP1");
80 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
81 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
82 ASSERT_EQ(item.GetChildren().size(), 2);
84 AbstractItem& child = item.FindByID("not_exist_button");
85 ASSERT_EQ(child.GetType(), AbstractItem::NullObject);
88 int __fake_app_get_name(char** app_name) {
89 *app_name = (char*)"unittest_appname";
93 TEST_F(GroupItemTest, GetAppLabel) {
94 app_get_name_fake.custom_fake = __fake_app_get_name;
96 GroupItem item("GROUP1");
97 string app_label = item.GetAppLabel();
99 ASSERT_EQ(app_label, "unittest_appname");
102 TEST_F(GroupItemTest, SetDirection) {
103 GroupItem item("GROUP1");
104 item.SetDirection(true);
106 ASSERT_TRUE(item.IsVertical());