Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtterm / tests / erase / erase.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: erase.c /main/3 1995/10/31 11:57:36 rswiston $ */
24 #include <stdio.h>
25 #include  "synvar.h"
26
27 #ifdef LOG
28 FILE *TermLog;
29 #define SAVELOG  fclose(TermLog); TermLog = fopen("term.log", "a");
30 #endif
31
32 char LogStr[200];
33
34 void FillScreen(Lines, Cols, Ch)
35 int Lines, Cols;
36 char Ch;
37 {
38   int i, j; char Str[10];
39    ClearScreen();
40    sprintf(Str, "%c", Ch);
41    for (i=0; i < Lines; i++) 
42      for (j=0; j < Cols; j++) 
43        WRITETEST(Str);
44 }
45
46 void EraseLnTest(Lines, Cols, WinName)
47 int Lines, Cols;
48 char *WinName;
49 {
50   int i; char Str[IMAGE_FILE_LEN];
51     FillScreen(Lines, Cols, 'X');
52     FLUSHTEST();
53     HomeUp();
54     for (i=0; i < Lines; i++) {
55       CursorForward(1); EraseLnFromCur(); CursorDown(1); 
56 #ifdef SLOW
57       sleep(1); FLUSHTEST();
58 #endif
59     }
60 #ifdef SYNLIB
61     sprintf(Str, "%serase1", IMAGE_DIR);
62     MatchWindows(WinName, Str);
63 #endif
64     HomeUp();
65     FillScreen(Lines, Cols, 'M');
66     FLUSHTEST();
67     HomeUp();
68     for (i=0; i < Lines; i++) {
69       CursorForward(1); EraseLnToCur(); CursorDown(1); 
70 #ifdef SLOW
71       sleep(1); FLUSHTEST();
72 #endif
73     }
74 #ifdef SYNLIB
75     sprintf(Str, "%serase2", IMAGE_DIR);
76     MatchWindows(WinName, Str);
77 #endif
78     HomeUp();
79     FillScreen(Lines, Cols, 'M');
80     FLUSHTEST();
81     HomeUp();
82     for (i=0; i < (Lines/2); i++) {
83       CursorForward(2); EraseLnAll(); CursorDown(2); 
84 #ifdef SLOW
85       sleep(1); FLUSHTEST();
86 #endif
87     }
88 #ifdef SYNLIB
89     sprintf(Str, "%serase3", IMAGE_DIR);
90     MatchWindows(WinName, Str);
91 #endif
92 }
93
94 #define MoveBy    5
95
96 void EraseScrTest(Lines, Cols, WinName)
97 int Lines, Cols;
98 char *WinName;
99 {
100   int i, Count;
101   char Str[IMAGE_FILE_LEN];
102     FillScreen(Lines, Cols, 'R');
103     FLUSHTEST();
104     Count = Lines / MoveBy;
105     for (i=0; i < Count; i++) {
106       CursorBack(((Cols-MoveBy) /Count)); CursorUp(MoveBy); 
107       EraseScrFromCur(); 
108 #ifdef SLOW
109       sleep(2); FLUSHTEST();
110 #endif
111     }
112     sprintf(Str, "%serase4", IMAGE_DIR);
113 #ifdef SYNLIB
114     MatchWindows(WinName, Str);
115 #endif
116     ClearScreen();
117     FillScreen(Lines, Cols, 'M');
118     FLUSHTEST();
119     HomeUp();
120     for (i=0; i < Count; i++) {
121       CursorForward(((Cols-MoveBy) /Count)); CursorDown(MoveBy); 
122       EraseScrToCur(); 
123 #ifdef SLOW
124       sleep(2); FLUSHTEST();
125 #endif
126     }
127 #ifdef SYNLIB
128     sprintf(Str, "%serase5", IMAGE_DIR);
129     MatchWindows(WinName, Str);
130 #endif
131 }
132
133
134 void EraseCharTest(Lines, Cols, WinName)
135 int Lines, Cols;
136 char *WinName;
137 {
138   int i, Count;
139   char Str[IMAGE_FILE_LEN];
140     FillScreen(Lines, Cols, 'R');
141     FLUSHTEST();
142     HomeUp();
143     CursorForward(Cols/2);
144     for (i=0; i < Lines; i++) {
145       CursorBack(1); EraseChars(i*2+1); CursorDown(1); 
146 #ifdef SLOW
147       sleep(1); FLUSHTEST();
148 #endif
149     }
150 #ifdef SYNLIB
151     sprintf(Str, "%serase6", IMAGE_DIR);
152     MatchWindows(WinName, Str);
153 #endif
154 }
155
156 void TestAllErase(WinName)
157 char *WinName;
158 {
159   int i,j,k, l, Wrap;
160   int Lines, Cols, TabSpace, TabCount;
161   char Str[IMAGE_FILE_LEN];
162
163     START(1, 0, 0, 0, 0);
164 /*
165     if (CheckTermStatus() == -1)
166        {printf("terminal emulator malfunctioning\n"); exit(-1);}
167 */
168     ClearScreen(); 
169     GetWinSize(&Lines, &Cols); 
170 #ifdef DEBUG
171 fprintf(TermLog, "WINDOW Size Cols: %d Lines: %d \n", Cols, Lines);
172 SAVELOG;
173 #endif
174     EraseLnTest(Lines, Cols, WinName);
175     EraseScrTest(Lines, Cols, WinName);
176     EraseCharTest(Lines, Cols, WinName);
177     DONE();
178 }
179
180 main(argc, argv)
181 int argc;
182 char *argv[];
183 {
184      
185 #ifdef LOG
186 if ((TermLog = fopen("term.log", "a")) == NULL) {
187    if ((TermLog = fopen("term.log", "w")) == NULL)
188       {printf("Logfile could not be opened \n"); exit(-1);}
189 }
190 fprintf(TermLog, "**************************************************\n");
191 LogTime();
192 fprintf(TermLog, "TestName: <%s> STARTS\n", argv[0]);
193 #endif 
194 #ifdef SYNLIB
195      InitTest(argc, argv);
196      AssignWinName("TermWin", TERM_EMU);
197 #endif
198      TestAllErase("TermWin");
199 #ifdef SYNLIB
200      CloseTest(False);
201 #endif
202 #ifdef LOG
203 fprintf(TermLog, "TestName: <%s> ENDS\n", argv[0]);
204 fclose(TermLog);
205 #endif
206 }
207