summaryrefslogtreecommitdiff
path: root/tests/noti_ex_unittest/src/test_noti_ex_text_item.cc
blob: 744a2309fbaf9bb92f1c3722704c64768dd8674b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include <gmock/gmock.h>

#include "mock/app_common_mock.hh"
#include "mock/test_fixture.hh"
#include "notification-ex/text_item.h"
#include "notification-ex/item_inflator.h"

using namespace tizen_base;
using namespace notification;
using namespace notification::item;

namespace {
class Mocks :
    virtual public ::testing::NiceMock<AppCommonMock> {};
} // namespace

class TexttItemTest : public TestFixture {
 public:
  TexttItemTest() : TestFixture(std::make_unique<::Mocks>()) {}
  virtual void SetUp() {
  }
  virtual void TearDown() {
  }
};

TEST_F(TexttItemTest, FindByID) {
  TextItem item("text_id", "contents", "hyperlink");

  AbstractItem& child = item.FindByID("text_id");
  TextItem& btn = static_cast<TextItem&>(child);
  ASSERT_EQ(btn.GetContents(), "contents");
}

TEST_F(TexttItemTest, FindByIDNullItemReturn) {
  TextItem item("text_id", "contents", "hyperlink");

  AbstractItem& child = item.FindByID("not_existed_item");
  ASSERT_EQ(child.GetType(), TextItem::NullObject);
}

TEST_F(TexttItemTest, SerializeDeserializeGetContents) {
  TextItem item("text_id", "contents");
  Bundle b = item.Serialize();
  std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(b);
  ASSERT_EQ(gen_item->GetType(), item.GetType());

  auto gen_text = std::static_pointer_cast<TextItem>(gen_item);
  ASSERT_EQ(item.GetContents(), gen_text->GetContents());
}

TEST_F(TexttItemTest, SetContentsGetContents) {
  TextItem item("text_id", "contents");
  ASSERT_EQ(item.GetContents(), "contents");

  item.SetContents("changed");
  ASSERT_EQ(item.GetContents(), "changed");
}

TEST_F(TexttItemTest, GetHyperLink) {
  TextItem item("text_id", "contents");
  ASSERT_TRUE(item.GetHyperLink().empty());

  TextItem item2("text_id", "contents", "hyperlink2");
  ASSERT_EQ(item2.GetHyperLink(), "hyperlink2");
}