>># 
>># Copyright 1990, 1991 by the Massachusetts Institute of Technology and
>># UniSoft Group Limited.
>># 
>># Permission to use, copy, modify, distribute, and sell this software and
>># its documentation for any purpose is hereby granted without fee,
>># provided that the above copyright notice appear in all copies and that
>># both that copyright notice and this permission notice appear in
>># supporting documentation, and that the names of MIT and UniSoft not be
>># used in advertising or publicity pertaining to distribution of the
>># software without specific, written prior permission.  MIT and UniSoft
>># make no representations about the suitability of this software for any
>># purpose.  It is provided "as is" without express or implied warranty.
>># 
>># $XConsortium: sndevnt.m,v 1.19 92/06/11 17:25:24 rws Exp $
>># 
>>#
>>TITLE XSendEvent CH08
>>ASSERTION A XSendEvent-1
A call to XSendEvent sends event_send to window w.
>>STRATEGY
Create window.
Discard all events in the event queue.
Call XSendEvent to send a KeyPress event to creator of window.
Verify that XSendEvent returned non-zero.
Verify that event was received.
Verify that send_event was not set to False.
Repeat for each event-type.
>>ASSERTION A XSendEvent-2
When w is PointerWindow, then the destination window is
the window that contains the pointer.
>>STRATEGY
Create window.
Select KeyPress-type events on window.
Grab server.
Enable synchronization.
Save initial pointer location.
Warp pointer to window.
Get new pointer location.
Discard all events in the event queue.
Call XSendEvent to send a KeyPress event to window containing pointer.
Get current pointer location.
Check to see if pointer moved.
Warp pointer back to where it started.
Disable synchronization.
Ungrab server.
Verify that XSendEvent returned non-zero.
Verify that event was received.
Verify that send_event was not set to False.
>>ASSERTION A XSendEvent-3
When w is InputFocus and an inferior of the focus window
contains the pointer, then the destination window is that
inferior.
>>STRATEGY
Create client2.
Create parent window.
Create inferior window.
Select KeyPress-type events on parent window with client2.
Flush client2 requests.
Select KeyPress-type events on child window.
Grab server.
Enable synchronization.
Set input focus to parent window.
Save initial pointer location.
Warp pointer to inferior of focus window.
Get new pointer location.
Discard all events in the event queue.
Call XSendEvent to send a KeyPress event to inferior of the focus window.
Get current pointer location.
Check to see if pointer moved.
Warp pointer back to where it started.
Disable synchronization.
Ungrab server.
Verify that XSendEvent returned non-zero.
Verify that event was received for inferior of focus window.
Verify that send_event was not set to False.
Verify that event was not received for focus window.
>>ASSERTION A XSendEvent-4
When w is InputFocus and an inferior of the focus window
does not contain the pointer, then the destination window is
the focus window.
>>STRATEGY
Create window.
Select KeyPress-type events on new focus window.
Set input focus to new focus window.
Discard all events in the event queue.
Call XSendEvent to send a KeyPress event to inferior of the focus window.
Verify that XSendEvent returned non-zero.
Verify that event was received for inferior of focus window.
Verify that send_event was not set to False.
>>ASSERTION - XSendEvent-5
When event_mask is set to NoEventMask, then a call to
XSendEvent results in event_send being sent to the client
that created the destination window.
>>ASSERTION A XSendEvent-6
When event_mask is set to NoEventMask and the client that
created the destination window w no longer exists, then no
event is sent.
>>STRATEGY
Create client2.
Call XSetCloseDownMode with RetainPermanent for client2.
Create window for client2.
Call XCloseDisplay for client2.
Select ALLEVENTS on window.
Call XSendEvent to send event to window.
Verify that XSendEvent returned non-zero.
Verify that no events were received.
>>ASSERTION A XSendEvent-7
When event_mask is not set to NoEventMask and no clients
have selected on the destination window and propagate is
False, then a call to XSendEvent results in no event being
sent.
>>STRATEGY
Create window.
Select no events on window.
Set propagate to False.
Set event_mask to something other than NoEventMask.
Discard all events in the event queue.
Call XSendEvent.
Verify that XSendEvent returned non-zero.
Verify that no events were received.
>>ASSERTION A XSendEvent-8
When event_mask is not set to NoEventMask and no clients
have selected on the destination w and propagate is True and
there is no matching ancestor of the destination w for which
no intervening window has that type in its
do-not-propagate-mask, then a call to XSendEvent results in
no event being sent.
>>STRATEGY
Create a window hierarchy.
Create a hierarchy member with KeyPressMask set in do_not_propagate_mask.
Create a child of this member without setting do_not_propagate_mask.
Create the hierarchy.
Select no events on the destination w.
Select for KeyPress on the grandparent window of this member.
Set w to the window corresponding to child node.
Set propagate to True.
Set event_mask to KeyPressMask.
Set event type to KeyPress.
Call XSendEvent.
Verify that XSendEvent returned non-zero.
Verify that no events were received.
Select for no events on the grandparent window of this member.
Call XSendEvent.
Verify that XSendEvent returned non-zero.
Verify that no events were received.
Change the do_not_propagate_mask from KeyPressMask to NoEventMask.
Call XSendEvent.
Verify that XSendEvent returned non-zero.
Verify that no events were received.
>>ASSERTION A XSendEvent-9
When event_mask is not set to NoEventMask and w is set to
InputFocus and an inferior of the focus window contains the
pointer and no clients have selected on that inferior, then
a call to XSendEvent results in no event being sent.
>>STRATEGY
Create client2.
Create parent window.
Create inferior window.
Select KeyPress-type events on parent window with client2.
Flush client2 requests.
Select no events on child window.
Grab server.
Enable synchronization.
Set input focus to parent window.
Save initial pointer location.
Warp pointer to inferior of focus window.
Get new pointer location.
Discard all events in the event queue.
Call XSendEvent to send a KeyPress event to inferior of the focus window.
Get current pointer location.
Check to see if pointer moved.
Warp pointer back to where it started.
Disable synchronization.
Ungrab server.
Verify that XSendEvent returned non-zero.
Verify that no event was received for focus window.
Verify that event was not received for client2.
>>ASSERTION A XSendEvent-10
When event_mask is not set to NoEventMask and w is set to
InputFocus and an inferior of the focus window does not
contain the pointer and no clients have selected on the
focus window, then a call to XSendEvent results in no event
being sent.
>>STRATEGY
Create window.
Grab server.
Enable synchronization.
Set input focus to new focus window.
Save initial pointer location.
Warp pointer away from inferior of focus window; to root.
Get new pointer location.
Select no events on new focus window.
Discard all events in the event queue.
Call XSendEvent with propagate == False, w == InputFocus & event_mask == KeyPressMask.
Get current pointer location.
Check to see if pointer moved.
Warp pointer back to where it started.
Disable synchronization.
Ungrab server.
Verify that XSendEvent returned non-zero.
Verify that no event was received.
Grab server.
Enable synchronization.
Set input focus to new focus window.
Save initial pointer location.
Warp pointer away from inferior of focus window; to root.
Get new pointer location.
Call XSendEvent again with propagate set to True.
Get current pointer location.
Check to see if pointer moved.
Warp pointer back to where it started.
Disable synchronization.
Ungrab server.
Verify that XSendEvent returned non-zero.
Verify that no event was received.
>>ASSERTION A XSendEvent-11
When event_mask is not set to NoEventMask and no clients
have selected on the destination w and propagate is True and
there is a matching ancestor of the destination w for which
no intervening window has that type in its
do-not-propagate-mask and that ancestor is an ancestor of
the focus window and InputFocus was not specified as the
destination, then a call to XSendEvent results in the event
being sent to all clients selecting a type in event_mask on
the first matching ancestor.
>>STRATEGY
Set event_mask to KeyPressMask.
Set propagate to True.
Create window hierarchy with depth of three and with all windows
have no bits set in their do-not-propagate-mask.
Set focus window to window mid-level in window hierarchy.
Set w to window at bottom of window hierarchy.
Create client2.
Select no events on w.
Select no events on w with client2.
Select KeyPress events on top-level window in window hierarchy.
Select KeyPress events on top-level window in window hierarchy
with client2.
Call XSendEvent to send a KeyPress event to w.
Verify that XSendEvent returned non-zero.
Verify that event was received for top-level window in window hierarchy.
Verify that send_event was not set to False.
Verify that event was received for top-level window in window hierarchy
for client2.
Verify that send_event was not set to False for client2.
>>ASSERTION A XSendEvent-12
When event_mask is not set to NoEventMask and no clients
have selected on the destination w and propagate is True and
there is a matching ancestor of the destination w for which
no intervening window has that type in its
do-not-propagate-mask and this ancestor is not an ancestor
of the focus window, then a call to XSendEvent results in
the event being sent to all clients selecting a type in
event_mask on the first matching ancestor.
>>STRATEGY
Set event_mask to KeyPressMask.
Set propagate to True.
Create window hierarchy with depth of three and with all windows
have no bits set in their do-not-propagate-mask.
Set focus window to top window in window hierarchy.
Set w to window at bottom of window hierarchy.
Create client2.
Select no events on w.
Select no events on w with client2.
Select KeyPress events on mid-level window in window hierarchy.
Select KeyPress events on mid-level window in window hierarchy
with client2.
Call XSendEvent to send a KeyPress event to w.
Verify that XSendEvent returned non-zero.
Verify that event was received for mid-level window in window hierarchy.
Verify that send_event was not set to False.
Verify that event was received for mid-level window in window hierarchy
for client2.
Verify that send_event was not set to False for client2.
>>ASSERTION A XSendEvent-13
A call to XSendEvent ignores active grabs.
>>STRATEGY
Create window.
Select ALLEVENTS on this window.
Set propagate to False.
Create client2.
Create window with client2.
Grab the pointer with client2 using client2's window as the grab window,
owner_events set to False, event_mask set to PointerMotionMask,
pointer_mode set to GrabModeSync, and keyboard_mode set to GrabModeSync.
Verify that XGrabPointer returned GrabSuccess.
Grab AnyButton with client2 using client2's window as the grab window,
owner_events set to False, event_mask set to ButtonPressMask,
pointer_mode set to GrabModeSync, and keyboard_mode set to GrabModeSync.
Grab the keyboard with client2 using client2's window as the grab window,
owner_events set to False, pointer_mode set to GrabModeSync,
and keyboard_mode set to GrabModeSync.
Verify that XGrabKeyboard returned GrabSuccess.
Set event_mask to PointerMotionMask.
Flush display, discarding events.
Flush client2, discarding events.
Call XSendEvent to send a MotionNotify event.
Verify that XSendEvent returned non-zero.
Flush display, not discarding events.
Flush client2, not discarding events.
Verify that event was received.
Verify that send_event was not set to False.
Verify that client2 received no events.
Set event_mask to ButtonPressMask.
Flush display, discarding events.
Flush client2, discarding events.
Call XSendEvent to send a ButtonPress event.
Verify that XSendEvent returned non-zero.
Flush display, not discarding events.
Flush client2, not discarding events.
Verify that event was received.
Verify that send_event was not set to False.
Verify that client2 received no events.
Set event_mask to KeyPressMask.
Flush display, discarding events.
Flush client2, discarding events.
Call XSendEvent to send a KeyPress event.
Flush display, not discarding events.
Flush client2, not discarding events.
Verify that XSendEvent returned non-zero.
Verify that event was received.
Verify that send_event was not set to False.
Verify that client2 received no events.
Ungrab the keyboard with client2.
Ungrab buttons with client2.
Ungrab the pointer with client2.
>>ASSERTION A XSendEvent-14
On a call to XSendEvent the only fields in the forwarded
event which are changed are the send_event and serial
fields.
>>STRATEGY
Create window.
Set type member of event to KeyPress.
Set serial member of event to 0.
Set send_event member of event to False.
Ignore display member of event, as it's filled in by Xlib.
Set window member of event to -1.
Discard all events in the event queue.
Call XSendEvent to send event to creator of window.
Verify that XSendEvent returned non-zero.
Verify that event was received.
Verify that type was set to KeyPress.
Verify that serial was not set to 0.
Verify that send_event was not set to False.
Check display member of event was filled in by Xlib properly.
Verify that window was set to 0.
Repeat for each event-type.
>>ASSERTION - XSendEvent-15
On a call to XSendEvent the send_event field in the
forwarded event is set to True.
>>ASSERTION A XSendEvent-16
On a call to XSendEvent the serial field in the forwarded
event is set correctly.
>>STRATEGY
Create window.
Set serial to zero.
Call NextRequest to get correct serial.
Call XSendEvent.
Verify that XSendEvent returned non-zero.
Verify that event was received.
Verify that serial in delivered event is set correctly.
>>ASSERTION A XSendEvent-17
The b member of the data union is an array of 20 chars.
>>STRATEGY
Set type to ClientMessage.
Verify that the size of the b member of the data union is 20 bytes.
>>ASSERTION A XSendEvent-18
The s member of the data union is an array of 10 shorts.
>>STRATEGY
Set type to ClientMessage.
Verify that the size of the s member of the data union is 20 bytes.
>>ASSERTION A XSendEvent-19
The l member of the data union is an array of 5 longs.
>>STRATEGY
Set type to ClientMessage.
Verify that the size of the l member of the data union is 20 bytes.
>>ASSERTION A XSendEvent-20
When event_send is a ClientMessage-type event and the
format field of event_send is not one of 8, 16, or 32, then
either XSendEvent returns zero or a BadValue error occurs.
>>STRATEGY
Create window.
Set format field of event_send to 0.
Call XSendEvent to send ClientMessage-type event.
Verify that XSendEvent either returned zero and no error occurs,
	or returned non-zero and a BadValue error occurs.
>>ASSERTION A XSendEvent-21
When the event in event_send is not one of the core events
or one of the events defined by an extension, then either
XSendEvent returns zero or a BadValue error occurs.
>>STRATEGY
Create window.
Use notmember() to get some bad event types.
Make sure this list also includes 0 and 1 which are specifically for errors and replies.
Call XSendEvent to send bad event type.
Verify that XSendEvent either returned zero and no error occurs,
	or returned non-zero and a BadValue error occurs.
>>ASSERTION A XSendEvent-22
When a window argument does not name a valid window, then a
BadWindow error occurs.
>>STRATEGY
Create a bad window by creating and destroying a window.
Initialise the event structure for the call.
Verify that a BadWindow error occurs.
