File: CommText6.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 (260 lines) | stat: -rw-r--r-- 7,490 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* $TOG: CommText6.c /main/7 1997/10/02 16:23:51 csn $ */
/*
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
 */
/*
 * HISTORY
 */
#include <testlib.h>


/*
 *  Global variables.
 */
Arg args[MAX_ARGS];
int n;

static char string1[] = "Sample Text";
static char string2[] = "Sample Text2";
static char string3[] =  "The <Return> key was pressed.";
static char string4[] = "Changed the string.";

static char font_name1[] = "8x13";
static char font_name2[] = "8x13bold";

static char render_tag[] = "render1";


static void ChangeString(Widget w, XtPointer client_data,
                                XtPointer call_data)
{
    XmString  tcs = (XmString)0;


      n = 0;
    XtSetArg(args[n], XmNvalue, string3 );  n++;
      XtSetValues(w, args, n);

      if ( tcs ) XmStringFree( tcs );
      
}


static void ChangeString2(Widget w, XtPointer client_data,
                                XtPointer call_data)
{
    XmString  tcs = (XmString)0;

      n = 0;
    XtSetArg(args[n], XmNvalue, string4);  n++;
      XtSetValues(w, args, n);
     
      if (tcs) XmStringFree(tcs);
}

void SetStringCB(w, client_data, call_data)
     Widget w;
     XtPointer client_data;
     XtPointer call_data;
{
     XmString  string;
     static char new_string[] = "New\nset\nvalue";
       
     XmTextSetString((Widget)client_data, new_string);
}

void InsertStringCB(w, client_data, call_data)
     Widget w;
     XtPointer client_data;
     XtPointer call_data;
{
     XmString  string;
     static char new_string[] = "+123+";
       
     XmTextInsert((Widget)client_data, 3, new_string);
}


