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