include-errno-dont-declare-it-20030111
[openafs.git] / src / gtx / object_test.c
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 RCSID("$Header$");
18
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*/
26 #include <errno.h>
27 #include <stdio.h>                  /*Standard I/O stuff*/
28 #include <cmd.h>                    /*Command interpretation library*/
29
30
31 /*
32  * Command line parameter indicies.
33  */
34 #define P_PACKAGE   0
35 #define P_DEBUG     1
36
37 static char pn[] = "object_test";   /*Program name*/
38 static int object_debug = 0;        /*Is debugging turned on?*/
39
40 /*--------------------------------------------------------------------------------
41  * test_objects
42  *
43  * Description:
44  *      Routine that does the actual testing of gator objects.
45  *
46  * Arguments:
47  *      int pkg : Number of windowing package to use.
48  *
49  * Returns:
50  *      0 on success,
51  *      Error value otherwise.
52  *
53  * Environment:
54  *      Nothing interesting.
55  *
56  * Side Effects:
57  *      As advertised.
58  *--------------------------------------------------------------------------------*/
59
60 static int test_objects(pkg)
61     int pkg;
62
63 { /*test_objects*/
64
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*/
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, "[%s:%s] Setting up initialization params for window package %d\n", pn, rn, pkg);
97     wi_params.i_type   = pkg;
98     wi_params.i_x      =   0;
99     wi_params.i_y      =   0;
100     wi_params.i_width  =  80;
101     wi_params.i_height = 200;
102     wi_params.i_debug  = object_debug;
103
104     /*
105       * Set up the basic onode initialization parameters, throwing in
106       * the graphics-specific stuff.
107       */
108     oi_params.i_debug = object_debug;
109     oi_params.i_gwparams = &wi_params;
110     code = gator_objects_init(&oi_params);
111     if (code) {
112         fprintf(stderr, "[%s:%s] Can't initialize gator objects package for window system %d; error is: %d\n", pn, rn, pkg, code);
113         return(code);
114     }
115
116     /*
117       * Set up some light objects and put them up on the screen.
118       */
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;
131
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;
137
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);
141       exit(-1);
142     }
143
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);
153       exit(-1);
154     }
155
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);
165       exit(-1);
166     }
167
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);
177       exit(-1);
178     }
179
180     /*
181       * Create a text object, too.
182       */
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;
197
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);
201       exit(-1);
202     }
203     OOP_DISPLAY(text_onp1);
204     sleep(2);
205
206     /*
207       * Now that we have our lights, turn them on and off a few times.
208       */
209     setting = 1;
210     sprintf(s, "%s", "ABCD");
211     strparams.x         = 0;
212     strparams.y         = 0;
213     strparams.s         = s;
214     strparams.highlight = 0;
215
216     for (i=0; i<10; i++) {
217       code = gator_light_set(light_onp1, setting);
218       if (code)
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"));
220       else
221         OOP_DISPLAY(light_onp1);
222
223       code = gator_light_set(light_onp2, setting);
224       if (code)
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"));
226       else
227         OOP_DISPLAY(light_onp2);
228
229       code = gator_light_set(light_onp3, setting);
230       if (code)
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"));
232       else
233         OOP_DISPLAY(light_onp3);
234
235       code = gator_light_set(light_onp4, setting);
236       if (code)
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"));
238       else
239         OOP_DISPLAY(light_onp4);
240       setting = (setting? 0 : 1);
241
242       sleep(1);
243
244       WOP_DRAWSTRING(text_onp1->o_window, &strparams);
245       strparams.x++;
246       strparams.y++;
247       sleep(1);
248
249     } /*Flash loop*/
250
251     OOP_DISPLAY(text_onp1);
252
253     /*
254       * Start writing stuff to our text object.
255       */
256     sprintf(s, "%s", "This is the first line");
257     code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
258     if (code)
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);
260     sleep(2);
261
262     sprintf(s, "%s", "This is the");
263     code = gator_text_Write(text_onp1, s, strlen(s), 0, 0);
264     if (code)
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);
266     sleep(2);
267
268     sprintf(s, "%s", " second line");
269     code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
270     if (code)
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);
272     sleep(2);
273
274     sprintf(s, "%s", "This is the highlighted third line");
275     code = gator_text_Write(text_onp1, s, strlen(s), 1, 1);
276     if (code)
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);
278     sleep(2);
279
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);
282     if (code)
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);
284     sleep(2);
285
286     sprintf(s, "%s", "This is line 5");
287     code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
288     if (code)
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);
290     sleep(2);
291
292     sprintf(s, "%s", "This is line 6");
293     code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
294     if (code)
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);
296     sleep(2);
297
298     sprintf(s, "%s", "This is line 7");
299     code = gator_text_Write(text_onp1, s, strlen(s), 0, 1);
300     if (code)
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);
302     sleep(4);
303
304     /*
305       * Now, try to scroll the sucker.
306       */
307     for (i = 0; i<10; i++) {
308       code = gator_text_Scroll(text_onp1, 1, GATOR_TEXT_SCROLL_UP);
309       if (code)
310       fprintf(stderr, "[%s:%s] Can't scroll up 1 line in text object at 0x%x\n", pn, rn, text_onp1);
311       sleep(2);
312     }
313
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);
317       sleep(2);
318     }
319
320     /*
321       * Before leaving, we clean up our windows.
322       */
323     WOP_CLEANUP(&gator_basegwin);
324
325 } /*test_objects*/
326
327 /*------------------------------------------------------------------------
328  * object_testInit
329  *
330  * Description:
331  *      Routine that is called when object_test is invoked, responsible
332  *      for basic initialization and command line parsing.
333  *
334  * Arguments:
335  *      as      : Command syntax descriptor.
336  *      arock   : Associated rock (not used here).
337  *
338  * Returns:
339  *      Zero (but may exit the entire program on error!)
340  *
341  * Environment:
342  *      Nothing interesting.
343  *
344  * Side Effects:
345  *      Initializes this program.
346  *------------------------------------------------------------------------*/
347
348 static int object_testInit(as, arock)
349     struct cmd_syndesc *as;
350     char *arock;
351
352 { /*object_testInit*/
353
354     static char rn[] = "object_testInit";   /*Routine name*/
355     int wpkg_to_use;                        /*Window package to use*/
356
357     if (as->parms[P_DEBUG].items != 0)
358         object_debug = 1;
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");
364             break;
365         case GATOR_WIN_DUMB:
366             fprintf(stderr, "dumb terminal\n");
367             break;
368         case GATOR_WIN_X11:
369             fprintf(stderr, "X11\n");
370             break;
371         default:
372             fprintf(stderr, "Illegal graphics package: %d\n", wpkg_to_use);
373             exit(-1);
374     } /*end switch (wpkg_to_use)*/
375
376     /*
377      * Now, drive the sucker.
378      */
379     test_objects(wpkg_to_use);
380
381     /*
382      * We initialized (and ran) correctly, so return the good news.
383      */
384     return(0);
385
386 } /*object_testInit*/
387
388 #include "AFS_component_version_number.c"
389
390 main(argc, argv)
391     int argc;
392     char **argv;
393
394 { /*main*/
395
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*/
399
400     /*
401      * Set up the commands we understand.
402      */
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");
409
410     /*
411      * Parse command-line switches & execute the test, then get the heck
412      * out of here.
413      */
414     code = cmd_Dispatch(argc, argv);
415     if (code) {
416         fprintf(stderr, "[%s:%s] Call to cmd_Dispatch() failed; code is %d\n", pn, rn, code);
417         exit(1);
418     }
419
420 } /*main*/