Use gmock instead of fff
[platform/core/api/notification.git] / tests / unittest / src / test_noti_ex_text_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 "mock/app_common_mock.h"
21 #include "mock/test_fixture.h"
22 #include "notification-ex/text_item.h"
23 #include "notification-ex/item_inflator.h"
24
25 using namespace tizen_base;
26 using namespace notification;
27 using namespace notification::item;
28
29 namespace {
30 class Mocks :
31     virtual public ::testing::NiceMock<AppCommonMock> {};
32 } // namespace
33
34 class TexttItemTest : public TestFixture {
35  public:
36   TexttItemTest() : TestFixture(std::make_unique<::Mocks>()) {}
37   virtual void SetUp() {
38   }
39   virtual void TearDown() {
40   }
41 };
42
43 TEST_F(TexttItemTest, FindByID) {
44   TextItem item("text_id", "contents", "hyperlink");
45
46   AbstractItem& child = item.FindByID("text_id");
47   TextItem& btn = static_cast<TextItem&>(child);
48   ASSERT_EQ(btn.GetContents(), "contents");
49 }
50
51 TEST_F(TexttItemTest, FindByIDNullItemReturn) {
52   TextItem item("text_id", "contents", "hyperlink");
53
54   AbstractItem& child = item.FindByID("not_existed_item");
55   ASSERT_EQ(child.GetType(), TextItem::NullObject);
56 }
57
58 TEST_F(TexttItemTest, SerializeDeserializeGetContents) {
59   TextItem item("text_id", "contents");
60   Bundle b = item.Serialize();
61   std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
62   ASSERT_EQ(gen_item->GetType(), item.GetType());
63
64   auto gen_text = std::static_pointer_cast<TextItem>(gen_item);
65   ASSERT_EQ(item.GetContents(), gen_text->GetContents());
66 }
67
68 TEST_F(TexttItemTest, SetContentsGetContents) {
69   TextItem item("text_id", "contents");
70   ASSERT_EQ(item.GetContents(), "contents");
71
72   item.SetContents("changed");
73   ASSERT_EQ(item.GetContents(), "changed");
74 }
75
76 TEST_F(TexttItemTest, GetHyperLink) {
77   TextItem item("text_id", "contents");
78   ASSERT_TRUE(item.GetHyperLink().empty());
79
80   TextItem item2("text_id", "contents", "hyperlink2");
81   ASSERT_EQ(item2.GetHyperLink(), "hyperlink2");
82 }