1 // $Id$
2 //
3 // Test functionality of CursWin
4 
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #endif
8 
9 #include "unistd.h"
10 
11 #include <iostream>
12 
13 #include "yacurs.h"
14 
test1()15 void test1() {
16     YACURS::CurStr str1("Hello, world!");
17     YACURS::INTERNAL::CursWin win(YACURS::Area(3, 2, 15, 70));
18 
19     win << str1;
20     win.refresh();
21 #ifdef SLOW_TESTS
22     sleep(2);
23 #endif
24 
25     win.clear();
26     win.box();
27     YACURS::CurStr str2("Hello, world!", YACURS::Coordinates(1, 1));
28     win << str2;
29     win.refresh();
30 #ifdef SLOW_TESTS
31     sleep(2);
32 #endif
33 
34     YACURS::INTERNAL::CursWin* subwin = win.derwin(YACURS::Area(2, 2, 10, 10));
35     subwin->box();
36     subwin->refresh();
37 #ifdef SLOW_TESTS
38     sleep(2);
39 #endif
40 
41     win.clear();
42     subwin->clear();
43     win.refresh();
44     delete subwin;
45 }
46 
test2()47 void test2() {
48     YACURS::INTERNAL::CursWin win(YACURS::Area(0, 0, 10, 10));
49 
50     for (int i = 0; i < 10; i++) {
51         YACURS::CurStr str("abcdefghijklmnopqrstuvwxyz",
52                            YACURS::Coordinates(i, i));
53         win.addstrx(str);
54     }
55 
56     win.refresh();
57 }
58 
test3()59 void test3() {
60     YACURS::INTERNAL::CursWin win(YACURS::Area(0, 10, 10, 10));
61 
62     win.box();
63 
64     for (int i = 1; i < 10; i++) {
65         YACURS::CurStr str("abcdefghijklmnopqrstuvwxyz",
66                            YACURS::Coordinates(i, i));
67         win.addstrx(str);
68     }
69 
70     win.refresh();
71 }
72 
test4()73 void test4() {
74     YACURS::INTERNAL::CursWin win(YACURS::Area(0, 20, 10, 10));
75 
76     char chr = 'A';
77 
78     for (int y = 0; y < 10; y++) {
79         win.move(YACURS::Coordinates(0, y));
80 
81         for (int x = 0; x < 10; x++) {
82             win.addch(chr);
83 #ifdef SLOW_TESTS
84             usleep(70000);
85 #endif
86             win.refresh();
87         }
88 
89         chr++;
90     }
91 
92     for (int y = 9; y >= 0; y--) {
93         for (int x = 9; x >= 0; x--) {
94             win.mvdelch(YACURS::Coordinates(x, y));
95 #ifdef SLOW_TESTS
96             usleep(70000);
97 #endif
98             win.refresh();
99         }
100     }
101 }
102 
test5()103 void test5() {
104     for (int anic = 0; anic < 2; anic++) {
105         YACURS::INTERNAL::CursWin win1(YACURS::Area(0, 0, 10, 10));
106         win1.set_color(YACURS::DIALOG);
107 
108         for (int i = 0; i < 10; i++) {
109             YACURS::CurStr str("abcdefghijklmnopqrstuvwxyz",
110                                YACURS::Coordinates(i, 9 - i));
111             win1.addstrx(str);
112 #ifdef SLOW_TESTS
113             usleep(70000);
114 #endif
115             win1.refresh();
116         }
117 
118         YACURS::INTERNAL::CursWin win2(YACURS::Area(10, 0, 10, 10));
119 
120         for (int i = 0; i < 10; i++) {
121             YACURS::CurStr str("abcdefghijklmnopqrstuvwxyz",
122                                YACURS::Coordinates(i, i));
123             win2.addstrx(str);
124 #ifdef SLOW_TESTS
125             usleep(70000);
126 #endif
127             win2.refresh();
128         }
129 
130         YACURS::INTERNAL::CursWin win4(YACURS::Area(10, 10, 10, 10));
131 
132         for (int i = 0; i < 10; i++) {
133             YACURS::CurStr str("abcdefghijklmnopqrstuvwxyz",
134                                YACURS::Coordinates(0, i));
135             win4.addnstr(str, 9 - i);
136 #ifdef SLOW_TESTS
137             usleep(70000);
138 #endif
139             win4.refresh();
140         }
141 
142         YACURS::INTERNAL::CursWin win3(YACURS::Area(0, 10, 10, 10));
143 
144         for (int i = 0; i < 10; i++) {
145             YACURS::CurStr str("abcdefghijklmnopqrstuvwxyz",
146                                YACURS::Coordinates(0, i));
147             win3.addnstr(str, i);
148 #ifdef SLOW_TESTS
149             usleep(70000);
150 #endif
151             win3.refresh();
152         }
153 
154 #ifdef SLOW_TESTS
155         usleep(70000);
156 #endif
157 
158         win1.clear();
159         win1.refresh();
160 #ifdef SLOW_TESTS
161         usleep(70000);
162 #endif
163 
164         win2.clear();
165         win2.refresh();
166 #ifdef SLOW_TESTS
167         usleep(70000);
168 #endif
169 
170         win3.clear();
171         win3.refresh();
172 #ifdef SLOW_TESTS
173         usleep(70000);
174 #endif
175 
176         win4.clear();
177         win4.refresh();
178 #ifdef SLOW_TESTS
179         usleep(70000);
180 #endif
181     }
182 }
183 
test6()184 void test6() {
185     YACURS::INTERNAL::CursWin win(YACURS::Area(0, 0, 10, 20));
186 
187     std::string str("abcdefghijklmnopqrstuvwxyz");
188 
189     for (int i = 0; i < 10; i++) {
190         win.move(YACURS::Coordinates(0, i));
191         win.addstrx(str);
192         win.refresh();
193     }
194 }
195 
test7()196 void test7() {
197     YACURS::CurStr str1("abcdefgh", YACURS::Coordinates(1, 1),
198                         YACURS::LISTBOX_HILITE);
199     YACURS::CurStr str2("abcde", YACURS::Coordinates(3, 2),
200                         YACURS::LISTBOX_HILITE);
201 
202     YACURS::INTERNAL::CursWin win1(YACURS::Area(0, 10, 10, 10));
203 
204     win1.box();
205     win1.addlinex(str1);
206     win1.addlinex(str2);
207     win1.move(YACURS::Coordinates(0, 3));
208     win1.addlinex("abcdefgh");
209     win1.refresh();
210 
211     YACURS::INTERNAL::CursWin win2(YACURS::Area(10, 10, 10, 10));
212     win2.addlinex(str1);
213     win2.addlinex(str2);
214     win2.move(YACURS::Coordinates(0, 3));
215     win2.addlinex("abcdefgh");
216     win2.refresh();
217 }
218 
test8()219 void test8() {
220     YACURS::CurStr str1("abcdefghij", YACURS::Coordinates(0, 0),
221                         YACURS::DIALOG);
222     YACURS::CurStr str2("abcde", YACURS::Coordinates(0, 1), YACURS::DEFAULT);
223     YACURS::CurStr str21("fghij", YACURS::Coordinates(5, 1),
224                          YACURS::INPUTWIDGET_FOCUS);
225     YACURS::CurStr str3("abcdefghij", YACURS::Coordinates(0, 2),
226                         YACURS::INPUTWIDGET_NOFOCUS);
227     YACURS::CurStr str4("abcdefghij", YACURS::Coordinates(0, 3),
228                         YACURS::INPUTWIDGET_FOCUS);
229     YACURS::CurStr str5("abcdefghij", YACURS::Coordinates(0, 4),
230                         YACURS::INPUTWIDGET_HIDDEN);
231     YACURS::CurStr str6("abcdefghij", YACURS::Coordinates(0, 5),
232                         YACURS::BUTTON_NOFOCUS);
233     YACURS::CurStr str7("abcdefghij", YACURS::Coordinates(0, 6),
234                         YACURS::BUTTON_FOCUS);
235     YACURS::CurStr str8("abcdefghij", YACURS::Coordinates(0, 7),
236                         YACURS::LISTBOX);
237     YACURS::CurStr str9("abcdefghij", YACURS::Coordinates(0, 8),
238                         YACURS::LISTBOX_HILITE);
239     YACURS::CurStr str10("abcdefghij", YACURS::Coordinates(0, 9),
240                          YACURS::CHECKBOXGROUP);
241 
242     YACURS::INTERNAL::CursWin win(YACURS::Area(0, 10, 10, 20));
243 
244     win.set_color(YACURS::DEFAULT);
245 
246     win.addlinex(str1);
247     win += str2;
248     win += str21;
249     win.addlinex(str3);
250     win += str4;
251     win.addlinex(str5);
252     win += str6;
253     win.addlinex(str7);
254     win += str8;
255     win.addlinex(str9);
256     win += str10;
257     win.refresh();
258 }
259 
test9()260 void test9() {
261     YACURS::INTERNAL::CursWin win1(YACURS::Area(0, 10, 10, 20), YACURS::DIALOG);
262 
263     win1.box();
264     win1.addstrx(YACURS::CurStr("abcdefghijklmnopqrstuvwxyz",
265                                 YACURS::Coordinates(1, 1),
266                                 YACURS::INPUTWIDGET_FOCUS));
267 
268     YACURS::INTERNAL::CursWin win2(YACURS::Area(5, 5, 10, 20),
269                                    YACURS::TITLEBAR);
270     win2.addstrx(YACURS::CurStr("abcdefghijklmnopqrstuvwxyz",
271                                 YACURS::Coordinates(1, 1),
272                                 YACURS::INPUTWIDGET_FOCUS));
273     win2.box();
274 
275     win1.refresh(true);
276     win2.refresh(true);
277 }
278 
main()279 int main() {
280     // test will not be run if stdout or stdin is not a tty.
281     if (isatty(STDOUT_FILENO) != 1 || isatty(STDIN_FILENO) != 1) exit(77);
282 
283 #if 0
284     std::cout << getpid() << std::endl;
285     sleep(15);
286 #endif
287 
288 #ifdef YACURS_USE_WCHAR
289     if (setlocale(LC_ALL, "en_US.UTF-8") == 0) exit(77);
290 #endif
291 
292     YACURS::Curses::init();
293 
294     test1();
295 #ifdef SLOW_TESTS
296     sleep(1);
297 #endif
298 
299     test2();
300     test3();
301     test4();
302 
303 #ifdef SLOW_TESTS
304     sleep(1);
305 #endif
306 
307     wclear(stdscr);
308     wrefresh(stdscr);
309 
310     test5();
311 
312 #ifdef SLOW_TESTS
313     sleep(1);
314 #endif
315 
316     wclear(stdscr);
317     wrefresh(stdscr);
318 
319     test6();
320 
321 #ifdef SLOW_TESTS
322     sleep(1);
323 #endif
324 
325     wclear(stdscr);
326     wrefresh(stdscr);
327 
328     test7();
329 
330 #ifdef SLOW_TESTS
331     sleep(1);
332 #endif
333 
334     wclear(stdscr);
335     wrefresh(stdscr);
336 
337     test8();
338 #ifdef SLOW_TESTS
339     sleep(1);
340 #endif
341 
342     test9();
343 #ifdef SLOW_TESTS
344     sleep(1);
345 #endif
346 
347     YACURS::Curses::end();
348 }
349