File: test-notify-manager.c

package info (click to toggle)
phosh 0.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 9,868 kB
  • sloc: ansic: 83,377; xml: 3,981; python: 717; sh: 449; makefile: 34; lisp: 22; javascript: 6
file content (172 lines) | stat: -rw-r--r-- 6,765 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (C) 2021 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "phosh-config.h"

#include "notify-dbus.h"
#include "shell-priv.h"
#include "notifications/notify-manager.h"

#include "testlib-full-shell.h"

#define BUS_NAME "org.freedesktop.Notifications"
#define OBJECT_PATH "/org/freedesktop/Notifications"

#define POP_TIMEOUT 50000000


static void
test_phosh_notify_manager_caps (PhoshTestFullShellFixture *fixture, gconstpointer unused)
{
  g_autoptr (GError) err = NULL;
  g_autoptr (PhoshDBusNotifications) proxy = NULL;
  g_auto (GStrv) caps = NULL;
  gboolean success;

  /* Wait until comp/shell are up */
  g_assert_nonnull (g_async_queue_timeout_pop (fixture->queue, POP_TIMEOUT));

  proxy = phosh_dbus_notifications_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                           G_DBUS_PROXY_FLAGS_NONE,
                                                           BUS_NAME,
                                                           OBJECT_PATH,
                                                           NULL,
                                                           &err);
  g_assert_no_error (err);
  g_assert_true (PHOSH_DBUS_IS_NOTIFICATIONS_PROXY (proxy));

  success = phosh_dbus_notifications_call_get_capabilities_sync (proxy,
                                                                 &caps,
                                                                 NULL,
                                                                 &err);
  g_assert_no_error (err);
  g_assert_true (success);

  g_assert_cmpint (g_strv_length (caps), ==, 5);
  g_assert_true (g_strv_contains ((const char * const *)caps, "body"));
  g_assert_true (g_strv_contains ((const char * const *)caps, "body-markup"));
  g_assert_true (g_strv_contains ((const char * const *)caps, "actions"));
  g_assert_true (g_strv_contains ((const char * const *)caps, "icon-static"));
  g_assert_true (g_strv_contains ((const char * const *)caps, "sound"));
}


static void
test_phosh_notify_manager_server_info (PhoshTestFullShellFixture *fixture, gconstpointer unused)
{
  g_autoptr (GError) err = NULL;
  g_autoptr (PhoshDBusNotifications) proxy = NULL;
  g_autofree char *name = NULL;
  g_autofree char *vendor = NULL;
  g_autofree char *version = NULL;
  g_autofree char *spec_ver = NULL;
  gboolean success;

  /* Wait until comp/shell are up */
  g_assert_nonnull (g_async_queue_timeout_pop (fixture->queue, POP_TIMEOUT));

  proxy = phosh_dbus_notifications_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                           G_DBUS_PROXY_FLAGS_NONE,
                                                           BUS_NAME,
                                                           OBJECT_PATH,
                                                           NULL,
                                                           &err);
  g_assert_no_error (err);
  g_assert_true (PHOSH_DBUS_IS_NOTIFICATIONS_PROXY (proxy));

  success = phosh_dbus_notifications_call_get_server_information_sync (proxy,
                                                                       &name,
                                                                       &vendor,
                                                                       &version,
                                                                       &spec_ver,
                                                                       NULL,
                                                                       &err);
  g_assert_no_error (err);
  g_assert_true (success);

  g_assert_cmpstr ("Phosh Notify Daemon", ==, name);
  g_assert_cmpstr ("Phosh", ==, vendor);
  g_assert_cmpstr (PHOSH_VERSION, ==, version);
  g_assert_cmpstr ("1.2", ==, spec_ver);
}


static void
on_new_notification (gboolean *data)
{
  *data = TRUE;
}


static void
test_phosh_notify_manager_server_notify (PhoshTestFullShellFixture *fixture, gconstpointer unused)
{
  g_autoptr (GError) err = NULL;
  g_autoptr (PhoshDBusNotifications) proxy = NULL;
  PhoshNotifyManager *nm = NULL;
  gboolean success, notified = FALSE;
  guint id;
  const char *const * actions = (const char*[]){ NULL };
  GVariant *hints = g_variant_new ("a{sv}",  NULL);

  /* Wait until comp/shell are up */
  g_assert_nonnull (g_async_queue_timeout_pop (fixture->queue, POP_TIMEOUT));

  proxy = phosh_dbus_notifications_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                           G_DBUS_PROXY_FLAGS_NONE,
                                                           BUS_NAME,
                                                           OBJECT_PATH,
                                                           NULL,
                                                           &err);
  g_assert_no_error (err);
  g_assert_true (PHOSH_DBUS_IS_NOTIFICATIONS_PROXY (proxy));

  /* phosh runs in another thread without locking, so careful */
  nm = phosh_notify_manager_get_default ();
  g_signal_connect_swapped (nm, "new-notification", G_CALLBACK (on_new_notification), &notified);

  success = phosh_dbus_notifications_call_notify_sync (proxy,
                                                       "com.example.notify",
                                                       -1,
                                                       "",
                                                       "",
                                                       "",
                                                       actions,
                                                       hints,
                                                       3,
                                                       &id,
                                                       NULL,
                                                       &err);
  g_assert_no_error (err);
  g_assert_true (success);
  g_assert_cmpint (id, ==, 1);
  g_assert_true (notified);
}


int
main (int argc, char *argv[])
{
  g_autoptr (PhoshTestFullShellFixtureCfg) cfg = NULL;

  g_test_init (&argc, &argv, NULL);

  cfg = phosh_test_full_shell_fixture_cfg_new ("phosh-notify-manager");

  PHOSH_FULL_SHELL_TEST_ADD ("/phosh/dbus/notify-manager/caps",
                             cfg,
                             test_phosh_notify_manager_caps);
  PHOSH_FULL_SHELL_TEST_ADD ("/phosh/dbus/notify-manager/server_info",
                             cfg,
                             test_phosh_notify_manager_server_info);
  PHOSH_FULL_SHELL_TEST_ADD ("/phosh/dbus/notify-manager/notify",
                             cfg,
                             test_phosh_notify_manager_server_notify);

  return g_test_run ();
}