eba55a732797b01c9377ad2ea6ffe19a97275d35
[platform/core/api/notification.git] / unittest / src / test_checkbox_item.cc
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <gtest/gtest.h>
18 #include <gmock/gmock.h>
19
20 #include "notification-ex/checkbox_item.h"
21 #include "notification-ex/item_inflator.h"
22
23 using namespace tizen_base;
24 using namespace notification;
25 using namespace notification::item;
26
27 class CheckBoxItemTest : public ::testing::Test {
28  public:
29   CheckBoxItem* item;
30   std::string id = "checkbox_id";
31   std::string title = "title";
32   bool isChecked = false;
33   virtual void SetUp() {
34     item = new CheckBoxItem(id, title, isChecked);
35   }
36   virtual void TearDown() {
37     delete item;
38   }
39 };
40
41 TEST_F(CheckBoxItemTest, create) {
42   EXPECT_NE(CheckBoxItemTest::item, nullptr);
43 }
44
45 TEST_F(CheckBoxItemTest, FindByID) {
46   AbstractItem& child = CheckBoxItemTest::item->FindByID(CheckBoxItemTest::id);
47   CheckBoxItem& checkbox = static_cast<CheckBoxItem&>(child);
48   ASSERT_EQ(checkbox.GetTitle(), CheckBoxItemTest::title);
49   ASSERT_EQ(checkbox.IsChecked(), CheckBoxItemTest::isChecked);
50 }
51
52 TEST_F(CheckBoxItemTest, FindByIDNullItemReturn) {
53   AbstractItem& child = CheckBoxItemTest::item->FindByID("not_existed_item");
54   ASSERT_EQ(child.GetType(), CheckBoxItem::NullObject);
55 }
56
57 TEST_F(CheckBoxItemTest, SerializeDeserialize) {
58   Bundle b = CheckBoxItemTest::item->Serialize();
59
60   std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
61   ASSERT_EQ(CheckBoxItemTest::item->GetType(), gen_item->GetType());
62
63   auto gen_checkbox = std::static_pointer_cast<CheckBoxItem>(gen_item);
64   ASSERT_EQ(CheckBoxItemTest::item->GetTitle(), gen_checkbox->GetTitle());
65 }