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

Defined functions

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