Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * Copyright 2000, International Business Machines Corporation and others. | |
3 | * All Rights Reserved. | |
4 | * | |
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 | |
8 | */ | |
9 | ||
10 | /* | |
11 | * object_test: A test of the gator object operations. | |
12 | *--------------------------------------------------------------------------------*/ | |
13 | ||
14 | #include <afsconfig.h> | |
15 | #include <afs/param.h> | |
16 | ||
17 | #include <roken.h> | |
18 | ||
19 | #include <afs/cmd.h> /*Command interpretation library */ | |
20 | ||
21 | #include "gtxscreenobj.h" /*Gator screen object interface */ | |
22 | #include "gtxtextobj.h" /*Gator text object interface */ | |
23 | #include "gtxlightobj.h" /*Gator light object interface */ | |
24 | #include "gtxwindows.h" /*Gator generic window package */ | |
25 | #include "gtxcurseswin.h" /*Gator curses window package */ | |
26 | #include "gtxdumbwin.h" /*Gator dumb terminal window package */ | |
27 | #include "gtxX11win.h" /*Gator X11 window package */ | |
28 | ||
29 | ||
30 | /* | |
31 | * Command line parameter indicies. | |
32 | */ | |
33 | #define P_PACKAGE 0 | |
34 | #define P_DEBUG 1 | |
35 | ||
36 | static char pn[] = "object_test"; /*Program name */ | |
37 | static int object_debug = 0; /*Is debugging turned on? */ | |
38 | ||
39 | /*-------------------------------------------------------------------------------- | |
40 | * test_objects | |
41 | * | |
42 | * Description: | |
43 | * Routine that does the actual testing of gator objects. | |
44 | * | |
45 | * Arguments: | |
46 | * int pkg : Number of windowing package to use. | |
47 | * | |
48 | * Returns: | |
49 | * 0 on success, | |
50 | * Error value otherwise. | |
51 | * | |
52 | * Environment: | |
53 | * Nothing interesting. | |
54 | * | |
55 | * Side Effects: | |
56 | * As advertised. | |
57 | *--------------------------------------------------------------------------------*/ | |
58 | ||
59 | static int | |
60 | test_objects(pkg) | |
61 | int pkg; | |
62 | ||
63 | { /*test_objects */ | |
64 | ||
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 */ | |
69 | #if 0 | |
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 */ | |
74 | #endif /* 0 */ | |
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 */ | |
91 | ||
92 | /* | |
93 | * Initialize the chosen gator window package. | |
94 | */ | |
95 | if (object_debug) | |
96 | fprintf(stderr, | |
97 | "[%s:%s] Setting up initialization params for window package %d\n", | |
98 | pn, rn, pkg); | |
99 | wi_params.i_type = pkg; | |
100 | wi_params.i_x = 0; | |
101 | wi_params.i_y = 0; | |
102 | wi_params.i_width = 80; | |
103 | wi_params.i_height = 200; | |
104 | wi_params.i_debug = object_debug; | |
105 | ||
106 | /* | |
107 | * Set up the basic onode initialization parameters, throwing in | |
108 | * the graphics-specific stuff. | |
109 | */ | |
110 | oi_params.i_debug = object_debug; | |
111 | oi_params.i_gwparams = &wi_params; | |
112 | code = gator_objects_init(&oi_params); | |
113 | if (code) { | |
114 | fprintf(stderr, | |
115 | "[%s:%s] Can't initialize gator objects package for window system %d; error is: %d\n", | |
116 | pn, rn, pkg, code); | |
117 | return (code); | |
118 | } | |
119 | ||
120 | /* | |
121 | * Set up some light objects and put them up on the screen. | |
122 | */ | |
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; | |
135 | ||
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; | |
141 | ||
142 | light_onp1 = | |
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); | |
146 | exit(-1); | |
147 | } | |
148 | ||
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 "); | |
155 | light_onp2 = | |
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); | |
159 | exit(-1); | |
160 | } | |
161 | ||
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 "); | |
168 | light_onp3 = | |
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); | |
172 | exit(-1); | |
173 | } | |
174 | ||
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 "); | |
181 | light_onp4 = | |
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); | |
185 | exit(-1); | |
186 | } | |
187 | ||
188 | /* | |
189 | * Create a text object, too. | |
190 | */ | |
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; | |
205 | ||
206 | text_onp1 = | |
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); | |
210 | exit(-1); | |
211 | } | |
212 | OOP_DISPLAY(text_onp1); | |
213 | sleep(2); | |
214 | ||
215 | /* | |
216 | * Now that we have our lights, turn them on and off a few times. | |
217 | */ | |
218 | setting = 1; | |
219 | sprintf(s, "%s", "ABCD"); | |
220 | strparams.x = 0; | |
221 | strparams.y = 0; | |
222 | strparams.s = s; | |
223 | strparams.highlight = 0; | |
224 | ||
225 | for (i = 0; i < 10; i++) { | |
226 | code = gator_light_set(light_onp1, setting); | |
227 | if (code) | |
228 | fprintf(stderr, | |
229 | "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, | |
230 | rn, light_onp1, setting, (setting ? "ON" : "OFF")); | |
231 | else | |
232 | OOP_DISPLAY(light_onp1); | |
233 | ||
234 | code = gator_light_set(light_onp2, setting); | |
235 | if (code) | |
236 | fprintf(stderr, | |
237 | "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, | |
238 | rn, light_onp2, setting, (setting ? "ON" : "OFF")); | |
239 | else | |
240 | OOP_DISPLAY(light_onp2); | |
241 | ||
242 | code = gator_light_set(light_onp3, setting); | |
243 | if (code) | |
244 | fprintf(stderr, | |
245 | "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, | |
246 | rn, light_onp3, setting, (setting ? "ON" : "OFF")); | |
247 | else | |
248 | OOP_DISPLAY(light_onp3); | |
249 | ||
250 | code = gator_light_set(light_onp4, setting); | |
251 | if (code) | |
252 | fprintf(stderr, | |
253 | "[%s:%s] Can't set gator light at 0x%x to %d (%s)\n", pn, | |
254 | rn, light_onp4, setting, (setting ? "ON" : "OFF")); | |
255 | else | |
256 | OOP_DISPLAY(light_onp4); | |
257 | setting = (setting ? 0 : 1); | |
258 | ||
259 | sleep(1); | |
260 | ||
261 | WOP_DRAWSTRING(text_onp1->o_window, &strparams); | |
262 | strparams.x++; | |
263 | strparams.y++; | |
264 | sleep(1); | |
265 | ||
266 | } /*Flash loop */ | |
267 | ||
268 | OOP_DISPLAY(text_onp1); | |
269 | ||
270 | /* | |
271 | * Start writing stuff to our text object. | |
272 | */ | |
273 | sprintf(s, "%s", "This is the first line"); | |
274 | code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); | |
275 | if (code) | |
276 | fprintf(stderr, | |
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); | |
279 | sleep(2); | |
280 | ||
281 | sprintf(s, "%s", "This is the"); | |
282 | code = gator_text_Write(text_onp1, s, strlen(s), 0, 0); | |
283 | if (code) | |
284 | fprintf(stderr, | |
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); | |
287 | sleep(2); | |
288 | ||
289 | sprintf(s, "%s", " second line"); | |
290 | code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); | |
291 | if (code) | |
292 | fprintf(stderr, | |
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); | |
295 | sleep(2); | |
296 | ||
297 | sprintf(s, "%s", "This is the highlighted third line"); | |
298 | code = gator_text_Write(text_onp1, s, strlen(s), 1, 1); | |
299 | if (code) | |
300 | fprintf(stderr, | |
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); | |
303 | sleep(2); | |
304 | ||
305 | sprintf(s, "%s", | |
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); | |
308 | if (code) | |
309 | fprintf(stderr, | |
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); | |
312 | sleep(2); | |
313 | ||
314 | sprintf(s, "%s", "This is line 5"); | |
315 | code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); | |
316 | if (code) | |
317 | fprintf(stderr, | |
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); | |
320 | sleep(2); | |
321 | ||
322 | sprintf(s, "%s", "This is line 6"); | |
323 | code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); | |
324 | if (code) | |
325 | fprintf(stderr, | |
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); | |
328 | sleep(2); | |
329 | ||
330 | sprintf(s, "%s", "This is line 7"); | |
331 | code = gator_text_Write(text_onp1, s, strlen(s), 0, 1); | |
332 | if (code) | |
333 | fprintf(stderr, | |
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); | |
336 | sleep(4); | |
337 | ||
338 | /* | |
339 | * Now, try to scroll the sucker. | |
340 | */ | |
341 | for (i = 0; i < 10; i++) { | |
342 | code = gator_text_Scroll(text_onp1, 1, GATOR_TEXT_SCROLL_UP); | |
343 | if (code) | |
344 | fprintf(stderr, | |
345 | "[%s:%s] Can't scroll up 1 line in text object at 0x%x\n", | |
346 | pn, rn, text_onp1); | |
347 | sleep(2); | |
348 | } | |
349 | ||
350 | for (i = 0; i < 10; i++) { | |
351 | code = gator_text_Scroll(text_onp1, 2, GATOR_TEXT_SCROLL_DOWN); | |
352 | fprintf(stderr, | |
353 | "[%s:%s] Can't scroll down 2 lines in text object at 0x%x\n", | |
354 | pn, rn, text_onp1); | |
355 | sleep(2); | |
356 | } | |
357 | ||
358 | /* | |
359 | * Before leaving, we clean up our windows. | |
360 | */ | |
361 | WOP_CLEANUP(&gator_basegwin); | |
362 | ||
363 | } /*test_objects */ | |
364 | ||
365 | /*------------------------------------------------------------------------ | |
366 | * object_testInit | |
367 | * | |
368 | * Description: | |
369 | * Routine that is called when object_test is invoked, responsible | |
370 | * for basic initialization and command line parsing. | |
371 | * | |
372 | * Arguments: | |
373 | * as : Command syntax descriptor. | |
374 | * arock : Associated rock (not used here). | |
375 | * | |
376 | * Returns: | |
377 | * Zero (but may exit the entire program on error!) | |
378 | * | |
379 | * Environment: | |
380 | * Nothing interesting. | |
381 | * | |
382 | * Side Effects: | |
383 | * Initializes this program. | |
384 | *------------------------------------------------------------------------*/ | |
385 | ||
386 | static int | |
387 | object_testInit(struct cmd_syndesc *as, void *arock) | |
388 | { /*object_testInit */ | |
389 | ||
390 | static char rn[] = "object_testInit"; /*Routine name */ | |
391 | int wpkg_to_use; /*Window package to use */ | |
392 | ||
393 | if (as->parms[P_DEBUG].items != 0) | |
394 | object_debug = 1; | |
395 | wpkg_to_use = atoi(as->parms[P_PACKAGE].items->data); | |
396 | fprintf(stderr, "[%s:%s] Using graphics package %d: ", pn, rn, | |
397 | wpkg_to_use); | |
398 | switch (wpkg_to_use) { | |
399 | case GATOR_WIN_CURSES: | |
400 | fprintf(stderr, "curses\n"); | |
401 | break; | |
402 | case GATOR_WIN_DUMB: | |
403 | fprintf(stderr, "dumb terminal\n"); | |
404 | break; | |
405 | case GATOR_WIN_X11: | |
406 | fprintf(stderr, "X11\n"); | |
407 | break; | |
408 | default: | |
409 | fprintf(stderr, "Illegal graphics package: %d\n", wpkg_to_use); | |
410 | exit(-1); | |
411 | } /*end switch (wpkg_to_use) */ | |
412 | ||
413 | /* | |
414 | * Now, drive the sucker. | |
415 | */ | |
416 | test_objects(wpkg_to_use); | |
417 | ||
418 | /* | |
419 | * We initialized (and ran) correctly, so return the good news. | |
420 | */ | |
421 | return (0); | |
422 | ||
423 | } /*object_testInit */ | |
424 | ||
425 | #include "AFS_component_version_number.c" | |
426 | ||
427 | main(argc, argv) | |
428 | int argc; | |
429 | char **argv; | |
430 | ||
431 | { /*main */ | |
432 | ||
433 | static char rn[] = "main"; /*Routine name */ | |
434 | afs_int32 code; /*Return code */ | |
435 | struct cmd_syndesc *ts; /*Ptr to cmd line syntax descriptor */ | |
436 | ||
437 | /* | |
438 | * Set up the commands we understand. | |
439 | */ | |
440 | ts = cmd_CreateSyntax("initcmd", object_testInit, NULL, 0, | |
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"); | |
445 | ||
446 | /* | |
447 | * Parse command-line switches & execute the test, then get the heck | |
448 | * out of here. | |
449 | */ | |
450 | code = cmd_Dispatch(argc, argv); | |
451 | if (code) { | |
452 | fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", | |
453 | pn, rn, code); | |
454 | exit(1); | |
455 | } | |
456 | ||
457 | } /*main */ |