2010-07-27 13:02:24 -06:00
|
|
|
/**
|
|
|
|
* Copyright © 2009 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protocol testing for XIQueryVersion request and reply.
|
|
|
|
*
|
|
|
|
* Test approach:
|
|
|
|
* Wrap WriteToClient to intercept the server's reply.
|
|
|
|
* Repeatedly test a client/server version combination, compare version in
|
|
|
|
* reply with versions given. Version must be equal to either
|
|
|
|
* server version or client version, whichever is smaller.
|
|
|
|
* Client version less than 2 must return BadValue.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include <X11/extensions/XI2proto.h>
|
|
|
|
#include "inputstr.h"
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "extinit.h" /* for XInputExtensionInit */
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "xiqueryversion.h"
|
|
|
|
#include "protocol-common.h"
|
2013-09-28 09:36:30 -06:00
|
|
|
#include "exglobals.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
extern XExtensionVersion XIVersion;
|
|
|
|
|
|
|
|
struct test_data {
|
|
|
|
int major_client;
|
|
|
|
int minor_client;
|
|
|
|
int major_server;
|
|
|
|
int minor_server;
|
2013-09-28 09:36:30 -06:00
|
|
|
int major_expected;
|
|
|
|
int minor_expected;
|
2010-07-27 13:02:24 -06:00
|
|
|
};
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
ClientRec client_window;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
2013-06-07 11:28:45 -06:00
|
|
|
reply_XIQueryVersion(ClientPtr client, int len, char *data, void *closure)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
xXIQueryVersionReply *rep = (xXIQueryVersionReply *) data;
|
2013-06-07 11:28:45 -06:00
|
|
|
struct test_data *versions = (struct test_data *) closure;
|
2010-07-27 13:02:24 -06:00
|
|
|
unsigned int sver, cver, ver;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (client->swapped) {
|
|
|
|
swapl(&rep->length);
|
|
|
|
swaps(&rep->sequenceNumber);
|
|
|
|
swaps(&rep->major_version);
|
|
|
|
swaps(&rep->minor_version);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
reply_check_defaults(rep, len, XIQueryVersion);
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
assert(rep->length == 0);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
sver = versions->major_server * 1000 + versions->minor_server;
|
|
|
|
cver = versions->major_client * 1000 + versions->minor_client;
|
|
|
|
ver = rep->major_version * 1000 + rep->minor_version;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
assert(ver >= 2000);
|
|
|
|
assert((sver > cver) ? ver == cver : ver == sver);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
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;
|
|
|
|
|
|
|
|
reply_check_defaults(rep, len, XIQueryVersion);
|
|
|
|
assert(rep->length == 0);
|
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
assert(versions->major_expected == rep->major_version);
|
|
|
|
assert(versions->minor_expected == rep->minor_version);
|
2013-06-07 11:28:45 -06:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/**
|
|
|
|
* Run a single test with server version smaj.smin and client
|
|
|
|
* version cmaj.cmin. Verify that return code is equal to 'error'.
|
|
|
|
*
|
|
|
|
* Test is run normal, then for a swapped client.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
request_XIQueryVersion(int smaj, int smin, int cmaj, int cmin, int error)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct test_data versions;
|
|
|
|
xXIQueryVersionReq request;
|
|
|
|
ClientRec client;
|
|
|
|
|
|
|
|
request_init(&request, XIQueryVersion);
|
|
|
|
client = init_client(request.length, &request);
|
2014-09-27 11:52:59 -06:00
|
|
|
global_userdata = (void *) &versions;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/* Change the server to support smaj.smin */
|
|
|
|
XIVersion.major_version = smaj;
|
|
|
|
XIVersion.minor_version = smin;
|
|
|
|
|
|
|
|
/* remember versions we send and expect */
|
|
|
|
versions.major_client = cmaj;
|
|
|
|
versions.minor_client = cmin;
|
|
|
|
versions.major_server = XIVersion.major_version;
|
|
|
|
versions.minor_server = XIVersion.minor_version;
|
|
|
|
|
|
|
|
request.major_version = versions.major_client;
|
|
|
|
request.minor_version = versions.minor_client;
|
|
|
|
rc = ProcXIQueryVersion(&client);
|
2011-11-05 07:32:40 -06:00
|
|
|
assert(rc == error);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
client = init_client(request.length, &request);
|
2010-07-27 13:02:24 -06:00
|
|
|
client.swapped = TRUE;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&request.length);
|
|
|
|
swaps(&request.major_version);
|
|
|
|
swaps(&request.minor_version);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
rc = SProcXIQueryVersion(&client);
|
2011-11-05 07:32:40 -06:00
|
|
|
assert(rc == error);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Client version less than 2.0 must return BadValue, all other combinations
|
|
|
|
* Success */
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
test_XIQueryVersion(void)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
reply_handler = reply_XIQueryVersion;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Server version 2.0 - client versions [1..3].0\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
/* some simple tests to catch common errors quickly */
|
|
|
|
request_XIQueryVersion(2, 0, 1, 0, BadValue);
|
|
|
|
request_XIQueryVersion(2, 0, 2, 0, Success);
|
|
|
|
request_XIQueryVersion(2, 0, 3, 0, Success);
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Server version 3.0 - client versions [1..3].0\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
request_XIQueryVersion(3, 0, 1, 0, BadValue);
|
|
|
|
request_XIQueryVersion(3, 0, 2, 0, Success);
|
|
|
|
request_XIQueryVersion(3, 0, 3, 0, Success);
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Server version 2.0 - client versions [1..3].[1..3]\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
request_XIQueryVersion(2, 0, 1, 1, BadValue);
|
|
|
|
request_XIQueryVersion(2, 0, 2, 2, Success);
|
|
|
|
request_XIQueryVersion(2, 0, 3, 3, Success);
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Server version 2.2 - client versions [1..3].0\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
request_XIQueryVersion(2, 2, 1, 0, BadValue);
|
|
|
|
request_XIQueryVersion(2, 2, 2, 0, Success);
|
|
|
|
request_XIQueryVersion(2, 2, 3, 0, Success);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* this one takes a while */
|
|
|
|
unsigned int cmin, cmaj, smin, smaj;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Testing all combinations.\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
for (smaj = 2; smaj <= 0xFFFF; smaj++)
|
|
|
|
for (smin = 0; smin <= 0xFFFF; smin++)
|
|
|
|
for (cmin = 0; cmin <= 0xFFFF; cmin++)
|
2012-06-10 07:21:05 -06:00
|
|
|
for (cmaj = 0; cmaj <= 0xFFFF; cmaj++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
int error = (cmaj < 2) ? BadValue : Success;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
request_XIQueryVersion(smaj, smin, cmaj, cmin, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
reply_handler = NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_XIQueryVersion_multiple(void)
|
|
|
|
{
|
|
|
|
xXIQueryVersionReq request;
|
|
|
|
ClientRec client;
|
2013-09-28 09:36:30 -06:00
|
|
|
XIClientPtr pXIClient;
|
2013-06-07 11:28:45 -06:00
|
|
|
struct test_data versions;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
request_init(&request, XIQueryVersion);
|
|
|
|
client = init_client(request.length, &request);
|
|
|
|
|
|
|
|
/* Change the server to support 2.2 */
|
|
|
|
XIVersion.major_version = 2;
|
|
|
|
XIVersion.minor_version = 2;
|
|
|
|
|
|
|
|
reply_handler = reply_XIQueryVersion_multiple;
|
2014-09-27 11:52:59 -06:00
|
|
|
global_userdata = (void *) &versions;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
/* run 1 */
|
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
/* client is lower than server, nonexpected */
|
|
|
|
versions.major_expected = request.major_version = 2;
|
|
|
|
versions.minor_expected = request.minor_version = 1;
|
2013-06-07 11:28:45 -06:00
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == Success);
|
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
/* client is higher than server, no change */
|
2013-06-07 11:28:45 -06:00
|
|
|
request.major_version = 2;
|
|
|
|
request.minor_version = 3;
|
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == Success);
|
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
/* client tries to set higher version, stays same */
|
2013-06-07 11:28:45 -06:00
|
|
|
request.major_version = 2;
|
|
|
|
request.minor_version = 2;
|
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == Success);
|
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
/* client tries to set lower version, no change */
|
2013-06-07 11:28:45 -06:00
|
|
|
request.major_version = 2;
|
|
|
|
request.minor_version = 0;
|
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == BadValue);
|
|
|
|
|
|
|
|
/* run 2 */
|
|
|
|
client = init_client(request.length, &request);
|
|
|
|
XIVersion.major_version = 2;
|
2013-09-28 09:36:30 -06:00
|
|
|
XIVersion.minor_version = 3;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
versions.major_expected = request.major_version = 2;
|
|
|
|
versions.minor_expected = request.minor_version = 2;
|
2013-06-07 11:28:45 -06:00
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == Success);
|
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
/* client bumps version from 2.2 to 2.3 */
|
2013-06-07 11:28:45 -06:00
|
|
|
request.major_version = 2;
|
2013-09-28 09:36:30 -06:00
|
|
|
versions.minor_expected = request.minor_version = 3;
|
2013-06-07 11:28:45 -06:00
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == Success);
|
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
/* real version is changed, too! */
|
|
|
|
pXIClient = dixLookupPrivate(&client.devPrivates, XIClientPrivateKey);
|
|
|
|
assert(pXIClient->minor_version == 3);
|
|
|
|
|
|
|
|
/* client tries to set lower version, no change */
|
2013-06-07 11:28:45 -06:00
|
|
|
request.major_version = 2;
|
|
|
|
request.minor_version = 1;
|
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == BadValue);
|
|
|
|
|
|
|
|
/* run 3 */
|
|
|
|
client = init_client(request.length, &request);
|
|
|
|
XIVersion.major_version = 2;
|
2013-09-28 09:36:30 -06:00
|
|
|
XIVersion.minor_version = 3;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
versions.major_expected = request.major_version = 2;
|
|
|
|
versions.minor_expected = request.minor_version = 3;
|
2013-06-07 11:28:45 -06:00
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == Success);
|
|
|
|
|
|
|
|
request.major_version = 2;
|
2013-09-28 09:36:30 -06:00
|
|
|
versions.minor_expected = request.minor_version = 2;
|
2013-06-07 11:28:45 -06:00
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == Success);
|
|
|
|
|
2013-09-28 09:36:30 -06:00
|
|
|
/* but real client version must not be lowered */
|
|
|
|
pXIClient = dixLookupPrivate(&client.devPrivates, XIClientPrivateKey);
|
|
|
|
assert(pXIClient->minor_version == 3);
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
request.major_version = 2;
|
|
|
|
request.minor_version = 1;
|
|
|
|
rc = ProcXIQueryVersion(&client);
|
|
|
|
assert(rc == BadValue);
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
2019-07-27 01:57:06 -06:00
|
|
|
protocol_xiqueryversion_test(void)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
init_simple();
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
test_XIQueryVersion();
|
2013-06-07 11:28:45 -06:00
|
|
|
test_XIQueryVersion_multiple();
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
return 0;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|