/*
* Copyright (c) 2005 X.Org Foundation L.L.C.
* 
* 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 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.
* 
* Copyright (c) Applied Testing and Technology, Inc. 1995
* All Rights Reserved.
* 
* 
* Portions of this software are based on Xlib and X Protocol Test Suite.
* We have used this material under the terms of its copyright, which grants
* free use, subject to the conditions below.  Note however that those
* portions of this software that are based on the original Test Suite have
* been significantly revised and that all such revisions are copyright (c)
* 1995 Applied Testing and Technology, Inc.  Insomuch as the proprietary
* revisions cannot be separated from the freely copyable material, the net
* result is that use of this software is governed by the ApTest copyright.
* 
* Copyright (c) 1990, 1991  X Consortium
* 
* 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 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
* X CONSORTIUM 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.
* 
* Except as contained in this notice, the name of the X Consortium shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from the X Consortium.
* 
* 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 name of UniSoft not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.  UniSoft
* makes no representations about the suitability of this software for any
* purpose.  It is provided "as is" without express or implied warranty.
* 
* Copyright (c) 2005 X.Org Foundation LLC
* 
* 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 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.
* 
* Copyright (c) Applied Testing and Technology, Inc. 1995
* All Rights Reserved.
* 
* 
* Portions of this software are based on Xlib and X Protocol Test Suite.
* We have used this material under the terms of its copyright, which grants
* free use, subject to the conditions below.  Note however that those
* portions of this software that are based on the original Test Suite have
* been significantly revised and that all such revisions are copyright (c)
* 1995 Applied Testing and Technology, Inc.  Insomuch as the proprietary
* revisions cannot be separated from the freely copyable material, the net
* result is that use of this software is governed by the ApTest copyright.
* 
* Copyright (c) 1990, 1991  X Consortium
* 
* 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 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
* X CONSORTIUM 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.
* 
* Except as contained in this notice, the name of the X Consortium shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from the X Consortium.
* 
* Copyright 1990, 1991 by 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 name of UniSoft not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.  UniSoft
* makes no representations about the suitability of this software for any
* purpose.  It is provided "as is" without express or implied warranty.
* 
* Copyright (c) 2005 X.Org Foundation LLC
* 
* 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 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.
* 
* Copyright (c) Applied Testing and Technology, Inc. 1995
* All Rights Reserved.
* 
* 
* Portions of this software are based on Xlib and X Protocol Test Suite.
* We have used this material under the terms of its copyright, which grants
* free use, subject to the conditions below.  Note however that those
* portions of this software that are based on the original Test Suite have
* been significantly revised and that all such revisions are copyright (c)
* 1995 Applied Testing and Technology, Inc.  Insomuch as the proprietary
* revisions cannot be separated from the freely copyable material, the net
* result is that use of this software is governed by the ApTest copyright.
* 
* Copyright (c) 1990, 1991  X Consortium
* 
* 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 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
* X CONSORTIUM 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.
* 
* Except as contained in this notice, the name of the X Consortium shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from the X Consortium.
* 
* Copyright 1990, 1991 by 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 name of UniSoft not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.  UniSoft
* makes no representations about the suitability of this software for any
* purpose.  It is provided "as is" without express or implied warranty.
* 
*/
/*
 * SYNOPSIS:
 *   void
 *   XDefineCursor(display, w, cursor)
 *   Display *display;
 *   Window w;
 *   Cursor cursor;
 */


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include	<stdlib.h>
#include	<stdio.h>
#include	<string.h>
#include	"xtest.h"
#include	"X11/Xlib.h"
#include	"X11/Xutil.h"
#include	"X11/Xresource.h"
#include	"X11/keysym.h"
#include	"tet_api.h"
#include	"xtestlib.h"
#include	"pixval.h"
#ifdef INPUTEXTENSION
#include        "X11/extensions/XInput.h"
#include        "XItest.h"
#endif

extern	Display	*Dsp;
extern	Window	Win;

