[test] Rename test-symbols to check-symbols
[apps/home/video-player.git] / test / hb-test.h
1 /*
2  * Copyright © 2011  Google, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
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.
11  *
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
16  * DAMAGE.
17  *
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.
23  *
24  * Google Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_TEST_H
28 #define HB_TEST_H
29
30 #include <config.h>
31
32 #include <hb-glib.h>
33
34 #include <stdlib.h>
35 #include <string.h>
36
37 HB_BEGIN_DECLS
38
39 /* Just in case */
40 #undef G_DISABLE_ASSERT
41
42
43 /* Misc */
44
45 /* This is too ugly to be public API, but quite handy. */
46 #define HB_TAG_CHAR4(s)   (HB_TAG(((const char *) s)[0], \
47                                   ((const char *) s)[1], \
48                                   ((const char *) s)[2], \
49                                   ((const char *) s)[3]))
50
51
52 /* Helpers */
53
54 static inline void
55 hb_test_init (int *argc, char ***argv)
56 {
57   g_thread_init (NULL);
58   g_test_init (argc, argv, NULL);
59 }
60
61 static inline int
62 hb_test_run (void)
63 {
64   return g_test_run ();
65 }
66
67
68 /* Bugzilla helpers */
69
70 static inline void
71 hb_test_bug (const char *uri_base, unsigned int number)
72 {
73   char *s = g_strdup_printf ("%u", number);
74
75   g_test_bug_base (uri_base);
76   g_test_bug (s);
77
78   g_free (s);
79 }
80
81 static inline void
82 hb_test_bug_freedesktop (unsigned int number)
83 {
84   hb_test_bug ("http://bugs.freedesktop.org/", number);
85 }
86
87 static inline void
88 hb_test_bug_gnome (unsigned int number)
89 {
90   hb_test_bug ("http://bugzilla.gnome.org/", number);
91 }
92
93 static inline void
94 hb_test_bug_mozilla (unsigned int number)
95 {
96   hb_test_bug ("http://bugzilla.mozilla.org/", number);
97 }
98
99 static inline void
100 hb_test_bug_redhat (unsigned int number)
101 {
102   hb_test_bug ("http://bugzilla.redhat.com/", number);
103 }
104
105
106 /* Wrap glib test functions to simplify.  Should have been in glib already. */
107
108 /* Drops the "test_" prefix and converts '_' to '/'.
109  * Essentially builds test path from function name. */
110 static inline char *
111 hb_test_normalize_path (const char *path)
112 {
113   char *s, *p;
114
115   g_assert (0 == strncmp (path, "test_", 5));
116   path += 4;
117
118   s = g_strdup (path);
119   for (p = s; *p; p++)
120     if (*p == '_')
121       *p = '/';
122
123   return s;
124 }
125
126
127 #if GLIB_CHECK_VERSION(2,25,12)
128 typedef GTestFunc        hb_test_func_t;
129 typedef GTestDataFunc    hb_test_data_func_t;
130 typedef GTestFixtureFunc hb_test_fixture_func_t;
131 #else
132 typedef void (*hb_test_func_t)         (void);
133 typedef void (*hb_test_data_func_t)    (gconstpointer user_data);
134 typedef void (*hb_test_fixture_func_t) (gpointer      fixture,
135                                         gconstpointer user_data);
136 #endif
137
138 static inline void
139 hb_test_add_func (const char *test_path,
140                   hb_test_func_t   test_func)
141 {
142   char *normal_path = hb_test_normalize_path (test_path);
143   g_test_add_func (normal_path, test_func);
144   g_free (normal_path);
145 }
146 #define hb_test_add(Func) hb_test_add_func (#Func, Func)
147
148 static inline void
149 hb_test_add_func_flavor (const char *test_path,
150                          const char *flavor,
151                          hb_test_func_t   test_func)
152 {
153   char *path = g_strdup_printf ("%s/%s", test_path, flavor);
154   hb_test_add_func (path, test_func);
155   g_free (path);
156 }
157 #define hb_test_add_flavor(Flavor, Func) hb_test_add_func (#Func, Flavor, Func)
158
159 static inline void
160 hb_test_add_data_func (const char          *test_path,
161                        gconstpointer        test_data,
162                        hb_test_data_func_t  test_func)
163 {
164   char *normal_path = hb_test_normalize_path (test_path);
165   g_test_add_data_func (normal_path, test_data, test_func);
166   g_free (normal_path);
167 }
168 #define hb_test_add_data(UserData, Func) hb_test_add_data_func (#Func, UserData, Func)
169
170 static inline void
171 hb_test_add_data_func_flavor (const char          *test_path,
172                               const char          *flavor,
173                               gconstpointer        test_data,
174                               hb_test_data_func_t  test_func)
175 {
176   char *path = g_strdup_printf ("%s/%s", test_path, flavor);
177   hb_test_add_data_func (path, test_data, test_func);
178   g_free (path);
179 }
180 #define hb_test_add_data_flavor(UserData, Flavor, Func) hb_test_add_data_func_flavor (#Func, Flavor, UserData, Func)
181
182
183 static inline void
184 hb_test_add_vtable (const char             *test_path,
185                     gsize                   data_size,
186                     gconstpointer           test_data,
187                     hb_test_fixture_func_t  data_setup,
188                     hb_test_fixture_func_t  data_test,
189                     hb_test_fixture_func_t  data_teardown)
190 {
191   char *normal_path = hb_test_normalize_path (test_path);
192   g_test_add_vtable (normal_path, data_size, test_data, data_setup, data_test, data_teardown);
193   g_free (normal_path);
194 }
195 #define hb_test_add_fixture(FixturePrefix, UserData, Func) \
196 G_STMT_START { \
197   typedef G_PASTE (FixturePrefix, _t) Fixture; \
198   void (*add_vtable) (const char*, gsize, gconstpointer, \
199                       void (*) (Fixture*, gconstpointer), \
200                       void (*) (Fixture*, gconstpointer), \
201                       void (*) (Fixture*, gconstpointer)) \
202         = (void (*) (const gchar *, gsize, gconstpointer, \
203                      void (*) (Fixture*, gconstpointer), \
204                      void (*) (Fixture*, gconstpointer), \
205                      void (*) (Fixture*, gconstpointer))) hb_test_add_vtable; \
206   add_vtable (#Func, sizeof (G_PASTE (FixturePrefix, _t)), UserData, \
207               G_PASTE (FixturePrefix, _init), Func, G_PASTE (FixturePrefix, _finish)); \
208 } G_STMT_END
209
210 static inline void
211 hb_test_add_vtable_flavor (const char             *test_path,
212                            const char             *flavor,
213                            gsize                   data_size,
214                            gconstpointer           test_data,
215                            hb_test_fixture_func_t  data_setup,
216                            hb_test_fixture_func_t  data_test,
217                            hb_test_fixture_func_t  data_teardown)
218 {
219   char *path = g_strdup_printf ("%s/%s", test_path, flavor);
220   hb_test_add_vtable (path, data_size, test_data, data_setup, data_test, data_teardown);
221   g_free (path);
222 }
223 #define hb_test_add_fixture_flavor(FixturePrefix, UserData, Flavor, Func) \
224 G_STMT_START { \
225   typedef G_PASTE (FixturePrefix, _t) Fixture; \
226   void (*add_vtable) (const char*, const char *, gsize, gconstpointer, \
227                       void (*) (Fixture*, gconstpointer), \
228                       void (*) (Fixture*, gconstpointer), \
229                       void (*) (Fixture*, gconstpointer)) \
230         = (void (*) (const gchar *, const char *, gsize, gconstpointer, \
231                      void (*) (Fixture*, gconstpointer), \
232                      void (*) (Fixture*, gconstpointer), \
233                      void (*) (Fixture*, gconstpointer))) hb_test_add_vtable_flavor; \
234   add_vtable (#Func, Flavor, sizeof (G_PASTE (FixturePrefix, _t)), UserData, \
235               G_PASTE (FixturePrefix, _init), Func, G_PASTE (FixturePrefix, _finish)); \
236 } G_STMT_END
237
238
239 HB_END_DECLS
240
241 #endif /* HB_TEST_H */