[PATCH 1/2] test/xi2: Check new XInput 2.2 and newer QueryVersion semantics

Keith Packard keithp at keithp.com
Tue Jul 30 10:44:41 PDT 2013


Post-2.2 XInput version checking semantics have changed to allow
applications to request multiple versions, as long as those are
compatible. Check to make sure the server returns the lessor of the
requested and server-supported version, for each request made.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 test/xi2/protocol-xiqueryversion.c | 92 ++++++++++++++++++++++++++------------
 1 file changed, 64 insertions(+), 28 deletions(-)

diff --git a/test/xi2/protocol-xiqueryversion.c b/test/xi2/protocol-xiqueryversion.c
index aff0237..d46d341 100644
--- a/test/xi2/protocol-xiqueryversion.c
+++ b/test/xi2/protocol-xiqueryversion.c
@@ -84,11 +84,17 @@ reply_XIQueryVersion(ClientPtr client, int len, char *data, void *closure)
     assert((sver > cver) ? ver == cver : ver == sver);
 }
 
+static int
+new_as_2_2(int major, int minor) {
+    return major > 2 || (major == 2 && minor >= 2);
+}
+
 static void
 reply_XIQueryVersion_multiple(ClientPtr client, int len, char *data, void *closure)
 {
     xXIQueryVersionReply *rep = (xXIQueryVersionReply *) data;
     struct test_data *versions = (struct test_data *) closure;
+    unsigned int sver, cver, ver;
 
     reply_check_defaults(rep, len, XIQueryVersion);
     assert(rep->length == 0);
@@ -98,8 +104,38 @@ reply_XIQueryVersion_multiple(ClientPtr client, int len, char *data, void *closu
         versions->minor_cached = rep->minor_version;
     }
 
-    assert(versions->major_cached == rep->major_version);
-    assert(versions->minor_cached == rep->minor_version);
+    if (new_as_2_2(versions->major_cached, versions->minor_cached) &&
+        new_as_2_2(versions->major_client, versions->minor_client))
+    {
+	/* 
+           If all of the requested versions are 2.2 or greater, then
+           consecutive calls to XIQueryVersion by the same client with the
+           same major version will return the requested version, but the server
+           will operate according to the highest requested version number.
+        */
+        
+        sver = versions->major_server * 1000 + versions->minor_server;
+        cver = versions->major_client * 1000 + versions->minor_client;
+        ver = rep->major_version * 1000 + rep->minor_version;
+
+        if (sver >= cver) {
+            assert (cver == ver);
+        } else {
+            assert (sver == ver);
+        }
+    } else {
+	/*
+          If either the previous or current requested versions is less than
+          2.2, or if the requested major version numbers do not match, then
+          consecutive calls to XIQueryVersion by the same client always
+          return the first returned major.minor version. If the client
+          requests a version lower than the first returned major.minor
+          version in a subsequent call, a BadValue error occurs.
+        */
+
+        assert(versions->major_cached == rep->major_version);
+        assert(versions->minor_cached == rep->minor_version);
+    }
 }
 
 /**
@@ -206,8 +242,8 @@ test_XIQueryVersion_multiple(void)
     client = init_client(request.length, &request);
 
     /* Change the server to support 2.2 */
-    XIVersion.major_version = 2;
-    XIVersion.minor_version = 2;
+    versions.major_server = XIVersion.major_version = 2;
+    versions.minor_server = XIVersion.minor_version = 2;
 
     reply_handler = reply_XIQueryVersion_multiple;
     userdata = (void *) &versions;
@@ -217,70 +253,70 @@ test_XIQueryVersion_multiple(void)
     versions.minor_cached = -1;
 
     /* client is lower than server, noncached */
-    request.major_version = 2;
-    request.minor_version = 1;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 1;
     rc = ProcXIQueryVersion(&client);
     assert(rc == Success);
 
     /* client is higher than server, cached */
-    request.major_version = 2;
-    request.minor_version = 3;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 3;
     rc = ProcXIQueryVersion(&client);
     assert(rc == Success);
 
     /* client is equal, cached */
-    request.major_version = 2;
-    request.minor_version = 2;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 2;
     rc = ProcXIQueryVersion(&client);
     assert(rc == Success);
 
     /* client is low than cached */
-    request.major_version = 2;
-    request.minor_version = 0;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 0;
     rc = ProcXIQueryVersion(&client);
     assert(rc == BadValue);
 
     /* run 2 */
     client = init_client(request.length, &request);
-    XIVersion.major_version = 2;
-    XIVersion.minor_version = 2;
+    versions.major_server = XIVersion.major_version = 2;
+    versions.minor_server = XIVersion.minor_version = 2;
     versions.major_cached = -1;
     versions.minor_cached = -1;
 
-    request.major_version = 2;
-    request.minor_version = 2;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 2;
     rc = ProcXIQueryVersion(&client);
     assert(rc == Success);
 
-    request.major_version = 2;
-    request.minor_version = 3;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 3;
     rc = ProcXIQueryVersion(&client);
     assert(rc == Success);
 
-    request.major_version = 2;
-    request.minor_version = 1;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 1;
     rc = ProcXIQueryVersion(&client);
     assert(rc == BadValue);
 
     /* run 3 */
     client = init_client(request.length, &request);
-    XIVersion.major_version = 2;
-    XIVersion.minor_version = 2;
+    versions.major_server = XIVersion.major_version = 2;
+    versions.minor_server = XIVersion.minor_version = 2;
     versions.major_cached = -1;
     versions.minor_cached = -1;
 
-    request.major_version = 2;
-    request.minor_version = 3;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 3;
     rc = ProcXIQueryVersion(&client);
     assert(rc == Success);
 
-    request.major_version = 2;
-    request.minor_version = 2;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 2;
     rc = ProcXIQueryVersion(&client);
     assert(rc == Success);
 
-    request.major_version = 2;
-    request.minor_version = 1;
+    versions.major_client = request.major_version = 2;
+    versions.minor_client = request.minor_version = 1;
     rc = ProcXIQueryVersion(&client);
     assert(rc == BadValue);
 }
-- 
1.8.3.2



More information about the xorg-devel mailing list