[PATCH xorg-gtest 5/5] device: add HasEvent() and GetAbsData()

Peter Hutterer peter.hutterer at who-t.net
Mon Jan 14 14:17:38 PST 2013


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 include/xorg/gtest/evemu/xorg-gtest-device.h |  25 ++++
 src/device.cpp                               |  21 ++++
 test/SynPS2-Synaptics-TouchPad.desc          |  33 ++++++
 test/device-test.cpp                         | 164 +++++++++++++++++++++++++++
 4 files changed, 243 insertions(+)
 create mode 100644 test/SynPS2-Synaptics-TouchPad.desc

diff --git a/include/xorg/gtest/evemu/xorg-gtest-device.h b/include/xorg/gtest/evemu/xorg-gtest-device.h
index 60087dd..61a9c01 100644
--- a/include/xorg/gtest/evemu/xorg-gtest-device.h
+++ b/include/xorg/gtest/evemu/xorg-gtest-device.h
@@ -102,6 +102,31 @@ class Device {
    */
   const std::string& GetDeviceNode(void);
 
+  /**
+   * Check if a device supports a specific event.
+   *
+   * @param [in] type Type of the event (EV_REL, EV_ABS, ...)
+   * @param [in] code Event code (ABS_X, REL_Y, ...)
+   *
+   * @return true if this device supports this event or false otherwise.
+   */
+  bool HasEvent(int type, int code);
+
+  /**
+   * Retrieve data about an absolute axis on this device.
+   *
+   * @param [in] code The axis to query (e.g. ABS_X)
+   * @param [out] min Min value for this axis
+   * @param [out] max Max value for this axis
+   * @param [out] fuzz Fuzz value for this axis
+   * @param [out] flat Flat value for this axis
+   * @param [out] resolution Resolution of this axis
+   *
+   * @return false if this device doesn't have this axis, or true on success
+   */
+  bool GetAbsData(int code, int *min, int *max, int *fuzz = NULL, int *flat = NULL, int *resolution = NULL);
+
+
  private:
   struct Private;
   std::auto_ptr<Private> d_;
diff --git a/src/device.cpp b/src/device.cpp
index ea98d17..a57864d 100644
--- a/src/device.cpp
+++ b/src/device.cpp
@@ -236,6 +236,27 @@ void xorg::testing::evemu::Device::PlayOne(int type, int code, int value, bool s
   }
 }
 
+bool xorg::testing::evemu::Device::HasEvent(int type, int code)
+{
+    return evemu_has_event(d_->device, type, code);
+}
+
+bool xorg::testing::evemu::Device::GetAbsData(int code, int *min, int *max, int *fuzz, int *flat, int *resolution)
+{
+    if (!HasEvent(EV_ABS, code))
+        return false;
+
+    *min = evemu_get_abs_minimum(d_->device, code);
+    *max = evemu_get_abs_maximum(d_->device, code);
+    if (fuzz)
+        *fuzz = evemu_get_abs_fuzz(d_->device, code);
+    if (flat)
+        *flat = evemu_get_abs_flat(d_->device, code);
+    if (resolution)
+        *resolution = evemu_get_abs_resolution(d_->device, code);
+    return true;
+}
+
 const std::string& xorg::testing::evemu::Device::GetDeviceNode(void) {
   if (d_->device_node.empty())
     GuessDeviceNode(d_->ctime);
diff --git a/test/SynPS2-Synaptics-TouchPad.desc b/test/SynPS2-Synaptics-TouchPad.desc
new file mode 100644
index 0000000..3f4982b
--- /dev/null
+++ b/test/SynPS2-Synaptics-TouchPad.desc
@@ -0,0 +1,33 @@
+N: SynPS/2 Synaptics TouchPad
+I: 0011 0002 0007 01b1
+P: 05 00 00 00 00 00 00 00
+B: 00 0b 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 01 00 00 00 00 00
+B: 01 20 e5 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 02 00 00 00 00 00 00 00 00
+B: 03 03 00 00 11 00 80 60 06
+B: 04 00 00 00 00 00 00 00 00
+B: 05 00 00 00 00 00 00 00 00
+B: 11 00 00 00 00 00 00 00 00
+B: 12 00 00 00 00 00 00 00 00
+B: 15 00 00 00 00 00 00 00 00
+B: 15 00 00 00 00 00 00 00 00
+A: 00 1472 5472 8 0
+A: 01 1408 4448 8 0
+A: 18 0 255 0 0
+A: 1c 0 15 0 0
+A: 2f 0 1 0 0
+A: 35 1472 5472 8 0
+A: 36 1408 4448 8 0
+A: 39 0 65535 0 0
+A: 3a 0 255 0 0
diff --git a/test/device-test.cpp b/test/device-test.cpp
index 47ddb26..f3b5683 100644
--- a/test/device-test.cpp
+++ b/test/device-test.cpp
@@ -24,6 +24,170 @@ TEST(Device, InotifyWait)
   ASSERT_FALSE(d.GetDeviceNode().empty());
 }
 
