[PATCH 1/2] test/xi2: Add a test for XIGrabDevice

Peter Hutterer peter.hutterer at who-t.net
Sun Apr 14 17:20:26 PDT 2013


On Sat, Apr 13, 2013 at 04:22:53AM +0200, Rui Matos wrote:
> Currently fails but will get fixed in the next commit.

did this test really succeed? because it fails here and it looks like it
cannot actually work. 

protocol-xigrabdevice: protocol-xigrabdevice.c:73: request_XIGrabDevice:
Assertion `rc == error' failed.

rc is BadWindow because dixLookupWindow fails. You wrap it in code, but the
wrap has no effect because both dixLookupWindow and GrabDevice are part of
libdix.a. so __wrap_dixLookupWindow is never called, we alway get BadWindow
and the interesting part of the test is never called.

Cheers,
   Peter

> ---
>  test/xi2/.gitignore              |   1 +
>  test/xi2/Makefile.am             |   4 ++
>  test/xi2/protocol-xigrabdevice.c | 123 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 128 insertions(+)
>  create mode 100644 test/xi2/protocol-xigrabdevice.c
> 
> diff --git a/test/xi2/.gitignore b/test/xi2/.gitignore
> index 817aa7b..548c1fb 100644
> --- a/test/xi2/.gitignore
> +++ b/test/xi2/.gitignore
> @@ -1,6 +1,7 @@
>  protocol-eventconvert
>  protocol-xigetclientpointer
>  protocol-xigetselectedevents
> +protocol-xigrabdevice
>  protocol-xipassivegrabdevice
>  protocol-xiquerydevice
>  protocol-xiquerypointer
> diff --git a/test/xi2/Makefile.am b/test/xi2/Makefile.am
> index 9de7abf..ba4ba97 100644
> --- a/test/xi2/Makefile.am
> +++ b/test/xi2/Makefile.am
> @@ -8,6 +8,7 @@ noinst_PROGRAMS =  \
>          protocol-xisetclientpointer \
>          protocol-xigetclientpointer \
>          protocol-xipassivegrabdevice \
> +        protocol-xigrabdevice \
>          protocol-xiquerypointer \
>          protocol-xiwarppointer \
>          protocol-eventconvert \
> @@ -33,6 +34,7 @@ protocol_xisetclientpointer_LDADD=$(TEST_LDADD)
>  protocol_xigetclientpointer_LDADD=$(TEST_LDADD)
>  protocol_xiquerypointer_LDADD=$(TEST_LDADD)
>  protocol_xipassivegrabdevice_LDADD=$(TEST_LDADD)
> +protocol_xigrabdevice_LDADD=$(TEST_LDADD)
>  protocol_xiwarppointer_LDADD=$(TEST_LDADD)
>  protocol_eventconvert_LDADD=$(TEST_LDADD)
>  xi2_LDADD=$(TEST_LDADD)
> @@ -44,6 +46,7 @@ protocol_xigetselectedevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-
>  protocol_xisetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupClient
>  protocol_xigetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupClient
>  protocol_xipassivegrabdevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,GrabButton -Wl,-wrap,dixLookupWindow -Wl,-wrap,WriteToClient
> +protocol_xigrabdevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupWindow -Wl,-wrap,WriteToClient
>  protocol_xiquerypointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
>  protocol_xiwarppointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
>  xi2_LDFLAGS=$(AM_LDFLAGS)
> @@ -56,6 +59,7 @@ protocol_xisetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xisetclientpointe
>  protocol_xigetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xigetclientpointer.c
>  protocol_xiquerypointer_SOURCES=$(COMMON_SOURCES) protocol-xiquerypointer.c
>  protocol_xipassivegrabdevice_SOURCES=$(COMMON_SOURCES) protocol-xipassivegrabdevice.c
> +protocol_xigrabdevice_SOURCES=$(COMMON_SOURCES) protocol-xigrabdevice.c
>  protocol_xiwarppointer_SOURCES=$(COMMON_SOURCES) protocol-xiwarppointer.c
>  else
>  # Print that xi2-tests were skipped (exit code 77 for automake test harness)
> diff --git a/test/xi2/protocol-xigrabdevice.c b/test/xi2/protocol-xigrabdevice.c
> new file mode 100644
> index 0000000..f3044be
> --- /dev/null
> +++ b/test/xi2/protocol-xigrabdevice.c
> @@ -0,0 +1,123 @@
> +/**
> + * Copyright © 2013 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 XIGrabDevice request.
> + */
> +#include <stdint.h>
> +#include <X11/X.h>
> +#include <X11/Xproto.h>
> +#include <X11/extensions/XI2proto.h>
> +#include "inputstr.h"
> +#include "xigrabdev.h"
> +#include "mi.h"
> +
> +#include "protocol-common.h"
> +
> +static ClientRec client_request;
> +
> +int
> +__wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
> +{
> +    if (id == root.drawable.id) {
> +        *win = &root;
> +        return Success;
> +    }
> +    else if (id == window.drawable.id) {
> +        *win = &window;
> +        return Success;
> +    }
> +
> +    return __real_dixLookupWindow(win, id, client, access);
> +}
> +
> +static void
> +reply_XIGrabDevice(ClientPtr client, int len, char *data, void *closure)
> +{
> +    xXIGrabDeviceReply *rep = (xXIGrabDeviceReply *) data;
> +
> +    reply_check_defaults(rep, len, XIGrabDevice);
> +}
> +
> +static void
> +request_XIGrabDevice(ClientPtr client, xXIGrabDeviceReq * req,
> +                            int error, int errval)
> +{
> +    int rc;
> +
> +    rc = ProcXIGrabDevice(&client_request);
> +    assert(rc == error);
> +
> +    if (rc != Success)
> +        assert(client_request.errorValue == errval);
> +
> +}
> +
> +static unsigned char *data[4096];       /* the request buffer */
> +static void
> +test_XIGrabDevice(void)
> +{
> +    xXIGrabDeviceReq *request = (xXIGrabDeviceReq *) data;
> +
> +    request_init(request, XIGrabDevice);
> +
> +    request->grab_window = CLIENT_WINDOW_ID;
> +
> +    reply_handler = reply_XIGrabDevice;
> +    client_request = init_client(request->length, request);
> +
> +    request->deviceid = devices.vcp->id;
> +    request->grab_mode = XIGrabModeSync;
> +    request->paired_device_mode = XIGrabModeAsync;
> +    request_XIGrabDevice(&client_request, request, Success, 0);
> +    assert(devices.vcp->deviceGrab.grab->keyboardMode == XIGrabModeAsync);
> +    assert(devices.vcp->deviceGrab.grab->pointerMode == XIGrabModeSync);
> +
> +    request->deviceid = devices.vck->id;
> +    request->grab_mode = XIGrabModeSync;
> +    request->paired_device_mode = XIGrabModeAsync;
> +    request_XIGrabDevice(&client_request, request, Success, 0);
> +    assert(devices.vck->deviceGrab.grab->keyboardMode == XIGrabModeSync);
> +    assert(devices.vck->deviceGrab.grab->pointerMode == XIGrabModeAsync);
> +}
> +
> +int
> +main(int argc, char **argv)
> +{
> +    InitEvents();
> +    mieqInit();
> +
> +    init_simple();
> +
> +    /* Should go in protocol-common.c ? */
> +    window.realized = 1;
> +    screen.root = &root;
> +
> +    test_XIGrabDevice();
> +
> +    return 0;
> +}
> -- 
> 1.8.1.4
> 


More information about the xorg-devel mailing list