2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * object_test: A test of the gator object operations.
12 *--------------------------------------------------------------------------------*/
14 #include <afsconfig.h>
15 #include <afs/param.h>
19 #include "gtxscreenobj.h" /*Gator screen object interface*/
20 #include "gtxtextobj.h" /*Gator text object interface*/
21 #include "gtxlightobj.h" /*Gator light object interface*/
22 #include "gtxwindows.h" /*Gator generic window package*/
23 #include "gtxcurseswin.h" /*Gator curses window package*/
24 #include "gtxdumbwin.h" /*Gator dumb terminal window package*/
25 #include "gtxX11win.h" /*Gator X11 window package*/
27 #include <stdio.h> /*Standard I/O stuff*/
28 #include <cmd.h> /*Command interpretation library*/
32 * Command line parameter indicies.
37 static char pn[] = "object_test"; /*Program name*/
38 static int object_debug = 0; /*Is debugging turned on?*/
40 /*--------------------------------------------------------------------------------
44 * Routine that does the actual testing of gator objects.
47 * int pkg : Number of windowing package to use.
51 * Error value otherwise.
54 * Nothing interesting.
58 *--------------------------------------------------------------------------------*/
60 static int test_objects(pkg)
65 static char rn[] = "test_objects"; /*Routine name*/
66 register int code; /*Return code*/
67 struct onode_initparams oi_params; /*Init params*/
68 struct gwin_initparams wi_params; /*Window initialization params*/
70 /*We don't need these, do we?*/
71 struct gator_cursesgwin_params c_crparams; /*Curses window creation params*/
72 struct gator_dumbgwin_params d_crparams; /*Dumb terminal window creation params*/
73 struct gator_X11gwin_params x_crparams; /*X11 window creation params*/
75 struct gator_light_crparams light_crparams; /*Light creation params*/
76 char helpstring1[128]; /*Help string to use*/
77 char helpstring2[128]; /*Help string to use*/
78 char helpstring3[128]; /*Help string to use*/
79 char helpstring4[128]; /*Help string to use*/
80 char helpstringt1[128]; /*Help string to use*/
81 struct onode *light_onp1; /*Ptr to light onode*/
82 struct onode *light_onp2; /*Ptr to another light onode*/
83 struct onode *light_onp3; /*Ptr to another light onode*/
84 struct onode *light_onp4; /*Ptr to another light onode*/
85 struct onode *text_onp1; /*Ptr to text onode*/
86 int i; /*Generic loop variable*/
87 int setting; /*Current light setting*/
88 struct gator_textobj_params text_crparams; /*Text creation params*/
89 char s[128]; /*Another string*/
90 struct gwin_strparams strparams; /*String-drawing params*/
93 * Initialize the chosen gator window package.
96 fprintf(stderr, "[%s:%s] Setting up initialization params for window package %d\n", pn, rn, pkg);
97 wi_params.i_type = pkg;
100 wi_params.i_width = 80;
101 wi_params.i_height = 200;
102 wi_params.i_debug = object_debug;
105 * Set up the basic onode initialization parameters, throwing in
106 * the graphics-specific stuff.
108 oi_params.i_debug = object_debug;
109 oi_params.i_gwparams = &wi_params;
110 code = gator_objects_init(&oi_params);
112 fprintf(stderr, "[%s:%s] Can't initialize gator objects package for window system %d; error is: %d\n", pn, rn, pkg, code);
117 * Set up some light objects and put them up on the screen.
119 sprintf(helpstring1, "%s", "Help string for light 1");
120 light_crparams.onode_params.cr_type = GATOR_OBJ_LIGHT;
121 sprintf(light_crparams.onode_params.cr_name, "%s", "Light1");
122 light_crparams.onode_params.cr_x = 10;
123 light_crparams.onode_params.cr_y = 10;
124 light_crparams.onode_params.cr_width = 10;
125 light_crparams.onode_params.cr_height = 1;
126 light_crparams.onode_params.cr_window = &gator_basegwin;
127 light_crparams.onode_params.cr_home_obj = NULL;
128 light_crparams.onode_params.cr_prev_obj = NULL;
129 light_crparams.onode_params.cr_parent_obj = NULL;
130 light_crparams.onode_params.cr_helpstring = helpstring1;
132 light_crparams.appearance = 0;
133 light_crparams.flashfreq = 0;
134 sprintf(light_crparams.label, "%s", "Light 1 ");
135 light_crparams.label_x = 0;
136 light_crparams.label_y = 0;
138 light_onp1 = gator_objects_create((struct onode_createparams *)(&light_crparams));
139 if (light_onp1 == NULL) {
140 fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn);
144 sprintf(helpstring2, "%s", "Help string for light 2");
145 light_crparams.onode_params.cr_helpstring = helpstring2;
146 light_crparams.onode_params.cr_x = 10;
147 light_crparams.onode_params.cr_y = 12;
148 sprintf(light_crparams.onode_params.cr_name, "%s", "Light2");
149 sprintf(light_crparams.label, "%s", "Light 2 ");
150 light_onp2 = gator_objects_create((struct onode_createparams *)(&light_crparams));
151 if (light_onp2 == NULL) {
152 fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn);
156 sprintf(helpstring3, "%s", "Help string for light 3");
157 light_crparams.onode_params.cr_helpstring = helpstring3;
158 light_crparams.onode_params.cr_x = 10;
159 light_crparams.onode_params.cr_y = 14;
160 sprintf(light_crparams.onode_params.cr_name, "%s", "Light3");
161 sprintf(light_crparams.label, "%s", "Light 3 ");
162 light_onp3 = gator_objects_create((struct onode_createparams *)(&light_crparams));
163 if (light_onp3 == NULL) {
164 fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn);
168 sprintf(helpstring4, "%s", "Help string for light 4");
169 light_crparams.onode_params.cr_helpstring = helpstring4;
170 light_crparams.onode_params.cr_x = 21;
171 light_crparams.onode_params.cr_y = 10;
172 sprintf(light_crparams.onode_params.cr_name, "%s", "Light4");
173 sprintf(light_crparams.label, "%s", "Light 4 ");
174 light_onp4 = gator_objects_create((struct onode_createparams *)(&light_crparams));
175 if (light_onp4 == NULL) {
176 fprintf(stderr, "[%s:%s] Can't create light object\n", pn, rn);
181 * Create a text object, too.
183 sprintf(helpstringt1, "%s", "Help string for text");
184 text_crparams.onode_params.cr_type = GATOR_OBJ_TEXT;
185 sprintf(text_crparams.onode_params.cr_name, "%s", "Text1");
186 text_crparams.onode_params.cr_x = 30;
187 text_crparams.onode_params.cr_y = 10;
188 text_crparams.onode_params.cr_width = 35;
189 text_crparams.onode_params.cr_height = 7;
190 text_crparams.onode_params.cr_window = &gator_basegwin;
191 text_crparams.onode_params.cr_home_obj = NULL;
192 text_crparams.onode_params.cr_prev_obj = NULL;
193 text_crparams.onode_params.cr_parent_obj = NULL;
194 text_crparams.onode_params.cr_helpstring = helpstringt1;
195 text_crparams.maxEntries = 7;
196 text_crparams.maxCharsPerEntry = 35;
198 text_onp1 = gator_objects_create((struct onode_createparams *)(&text_crparams));
199 if (text_onp1 == NULL) {
200 fprintf(stderr, "[%s:%s] Can't create text object\n", pn, rn);
203 OOP_DISPLAY(text_onp1);
207 * Now that we have our lights, turn them on and off a few times.
210 sprintf(s, "%s", "ABCD");
214 strparams.highlight = 0;
216 for (i=0; i<10; i++) {
217 code = gator_light_set(light_onp1, setting);
219 fprintf(stderr, "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, rn, light_onp1, setting, (setting? "ON" : "OFF"));
221 OOP_DISPLAY(light_onp1);
223 code = gator_light_set(light_onp2, setting);
225 fprintf(stderr, "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, rn, light_onp2, setting, (setting? "ON" : "OFF"));
227 OOP_DISPLAY(light_onp2);
229 code = gator_light_set(light_onp3, setting);
231 fprintf(stderr, "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, rn, light_onp3, setting, (setting? "ON" : "OFF"));
233 OOP_DISPLAY(light_onp3);
235 code = gator_light_set(light_onp4, setting);
237 fprintf(stderr, "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, rn, light_onp4, setting, (setting? "ON" : "OFF"));
239 OOP_DISPLAY(light_onp4);
240 setting = (setting? 0 : 1);
244 WOP_DRAWSTRING(text_onp1->o_window, &strparams);
251 OOP_DISPLAY(text_onp1);
254 * Start writing stuff to our text object.
256 sprintf(s, "%s", "This is the first line");
257 code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
259 fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code);
262 sprintf(s, "%s", "This is the");
263 code = gator_text_Write(text_onp1, s, strlen(s), 0, 0);
265 fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code);
268 sprintf(s, "%s", " second line");
269 code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
271 fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code);
274 sprintf(s, "%s", "This is the highlighted third line");
275 code = gator_text_Write(text_onp1, s, strlen(s), 1, 1);
277 fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code);
280 sprintf(s, "%s", "This is the very, very, very, very, very, very, very long fourth line");
281 code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
283 fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code);
286 sprintf(s, "%s", "This is line 5");
287 code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
289 fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code);
292 sprintf(s, "%s", "This is line 6");
293 code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
295 fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code);
298 sprintf(s, "%s", "This is line 7");
299 code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
301 fprintf(stderr, "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n", pn, rn, s, strlen(s), text_onp1, code);
305 * Now, try to scroll the sucker.
307 for (i = 0; i<10; i++) {
308 code = gator_text_Scroll(text_onp1, 1, GATOR_TEXT_SCROLL_UP);
310 fprintf(stderr, "[%s:%s] Can't scroll up 1 line in text object at 0x%x\n", pn, rn, text_onp1);
314 for (i = 0; i < 10; i++) {
315 code = gator_text_Scroll(text_onp1, 2, GATOR_TEXT_SCROLL_DOWN);
316 fprintf(stderr, "[%s:%s] Can't scroll down 2 lines in text object at 0x%x\n", pn, rn, text_onp1);
321 * Before leaving, we clean up our windows.
323 WOP_CLEANUP(&gator_basegwin);
327 /*------------------------------------------------------------------------
331 * Routine that is called when object_test is invoked, responsible
332 * for basic initialization and command line parsing.
335 * as : Command syntax descriptor.
336 * arock : Associated rock (not used here).
339 * Zero (but may exit the entire program on error!)
342 * Nothing interesting.
345 * Initializes this program.
346 *------------------------------------------------------------------------*/
348 static int object_testInit(as, arock)
349 struct cmd_syndesc *as;
352 { /*object_testInit*/
354 static char rn[] = "object_testInit"; /*Routine name*/
355 int wpkg_to_use; /*Window package to use*/
357 if (as->parms[P_DEBUG].items != 0)
359 wpkg_to_use = atoi(as->parms[P_PACKAGE].items->data);
360 fprintf(stderr, "[%s:%s] Using graphics package %d: ", pn, rn, wpkg_to_use);
361 switch (wpkg_to_use) {
362 case GATOR_WIN_CURSES:
363 fprintf(stderr, "curses\n");
366 fprintf(stderr, "dumb terminal\n");
369 fprintf(stderr, "X11\n");
372 fprintf(stderr, "Illegal graphics package: %d\n", wpkg_to_use);
374 } /*end switch (wpkg_to_use)*/
377 * Now, drive the sucker.
379 test_objects(wpkg_to_use);
382 * We initialized (and ran) correctly, so return the good news.
386 } /*object_testInit*/
388 #include "AFS_component_version_number.c"
396 static char rn[] = "main"; /*Routine name*/
397 register afs_int32 code; /*Return code*/
398 register struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor*/
401 * Set up the commands we understand.
403 ts = cmd_CreateSyntax("initcmd", object_testInit, 0,
404 "Initialize the program");
405 cmd_AddParm(ts, "-package", CMD_SINGLE, CMD_REQUIRED,
406 "Graphics package to use");
407 cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL,
408 "Turn debugging on");
411 * Parse command-line switches & execute the test, then get the heck
414 code = cmd_Dispatch(argc, argv);
416 fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", pn, rn, code);