extern	Window	ErrdefWindow;
extern	Drawable ErrdefDrawable;
extern	GC		ErrdefGC;
extern	Colormap ErrdefColormap;
extern	Pixmap	ErrdefPixmap;
extern	Atom	ErrdefAtom;
extern	Cursor	ErrdefCursor;
extern	Font	ErrdefFont;


#define T_XDefineCursor	1
char    *TestName = "XDefineCursor";

/*
 * Defines for different argument types
 */
#define A_DISPLAY display
#define A_WINDOW w
#define A_DRAWABLE w
#define A_CURSOR cursor


/*
 * Arguments to the XDefineCursor function
 */
static Display *display;
static Window w;
static Cursor cursor;


int 	tet_thistest;

/*
 * Called at the beginning of each test purpose to reset the
 * arguments to their initial values
 */
static void
setargs()
{
	display = Dsp;
	w = 0;
	cursor = 0;
}

/*
 * Set the arguments to default values for error tests
 */
static void
seterrdef()
{
	w = ErrdefWindow;
	cursor = ErrdefCursor;
}

static void t001(){

XVisualInfo		*vp;
int 	pass = 0, fail = 0;

 	report_purpose(1);

	report_assertion("Assertion XDefineCursor-1.(B)");
	report_assertion("A call to XDefineCursor sets the cursor for the window to");
	report_assertion("be cursor.");
	report_assertion("Reason for omission: There is no known portable test method for this assertion");

	report_strategy("If extended testing is required:");
	report_strategy("  Create a window.");
	report_strategy("  Obtain a non-default cursor.");
	report_strategy("  Set the window cursor using XDefineCursor.");
	report_strategy("  Verify that the window cursor is set correctly.");
	report_strategy("Otherwise:");
	report_strategy("  Create cursor.");
	report_strategy("  Create windows.");
	report_strategy("  Call XDefineCursor.");

	tpstartup();
	setargs();
	/* If extended testing is required: */
	if(noext(0) == False) {


		/* Create a window. */
		w = defwin(display);
		/* Obtain a non-default cursor. */
		cursor = makecur(display);
		/* Set the window cursor using xname. */
		startcall(display);
		if (isdeleted())
			return;
		XDefineCursor(display, w, cursor);
		endcall(display);
		if (geterr() != Success) {
			report("Got %s, Expecting Success", errorname(geterr()));
			FAIL;
		}

		/* Verify that the window cursor is set correctly. */
		if(curofwin(display, cursor, w) == False) {
			report("The cursor for the window was not set correctly.");
			FAIL;
		} else
			PASS;
	} else {

	/* Otherwise: */

		/* Create cursor. */
		cursor = makecur(display);
		/* Create windows. */
		for (resetvinf(VI_WIN); nextvinf(&vp); ) {
			w = makewin(display, vp);
		/* Call XDefineCursor. */
			startcall(display);
			if (isdeleted())
				return;
			XDefineCursor(display, w, cursor);
			endcall(display);
			if (geterr() != Success) {
				report("Got %s, Expecting Success", errorname(geterr()));
				FAIL;
			}
			if (geterr() != Success)
				FAIL;
			else
				CHECK;
		}	
		CHECKUNTESTED(nvinf());
	}

	tpcleanup();
	pfcount(pass, fail);
}

