Update some items
[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 notification::item;
24
25 class CheckBoxItemTest : public ::testing::Test {
26  public:
27   CheckBoxItem* item;
28   std::string id = "checkbox_id";
29   std::string title = "title";
30   bool isChecked = false;
31   virtual void SetUp() {
32     item = new CheckBoxItem(id, title, isChecked);
33   }
34   virtual void TearDown() {
35     delete item;
36   }
37 };
38
39 TEST_F(CheckBoxItemTest, create) {
40   EXPECT_NE(CheckBoxItemTest::item, nullptr);
41 }
42
43 TEST_F(CheckBoxItemTest, FindByID) {
44   AbstractItem& child = CheckBoxItemTest::item->FindByID(CheckBoxItemTest::id);
45   CheckBoxItem& checkbox = static_cast<CheckBoxItem&>(child);
46   ASSERT_EQ(checkbox.GetTitle(), CheckBoxItemTest::title);
47   ASSERT_EQ(checkbox.IsChecked(), CheckBoxItemTest::isChecked);
48 }
49
50 TEST_F(CheckBoxItemTest, FindByIDNullItemReturn) {
51   AbstractItem& child = CheckBoxItemTest::item->FindByID("not_existed_item");
52   ASSERT_EQ(child.GetType(), CheckBoxItem::NullObject);
53 }
54
55 TEST_F(CheckBoxItemTest, SerializeDeserialize) {
56   Bundle b = CheckBoxItemTest::item->Serialize();
57
58   ItemFactory factory;
59   std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
60   ASSERT_EQ(CheckBoxItemTest::item->GetType(), gen_item.get()->GetType());
61
62   CheckBoxItem* gen_checkbox = static_cast<CheckBoxItem*>(gen_item.get());
63   ASSERT_EQ(CheckBoxItemTest::item->GetTitle(), gen_checkbox->GetTitle());
64 }