1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) 2008-2010 Kouhei Sutou <kou@clear-code.com>
4 *
5 * This library is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 #include <gcutter.h>
21
22 #include <cutter/cut-enum-types.h>
23 #include <cuttest-enum.h>
24
25 void test_direct (void);
26 void test_int (void);
27 void test_uint (void);
28 void test_int64 (void);
29 void test_uint64 (void);
30 void test_size (void);
31 void data_char (void);
32 void test_char (gconstpointer data);
33 void test_string (void);
34 void test_type (void);
35 void test_flags (void);
36 void test_enum (void);
37 void test_pointer (void);
38 void data_boolean (void);
39 void test_boolean (gconstpointer data);
40 void test_double (void);
41
42 static GString *string;
43
44 void
cut_setup(void)45 cut_setup (void)
46 {
47 string = g_string_new(NULL);
48 }
49
50 void
cut_teardown(void)51 cut_teardown (void)
52 {
53 if (string)
54 g_string_free(string, TRUE);
55 }
56
57 void
test_direct(void)58 test_direct (void)
59 {
60 gcut_inspect_direct(string, GUINT_TO_POINTER(100), NULL);
61 cut_assert_equal_string("100", string->str);
62 }
63
64 void
test_int(void)65 test_int (void)
66 {
67 gint value = G_MININT;
68
69 gcut_inspect_int(string, &value, NULL);
70 cut_assert_equal_string("-2147483648", string->str);
71 }
72
73 void
test_uint(void)74 test_uint (void)
75 {
76 guint value = G_MAXUINT;
77
78 gcut_inspect_uint(string, &value, NULL);
79 cut_assert_equal_string("4294967295", string->str);
80 }
81
82 void
test_int64(void)83 test_int64 (void)
84 {
85 gint64 value = G_MININT64;
86
87 gcut_inspect_int64(string, &value, NULL);
88 cut_assert_equal_string("-9223372036854775808", string->str);
89 }
90
91 void
test_uint64(void)92 test_uint64 (void)
93 {
94 guint64 value = G_MAXUINT64;
95
96 gcut_inspect_uint64(string, &value, NULL);
97 cut_assert_equal_string("18446744073709551615", string->str);
98 }
99
100 void
test_size(void)101 test_size (void)
102 {
103 gsize value = 29;
104
105 gcut_inspect_size(string, &value, NULL);
106 cut_assert_equal_string("29", string->str);
107 }
108
109 void
data_char(void)110 data_char (void)
111 {
112 #define ADD_DATUM(label, expected, character) \
113 gcut_add_datum(label, \
114 "expected", G_TYPE_STRING, expected, \
115 "value", G_TYPE_CHAR, character, \
116 NULL)
117
118 ADD_DATUM("normal", "'X'", 'X');
119 ADD_DATUM("NULL", "'\\0'", '\0');
120 ADD_DATUM("escaped", "'\\n'", '\n');
121 ADD_DATUM("backslash", "'\\\\'", '\\');
122 ADD_DATUM("quote", "'\\''", '\'');
123
124 #undef ADD_DATUM
125 }
126
127 void
test_char(gconstpointer data)128 test_char (gconstpointer data)
129 {
130 gchar value;
131 const gchar *expected;
132
133
134 expected = gcut_data_get_string(data, "expected");
135 value = gcut_data_get_char(data, "value");
136 gcut_inspect_char(string, &value, NULL);
137 cut_assert_equal_string(expected, string->str);
138 }
139
140 void
test_string(void)141 test_string (void)
142 {
143 gcut_inspect_string(string, "XXX", NULL);
144 cut_assert_equal_string("\"XXX\"", string->str);
145 }
146
147 void
test_type(void)148 test_type (void)
149 {
150 GType type;
151
152 type = GCUT_TYPE_DYNAMIC_DATA;
153 gcut_inspect_type(string, &type, NULL);
154 cut_assert_equal_string("<GCutDynamicData>", string->str);
155 }
156
157 void
test_flags(void)158 test_flags (void)
159 {
160 CuttestFlags flags;
161 GType flags_type;
162
163 flags = CUTTEST_FLAG_FIRST | CUTTEST_FLAG_SECOND;
164 flags_type = CUTTEST_TYPE_FLAGS;
165 gcut_inspect_flags(string, &flags, &flags_type);
166 cut_assert_equal_string("#<CuttestFlags: first|second "
167 "(CUTTEST_FLAG_FIRST:0x1)|"
168 "(CUTTEST_FLAG_SECOND:0x2)>",
169 string->str);
170 }
171
172 void
test_enum(void)173 test_enum (void)
174 {
175 CutTestResultStatus value;
176 GType enum_type;
177
178 value = CUT_TEST_RESULT_SUCCESS;
179 enum_type = CUT_TYPE_TEST_RESULT_STATUS;
180 gcut_inspect_enum(string, &value, &enum_type);
181 cut_assert_equal_string(cut_take_printf("#<CutTestResultStatus: "
182 "success"
183 "(CUT_TEST_RESULT_SUCCESS:%d)>",
184 CUT_TEST_RESULT_SUCCESS),
185 string->str);
186 }
187
188 void
test_pointer(void)189 test_pointer (void)
190 {
191 gpointer value;
192
193 value = string;
194 gcut_inspect_pointer(string, value, NULL);
195 cut_assert_equal_string(cut_take_printf("#<%p>", value),
196 string->str);
197 }
198
199
200 void
data_boolean(void)201 data_boolean (void)
202 {
203 #define ADD_DATUM(label, expected, boolean) \
204 gcut_add_datum(label, \
205 "expected", G_TYPE_STRING, expected, \
206 "value", G_TYPE_BOOLEAN, boolean, \
207 NULL)
208
209 ADD_DATUM("true", "TRUE", TRUE);
210 ADD_DATUM("false", "FALSE", FALSE);
211 ADD_DATUM("not false", "TRUE", 100);
212
213 #undef ADD_DATUM
214 }
215
216 void
test_boolean(gconstpointer data)217 test_boolean (gconstpointer data)
218 {
219 gboolean value;
220 const gchar *expected;
221
222 expected = gcut_data_get_string(data, "expected");
223 value = gcut_data_get_boolean(data, "value");
224
225 gcut_inspect_boolean(string, &value, NULL);
226 cut_assert_equal_string(expected, string->str);
227 }
228
229 void
test_double(void)230 test_double (void)
231 {
232 gdouble value = 2.9;
233
234 gcut_inspect_double(string, &value, NULL);
235 cut_assert_equal_string("2.9", string->str);
236 }
237
238 /*
239 vi:nowrap:ai:expandtab:sw=4:ts=4
240 */
241