[glib] win32: suppress fatal error dialog box when running tests



commit e97a2f4195fb5bd8d7777651232dc10487a1ed92
Author: Dan Winship <danw gnome org>
Date:   Thu Nov 15 22:26:54 2012 -0500

    win32: suppress fatal error dialog box when running tests
    
    When running a test program (ie, if g_test_init() has been called),
    don't pop up a dialog box when a fatal error occurs. Just print the
    message to stderr and exit.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679683

 docs/reference/glib/glib-sections.txt |    1 +
 glib/gmessages.c                      |   14 +++++++++-----
 glib/gtestutils.c                     |   10 ++++++++++
 glib/gtestutils.h                     |    1 +
 4 files changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 546bc98..e4e9df4 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -2877,6 +2877,7 @@ g_compute_hmac_for_string
 g_test_minimized_result
 g_test_maximized_result
 g_test_init
+g_test_initialized
 g_test_quick
 g_test_slow
 g_test_thorough
diff --git a/glib/gmessages.c b/glib/gmessages.c
index e2be9ab..91d7a21 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -820,7 +820,8 @@ mklevel_prefix (gchar          level_prefix[STRING_BUFFER_SIZE],
     strcat (level_prefix, " **");
 
 #ifdef G_OS_WIN32
-  win32_keep_fatal_message = (log_level & G_LOG_FLAG_FATAL) != 0;
+  if ((log_level & G_LOG_FLAG_FATAL) != 0 && !g_test_initialized ())
+    win32_keep_fatal_message = TRUE;
 #endif
   return to_stdout ? 1 : 2;
 }
@@ -954,10 +955,13 @@ g_logv (const gchar   *log_domain,
 	  if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
             {
 #ifdef G_OS_WIN32
-	      gchar *locale_msg = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL);
-	      
-	      MessageBox (NULL, locale_msg, NULL,
-			  MB_ICONERROR|MB_SETFOREGROUND);
+              if (win32_keep_fatal_message)
+                {
+                  gchar *locale_msg = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL);
+
+                  MessageBox (NULL, locale_msg, NULL,
+                              MB_ICONERROR|MB_SETFOREGROUND);
+                }
 	      if (IsDebuggerPresent () && !(test_level & G_LOG_FLAG_RECURSION))
 		G_BREAKPOINT ();
 	      else
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index 5fba96f..c7b7249 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -106,6 +106,16 @@
  */
 
 /**
+ * g_test_initialized:
+ *
+ * Returns %TRUE if g_test_init() has been called.
+ *
+ * Returns: %TRUE if g_test_init() has been called.
+ *
+ * Since: 2.36
+ */
+
+/**
  * g_test_quick:
  *
  * Returns %TRUE if tests are run in quick mode.
diff --git a/glib/gtestutils.h b/glib/gtestutils.h
index 967fa63..3721519 100644
--- a/glib/gtestutils.h
+++ b/glib/gtestutils.h
@@ -92,6 +92,7 @@ void    g_test_init                     (int            *argc,
                                          char         ***argv,
                                          ...);
 /* 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)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]