[Cogl] [PATCH] conform: explicitly check value of boolean env vars
Robert Bragg
robert at sixbynine.org
Fri Feb 15 09:27:19 PST 2013
From: Robert Bragg <robert at linux.intel.com>
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
---
tests/conform/test-utils.c | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c
index 653791e..7f78587 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -78,6 +78,36 @@ check_flags (TestFlags flags,
return TRUE;
}
+CoglBool
+is_boolean_env_set (const char *variable)
+{
+ char *val = getenv (variable);
+ CoglBool ret;
+
+ if (!val)
+ return FALSE;
+
+ val = g_ascii_strdown (val, -1);
+
+ if (strcmp (val, "1") == 0 ||
+ strcmp (val, "on") == 0 ||
+ strcmp (val, "true") == 0)
+ ret = TRUE;
+ else if (strcmp (val, "0") == 0 ||
+ strcmp (val, "off") == 0 ||
+ strcmp (val, "false") == 0)
+ ret = FALSE;
+ else
+ {
+ g_critical ("Spurious boolean environment variable value (%s=%s)",
+ variable, val);
+ ret = TRUE;
+ }
+
+ g_free (val);
+ return ret;
+}
+
void
test_utils_init (TestFlags requirement_flags,
TestFlags known_failure_flags)
@@ -99,7 +129,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"))
@@ -123,7 +154,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);
--
1.8.1.1
More information about the Cogl
mailing list