[gnome-color-manager] Add some self tests to GcmUtils



commit 26bd48f986856ba4b8dc237dc9db85828a088455
Author: Richard Hughes <richard hughsie com>
Date:   Fri Nov 27 14:20:28 2009 +0000

    Add some self tests to GcmUtils

 src/Makefile.am     |    1 +
 src/gcm-self-test.c |    2 +
 src/gcm-utils.c     |   79 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2c03445..ea6bd86 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -163,6 +163,7 @@ gcm_self_test_SOURCES =					\
 	gcm-self-test.c					\
 	gcm-edid.c					\
 	gcm-tables.c					\
+	gcm-utils.c					\
 	egg-test.h					\
 	egg-test.c					\
 	$(NULL)
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index b474067..0706b86 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -26,6 +26,7 @@
 /* prototypes */
 void gcm_edid_test (EggTest *test);
 void gcm_tables_test (EggTest *test);
+void gcm_utils_test (EggTest *test);
 
 int
 main (int argc, char **argv)
@@ -41,6 +42,7 @@ main (int argc, char **argv)
 	/* components */
 	gcm_edid_test (test);
 	gcm_tables_test (test);
+	gcm_utils_test (test);
 
 	return (egg_test_finish (test));
 }
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 48888d5..81e94d1 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -587,9 +587,88 @@ gcm_utils_get_default_config_location (void)
 {
 	gchar *filename;
 
+#ifdef EGG_TEST
+	filename = g_strdup ("/tmp/config.dat");
+#else
 	/* create default path */
 	filename = g_build_filename (g_get_user_config_dir (), "gnome-color-manager", "config.dat", NULL);
+#endif
 
 	return filename;
 }
 
+/***************************************************************************
+ ***                          MAKE CHECK TESTS                           ***
+ ***************************************************************************/
+#ifdef EGG_TEST
+#include "egg-test.h"
+
+void
+gcm_utils_test (EggTest *test)
+{
+	gboolean ret;
+	GError *error = NULL;
+	GPtrArray *array;
+	gchar *filename;
+
+	if (!egg_test_start (test, "GcmUtils"))
+		return;
+
+	/************************************************************/
+	egg_test_title (test, "get profile filenames");
+	array = gcm_utils_get_profile_filenames ();
+	egg_test_assert (test, array->len > 1);
+	g_ptr_array_unref (array);
+
+	/************************************************************/
+	egg_test_title (test, "get filename of data file");
+	filename = gcm_utils_get_profile_destination ("dave.icc");
+	if (g_str_has_suffix (filename, "/.color/icc/dave.icc"))
+		egg_test_success (test, NULL);
+	else
+		egg_test_failed (test, "failed to get filename: %s", filename);
+	g_free (filename);
+
+	/************************************************************/
+	egg_test_title (test, "detect LVDS panels");
+	ret = gcm_utils_output_is_lcd_internal ("LVDS1");
+	egg_test_assert (test, ret);
+
+	/************************************************************/
+	egg_test_title (test, "detect external panels");
+	ret = gcm_utils_output_is_lcd_internal ("DVI1");
+	egg_test_assert (test, !ret);
+
+	/************************************************************/
+	egg_test_title (test, "detect LCD panels");
+	ret = gcm_utils_output_is_lcd ("LVDS1");
+	egg_test_assert (test, ret);
+
+	/************************************************************/
+	egg_test_title (test, "detect LCD panels (2)");
+	ret = gcm_utils_output_is_lcd ("DVI1");
+	egg_test_assert (test, ret);
+
+	/************************************************************/
+	egg_test_title (test, "Make sensible filename");
+	filename = g_strdup ("Hello\n\rWorld!");
+	gcm_utils_alphanum_lcase (filename);
+	if (g_strcmp0 (filename, "hello__world_") == 0)
+		egg_test_success (test, NULL);
+	else
+		egg_test_failed (test, "failed to get filename: %s", filename);
+	g_free (filename);
+
+	/************************************************************/
+	egg_test_title (test, "get default config location (when in make check)");
+	filename = gcm_utils_get_default_config_location ();
+	if (g_strcmp0 (filename, "/tmp/config.dat") == 0)
+		egg_test_success (test, NULL);
+	else
+		egg_test_failed (test, "failed to get correct config location: %s", filename);
+	g_free (filename);
+
+	egg_test_end (test);
+}
+#endif
+



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