Improve coverage and add notification unittest
[platform/core/api/notification.git] / tests / noti_ex_unittest / src / test_noti_ex_event_info.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 <gmock/gmock.h>
18
19 #include "mock/app_common_mock.hh"
20 #include "mock/test_fixture.hh"
21 #include "notification-ex/event_info_internal.h"
22
23 using namespace tizen_base;
24 using namespace notification;
25 using namespace std;
26
27 namespace {
28 class Mocks :
29     virtual public ::testing::NiceMock<AppCommonMock> {};
30 } // namespace
31
32 class EventInfoTest : public TestFixture {
33  public:
34   EventInfoTest() : TestFixture(std::make_unique<::Mocks>()) {}
35  protected:
36   void SetUp() override {}
37   void TearDown() override {}
38 };
39
40 TEST_F(EventInfoTest, SerializeDeserialize) {
41   EventInfo info(EventInfo::Get, "test", "channel", "id");
42   Bundle b = info.Serialize();
43   EventInfo serialized(b);
44   ASSERT_EQ(serialized.GetEventType(), info.GetEventType());
45   ASSERT_EQ(serialized.GetOwner(), info.GetOwner());
46   ASSERT_EQ(serialized.GetChannel(), info.GetChannel());
47   ASSERT_EQ(serialized.GetItemId(), info.GetItemId());
48   ASSERT_EQ(serialized.GetUid(), info.GetUid());
49 }
50
51 TEST_F(EventInfoTest, GetString) {
52   ASSERT_EQ(EventInfo::GetString(EventInfo::Post), "Post");
53   ASSERT_EQ(EventInfo::GetString(EventInfo::Update), "Update");
54   ASSERT_EQ(EventInfo::GetString(EventInfo::Delete), "Delete");
55   ASSERT_EQ(EventInfo::GetString(EventInfo::Get), "Get");
56 }
57
58 TEST_F(EventInfoTest, GetSetEventType) {
59   EventInfo info(EventInfo::Get, "test", "channel", "id");
60   info.SetEventType(EventInfo::Post);
61   int type = info.GetEventType();
62   EXPECT_EQ(type, EventInfo::Post);
63 }
64
65 TEST_F(EventInfoTest, GetSetValidOwner) {
66   EventInfo info(EventInfo::Get, "test", "channel", "id");
67   info.SetValidatedOwner("testowner");
68   std::string owner = info.GetValidatedOwner();
69   EXPECT_STREQ(owner.c_str(), "testowner");
70 }
71
72 TEST_F(EventInfoTest, GetSetUid) {
73   EventInfo info(EventInfo::Get, "test", "channel", "id");
74   info.SetUid(5001);
75   uid_t my_uid = info.GetUid();
76   EXPECT_EQ(my_uid, 5001);
77 }
78
79 TEST_F(EventInfoTest, GetSetValidUid) {
80   EventInfo info(EventInfo::Get, "test", "channel", "id");
81   info.SetValidatedUid(5001);
82   uid_t my_uid = info.GetValidatedUid();
83   EXPECT_EQ(my_uid, 5001);
84 }
85
86 TEST_F(EventInfoTest, GetSetError) {
87   EventInfo info(EventInfo::Get, "test", "channel", "id");
88   info.SetError(NotificationError::ERROR_NONE);
89   NotificationError err = info.GetError();
90   EXPECT_EQ(err, NotificationError::ERROR_NONE);
91 }