1: #include <X/mit-copyright.h>
   2: 
   3: /* $Header: posttest.c,v 10.7 86/02/01 16:16:20 tony Rel $ */
   4: /* Copyright    Massachusetts Institute of Technology    1985	*/
   5: 
   6: /*
   7:  * XMenu:	MIT Project Athena, X Window System menu package.
   8:  *
   9:  *	posttest.c	Posttest is the XMenu posting and testing utility.
  10:  *
  11:  *	Author:		Tony Della Fera, DEC
  12:  *			September, 1985
  13:  */
  14: 
  15: #include <X/Xlib.h>
  16: #include "../XMenu.h"
  17: #include <stdio.h>
  18: 
  19: main(argc, argv)
  20:     int argc;       /* Argument count. */
  21:     char **argv;    /* Argument vector. */
  22: {
  23:     register int i;     /* Counter. */
  24:     register int j;     /* Counter. */
  25:     register int stat;      /* Return status. */
  26:     register XMenu *menu;   /* Menu structure. */
  27:     char *data;         /* Test data. */
  28: 
  29:     int p_num = 2;      /* Pane number. */
  30:     int s_num = 2;      /* Selection number. */
  31:     int x, y;           /* Mouse X and Y postition. */
  32: 
  33:     Window twin;        /* Temporary window. */
  34: 
  35:     /*
  36:      * Open the display.
  37:      */
  38:     if (XOpenDisplay(NULL) == NULL) {
  39:     printf("posttest: Error opening display.\n");
  40:     exit(0);
  41:     }
  42: 
  43:     /*
  44:      * Create the XMenu.
  45:      */
  46:     menu = (XMenu *)XMenuCreate(RootWindow, argv[0]);
  47:     if (menu == NULL) MenuError();
  48: 
  49:     /*
  50:      * Assemble the panes and selections.
  51:      */
  52:     printf("Posttest assembling panes: zero... ");
  53:     stat = XMenuAddPane(menu, "Pane Zero", 1);
  54:     if (stat == XM_FAILURE) MenuError();
  55:     stat = XMenuAddSelection(menu, 0, (char *)1, "Exit posttest.", 1);
  56:     if (stat == XM_FAILURE) MenuError();
  57:     stat = XMenuAddSelection(menu, 0, (char *)2, "Selection one.", 1);
  58:     if (stat == XM_FAILURE) MenuError();
  59:     stat = XMenuAddSelection(menu, 0, (char *)2, "Selection two.", 1);
  60:     if (stat == XM_FAILURE) MenuError();
  61:     stat = XMenuAddSelection(menu, 0, (char *)2, "Selection three.", 1);
  62:     if (stat == XM_FAILURE) MenuError();
  63: 
  64:     printf("one... ");
  65:     stat = XMenuAddPane(menu, "Pane One", 1);
  66:     if (stat == XM_FAILURE) MenuError();
  67:     stat = XMenuAddSelection(menu, 1, (char *)2, "Selection zero.", 1);
  68:     if (stat == XM_FAILURE) MenuError();
  69:     stat = XMenuAddSelection(menu, 1, (char *)2, "Selection one.", 1);
  70:     if (stat == XM_FAILURE) MenuError();
  71:     stat = XMenuAddSelection(menu, 1, (char *)2, "Selection two.", 1);
  72:     if (stat == XM_FAILURE) MenuError();
  73: 
  74:     printf("two... ");
  75:     stat = XMenuAddPane(menu, "Pane Two", 1);
  76:     if (stat == XM_FAILURE) MenuError();
  77:     stat = XMenuAddSelection(menu, 2, (char *)2, "Selection zero.", 1);
  78:     if (stat == XM_FAILURE) MenuError();
  79:     stat = XMenuAddSelection(menu, 2, (char *)2, "Selection one.", 1);
  80:     if (stat == XM_FAILURE) MenuError();
  81:     stat = XMenuAddSelection(menu, 2, (char *)2, "Selection two.", 1);
  82:     if (stat == XM_FAILURE) MenuError();
  83:     stat = XMenuAddSelection(menu, 2, (char *)2, "Selection three.", 1);
  84:     if (stat == XM_FAILURE) MenuError();
  85:     stat = XMenuAddSelection(menu, 2, (char *)2, "Selection four.", 1);
  86:     if (stat == XM_FAILURE) MenuError();
  87: 
  88:     printf("three... ");
  89:     stat = XMenuAddPane(menu, "Pane Three", 1);
  90:     if (stat == XM_FAILURE) MenuError();
  91:     stat = XMenuAddSelection(menu, 3, (char *)2, "Selection zero.", 1);
  92:     if (stat == XM_FAILURE) MenuError();
  93: 
  94:     printf("four... ");
  95:     stat = XMenuAddPane(menu, "Pane Four", 1);
  96:     if (stat == XM_FAILURE) MenuError();
  97:     stat = XMenuAddSelection(menu, 4, (char *)2, "Selection zero.", 1);
  98:     if (stat == XM_FAILURE) MenuError();
  99:     stat = XMenuAddSelection(menu, 4, (char *)2, "Selection one.", 1);
 100:     if (stat == XM_FAILURE) MenuError();
 101:     printf("done.\n");
 102: 
 103:     /*
 104:      * Recompute menu.
 105:      */
 106:     printf("Posttest recomputing menu dependencies.\n");
 107:     stat = XMenuRecompute(menu);
 108:     if (stat == XM_FAILURE) MenuError();
 109: 
 110:     /*
 111:      * Post the menu.
 112:      */
 113:     while (1) {
 114:     data = NULL;
 115:     printf(
 116:         "Posttest posting menu: pane = %d, selection = %d.\n",
 117:         p_num, s_num
 118:     );
 119:     XQueryMouse(RootWindow, &x, &y, &twin);
 120:     stat = XMenuActivate(
 121:         menu,
 122:         &p_num, &s_num,
 123:         x, y,
 124:         ButtonPressed,
 125:         &data
 126:     );
 127:     printf("Postest results:  data = %d, pane = %d, selection = %d\n",
 128:         (int)data, p_num, s_num);
 129:     if (stat == XM_FAILURE) MenuError();
 130:     if (stat == XM_NO_SELECT) {
 131:         printf("Posttest reports no selection made.\n");
 132:         s_num = 0;
 133:         continue;
 134:     }
 135:     if (stat == XM_IA_SELECT) {
 136:         printf("Posttest reports no selection active.\n");
 137:         continue;
 138:     }
 139:     if ((int)data == 1) break;
 140:     }
 141: 
 142:     /*
 143:      * Destroy XMenu.
 144:      */
 145:     printf("Posttest destroying menu.\n");
 146:     XMenuDestroy(menu);
 147: }
 148: 
 149: /*
 150:  * Print the XMenu error message.
 151:  */
 152: MenuError()
 153: {
 154:     printf("\nPosttest reports XMenu error: %s.\n\n", XMenuError());
 155:     exit(0);
 156: }

Defined functions

MenuError defined in line 152; used 23 times
main defined in line 19; never used
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1280
Valid CSS Valid XHTML 1.0 Strict