[cogl/cogl-1.14] conform: explicitly check value of boolean env vars



commit 255b815f76c4281311b457e33c8b3bc6f4ff1534
Author: Robert Bragg <robert linux intel com>
Date:   Fri Feb 15 17:21:04 2013 +0000

    conform: explicitly check value of boolean env vars
    
    For the boolean environment variables that affect the running of the
    conformance tests we now explicitly check the value of those variables
    so that "0", "off" and "false" (upper or lower case) will be considered
    as FALSE instead of just interpreting set as TRUE and unset as FALSE. If
    the value is set to something entirely spurious then we abort with a
    warning message. Thanks to Artie Eoff for suggesting this change.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693894
    
    Reviewed-by: Neil Roberts <neil linux intel com>
    
    (cherry picked from commit 25a8cf3607a482ca390eb9841295d1b365cbe53b)

 tests/conform/test-utils.c |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c
index 99d6926..aea359d 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -79,6 +79,33 @@ check_flags (TestFlags flags,
   return TRUE;
 }
 
+CoglBool
+is_boolean_env_set (const char *variable)
+{
+  char *val = getenv (variable);
+  CoglBool ret;
+
+  if (!val)
+    return FALSE;
+
+  if (g_ascii_strcasecmp (val, "1") == 0 ||
+      g_ascii_strcasecmp (val, "on") == 0 ||
+      g_ascii_strcasecmp (val, "true") == 0)
+    ret = TRUE;
+  else if (g_ascii_strcasecmp (val, "0") == 0 ||
+           g_ascii_strcasecmp (val, "off") == 0 ||
+           g_ascii_strcasecmp (val, "false") == 0)
+    ret = FALSE;
+  else
+    {
+      g_critical ("Spurious boolean environment variable value (%s=%s)",
+                  variable, val);
+      ret = TRUE;
+    }
+
+  return ret;
+}
+
 void
 test_utils_init (TestFlags requirement_flags,
                  TestFlags known_failure_flags)
@@ -100,7 +127,8 @@ test_utils_init (TestFlags requirement_flags,
                 "$ make test-report");
   counter++;
 
-  if (g_getenv ("COGL_TEST_VERBOSE") || g_getenv ("V"))
+  if (is_boolean_env_set ("COGL_TEST_VERBOSE") ||
+      is_boolean_env_set ("V"))
     cogl_test_is_verbose = TRUE;
 
   if (g_getenv ("G_DEBUG"))
@@ -124,7 +152,7 @@ test_utils_init (TestFlags requirement_flags,
   missing_requirement = !check_flags (requirement_flags, renderer);
   known_failure = !check_flags (known_failure_flags, renderer);
 
-  if (getenv  ("COGL_TEST_ONSCREEN"))
+  if (is_boolean_env_set ("COGL_TEST_ONSCREEN"))
     {
       onscreen = cogl_onscreen_new (test_ctx, 640, 480);
       test_fb = COGL_FRAMEBUFFER (onscreen);



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