Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtterm / tests / charatt / charatt.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: charatt.c /main/3 1995/10/31 11:55:53 rswiston $ */
24 #include <stdio.h>
25 #include  "synvar.h"
26 #include  "common.h"
27
28 #ifdef LOG
29 FILE *TermLog;
30 #define SAVELOG  fclose(TermLog); TermLog = fopen("term.log", "a");
31 #endif
32
33 char LogStr[200];
34
35 #define Normal        0
36 #define Bold          1
37 #define Underscore    2
38 #define Inverse       3
39 #define Blink         4
40
41 static char *DispAttArr[] = {"Normal","Bold", "Underscore", "Inverse", "Blink"};
42
43 static SetDispAttr(WhichAttr, NewLine, BlinkOn)
44 int WhichAttr;
45 Bool NewLine, BlinkOn;
46 {
47     switch (WhichAttr) {
48       case Normal: 
49         SetDispNormal();  break;
50       case Bold:
51         SetDispBold();  break;
52       case Underscore:
53         SetDispUnderscore();  break;
54       case Inverse:
55         SetDispInverse();  break;
56     }
57     if (BlinkOn == True) SetDispBlink(); 
58     WRITETEST(DispAttArr[WhichAttr]);
59     if (NewLine == True) {
60        NextLine();
61        SetDispNormal(); 
62     }
63 }
64
65
66 void TestDispAtt(WinName)
67 char *WinName;
68 {
69   int i, j, k, Lines, Cols;
70   char Str[IMAGE_FILE_LEN];
71   Bool BlinkOn;
72
73     ClearScreen(); 
74     for (i=0; i < 2; i++) {
75       if (i == 1) BlinkOn = True;
76       else BlinkOn = False; 
77       SetDispAttr(Normal, True, BlinkOn);
78       SetDispAttr(Bold, True, BlinkOn);
79       SetDispAttr(Underscore, True, BlinkOn);
80       SetDispAttr(Inverse, True, BlinkOn);
81       SetDispAttr(Bold, False, BlinkOn);
82       SetDispAttr(Underscore, True, BlinkOn);
83       SetDispAttr(Bold, False, BlinkOn);
84       SetDispAttr(Inverse, True, BlinkOn);
85       SetDispAttr(Bold, False, BlinkOn); 
86       SetDispAttr(Underscore, False, BlinkOn);
87       SetDispAttr(Inverse, True, BlinkOn);
88       SetDispAttr(Underscore, False, BlinkOn);
89       SetDispAttr(Inverse, True, BlinkOn);
90     }
91 #ifdef SYNLIB
92     sprintf(Str, "%scharatt1", IMAGE_DIR);
93     MatchWindows(WinName, Str);
94 #endif
95     SetDispNormal();
96 FLUSHTEST();
97 }
98
99 void TestCursor(WinName)
100 char *WinName;
101 {
102   char Str[IMAGE_FILE_LEN];
103     SetScrollRegn(5, 15);
104     SetDispBold(); 
105     SetDispInverse(); 
106     SetDispUnderscore();
107     SetOriginMode(DECModeSet); /* To Origin Mode */
108     SetWrapMode(DECModeSet);
109     AbsoluteGoToXY(46, 14);
110     SaveCursor();
111     SetDispNormal();
112     SetOriginMode(DECModeReset); 
113     SetWrapMode(DECModeReset);
114     ClearScreen();
115     WRITETEST("Now In Normal Char Att; Cursor Mode; in Line 1; with no wrap and on restoring cursor");
116     NextLine();
117     WRITETEST("You did not see full line because of no wrap;On Restoring Cursor");
118     RestoreCursor();
119     WRITETEST("I Should start at (46,14) with char attribute Bold Inverse Underline, Origin mode set, scrolling region is 5,15 with wrap mode on");
120 #ifdef SYNLIB
121     sprintf(Str, "%scharatt2", IMAGE_DIR);
122     MatchWindows(WinName, Str);
123 #endif
124 }
125
126 void ResetTerm(Cols)
127 int Cols;
128 {
129     SetDispNormal();
130     SetOriginMode(DECModeReset); 
131     SetScrollRegn(1, Cols);
132 }
133
134 main(argc, argv)
135 int argc;
136 char *argv[];
137 {
138      
139   int NumLines, NumCols;
140 #ifdef LOG
141 if ((TermLog = fopen("term.log", "a")) == NULL) {
142    if ((TermLog = fopen("term.log", "w")) == NULL)
143       {printf("Logfile could not be opened \n"); exit(-1);}
144 }
145 fprintf(TermLog, "**************************************************\n");
146 LogTime();
147 fprintf(TermLog, "TestName: <%s> STARTS\n", argv[0]);
148 #endif 
149     START(1,0,0,0,0);
150     if (CheckTermStatus() == -1)
151        {printf("terminal emulator malfunctioning\n"); DONE(); return;} 
152     GetWinSize(&NumLines, &NumCols);
153 #ifdef SYNLIB
154      InitTest(argc, argv);
155      AssignWinName("TermWin", TERM_EMU);
156 #endif
157      TestDispAtt("TermWin");
158 #ifdef SLOW
159 sleep(10);
160 #endif
161      TestCursor("TermWin");
162      ResetTerm(NumCols);
163 #ifdef SYNLIB
164      CloseTest(False);
165 #endif
166     DONE();
167 #ifdef LOG
168 fprintf(TermLog, "TestName: <%s> ENDS\n", argv[0]);
169 fclose(TermLog);
170 #endif
171 }
172