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