don't #include <glib.h> from other public headers
[platform/upstream/glib.git] / glib / gtestutils.h
index 8646a89..18f1ede 100644 (file)
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+
+#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
+#error "Only <glib.h> can be included directly."
+#endif
+
 #ifndef __G_TEST_UTILS_H__
 #define __G_TEST_UTILS_H__
 
-#include <glib.h>
+#include <glib/gmessages.h>
+#include <glib/gstring.h>
+#include <glib/gtypes.h>
+#include <glib/gerror.h>
+#include <glib/gslist.h>
 
 G_BEGIN_DECLS
 
@@ -48,6 +57,12 @@ typedef struct GTestSuite GTestSuite;
                                              if (__n1 cmp __n2) ; else \
                                                g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
                                                  #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'f'); } while (0)
+#define g_assert_no_error(err)          do { if (err) \
+                                               g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
+                                                 #err, err, 0, 0); } while (0)
+#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)
 #ifdef G_DISABLE_ASSERT
 #define g_assert_not_reached()          do { (void) 0; } while (0)
 #define g_assert(expr)                  do { (void) 0; } while (0)
@@ -90,14 +105,17 @@ void    g_test_add_data_func            (const char     *testpath,
                                          void          (*test_func) (gconstpointer));
 /* hook up a test with fixture under test path */
 #define g_test_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
-                                        ((void (*) (const char*,       \
+                                       G_STMT_START {                  \
+                                         void (*add_vtable) (const char*,       \
                                                     gsize,             \
                                                     gconstpointer,     \
                                                     void (*) (Fixture*, gconstpointer),   \
                                                     void (*) (Fixture*, gconstpointer),   \
-                                                    void (*) (Fixture*, gconstpointer)))  \
-                                         (void*) g_test_add_vtable) \
-                                          (testpath, sizeof (Fixture), tdata, fsetup, ftest, fteardown)
+                                                    void (*) (Fixture*, gconstpointer)) =  (void (*) (const gchar *, gsize, gconstpointer, void (*) (Fixture*, gconstpointer), void (*) (Fixture*, gconstpointer), void (*) (Fixture*, gconstpointer))) g_test_add_vtable; \
+                                         add_vtable \
+                                          (testpath, sizeof (Fixture), tdata, fsetup, ftest, fteardown); \
+                                       } G_STMT_END
+
 /* add test messages to the test report */
 void    g_test_message                  (const char *format,
                                          ...) G_GNUC_PRINTF (1, 2);
@@ -166,12 +184,12 @@ void    g_assertion_message             (const char     *domain,
                                          const char     *file,
                                          int             line,
                                          const char     *func,
-                                         const char     *message);
+                                         const char     *message) G_GNUC_NORETURN;
 void    g_assertion_message_expr        (const char     *domain,
                                          const char     *file,
                                          int             line,
                                          const char     *func,
-                                         const char     *expr);
+                                         const char     *expr) G_GNUC_NORETURN;
 void    g_assertion_message_cmpstr      (const char     *domain,
                                          const char     *file,
                                          int             line,
@@ -179,7 +197,7 @@ void    g_assertion_message_cmpstr      (const char     *domain,
                                          const char     *expr,
                                          const char     *arg1,
                                          const char     *cmp,
-                                         const char     *arg2);
+                                         const char     *arg2) G_GNUC_NORETURN;
 void    g_assertion_message_cmpnum      (const char     *domain,
                                          const char     *file,
                                          int             line,
@@ -188,7 +206,15 @@ void    g_assertion_message_cmpnum      (const char     *domain,
                                          long double     arg1,
                                          const char     *cmp,
                                          long double     arg2,
-                                         char            numtype);
+                                         char            numtype) G_GNUC_NORETURN;
+void    g_assertion_message_error       (const char     *domain,
+                                         const char     *file,
+                                         int             line,
+                                         const char     *func,
+                                         const char     *expr,
+                                         GError         *error,
+                                         GQuark          error_domain,
+                                         int             error_code) G_GNUC_NORETURN;
 void    g_test_add_vtable               (const char     *testpath,
                                          gsize           data_size,
                                          gconstpointer   test_data,
@@ -240,6 +266,27 @@ void            g_test_log_buffer_push  (GTestLogBuffer *tbuffer,
 GTestLogMsg*    g_test_log_buffer_pop   (GTestLogBuffer *tbuffer);
 void            g_test_log_msg_free     (GTestLogMsg    *tmsg);
 
+/**
+ * GTestLogFatalFunc:
+ * @log_domain: the log domain of the message
+ * @log_level: the log level of the message (including the fatal and recursion flags)
+ * @message: the message to process
+ * @user_data: user data, set in g_test_log_set_fatal_handler()
+ *
+ * Specifies the prototype of fatal log handler functions.
+ *
+ * Return value: %TRUE if the program should abort, %FALSE otherwise
+ *
+ * Since: 2.22
+ */
+typedef gboolean        (*GTestLogFatalFunc)    (const gchar    *log_domain,
+                                                 GLogLevelFlags  log_level,
+                                                 const gchar    *message,
+                                                 gpointer        user_data);
+void
+g_test_log_set_fatal_handler            (GTestLogFatalFunc log_func,
+                                         gpointer          user_data);
+
 G_END_DECLS
 
 #endif /* __G_TEST_UTILS_H__ */