Signed-off-by: Peter Hutterer <[email protected]>
---

> I could remove WCM_LCD from the definition of WCM_TPC but I think the
> more correct fix would actually be changing TabletHasFeature(common,
> feature):
> 
> from
> 
> (((common->tablet_type) & (feature)) != 0)
> 
> to
> 
> (((common->tablet_type) & (feature)) == feature)
> 
> I'll be working on some other patches first in case anybody wants to
> give some more feedback.

I've had this patch in my devel tree for a while but haven't started using
it yet. Was born of the same problem that the == 0 check didn't cover what I
needed at the time. Maybe we should use these instead.

 src/xf86WacomDefs.h |   14 ++++++++++++++
 test/wacom-tests.c  |   21 +++++++++++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index cae441c..9063fc0 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -104,6 +104,20 @@
 #define OFF(x)         ((x)%BITS_PER_LONG)
 #define LONG(x)                ((x)/BITS_PER_LONG)
 
+/**
+ * Test if the mask is set in the given bitfield.
+ * @return TRUE if set or FALSE otherwise.
+ */
+#define MaskIsSet(bitfield, mask) !!(((bitfield) & (mask)) == (mask))
+/**
+ * Set the given mask for the given bitfield.
+ */
+#define MaskSet(bitfield, mask) ((bitfield) |= (mask))
+/**
+ * Clear the given mask from the given bitfield
+ */
+#define MaskClear(bitfield, mask) ((bitfield) &= ~(mask))
+
 /******************************************************************************
  * Forward Declarations
  *****************************************************************************/
diff --git a/test/wacom-tests.c b/test/wacom-tests.c
index 42a7557..e0891ae 100644
--- a/test/wacom-tests.c
+++ b/test/wacom-tests.c
@@ -531,6 +531,26 @@ static void test_set_type(void)
 #undef reset
 }
 
+static int test_flag_set(void)
+{
+       int i;
+       unsigned int flags = 0;
+
+       for (i = 0; i < sizeof(flags); i++)
+       {
+               int mask = 1 << i;
+               flags = 0;
+
+               assert(!MaskIsSet(flags, mask));
+               MaskSet(flags, mask);
+               assert(flags != 0);
+               assert(MaskIsSet(flags, mask));
+               MaskClear(flags, mask);
+               assert(!MaskIsSet(flags, mask));
+               assert(flags == 0);
+       }
+}
+
 int main(int argc, char** argv)
 {
        test_common_ref();
@@ -541,6 +561,7 @@ int main(int argc, char** argv)
        test_tilt_to_rotation();
        test_mod_buttons();
        test_set_type();
+       test_flag_set();
        return 0;
 }
 
-- 
1.7.4.2

------------------------------------------------------------------------------
Forrester Wave Report - Recovery time is now measured in hours and minutes
not days. Key insights are discussed in the 2010 Forrester Wave Report as
part of an in-depth evaluation of disaster recovery service providers.
Forrester found the best-in-class provider in terms of services and vision.
Read this report now!  http://p.sf.net/sfu/ibm-webcastpromo
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to