static void t002(){

Cursor	cursor2;
Window	altroot;
Bool	samedefcursor;
int 	pass = 0, fail = 0;

 	report_purpose(2);

	report_assertion("Assertion XDefineCursor-2.(B)");
	report_assertion("When the cursor is None and the window is the root window,");
	report_assertion("then the default cursor will be used.");
	report_assertion("Reason for omission: There is no known portable test method for this assertion");

	report_strategy("If extended testing is required:");
	report_strategy("  If the server supports two screens with the same default cursor:");
	report_strategy("    Set the root window cursor to a non-default cursor using XDefineCursor.");
	report_strategy("    Verify that the cursor was set correctly.");
	report_strategy("    Warp the pointer into the root window.");
	report_strategy("    Verify that the current cursor is that of the root window.");
	report_strategy("    Warp the pointer to the alternate root window.");
	report_strategy("    Verify that the current cursor is not the same as that of the default root window.");
	report_strategy("    Reset the cursor of the root window to the default cursor using XDefineCursor.");
	report_strategy("    Verify that the current cursor is the same as that of the default root window.");
	report_strategy("  Otherwise :");
	report_strategy("    Set the root window cursor to a non-default cursor using XDefineCursor.");
	report_strategy("    Verify that the cursor was set correctly.");
	report_strategy("    Warp the pointer to the root window.");
	report_strategy("    Verify that the current cursor is that of the root window.");
	report_strategy("    Reset the cursor of the root window to the default cursor using XDefineCursor.");
	report_strategy("    Verify that the root window cursor is no longer the non-default cursor.");
	report_strategy("Otherwise:");
	report_strategy("  Set window to root window.");
	report_strategy("  Call XDefineCursor with cursor set to None.");

	tpstartup();
	setargs();
	/* If extended testing is required: */
	if(noext(0) == False) {

		if(config.alt_screen != -1) {
			warppointer(display, DRW(display), 0,0);
			altroot = RootWindow(display, config.alt_screen);
			samedefcursor = spriteiswin(display, altroot);
		}

		/* If the server supports two screens with the same default cursor: */
		if(config.alt_screen != -1 && samedefcursor) {

			/* Set the root window cursor to a non-default cursor using xname. */
			cursor = makecur(display);
			w = DRW(display);
			startcall(display);
			if (isdeleted())
				return;
			XDefineCursor(display, w, cursor);
			endcall(display);
			if (geterr() != Success) {
				report("Got %s, Expecting Success", errorname(geterr()));
				FAIL;
			}
			
			/* Verify that the cursor was set correctly. */
			if(curofwin(display, cursor, w) == False) {
				report("%s() did not set the root window's cursor correctly.", TestName);
				FAIL;
			} else
				CHECK;

			/* Warp the pointer into the root window. */
			warppointer(display, w, 0,0);

			/* Verify that the current cursor is that of the root window. */
			if(spriteiswin(display, w) == False) {
				delete("Current cursor is not that of the root window.");
				return;
			} else
				CHECK;

			/* Warp the pointer to the alternate root window. */
			warppointer(display, altroot, 0,0);

			/* Verify that the current cursor is not the same as that of the default root window. */
			if(spriteiswin(display, DRW(display)) != False) {
				delete("The alternate root window's cursor was not set to the default cursor.");
				return;
			} else
				CHECK;

			/* Reset the cursor of the root window to the default cursor using xname. */
			cursor = None;
			startcall(display);
			if (isdeleted())
				return;
			XDefineCursor(display, w, cursor);
			endcall(display);
			if (geterr() != Success) {
				report("Got %s, Expecting Success", errorname(geterr()));
				FAIL;
			}

			/* Verify that the current cursor is the same as that of the default root window. */
			if(spriteiswin(display, DRW(display)) == False) {
				report("Root window's cursor was not set to the default cursor.");
				FAIL;
			} else
				CHECK;

			CHECKPASS(4);

		} else {

		/* Otherwise : */

			/* Set the root window cursor to a non-default cursor using xname. */
			cursor = cursor2 = makecur2(display);
			w = DRW(display);
			startcall(display);
			if (isdeleted())
				return;
			XDefineCursor(display, w, cursor);
			endcall(display);
			if (geterr() != Success) {
				report("Got %s, Expecting Success", errorname(geterr()));
				FAIL;
			}

			/* Verify that the cursor was set correctly. */
			if(curofwin(display, cursor, w) == False) {
				report("%s() did not set the root window's cursor correctly.", TestName);
				return;
			} else
				CHECK;

			/* Warp the pointer to the root window. */
			warppointer(display, w, 0,0);

			/* Verify that the current cursor is that of the root window. */
			if(spriteiswin(display, w) == False) {
				delete("Current cursor is not that of the root window.");
				return;
			} else
				CHECK;

			/* Reset the cursor of the root window to the default cursor using xname. */
			cursor = None;
			startcall(display);
			if (isdeleted())
				return;
			XDefineCursor(display, w, cursor);
			endcall(display);
			if (geterr() != Success) {
				report("Got %s, Expecting Success", errorname(geterr()));
				FAIL;
			}

			/* Verify that the root window cursor is no longer the non-default cursor. */
			if(curofwin(display, cursor2, w) != False) {
				report("%s() did not set the root window's cursor to the default cursor.", TestName);
				FAIL;
			} else
				CHECK;

			CHECKUNTESTED(3);
		}

	} else {

	/* Otherwise: */

		/* Set window to root window. */
		w = DRW(display);

		/* Call XDefineCursor with cursor set to None. */
		cursor = None;
		startcall(display);
		if (isdeleted())
			return;
		XDefineCursor(display, w, cursor);
		endcall(display);
		if (geterr() != Success) {
			report("Got %s, Expecting Success", errorname(geterr()));
			FAIL;
		}

		if (geterr() == Success)
			UNTESTED;
		else
			FAIL;
	}

	tpcleanup();
	pfcount(pass, fail);
}

