Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtterm / tests / Riconic / Riconic.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Riconic.c /main/3 1995/10/31 11:52:08 rswiston $ */
24 #include <stdio.h>
25 #include <math.h>
26 #include  "synvar.h"
27 #include  "common.h"
28
29 #ifdef LOG
30 FILE *TermLog;
31 #define SAVELOG  fclose(TermLog); TermLog = fopen("term.log", "a");
32 #endif
33
34 #define BLANK    ' '
35
36 char LogStr[200];
37
38
39 void TestIconify(WinName, String, TestNum)
40 char *WinName, *String;
41 int TestNum;
42 {
43   char Str[IMAGE_FILE_LEN];
44     sprintf(Str, "%sriconic%d", IMAGE_DIR, TestNum);
45     MatchWindows(WinName, Str);
46     Deiconify(WinName);
47     if (WaitWinMap(WinName) < 0) LogError("Deiconify did not work");
48     PrintTermString(WinName, String);
49     sprintf(Str, "%sriconic%dA", IMAGE_DIR, TestNum);
50     MatchWindows(WinName, Str);
51     CloseTerm(WinName);
52 }
53
54 void TestIconifyMap(WinName, String, TestNum)
55 char *WinName, *String;
56 int TestNum;
57 {
58   char Str[IMAGE_FILE_LEN];
59     sprintf(Str, "%sriconic%d", IMAGE_DIR, TestNum);
60     MatchWindows(WinName, Str);
61     if (TestNum == 3) {
62        if (WaitWinMap(WinName) < 0) LogError("mapOnOutput: True did not work");
63        PrintTermString(WinName, String);
64        sprintf(Str, "%sriconic%dA", IMAGE_DIR, TestNum);
65        MatchWindows(WinName, Str);
66        PrintTermString(WinName, "1");
67        CloseTerm(WinName);
68     }
69     else {
70        if (WaitWinMap(WinName) == 0) LogError("mapOnOutput:False did not work");
71        else {
72          Deiconify(WinName); 
73          if (WaitWinMap(WinName) < 0) LogError("Deiconify did not work");
74          CloseTerm(WinName);
75        }
76     }
77 }
78
79
80 static char *OptionArr[] = {
81 /*0*/ " -iconic ",
82 /*1*/ " -iconic -xrm 'dtterm*iconName: Test' ",
83 /*2*/ " -iconic -map -xrm 'dtterm*mapOnOutputDelay: 5' -e wait5write",
84 /*3*/ " -iconic +map -xrm 'dtterm*mapOnOutputDelay: 5' -e wait5write"
85 };
86
87 static char *ResourceArr[] = {
88 /*0*/ "iconic True",
89 /*1*/ "iconic True iconName test",
90 /*2*/ "iconic True mapOnOutput True mapOnOutputDelay 5",
91 /*3*/ "iconic True mapOnOutput False mapOnOutputDelay 5"
92 };
93
94 static char *LogAction[] = {
95 "Testing Option  iconic True ",
96 "Testing Option  iconic True iconName Test",
97 "Testing Option  iconic True mapOnOutput True mapOnOutputDelay 5",
98 "Testing Option  iconic True mapOnOutput False mapOnOutputDelay 5"
99 };
100
101 int MakeResourceFile(ResArr)
102 char *ResArr;
103 {
104   FILE *ResFile;
105   int i, j, Len;
106   char Resource[50], Value[50];
107     
108     if ((ResFile = fopen("res", "w")) == NULL)
109        {LogError("Resource File Creation fail"); return(-1);}
110     for (i=0; i < 50; i++) Resource[i] = BLANK;
111     for (i=0; i < 50; i++) Value[i] = BLANK;
112     Len = strlen(ResArr); i=0;
113     while (i < Len) {
114       j = 0;
115       while (ResArr[i] != BLANK) Resource[j++] = ResArr[i++];
116       Resource[j] = NULLCHAR;
117       i++; j = 0;
118       while ((ResArr[i] != BLANK) && (ResArr[i] != NULLCHAR))
119             Value[j++] = ResArr[i++];
120       Value[j] = NULLCHAR;
121       i++;
122       fprintf(ResFile, "%s*%s: %s\n", TERM_EMU, Resource, Value);
123     }
124     fclose(ResFile);
125 }
126
127 #define ArrCount    (int) (sizeof(OptionArr) / sizeof(char *))
128
129 main(argc, argv)
130 int argc;
131 char *argv[];
132 {
133    SynStatus Result;
134    char Command[NEED_LEN];
135    int i;
136      
137 #ifdef LOG
138 if ((TermLog = fopen("term.log", "a")) == NULL) {
139    if ((TermLog = fopen("term.log", "w")) == NULL)
140       {printf("Logfile could not be opened \n"); exit(-1);}
141 }
142 LogError("****************************************************************************");
143 LogTime();
144 sprintf(Command, "TestName: <%s> STARTS\n", argv[0]);
145 LogError(Command);
146 #endif 
147      InitTest(argc, argv);
148      for (i=0; i < ArrCount; i++) {
149        CheckCapsLock();
150        ExecCommand("xrdb -load xrdb.out");
151        MakeResourceFile(ResourceArr[i]);
152        CheckCapsLock();
153        strcpy(Command, "xrdb -merge res; ");
154        strcat(Command, TERM_EMU);
155        if (i > 1) strcat(Command, " -e wait5write");
156        ExecCommand(Command);
157        if (WaitWinMap("TermWin") < 0) continue;
158        AssignWinName("TermWin", TERM_EMU);
159        if (i <= 1) TestIconify("TermWin", OptionArr[i], i+1);
160        else TestIconifyMap("TermWin", OptionArr[i], i+1);
161        WaitWinUnMap("TermWin", 60L);
162      }
163      CheckCapsLock();
164      ExecCommand("xrdb -load xrdb.out");
165      CloseTest(False);
166 #ifdef LOG
167 sprintf(Command, "TestName: <%s> ENDS\n", argv[0]);
168 LogError(Command);
169 LogError("****************************************************************************");
170 fclose(TermLog);
171 #endif
172 }
173