2
Test code for string list
4
Copyright 2012 Canonical Ltd.
6
This program is free software: you can redistribute it and/or modify it
7
under the terms of the GNU General Public License version 3, as published
8
by the Free Software Foundation.
10
This program is distributed in the hope that it will be useful, but
11
WITHOUT ANY WARRANTY; without even the implied warranties of
12
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
PURPOSE. See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License along
16
with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include <glib-object.h>
21
#include "hudstringlist.h"
24
test_hud_string_list_cons ()
26
HudStringList *list = NULL, *first = NULL, *second = NULL, *tmp = NULL;
28
first = hud_string_list_cons ("first", NULL );
30
g_assert_cmpstr(hud_string_list_get_head(list), ==, "first");
31
g_assert(hud_string_list_get_tail(list) == NULL);
33
second = hud_string_list_add_item ("second", list);
35
g_assert_cmpstr(hud_string_list_get_head(list), ==, "second");
36
g_assert(hud_string_list_get_tail(list) == first);
38
tmp = hud_string_list_get_tail (list);
39
g_assert_cmpstr(hud_string_list_get_head(tmp), ==, "first");
40
g_assert(hud_string_list_get_tail(tmp) == NULL);
42
list = hud_string_list_add_item ("third", list);
43
g_assert_cmpstr(hud_string_list_get_head(list), ==, "third");
44
g_assert(hud_string_list_get_tail(list) == second);
46
tmp = hud_string_list_get_tail (list);
47
g_assert_cmpstr(hud_string_list_get_head(tmp), ==, "second");
48
g_assert(hud_string_list_get_tail(tmp) == first);
50
tmp = hud_string_list_get_tail (tmp);
51
g_assert_cmpstr(hud_string_list_get_head(tmp), ==, "first");
52
g_assert(hud_string_list_get_tail(tmp) == NULL);
54
hud_string_list_unref (list);
58
test_hud_string_list_cons_label ()
60
HudStringList *list = NULL, *first = NULL, *second = NULL, *third = NULL,
63
first = hud_string_list_cons_label ("f_irs_t", NULL );
65
g_assert_cmpstr(hud_string_list_get_head(list), ==, "first");
66
g_assert(hud_string_list_get_tail(list) == NULL);
68
second = hud_string_list_cons_label ("_sec_ond", list);
69
hud_string_list_unref (list);
71
g_assert_cmpstr(hud_string_list_get_head(list), ==, "second");
72
g_assert(hud_string_list_get_tail(list) == first);
74
tmp = hud_string_list_get_tail (list);
75
g_assert_cmpstr(hud_string_list_get_head(tmp), ==, "first");
76
g_assert(hud_string_list_get_tail(tmp) == NULL);
78
third = hud_string_list_cons_label ("third_", list);
79
hud_string_list_unref (list);
81
/* Note that it's not supposed to strip the underscore from the end */
82
g_assert_cmpstr(hud_string_list_get_head(list), ==, "third_");
83
g_assert(hud_string_list_get_tail(list) == second);
85
tmp = hud_string_list_get_tail (list);
86
g_assert_cmpstr(hud_string_list_get_head(tmp), ==, "second");
87
g_assert(hud_string_list_get_tail(tmp) == first);
89
tmp = hud_string_list_get_tail (tmp);
90
g_assert_cmpstr(hud_string_list_get_head(tmp), ==, "first");
91
g_assert(hud_string_list_get_tail(tmp) == NULL);
93
hud_string_list_unref (list);
97
test_hud_string_list_pretty_print ()
99
HudStringList *list = NULL;
101
list = hud_string_list_cons ("first", NULL );
102
list = hud_string_list_add_item ("second", list);
103
list = hud_string_list_add_item ("third", list);
104
list = hud_string_list_add_item ("fourth", list);
106
g_assert_cmpstr(hud_string_list_pretty_print(list, " > "), ==,
107
"first > second > third > fourth");
109
hud_string_list_unref (list);
113
test_hud_string_list_pretty_print_null ()
115
g_assert_cmpstr(hud_string_list_pretty_print(NULL, " "), ==, "");
119
test_string_list_suite ()
121
g_test_add_func ("/hud/string_list/cons", test_hud_string_list_cons);
122
g_test_add_func ("/hud/string_list/cons_label",
123
test_hud_string_list_cons_label);
124
g_test_add_func ("/hud/string_list/pretty_print",
125
test_hud_string_list_pretty_print);
126
g_test_add_func ("/hud/string_list/pretty_print_null",
127
test_hud_string_list_pretty_print_null);
131
main (gint argc, gchar * argv[])
133
#ifndef GLIB_VERSION_2_36
136
g_test_init (&argc, &argv, NULL );
137
test_string_list_suite ();
138
return g_test_run ();