File: ComboBox8.c

package info (click to toggle)
motif 2.3.4-13
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,160 kB
  • ctags: 51,769
  • sloc: ansic: 596,938; cpp: 3,951; yacc: 2,854; makefile: 2,070; csh: 1,199; sh: 1,070; lex: 455
file content (130 lines) | stat: -rw-r--r-- 3,200 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* $XConsortium: ComboBox8.c /main/4 1996/05/08 23:33:59 drk $ */
#include <testlib.h>

/* Changing this value can destroy the test */
#define NUM_STRINGS 4

static char *strings[NUM_STRINGS] = {
	"Mother",
	"Father",
	"Sister",
	"Brother" };

XmString	list_items[NUM_STRINGS];

Widget		Form, ComboBox;

  int
main( int argc, char **argv )
{
int		i, n;
Arg		args[25];
char		buffer[25];
XmString	string;

int		instance;
unsigned char	combo_box_type;

  CommonTestInit (argc, argv);

  (void)printf( "Begin Test\n" );

  if (UserData == NULL)
  {
      printf ("Usage: ComboBox8 -u <comboBoxType>\n");
      exit(0);
  }

 /*
  *  Determine which type of ComboBox is being created.
  */
  if ( strcmp( UserData, "COMBO_BOX" ) == 0 )
  {
     instance = 1;
     combo_box_type = XmCOMBO_BOX;
  }
  else if ( strcmp( UserData, "DROP_DOWN_COMBO_BOX" ) == 0 )
  {
     instance = 2;
     combo_box_type = XmDROP_DOWN_COMBO_BOX;
  }
  else if ( strcmp( UserData, "DROP_DOWN_LIST" ) == 0 )
  {
     instance = 3;
     combo_box_type = XmDROP_DOWN_LIST;
  }

  n = 0;
  Form = XmCreateForm( Shell1, "Form", args, n ); 
  XtManageChild( Form );

  sprintf( buffer, "ComboBox%d", instance );

  for ( i = 0; i < NUM_STRINGS; i++ )
    { list_items[i]=XmStringCreateLtoR(strings[i],XmFONTLIST_DEFAULT_TAG); }

  n = 0;
  XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM ); n++;
  XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ); n++;
  XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ); n++;
  XtSetArg( args[n], XmNcomboBoxType, combo_box_type ); n++;
  XtSetArg( args[n], XmNitems, list_items ); n++;
  XtSetArg( args[n], XmNitemCount, NUM_STRINGS ); n++;
  XtSetArg( args[n], XmNvisibleItemCount, NUM_STRINGS-1 ); n++;
  ComboBox = XmCreateComboBox( Form, buffer, args, n ); 
  XtManageChild( ComboBox );

  XtRealizeWidget( Shell1 );


  /* TP 1 */
  (void)printf( "Test Purpose 1\n" );
  XmComboBoxSelectItem( ComboBox, list_items[0] );	/* The first item */
  CommonPause();
 
  /* TP 2 */
  (void)printf( "Test Purpose 2\n" );
  XmComboBoxSelectItem( ComboBox, list_items[3] );	/* The last item */
  CommonPause();
 
  /* TP 3 */
  (void)printf( "Test Purpose 3\n" );
  /* The user scrolls down to display the final item */
  CommonPause();
 
  /* TP 4 */
  (void)printf( "Test Purpose 4\n" );
  (void)printf( "Deliberate Error: XmComboBoxSelectItem called with an "
	"item not present in the ComboBox.\n" );
  string = XmStringCreate( "Non-matching", XmFONTLIST_DEFAULT_TAG );
  XmComboBoxSelectItem( ComboBox, string );
  XmStringFree( string );
  CommonPause();

  /* TP 5 */
  (void)printf( "Test Purpose 5\n" );
  XmComboBoxSetItem( ComboBox, list_items[1] );		/* The 2nd item */
  CommonPause();

  /* TP 6 */
  (void)printf( "Test Purpose 6\n" );
  XmComboBoxSetItem( ComboBox, list_items[0] );		/* The 1st item */
  CommonPause();

  /* TP 7 */
  (void)printf( "Test Purpose 7\n" );
  XmComboBoxSetItem( ComboBox, list_items[3] );		/* The last item */
  CommonPause();

  XtAppMainLoop( app_context );

  for ( i = 0; i < NUM_STRINGS; i++ )
    { XmStringFree(list_items[i]); }

  XtDestroyWidget( ComboBox );
  XtDestroyWidget( Form );

  (void)printf( "End Test\n" );

  return 0;
}