~jbicha/hud/build-depend-on-valac-not-gir

« back to all changes in this revision

Viewing changes to tests/test-string-list.c

  • Committer: Tarmac
  • Author(s): Ted Gould, Pete Woods, Antti Kaijanmäki, Ted Gould, Albert Astals, Ryan Lortie, Łukasz 'sil2100' Zemczak, Albert Astals Cid, Mathieu Trudel-Lapierre, Kaleo, Tarmac, Ricardo Salveti de Araujo, Michael Terry, Automatic PS uploader
  • Date: 2013-04-10 16:04:51 UTC
  • mfrom: (227.3.148 phablet)
  • Revision ID: tarmac-20130410160451-o3owpv3zaxulm5of
HUD 2.0 Merge.

Approved by PS Jenkins bot, Mathieu Trudel-Lapierre.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Test code for string list
 
3
 
 
4
 Copyright 2012 Canonical Ltd.
 
5
 
 
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.
 
9
 
 
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.
 
14
 
 
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/>.
 
17
 */
 
18
 
 
19
#include <glib-object.h>
 
20
 
 
21
#include "hudstringlist.h"
 
22
 
 
23
static void
 
24
test_hud_string_list_cons ()
 
25
{
 
26
  HudStringList *list = NULL, *first = NULL, *second = NULL, *tmp = NULL;
 
27
 
 
28
  first = hud_string_list_cons ("first", NULL );
 
29
  list = first;
 
30
  g_assert_cmpstr(hud_string_list_get_head(list), ==, "first");
 
31
  g_assert(hud_string_list_get_tail(list) == NULL);
 
32
 
 
33
  second = hud_string_list_add_item ("second", list);
 
34
  list = second;
 
35
  g_assert_cmpstr(hud_string_list_get_head(list), ==, "second");
 
36
  g_assert(hud_string_list_get_tail(list) == first);
 
37
 
 
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);
 
41
 
 
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);
 
45
 
 
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);
 
49
 
 
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);
 
53
 
 
54
  hud_string_list_unref (list);
 
55
}
 
56
 
 
57
static void
 
58
test_hud_string_list_cons_label ()
 
59
{
 
60
  HudStringList *list = NULL, *first = NULL, *second = NULL, *third = NULL,
 
61
      *tmp = NULL;
 
62
 
 
63
  first = hud_string_list_cons_label ("f_irs_t", NULL );
 
64
  list = first;
 
65
  g_assert_cmpstr(hud_string_list_get_head(list), ==, "first");
 
66
  g_assert(hud_string_list_get_tail(list) == NULL);
 
67
 
 
68
  second = hud_string_list_cons_label ("_sec_ond", list);
 
69
  hud_string_list_unref (list);
 
70
  list = second;
 
71
  g_assert_cmpstr(hud_string_list_get_head(list), ==, "second");
 
72
  g_assert(hud_string_list_get_tail(list) == first);
 
73
 
 
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);
 
77
 
 
78
  third = hud_string_list_cons_label ("third_", list);
 
79
  hud_string_list_unref (list);
 
80
  list = third;
 
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);
 
84
 
 
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);
 
88
 
 
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);
 
92
 
 
93
  hud_string_list_unref (list);
 
94
}
 
95
 
 
96
static void
 
97
test_hud_string_list_pretty_print ()
 
98
{
 
99
  HudStringList *list = NULL;
 
100
 
 
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);
 
105
 
 
106
  g_assert_cmpstr(hud_string_list_pretty_print(list, " > "), ==,
 
107
      "first > second > third > fourth");
 
108
 
 
109
  hud_string_list_unref (list);
 
110
}
 
111
 
 
112
static void
 
113
test_hud_string_list_pretty_print_null ()
 
114
{
 
115
  g_assert_cmpstr(hud_string_list_pretty_print(NULL, " "), ==, "");
 
116
}
 
117
 
 
118
static void
 
119
test_string_list_suite ()
 
120
{
 
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);
 
128
}
 
129
 
 
130
gint
 
131
main (gint argc, gchar * argv[])
 
132
{
 
133
#ifndef GLIB_VERSION_2_36
 
134
  g_type_init ();
 
135
#endif
 
136
  g_test_init (&argc, &argv, NULL );
 
137
  test_string_list_suite ();
 
138
  return g_test_run ();
 
139
}