1 | #include "owl.h" |
---|
2 | #include <unistd.h> |
---|
3 | #include <stdlib.h> |
---|
4 | |
---|
5 | static const char fileIdent[] = "$Id$"; |
---|
6 | |
---|
7 | owl_global g; |
---|
8 | |
---|
9 | void screeninit() |
---|
10 | { |
---|
11 | char buff[1024]; |
---|
12 | |
---|
13 | sprintf(buff, "TERMINFO=%s", TERMINFO); |
---|
14 | putenv(buff); |
---|
15 | |
---|
16 | initscr(); |
---|
17 | start_color(); |
---|
18 | /* cbreak(); */ |
---|
19 | raw(); |
---|
20 | noecho(); |
---|
21 | intrflush(stdscr,FALSE); |
---|
22 | keypad(stdscr,TRUE); |
---|
23 | nodelay(stdscr,1); |
---|
24 | clear(); |
---|
25 | refresh(); |
---|
26 | meta(stdscr, TRUE); |
---|
27 | } |
---|
28 | |
---|
29 | void test1() |
---|
30 | { |
---|
31 | int j; |
---|
32 | owl_editwin e; |
---|
33 | |
---|
34 | screeninit(); |
---|
35 | |
---|
36 | owl_editwin_init(&e, stdscr, LINES, COLS, OWL_EDITWIN_STYLE_MULTILINE, NULL); |
---|
37 | /* owl_editwin_set_locktext(&e, "Here is some locktext:\n");*/ |
---|
38 | doupdate(); |
---|
39 | while (1) { |
---|
40 | usleep(50); |
---|
41 | |
---|
42 | j=getch(); |
---|
43 | |
---|
44 | if (j==ERR) continue; |
---|
45 | |
---|
46 | if (j==3) break; |
---|
47 | |
---|
48 | if (j==27) { |
---|
49 | j=getch(); |
---|
50 | if (j==ERR) continue; |
---|
51 | owl_editwin_process_char(&e, j); |
---|
52 | doupdate(); |
---|
53 | } else { |
---|
54 | owl_editwin_process_char(&e, j); |
---|
55 | doupdate(); |
---|
56 | } |
---|
57 | } |
---|
58 | endwin(); |
---|
59 | printf("Had:\n%s", owl_editwin_get_text(&e)); |
---|
60 | } |
---|
61 | |
---|
62 | void test2(char *in) |
---|
63 | { |
---|
64 | owl_fmtext t; |
---|
65 | |
---|
66 | screeninit(); |
---|
67 | |
---|
68 | owl_fmtext_init_null(&t); |
---|
69 | owl_fmtext_append_ztext(&t, in); |
---|
70 | owl_fmtext_curs_waddstr(&t, stdscr); |
---|
71 | wrefresh(stdscr); |
---|
72 | sleep(5000); |
---|
73 | endwin(); |
---|
74 | } |
---|
75 | |
---|
76 | void test3() |
---|
77 | { |
---|
78 | ZNotice_t *n; |
---|
79 | |
---|
80 | printf("%i\n", sizeof(n->z_uid.zuid_addr)); |
---|
81 | /* gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET); */ |
---|
82 | } |
---|
83 | |
---|
84 | void colorinfo() |
---|
85 | { |
---|
86 | char buff[1024]; |
---|
87 | |
---|
88 | screeninit(); |
---|
89 | sprintf(buff, "Have %i COLOR_PAIRS\n", COLOR_PAIRS); |
---|
90 | addstr(buff); |
---|
91 | refresh(); |
---|
92 | sleep(10); |
---|
93 | endwin(); |
---|
94 | } |
---|
95 | |
---|
96 | void test4() |
---|
97 | { |
---|
98 | int j; |
---|
99 | char buff[1024]; |
---|
100 | |
---|
101 | screeninit(); |
---|
102 | |
---|
103 | while (1) { |
---|
104 | usleep(100); |
---|
105 | |
---|
106 | j=getch(); |
---|
107 | |
---|
108 | if (j==ERR) continue; |
---|
109 | |
---|
110 | if (j==3) break; |
---|
111 | sprintf(buff, "%o\n", j); |
---|
112 | addstr(buff); |
---|
113 | } |
---|
114 | endwin(); |
---|
115 | } |
---|
116 | |
---|
117 | void test_keypress() |
---|
118 | { |
---|
119 | int j, rev; |
---|
120 | char buff[1024], buff2[64]; |
---|
121 | |
---|
122 | screeninit(); |
---|
123 | |
---|
124 | while (1) { |
---|
125 | usleep(100); |
---|
126 | |
---|
127 | j=wgetch(stdscr); |
---|
128 | |
---|
129 | if (j==ERR) continue; |
---|
130 | |
---|
131 | if (j==3) break; |
---|
132 | if (0 == owl_keypress_tostring(j, 0, buff2, 1000)) { |
---|
133 | rev = owl_keypress_fromstring(buff2); |
---|
134 | sprintf(buff, "%s : 0x%x 0%o %d %d %s\n", buff2, j, j, j, rev, |
---|
135 | (j==rev?"matches":"*** WARNING: Does Not Reverse")); |
---|
136 | } else { |
---|
137 | sprintf(buff, "UNKNOWN : 0x%x 0%o %d\n", j, j, j); |
---|
138 | } |
---|
139 | addstr(buff); |
---|
140 | } |
---|
141 | endwin(); |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | #define OWL_DICT_NTESTS 20 |
---|
146 | #define OWL_UTIL_NTESTS 9 |
---|
147 | #define OWL_OBARRAY_NTESTS 5 |
---|
148 | #define OWL_VARIABLE_NTESTS 52 |
---|
149 | #define OWL_FILTER_NTESTS 23 |
---|
150 | |
---|
151 | int main(int argc, char **argv, char **env) |
---|
152 | { |
---|
153 | owl_errqueue_init(owl_global_get_errqueue(&g)); |
---|
154 | owl_obarray_init(&(g.obarray)); |
---|
155 | |
---|
156 | int numfailures=0; |
---|
157 | if (argc==1 || (argc==2 && 0==strcmp(argv[1],"reg"))) { |
---|
158 | printf("1..%d\n", OWL_UTIL_NTESTS+OWL_DICT_NTESTS+OWL_VARIABLE_NTESTS |
---|
159 | +OWL_FILTER_NTESTS+OWL_OBARRAY_NTESTS); |
---|
160 | numfailures += owl_util_regtest(); |
---|
161 | numfailures += owl_dict_regtest(); |
---|
162 | numfailures += owl_variable_regtest(); |
---|
163 | numfailures += owl_filter_regtest(); |
---|
164 | numfailures += owl_obarray_regtest(); |
---|
165 | if (numfailures) { |
---|
166 | fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures); |
---|
167 | } |
---|
168 | return(numfailures); |
---|
169 | } else if (argc==2 && 0==strcmp(argv[1],"test1")) { |
---|
170 | test1(); |
---|
171 | } else if (argc==2 && 0==strcmp(argv[1],"colorinfo")) { |
---|
172 | colorinfo(); |
---|
173 | } else if (argc==2 && 0==strcmp(argv[1],"test4")) { |
---|
174 | test4(); |
---|
175 | } else if (argc==2 && 0==strcmp(argv[1],"keypress")) { |
---|
176 | test_keypress(); |
---|
177 | } else { |
---|
178 | fprintf(stderr, "No test specified. Current options are: reg test1\n"); |
---|
179 | } |
---|
180 | return(0); |
---|
181 | } |
---|