[gnome-color-manager] Add self check code to GcmProfile



commit a8ca1186b2ac8fca5488b838dc1b9b7cb5b40343
Author: Richard Hughes <richard hughsie com>
Date:   Fri Nov 27 15:50:51 2009 +0000

    Add self check code to GcmProfile

 data/tests/AdobeGammaTest.icm |    1 +
 data/tests/bluish.icc         |    1 +
 src/Makefile.am               |    1 +
 src/gcm-profile.c             |  128 +++++++++++++++++++++++++++++++++++++++++
 src/gcm-self-test.c           |    2 +
 5 files changed, 133 insertions(+), 0 deletions(-)
---
diff --git a/data/tests/AdobeGammaTest.icm b/data/tests/AdobeGammaTest.icm
new file mode 120000
index 0000000..910f2ae
--- /dev/null
+++ b/data/tests/AdobeGammaTest.icm
@@ -0,0 +1 @@
+../profiles/AdobeGammaTest.icm
\ No newline at end of file
diff --git a/data/tests/bluish.icc b/data/tests/bluish.icc
new file mode 120000
index 0000000..22ee77b
--- /dev/null
+++ b/data/tests/bluish.icc
@@ -0,0 +1 @@
+../profiles/bluish.icc
\ No newline at end of file
diff --git a/src/Makefile.am b/src/Makefile.am
index d77e5a4..be67de5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -165,6 +165,7 @@ gcm_self_test_SOURCES =					\
 	gcm-tables.c					\
 	gcm-utils.c					\
 	gcm-device.c					\
+	gcm-profile.c					\
 	egg-test.h					\
 	egg-test.c					\
 	$(NULL)
diff --git a/src/gcm-profile.c b/src/gcm-profile.c
index 2a71d40..25d658f 100644
--- a/src/gcm-profile.c
+++ b/src/gcm-profile.c
@@ -1040,3 +1040,131 @@ gcm_profile_new (void)
 	return GCM_PROFILE (profile);
 }
 
+/***************************************************************************
+ ***                          MAKE CHECK TESTS                           ***
+ ***************************************************************************/
+#ifdef EGG_TEST
+#include "egg-test.h"
+
+typedef struct {
+	const gchar *copyright;
+	const gchar *vendor;
+	const gchar *description;
+	GcmProfileType type;
+} GcmProfileTestData;
+
+void
+gcm_profile_test_parse_file (EggTest *test, const gchar *datafile, GcmProfileTestData *test_data)
+{
+	gchar *filename;
+	gchar *filename_tmp;
+	gchar *copyright;
+	gchar *vendor;
+	gchar *description;
+	gchar *ascii_string;
+	gchar *pnp_id;
+	gchar *data;
+	guint width;
+	guint type;
+	gfloat gamma;
+	gboolean ret;
+	GError *error = NULL;
+	GcmProfile *profile;
+
+	/************************************************************/
+	egg_test_title (test, "get a profile object");
+	profile = gcm_profile_new ();
+	egg_test_assert (test, profile != NULL);
+
+	/************************************************************/
+	egg_test_title (test, "get filename of data file");
+	filename = egg_test_get_data_file (datafile);
+	egg_test_assert (test, (filename != NULL));
+
+	/************************************************************/
+	egg_test_title (test, "load ICC file");
+	ret = gcm_profile_parse (profile, filename, &error);
+	if (ret)
+		egg_test_success (test, NULL);
+	else
+		egg_test_failed (test, "failed to parse: %s", error->message);
+
+	/* get some properties */
+	g_object_get (profile,
+		      "copyright", &copyright,
+		      "vendor", &vendor,
+		      "description", &description,
+		      "filename", &filename_tmp,
+		      "type", &type,
+		      NULL);
+
+	/************************************************************/
+	egg_test_title (test, "check filename for %s", datafile);
+	if (g_strcmp0 (filename, filename_tmp) == 0)
+		egg_test_success (test, NULL);
+	else
+		egg_test_failed (test, "invalid value: %s, expecting: %s", filename, filename_tmp);
+
+	/************************************************************/
+	egg_test_title (test, "check copyright for %s", datafile);
+	if (g_strcmp0 (copyright, test_data->copyright) == 0)
+		egg_test_success (test, NULL);
+	else
+		egg_test_failed (test, "invalid value: %s, expecting: %s", copyright, test_data->copyright);
+
+	/************************************************************/
+	egg_test_title (test, "check vendor for %s", datafile);
+	if (g_strcmp0 (vendor, test_data->vendor) == 0)
+		egg_test_success (test, NULL);
+	else
+		egg_test_failed (test, "invalid value: %s, expecting: %s", vendor, test_data->vendor);
+
+	/************************************************************/
+	egg_test_title (test, "check description for %s", datafile);
+	if (g_strcmp0 (description, test_data->description) == 0)
+		egg_test_success (test, NULL);
+	else
+		egg_test_failed (test, "invalid value: %s, expecting: %s", description, test_data->description);
+
+	/************************************************************/
+	egg_test_title (test, "check type for %s", datafile);
+	if (type == test_data->type)
+		egg_test_success (test, NULL);
+	else
+		egg_test_failed (test, "invalid value: %i, expecting: %i", type, test_data->type);
+
+	g_object_unref (profile);
+	g_free (copyright);
+	g_free (vendor);
+	g_free (description);
+	g_free (data);
+	g_free (filename);
+	g_free (filename_tmp);
+}
+
+void
+gcm_profile_test (EggTest *test)
+{
+	GcmProfileTestData test_data;
+
+	if (!egg_test_start (test, "GcmProfile"))
+		return;
+
+	/* bluish test */
+	test_data.copyright = "Copyright (c) 1998 Hewlett-Packard Company";
+	test_data.vendor = "IEC http://www.iec.ch";;
+	test_data.description = "bluish test";
+	test_data.type = GCM_PROFILE_TYPE_DISPLAY_DEVICE;
+	gcm_profile_test_parse_file (test, "bluish.icc", &test_data);
+
+	/* Adobe test */
+	test_data.copyright = "Copyright (c) 1998 Hewlett-Packard Company Modified using Adobe Gamma";
+	test_data.vendor = "IEC http://www.iec.ch";;
+	test_data.description = "ADOBEGAMMA-Test";
+	test_data.type = GCM_PROFILE_TYPE_DISPLAY_DEVICE;
+	gcm_profile_test_parse_file (test, "AdobeGammaTest.icm", &test_data);
+
+	egg_test_end (test);
+}
+#endif
+
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 248f991..b1a927c 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -28,6 +28,7 @@ void gcm_edid_test (EggTest *test);
 void gcm_tables_test (EggTest *test);
 void gcm_utils_test (EggTest *test);
 void gcm_device_test (EggTest *test);
+void gcm_profile_test (EggTest *test);
 
 int
 main (int argc, char **argv)
@@ -45,6 +46,7 @@ main (int argc, char **argv)
 	gcm_tables_test (test);
 	gcm_utils_test (test);
 	gcm_device_test (test);
+	gcm_profile_test (test);
 
 	return (egg_test_finish (test));
 }



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