Improve coverage
[platform/core/appfw/data-provider-master.git] / tests / unit_tests / src / test_notification_ex_service.cc
1 /*
2  * Copyright (c) 2023 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
19 #include "tests/mock/aul_mock.h"
20 #include "tests/mock/gio_mock.h"
21 #include "tests/mock/notification_mock.h"
22 #include "tests/mock/test_fixture.h"
23
24 #include "include/service_common.h"
25 #include "include/notification_ex_service.h"
26
27 using ::testing::_;
28 using ::testing::Invoke;
29 using ::testing::Return;
30
31 namespace {
32
33 class Mocks : public ::testing::NiceMock<AulMock>,
34     public ::testing::NiceMock<GioMock>,
35     public ::testing::NiceMock<NotificationMock> {};
36
37 }  //namespace
38
39 class NotificationEXServiceTest : public TestFixture {
40  public:
41   NotificationEXServiceTest() : TestFixture(std::make_unique<Mocks>()) {}
42   virtual ~NotificationEXServiceTest() {}
43
44   virtual void SetUp() {
45   }
46
47   virtual void TearDown() {
48   }
49 };
50
51 TEST_F(NotificationEXServiceTest, notification_ex_service) {
52   GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(calloc(1, 4));
53   GDBusMessage* msg = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
54   GDBusMessage* msg2 = static_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
55   g_dbus_message_set_body(msg2, g_variant_new("(i)", 1));
56   EXPECT_CALL(GetMock<GioMock>(), g_bus_own_name_on_connection(_, _, _, _, _,
57       _, _)).WillOnce(Return(1));
58   EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _))
59       .WillOnce(Return(conn));
60   EXPECT_CALL(GetMock<AulMock>(), aul_app_get_appid_bypid(_, _, _))
61       .WillRepeatedly(Invoke([](int pid, char* appid, int size) {
62         snprintf(appid, size, "%s", "org.tizen.helloworld");
63         return AUL_R_OK;
64       }));
65   EXPECT_CALL(GetMock<GioMock>(),
66       g_dbus_message_new_method_call(_, _, _, _))
67       .WillRepeatedly(Return(msg));
68   EXPECT_CALL(GetMock<GioMock>(),
69       g_dbus_connection_send_message_with_reply_sync(
70         _, _, _, _, _, _, _))
71       .WillRepeatedly(Return(msg2));
72   EXPECT_CALL(GetMock<GioMock>(), g_dbus_message_get_body(_))
73       .WillRepeatedly(Return(g_variant_new("(i)", 1)));
74
75   int ret = notification_ex_service_init(0);
76   EXPECT_EQ(ret, 0);
77   GDBusConnection* inst_conn = notification_ex_service_get_gdbus_connection();
78   EXPECT_EQ(conn, inst_conn);
79   ret = notification_ex_service_fini();
80   EXPECT_EQ(ret, 0);
81
82   free(conn);
83 }