File indexing completed on 2024-11-15 09:42:03
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
0519 GLIB_AVAILABLE_IN_ALL
0520 gboolean g_test_trap_has_passed (void);
0521 GLIB_AVAILABLE_IN_ALL
0522 gboolean g_test_trap_reached_timeout (void);
0523 #define g_test_trap_assert_passed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 0, 0)
0524 #define g_test_trap_assert_failed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 1, 0)
0525 #define g_test_trap_assert_stdout(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 2, soutpattern)
0526 #define g_test_trap_assert_stdout_unmatched(soutpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 3, soutpattern)
0527 #define g_test_trap_assert_stderr(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 4, serrpattern)
0528 #define g_test_trap_assert_stderr_unmatched(serrpattern) g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 5, serrpattern)
0529
0530
0531 #define g_test_rand_bit() (0 != (g_test_rand_int() & (1 << 15)))
0532 GLIB_AVAILABLE_IN_ALL
0533 gint32 g_test_rand_int (void);
0534 GLIB_AVAILABLE_IN_ALL
0535 gint32 g_test_rand_int_range (gint32 begin,
0536 gint32 end);
0537 GLIB_AVAILABLE_IN_ALL
0538 double g_test_rand_double (void);
0539 GLIB_AVAILABLE_IN_ALL
0540 double g_test_rand_double_range (double range_start,
0541 double range_end);
0542
0543
0544
0545
0546
0547
0548 GLIB_AVAILABLE_IN_ALL
0549 GTestCase* g_test_create_case (const char *test_name,
0550 gsize data_size,
0551 gconstpointer test_data,
0552 GTestFixtureFunc data_setup,
0553 GTestFixtureFunc data_test,
0554 GTestFixtureFunc data_teardown);
0555 GLIB_AVAILABLE_IN_ALL
0556 GTestSuite* g_test_create_suite (const char *suite_name);
0557 GLIB_AVAILABLE_IN_ALL
0558 GTestSuite* g_test_get_root (void);
0559 GLIB_AVAILABLE_IN_ALL
0560 void g_test_suite_add (GTestSuite *suite,
0561 GTestCase *test_case);
0562 GLIB_AVAILABLE_IN_ALL
0563 void g_test_suite_add_suite (GTestSuite *suite,
0564 GTestSuite *nestedsuite);
0565 GLIB_AVAILABLE_IN_ALL
0566 int g_test_run_suite (GTestSuite *suite);
0567
0568 GLIB_AVAILABLE_IN_2_70
0569 void g_test_case_free (GTestCase *test_case);
0570
0571 GLIB_AVAILABLE_IN_2_70
0572 void g_test_suite_free (GTestSuite *suite);
0573
0574 GLIB_AVAILABLE_IN_ALL
0575 void g_test_trap_assertions (const char *domain,
0576 const char *file,
0577 int line,
0578 const char *func,
0579 guint64 assertion_flags,
0580 const char *pattern);
0581 GLIB_AVAILABLE_IN_ALL
0582 void g_assertion_message (const char *domain,
0583 const char *file,
0584 int line,
0585 const char *func,
0586 const char *message) G_ANALYZER_NORETURN;
0587 G_NORETURN
0588 GLIB_AVAILABLE_IN_ALL
0589 void g_assertion_message_expr (const char *domain,
0590 const char *file,
0591 int line,
0592 const char *func,
0593 const char *expr);
0594 GLIB_AVAILABLE_IN_ALL
0595 void g_assertion_message_cmpstr (const char *domain,
0596 const char *file,
0597 int line,
0598 const char *func,
0599 const char *expr,
0600 const char *arg1,
0601 const char *cmp,
0602 const char *arg2) G_ANALYZER_NORETURN;
0603
0604 GLIB_AVAILABLE_IN_2_68
0605 void g_assertion_message_cmpstrv (const char *domain,
0606 const char *file,
0607 int line,
0608 const char *func,
0609 const char *expr,
0610 const char * const *arg1,
0611 const char * const *arg2,
0612 gsize first_wrong_idx) G_ANALYZER_NORETURN;
0613 GLIB_AVAILABLE_IN_2_78
0614 void g_assertion_message_cmpint (const char *domain,
0615 const char *file,
0616 int line,
0617 const char *func,
0618 const char *expr,
0619 guint64 arg1,
0620 const char *cmp,
0621 guint64 arg2,
0622 char numtype) G_ANALYZER_NORETURN;
0623 GLIB_AVAILABLE_IN_ALL
0624 void g_assertion_message_cmpnum (const char *domain,
0625 const char *file,
0626 int line,
0627 const char *func,
0628 const char *expr,
0629 long double arg1,
0630 const char *cmp,
0631 long double arg2,
0632 char numtype) G_ANALYZER_NORETURN;
0633 GLIB_AVAILABLE_IN_ALL
0634 void g_assertion_message_error (const char *domain,
0635 const char *file,
0636 int line,
0637 const char *func,
0638 const char *expr,
0639 const GError *error,
0640 GQuark error_domain,
0641 int error_code) G_ANALYZER_NORETURN;
0642 GLIB_AVAILABLE_IN_ALL
0643 void g_test_add_vtable (const char *testpath,
0644 gsize data_size,
0645 gconstpointer test_data,
0646 GTestFixtureFunc data_setup,
0647 GTestFixtureFunc data_test,
0648 GTestFixtureFunc data_teardown);
0649 typedef struct {
0650 gboolean test_initialized;
0651 gboolean test_quick;
0652 gboolean test_perf;
0653 gboolean test_verbose;
0654 gboolean test_quiet;
0655 gboolean test_undefined;
0656 } GTestConfig;
0657 GLIB_VAR const GTestConfig * const g_test_config_vars;
0658
0659
0660 typedef enum {
0661 G_TEST_RUN_SUCCESS,
0662 G_TEST_RUN_SKIPPED,
0663 G_TEST_RUN_FAILURE,
0664 G_TEST_RUN_INCOMPLETE
0665 } GTestResult;
0666
0667 typedef enum {
0668 G_TEST_LOG_NONE,
0669 G_TEST_LOG_ERROR,
0670 G_TEST_LOG_START_BINARY,
0671 G_TEST_LOG_LIST_CASE,
0672 G_TEST_LOG_SKIP_CASE,
0673 G_TEST_LOG_START_CASE,
0674 G_TEST_LOG_STOP_CASE,
0675 G_TEST_LOG_MIN_RESULT,
0676 G_TEST_LOG_MAX_RESULT,
0677 G_TEST_LOG_MESSAGE,
0678 G_TEST_LOG_START_SUITE,
0679 G_TEST_LOG_STOP_SUITE
0680 } GTestLogType;
0681
0682 typedef struct {
0683 GTestLogType log_type;
0684 guint n_strings;
0685 gchar **strings;
0686 guint n_nums;
0687 long double *nums;
0688 } GTestLogMsg;
0689 typedef struct {
0690
0691 GString *data;
0692 GSList *msgs;
0693 } GTestLogBuffer;
0694
0695 GLIB_AVAILABLE_IN_ALL
0696 const char* g_test_log_type_name (GTestLogType log_type);
0697 GLIB_AVAILABLE_IN_ALL
0698 GTestLogBuffer* g_test_log_buffer_new (void);
0699 GLIB_AVAILABLE_IN_ALL
0700 void g_test_log_buffer_free (GTestLogBuffer *tbuffer);
0701 GLIB_AVAILABLE_IN_ALL
0702 void g_test_log_buffer_push (GTestLogBuffer *tbuffer,
0703 guint n_bytes,
0704 const guint8 *bytes);
0705 GLIB_AVAILABLE_IN_ALL
0706 GTestLogMsg* g_test_log_buffer_pop (GTestLogBuffer *tbuffer);
0707 GLIB_AVAILABLE_IN_ALL
0708 void g_test_log_msg_free (GTestLogMsg *tmsg);
0709
0710
0711
0712
0713
0714
0715
0716
0717
0718
0719
0720
0721
0722
0723 typedef gboolean (*GTestLogFatalFunc) (const gchar *log_domain,
0724 GLogLevelFlags log_level,
0725 const gchar *message,
0726 gpointer user_data);
0727 GLIB_AVAILABLE_IN_ALL
0728 void
0729 g_test_log_set_fatal_handler (GTestLogFatalFunc log_func,
0730 gpointer user_data);
0731
0732 GLIB_AVAILABLE_IN_2_34
0733 void g_test_expect_message (const gchar *log_domain,
0734 GLogLevelFlags log_level,
0735 const gchar *pattern);
0736 GLIB_AVAILABLE_IN_2_34
0737 void g_test_assert_expected_messages_internal (const char *domain,
0738 const char *file,
0739 int line,
0740 const char *func);
0741
0742 typedef enum
0743 {
0744 G_TEST_DIST,
0745 G_TEST_BUILT
0746 } GTestFileType;
0747
0748 GLIB_AVAILABLE_IN_2_38
0749 gchar * g_test_build_filename (GTestFileType file_type,
0750 const gchar *first_path,
0751 ...) G_GNUC_NULL_TERMINATED;
0752 GLIB_AVAILABLE_IN_2_38
0753 const gchar *g_test_get_dir (GTestFileType file_type);
0754 GLIB_AVAILABLE_IN_2_38
0755 const gchar *g_test_get_filename (GTestFileType file_type,
0756 const gchar *first_path,
0757 ...) G_GNUC_NULL_TERMINATED;
0758
0759 #define g_test_assert_expected_messages() g_test_assert_expected_messages_internal (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC)
0760
0761 G_END_DECLS
0762
0763 #endif