summaryrefslogtreecommitdiff
path: root/test/unit_tests/test_message_port.cc
blob: 77eec350689879a7355f434a46b20acd0c035f50 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/*
 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * 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 <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <bundle_cpp.h>
#include <bundle_internal.h>
#include <pkgmgr_info_mock.h>

#include <iostream>
#include <memory>

#include "message_port.h"
#include "gio_mock.h"
#include "aul.h"
#include "test_fixture.h"

using ::testing::_;
using ::testing::DoAll;
using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::Invoke;

typedef enum {
  LOG_ID_INVALID = -1,
  LOG_ID_MAIN,
  LOG_ID_RADIO,
  LOG_ID_SYSTEM,
  LOG_ID_APPS,
  LOG_ID_KMSG,
  LOG_ID_SYSLOG,
  LOG_ID_MAX
} log_id_t;

extern "C" int __dlog_print(
  log_id_t log_id, int prio, const char* tag, const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  vprintf(fmt, ap);
  va_end(ap);
  printf("\n");

  return 0;
}

extern "C" void g_object_unref(gpointer _object) {
}

extern "C" gboolean g_source_remove(guint tag) {
  return true;
}

extern "C" int aul_request_message_port_socket_pair(int* fd) {
  fd[0] = 77;
  fd[1] = 777;
  return 0;
}

extern "C" int pthread_mutex_lock(pthread_mutex_t* mutex) {
  return 0;
}

extern "C" int pthread_mutex_unlock(pthread_mutex_t* mutex) {
  return 0;
}

extern "C" int aul_app_get_appid_bypid(int pid, char* appid, int len) {
  char test[5] = "test";
  snprintf(appid, sizeof(test), "%s", test);
  return 0;
}

extern "C" gint g_unix_fd_list_append(GUnixFDList* list,
    gint fd, GError** error) {
  return 0;
}


GVariant* __call_sync_reply;
extern "C" GVariant* g_dbus_connection_call_sync(
    GDBusConnection* connection, const gchar* bus_name,
    const gchar* object_path, const gchar* interface_name,
    const gchar* method_name, GVariant* parameters,
    const GVariantType* reply_type, GDBusCallFlags flags,
    gint timeout_msec, GCancellable* cancellable, GError** error) {
  if (__call_sync_reply != nullptr)
    return __call_sync_reply;
  return g_variant_new("(u)", 1);
}

class Mocks : public ::testing::NiceMock<GioMock>,
              public ::testing::NiceMock<PkgmgrInfoMock> {};

class MessagePortTest : public TestFixture {
 public:
  MessagePortTest() : TestFixture(std::make_unique<Mocks>()) {}
  virtual ~MessagePortTest() {}

  virtual void SetUp() {
  }

  virtual void TearDown() {
  }
};

static void __message_cb(int local_port_id, const char* remote_app_id,
    const char* remote_port, bool trusted_remote_port,
    bundle* message, void* user_data) {
}

static void __trusted_message_cb(int trusted_local_port_id,
    const char* remote_app_id, const char* remote_port,
    bool trusted_remote_port, bundle* message, void* user_data) {
}

struct _GDBusMessage {
  int test;
};
typedef struct _GDBusMessage GDBusMessage;
GDBusMessage __message;

GUnixFDList __fd_list;
extern "C" GUnixFDList* g_dbus_message_get_unix_fd_list(
    GDBusMessage* message) {
  return &__fd_list;
}

typedef struct _GDBusConnection GDBusConnection;
struct _GDBusConnection {
  int test;
};

GDBusConnection __gdbus_conn;
int __port_id;
static guint __connection_register_object(GDBusConnection* connection,
    const gchar* object_path, GDBusInterfaceInfo* interface_info,
    const GDBusInterfaceVTable* vtable, gpointer user_data,
    GDestroyNotify user_data_free_func, GError** error) {
  tizen_base::Bundle msg;
  vtable->method_call(&__gdbus_conn, "sender", "obj_path", "iface_name",
      "send_message",
      g_variant_new("(ssbbssbus)", "test", "PORT", 0, 0, "test",
        "PORT", 0, msg.ToRaw().second, msg.ToRaw().first.get()),
      nullptr, nullptr);
  return __port_id;
}

static guint __connection_register_object_trusted(GDBusConnection* connection,
    const gchar* object_path, GDBusInterfaceInfo* interface_info,
    const GDBusInterfaceVTable* vtable, gpointer user_data,
    GDestroyNotify user_data_free_func, GError** error) {
  tizen_base::Bundle msg;
  vtable->method_call(&__gdbus_conn, "sender", "obj_path", "iface_name",
      "send_message",
      g_variant_new("(ssbbssbus)", "test", "PORT", 1, 0, "test",
        "PORT", 0, 1, msg.ToRaw().first.get()),
      nullptr, nullptr);
  return __port_id;
}

TEST_F(MessagePortTest, message_port_register_local_port) {
  EXPECT_CALL(GetMock<GioMock>(), g_bus_get_sync(_, _, _)).
          WillOnce(Return(&__gdbus_conn));
  GDBusNodeInfo* info = reinterpret_cast<GDBusNodeInfo*>(
      malloc(sizeof(GDBusNodeInfo)));
  info->ref_count = 10;
  info->path = NULL;
  info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
      malloc(sizeof(GDBusInterfaceInfo*)));
  info->nodes = NULL;
  info->annotations = NULL;
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_connection_register_object(_, _, _, _, _, _, _)).
          WillOnce(Return(1));

  int port = message_port_register_local_port("PORT", __message_cb, nullptr);
  EXPECT_EQ(port, 1);
  port = message_port_register_local_port("PORT", __message_cb, nullptr);
  EXPECT_EQ(port, 1);
}

extern "C" gint* g_unix_fd_list_steal_fds(GUnixFDList* list, gint* length) {
  gint* fds = (gint*)calloc(2, sizeof(gint));
  fds[0] = 1;
  fds[1] = 2;
  return fds;
}

GIOChannel __gio_channel;
extern "C" GIOChannel* g_io_channel_unix_new(gint fd) {
  return &__gio_channel;
}

GIOFunc __io_func;
gpointer __io_data;
GDestroyNotify __io_notify;
extern "C" guint g_io_add_watch_full(GIOChannel* channel, gint priority,
    GIOCondition condition, GIOFunc func, gpointer user_data,
    GDestroyNotify notify) {
  __io_func = func;
  __io_data = user_data;
  __io_notify = notify;
  return 1;
}

extern "C" GIOStatus g_io_channel_shutdown(GIOChannel* channel,
    gboolean flush, GError** err) {
  return G_IO_STATUS_NORMAL;
}

extern "C" void g_io_channel_unref(GIOChannel* channel) {
}

extern "C" gint g_io_channel_unix_get_fd(GIOChannel* channel) {
  return 1;
}

extern "C" ssize_t read(int desc, void* buf, size_t count) {
  if (count == 4 && buf != NULL) {
    int val = 4;
    memcpy(buf, &val, count);
  }
  return count;
}

extern "C" ssize_t write(int fd, const void* buf, size_t count) {
  return count;
}

guint __g_bus_watch_name_on_connection(GDBusConnection* connection,
    const gchar* name, GBusNameWatcherFlags flags,
    GBusNameAppearedCallback name_appeared_handler,
    GBusNameVanishedCallback name_vanished_handler,
    gpointer user_data,
    GDestroyNotify user_data_free_func) {
  int* id = NULL;
  name_appeared_handler(nullptr, "test", "test", (gpointer)id);
  name_vanished_handler(nullptr, "test", (gpointer)id);
  return 10;
}

TEST_F(MessagePortTest, message_port_register_local_port2) {
  GDBusNodeInfo* info = reinterpret_cast<GDBusNodeInfo*>(
      malloc(sizeof(GDBusNodeInfo)));
  info->ref_count = 10;
  info->path = NULL;
  info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
      malloc(sizeof(GDBusInterfaceInfo*)));
  info->nodes = NULL;
  info->annotations = NULL;
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_connection_register_object(_, _, _, _, _, _, _)).
          WillOnce(Invoke(__connection_register_object));
  EXPECT_CALL(GetMock<GioMock>(),
      g_bus_watch_name_on_connection(_, _, _, _, _, _, _)).
          WillOnce(Invoke(__g_bus_watch_name_on_connection));
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_message_new_method_call(_, _, _, _)).
          WillOnce(Return(&__message));
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
          WillOnce(Return(&__message));

  __port_id = 10;
  int port = message_port_register_local_port("PORT2", __message_cb, nullptr);
  EXPECT_EQ(port, __port_id);
  __io_func(nullptr, G_IO_IN, __io_data);
}

TEST_F(MessagePortTest, message_port_register_local_port3) {
  GDBusNodeInfo* info = reinterpret_cast<GDBusNodeInfo*>(
      malloc(sizeof(GDBusNodeInfo)));
  info->ref_count = 10;
  info->path = NULL;
  info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
      malloc(sizeof(GDBusInterfaceInfo*)));
  info->nodes = NULL;
  info->annotations = NULL;
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_connection_register_object(_, _, _, _, _, _, _)).
          WillOnce(Invoke(__connection_register_object_trusted));

  __port_id = 20;
  int port = message_port_register_local_port("PORT3", __message_cb, nullptr);
  EXPECT_EQ(port, __port_id);
  __io_notify(__io_data);
}

TEST_F(MessagePortTest, message_port_register_local_port_n) {
  int port = message_port_register_local_port(nullptr, __message_cb, nullptr);
  EXPECT_EQ(port, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_send_message) {
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_message_new_method_call(_, _, _, _)).
          WillOnce(Return(&__message));

  tizen_base::Bundle message;
  int ret = message_port_send_message("test", "PORT", message.GetHandle());
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_send_message_n) {
  int ret = message_port_send_message(nullptr, "PORT", nullptr);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_send_message_with_local_port) {
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_message_new_method_call(_, _, _, _)).
          WillOnce(Return(&__message));

  tizen_base::Bundle message;
  int ret = message_port_send_message_with_local_port(
      "test", "PORT", message.GetHandle(), 1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_send_message_with_local_port_n1) {
  int ret = message_port_send_message_with_local_port(
      nullptr, "PORT", nullptr, 1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_send_message_with_local_port_n2) {
  tizen_base::Bundle message;
  int ret = message_port_send_message_with_local_port(
      "test", "PORT", message.GetHandle(), -1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_send_message_with_local_port2) {
  if (__call_sync_reply != nullptr)
    g_variant_unref(__call_sync_reply);
  __call_sync_reply = g_variant_new("(b)", true);

  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_message_new_method_call(_, _, _, _)).
          WillOnce(Return(&__message));
  tizen_base::Bundle message;
  int ret = message_port_send_message_with_local_port(
      "remote_app", "PORT", message.GetHandle(), 1);
  g_variant_unref(__call_sync_reply);
  __call_sync_reply = nullptr;

  ret = message_port_send_message_with_local_port(
      "remote_app", "PORT", message.GetHandle(), 1);
  g_variant_unref(__call_sync_reply);
  __call_sync_reply = nullptr;

  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
  __io_func(nullptr, G_IO_IN, __io_data);
}

TEST_F(MessagePortTest, message_port_send_message_with_local_port3) {
  if (__call_sync_reply != nullptr)
    g_variant_unref(__call_sync_reply);
  __call_sync_reply = g_variant_new("(b)", true);

  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_message_new_method_call(_, _, _, _)).
          WillOnce(Return(&__message));
  tizen_base::Bundle message;
  int ret = message_port_send_message_with_local_port(
      "remote_app", "PORT", message.GetHandle(), 1);
  g_variant_unref(__call_sync_reply);
  __call_sync_reply = nullptr;
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
  __io_notify(__io_data);
}

TEST_F(MessagePortTest, message_port_register_trusted_local_port) {
  GDBusNodeInfo* info = reinterpret_cast<GDBusNodeInfo*>(
      malloc(sizeof(GDBusNodeInfo)));
  info->ref_count = 10;
  info->path = NULL;
  info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
      malloc(sizeof(GDBusInterfaceInfo*)));
  info->nodes = NULL;
  info->annotations = NULL;
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_connection_register_object(_, _, _, _, _, _, _)).
          WillOnce(Return(2));

  int port = message_port_register_trusted_local_port("PORT",
      __trusted_message_cb, nullptr);
  EXPECT_EQ(port, 2);
}

TEST_F(MessagePortTest, message_port_register_trusted_local_port_n) {
  int port = message_port_register_trusted_local_port(
      nullptr, __message_cb, nullptr);
  EXPECT_EQ(port, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_send_trusted_message_with_local_port) {
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_message_new_method_call(_, _, _, _)).
          WillOnce(Return(&__message));

  tizen_base::Bundle message;
  int ret = message_port_send_trusted_message_with_local_port(
      "test", "PORT", message.GetHandle(), 1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_send_trusted_message_with_local_port_n1) {
  int ret = message_port_send_trusted_message_with_local_port(
      nullptr, "PORT", nullptr, 1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_send_trusted_message_with_local_port_n2) {
  tizen_base::Bundle message;
  int ret = message_port_send_trusted_message_with_local_port(
      "test", "PORT", message.GetHandle(), -1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_send_trusted_message) {
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_message_new_method_call(_, _, _, _)).
          WillOnce(Return(&__message));

  tizen_base::Bundle message;
  int ret = message_port_send_trusted_message(
      "test", "PORT", message.GetHandle());
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_send_trusted_message_n) {
  int ret = message_port_send_trusted_message(nullptr, "PORT", nullptr);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_send_trusted_message_n2) {
  EXPECT_CALL(GetMock<GioMock>(),
      g_dbus_message_new_method_call(_, _, _, _)).
          WillOnce(Return(nullptr));

  tizen_base::Bundle message;
  int ret = message_port_send_trusted_message(
      "test", "PORT", message.GetHandle());
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_OUT_OF_MEMORY);
}

TEST_F(MessagePortTest, message_port_unregister_local_port) {
  int ret = message_port_unregister_local_port(1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_unregister_local_port_n) {
  int ret = message_port_unregister_local_port(-1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_unregister_trusted_local_port) {
  int ret = message_port_unregister_trusted_local_port(2);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_unregister_trusted_local_port_n) {
  int ret = message_port_unregister_trusted_local_port(-1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_check_remote_port) {
  bool exist;

  int ret = message_port_check_remote_port("test", "test", &exist);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_check_remote_port_n) {
  bool exist;

  int ret = message_port_check_remote_port(nullptr, "test", &exist);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_check_trusted_remote_port) {
  pkgmgrinfo_cert_compare_result_type_e res = PMINFO_CERT_COMPARE_MATCH;
  EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
      pkgmgrinfo_pkginfo_compare_usr_app_cert_info(_, _, _, _)).
      WillOnce(DoAll(SetArgPointee<3>(res),
                      Return(0)));

  if (__call_sync_reply != nullptr)
    g_variant_unref(__call_sync_reply);
  __call_sync_reply = g_variant_new("(b)", true);

  tizen_base::Bundle message;
  bool exist;
  int ret = message_port_check_trusted_remote_port("test2", "PORT", &exist);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_check_trusted_remote_port_n) {
  EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
      pkgmgrinfo_appinfo_get_usr_appinfo(_, _, _)).
      Times(8).
      WillOnce(Return(1)).
      WillOnce(Return(0)).
      WillOnce(Return(0)).
      WillOnce(Return(1)).
      WillOnce(Return(0)).
      WillOnce(Return(0)).
      WillOnce(Return(0)).
      WillOnce(Return(0));
  EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
      pkgmgrinfo_appinfo_is_preload(_, _)).
      Times(6).
      WillOnce(Return(1)).
      WillOnce(Return(0)).
      WillOnce(Return(0)).
      WillOnce(Return(1)).
      WillOnce(DoAll(SetArgPointee<1>(true),
                      Return(0))).
      WillOnce(DoAll(SetArgPointee<1>(true),
                      Return(0)));
  EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
      pkgmgrinfo_pkginfo_compare_usr_app_cert_info(_, _, _, _)).
      WillRepeatedly(Return(-1));
  bool exist;
  int ret = message_port_check_trusted_remote_port(nullptr, "PORT", &exist);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);

  //For code coverage
  __call_sync_reply = g_variant_new("(b)", true);
  ret = message_port_check_trusted_remote_port("test3", "PORT", &exist);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH);

  __call_sync_reply = g_variant_new("(b)", true);
  ret = message_port_check_trusted_remote_port("test4", "PORT", &exist);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH);

  __call_sync_reply = g_variant_new("(b)", true);
  ret = message_port_check_trusted_remote_port("test5", "PORT", &exist);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH);

  __call_sync_reply = g_variant_new("(b)", true);
  ret = message_port_check_trusted_remote_port("test6", "PORT", &exist);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH);

  __call_sync_reply = g_variant_new("(b)", true);
  ret = message_port_check_trusted_remote_port("test7", "PORT", &exist);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

static void __registration_event_cb(const char* remote_app_id,
  const char* remote_port, bool trusted_remote_port, void* user_data) {
}

TEST_F(MessagePortTest, message_port_add_registered_cb) {
  EXPECT_CALL(GetMock<GioMock>(),
      g_bus_watch_name_on_connection(_, _, _, _, _, _, _)).WillOnce(
        Invoke(__g_bus_watch_name_on_connection));
  int watcher_id;
  int ret = message_port_add_registered_cb("test", "PORT", false,
      __registration_event_cb, nullptr, &watcher_id);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_add_registered_cb_n) {
  int watcher_id;
  int ret = message_port_add_registered_cb(nullptr, "PORT", false,
      __registration_event_cb, nullptr, &watcher_id);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_add_unregistered_cb) {
  EXPECT_CALL(GetMock<GioMock>(),
      g_bus_watch_name_on_connection(_, _, _, _, _, _, _)).WillOnce(Return(2));
  int watcher_id;
  int ret = message_port_add_unregistered_cb("test", "PORT", false,
      __registration_event_cb, nullptr, &watcher_id);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_add_unregistered_cb_n) {
  int watcher_id;
  int ret = message_port_add_unregistered_cb(nullptr, "PORT", false,
      __registration_event_cb, nullptr, &watcher_id);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}

TEST_F(MessagePortTest, message_port_remove_registration_event_cb) {
  int ret = message_port_remove_registration_event_cb(10);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_NONE);
}

TEST_F(MessagePortTest, message_port_remove_registration_event_cb_n) {
  int ret = message_port_remove_registration_event_cb(-1);
  EXPECT_EQ(ret, MESSAGE_PORT_ERROR_INVALID_PARAMETER);
}