X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Fgtestutils.h;h=2e27a2a64e03b993b5c6eeeb47a36c56590c8a3f;hb=2a53b4d0e2c98a14aedf31e38f0ad1fb2e8fe26f;hp=6636711dab8cc9c8fdfc3be23fd2d04760828c54;hpb=e3a29184d56b3a65664eb8859e61afbc804497c8;p=platform%2Fupstream%2Fglib.git
diff --git a/glib/gtestutils.h b/glib/gtestutils.h
index 6636711..2e27a2a 100644
--- a/glib/gtestutils.h
+++ b/glib/gtestutils.h
@@ -13,18 +13,16 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see .
*/
+#ifndef __G_TEST_UTILS_H__
+#define __G_TEST_UTILS_H__
+
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only can be included directly."
#endif
-#ifndef __G_TEST_UTILS_H__
-#define __G_TEST_UTILS_H__
-
#include
#include
#include
@@ -66,49 +64,75 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
#define g_assert_error(err, dom, c) do { if (!err || (err)->domain != dom || (err)->code != c) \
g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#err, err, dom, c); } while (0)
+#define g_assert_true(expr) do { if G_LIKELY (expr) ; else \
+ g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
+ "'" #expr "' should be TRUE"); \
+ } while (0)
+#define g_assert_false(expr) do { if G_LIKELY (!(expr)) ; else \
+ g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
+ "'" #expr "' should be FALSE"); \
+ } while (0)
+#define g_assert_null(expr) do { if G_LIKELY ((expr) == NULL) ; else \
+ g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
+ "'" #expr "' should be NULL"); \
+ } while (0)
+#define g_assert_nonnull(expr) do { if G_LIKELY ((expr) != NULL) ; else \
+ g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
+ "'" #expr "' should not be NULL"); \
+ } while (0)
#ifdef G_DISABLE_ASSERT
#define g_assert_not_reached() do { (void) 0; } while (0)
#define g_assert(expr) do { (void) 0; } while (0)
+#define g_assert_se(expr) ((void) (expr))
#else /* !G_DISABLE_ASSERT */
-#define g_assert_not_reached() do { g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0)
+#define g_assert_not_reached() do { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0)
#define g_assert(expr) do { if G_LIKELY (expr) ; else \
g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
- #expr); } while (0)
+ #expr); \
+ } while (0)
+#define g_assert_se(expr) g_assert((expr))
#endif /* !G_DISABLE_ASSERT */
+GLIB_AVAILABLE_IN_ALL
int g_strcmp0 (const char *str1,
const char *str2);
/* report performance results */
+GLIB_AVAILABLE_IN_ALL
void g_test_minimized_result (double minimized_quantity,
const char *format,
...) G_GNUC_PRINTF (2, 3);
+GLIB_AVAILABLE_IN_ALL
void g_test_maximized_result (double maximized_quantity,
const char *format,
...) G_GNUC_PRINTF (2, 3);
/* initialize testing framework */
+GLIB_AVAILABLE_IN_ALL
void g_test_init (int *argc,
char ***argv,
- ...);
+ ...) G_GNUC_NULL_TERMINATED;
/* query testing framework config */
-#define g_test_initialized() (g_test_config_vars->test_initialized)
-#define g_test_quick() (g_test_config_vars->test_quick)
-#define g_test_slow() (!g_test_config_vars->test_quick)
-#define g_test_thorough() (!g_test_config_vars->test_quick)
-#define g_test_perf() (g_test_config_vars->test_perf)
-#define g_test_verbose() (g_test_config_vars->test_verbose)
-#define g_test_quiet() (g_test_config_vars->test_quiet)
-#define g_test_undefined() (g_test_config_vars->test_undefined)
-GLIB_AVAILABLE_IN_2_36
+#define g_test_initialized() (g_test_config_vars->test_initialized)
+#define g_test_quick() (g_test_config_vars->test_quick)
+#define g_test_slow() (!g_test_config_vars->test_quick)
+#define g_test_thorough() (!g_test_config_vars->test_quick)
+#define g_test_perf() (g_test_config_vars->test_perf)
+#define g_test_verbose() (g_test_config_vars->test_verbose)
+#define g_test_quiet() (g_test_config_vars->test_quiet)
+#define g_test_undefined() (g_test_config_vars->test_undefined)
+GLIB_AVAILABLE_IN_2_38
gboolean g_test_subprocess (void);
/* run all tests under toplevel suite (path: /) */
+GLIB_AVAILABLE_IN_ALL
int g_test_run (void);
/* hook up a test functions under test path */
+GLIB_AVAILABLE_IN_ALL
void g_test_add_func (const char *testpath,
GTestFunc test_func);
+GLIB_AVAILABLE_IN_ALL
void g_test_add_data_func (const char *testpath,
gconstpointer test_data,
GTestDataFunc test_func);
@@ -120,7 +144,16 @@ void g_test_add_data_func_full (const char *testpath,
GDestroyNotify data_free_func);
/* tell about failure */
+GLIB_AVAILABLE_IN_2_30
void g_test_fail (void);
+GLIB_AVAILABLE_IN_2_38
+void g_test_incomplete (const gchar *msg);
+GLIB_AVAILABLE_IN_2_38
+void g_test_skip (const gchar *msg);
+GLIB_AVAILABLE_IN_2_38
+gboolean g_test_failed (void);
+GLIB_AVAILABLE_IN_2_38
+void g_test_set_nonfatal_assertions (void);
/* hook up a test with fixture under test path */
#define g_test_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
@@ -135,46 +168,54 @@ void g_test_fail (void);
(testpath, sizeof (Fixture), tdata, fsetup, ftest, fteardown); \
} G_STMT_END
-GLIB_AVAILABLE_IN_2_36
-gboolean g_test_case_exists (const char *test_path);
-
/* add test messages to the test report */
+GLIB_AVAILABLE_IN_ALL
void g_test_message (const char *format,
...) G_GNUC_PRINTF (1, 2);
+GLIB_AVAILABLE_IN_ALL
void g_test_bug_base (const char *uri_pattern);
+GLIB_AVAILABLE_IN_ALL
void g_test_bug (const char *bug_uri_snippet);
/* measure test timings */
+GLIB_AVAILABLE_IN_ALL
void g_test_timer_start (void);
+GLIB_AVAILABLE_IN_ALL
double g_test_timer_elapsed (void); /* elapsed seconds */
+GLIB_AVAILABLE_IN_ALL
double g_test_timer_last (void); /* repeat last elapsed() result */
/* automatically g_free or g_object_unref upon teardown */
+GLIB_AVAILABLE_IN_ALL
void g_test_queue_free (gpointer gfree_pointer);
+GLIB_AVAILABLE_IN_ALL
void g_test_queue_destroy (GDestroyNotify destroy_func,
gpointer destroy_data);
#define g_test_queue_unref(gobject) g_test_queue_destroy (g_object_unref, gobject)
-/* test traps are guards used around forked tests */
typedef enum {
G_TEST_TRAP_SILENCE_STDOUT = 1 << 7,
G_TEST_TRAP_SILENCE_STDERR = 1 << 8,
G_TEST_TRAP_INHERIT_STDIN = 1 << 9
} GTestTrapFlags;
-GLIB_DEPRECATED_IN_2_36_FOR (g_test_trap_subprocess)
+GLIB_DEPRECATED_IN_2_38_FOR (g_test_trap_subprocess)
gboolean g_test_trap_fork (guint64 usec_timeout,
GTestTrapFlags test_trap_flags);
-GLIB_AVAILABLE_IN_2_36
-void g_test_trap_subprocess (const char *test_path,
- guint64 usec_timeout,
- GTestTrapFlags test_trap_flags);
+typedef enum {
+ G_TEST_SUBPROCESS_INHERIT_STDIN = 1 << 0,
+ G_TEST_SUBPROCESS_INHERIT_STDOUT = 1 << 1,
+ G_TEST_SUBPROCESS_INHERIT_STDERR = 1 << 2
+} GTestSubprocessFlags;
-#define g_test_trap_subprocess(test_path, usec_timeout, test_trap_flags) \
- g_assert (g_test_case_exists (test_path)); \
- g_test_trap_subprocess (test_path, usec_timeout, test_trap_flags);
+GLIB_AVAILABLE_IN_2_38
+void g_test_trap_subprocess (const char *test_path,
+ guint64 usec_timeout,
+ GTestSubprocessFlags test_flags);
+GLIB_AVAILABLE_IN_ALL
gboolean g_test_trap_has_passed (void);
+GLIB_AVAILABLE_IN_ALL
gboolean g_test_trap_reached_timeout (void);
#define g_test_trap_assert_passed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 0, 0)
#define g_test_trap_assert_failed() g_test_trap_assertions (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, 1, 0)
@@ -185,45 +226,59 @@ gboolean g_test_trap_reached_timeout (void);
/* provide seed-able random numbers for tests */
#define g_test_rand_bit() (0 != (g_test_rand_int() & (1 << 15)))
+GLIB_AVAILABLE_IN_ALL
gint32 g_test_rand_int (void);
+GLIB_AVAILABLE_IN_ALL
gint32 g_test_rand_int_range (gint32 begin,
gint32 end);
+GLIB_AVAILABLE_IN_ALL
double g_test_rand_double (void);
+GLIB_AVAILABLE_IN_ALL
double g_test_rand_double_range (double range_start,
double range_end);
/* semi-internal API */
+GLIB_AVAILABLE_IN_ALL
GTestCase* g_test_create_case (const char *test_name,
gsize data_size,
gconstpointer test_data,
GTestFixtureFunc data_setup,
GTestFixtureFunc data_test,
GTestFixtureFunc data_teardown);
+GLIB_AVAILABLE_IN_ALL
GTestSuite* g_test_create_suite (const char *suite_name);
+GLIB_AVAILABLE_IN_ALL
GTestSuite* g_test_get_root (void);
+GLIB_AVAILABLE_IN_ALL
void g_test_suite_add (GTestSuite *suite,
GTestCase *test_case);
+GLIB_AVAILABLE_IN_ALL
void g_test_suite_add_suite (GTestSuite *suite,
GTestSuite *nestedsuite);
+GLIB_AVAILABLE_IN_ALL
int g_test_run_suite (GTestSuite *suite);
/* internal ABI */
+GLIB_AVAILABLE_IN_ALL
void g_test_trap_assertions (const char *domain,
const char *file,
int line,
const char *func,
guint64 assertion_flags, /* 0-pass, 1-fail, 2-outpattern, 4-errpattern */
const char *pattern);
+GLIB_AVAILABLE_IN_ALL
void g_assertion_message (const char *domain,
const char *file,
int line,
const char *func,
- const char *message) G_GNUC_NORETURN;
+ const char *message);
+GLIB_AVAILABLE_IN_ALL
void g_assertion_message_expr (const char *domain,
const char *file,
int line,
const char *func,
const char *expr) G_GNUC_NORETURN;
+GLIB_AVAILABLE_IN_ALL
void g_assertion_message_cmpstr (const char *domain,
const char *file,
int line,
@@ -231,7 +286,8 @@ void g_assertion_message_cmpstr (const char *domain,
const char *expr,
const char *arg1,
const char *cmp,
- const char *arg2) G_GNUC_NORETURN;
+ const char *arg2);
+GLIB_AVAILABLE_IN_ALL
void g_assertion_message_cmpnum (const char *domain,
const char *file,
int line,
@@ -240,7 +296,8 @@ void g_assertion_message_cmpnum (const char *domain,
long double arg1,
const char *cmp,
long double arg2,
- char numtype) G_GNUC_NORETURN;
+ char numtype);
+GLIB_AVAILABLE_IN_ALL
void g_assertion_message_error (const char *domain,
const char *file,
int line,
@@ -248,7 +305,8 @@ void g_assertion_message_error (const char *domain,
const char *expr,
const GError *error,
GQuark error_domain,
- int error_code) G_GNUC_NORETURN;
+ int error_code);
+GLIB_AVAILABLE_IN_ALL
void g_test_add_vtable (const char *testpath,
gsize data_size,
gconstpointer test_data,
@@ -276,7 +334,9 @@ typedef enum {
G_TEST_LOG_STOP_CASE, /* d:status d:nforks d:elapsed */
G_TEST_LOG_MIN_RESULT, /* s:blurb d:result */
G_TEST_LOG_MAX_RESULT, /* s:blurb d:result */
- G_TEST_LOG_MESSAGE /* s:blurb */
+ G_TEST_LOG_MESSAGE, /* s:blurb */
+ G_TEST_LOG_START_SUITE,
+ G_TEST_LOG_STOP_SUITE
} GTestLogType;
typedef struct {
@@ -292,13 +352,19 @@ typedef struct {
GSList *msgs;
} GTestLogBuffer;
+GLIB_AVAILABLE_IN_ALL
const char* g_test_log_type_name (GTestLogType log_type);
+GLIB_AVAILABLE_IN_ALL
GTestLogBuffer* g_test_log_buffer_new (void);
+GLIB_AVAILABLE_IN_ALL
void g_test_log_buffer_free (GTestLogBuffer *tbuffer);
+GLIB_AVAILABLE_IN_ALL
void g_test_log_buffer_push (GTestLogBuffer *tbuffer,
guint n_bytes,
const guint8 *bytes);
+GLIB_AVAILABLE_IN_ALL
GTestLogMsg* g_test_log_buffer_pop (GTestLogBuffer *tbuffer);
+GLIB_AVAILABLE_IN_ALL
void g_test_log_msg_free (GTestLogMsg *tmsg);
/**
@@ -310,7 +376,7 @@ void g_test_log_msg_free (GTestLogMsg *tmsg);
*
* Specifies the prototype of fatal log handler functions.
*
- * Return value: %TRUE if the program should abort, %FALSE otherwise
+ * Returns: %TRUE if the program should abort, %FALSE otherwise
*
* Since: 2.22
*/
@@ -318,18 +384,38 @@ typedef gboolean (*GTestLogFatalFunc) (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data);
+GLIB_AVAILABLE_IN_ALL
void
g_test_log_set_fatal_handler (GTestLogFatalFunc log_func,
gpointer user_data);
+GLIB_AVAILABLE_IN_2_34
void g_test_expect_message (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *pattern);
+GLIB_AVAILABLE_IN_2_34
void g_test_assert_expected_messages_internal (const char *domain,
const char *file,
int line,
const char *func);
+typedef enum
+{
+ G_TEST_DIST,
+ G_TEST_BUILT
+} GTestFileType;
+
+GLIB_AVAILABLE_IN_2_38
+gchar * g_test_build_filename (GTestFileType file_type,
+ const gchar *first_path,
+ ...) G_GNUC_NULL_TERMINATED;
+GLIB_AVAILABLE_IN_2_38
+const gchar *g_test_get_dir (GTestFileType file_type);
+GLIB_AVAILABLE_IN_2_38
+const gchar *g_test_get_filename (GTestFileType file_type,
+ const gchar *first_path,
+ ...) G_GNUC_NULL_TERMINATED;
+
#define g_test_assert_expected_messages() g_test_assert_expected_messages_internal (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC)
G_END_DECLS