Improve unit TCs
[platform/core/api/notification.git] / unittest / src / test_icon_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/icon_item.h"
21 #include "notification-ex/item_inflator.h"
22
23 using namespace notification;
24 using namespace notification::item;
25
26 class IconItemTest : public ::testing::Test {
27  public:
28   IconItem* item;
29   std::string id = "icon_id";
30   virtual void SetUp() {
31     item = new IconItem(id, "icon_path");
32   }
33   virtual void TearDown() {
34     delete item;
35   }
36 };
37
38 TEST_F(IconItemTest, create) {
39   EXPECT_NE(IconItemTest::item, nullptr);
40 }
41
42 TEST_F(IconItemTest, FindByID) {
43   AbstractItem& child = IconItemTest::item->FindByID(IconItemTest::id);
44   IconItem& icon = static_cast<IconItem&>(child);
45   ASSERT_EQ(icon.GetImagePath(), "icon_path");
46 }
47
48 TEST_F(IconItemTest, FindByIDNullItemReturn) {
49   AbstractItem& child = IconItemTest::item->FindByID("not_existed_item");
50   ASSERT_EQ(child.GetType(), IconItem::NullObject);
51 }
52
53 TEST_F(IconItemTest, SerializeDeserialize) {
54   Bundle b = IconItemTest::item->Serialize();
55
56   std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
57   ASSERT_EQ(IconItemTest::item->GetType(), gen_item->GetType());
58
59   auto gen_icon = std::static_pointer_cast<IconItem>(gen_item);
60   ASSERT_EQ(IconItemTest::item->GetImagePath(), gen_icon->GetImagePath());
61 }