/* $XConsortium: elemcon9.c,v 5.4 94/04/17 20:46:58 hersh Exp $ */ /***************************************************************** Copyright (c) 1989,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 (c) 1989,1990, 1991 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. ******************************************************************/ /* ## elemcon9.c - test pinq_elem_type_size, pinq_elem_content, ## pinq_cur_elem_type_size, and pinq_cur_elem_content, as well ## as archiving and structure copying, for all element types. ## Command line switches turn on or off the different ## types of testing, and integer arguments specify structure ## elements to be stored; these two types of arguments can ## be freely intermixed. Test execution scripts may choose ## to execute this test multiple times with different sets ## of elements. * * Usage: command line arguments consist of integers specifying test * cases, and the following flags: * -a (+a) : turn off (on) archive testing; the default is off * -c (+c) : turn off (on) element content testing; default is on * * These flags may be freely intermixed with the integers specifying * cases; they will only have effect on the cases following them in * the command line (thus, they should be placed first, unless * you want to perform different tests later in the test set). * * The integers specifying element types correspond solely to * where they occur in the big switch statement in main(), not * to anything in any standard. This list currently consists * of Phigs elements in roughly alphabetical order, followed by * Phigs+ elements in alphabetical order, but this is not * guaranteed to remain true (i.e. elements may be added that * are out of alphabetical order). * * To add new elements, add a new case in the big switch, * a handler for the element in i_compare_element() in * tools/pexint/computils.c, and adjust the number in the * error message printed in the default case at the end of *the big switch. * * To add new test types, add: a new flag variable, a new case * in element_test, new cases in both argument switches at the beginning * of main(), a new letter in the error output message at the * very end of the big switch, and a new line in the comment above. */ #include "phigs/phigs.h" #include "X11/Xlib.h" #include "X11/Xutil.h" #include "X11/Xatom.h" #include #include "logmsg.h" #include "imath.h" #include "computils.h" #include "testutils.h" #define STR1 1 #define WS1 1 #define DEST_STR 88 /* * Sample data for some simple-valued items */ #define SAMPLE_ANNOT_STYLE 2 #define SAMPLE_TEXT_HEIGHT 5.5 /* * flag variables specifying what kinds of testing are performed */ int test_content = 1; int test_archive = 0; int test_copy = 0; /* * element_test() - perform a set of tests on the specified element * according to current values of test_content and test_archive. * if test_content is true, then the element's content is read * back and compared against the expected (assumes that the current * element in the current structure is the one being compared against). * if test_archive is true, then archive tests are performed. */ void element_test(type_num,struct_id, element, expecttype, expectdata, element_name) int type_num; /* number of test case, corresponding */ /* to element type (where the number */ /* of a type is determined solely by */ /* where it is placed in the big switch */ /* in main() ) */ Pint struct_id; Pint element; Pelem_type expecttype; Pelem_data *expectdata; char *element_name; /* string naming the element type */ { Pint_list strs; Popen_struct_status st_status; /* for inquiring current open struct */ Pint error; Pint saved_ptr, saved_struct; /* original element pointer and structid */ Pint dest_ptr; /* starting elemptr in destination struct */ char elname_plus_note[100]; /* element name plus comment */ strs.num_ints = 1; strs.ints = &struct_id; if (test_content) { /* perform test of inquiring element content */ tvprintf(2, "testing content of element %d, type %d=%s\n", element, type_num, element_name); i_check_element(struct_id, element, expecttype, expectdata, element_name); i_check_current_element(expecttype, expectdata, element_name); } if (test_archive) { /* perform archive tests */ tvprintf(2,"testing archiving for element %d, type %d=%s\n", element, type_num, element_name); unlink("archfile"); popen_ar_file(1,"archfile"); par_all_structs(1); pclose_struct(); punpost_struct(WS1,STR1); pdel_all_structs(); pret_all_structs(1); pclose_ar_file(1); i_check_element(struct_id, element, expecttype, expectdata, element_name); popen_struct(STR1); ppost_struct(WS1,STR1,1.0); } if (test_copy) { pinq_open_struct(&error, &st_status, &saved_struct); if (st_status == PSTRUCT_OPEN) { /* save element pointer, struct id for later restoration */ pinq_elem_ptr(&error, &saved_ptr); pclose_struct(); } popen_struct(DEST_STR); pinq_elem_ptr(&error, &dest_ptr); pcopy_all_elems_struct(struct_id); sprintf(elname_plus_note, "%s(copied)", element_name); i_check_element(DEST_STR, element+dest_ptr, expecttype, expectdata, elname_plus_note); pclose_struct(); if (st_status == PSTRUCT_OPEN) { popen_struct(saved_struct); pset_elem_ptr(saved_ptr); } } } main(argc,argv) int argc; char *argv[]; { int i,j, length; char *description; int argument; int testcase; Window ws_window; Display *ws_display; int curr_element = 0; /* variables and structures for sample data */ Pelem_data peldata; static Pint tenpints[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, sixpints[6] = {11, 12, 13, 14, 15, 16}; static Pint_list pintlist = {10, tenpints}, pintlist2 = {6, sixpints}; static Ptext_align ptxalign = { PHOR_LEFT, PVERT_HALF }; static Pvec pvector = { 19.5, 6.25 } ; static Pfloat_size pfloat_s = { 19.5, 6.25 } ; static Pvec3 pvector3a = {0.0, 1.0, 0.0}, ref_vectors[2] = {{0.0, 0.9, 0.1}, {0.2, 0.5, 0.5}}; static Pvec3 pvector3_array[] = {{0.0, 1.0, 0.0}, {0.5, 0.5, 0.2}, {0.5, 0.2, 0.1}, {0.1, 0.7, 0.2}, {0.2, 0.5, 0.3}, {0.1, 0.1, 0.8}}; static Ppoint ppoint = { 12.5, 4.0 }; static Ppoint3 ppoint3 = { 4.25, 5.0, 6.05}; static Pdata pdata = { 29, "some sample application data"}; static Prect prect = { {0.3, 0.3} , {0.7, 0.7}}; static Pint_size pdim = { 4, 3 }; static Pint color_array[3][4] = { {2, 2, 2, 2}, {2, 4, 4, 2}, {2, 4, 4, 2} }; static Ppat_rep patrep = {{4, 3}, color_array[0]}; static Pparal pgram = {{0.1, 0.1, 0.1}, {0.9, 0.1, 0.3}, {0.2, 0.7, -1.0}}; static Ppoint ppoints[] = { {0.5, 0.2}, {0.7, 0.2}, {0.1, 0.8} }, ppoints_b[] = { {0.1, 0.1}, {0.3, 0.1}, {0.9, 0.8}, {0.1, 0.15} }; static Ppoint3 ppoint3s[] = { {0.5, 0.5, 0.5}, {0.7, 0.3, 0.6}, {0.1, 2.3, 0.1} }, ppoint3s_b[] = { {0.5, 0.1, 1.2}, {0.4, 0.2, 0.0}, {0.8, 0.1, 0.0}, {0.2, 0.1, 0.0}, {0.1, 0.4, 0.1}, {0.5, 0.4, 0.2}}; static Ppoint_list two_ppoints[] = { {3, ppoints}, {4, ppoints_b} }; static Ppoint_list_list ppoints_list; static Ppoint_list3 two_ppoint3s[] = { {3, ppoint3s}, {4, ppoint3s_b} }; static Ppoint_list_list3 ppoints_list3; static Pmatrix pmatrix = { {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {3.2, 1.5, 1.0}}; static Pmatrix3 pmatrix3 = { {1.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {4.5, 3.2, 1.5, 1.0}}; static Phalf_space phalf[3] = {{{0.5, 0.2},{1.0, 0.0}}, /* halfspace 1 */ {{0.2, 0.0},{0.0, 1.0}}, /* halfspace 2 */ {{0.9, 0.9},{-1.0,0.0}}}; /* halfspace 3 */ static Phalf_space_list phalflst = { 3, phalf}; static Phalf_space3 phalf3[3] = {{{0.5, 0.2, 0.0}, {1.0, 0.0, 0.0}}, /* halfspace 1 */ {{0.2, 0.0, 0.5}, {0.0, 1.0, 0.0}}, /* halfspace 2 */ {{0.9, 0.9, 0.2}, {-1.0, 0.0, 0.0}}}; /* halfspace 3 */ static Phalf_space_list3 phalflst3 = { 3, phalf3}; Pgcolr pgcolr; Prefl_props parea_props; /* for fill area set3 w/ data */ Pfacet_data3 pfacet_data; static Pedge_flag flags[] = {PEDGE_ON, PEDGE_OFF, PEDGE_ON, PEDGE_OFF}; static Pedge_data_list pedge_data[2]; Pptconorm3 ptconorm1[3], ptconorm2[4]; static struct { /* hsv colors for vertices */ Pfloat h; Pfloat s; Pfloat v; } vcolors1[3] = {0.1,0.1,0.1, 0.2,0.2,0.2, 0.3,0.3,0.3}, vcolors2[4] = {0.4,0.4,0.4, 0.5,0.5,0.5, 0.6,0.6,0.6, 0.7,0.7,0.7}; static Pvec3 normals1[] = { {0.5, 0.5, 0.0}, /* normals for */ {0.7, 0.3, 0.1}, /* vertices */ {0.1, 0.3, 0.1} }, normals2[] = { {0.5, 0.1, 0.3}, {0.4, 0.2, 0.0}, {0.8, 0.1, 0.0}, {0.2, 0.1, 0.6} }; Pfacet_vdata_list3 pfacet_vdata[2]; /* for ppolyline_set3_data: */ Pptco3 ptco1[3], ptco2[4]; Pline_vdata_list3 pline_vdata[2]; /* for quad3_data and tri3_data: */ Pfacet_data_arr3 facet_arr; Pconorm3 conorms[2]; Pfacet_vdata_arr3 vertex_arr; Pptconorm3 ptconorms[6]; static Pint_size quad_dims = { 2, 3 }; /* put arguments into test description string */ for (i=1, length=0; i < argc; i++) length += strlen(argv[i]) + 1; /* one extra for space */ description = (char *) malloc(length + 50); strcpy(description, "inquiring element type, size, content ("); for (i=1; i < argc; i++) { strcat(description, argv[i]); if (i != argc-1) strcat(description, " "); } strcat(description, ")"); tbegintest("elemcon9", description); /* Set up phigs, workstation, and structure */ i_open_phigs(NULL, PDEF_MEM_SIZE); i_open_x_ws(WS1, &ws_display, &ws_window, 300, 100, 200, 200); popen_struct(STR1); ppost_struct(WS1, STR1, 1.0); /* * For every integer argument, execute the appropriate test case. */ for (argument=1; argument