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
|
/*
* Purple - Internet Messaging Library
* Copyright (C) Pidgin Developers <devel@pidgin.im>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
#include <glib.h>
#include <purple.h>
/******************************************************************************
* Tests
*****************************************************************************/
static void
test_purple_saved_presence_new(void) {
PurpleSavedPresence *presence = NULL;
presence = purple_saved_presence_new();
g_assert_true(PURPLE_IS_SAVED_PRESENCE(presence));
g_clear_object(&presence);
}
static void
test_purple_saved_presence_properties(void) {
PurpleSavedPresence *presence = NULL;
PurplePresencePrimitive primitive;
GDateTime *last_used = NULL;
GDateTime *last_used1 = NULL;
guint use_count;
char *name;
char *message;
char *emoji;
last_used = g_date_time_new_now_local();
/* Use g_object_new so we can test setting properties by name. All of them
* call the setter methods, so by doing it this way we exercise more of the
* code.
*/
presence = g_object_new(
PURPLE_TYPE_SAVED_PRESENCE,
"last-used", last_used,
"use-count", 123,
"name", "my saved status",
"primitive", PURPLE_PRESENCE_PRIMITIVE_STREAMING,
"message", "I'm live on twitch at https://twitch.tv/rw_grim/",
"emoji", "💀",
NULL);
/* Now use g_object_get to read all of the properties. */
g_object_get(
presence,
"last-used", &last_used1,
"use-count", &use_count,
"name", &name,
"primitive", &primitive,
"message", &message,
"emoji", &emoji,
NULL);
/* Compare all the things. */
g_assert_nonnull(last_used1);
g_assert_true(g_date_time_equal(last_used, last_used1));
g_clear_pointer(&last_used1, g_date_time_unref);
g_assert_cmpuint(use_count, ==, 123);
g_assert_cmpstr(name, ==, "my saved status");
g_clear_pointer(&name, g_free);
g_assert_cmpint(primitive, ==, PURPLE_PRESENCE_PRIMITIVE_STREAMING);
g_assert_cmpstr(message, ==,
"I'm live on twitch at https://twitch.tv/rw_grim/");
g_clear_pointer(&message, g_free);
g_assert_cmpstr(emoji, ==, "💀");
g_clear_pointer(&emoji, g_free);
g_clear_pointer(&last_used, g_date_time_unref);
g_clear_object(&presence);
}
/******************************************************************************
* Main
*****************************************************************************/
gint
main(gint argc, gchar *argv[]) {
g_test_init(&argc, &argv, NULL);
g_test_add_func("/saved-presence/new",
test_purple_saved_presence_new);
g_test_add_func("/saved-presence/properties",
test_purple_saved_presence_properties);
return g_test_run();
}
|