File: test-notification-frame.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 (175 lines) | stat: -rw-r--r-- 5,961 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright © 2020 Zander Brown <zbrown@gnome.org>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Zander Brown <zbrown@gnome.org>
 */

#include "notifications/notification-frame.c"


static gboolean actioned_called = FALSE;


static void
actioned (PhoshNotification *noti,
          const char        *action)
{
  actioned_called = TRUE;

  g_assert_cmpstr (action, ==, "default");
}



static void
test_phosh_notification_frame_new (void)
{
  g_autoptr (PhoshNotification) noti = NULL;
  GtkWidget *frame = NULL;
  g_autoptr (GDateTime) now = g_date_time_new_now_local ();

  noti = phosh_notification_new (0,
                                 NULL,
                                 NULL,
                                 "Hey",
                                 "Testing",
                                 NULL,
                                 NULL,
                                 PHOSH_NOTIFICATION_URGENCY_NORMAL,
                                 NULL,
                                 FALSE,
                                 FALSE,
                                 NULL,
                                 NULL,
                                 now);

  frame = phosh_notification_frame_new (TRUE, NULL);
  phosh_notification_frame_bind_notification (PHOSH_NOTIFICATION_FRAME (frame),
                                              noti);
}


static void
test_phosh_notification_frame_new_filter (void)
{
  g_autoptr (PhoshNotification) noti = NULL;
  PhoshNotificationFrame *frame = NULL;
  g_autoptr (GDateTime) now = g_date_time_new_now_local ();
  const char *filters[] = { "X-Phosh-Foo", "X-Phosh-Bar", NULL };

  noti = phosh_notification_new (0,
                                 NULL,
                                 NULL,
                                 "Hey",
                                 "Testing",
                                 NULL,
                                 NULL,
                                 PHOSH_NOTIFICATION_URGENCY_NORMAL,
                                 NULL,
                                 FALSE,
                                 FALSE,
                                 NULL,
                                 NULL,
                                 now);

  frame = PHOSH_NOTIFICATION_FRAME (phosh_notification_frame_new (TRUE, filters));
  phosh_notification_frame_bind_notification (PHOSH_NOTIFICATION_FRAME (frame),
                                              noti);
  g_assert_cmpstr (phosh_notification_frame_get_action_filter_keys (frame)[0], ==, "X-Phosh-Foo");
  g_assert_cmpstr (phosh_notification_frame_get_action_filter_keys (frame)[1], ==, "X-Phosh-Bar");
  g_assert_cmpstr (phosh_notification_frame_get_action_filter_keys (frame)[2], ==, NULL);
}


static void
test_phosh_notification_frame_need_separator (void)
{
  g_autoptr (PhoshNotification) noti = NULL;
  GtkWidget *content = NULL;
  g_auto (GStrv) actions = NULL;
  gboolean separator_needed;
  g_autoptr (GDateTime) now = g_date_time_new_now_local ();
  g_autoptr (GStrvBuilder) builder = NULL;

  builder = g_strv_builder_new ();
  g_strv_builder_add (builder, "default");
  g_strv_builder_add (builder, "Default Action");
  g_strv_builder_add (builder, NULL);
  actions = g_strv_builder_end (builder);

  noti = phosh_notification_new (0,
                                 NULL,
                                 NULL,
                                 "Hey",
                                 "Testing",
                                 NULL,
                                 NULL,
                                 PHOSH_NOTIFICATION_URGENCY_NORMAL,
                                 actions,
                                 FALSE,
                                 FALSE,
                                 NULL,
                                 NULL,
                                 now);

  content = phosh_notification_content_new (noti, TRUE, NULL);
  separator_needed = needs_separator (PHOSH_NOTIFICATION_CONTENT (content));
  g_assert_true (separator_needed);
}


static void
test_phosh_notification_frame_notification_activated (void)
{
  g_autoptr (PhoshNotification) noti = NULL;
  GtkWidget *frame = NULL;
  GtkWidget *list = NULL;
  GtkListBoxRow *row = NULL;
  g_autoptr (GDateTime) now = g_date_time_new_now_local ();

  noti = phosh_notification_new (0,
                                 NULL,
                                 NULL,
                                 "Hey",
                                 "Testing",
                                 NULL,
                                 NULL,
                                 PHOSH_NOTIFICATION_URGENCY_NORMAL,
                                 NULL,
                                 FALSE,
                                 FALSE,
                                 NULL,
                                 NULL,
                                 now);

  frame = phosh_notification_frame_new (TRUE, NULL);
  phosh_notification_frame_bind_notification (PHOSH_NOTIFICATION_FRAME (frame),
                                              noti);
  g_signal_connect (noti, "actioned", G_CALLBACK (actioned), NULL);

  actioned_called = FALSE;

  list = PHOSH_NOTIFICATION_FRAME (frame)->list_notifs;
  row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (list), 0);

  notification_activated (PHOSH_NOTIFICATION_FRAME (frame),
                          row,
                          GTK_LIST_BOX (list));
  g_assert_true (actioned_called);
}


int
main (int argc, char **argv)
{
  gtk_test_init (&argc, &argv, NULL);

  g_test_add_func ("/phosh/notification-frame/new", test_phosh_notification_frame_new);
  g_test_add_func ("/phosh/notification-frame/new-filter", test_phosh_notification_frame_new_filter);
  g_test_add_func ("/phosh/notification-frame/needs-separator", test_phosh_notification_frame_need_separator);
  g_test_add_func ("/phosh/notification-frame/notification-activated", test_phosh_notification_frame_notification_activated);

  return g_test_run ();
}