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
41 #undef G_DISABLE_ASSERT
46 /* This is too ugly to be public API, but quite handy. */
47 #define HB_TAG_CHAR4(s) (HB_TAG(((const char *) s)[0], \
48 ((const char *) s)[1], \
49 ((const char *) s)[2], \
50 ((const char *) s)[3]))
53 static inline const char *
59 s = getenv ("srcdir");
77 hb_test_init (int *argc, char ***argv)
79 g_test_init (argc, argv, NULL);
89 /* Bugzilla helpers */
92 hb_test_bug (const char *uri_base, unsigned int number)
94 char *s = g_strdup_printf ("%u", number);
96 g_test_bug_base (uri_base);
103 hb_test_bug_freedesktop (unsigned int number)
105 hb_test_bug ("http://bugs.freedesktop.org/", number);
109 hb_test_bug_gnome (unsigned int number)
111 hb_test_bug ("http://bugzilla.gnome.org/", number);
115 hb_test_bug_mozilla (unsigned int number)
117 hb_test_bug ("http://bugzilla.mozilla.org/", number);
121 hb_test_bug_redhat (unsigned int number)
123 hb_test_bug ("http://bugzilla.redhat.com/", number);
127 /* Wrap glib test functions to simplify. Should have been in glib already. */
129 /* Drops the "test_" prefix and converts '_' to '/'.
130 * Essentially builds test path from function name. */
132 hb_test_normalize_path (const char *path)
136 g_assert (0 == strncmp (path, "test_", 5));
148 #if GLIB_CHECK_VERSION(2,25,12)
149 typedef GTestFunc hb_test_func_t;
150 typedef GTestDataFunc hb_test_data_func_t;
151 typedef GTestFixtureFunc hb_test_fixture_func_t;
153 typedef void (*hb_test_func_t) (void);
154 typedef void (*hb_test_data_func_t) (gconstpointer user_data);
155 typedef void (*hb_test_fixture_func_t) (void);
158 #if !GLIB_CHECK_VERSION(2,30,0)
159 #define g_test_fail() g_error("Test failed")
163 hb_test_add_func (const char *test_path,
164 hb_test_func_t test_func)
166 char *normal_path = hb_test_normalize_path (test_path);
167 g_test_add_func (normal_path, test_func);
168 g_free (normal_path);
170 #define hb_test_add(Func) hb_test_add_func (#Func, Func)
173 hb_test_add_func_flavor (const char *test_path,
175 hb_test_func_t test_func)
177 char *path = g_strdup_printf ("%s/%s", test_path, flavor);
178 hb_test_add_func (path, test_func);
181 #define hb_test_add_flavor(Flavor, Func) hb_test_add_func (#Func, Flavor, Func)
184 hb_test_add_data_func (const char *test_path,
185 gconstpointer test_data,
186 hb_test_data_func_t test_func)
188 char *normal_path = hb_test_normalize_path (test_path);
189 g_test_add_data_func (normal_path, test_data, test_func);
190 g_free (normal_path);
192 #define hb_test_add_data(UserData, Func) hb_test_add_data_func (#Func, UserData, Func)
195 hb_test_add_data_func_flavor (const char *test_path,
197 gconstpointer test_data,
198 hb_test_data_func_t test_func)
200 char *path = g_strdup_printf ("%s/%s", test_path, flavor);
201 hb_test_add_data_func (path, test_data, test_func);
204 #define hb_test_add_data_flavor(UserData, Flavor, Func) hb_test_add_data_func_flavor (#Func, Flavor, UserData, Func)
208 hb_test_add_vtable (const char *test_path,
210 gconstpointer test_data,
211 hb_test_fixture_func_t data_setup,
212 hb_test_fixture_func_t data_test,
213 hb_test_fixture_func_t data_teardown)
215 char *normal_path = hb_test_normalize_path (test_path);
216 g_test_add_vtable (normal_path, data_size, test_data, data_setup, data_test, data_teardown);
217 g_free (normal_path);
219 #define hb_test_add_fixture(FixturePrefix, UserData, Func) \
221 typedef G_PASTE (FixturePrefix, _t) Fixture; \
222 void (*add_vtable) (const char*, gsize, gconstpointer, \
223 void (*) (Fixture*, gconstpointer), \
224 void (*) (Fixture*, gconstpointer), \
225 void (*) (Fixture*, gconstpointer)) \
226 = (void (*) (const gchar *, gsize, gconstpointer, \
227 void (*) (Fixture*, gconstpointer), \
228 void (*) (Fixture*, gconstpointer), \
229 void (*) (Fixture*, gconstpointer))) hb_test_add_vtable; \
230 add_vtable (#Func, sizeof (G_PASTE (FixturePrefix, _t)), UserData, \
231 G_PASTE (FixturePrefix, _init), Func, G_PASTE (FixturePrefix, _finish)); \
235 hb_test_add_vtable_flavor (const char *test_path,
238 gconstpointer test_data,
239 hb_test_fixture_func_t data_setup,
240 hb_test_fixture_func_t data_test,
241 hb_test_fixture_func_t data_teardown)
243 char *path = g_strdup_printf ("%s/%s", test_path, flavor);
244 hb_test_add_vtable (path, data_size, test_data, data_setup, data_test, data_teardown);
247 #define hb_test_add_fixture_flavor(FixturePrefix, UserData, Flavor, Func) \
249 typedef G_PASTE (FixturePrefix, _t) Fixture; \
250 void (*add_vtable) (const char*, const char *, gsize, gconstpointer, \
251 void (*) (Fixture*, gconstpointer), \
252 void (*) (Fixture*, gconstpointer), \
253 void (*) (Fixture*, gconstpointer)) \
254 = (void (*) (const gchar *, const char *, gsize, gconstpointer, \
255 void (*) (Fixture*, gconstpointer), \
256 void (*) (Fixture*, gconstpointer), \
257 void (*) (Fixture*, gconstpointer))) hb_test_add_vtable_flavor; \
258 add_vtable (#Func, Flavor, sizeof (G_PASTE (FixturePrefix, _t)), UserData, \
259 G_PASTE (FixturePrefix, _init), Func, G_PASTE (FixturePrefix, _finish)); \
265 #endif /* HB_TEST_H */