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::item;
17 class GroupItemTest : public ::testing::Test {
19 void SetUp() override {}
20 void TearDown() override {}
23 TEST_F(GroupItemTest, AddChild) {
24 GroupItem item("GROUP1");
25 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
26 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
27 ASSERT_EQ(item.GetChildren().size(), 2);
30 TEST_F(GroupItemTest, RemoveChild) {
31 GroupItem item("GROUP1");
32 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
33 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
34 ASSERT_EQ(item.GetChildren().size(), 2);
36 item.RemoveChild("btn1");
37 ASSERT_EQ(item.GetChildren().size(), 1);
40 TEST_F(GroupItemTest, SerializeDeserialize) {
41 GroupItem item("GROUP1");
42 item.AddChild(std::make_shared<ButtonItem>("btn1", "test1"));
43 item.AddChild(std::make_shared<ButtonItem>("btn2", "test2"));
45 Bundle b = item.Serialize();
47 shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
48 ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
50 GroupItem* gen_group = static_cast<GroupItem*>(gen_item.get());
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.get()->GetType(), (*it).get()->GetType());
57 if (i.get()->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 shared_ptr<AbstractItem> child = item.FindByID("btn2");
74 ButtonItem* btn = static_cast<ButtonItem*>(child.get());
75 ASSERT_EQ(btn->GetTitle(), "test2");
78 int __fake_app_get_name(char** app_name) {
79 *app_name = (char*)"unittest_appname";
83 TEST_F(GroupItemTest, GetAppLabel) {
84 app_get_name_fake.custom_fake = __fake_app_get_name;
86 GroupItem item("GROUP1");
87 string app_label = item.GetAppLabel();
89 ASSERT_EQ(app_label, "unittest_appname");
92 TEST_F(GroupItemTest, SetDirection) {
93 GroupItem item("GROUP1");
94 item.SetDirection(true);
96 ASSERT_TRUE(item.IsVertical());