[gnome-color-manager] Add some self test code for GcmTables, and fix up the failures on Debian
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add some self test code for GcmTables, and fix up the failures on Debian
- Date: Fri, 27 Nov 2009 12:52:47 +0000 (UTC)
commit fa33c4dc3dbe118b261b30e0de0204452d95df98
Author: Richard Hughes <richard hughsie com>
Date: Fri Nov 27 12:52:07 2009 +0000
Add some self test code for GcmTables, and fix up the failures on Debian
src/Makefile.am | 1 +
src/gcm-self-test.c | 2 +
src/gcm-tables.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 98 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 8a8d8f7..2c03445 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -162,6 +162,7 @@ check_PROGRAMS = \
gcm_self_test_SOURCES = \
gcm-self-test.c \
gcm-edid.c \
+ gcm-tables.c \
egg-test.h \
egg-test.c \
$(NULL)
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 8f82300..b474067 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -25,6 +25,7 @@
/* prototypes */
void gcm_edid_test (EggTest *test);
+void gcm_tables_test (EggTest *test);
int
main (int argc, char **argv)
@@ -39,6 +40,7 @@ main (int argc, char **argv)
/* components */
gcm_edid_test (test);
+ gcm_tables_test (test);
return (egg_test_finish (test));
}
diff --git a/src/gcm-tables.c b/src/gcm-tables.c
index e73c750..f38de10 100644
--- a/src/gcm-tables.c
+++ b/src/gcm-tables.c
@@ -185,14 +185,45 @@ gcm_tables_class_init (GcmTablesClass *klass)
}
/**
+ * gcm_tables_set_default_data_dir:
+ **/
+static gboolean
+gcm_tables_set_default_data_dir (GcmTables *tables)
+{
+ gboolean ret;
+
+ /* shipped in hwdata, e.g. Red Hat */
+ ret = g_file_test ("/usr/share/hwdata/pnp.ids", G_FILE_TEST_EXISTS);
+ if (ret) {
+ tables->priv->data_dir = g_strdup ("/usr/share/hwdata");
+ goto out;
+ }
+
+ /* shipped in pnputils, e.g. Debian */
+ ret = g_file_test ("/usr/share/misc/pnp.ids", G_FILE_TEST_EXISTS);
+ if (ret) {
+ tables->priv->data_dir = g_strdup ("/usr/share/misc");
+ goto out;
+ }
+
+ /* need to install package? */
+ egg_warning ("cannot find pnp.ids");
+out:
+ return ret;
+}
+
+/**
* gcm_tables_init:
**/
static void
gcm_tables_init (GcmTables *tables)
{
tables->priv = GCM_TABLES_GET_PRIVATE (tables);
- tables->priv->data_dir = g_strdup ("/usr/share/hwdata");
+ tables->priv->data_dir = NULL;
tables->priv->pnp_table = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_free);
+
+ /* the default location differs on debian and other distros */
+ gcm_tables_set_default_data_dir (tables);
}
/**
@@ -223,3 +254,66 @@ gcm_tables_new (void)
return GCM_TABLES (tables);
}
+/***************************************************************************
+ *** MAKE CHECK TESTS ***
+ ***************************************************************************/
+#ifdef EGG_TEST
+#include "egg-test.h"
+
+void
+gcm_tables_test (EggTest *test)
+{
+ GcmTables *tables;
+ gboolean ret;
+ GError *error = NULL;
+ gchar *vendor;
+
+ if (!egg_test_start (test, "GcmTables"))
+ return;
+
+ /************************************************************/
+ egg_test_title (test, "get a tables object");
+ tables = gcm_tables_new ();
+ egg_test_assert (test, tables != NULL);
+
+ /************************************************************/
+ egg_test_title (test, "check pnp id 'IBM'");
+ vendor = gcm_tables_get_pnp_id (tables, "IBM", &error);
+ if (vendor == NULL)
+ egg_test_failed (test, "failed to get value: %s", error->message);
+ if (g_strcmp0 (vendor, "IBM France") == 0)
+ egg_test_success (test, NULL);
+ else
+ egg_test_failed (test, "invalid value: %s", vendor);
+ g_free (vendor);
+
+ /************************************************************/
+ egg_test_title (test, "check pnp id 'MIL'");
+ vendor = gcm_tables_get_pnp_id (tables, "MIL", &error);
+ if (vendor == NULL)
+ egg_test_failed (test, "failed to get value: %s", error->message);
+ if (g_strcmp0 (vendor, "Marconi Instruments Ltd") == 0)
+ egg_test_success (test, NULL);
+ else
+ egg_test_failed (test, "invalid value: %s", vendor);
+ g_free (vendor);
+
+ /************************************************************/
+ egg_test_title (test, "check pnp id 'XXX'");
+ vendor = gcm_tables_get_pnp_id (tables, "XXX", &error);
+ if (vendor == NULL) {
+ if (error == NULL)
+ egg_test_failed (test, "failed to get value and no error set");
+ g_clear_error (&error);
+ egg_test_success (test, NULL);
+ } else {
+ egg_test_failed (test, "vendor should not exist");
+ }
+ g_free (vendor);
+
+ g_object_unref (tables);
+
+ egg_test_end (test);
+}
+#endif
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]