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>
18 #include "gtxscreenobj.h" /*Gator screen object interface */
19 #include "gtxtextobj.h" /*Gator text object interface */
20 #include "gtxlightobj.h" /*Gator light object interface */
21 #include "gtxwindows.h" /*Gator generic window package */
22 #include "gtxcurseswin.h" /*Gator curses window package */
23 #include "gtxdumbwin.h" /*Gator dumb terminal window package */
24 #include "gtxX11win.h" /*Gator X11 window package */
26 #include <stdio.h> /*Standard I/O stuff */
27 #include <cmd.h> /*Command interpretation library */
31 * Command line parameter indicies.
36 static char pn
[] = "object_test"; /*Program name */
37 static int object_debug
= 0; /*Is debugging turned on? */
39 /*--------------------------------------------------------------------------------
43 * Routine that does the actual testing of gator objects.
46 * int pkg : Number of windowing package to use.
50 * Error value otherwise.
53 * Nothing interesting.
57 *--------------------------------------------------------------------------------*/
65 static char rn
[] = "test_objects"; /*Routine name */
66 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.
97 "[%s:%s] Setting up initialization params for window package %d\n",
99 wi_params
.i_type
= pkg
;
102 wi_params
.i_width
= 80;
103 wi_params
.i_height
= 200;
104 wi_params
.i_debug
= object_debug
;
107 * Set up the basic onode initialization parameters, throwing in
108 * the graphics-specific stuff.
110 oi_params
.i_debug
= object_debug
;
111 oi_params
.i_gwparams
= &wi_params
;
112 code
= gator_objects_init(&oi_params
);
115 "[%s:%s] Can't initialize gator objects package for window system %d; error is: %d\n",
121 * Set up some light objects and put them up on the screen.
123 sprintf(helpstring1
, "%s", "Help string for light 1");
124 light_crparams
.onode_params
.cr_type
= GATOR_OBJ_LIGHT
;
125 sprintf(light_crparams
.onode_params
.cr_name
, "%s", "Light1");
126 light_crparams
.onode_params
.cr_x
= 10;
127 light_crparams
.onode_params
.cr_y
= 10;
128 light_crparams
.onode_params
.cr_width
= 10;
129 light_crparams
.onode_params
.cr_height
= 1;
130 light_crparams
.onode_params
.cr_window
= &gator_basegwin
;
131 light_crparams
.onode_params
.cr_home_obj
= NULL
;
132 light_crparams
.onode_params
.cr_prev_obj
= NULL
;
133 light_crparams
.onode_params
.cr_parent_obj
= NULL
;
134 light_crparams
.onode_params
.cr_helpstring
= helpstring1
;
136 light_crparams
.appearance
= 0;
137 light_crparams
.flashfreq
= 0;
138 sprintf(light_crparams
.label
, "%s", "Light 1 ");
139 light_crparams
.label_x
= 0;
140 light_crparams
.label_y
= 0;
143 gator_objects_create((struct onode_createparams
*)(&light_crparams
));
144 if (light_onp1
== NULL
) {
145 fprintf(stderr
, "[%s:%s] Can't create light object\n", pn
, rn
);
149 sprintf(helpstring2
, "%s", "Help string for light 2");
150 light_crparams
.onode_params
.cr_helpstring
= helpstring2
;
151 light_crparams
.onode_params
.cr_x
= 10;
152 light_crparams
.onode_params
.cr_y
= 12;
153 sprintf(light_crparams
.onode_params
.cr_name
, "%s", "Light2");
154 sprintf(light_crparams
.label
, "%s", "Light 2 ");
156 gator_objects_create((struct onode_createparams
*)(&light_crparams
));
157 if (light_onp2
== NULL
) {
158 fprintf(stderr
, "[%s:%s] Can't create light object\n", pn
, rn
);
162 sprintf(helpstring3
, "%s", "Help string for light 3");
163 light_crparams
.onode_params
.cr_helpstring
= helpstring3
;
164 light_crparams
.onode_params
.cr_x
= 10;
165 light_crparams
.onode_params
.cr_y
= 14;
166 sprintf(light_crparams
.onode_params
.cr_name
, "%s", "Light3");
167 sprintf(light_crparams
.label
, "%s", "Light 3 ");
169 gator_objects_create((struct onode_createparams
*)(&light_crparams
));
170 if (light_onp3
== NULL
) {
171 fprintf(stderr
, "[%s:%s] Can't create light object\n", pn
, rn
);
175 sprintf(helpstring4
, "%s", "Help string for light 4");
176 light_crparams
.onode_params
.cr_helpstring
= helpstring4
;
177 light_crparams
.onode_params
.cr_x
= 21;
178 light_crparams
.onode_params
.cr_y
= 10;
179 sprintf(light_crparams
.onode_params
.cr_name
, "%s", "Light4");
180 sprintf(light_crparams
.label
, "%s", "Light 4 ");
182 gator_objects_create((struct onode_createparams
*)(&light_crparams
));
183 if (light_onp4
== NULL
) {
184 fprintf(stderr
, "[%s:%s] Can't create light object\n", pn
, rn
);
189 * Create a text object, too.
191 sprintf(helpstringt1
, "%s", "Help string for text");
192 text_crparams
.onode_params
.cr_type
= GATOR_OBJ_TEXT
;
193 sprintf(text_crparams
.onode_params
.cr_name
, "%s", "Text1");
194 text_crparams
.onode_params
.cr_x
= 30;
195 text_crparams
.onode_params
.cr_y
= 10;
196 text_crparams
.onode_params
.cr_width
= 35;
197 text_crparams
.onode_params
.cr_height
= 7;
198 text_crparams
.onode_params
.cr_window
= &gator_basegwin
;
199 text_crparams
.onode_params
.cr_home_obj
= NULL
;
200 text_crparams
.onode_params
.cr_prev_obj
= NULL
;
201 text_crparams
.onode_params
.cr_parent_obj
= NULL
;
202 text_crparams
.onode_params
.cr_helpstring
= helpstringt1
;
203 text_crparams
.maxEntries
= 7;
204 text_crparams
.maxCharsPerEntry
= 35;
207 gator_objects_create((struct onode_createparams
*)(&text_crparams
));
208 if (text_onp1
== NULL
) {
209 fprintf(stderr
, "[%s:%s] Can't create text object\n", pn
, rn
);
212 OOP_DISPLAY(text_onp1
);
216 * Now that we have our lights, turn them on and off a few times.
219 sprintf(s
, "%s", "ABCD");
223 strparams
.highlight
= 0;
225 for (i
= 0; i
< 10; i
++) {
226 code
= gator_light_set(light_onp1
, setting
);
229 "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn
,
230 rn
, light_onp1
, setting
, (setting
? "ON" : "OFF"));
232 OOP_DISPLAY(light_onp1
);
234 code
= gator_light_set(light_onp2
, setting
);
237 "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn
,
238 rn
, light_onp2
, setting
, (setting
? "ON" : "OFF"));
240 OOP_DISPLAY(light_onp2
);
242 code
= gator_light_set(light_onp3
, setting
);
245 "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn
,
246 rn
, light_onp3
, setting
, (setting
? "ON" : "OFF"));
248 OOP_DISPLAY(light_onp3
);
250 code
= gator_light_set(light_onp4
, setting
);
253 "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn
,
254 rn
, light_onp4
, setting
, (setting
? "ON" : "OFF"));
256 OOP_DISPLAY(light_onp4
);
257 setting
= (setting
? 0 : 1);
261 WOP_DRAWSTRING(text_onp1
->o_window
, &strparams
);
268 OOP_DISPLAY(text_onp1
);
271 * Start writing stuff to our text object.
273 sprintf(s
, "%s", "This is the first line");
274 code
= gator_text_Write(text_onp1
, s
, strlen(s
), 0, 1);
277 "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n",
278 pn
, rn
, s
, strlen(s
), text_onp1
, code
);
281 sprintf(s
, "%s", "This is the");
282 code
= gator_text_Write(text_onp1
, s
, strlen(s
), 0, 0);
285 "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n",
286 pn
, rn
, s
, strlen(s
), text_onp1
, code
);
289 sprintf(s
, "%s", " second line");
290 code
= gator_text_Write(text_onp1
, s
, strlen(s
), 0, 1);
293 "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n",
294 pn
, rn
, s
, strlen(s
), text_onp1
, code
);
297 sprintf(s
, "%s", "This is the highlighted third line");
298 code
= gator_text_Write(text_onp1
, s
, strlen(s
), 1, 1);
301 "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n",
302 pn
, rn
, s
, strlen(s
), text_onp1
, code
);
306 "This is the very, very, very, very, very, very, very long fourth line");
307 code
= gator_text_Write(text_onp1
, s
, strlen(s
), 0, 1);
310 "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n",
311 pn
, rn
, s
, strlen(s
), text_onp1
, code
);
314 sprintf(s
, "%s", "This is line 5");
315 code
= gator_text_Write(text_onp1
, s
, strlen(s
), 0, 1);
318 "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n",
319 pn
, rn
, s
, strlen(s
), text_onp1
, code
);
322 sprintf(s
, "%s", "This is line 6");
323 code
= gator_text_Write(text_onp1
, s
, strlen(s
), 0, 1);
326 "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n",
327 pn
, rn
, s
, strlen(s
), text_onp1
, code
);
330 sprintf(s
, "%s", "This is line 7");
331 code
= gator_text_Write(text_onp1
, s
, strlen(s
), 0, 1);
334 "[%s:%s] Can't write '%s' (%d chars) to text object at 0x%x; error code is %d\n",
335 pn
, rn
, s
, strlen(s
), text_onp1
, code
);
339 * Now, try to scroll the sucker.
341 for (i
= 0; i
< 10; i
++) {
342 code
= gator_text_Scroll(text_onp1
, 1, GATOR_TEXT_SCROLL_UP
);
345 "[%s:%s] Can't scroll up 1 line in text object at 0x%x\n",
350 for (i
= 0; i
< 10; i
++) {
351 code
= gator_text_Scroll(text_onp1
, 2, GATOR_TEXT_SCROLL_DOWN
);
353 "[%s:%s] Can't scroll down 2 lines in text object at 0x%x\n",
359 * Before leaving, we clean up our windows.
361 WOP_CLEANUP(&gator_basegwin
);
365 /*------------------------------------------------------------------------
369 * Routine that is called when object_test is invoked, responsible
370 * for basic initialization and command line parsing.
373 * as : Command syntax descriptor.
374 * arock : Associated rock (not used here).
377 * Zero (but may exit the entire program on error!)
380 * Nothing interesting.
383 * Initializes this program.
384 *------------------------------------------------------------------------*/
387 object_testInit(struct cmd_syndesc
*as
, void *arock
)
388 { /*object_testInit */
390 static char rn
[] = "object_testInit"; /*Routine name */
391 int wpkg_to_use
; /*Window package to use */
393 if (as
->parms
[P_DEBUG
].items
!= 0)
395 wpkg_to_use
= atoi(as
->parms
[P_PACKAGE
].items
->data
);
396 fprintf(stderr
, "[%s:%s] Using graphics package %d: ", pn
, rn
,
398 switch (wpkg_to_use
) {
399 case GATOR_WIN_CURSES
:
400 fprintf(stderr
, "curses\n");
403 fprintf(stderr
, "dumb terminal\n");
406 fprintf(stderr
, "X11\n");
409 fprintf(stderr
, "Illegal graphics package: %d\n", wpkg_to_use
);
411 } /*end switch (wpkg_to_use) */
414 * Now, drive the sucker.
416 test_objects(wpkg_to_use
);
419 * We initialized (and ran) correctly, so return the good news.
423 } /*object_testInit */
425 #include "AFS_component_version_number.c"
433 static char rn
[] = "main"; /*Routine name */
434 afs_int32 code
; /*Return code */
435 struct cmd_syndesc
*ts
; /*Ptr to cmd line syntax descriptor */
438 * Set up the commands we understand.
440 ts
= cmd_CreateSyntax("initcmd", object_testInit
, NULL
,
441 "Initialize the program");
442 cmd_AddParm(ts
, "-package", CMD_SINGLE
, CMD_REQUIRED
,
443 "Graphics package to use");
444 cmd_AddParm(ts
, "-debug", CMD_FLAG
, CMD_OPTIONAL
, "Turn debugging on");
447 * Parse command-line switches & execute the test, then get the heck
450 code
= cmd_Dispatch(argc
, argv
);
452 fprintf(stderr
, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n",