[unicode] Make _get_parent() return _nil object instead of NULL
[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_test_init (argc, argv, NULL);
58 }
59
60 static inline int
61 hb_test_run (void)
62 {
63   return g_test_run ();
64 }
65
66
67 /* Bugzilla helpers */
68
69 static inline void
70 hb_test_bug (const char *uri_base, unsigned int number)
71 {
72   char *s = g_strdup_printf ("%u", number);
73
74   g_test_bug_base (uri_base);
75   g_test_bug (s);
76
77   g_free (s);
78 }
79
80 static inline void
81 hb_test_bug_freedesktop (unsigned int number)
82 {
83   hb_test_bug ("http://bugs.freedesktop.org/", number);
84 }
85
86 static inline void
87 hb_test_bug_gnome (unsigned int number)
88 {
89   hb_test_bug ("http://bugzilla.gnome.org/", number);
90 }
91
92 static inline void
93 hb_test_bug_mozilla (unsigned int number)
94 {
95   hb_test_bug ("http://bugzilla.mozilla.org/", number);
96 }
97
98 static inline void
99 hb_test_bug_redhat (unsigned int number)
100 {
101   hb_test_bug ("http://bugzilla.redhat.com/", number);
102 }
103
104
105 /* Wrap glib test functions to simplify.  Should have been in glib already. */
106
107 /* Drops the "test_" prefix and converts '_' to '/'.
108  * Essentially builds test path from function name. */
109 static inline char *
110 hb_test_normalize_path (const char *path)
111 {
112   char *s, *p;
113
114   g_assert (0 == strncmp (path, "test_", 5));
115   path += 4;
116
117   s = g_strdup (path);
118   for (p = s; *p; p++)
119     if (*p == '_')
120       *p = '/';
121
122   return s;
123 }
124
125
126 static inline void
127 hb_test_add_func (const char *test_path,
128                   GTestFunc   test_func)
129 {
130   char *normal_path = hb_test_normalize_path (test_path);
131   g_test_add_func (normal_path, test_func);
132   g_free (normal_path);
133 }
134 #define hb_test_add(Func) hb_test_add_func (#Func, Func)
135
136 static inline void
137 hb_test_add_func_flavor (const char *test_path,
138                          const char *flavor,
139                          GTestFunc   test_func)
140 {
141   char *path = g_strdup_printf ("%s/%s", test_path, flavor);
142   hb_test_add_func (path, test_func);
143   g_free (path);
144 }
145 #define hb_test_add_flavor(Flavor, Func) hb_test_add_func (#Func, Flavor, Func)
146
147 static inline void
148 hb_test_add_data_func (const char    *test_path,
149                        gconstpointer  test_data,
150                        GTestDataFunc  test_func)
151 {
152   char *normal_path = hb_test_normalize_path (test_path);
153   g_test_add_data_func (normal_path, test_data, test_func);
154   g_free (normal_path);
155 }
156 #define hb_test_add_data(UserData, Func) hb_test_add_data_func (#Func, UserData, Func)
157
158 static inline void
159 hb_test_add_data_func_flavor (const char    *test_path,
160                               const char    *flavor,
161                               gconstpointer  test_data,
162                               GTestDataFunc  test_func)
163 {
164   char *path = g_strdup_printf ("%s/%s", test_path, flavor);
165   hb_test_add_data_func (path, test_data, test_func);
166   g_free (path);
167 }
168 #define hb_test_add_data_flavor(UserData, Flavor, Func) hb_test_add_data_func_flavor (#Func, Flavor, UserData, Func)
169
170
171 static inline void
172 hb_test_add_vtable (const char       *test_path,
173                     gsize             data_size,
174                     gconstpointer     test_data,
175                     GTestFixtureFunc  data_setup,
176                     GTestFixtureFunc  data_test,
177                     GTestFixtureFunc  data_teardown)
178 {
179   char *normal_path = hb_test_normalize_path (test_path);
180   g_test_add_vtable (normal_path, data_size, test_data, data_setup, data_test, data_teardown);
181   g_free (normal_path);
182 }
183 #define hb_test_add_fixture(FixturePrefix, UserData, Func) \
184 G_STMT_START { \
185   typedef G_PASTE (FixturePrefix, _t) Fixture; \
186   void (*add_vtable) (const char*, gsize, gconstpointer, \
187                       void (*) (Fixture*, gconstpointer), \
188                       void (*) (Fixture*, gconstpointer), \
189                       void (*) (Fixture*, gconstpointer)) \
190         = (void (*) (const gchar *, gsize, gconstpointer, \
191                      void (*) (Fixture*, gconstpointer), \
192                      void (*) (Fixture*, gconstpointer), \
193                      void (*) (Fixture*, gconstpointer))) hb_test_add_vtable; \
194   add_vtable (#Func, sizeof (G_PASTE (FixturePrefix, _t)), UserData, \
195               G_PASTE (FixturePrefix, _init), Func, G_PASTE (FixturePrefix, _finish)); \
196 } G_STMT_END
197
198 static inline void
199 hb_test_add_vtable_flavor (const char       *test_path,
200                            const char       *flavor,
201                            gsize             data_size,
202                            gconstpointer     test_data,
203                            GTestFixtureFunc  data_setup,
204                            GTestFixtureFunc  data_test,
205                            GTestFixtureFunc  data_teardown)
206 {
207   char *path = g_strdup_printf ("%s/%s", test_path, flavor);
208   hb_test_add_vtable (path, data_size, test_data, data_setup, data_test, data_teardown);
209   g_free (path);
210 }
211 #define hb_test_add_fixture_flavor(FixturePrefix, UserData, Flavor, Func) \
212 G_STMT_START { \
213   typedef G_PASTE (FixturePrefix, _t) Fixture; \
214   void (*add_vtable) (const char*, const char *, gsize, gconstpointer, \
215                       void (*) (Fixture*, gconstpointer), \
216                       void (*) (Fixture*, gconstpointer), \
217                       void (*) (Fixture*, gconstpointer)) \
218         = (void (*) (const gchar *, const char *, gsize, gconstpointer, \
219                      void (*) (Fixture*, gconstpointer), \
220                      void (*) (Fixture*, gconstpointer), \
221                      void (*) (Fixture*, gconstpointer))) hb_test_add_vtable_flavor; \
222   add_vtable (#Func, Flavor, sizeof (G_PASTE (FixturePrefix, _t)), UserData, \
223               G_PASTE (FixturePrefix, _init), Func, G_PASTE (FixturePrefix, _finish)); \
224 } G_STMT_END
225
226
227 HB_END_DECLS
228
229 #endif /* HB_TEST_H */