2 * Copyright © 2011 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
43 #undef G_DISABLE_ASSERT
48 /* This is too ugly to be public API, but quite handy. */
49 #define HB_TAG_CHAR4(s) (HB_TAG(((const char *) s)[0], \
50 ((const char *) s)[1], \
51 ((const char *) s)[2], \
52 ((const char *) s)[3]))
55 static inline const char *
61 s = getenv ("srcdir");
79 hb_test_init (int *argc, char ***argv)
81 g_test_init (argc, argv, NULL);
90 /* Bugzilla helpers */
93 hb_test_bug (const char *uri_base, unsigned int number)
95 char *s = g_strdup_printf ("%u", number);
97 g_test_bug_base (uri_base);
104 hb_test_bug_freedesktop (unsigned int number)
106 hb_test_bug ("http://bugs.freedesktop.org/", number);
110 hb_test_bug_gnome (unsigned int number)
112 hb_test_bug ("http://bugzilla.gnome.org/", number);
116 hb_test_bug_mozilla (unsigned int number)
118 hb_test_bug ("http://bugzilla.mozilla.org/", number);
122 hb_test_bug_redhat (unsigned int number)
124 hb_test_bug ("http://bugzilla.redhat.com/", number);
128 /* Wrap glib test functions to simplify. Should have been in glib already. */
130 /* Drops the "test_" prefix and converts '_' to '/'.
131 * Essentially builds test path from function name. */
133 hb_test_normalize_path (const char *path)
137 g_assert (0 == strncmp (path, "test_", 5));
149 #if GLIB_CHECK_VERSION(2,25,12)
150 typedef GTestFunc hb_test_func_t;
151 typedef GTestDataFunc hb_test_data_func_t;
152 typedef GTestFixtureFunc hb_test_fixture_func_t;
154 typedef void (*hb_test_func_t) (void);
155 typedef void (*hb_test_data_func_t) (gconstpointer user_data);
156 typedef void (*hb_test_fixture_func_t) (void);
159 #if !GLIB_CHECK_VERSION(2,30,0)
160 #define g_test_fail() g_error("Test failed")
162 #ifndef g_assert_true
163 #define g_assert_true g_assert
165 #ifndef g_assert_cmpmem
166 #define g_assert_cmpmem(m1, l1, m2, l2) g_assert_true (l1 == l2 && memcmp (m1, m2, l1) == 0)
169 static inline void hb_test_assert_blobs_equal (hb_blob_t *expected_blob, hb_blob_t *actual_blob)
171 unsigned int expected_length, actual_length;
172 const char *raw_expected = hb_blob_get_data (expected_blob, &expected_length);
173 const char *raw_actual = hb_blob_get_data (actual_blob, &actual_length);
174 g_assert_cmpint(expected_length, ==, actual_length);
175 g_assert_cmpint(0, ==, memcmp(raw_expected, raw_actual, expected_length));
179 hb_test_add_func (const char *test_path,
180 hb_test_func_t test_func)
182 char *normal_path = hb_test_normalize_path (test_path);
183 g_test_add_func (normal_path, test_func);
184 g_free (normal_path);
186 #define hb_test_add(Func) hb_test_add_func (#Func, Func)
189 hb_test_add_func_flavor (const char *test_path,
191 hb_test_func_t test_func)
193 char *path = g_strdup_printf ("%s/%s", test_path, flavor);
194 hb_test_add_func (path, test_func);
197 #define hb_test_add_flavor(Flavor, Func) hb_test_add_func (#Func, Flavor, Func)
200 hb_test_add_data_func (const char *test_path,
201 gconstpointer test_data,
202 hb_test_data_func_t test_func)
204 char *normal_path = hb_test_normalize_path (test_path);
205 g_test_add_data_func (normal_path, test_data, test_func);
206 g_free (normal_path);
208 #define hb_test_add_data(UserData, Func) hb_test_add_data_func (#Func, UserData, Func)
211 hb_test_add_data_func_flavor (const char *test_path,
213 gconstpointer test_data,
214 hb_test_data_func_t test_func)
216 char *path = g_strdup_printf ("%s/%s", test_path, flavor);
217 hb_test_add_data_func (path, test_data, test_func);
220 #define hb_test_add_data_flavor(UserData, Flavor, Func) hb_test_add_data_func_flavor (#Func, Flavor, UserData, Func)
224 hb_test_add_vtable (const char *test_path,
226 gconstpointer test_data,
227 hb_test_fixture_func_t data_setup,
228 hb_test_fixture_func_t data_test,
229 hb_test_fixture_func_t data_teardown)
231 char *normal_path = hb_test_normalize_path (test_path);
232 g_test_add_vtable (normal_path, data_size, test_data, data_setup, data_test, data_teardown);
233 g_free (normal_path);
235 #define hb_test_add_fixture(FixturePrefix, UserData, Func) \
237 typedef G_PASTE (FixturePrefix, _t) Fixture; \
238 void (*add_vtable) (const char*, gsize, gconstpointer, \
239 void (*) (Fixture*, gconstpointer), \
240 void (*) (Fixture*, gconstpointer), \
241 void (*) (Fixture*, gconstpointer)) \
242 = (void (*) (const gchar *, gsize, gconstpointer, \
243 void (*) (Fixture*, gconstpointer), \
244 void (*) (Fixture*, gconstpointer), \
245 void (*) (Fixture*, gconstpointer))) hb_test_add_vtable; \
246 add_vtable (#Func, sizeof (G_PASTE (FixturePrefix, _t)), UserData, \
247 G_PASTE (FixturePrefix, _init), Func, G_PASTE (FixturePrefix, _finish)); \
251 hb_test_add_vtable_flavor (const char *test_path,
254 gconstpointer test_data,
255 hb_test_fixture_func_t data_setup,
256 hb_test_fixture_func_t data_test,
257 hb_test_fixture_func_t data_teardown)
259 char *path = g_strdup_printf ("%s/%s", test_path, flavor);
260 hb_test_add_vtable (path, data_size, test_data, data_setup, data_test, data_teardown);
263 #define hb_test_add_fixture_flavor(FixturePrefix, UserData, Flavor, Func) \
265 typedef G_PASTE (FixturePrefix, _t) Fixture; \
266 void (*add_vtable) (const char*, const char *, gsize, gconstpointer, \
267 void (*) (Fixture*, gconstpointer), \
268 void (*) (Fixture*, gconstpointer), \
269 void (*) (Fixture*, gconstpointer)) \
270 = (void (*) (const gchar *, const char *, gsize, gconstpointer, \
271 void (*) (Fixture*, gconstpointer), \
272 void (*) (Fixture*, gconstpointer), \
273 void (*) (Fixture*, gconstpointer))) hb_test_add_vtable_flavor; \
274 add_vtable (#Func, Flavor, sizeof (G_PASTE (FixturePrefix, _t)), UserData, \
275 G_PASTE (FixturePrefix, _init), Func, G_PASTE (FixturePrefix, _finish)); \
281 #endif /* HB_TEST_H */