Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtterm / tests / Rlogging / Rlogging.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: Rlogging.c /main/3 1995/10/31 11:52:32 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 static char *LogAction[] = { 
37 /*0*/ "Testing Resourse Option:logging True",
38 /*1*/ "Testing Resourse Option:logging True but in unwritable directory",
39 /*2*/ "Testing Resourse Option:logging True logFile Term.Log",
40 /*3*/ "Testing Resourse Option:logging False logFile Term.Log",
41 };
42
43
44 static char *ResourceArr[] = {
45 /*0*/ "logging True",
46 /*1*/ "logging True ",
47 /*2*/ "logging True logFile Term.Log",
48 /*3*/ "logging False logFile Term.Log",
49 };
50
51 int MakeResourceFile(ResArr)
52 char *ResArr;
53 {
54   FILE *ResFile;
55   int i, j, Len;
56   char Resource[50], Value[50];
57     
58     if ((ResFile = fopen("res", "w")) == NULL)
59        {LogError("Resource File Creation fail"); return(-1);}
60     for (i=0; i < 50; i++) Resource[i] = BLANK;
61     for (i=0; i < 50; i++) Value[i] = BLANK;
62     Len = strlen(ResArr); i=0;
63     while (i < Len) {
64       j = 0;
65       while (ResArr[i] != BLANK) Resource[j++] = ResArr[i++];
66       Resource[j] = NULLCHAR;
67       i++; j = 0;
68       while ((ResArr[i] != BLANK) && (ResArr[i] != NULLCHAR))
69             Value[j++] = ResArr[i++];
70       Value[j] = NULLCHAR;
71       i++;
72       fprintf(ResFile, "%s*%s: %s\n", TERM_EMU, Resource, Value);
73     }
74     fclose(ResFile);
75 }
76
77
78 #define ArrCount    (int) (sizeof(ResourceArr) / sizeof(char *))
79
80 main(argc, argv)
81 int argc;
82 char *argv[];
83 {
84    SynStatus Result;
85    char Command[NEED_LEN];
86    int i;
87      
88 #ifdef LOG
89 if ((TermLog = fopen("term.log", "a")) == NULL) {
90    if ((TermLog = fopen("term.log", "w")) == NULL)
91       {printf("Logfile could not be opened \n"); exit(-1);}
92 }
93 LogError("****************************************************************************");
94 LogTime();
95 sprintf(Command, "TestName: <%s> STARTS\n", argv[0]);
96 LogError(Command);
97 #endif 
98      InitTest(argc, argv);
99      CheckCapsLock();
100      ExecCommand("mkdir tmplog");
101      for (i=0; i < ArrCount; i++) {
102        CheckCapsLock();
103        ExecCommand("xrdb -load xrdb.out");
104        MakeResourceFile(ResourceArr[i]);
105        CheckCapsLock();
106        ExecCommand("xrdb -merge res"); sleep(5);
107        CheckCapsLock();
108        ExecCommand("mv  DTtermLog* tmplog"); sleep(1);
109        ExecCommand("mv Term.Log tmplog"); sleep(1);
110        if (i == 1) { /* try in un writable directory */
111           ExecCommand("mkdir unwrite"); sleep(1);
112           ExecCommand("chmod 555 unwrite"); sleep(1);
113           ExecCommand("cd  unwrite"); sleep(1);
114        }
115        LogError(LogAction[i]);
116        strcpy(Command, TERM_EMU);
117        CheckCapsLock();
118        ExecCommand(Command); sleep(1);
119        if (WaitWinMap("TermWin") < 0) continue;
120        AssignWinName("TermWin", TERM_EMU);
121        JustExit("TermWin");
122        WaitWinUnMap("TermWin", 10L);
123        switch (i) {
124          case 0: 
125            ExecCommand("test-l"); break;
126          case 1: 
127            ExecCommand("test+l"); break;
128          case 2: 
129            ExecCommand("test-lf"); break;
130          case 3: ExecCommand("test+l"); break;
131        }
132        if (i == 1) {
133           ExecCommand("cd ..");
134           ExecCommand("rmdir unwrite");
135        }
136 sleep(2);
137      }
138      ExecCommand("mv  tmplog/DTtermLog* ."); sleep(1);
139      ExecCommand("mv tmplog/Term.Log ."); sleep(1);
140      ExecCommand("rmdir tmplog");
141      CheckCapsLock();
142      ExecCommand("xrdb -load xrdb.out");
143      CloseTest(False);
144 #ifdef LOG
145 sprintf(Command, "TestName: <%s> ENDS\n", argv[0]);
146 LogError(Command);
147 LogError("****************************************************************************");
148 fclose(TermLog);
149 #endif
150 }
151