
/* $XConsortium: editmode3.pi,v 5.2 94/04/17 20:46:57 rws Exp $ */

/*****************************************************************

Copyright (c) 1989, 1990, 1991,1990  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 (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, 
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 Sun Microsystems,
and the X Consortium, not be used in advertising or publicity 
pertaining to distribution of the software without specific, written 
prior permission.  

SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

## editmode3.pi - test functionity of REPLACE (and INSERT) edit mode. 
## Try replacing a first element, last element,
## and middle element.  Also use INSERT mode to build up structure.

tbegintest("editmode3","Editing structures with REPLACE mode");

source macro.pi		/* general testing utility macros */
source strmacro.pi	/* macros for structure content area */
source apimacro.pi	/* macros for api-specific functions */

# Set up phigs, workstation, and structure
api_open_phigs(NULL,PDEF_MEM_SIZE);
api_open_ws(1);
popen_struct(1);
ppost_struct(1,1,1.0);

# Set REPLACE mode
pset_edit_mode(PEDIT_REPLACE);

# Add an element to the empty structure (edge colour index)
# (struct should become: (MARKER_SCALE_FACTOR))
pset_marker_size(1.0);
im_confirm_elemptr(1, 
	"failed: Elem ptr %d, not 1, after adding element to empty struct\n");
im_confirm_elemtype(1, 1, PELEM_MARKER_SIZE, 
	"failed: First element added, %d, should be MARKER_SCALE_FACTOR\n");

# Adding another element (interior color index) should replace the marker size
# (struct should become (LINETYPE))
pset_linetype(1);
im_confirm_elemptr(1, "failed: elem pointer is %d, should have stayed 1\n");
im_confirm_elemtype(1, 1, PELEM_LINETYPE,
	"failed: element type %d should have been replaced by PELEM_LINETYPE");

# Set INSERT mode, add a couple more structure elements
# (struct should become: (LINETYPE, LABEL, MARKERTYPE))
pset_edit_mode(PEDIT_INSERT);
plabel(2);
pset_marker_type(3);
im_confirm_elemptr(3, "failed: elem pointer, %d, should have advanced to 3\n");
im_confirm_elemtype(1, 2, PELEM_LABEL, 
	"failed: element 2 was %d, expected PELEM_LABEL\n");
im_confirm_elemtype(1, 3, PELEM_MARKER_TYPE,
	"failed: element 3 was %d, expected PEL_MARKERTYPE\n");

# Set mode back to REPLACE
pset_edit_mode(PEDIT_REPLACE);
pinq_edit_mode(&err, &mode);
im_chkerr(err, "pinq_edit_mode");
im_ifneq(mode, PEDIT_REPLACE, "failed: Edit mode %d not reset to REPLACE\n", mode);

# replace last element with EDGE TYPE
# (struct should become: (LINETYPE, LABEL, EDGETYPE))
pset_edgetype(3);
im_confirm_elemptr(3, "failed: elem pointer %d should be 3\n");
im_confirm_elemtype(1, 3, PELEM_EDGETYPE, 
	"failed: element %d should have been replaced by PELEM_EDGETYPE\n");

# replace middle element 2 with line width
# (struct should become: (LINETYPE, LINEWIDTH, EDGETYPE))
pset_elem_ptr(2);
pset_linewidth(2.0);
im_confirm_elemptr(2, "failed: elem ptr %d didn't remain 2 in REPLACE mode\n");
im_confirm_elemtype(1, 2, PELEM_LINEWIDTH,
	"failed: second element %d not replaced by LINEWIDTH\n");
pinq_elem_type_size(1, 3, &error, &actualtype, &elemsize); 
if (actualtype != PELEM_EDGETYPE) 
    if (actualtype == PELEM_LINEWIDTH) 
        tfprintf("failed: element  %d AFTER elem ptr replaced\n", 3); 
    else
        tfprintf("failed: 3rd element %d should be LINEWIDTH\n", actualtype);
    endif
endif  
# test length of structure by setting elem ptr to high number
pset_elem_ptr(666);
im_confirm_elemptr(3, "elem pointer was %d, expected last elem to be 3\n");



pclose_struct();
pclose_ws(1);
pclose_phigs();
tendtest();