+TEST(Device, HasEvent)
+{
+    XORG_TESTCASE("HasEvent must return the right bits.\n");
+
+    xorg::testing::evemu::Device d(TEST_ROOT_DIR "PIXART-USB-OPTICAL-MOUSE.desc");
+
+    for (int i = ABS_X; i < ABS_MAX; i++)
+        ASSERT_FALSE(d.HasEvent(EV_ABS, i)) << "Axis code " << i;
+
+    for (int i = REL_X; i < REL_MAX; i++) {
+        if (i == REL_X || i == REL_Y || i == REL_WHEEL)
+            ASSERT_TRUE(d.HasEvent(EV_REL, i)) << "Axis code " << i;
+        else
+            ASSERT_FALSE(d.HasEvent(EV_REL, i)) << "Axis code " << i;
+    }
+
+    for (int i = BTN_LEFT; i < KEY_MAX; i++) {
+        if (i == BTN_LEFT || i == BTN_RIGHT || i == BTN_MIDDLE)
+            ASSERT_TRUE(d.HasEvent(EV_KEY, i)) << "Axis code " << i;
+        else
+            ASSERT_FALSE(d.HasEvent(EV_KEY, i)) << "Axis code " << i;
+    }
+
+    xorg::testing::evemu::Device d2(TEST_ROOT_DIR "SynPS2-Synaptics-TouchPad.desc");
+
+    for (int i = REL_X; i < REL_MAX; i++)
+        ASSERT_FALSE(d2.HasEvent(EV_REL, i)) << "Axis code " << i;
+
+    for (int i = ABS_X; i < ABS_MAX; i++) {
+        switch (i) {
+            case ABS_X:
+            case ABS_Y:
+            case ABS_PRESSURE:
+            case ABS_TOOL_WIDTH:
+            case ABS_MT_SLOT:
+            case ABS_MT_POSITION_X:
+            case ABS_MT_POSITION_Y:
+            case ABS_MT_TRACKING_ID:
+            case ABS_MT_PRESSURE:
+                ASSERT_TRUE(d2.HasEvent(EV_ABS, i)) << "Axis code " << i;
+                break;
+            default:
+                ASSERT_FALSE(d2.HasEvent(EV_REL, i)) << "Axis code " << i;
+                break;
+
+        }
+    }
+
+    for (int i = BTN_LEFT; i < KEY_MAX; i++) {
+        switch (i) {
+            case BTN_LEFT:
+            case BTN_TOOL_FINGER:
+            case BTN_TOOL_QUINTTAP:
+            case BTN_TOUCH:
+            case BTN_TOOL_DOUBLETAP:
+            case BTN_TOOL_TRIPLETAP:
+            case BTN_TOOL_QUADTAP:
+                ASSERT_TRUE(d2.HasEvent(EV_KEY, i)) << "Axis code " << i;
+                break;
+            default:
+                ASSERT_FALSE(d2.HasEvent(EV_KEY, i)) << "Axis code " << i;
+        }
+    }
+
+}
+
+TEST(Device, AbsAxisData) {
+    XORG_TESTCASE("GetAbsData must return the right values.\n");
+
+    xorg::testing::evemu::Device d(TEST_ROOT_DIR "SynPS2-Synaptics-TouchPad.desc");
+
+    const int DEFAULT = -3;
+
+    for (int i = ABS_X; i < ABS_MAX; i++) {
+        int min = 0, max = 0, fuzz = 0, flat = 0, resolution = 0;
+        bool axis_exists = 1;
+
+        switch (i) {
+            case ABS_X:
+            case ABS_MT_POSITION_X:
+                min = 1472;
+                max = 5472;
+                fuzz = 8;
+                break;
+            case ABS_Y:
+            case ABS_MT_POSITION_Y:
+                min = 1408;
+                max = 4448;
+                fuzz = 8;
+                break;
+            case ABS_PRESSURE:
+                min = 0;
+                max = 255;
+                break;
+            case ABS_TOOL_WIDTH:
+                min = 0;
+                max = 15;
+                break;
+            case ABS_MT_SLOT:
+                min = 0;
+                max = 1;
+                break;
+            case ABS_MT_TRACKING_ID:
+                min = 0;
+                max = 65535;
+                break;
+            case ABS_MT_PRESSURE:
+                min = 0;
+                max = 255;
+                break;
+            default:
+                axis_exists = false;
+                break;
+        }
+
+        if (axis_exists) {
+            int min_ret = min;
+            int max_ret = max;
+            int fuzz_ret = fuzz;
+            int flat_ret = flat;
+            int res_ret = resolution;
+
+            ASSERT_TRUE(d.GetAbsData(i, &min_ret, &max_ret)) << "Axis code " << i;
+            ASSERT_EQ(min, min_ret);
+            ASSERT_EQ(max, max_ret);
+
+            ASSERT_TRUE(d.GetAbsData(i, &min_ret, &max_ret, &fuzz)) << "Axis code " << i;
+            ASSERT_EQ(min, min_ret);
+            ASSERT_EQ(max, max_ret);
+            ASSERT_EQ(fuzz, fuzz_ret);
+
+            ASSERT_TRUE(d.GetAbsData(i, &min_ret, &max_ret, &fuzz, &flat)) << "Axis code " << i;
+            ASSERT_EQ(min, min_ret);
+            ASSERT_EQ(max, max_ret);
+            ASSERT_EQ(fuzz, fuzz_ret);
+            ASSERT_EQ(flat, flat_ret);
+
+            ASSERT_TRUE(d.GetAbsData(i, &min_ret, &max_ret, &fuzz, &flat, &res_ret)) << "Axis code " << i;
+            ASSERT_EQ(min, min_ret);
+            ASSERT_EQ(max, max_ret);
+            ASSERT_EQ(fuzz, fuzz_ret);
+            ASSERT_EQ(flat, flat_ret);
+            ASSERT_EQ(res_ret, resolution);
+        } else {
+            min = DEFAULT;
+            max = DEFAULT;
+            fuzz = DEFAULT;
+            flat = DEFAULT;
+            resolution = DEFAULT;
+
+            ASSERT_FALSE(d.GetAbsData(i, &min, &max)) << "Axis code " << i;
+
+            /* make sure we didn't overwrite the values */
+            ASSERT_EQ(min, DEFAULT);
+            ASSERT_EQ(max, DEFAULT);
+            ASSERT_EQ(fuzz, DEFAULT);
+            ASSERT_EQ(flat, DEFAULT);
+            ASSERT_EQ(resolution, DEFAULT);
+        }
+
+    }
+}
+
+
 #endif
 
 int main(int argc, char *argv[]) {
-- 
1.8.1



More information about the xorg-devel mailing list