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