Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtterm / tests / Rvisualbell / Rvisualbell.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: Rvisualbell.c /main/3 1995/10/31 11:55:11 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 char LogStr[200];
35
36
37 void TestVisualbell(WinName, TestNum)
38 char *WinName;
39 int TestNum;
40 {
41   char Str[IMAGE_FILE_LEN];
42   int i;
43     for (i=0; i < 4; i++) 
44       PressCtrlGKey(WinName);
45     if ((TestNum % 2) == 0)
46        PrintTermString(WinName, "You should have heard beep");
47     else 
48        PrintTermString(WinName, "You should have seen screen flashing");
49 sleep(5);
50     CloseTerm(WinName);
51 }
52
53 static char *OptionArr[] = { 
54 /*0*/ " -vb ",
55 /*1*/ " -xrm 'visualBell: False' -vb",
56 /*2*/ " +vb ",
57 /*3*/ " -xrm 'visualBell: True' +vb"
58 };
59
60 static char *LogAction[] = { 
61 /*0*/ " Testing Option: -vb ",
62 /*1*/ " Testing Option: -xrm 'visualBell: False' -vb",
63 /*2*/ " Testing Option: +vb ",
64 /*3*/ " Testing Option: -xrm 'visualBell: True' +vb"
65 };
66
67 static char *ResourceArr[] = {
68 /*0*/ "visualBell True",
69 /*1*/ "visualBell False ",
70 /*2*/ "visualBell on ",
71 /*3*/ "visualBell off "
72 };
73
74 int MakeResourceFile(ResArr)
75 char *ResArr;
76 {
77   FILE *ResFile;
78   int i, j, Len;
79   char Resource[50], Value[50];
80     
81     if ((ResFile = fopen("res", "w")) == NULL)
82        {LogError("Resource File Creation fail"); return(-1);}
83     for (i=0; i < 50; i++) Resource[i] = BLANK;
84     for (i=0; i < 50; i++) Value[i] = BLANK;
85     Len = strlen(ResArr); i=0;
86     while (i < Len) {
87       j = 0;
88       while (ResArr[i] != BLANK) Resource[j++] = ResArr[i++];
89       Resource[j] = NULLCHAR;
90       i++; j = 0;
91       while ((ResArr[i] != BLANK) && (ResArr[i] != NULLCHAR))
92             Value[j++] = ResArr[i++];
93       Value[j] = NULLCHAR;
94       i++;
95       fprintf(ResFile, "%s*%s: %s\n", TERM_EMU, Resource, Value);
96     }
97     fclose(ResFile);
98 }
99
100
101 #define ArrCount    (int) (sizeof(ResourceArr) / sizeof(char *))
102
103 main(argc, argv)
104 int argc;
105 char *argv[];
106 {
107    SynStatus Result;
108    char Command[NEED_LEN];
109    int i;
110      
111 #ifdef LOG
112 if ((TermLog = fopen("term.log", "a")) == NULL) {
113    if ((TermLog = fopen("term.log", "w")) == NULL)
114       {printf("Logfile could not be opened \n"); exit(-1);}
115 }
116 LogError("****************************************************************************");
117 LogTime();
118 sprintf(Command, "TestName: <%s> STARTS\n", argv[0]);
119 LogError(Command);
120 #endif 
121      InitTest(argc, argv);
122      for (i=0; i < ArrCount; i++) {
123        CheckCapsLock();
124        ExecCommand("xrdb -load xrdb.out");
125        MakeResourceFile(ResourceArr[i]);
126        LogError(LogAction[i]);
127        strcpy(Command, "xrdb -merge res; ");
128        strcat(Command, TERM_EMU);
129        CheckCapsLock();
130        ExecCommand(Command);
131        if (WaitWinMap("TermWin") < 0) continue;
132        AssignWinName("TermWin", TERM_EMU);
133        TestVisualbell("TermWin", i+1);
134        WaitWinUnMap("TermWin", 60L);
135      }
136      CheckCapsLock();
137      ExecCommand("xrdb -load xrdb.out");
138      CloseTest(False);
139 #ifdef LOG
140 sprintf(Command, "TestName: <%s> ENDS\n", argv[0]);
141 LogError(Command);
142 LogError("****************************************************************************");
143 fclose(TermLog);
144 #endif
145 }
146