File: test-notification-source.c

package info (click to toggle)
phosh 0.52.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,732 kB
  • sloc: ansic: 82,495; xml: 3,912; python: 717; sh: 456; makefile: 34; lisp: 22; javascript: 6
file content (144 lines) | stat: -rw-r--r-- 4,850 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
/*
 * Copyright © 2020 Zander Brown <zbrown@gnome.org>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Zander Brown <zbrown@gnome.org>
 */

#include "notifications/notification-source.c"
#include "stubs/bad-prop.h"


static void
test_phosh_notification_source_new (void)
{
  g_autoptr (PhoshNotificationSource) source = NULL;
  g_autoptr (PhoshNotification) noti = NULL;
  const char *name;
  g_autoptr (GDateTime) now = g_date_time_new_now_local ();

  source = phosh_notification_source_new ("org.gnome.zbrown.KingsCross");

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

  phosh_notification_source_add (source, noti);

  name = phosh_notification_source_get_name (PHOSH_NOTIFICATION_SOURCE (source));

  g_assert_cmpint (g_list_model_get_n_items (G_LIST_MODEL (source)), ==, 1);
  g_assert_true (noti == g_list_model_get_item (G_LIST_MODEL (source), 0));
  g_assert_cmpstr (name, ==, "org.gnome.zbrown.KingsCross");
}


static void
test_phosh_notification_source_get (void)
{
  g_autoptr (PhoshNotificationSource) source = NULL;
  g_autofree char *name;

  source = phosh_notification_source_new ("org.gnome.zbrown.KingsCross");

  g_object_get (source, "name", &name, NULL);

  g_assert_cmpstr (name, ==, "org.gnome.zbrown.KingsCross");
}


static void
test_phosh_notification_source_close_invalid (void)
{
  if (g_test_subprocess ()) {
    g_autoptr (PhoshNotificationSource) source = NULL;
    g_autoptr (PhoshNotification) noti = NULL;

    g_autoptr (GDateTime) now = g_date_time_new_now_local ();

    source = phosh_notification_source_new ("org.gnome.zbrown.KingsCross");

    noti = phosh_notification_new (0,
                                   NULL,
                                   NULL,
                                   "Hey",
                                   "Testing",
                                   NULL,
                                   NULL,
                                   PHOSH_NOTIFICATION_URGENCY_NORMAL,
                                   NULL,
                                   FALSE,
                                   FALSE,
                                   NULL,
                                   NULL,
                                   now);
    phosh_notification_source_add (source, noti);
    noti = phosh_notification_new (1,
                                   NULL,
                                   NULL,
                                   "Hey",
                                   "Testing",
                                   NULL,
                                   NULL,
                                   PHOSH_NOTIFICATION_URGENCY_NORMAL,
                                   NULL,
                                   FALSE,
                                   FALSE,
                                   NULL,
                                   NULL,
                                   now);
    /* Boom */
    closed (source, PHOSH_NOTIFICATION_REASON_DISMISSED, noti);
  }
  g_test_trap_subprocess (NULL, 0, 0);
  g_test_trap_assert_failed ();
  g_test_trap_assert_stderr ("*: phosh-notification-source-CRITICAL *"
                             "Can't remove unknown notification *\n");
}


static void
test_phosh_notification_source_set_prop_invalid (void)
{
  g_autoptr (PhoshNotificationSource) source =
    phosh_notification_source_new ("org.gnome.zbrown.KingsCross");

  BAD_PROP_SET (source, phosh_notification_source, PhoshNotificationSource);
}


static void
test_phosh_notification_source_get_prop_invalid (void)
{
  g_autoptr(PhoshNotificationSource) source =
    phosh_notification_source_new ("org.gnome.zbrown.KingsCross");

  BAD_PROP_GET (source, phosh_notification_source, PhoshNotificationSource);
}


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

  g_test_add_func ("/phosh/notification-source/new", test_phosh_notification_source_new);
  g_test_add_func ("/phosh/notification-source/get", test_phosh_notification_source_get);
  g_test_add_func ("/phosh/notification-source/close-invalid", test_phosh_notification_source_close_invalid);
  g_test_add_func ("/phosh/notification-source/set_prop_invalid", test_phosh_notification_source_set_prop_invalid);
  g_test_add_func ("/phosh/notification-source/get_prop_invalid", test_phosh_notification_source_get_prop_invalid);

  return g_test_run ();
}