File indexing completed on 2025-02-18 10:03:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef __G_TEST_UTILS_H__
0022 #define __G_TEST_UTILS_H__
0023
0024 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
0025 #error "Only <glib.h> can be included directly."
0026 #endif
0027
0028 #include <glib/gmessages.h>
0029 #include <glib/gstring.h>
0030 #include <glib/gerror.h>
0031 #include <glib/gslist.h>
0032 #include <errno.h>
0033 #include <stdlib.h>
0034 #include <string.h>
0035
0036 G_BEGIN_DECLS
0037
0038 typedef struct GTestCase GTestCase;
0039 typedef struct GTestSuite GTestSuite;
0040 typedef void (*GTestFunc) (void);
0041 typedef void (*GTestDataFunc) (gconstpointer user_data);
0042 typedef void (*GTestFixtureFunc) (gpointer fixture,
0043 gconstpointer user_data);
0044
0045
0046 #define g_assert_cmpstr(s1, cmp, s2) G_STMT_START { \
0047 const char *__s1 = (s1), *__s2 = (s2); \
0048 if (g_strcmp0 (__s1, __s2) cmp 0) ; else \
0049 g_assertion_message_cmpstr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0050 #s1 " " #cmp " " #s2, __s1, #cmp, __s2); \
0051 } G_STMT_END
0052 #if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_78
0053 #define g_assert_cmpint(n1, cmp, n2) G_STMT_START { \
0054 gint64 __n1 = (n1), __n2 = (n2); \
0055 if (__n1 cmp __n2) ; else \
0056 g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0057 #n1 " " #cmp " " #n2, (guint64)__n1, #cmp, (guint64)__n2, 'i'); \
0058 } G_STMT_END
0059 #define g_assert_cmpuint(n1, cmp, n2) G_STMT_START { \
0060 guint64 __n1 = (n1), __n2 = (n2); \
0061 if (__n1 cmp __n2) ; else \
0062 g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0063 #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'u'); \
0064 } G_STMT_END
0065 #define g_assert_cmphex(n1, cmp, n2) G_STMT_START { \
0066 guint64 __n1 = (n1), __n2 = (n2); \
0067 if (__n1 cmp __n2) ; else \
0068 g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0069 #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'x'); \
0070 } G_STMT_END
0071 #else
0072 #define g_assert_cmpint(n1, cmp, n2) G_STMT_START { \
0073 gint64 __n1 = (n1), __n2 = (n2); \
0074 if (__n1 cmp __n2) ; else \
0075 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0076 #n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'i'); \
0077 } G_STMT_END
0078 #define g_assert_cmpuint(n1, cmp, n2) G_STMT_START { \
0079 guint64 __n1 = (n1), __n2 = (n2); \
0080 if (__n1 cmp __n2) ; else \
0081 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0082 #n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'i'); \
0083 } G_STMT_END
0084 #define g_assert_cmphex(n1, cmp, n2) G_STMT_START {\
0085 guint64 __n1 = (n1), __n2 = (n2); \
0086 if (__n1 cmp __n2) ; else \
0087 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0088 #n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'x'); \
0089 } G_STMT_END
0090 #endif
0091 #define g_assert_cmpfloat(n1,cmp,n2) G_STMT_START { \
0092 long double __n1 = (long double) (n1), __n2 = (long double) (n2); \
0093 if (__n1 cmp __n2) ; else \
0094 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0095 #n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'f'); \
0096 } G_STMT_END
0097 #define g_assert_cmpfloat_with_epsilon(n1,n2,epsilon) \
0098 G_STMT_START { \
0099 double __n1 = (n1), __n2 = (n2), __epsilon = (epsilon); \
0100 if (G_APPROX_VALUE (__n1, __n2, __epsilon)) ; else \
0101 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0102 #n1 " == " #n2 " (+/- " #epsilon ")", __n1, "==", __n2, 'f'); \
0103 } G_STMT_END
0104 #if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_78
0105 #define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
0106 gconstpointer __m1 = m1, __m2 = m2; \
0107 size_t __l1 = (size_t) l1, __l2 = (size_t) l2; \
0108 if (__l1 != 0 && __m1 == NULL) \
0109 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0110 "assertion failed (" #l1 " == 0 || " #m1 " != NULL)"); \
0111 else if (__l2 != 0 && __m2 == NULL) \
0112 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0113 "assertion failed (" #l2 " == 0 || " #m2 " != NULL)"); \
0114 else if (__l1 != __l2) \
0115 g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0116 #l1 " (len(" #m1 ")) == " #l2 " (len(" #m2 "))", \
0117 __l1, "==", __l2, 'u'); \
0118 else if (__l1 != 0 && __m2 != NULL && memcmp (__m1, __m2, __l1) != 0) \
0119 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0120 "assertion failed (" #m1 " == " #m2 ")"); \
0121 } G_STMT_END
0122 #else
0123 #define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
0124 gconstpointer __m1 = m1, __m2 = m2; \
0125 size_t __l1 = (size_t) l1, __l2 = (size_t) l2; \
0126 if (__l1 != 0 && __m1 == NULL) \
0127 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0128 "assertion failed (" #l1 " == 0 || " #m1 " != NULL)"); \
0129 else if (__l2 != 0 && __m2 == NULL) \
0130 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0131 "assertion failed (" #l2 " == 0 || " #m2 " != NULL)"); \
0132 else if (__l1 != __l2) \
0133 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0134 #l1 " (len(" #m1 ")) == " #l2 " (len(" #m2 "))", \
0135 (long double) __l1, "==", (long double) __l2, 'i'); \
0136 else if (__l1 != 0 && __m2 != NULL && memcmp (__m1, __m2, __l1) != 0) \
0137 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0138 "assertion failed (" #m1 " == " #m2 ")"); \
0139 } G_STMT_END
0140 #endif
0141 #define g_assert_cmpvariant(v1, v2) \
0142 G_STMT_START \
0143 { \
0144 GVariant *__v1 = (v1), *__v2 = (v2); \
0145 if (!g_variant_equal (__v1, __v2)) \
0146 { \
0147 gchar *__s1, *__s2, *__msg; \
0148 __s1 = g_variant_print (__v1, TRUE); \
0149 __s2 = g_variant_print (__v2, TRUE); \
0150 __msg = g_strdup_printf ("assertion failed (" #v1 " == " #v2 "): %s does not equal %s", __s1, __s2); \
0151 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
0152 g_free (__s1); \
0153 g_free (__s2); \
0154 g_free (__msg); \
0155 } \
0156 } \
0157 G_STMT_END
0158 #define g_assert_cmpstrv(strv1, strv2) \
0159 G_STMT_START \
0160 { \
0161 const char * const *__strv1 = (const char * const *) (strv1); \
0162 const char * const *__strv2 = (const char * const *) (strv2); \
0163 if (!__strv1 || !__strv2) \
0164 { \
0165 if (__strv1) \
0166 { \
0167 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0168 "assertion failed (" #strv1 " == " #strv2 "): " #strv2 " is NULL, but " #strv1 " is not"); \
0169 } \
0170 else if (__strv2) \
0171 { \
0172 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0173 "assertion failed (" #strv1 " == " #strv2 "): " #strv1 " is NULL, but " #strv2 " is not"); \
0174 } \
0175 } \
0176 else \
0177 { \
0178 guint __l1 = g_strv_length ((char **) __strv1); \
0179 guint __l2 = g_strv_length ((char **) __strv2); \
0180 if (__l1 != __l2) \
0181 { \
0182 char *__msg; \
0183 __msg = g_strdup_printf ("assertion failed (" #strv1 " == " #strv2 "): length %u does not equal length %u", __l1, __l2); \
0184 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
0185 g_free (__msg); \
0186 } \
0187 else \
0188 { \
0189 guint __i; \
0190 for (__i = 0; __i < __l1; __i++) \
0191 { \
0192 if (g_strcmp0 (__strv1[__i], __strv2[__i]) != 0) \
0193 { \
0194 g_assertion_message_cmpstrv (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0195 #strv1 " == " #strv2, \
0196 __strv1, __strv2, __i); \
0197 } \
0198 } \
0199 } \
0200 } \
0201 } \
0202 G_STMT_END
0203 #define g_assert_no_errno(expr) G_STMT_START { \
0204 int __ret, __errsv; \
0205 errno = 0; \
0206 __ret = expr; \
0207 __errsv = errno; \
0208 if (__ret < 0) \
0209 { \
0210 gchar *__msg; \
0211 __msg = g_strdup_printf ("assertion failed (" #expr " >= 0): errno %i: %s", __errsv, g_strerror (__errsv)); \
0212 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \
0213 g_free (__msg); \
0214 } \
0215 } G_STMT_END \
0216 GLIB_AVAILABLE_MACRO_IN_2_66
0217 #define g_assert_no_error(err) G_STMT_START { \
0218 if (err) \
0219 g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0220 #err, err, 0, 0); \
0221 } G_STMT_END
0222 #define g_assert_error(err, dom, c) G_STMT_START { \
0223 if (!err || (err)->domain != dom || (err)->code != c) \
0224 g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0225 #err, err, dom, c); \
0226 } G_STMT_END
0227 #define g_assert_true(expr) G_STMT_START { \
0228 if G_LIKELY (expr) ; else \
0229 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0230 "'" #expr "' should be TRUE"); \
0231 } G_STMT_END
0232 #define g_assert_false(expr) G_STMT_START { \
0233 if G_LIKELY (!(expr)) ; else \
0234 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0235 "'" #expr "' should be FALSE"); \
0236 } G_STMT_END
0237
0238
0239 #if G_CXX_STD_CHECK_VERSION (11)
0240 #define g_assert_null(expr) G_STMT_START { if G_LIKELY ((expr) == nullptr) ; else \
0241 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0242 "'" #expr "' should be nullptr"); \
0243 } G_STMT_END
0244 #define g_assert_nonnull(expr) G_STMT_START { \
0245 if G_LIKELY ((expr) != nullptr) ; else \
0246 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0247 "'" #expr "' should not be nullptr"); \
0248 } G_STMT_END
0249 #else
0250 #define g_assert_null(expr) G_STMT_START { if G_LIKELY ((expr) == NULL) ; else \
0251 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0252 "'" #expr "' should be NULL"); \
0253 } G_STMT_END
0254 #define g_assert_nonnull(expr) G_STMT_START { \
0255 if G_LIKELY ((expr) != NULL) ; else \
0256 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0257 "'" #expr "' should not be NULL"); \
0258 } G_STMT_END
0259 #endif
0260
0261 #ifdef G_DISABLE_ASSERT
0262
0263
0264 #if __GNUC__ >= 5 || g_macro__has_builtin(__builtin_unreachable)
0265 #define g_assert_not_reached() G_STMT_START { (void) 0; __builtin_unreachable (); } G_STMT_END
0266 #elif defined (_MSC_VER)
0267 #define g_assert_not_reached() G_STMT_START { (void) 0; __assume (0); } G_STMT_END
0268 #else
0269 #define g_assert_not_reached() G_STMT_START { (void) 0; } G_STMT_END
0270 #endif
0271
0272 #define g_assert(expr) G_STMT_START { (void) 0; } G_STMT_END
0273 #else
0274 #define g_assert_not_reached() G_STMT_START { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } G_STMT_END
0275 #define g_assert(expr) G_STMT_START { \
0276 if G_LIKELY (expr) ; else \
0277 g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
0278 #expr); \
0279 } G_STMT_END
0280 #endif
0281
0282 GLIB_AVAILABLE_IN_ALL
0283 int g_strcmp0 (const char *str1,
0284 const char *str2);
0285
0286
0287 GLIB_AVAILABLE_IN_ALL
0288 void g_test_minimized_result (double minimized_quantity,
0289 const char *format,
0290 ...) G_GNUC_PRINTF (2, 3);
0291 GLIB_AVAILABLE_IN_ALL
0292 void g_test_maximized_result (double maximized_quantity,
0293 const char *format,
0294 ...) G_GNUC_PRINTF (2, 3);
0295
0296
0297 GLIB_AVAILABLE_IN_ALL
0298 void g_test_init (int *argc,
0299 char ***argv,
0300 ...) G_GNUC_NULL_TERMINATED;
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331 #define G_TEST_OPTION_ISOLATE_DIRS "isolate_dirs"
0332
0333
0334
0335
0336
0337 #ifdef G_DISABLE_ASSERT
0338 #if defined(G_HAVE_ISO_VARARGS)
0339 #define g_test_init(argc, argv, ...) \
0340 G_STMT_START { \
0341 g_printerr ("Tests were compiled with G_DISABLE_ASSERT and are likely no-ops. Aborting.\n"); \
0342 exit (1); \
0343 } G_STMT_END
0344 #elif defined(G_HAVE_GNUC_VARARGS)
0345 #define g_test_init(argc, argv...) \
0346 G_STMT_START { \
0347 g_printerr ("Tests were compiled with G_DISABLE_ASSERT and are likely no-ops. Aborting.\n"); \
0348 exit (1); \
0349 } G_STMT_END
0350 #else
0351
0352 #endif
0353 #endif
0354
0355
0356 #define g_test_initialized() (g_test_config_vars->test_initialized)
0357 #define g_test_quick() (g_test_config_vars->test_quick)
0358 #define g_test_slow() (!g_test_config_vars->test_quick)
0359 #define g_test_thorough() (!g_test_config_vars->test_quick)
0360 #define g_test_perf() (g_test_config_vars->test_perf)
0361 #define g_test_verbose() (g_test_config_vars->test_verbose)
0362 #define g_test_quiet() (g_test_config_vars->test_quiet)
0363 #define g_test_undefined() (g_test_config_vars->test_undefined)
0364 GLIB_AVAILABLE_IN_2_38
0365 gboolean g_test_subprocess (void);
0366
0367
0368 GLIB_AVAILABLE_IN_ALL
0369 int g_test_run (void);
0370
0371 GLIB_AVAILABLE_IN_ALL
0372 void g_test_add_func (const char *testpath,
0373 GTestFunc test_func);
0374
0375 GLIB_AVAILABLE_IN_ALL
0376 void g_test_add_data_func (const char *testpath,
0377 gconstpointer test_data,
0378 GTestDataFunc test_func);
0379
0380 GLIB_AVAILABLE_IN_2_34
0381 void g_test_add_data_func_full (const char *testpath,
0382 gpointer test_data,
0383 GTestDataFunc test_func,
0384 GDestroyNotify data_free_func);
0385
0386
0387 GLIB_AVAILABLE_IN_2_68
0388 const char * g_test_get_path (void);
0389
0390
0391 GLIB_AVAILABLE_IN_2_30
0392 void g_test_fail (void);
0393 GLIB_AVAILABLE_IN_2_70
0394 void g_test_fail_printf (const char *format,
0395 ...) G_GNUC_PRINTF (1, 2);
0396 GLIB_AVAILABLE_IN_2_38
0397 void g_test_incomplete (const gchar *msg);
0398 GLIB_AVAILABLE_IN_2_70
0399 void g_test_incomplete_printf (const char *format,
0400 ...) G_GNUC_PRINTF (1, 2);
0401 GLIB_AVAILABLE_IN_2_38
0402 void g_test_skip (const gchar *msg);
0403 GLIB_AVAILABLE_IN_2_70
0404 void g_test_skip_printf (const char *format,
0405 ...) G_GNUC_PRINTF (1, 2);
0406 GLIB_AVAILABLE_IN_2_38
0407 gboolean g_test_failed (void);
0408 GLIB_AVAILABLE_IN_2_38
0409 void g_test_set_nonfatal_assertions (void);
0410 GLIB_AVAILABLE_IN_2_78
0411 void g_test_disable_crash_reporting (void);
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432 #define g_test_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
0433 G_STMT_START { \
0434 void (*add_vtable) (const char*, \
0435 gsize, \
0436 gconstpointer, \
0437 void (*) (Fixture*, gconstpointer), \
0438 void (*) (Fixture*, gconstpointer), \
0439 void (*) (Fixture*, gconstpointer)) = (void (*) (const gchar *, gsize, gconstpointer, void (*) (Fixture*, gconstpointer), void (*) (Fixture*, gconstpointer), void (*) (Fixture*, gconstpointer))) g_test_add_vtable; \
0440 add_vtable \
0441 (testpath, sizeof (Fixture), tdata, fsetup, ftest, fteardown); \
0442 } G_STMT_END
0443
0444
0445 GLIB_AVAILABLE_IN_ALL
0446 void g_test_message (const char *format,
0447 ...) G_GNUC_PRINTF (1, 2);
0448 GLIB_AVAILABLE_IN_ALL
0449 void g_test_bug_base (const char *uri_pattern);
0450 GLIB_AVAILABLE_IN_ALL
0451 void g_test_bug (const char *bug_uri_snippet);
0452 GLIB_AVAILABLE_IN_2_62
0453 void g_test_summary (const char *summary);
0454
0455 GLIB_AVAILABLE_IN_ALL
0456 void g_test_timer_start (void);
0457 GLIB_AVAILABLE_IN_ALL
0458 double g_test_timer_elapsed (void);
0459 GLIB_AVAILABLE_IN_ALL
0460 double g_test_timer_last (void);
0461
0462
0463 GLIB_AVAILABLE_IN_ALL
0464 void g_test_queue_free (gpointer gfree_pointer);
0465 GLIB_AVAILABLE_IN_ALL
0466 void g_test_queue_destroy (GDestroyNotify destroy_func,
0467 gpointer destroy_data);
0468 #define g_test_queue_unref(gobject) g_test_queue_destroy (g_object_unref, gobject)
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492 typedef enum {
0493 G_TEST_TRAP_DEFAULT GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0,
0494 G_TEST_TRAP_SILENCE_STDOUT = 1 << 7,
0495 G_TEST_TRAP_SILENCE_STDERR = 1 << 8,
0496 G_TEST_TRAP_INHERIT_STDIN = 1 << 9
0497 } GTestTrapFlags GLIB_DEPRECATED_TYPE_IN_2_38_FOR(GTestSubprocessFlags);
0498
0499 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
0500
0501 GLIB_DEPRECATED_IN_2_38_FOR (g_test_trap_subprocess)
0502 gboolean g_test_trap_fork (guint64 usec_timeout,
0503 GTestTrapFlags test_trap_flags);
0504
0505 G_GNUC_END_IGNORE_DEPRECATIONS
0506
0507 typedef enum {
0508 G_TEST_SUBPROCESS_DEFAULT GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0,
0509 G_TEST_SUBPROCESS_INHERIT_STDIN = 1 << 0,
0510 G_TEST_SUBPROCESS_INHERIT_STDOUT = 1 << 1,
0511 G_TEST_SUBPROCESS_INHERIT_STDERR = 1 << 2
0512 } GTestSubprocessFlags;
0513
0514 GLIB_AVAILABLE_IN_2_38
0515 void g_test_trap_subprocess (const char *test_path,
0516 guint64 usec_timeout,
0517 GTestSubprocessFlags test_flags);
0518 GLIB_AVAILABLE_IN_2_80
0519 void g_test_trap_subprocess_with_envp (const char *test_path,
0520 const char * const *envp,
0521 guint64 usec_timeout,
0522 GTestSubprocessFlags test_flags);
0523
0524 GLIB_AVAILABLE_IN_ALL
0525 gboolean g_test_trap_has_passed (void);
0526 GLIB_AVAILABLE_IN_ALL
0527 gboolean g_test_trap_reached_timeout (void);
0528 #define g_test_trap_assert_passed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 0, 0)
0529 #define g_test_trap_assert_failed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 1, 0)
0530 #define g_test_trap_assert_stdout(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 2, soutpattern)
0531 #define g_test_trap_assert_stdout_unmatched(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 3, soutpattern)
0532 #define g_test_trap_assert_stderr(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 4, serrpattern)
0533 #define g_test_trap_assert_stderr_unmatched(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 5, serrpattern)
0534
0535
0536 #define g_test_rand_bit() (0 != (g_test_rand_int() & (1 << 15)))
0537 GLIB_AVAILABLE_IN_ALL
0538 gint32 g_test_rand_int (void);
0539 GLIB_AVAILABLE_IN_ALL
0540 gint32 g_test_rand_int_range (gint32 begin,
0541 gint32 end);
0542 GLIB_AVAILABLE_IN_ALL
0543 double g_test_rand_double (void);
0544 GLIB_AVAILABLE_IN_ALL
0545 double g_test_rand_double_range (double range_start,
0546 double range_end);
0547
0548
0549
0550
0551
0552
0553 GLIB_AVAILABLE_IN_ALL
0554 GTestCase* g_test_create_case (const char *test_name,
0555 gsize data_size,
0556 gconstpointer test_data,
0557 GTestFixtureFunc data_setup,
0558 GTestFixtureFunc data_test,
0559 GTestFixtureFunc data_teardown);
0560 GLIB_AVAILABLE_IN_ALL
0561 GTestSuite* g_test_create_suite (const char *suite_name);
0562 GLIB_AVAILABLE_IN_ALL
0563 GTestSuite* g_test_get_root (void);
0564 GLIB_AVAILABLE_IN_ALL
0565 void g_test_suite_add (GTestSuite *suite,
0566 GTestCase *test_case);
0567 GLIB_AVAILABLE_IN_ALL
0568 void g_test_suite_add_suite (GTestSuite *suite,
0569 GTestSuite *nestedsuite);
0570 GLIB_AVAILABLE_IN_ALL
0571 int g_test_run_suite (GTestSuite *suite);
0572
0573 GLIB_AVAILABLE_IN_2_70
0574 void g_test_case_free (GTestCase *test_case);
0575
0576 GLIB_AVAILABLE_IN_2_70
0577 void g_test_suite_free (GTestSuite *suite);
0578
0579 GLIB_AVAILABLE_IN_ALL
0580 void g_test_trap_assertions (const char *domain,
0581 const char *file,
0582 int line,
0583 const char *func,
0584 guint64 assertion_flags,
0585 const char *pattern);
0586 GLIB_AVAILABLE_IN_ALL
0587 void g_assertion_message (const char *domain,
0588 const char *file,
0589 int line,
0590 const char *func,
0591 const char *message) G_ANALYZER_NORETURN;
0592 G_NORETURN
0593 GLIB_AVAILABLE_IN_ALL
0594 void g_assertion_message_expr (const char *domain,
0595 const char *file,
0596 int line,
0597 const char *func,
0598 const char *expr);
0599 GLIB_AVAILABLE_IN_ALL
0600 void g_assertion_message_cmpstr (const char *domain,
0601 const char *file,
0602 int line,
0603 const char *func,
0604 const char *expr,
0605 const char *arg1,
0606 const char *cmp,
0607 const char *arg2) G_ANALYZER_NORETURN;
0608
0609 GLIB_AVAILABLE_IN_2_68
0610 void g_assertion_message_cmpstrv (const char *domain,
0611 const char *file,
0612 int line,
0613 const char *func,
0614 const char *expr,
0615 const char * const *arg1,
0616 const char * const *arg2,
0617 gsize first_wrong_idx) G_ANALYZER_NORETURN;
0618 GLIB_AVAILABLE_IN_2_78
0619 void g_assertion_message_cmpint (const char *domain,
0620 const char *file,
0621 int line,
0622 const char *func,
0623 const char *expr,
0624 guint64 arg1,
0625 const char *cmp,
0626 guint64 arg2,
0627 char numtype) G_ANALYZER_NORETURN;
0628 GLIB_AVAILABLE_IN_ALL
0629 void g_assertion_message_cmpnum (const char *domain,
0630 const char *file,
0631 int line,
0632 const char *func,
0633 const char *expr,
0634 long double arg1,
0635 const char *cmp,
0636 long double arg2,
0637 char numtype) G_ANALYZER_NORETURN;
0638 GLIB_AVAILABLE_IN_ALL
0639 void g_assertion_message_error (const char *domain,
0640 const char *file,
0641 int line,
0642 const char *func,
0643 const char *expr,
0644 const GError *error,
0645 GQuark error_domain,
0646 int error_code) G_ANALYZER_NORETURN;
0647 GLIB_AVAILABLE_IN_ALL
0648 void g_test_add_vtable (const char *testpath,
0649 gsize data_size,
0650 gconstpointer test_data,
0651 GTestFixtureFunc data_setup,
0652 GTestFixtureFunc data_test,
0653 GTestFixtureFunc data_teardown);
0654 typedef struct {
0655 gboolean test_initialized;
0656 gboolean test_quick;
0657 gboolean test_perf;
0658 gboolean test_verbose;
0659 gboolean test_quiet;
0660 gboolean test_undefined;
0661 } GTestConfig;
0662 GLIB_VAR const GTestConfig * const g_test_config_vars;
0663
0664
0665 typedef enum {
0666 G_TEST_RUN_SUCCESS,
0667 G_TEST_RUN_SKIPPED,
0668 G_TEST_RUN_FAILURE,
0669 G_TEST_RUN_INCOMPLETE
0670 } GTestResult;
0671
0672 typedef enum {
0673 G_TEST_LOG_NONE,
0674 G_TEST_LOG_ERROR,
0675 G_TEST_LOG_START_BINARY,
0676 G_TEST_LOG_LIST_CASE,
0677 G_TEST_LOG_SKIP_CASE,
0678 G_TEST_LOG_START_CASE,
0679 G_TEST_LOG_STOP_CASE,
0680 G_TEST_LOG_MIN_RESULT,
0681 G_TEST_LOG_MAX_RESULT,
0682 G_TEST_LOG_MESSAGE,
0683 G_TEST_LOG_START_SUITE,
0684 G_TEST_LOG_STOP_SUITE
0685 } GTestLogType;
0686
0687 typedef struct {
0688 GTestLogType log_type;
0689 guint n_strings;
0690 gchar **strings;
0691 guint n_nums;
0692 long double *nums;
0693 } GTestLogMsg;
0694 typedef struct {
0695
0696 GString *data;
0697 GSList *msgs;
0698 } GTestLogBuffer;
0699
0700 GLIB_AVAILABLE_IN_ALL
0701 const char* g_test_log_type_name (GTestLogType log_type);
0702 GLIB_AVAILABLE_IN_ALL
0703 GTestLogBuffer* g_test_log_buffer_new (void);
0704 GLIB_AVAILABLE_IN_ALL
0705 void g_test_log_buffer_free (GTestLogBuffer *tbuffer);
0706 GLIB_AVAILABLE_IN_ALL
0707 void g_test_log_buffer_push (GTestLogBuffer *tbuffer,
0708 guint n_bytes,
0709 const guint8 *bytes);
0710 GLIB_AVAILABLE_IN_ALL
0711 GTestLogMsg* g_test_log_buffer_pop (GTestLogBuffer *tbuffer);
0712 GLIB_AVAILABLE_IN_ALL
0713 void g_test_log_msg_free (GTestLogMsg *tmsg);
0714
0715
0716
0717
0718
0719
0720
0721
0722
0723
0724
0725
0726
0727
0728 typedef gboolean (*GTestLogFatalFunc) (const gchar *log_domain,
0729 GLogLevelFlags log_level,
0730 const gchar *message,
0731 gpointer user_data);
0732 GLIB_AVAILABLE_IN_ALL
0733 void
0734 g_test_log_set_fatal_handler (GTestLogFatalFunc log_func,
0735 gpointer user_data);
0736
0737 GLIB_AVAILABLE_IN_2_34
0738 void g_test_expect_message (const gchar *log_domain,
0739 GLogLevelFlags log_level,
0740 const gchar *pattern);
0741 GLIB_AVAILABLE_IN_2_34
0742 void g_test_assert_expected_messages_internal (const char *domain,
0743 const char *file,
0744 int line,
0745 const char *func);
0746
0747 typedef enum
0748 {
0749 G_TEST_DIST,
0750 G_TEST_BUILT
0751 } GTestFileType;
0752
0753 GLIB_AVAILABLE_IN_2_38
0754 gchar * g_test_build_filename (GTestFileType file_type,
0755 const gchar *first_path,
0756 ...) G_GNUC_NULL_TERMINATED;
0757 GLIB_AVAILABLE_IN_2_38
0758 const gchar *g_test_get_dir (GTestFileType file_type);
0759 GLIB_AVAILABLE_IN_2_38
0760 const gchar *g_test_get_filename (GTestFileType file_type,
0761 const gchar *first_path,
0762 ...) G_GNUC_NULL_TERMINATED;
0763
0764 #define g_test_assert_expected_messages() g_test_assert_expected_messages_internal (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC)
0765
0766 G_END_DECLS
0767
0768 #endif