1 /* 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 */ 6 module glib.gtestutils; 7 8 import glib.gmessages; 9 import glib.gtypes; 10 import glib.gstring; 11 import glib.gerror; 12 import glib.gslist; 13 14 // TODO: (or not to do) D bindings 15 16 // typedef struct GTestCase GTestCase; 17 // typedef struct GTestSuite GTestSuite; 18 // typedef void (*GTestFunc) (void); 19 // typedef void (*GTestDataFunc) (gconstpointer user_data); 20 // typedef void (*GTestFixtureFunc) (gpointer fixture, 21 // gconstpointer user_data); 22 // 23 // /* assertion API */ 24 // #define g_assert_cmpstr(s1, cmp, s2) do { const char *__s1 = (s1), *__s2 = (s2); \ 25 // if (g_strcmp0 (__s1, __s2) cmp 0) ; else \ 26 // g_assertion_message_cmpstr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 27 // #s1 " " #cmp " " #s2, __s1, #cmp, __s2); } while (0) 28 // #define g_assert_cmpint(n1, cmp, n2) do { gint64 __n1 = (n1), __n2 = (n2); \ 29 // if (__n1 cmp __n2) ; else \ 30 // g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 31 // #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); } while (0) 32 // #define g_assert_cmpuint(n1, cmp, n2) do { guint64 __n1 = (n1), __n2 = (n2); \ 33 // if (__n1 cmp __n2) ; else \ 34 // g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 35 // #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); } while (0) 36 // #define g_assert_cmphex(n1, cmp, n2) do { guint64 __n1 = (n1), __n2 = (n2); \ 37 // if (__n1 cmp __n2) ; else \ 38 // g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 39 // #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'x'); } while (0) 40 // #define g_assert_cmpfloat(n1,cmp,n2) do { long double __n1 = (n1), __n2 = (n2); \ 41 // if (__n1 cmp __n2) ; else \ 42 // g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 43 // #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'f'); } while (0) 44 // #define g_assert_no_error(err) do { if (err) \ 45 // g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 46 // #err, err, 0, 0); } while (0) 47 // #define g_assert_error(err, dom, c) do { if (!err || (err)->domain != dom || (err)->code != c) \ 48 // g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 49 // #err, err, dom, c); } while (0) 50 // #define g_assert_true(expr) do { if G_LIKELY (expr) ; else \ 51 // g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 52 // "'" #expr "' should be TRUE"); \ 53 // } while (0) 54 // #define g_assert_false(expr) do { if G_LIKELY (!(expr)) ; else \ 55 // g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 56 // "'" #expr "' should be FALSE"); \ 57 // } while (0) 58 // #define g_assert_null(expr) do { if G_LIKELY ((expr) == NULL) ; else \ 59 // g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 60 // "'" #expr "' should be NULL"); \ 61 // } while (0) 62 // #define g_assert_nonnull(expr) do { if G_LIKELY ((expr) != NULL) ; else \ 63 // g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 64 // "'" #expr "' should not be NULL"); \ 65 // } while (0) 66 // #ifdef G_DISABLE_ASSERT 67 // #define g_assert_not_reached() do { (void) 0; } while (0) 68 // #define g_assert(expr) do { (void) 0; } while (0) 69 // #else /* !G_DISABLE_ASSERT */ 70 // #define g_assert_not_reached() do { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0) 71 // #define g_assert(expr) do { if G_LIKELY (expr) ; else \ 72 // g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 73 // #expr); \ 74 // } while (0) 75 // #endif /* !G_DISABLE_ASSERT */ 76 // 77 // GLIB_AVAILABLE_IN_ALL 78 // int g_strcmp0 (const char *str1, 79 // const char *str2); 80 // 81 // /* report performance results */ 82 // GLIB_AVAILABLE_IN_ALL 83 // void g_test_minimized_result (double minimized_quantity, 84 // const char *format, 85 // ...) G_GNUC_PRINTF (2, 3); 86 // GLIB_AVAILABLE_IN_ALL 87 // void g_test_maximized_result (double maximized_quantity, 88 // const char *format, 89 // ...) G_GNUC_PRINTF (2, 3); 90 // 91 // /* initialize testing framework */ 92 // GLIB_AVAILABLE_IN_ALL 93 // void g_test_init (int *argc, 94 // char ***argv, 95 // ...) G_GNUC_NULL_TERMINATED; 96 // /* query testing framework config */ 97 // #define g_test_initialized() (g_test_config_vars->test_initialized) 98 // #define g_test_quick() (g_test_config_vars->test_quick) 99 // #define g_test_slow() (!g_test_config_vars->test_quick) 100 // #define g_test_thorough() (!g_test_config_vars->test_quick) 101 // #define g_test_perf() (g_test_config_vars->test_perf) 102 // #define g_test_verbose() (g_test_config_vars->test_verbose) 103 // #define g_test_quiet() (g_test_config_vars->test_quiet) 104 // #define g_test_undefined() (g_test_config_vars->test_undefined) 105 // GLIB_AVAILABLE_IN_2_38 106 // gboolean g_test_subprocess (void); 107 // 108 // /* run all tests under toplevel suite (path: /) */ 109 // GLIB_AVAILABLE_IN_ALL 110 // int g_test_run (void); 111 // /* hook up a test functions under test path */ 112 // GLIB_AVAILABLE_IN_ALL 113 // void g_test_add_func (const char *testpath, 114 // GTestFunc test_func); 115 // 116 // GLIB_AVAILABLE_IN_ALL 117 // void g_test_add_data_func (const char *testpath, 118 // gconstpointer test_data, 119 // GTestDataFunc test_func); 120 // 121 // GLIB_AVAILABLE_IN_2_34 122 // void g_test_add_data_func_full (const char *testpath, 123 // gpointer test_data, 124 // GTestDataFunc test_func, 125 // GDestroyNotify data_free_func); 126 // 127 // /* tell about failure */ 128 // GLIB_AVAILABLE_IN_2_30 129 // void g_test_fail (void); 130 // GLIB_AVAILABLE_IN_2_38 131 // void g_test_incomplete (const gchar *msg); 132 // GLIB_AVAILABLE_IN_2_38 133 // void g_test_skip (const gchar *msg); 134 // GLIB_AVAILABLE_IN_2_38 135 // gboolean g_test_failed (void); 136 // GLIB_AVAILABLE_IN_2_38 137 // void g_test_set_nonfatal_assertions (void); 138 // 139 // /* hook up a test with fixture under test path */ 140 // #define g_test_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \ 141 // G_STMT_START { \ 142 // void (*add_vtable) (const char*, \ 143 // gsize, \ 144 // gconstpointer, \ 145 // void (*) (Fixture*, gconstpointer), \ 146 // void (*) (Fixture*, gconstpointer), \ 147 // void (*) (Fixture*, gconstpointer)) = (void (*) (const gchar *, gsize, gconstpointer, void (*) (Fixture*, gconstpointer), void (*) (Fixture*, gconstpointer), void (*) (Fixture*, gconstpointer))) g_test_add_vtable; \ 148 // add_vtable \ 149 // (testpath, sizeof (Fixture), tdata, fsetup, ftest, fteardown); \ 150 // } G_STMT_END 151 // 152 // /* add test messages to the test report */ 153 // GLIB_AVAILABLE_IN_ALL 154 // void g_test_message (const char *format, 155 // ...) G_GNUC_PRINTF (1, 2); 156 // GLIB_AVAILABLE_IN_ALL 157 // void g_test_bug_base (const char *uri_pattern); 158 // GLIB_AVAILABLE_IN_ALL 159 // void g_test_bug (const char *bug_uri_snippet); 160 // /* measure test timings */ 161 // GLIB_AVAILABLE_IN_ALL 162 // void g_test_timer_start (void); 163 // GLIB_AVAILABLE_IN_ALL 164 // double g_test_timer_elapsed (void); /* elapsed seconds */ 165 // GLIB_AVAILABLE_IN_ALL 166 // double g_test_timer_last (void); /* repeat last elapsed() result */ 167 // 168 // /* automatically g_free or g_object_unref upon teardown */ 169 // GLIB_AVAILABLE_IN_ALL 170 // void g_test_queue_free (gpointer gfree_pointer); 171 // GLIB_AVAILABLE_IN_ALL 172 // void g_test_queue_destroy (GDestroyNotify destroy_func, 173 // gpointer destroy_data); 174 // #define g_test_queue_unref(gobject) g_test_queue_destroy (g_object_unref, gobject) 175 // 176 // typedef enum { 177 // G_TEST_TRAP_SILENCE_STDOUT = 1 << 7, 178 // G_TEST_TRAP_SILENCE_STDERR = 1 << 8, 179 // G_TEST_TRAP_INHERIT_STDIN = 1 << 9 180 // } GTestTrapFlags; 181 // 182 // GLIB_DEPRECATED_IN_2_38_FOR (g_test_trap_subprocess) 183 // gboolean g_test_trap_fork (guint64 usec_timeout, 184 // GTestTrapFlags test_trap_flags); 185 // 186 // typedef enum { 187 // G_TEST_SUBPROCESS_INHERIT_STDIN = 1 << 0, 188 // G_TEST_SUBPROCESS_INHERIT_STDOUT = 1 << 1, 189 // G_TEST_SUBPROCESS_INHERIT_STDERR = 1 << 2 190 // } GTestSubprocessFlags; 191 // 192 // GLIB_AVAILABLE_IN_2_38 193 // void g_test_trap_subprocess (const char *test_path, 194 // guint64 usec_timeout, 195 // GTestSubprocessFlags test_flags); 196 // 197 // GLIB_AVAILABLE_IN_ALL 198 // gboolean g_test_trap_has_passed (void); 199 // GLIB_AVAILABLE_IN_ALL 200 // gboolean g_test_trap_reached_timeout (void); 201 // #define g_test_trap_assert_passed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 0, 0) 202 // #define g_test_trap_assert_failed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 1, 0) 203 // #define g_test_trap_assert_stdout(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 2, soutpattern) 204 // #define g_test_trap_assert_stdout_unmatched(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 3, soutpattern) 205 // #define g_test_trap_assert_stderr(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 4, serrpattern) 206 // #define g_test_trap_assert_stderr_unmatched(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 5, serrpattern) 207 // 208 // /* provide seed-able random numbers for tests */ 209 // #define g_test_rand_bit() (0 != (g_test_rand_int() & (1 << 15))) 210 // GLIB_AVAILABLE_IN_ALL 211 // gint32 g_test_rand_int (void); 212 // GLIB_AVAILABLE_IN_ALL 213 // gint32 g_test_rand_int_range (gint32 begin, 214 // gint32 end); 215 // GLIB_AVAILABLE_IN_ALL 216 // double g_test_rand_double (void); 217 // GLIB_AVAILABLE_IN_ALL 218 // double g_test_rand_double_range (double range_start, 219 // double range_end); 220 // 221 // /* semi-internal API */ 222 // GLIB_AVAILABLE_IN_ALL 223 // GTestCase* g_test_create_case (const char *test_name, 224 // gsize data_size, 225 // gconstpointer test_data, 226 // GTestFixtureFunc data_setup, 227 // GTestFixtureFunc data_test, 228 // GTestFixtureFunc data_teardown); 229 // GLIB_AVAILABLE_IN_ALL 230 // GTestSuite* g_test_create_suite (const char *suite_name); 231 // GLIB_AVAILABLE_IN_ALL 232 // GTestSuite* g_test_get_root (void); 233 // GLIB_AVAILABLE_IN_ALL 234 // void g_test_suite_add (GTestSuite *suite, 235 // GTestCase *test_case); 236 // GLIB_AVAILABLE_IN_ALL 237 // void g_test_suite_add_suite (GTestSuite *suite, 238 // GTestSuite *nestedsuite); 239 // GLIB_AVAILABLE_IN_ALL 240 // int g_test_run_suite (GTestSuite *suite); 241 // 242 // /* internal ABI */ 243 // GLIB_AVAILABLE_IN_ALL 244 // void g_test_trap_assertions (const char *domain, 245 // const char *file, 246 // int line, 247 // const char *func, 248 // guint64 assertion_flags, /* 0-pass, 1-fail, 2-outpattern, 4-errpattern */ 249 // const char *pattern); 250 // GLIB_AVAILABLE_IN_ALL 251 // void g_assertion_message (const char *domain, 252 // const char *file, 253 // int line, 254 // const char *func, 255 // const char *message); 256 // GLIB_AVAILABLE_IN_ALL 257 // void g_assertion_message_expr (const char *domain, 258 // const char *file, 259 // int line, 260 // const char *func, 261 // const char *expr) G_GNUC_NORETURN; 262 // GLIB_AVAILABLE_IN_ALL 263 // void g_assertion_message_cmpstr (const char *domain, 264 // const char *file, 265 // int line, 266 // const char *func, 267 // const char *expr, 268 // const char *arg1, 269 // const char *cmp, 270 // const char *arg2); 271 // GLIB_AVAILABLE_IN_ALL 272 // void g_assertion_message_cmpnum (const char *domain, 273 // const char *file, 274 // int line, 275 // const char *func, 276 // const char *expr, 277 // long double arg1, 278 // const char *cmp, 279 // long double arg2, 280 // char numtype); 281 // GLIB_AVAILABLE_IN_ALL 282 // void g_assertion_message_error (const char *domain, 283 // const char *file, 284 // int line, 285 // const char *func, 286 // const char *expr, 287 // const GError *error, 288 // GQuark error_domain, 289 // int error_code); 290 // GLIB_AVAILABLE_IN_ALL 291 // void g_test_add_vtable (const char *testpath, 292 // gsize data_size, 293 // gconstpointer test_data, 294 // GTestFixtureFunc data_setup, 295 // GTestFixtureFunc data_test, 296 // GTestFixtureFunc data_teardown); 297 // typedef struct { 298 // gboolean test_initialized; 299 // gboolean test_quick; /* disable thorough tests */ 300 // gboolean test_perf; /* run performance tests */ 301 // gboolean test_verbose; /* extra info */ 302 // gboolean test_quiet; /* reduce output */ 303 // gboolean test_undefined; /* run tests that are meant to assert */ 304 // } GTestConfig; 305 // GLIB_VAR const GTestConfig * const g_test_config_vars; 306 // 307 // /* internal logging API */ 308 // typedef enum { 309 // G_TEST_LOG_NONE, 310 // G_TEST_LOG_ERROR, /* s:msg */ 311 // G_TEST_LOG_START_BINARY, /* s:binaryname s:seed */ 312 // G_TEST_LOG_LIST_CASE, /* s:testpath */ 313 // G_TEST_LOG_SKIP_CASE, /* s:testpath */ 314 // G_TEST_LOG_START_CASE, /* s:testpath */ 315 // G_TEST_LOG_STOP_CASE, /* d:status d:nforks d:elapsed */ 316 // G_TEST_LOG_MIN_RESULT, /* s:blurb d:result */ 317 // G_TEST_LOG_MAX_RESULT, /* s:blurb d:result */ 318 // G_TEST_LOG_MESSAGE, /* s:blurb */ 319 // G_TEST_LOG_START_SUITE, 320 // G_TEST_LOG_STOP_SUITE 321 // } GTestLogType; 322 // 323 // typedef struct { 324 // GTestLogType log_type; 325 // guint n_strings; 326 // gchar **strings; /* NULL terminated */ 327 // guint n_nums; 328 // long double *nums; 329 // } GTestLogMsg; 330 // typedef struct { 331 // /*< private >*/ 332 // GString *data; 333 // GSList *msgs; 334 // } GTestLogBuffer; 335 // 336 // GLIB_AVAILABLE_IN_ALL 337 // const char* g_test_log_type_name (GTestLogType log_type); 338 // GLIB_AVAILABLE_IN_ALL 339 // GTestLogBuffer* g_test_log_buffer_new (void); 340 // GLIB_AVAILABLE_IN_ALL 341 // void g_test_log_buffer_free (GTestLogBuffer *tbuffer); 342 // GLIB_AVAILABLE_IN_ALL 343 // void g_test_log_buffer_push (GTestLogBuffer *tbuffer, 344 // guint n_bytes, 345 // const guint8 *bytes); 346 // GLIB_AVAILABLE_IN_ALL 347 // GTestLogMsg* g_test_log_buffer_pop (GTestLogBuffer *tbuffer); 348 // GLIB_AVAILABLE_IN_ALL 349 // void g_test_log_msg_free (GTestLogMsg *tmsg); 350 // 351 // /** 352 // * GTestLogFatalFunc: 353 // * @log_domain: the log domain of the message 354 // * @log_level: the log level of the message (including the fatal and recursion flags) 355 // * @message: the message to process 356 // * @user_data: user data, set in g_test_log_set_fatal_handler() 357 // * 358 // * Specifies the prototype of fatal log handler functions. 359 // * 360 // * Returns: %TRUE if the program should abort, %FALSE otherwise 361 // * 362 // * Since: 2.22 363 // */ 364 // typedef gboolean (*GTestLogFatalFunc) (const gchar *log_domain, 365 // GLogLevelFlags log_level, 366 // const gchar *message, 367 // gpointer user_data); 368 // GLIB_AVAILABLE_IN_ALL 369 // void 370 // g_test_log_set_fatal_handler (GTestLogFatalFunc log_func, 371 // gpointer user_data); 372 // 373 // GLIB_AVAILABLE_IN_2_34 374 // void g_test_expect_message (const gchar *log_domain, 375 // GLogLevelFlags log_level, 376 // const gchar *pattern); 377 // GLIB_AVAILABLE_IN_2_34 378 // void g_test_assert_expected_messages_internal (const char *domain, 379 // const char *file, 380 // int line, 381 // const char *func); 382 // 383 // typedef enum 384 // { 385 // G_TEST_DIST, 386 // G_TEST_BUILT 387 // } GTestFileType; 388 // 389 // GLIB_AVAILABLE_IN_2_38 390 // gchar * g_test_build_filename (GTestFileType file_type, 391 // const gchar *first_path, 392 // ...) G_GNUC_NULL_TERMINATED; 393 // GLIB_AVAILABLE_IN_2_38 394 // const gchar *g_test_get_dir (GTestFileType file_type); 395 // GLIB_AVAILABLE_IN_2_38 396 // const gchar *g_test_get_filename (GTestFileType file_type, 397 // const gchar *first_path, 398 // ...) G_GNUC_NULL_TERMINATED; 399 // 400 // #define g_test_assert_expected_messages() g_test_assert_expected_messages_internal (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC) 401