void main_text6 (argc, argv)
     int argc;
     char **argv;
{
	Widget PanedWindow;
	Widget Text1;
	Widget Text2;
        Widget BBoard1;
	XtTranslations new_table;
	static String new_translation = "Ctrl<Key>r: activate()";
        XmString tcs;
        void *ret_val;
        Widget SetStringPB = NULL;
        Widget InsertStringPB = NULL;
        XmString string;
	char temp_string[100], *text2_return;
        XmStringContext *context;
        XmStringCharSet tag;
        XmStringDirection direction;
        XmStringComponentType unknown_tag;
        unsigned short        unknown_length;
        unsigned char         unknown_value;

	/*  initialize toolkit  */
	CommonTestInit(argc, argv);
	
	n = 0;
	XtSetArg(args[n], XmNwidth, 400);  n++;
	XtSetArg(args[n], XmNheight, 300);  n++;
	XtSetValues(Shell1, args, n);
	
	/* test case for PIR 3677 - realized here, not after children mngd */
	XtRealizeWidget(Shell1);
	/* end of test case for PIR 3677 */

	n = 0;
	PanedWindow = XmCreatePanedWindow(Shell1, "PanedWindow", args, n);
	XtManageChild(PanedWindow);

	n = 0;
	XtSetArg(args[n], XmNvalue, string1);  n++;
	XtSetArg(args[n], XmNfontList, CommonGetFontList(font_name1));  n++;
	Text1 = XmCreateText(PanedWindow, "Text1", args, n);
	XtManageChild (Text1);

	n = 0;
	XtSetArg(args[n], XmNfontList, CommonGetFontList(font_name2));  n++;
	XtSetArg(args[n], XmNvalue, string2);  n++;
	XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
	Text2 = XmCreateText(PanedWindow, "Text2", args, n);
	XtManageChild (Text2);

	/* begin test for CR */
	CommonPause(); 

	/* The instructions ask the user to change Text1 in a way that
	   can mess up the focus, then modify Text2 by adding a "2" at
	   the end.

	   Check the contents of the strings and print out a warning if
	   the value of the second string is not now "Sample Text22" */

	ret_val = XmTextGetString(Text2);

	text2_return = (char *)ret_val;

	if (!strcmp(text2_return, "The Sample Text2") == 0) 
	   printf ("\n+++\n.Test FAILS. String in Text2 does not match expected value.\n+++\n");
	else printf ("+++\nTest PASSES. No error.\n");
	fflush(stdout);

	XtFree ((char *)ret_val);

	CommonPause();

	/* end test for CR */

	XtAddCallback(Text1, XmNactivateCallback, CommonGenericCB, NULL);
	XtAddCallback(Text1, XmNactivateCallback, ChangeString, NULL);
	XtAddCallback(Text2, XmNactivateCallback, ChangeString2, NULL);

	/* test case for PIR 3677 - this realize is commented out
	XtRealizeWidget (Shell1);
	*/

	CommonPause();
	CommonPause();

	n=0;
	new_table = XtParseTranslationTable (new_translation);
	XtSetArg(args[n], XmNtranslations, new_table); n++;
	XtSetValues (Text2, args, n);

	CommonPause();

	/* test case for PIR 1772, PIR 1058 */
	XtAddCallback(Text1, XmNvalueChangedCallback, CommonGenericCB, NULL);
	XtAddCallback(Text1, XmNmodifyVerifyCallback, CommonGenericCB, NULL);

	CommonPause();
	/* end of test case for PIR 1772, PIR 1058 */

        /*  Begin testing CR 6141 */

        XtDestroyWidget( PanedWindow );

        n = 0;
        XtSetArg(args[n], XmNallowShellResize, True); n++;
        XtSetValues( Shell1, args, n );

        n = 0;
        XtSetArg(args[n], XmNwidth, 200); n++;
        XtSetArg(args[n], XmNheight, 200); n++;
        BBoard1 = XmCreateBulletinBoard( Shell1, "BBoard1", args, n );
        XtManageChild( BBoard1 );

        string = XmStringCreate("", XmFONTLIST_DEFAULT_TAG );

        n = 0;
        XtSetArg( args[n], XmNx, 0 ); n++;
        XtSetArg( args[n], XmNy, 0 ); n++;
        XtSetArg( args[n], XmNrows, 5 ); n++;
        XtSetArg( args[n], XmNcolumns, 40 ); n++;
        XtSetArg( args[n], XmNeditMode, XmMULTI_LINE_EDIT ); n++;
	XtSetArg( args[n], XmNvalue, "" ); n++;
        Text1 = XmCreateText( BBoard1, "Text1", args, n );
        XtManageChild( Text1 );

        string = XmStringCreate("Set String", XmFONTLIST_DEFAULT_TAG );

        n = 0;
        XtSetArg( args[n], XmNx, 0 ); n++;
        XtSetArg( args[n], XmNy, 100 ); n++;
        XtSetArg( args[n], XmNwidth, 100 ); n++;
        XtSetArg( args[n], XmNheight, 30 ); n++;
        XtSetArg( args[n], XmNlabelString, string ); n++;
        SetStringPB = XmCreatePushButton(BBoard1, "SetStringPB", args, n);
        XtAddCallback(SetStringPB, XmNactivateCallback, SetStringCB, Text1);
        XtManageChild (SetStringPB);

        XmStringFree( string );

        string = XmStringCreate("Insert", XmFONTLIST_DEFAULT_TAG );

        n = 0;
        XtSetArg( args[n], XmNx, 110 ); n++;
        XtSetArg( args[n], XmNy, 100 ); n++;
        XtSetArg( args[n], XmNwidth, 90 ); n++;
        XtSetArg( args[n], XmNheight, 30 ); n++;
        XtSetArg( args[n], XmNlabelString, string ); n++;
        InsertStringPB = XmCreatePushButton(BBoard1, "InsertStringPB", args, n);
        XtAddCallback(InsertStringPB, XmNactivateCallback,
                                      InsertStringCB, Text1);
        XtManageChild (InsertStringPB);

        XmStringFree( string );

        CommonPause();
       /*  End testing CR 6141 */

        CommonPause();

	XtAppMainLoop(app_context);
}