static void t003(){

Cursor		cursor;
Cursor		cursor2;
XVisualInfo	*vp;
Window		parent;
struct area	ar;
int 	pass = 0, fail = 0;

 	report_purpose(3);

	report_assertion("Assertion XDefineCursor-3.(B)");
	report_assertion("When the cursor is None and the window is not the root");
	report_assertion("window, then the parent's cursor will be used.");
	report_assertion("Reason for omission: There is no known portable test method for this assertion");

	report_strategy("If extended testing is required:");
	report_strategy("  Create a window.");
	report_strategy("  Set the cursor of that window to a non-default cursor.");
	report_strategy("  Verify that the parent window's cursor is correctly set.");
	report_strategy("  Warp the pointer into the parent.");
	report_strategy("  Verify that the current cursor is that of the parent.");
	report_strategy("  Create a child of the window.");
	report_strategy("  Set the cursor of the child to a different cursor.");
	report_strategy("  Verify that the child window's cursor is correctly set.");
	report_strategy("  Warp the pointer into the child.");
	report_strategy("  Verify that the current cursor is not that of the parent.");
	report_strategy("  Verify that the current cursor is that of the child.");
	report_strategy("  Set the child's cursor to None using XDefineCursor.");
	report_strategy("  Verify that the current cursor is that of the parent window.");
	report_strategy("Otherwise:");
	report_strategy("  Create windows.");
	report_strategy("  Call XDefineCursor with cursor set to None.");

	tpstartup();
	setargs();
	/* If extended testing is required: */
	if(noext(0) == False) {

		/* Create a window. */
		parent = defwin(display);
		cursor2 = makecur2(display);

		/* Set the cursor of that window to a non-default cursor. */
		cursor = cursor2;
		w = parent;
		startcall(display);
		if (isdeleted())
			return;
		XDefineCursor(display, w, cursor);
		endcall(display);
		if (geterr() != Success) {
			report("Got %s, Expecting Success", errorname(geterr()));
			FAIL;
		}

		/* Verify that the parent window's cursor is correctly set. */
		if(curofwin(display, cursor2, parent) == False) {
			report("%s() did not set the parent's cursor correctly.", TestName);
			FAIL;
		} else
			CHECK;

		/* Warp the pointer into the parent. */
		warppointer(display, parent, 0,0);

		/* Verify that the current cursor is that of the parent. */
		if(spriteiswin(display, parent) == False) {
			delete("Current cursor is not that of the parent.");
			return;
		} else
			CHECK;

		/* Create a child of the window. */
		ar.x = 10;
		ar.y = 10;
		ar.width = 20;
		ar.height = 20;
		w = crechild(display, parent, &ar);

		/* Set the cursor of the child to a different cursor. */
		cursor = makecur(display);
		startcall(display);
		if (isdeleted())
			return;
		XDefineCursor(display, w, cursor);
		endcall(display);
		if (geterr() != Success) {
			report("Got %s, Expecting Success", errorname(geterr()));
			FAIL;
		}

		/* Verify that the child window's cursor is correctly set. */
		if(curofwin(display, cursor, w) == False) {
			report("%s() did not set the child's cursor correctly.", TestName);
			FAIL;
		} else
			CHECK;

		/* Warp the pointer into the child. */
		warppointer(display, w , 0,0);

		/* Verify that the current cursor is not that of the parent. */
		if(spriteiswin(display, parent) != False) {
			delete("Parent and child have the same cursor.");
			return;
		} else
			CHECK;

		/* Verify that the current cursor is that of the child. */
		if(spriteiswin(display, w) == False) {
			delete("Current cursor is not that of the child.");
			return;
		} else
			CHECK;

		/* Set the child's cursor to None using xname. */
		cursor = None;
		startcall(display);
		if (isdeleted())
			return;
		XDefineCursor(display, w, cursor);		
		endcall(display);
		if (geterr() != Success) {
			report("Got %s, Expecting Success", errorname(geterr()));
			FAIL;
		}

		/* Verify that the current cursor is that of the parent window. */
		if(spriteiswin(display, parent) == False) {
			report("Cursor did not change to that of the window.");
			FAIL;
		} else
			CHECK;

		CHECKPASS(6);

	} else {

	/* Otherwise: */

		/* Create windows. */
		for (resetvinf(VI_WIN); nextvinf(&vp); ) {
			w = makewin(display, vp);

		/* Call XDefineCursor with cursor set to None. */
			cursor = None;
			startcall(display);
			if (isdeleted())
				return;
			XDefineCursor(display, w, cursor);
			endcall(display);
			if (geterr() != Success) {
				report("Got %s, Expecting Success", errorname(geterr()));
				FAIL;
			}
			if (geterr() != Success)
				FAIL;
			else
				CHECK;
		}
	
		CHECKUNTESTED(nvinf());
	}

	tpcleanup();
	pfcount(pass, fail);
}

