2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
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"
24 #include "include/service_common.h"
25 #include "include/notification_ex_service.h"
28 using ::testing::Invoke;
29 using ::testing::Return;
33 class Mocks : public ::testing::NiceMock<AulMock>,
34 public ::testing::NiceMock<GioMock>,
35 public ::testing::NiceMock<NotificationMock> {};
39 class NotificationEXServiceTest : public TestFixture {
41 NotificationEXServiceTest() : TestFixture(std::make_unique<Mocks>()) {}
42 virtual ~NotificationEXServiceTest() {}
44 virtual void SetUp() {
47 virtual void TearDown() {
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");
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(
71 .WillRepeatedly(Return(msg2));
72 EXPECT_CALL(GetMock<GioMock>(), g_dbus_message_get_body(_))
73 .WillRepeatedly(Return(g_variant_new("(i)", 1)));
75 int ret = notification_ex_service_init(0);
77 GDBusConnection* inst_conn = notification_ex_service_get_gdbus_connection();
78 EXPECT_EQ(conn, inst_conn);
79 ret = notification_ex_service_fini();