No two device description files should match on the same ID.

Since a tablet may be listed multiple times in the database if it has more
than one match, we can't assume the matches are unique, we need to compare
the device name.

Build hashtable of {match string : device name}, then check for each new
existing match string if the device name is identical.

Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
---
 test/Makefile.am       |  3 ++-
 test/tablet-validity.c | 37 +++++++++++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/test/Makefile.am b/test/Makefile.am
index 6b71c85..f3a61cc 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -6,7 +6,8 @@ AM_CPPFLAGS=-I$(top_srcdir)/libwacom 
-DTOPSRCDIR="\"$(top_srcdir)\""
 
 load_LDADD=$(top_builddir)/libwacom/libwacom.la
 dbverify_LDADD=$(top_builddir)/libwacom/libwacom.la
-tablet_validity_LDADD=$(top_builddir)/libwacom/libwacom.la
+tablet_validity_LDADD=$(top_builddir)/libwacom/libwacom.la $(GLIB_LIBS)
+tablet_validity_CFLAGS=$(AM_CPPFLAGS) $(GLIB_CFLAGS)
 
 if HAVE_LIBXML
 noinst_PROGRAMS += tablet-svg-validity
diff --git a/test/tablet-validity.c b/test/tablet-validity.c
index 19a4b98..28eaea9 100644
--- a/test/tablet-validity.c
+++ b/test/tablet-validity.c
@@ -39,6 +39,7 @@
 #include "libwacom.h"
 #include <assert.h>
 #include <unistd.h>
+#include <glib.h>
 
 typedef int (*NumModesFn) (const WacomDevice *device);
 
@@ -112,7 +113,30 @@ static int eraser_is_present(WacomDeviceDatabase *db, 
const int *styli, int nsty
        return 0;
 }
 
-static void verify_tablet(WacomDeviceDatabase *db, WacomDevice *device)
+static void verify_matches(WacomDeviceDatabase *db, GHashTable *matchtable, 
WacomDevice *device)
+{
+       const WacomMatch **matches;
+
+       assert(libwacom_get_match(device) != NULL);
+       matches = libwacom_get_matches(device);
+       assert(matches != NULL);
+
+       /* devices with multiple matches are listed multiple times in the
+          database, so we can't just compare the matches, we compare the
+          names */
+       for(; *matches; matches++) {
+               const char *matchstr;
+               const char *other;
+               matchstr = libwacom_match_get_match_string(*matches);
+               other = g_hash_table_lookup(matchtable, matchstr);
+               if (other != NULL)
+                       g_assert_cmpstr(libwacom_get_name(device), ==, 
g_hash_table_lookup(matchtable, matchstr));
+               g_hash_table_insert(matchtable, (gpointer)matchstr, 
(gpointer)libwacom_get_name(device));
+       }
+
+}
+
+static void verify_tablet(WacomDeviceDatabase *db, GHashTable *matchtable, 
WacomDevice *device)
 {
        const char *name;
        const int *styli;
@@ -129,8 +153,8 @@ static void verify_tablet(WacomDeviceDatabase *db, 
WacomDevice *device)
                assert(libwacom_get_vendor_id(device) > 0);
                assert(libwacom_get_product_id(device) > 0);
        }
-       assert(libwacom_get_match(device) != NULL);
-       assert(libwacom_get_matches(device) != NULL);
+
+       verify_matches(db, matchtable, device);
 
        /* ISDv4 are built-in, they may be of varying size */
        if (libwacom_get_class(device) != WCLASS_ISDV4) {
@@ -196,6 +220,7 @@ static void verify_tablet(WacomDeviceDatabase *db, 
WacomDevice *device)
 
 int main(int argc, char **argv)
 {
+       GHashTable *matches;
        WacomDeviceDatabase *db;
        WacomDevice **device, **devices;
 
@@ -208,8 +233,12 @@ int main(int argc, char **argv)
        assert(devices);
        assert(*devices);
 
+       matches = g_hash_table_new(g_str_hash, g_str_equal);
+
        for (device = devices; *device; device++)
-               verify_tablet(db, *device);
+               verify_tablet(db, matches, *device);
+
+       g_hash_table_destroy(matches);
 
        libwacom_database_destroy (db);
 
-- 
1.8.1


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to