static void t004(){

XVisualInfo	*vp;
int 	pass = 0, fail = 0;

 	report_purpose(4);

	report_assertion("Assertion XDefineCursor-4.(B)");
	report_assertion("When the cursor is other than None, then a call to");
	report_assertion("XDefineCursor sets the cursor for the window to be cursor");
	report_assertion("and causes the cursor to be displayed when the pointer is in");
	report_assertion("the window.");
	report_assertion("Reason for omission: There is no known portable test method for this assertion");

	report_strategy("If extended testing is required:");
	report_strategy("  Create a window.");
	report_strategy("  Set the window cursor to a non-default cursor.");
	report_strategy("  Verify that the window cursor is set correctly.");
	report_strategy("  Warp the pointer into the window.    ");
	report_strategy("  Verify that the current cursor is that of the window.");
	report_strategy("Otherwise:");
	report_strategy("  Create cursor.");
	report_strategy("  Create windows.");
	report_strategy("  Call XDefineCursor with cursor other than None.");

	tpstartup();
	setargs();
	/* If extended testing is required: */
	if(noext(0) == False) {

		cursor = makecur(display);
		/* Create a window. */
		w = defwin(display);
		
		/* Set the window cursor to a non-default cursor. */
		startcall(display);
		if (isdeleted())
			return;
		XDefineCursor(display, w, cursor);
		endcall(display);
		if (geterr() != Success) {
			report("Got %s, Expecting Success", errorname(geterr()));
			FAIL;
		}

		/* Verify that the window cursor is set correctly. */
		if(curofwin(display, cursor, w) == False) {
			report("The cursor for the window was not set correctly.");
			FAIL;
		} else
			CHECK;

		/* Warp the pointer into the window. */		
		warppointer(display, w, 0,0);

		/* Verify that the current cursor is that of the window. */
		if(spriteiswin(display, w) == False) {
			report("Cursor did not change to that of the window.");
			FAIL;
		} else
			CHECK;

		CHECKPASS(2);

	} else {

	/* Otherwise: */

		/* Create cursor. */
		cursor = makecur(display);

		/* Create windows. */
			for (resetvinf(VI_WIN); nextvinf(&vp); ) {
				w = makewin(display, vp);

		/* Call xname with cursor other than None. */
				startcall(display);
				if (isdeleted())
					return;
				XDefineCursor(display, w, cursor);
				endcall(display);
				if (geterr() != Success) {
					report("Got %s, Expecting Success", errorname(geterr()));
					FAIL;
				}
				if (geterr() != Success)
					FAIL;
				else
					CHECK;
			}

		CHECKUNTESTED(nvinf());
	}	

	tpcleanup();
	pfcount(pass, fail);
}

/* Including from file error/ECur.mc */
/* End of included file error/ECur.mc */

/* Including from file error/ECur.mc */
static void t005(){

unsigned int shape;
int 	pass = 0, fail = 0;

 	report_purpose(5);

	report_assertion("Assertion XDefineCursor-5.(A)");
	report_assertion("When a cursor argument does not name a valid Cursor, then a");
	report_assertion("BadCursor error occurs.");

	report_strategy("Create cursor with shape XT_FONTCURSOR_GOOD in font cursor.");
	report_strategy("Free cursor.");
	report_strategy("Call test function using bad cursor as the cursor argument.");
	report_strategy("Verify that a BadCursor error occurs.");

	tpstartup();
	setargs();
	seterrdef();

	/* UNSUPPORTED is not allowed */
	shape = config.fontcursor_good;
	if (config.fontcursor_good == -1) {
		delete("A value of UNSUPPORTED is not allowed for XT_FONTCURSOR_GOOD");
		return;
	}

	A_CURSOR = XCreateFontCursor(A_DISPLAY, shape);
	XFreeCursor(A_DISPLAY, A_CURSOR);

	startcall(display);
	if (isdeleted())
		return;
	XDefineCursor(display, w, cursor);
	endcall(display);
	if (geterr() != BadCursor) {
		report("Got %s, Expecting BadCursor", errorname(geterr()));
		FAIL;
	}

	if (geterr() == BadCursor)
		PASS;
	else
		FAIL;
	tpcleanup();
	pfcount(pass, fail);
}

/* End of included file error/ECur.mc */

/* Including from file error/EWin.mc */
/* End of included file error/EWin.mc */

/* Including from file error/EWin.mc */
static void t006(){

int 	pass = 0, fail = 0;

 	report_purpose(6);

	report_assertion("Assertion XDefineCursor-6.(A)");
	report_assertion("When a window argument does not name a valid Window, then a");
	report_assertion("BadWindow error occurs.");

	report_strategy("Create a bad window by creating and destroying a window.");
	report_strategy("Call test function using bad window as the window argument.");
	report_strategy("Verify that a BadWindow error occurs.");

	tpstartup();
	setargs();
	seterrdef();

	A_WINDOW = badwin(A_DISPLAY);

	startcall(display);
	if (isdeleted())
		return;
	XDefineCursor(display, w, cursor);
	endcall(display);
	if (geterr() != BadWindow) {
		report("Got %s, Expecting BadWindow", errorname(geterr()));
		FAIL;
	}

	if (geterr() == BadWindow)
		PASS;
	else
		FAIL;

	tpcleanup();
	pfcount(pass, fail);
}

/* End of included file error/EWin.mc */

/* End of Test Cases */


struct tet_testlist tet_testlist[] = {
	{ t001, 1 },
	{ t002, 2 },
	{ t003, 3 },
	{ t004, 4 },
	{ t005, 5 },
	{ t006, 6 },
	{ NULL, 0 }
};

int 	ntests = sizeof(tet_testlist)/sizeof(struct tet_testlist)-1;

void	(*tet_startup)() = fontstartup;
void	(*tet_cleanup)() = fontcleanup;
