Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / test / test_curses.py
CommitLineData
86530b38
AT
1#
2# Test script for the curses module
3#
4# This script doesn't actually display anything very coherent. but it
5# does call every method and function.
6#
7# Functions not tested: {def,reset}_{shell,prog}_mode, getch(), getstr(),
8# getmouse(), ungetmouse(), init_color()
9#
10
11import curses, sys, tempfile
12
13# Optionally test curses module. This currently requires that the
14# 'curses' resource be given on the regrtest command line using the -u
15# option. If not available, nothing after this line will be executed.
16
17from test import test_support
18test_support.requires('curses')
19
20def window_funcs(stdscr):
21 "Test the methods of windows"
22 win = curses.newwin(10,10)
23 win = curses.newwin(5,5, 5,5)
24 win2 = curses.newwin(15,15, 5,5)
25
26 for meth in [stdscr.addch, stdscr.addstr]:
27 for args in [('a'), ('a', curses.A_BOLD),
28 (4,4, 'a'), (5,5, 'a', curses.A_BOLD)]:
29 meth(*args)
30
31 for meth in [stdscr.box, stdscr.clear, stdscr.clrtobot,
32 stdscr.clrtoeol, stdscr.cursyncup, stdscr.delch,
33 stdscr.deleteln, stdscr.erase, stdscr.getbegyx,
34 stdscr.getbkgd, stdscr.getkey, stdscr.getmaxyx,
35 stdscr.getparyx, stdscr.getyx, stdscr.inch,
36 stdscr.insertln, stdscr.instr, stdscr.is_wintouched,
37 win.noutrefresh, stdscr.redrawwin, stdscr.refresh,
38 stdscr.standout, stdscr.standend, stdscr.syncdown,
39 stdscr.syncup, stdscr.touchwin, stdscr.untouchwin]:
40 meth()
41
42 stdscr.addnstr('1234', 3)
43 stdscr.addnstr('1234', 3, curses.A_BOLD)
44 stdscr.addnstr(4,4, '1234', 3)
45 stdscr.addnstr(5,5, '1234', 3, curses.A_BOLD)
46
47 stdscr.attron(curses.A_BOLD)
48 stdscr.attroff(curses.A_BOLD)
49 stdscr.attrset(curses.A_BOLD)
50 stdscr.bkgd(' ')
51 stdscr.bkgd(' ', curses.A_REVERSE)
52 stdscr.bkgdset(' ')
53 stdscr.bkgdset(' ', curses.A_REVERSE)
54
55 win.border(65, 66, 67, 68,
56 69, 70, 71, 72)
57 win.border('|', '!', '-', '_',
58 '+', '\\', '#', '/')
59 try:
60 win.border(65, 66, 67, 68,
61 69, [], 71, 72)
62 except TypeError:
63 pass
64 else:
65 raise RuntimeError, "Expected win.border() to raise TypeError"
66
67 stdscr.clearok(1)
68
69 win4 = stdscr.derwin(2,2)
70 win4 = stdscr.derwin(1,1, 5,5)
71 win4.mvderwin(9,9)
72
73 stdscr.echochar('a')
74 stdscr.echochar('a', curses.A_BOLD)
75 stdscr.hline('-', 5)
76 stdscr.hline('-', 5, curses.A_BOLD)
77 stdscr.hline(1,1,'-', 5)
78 stdscr.hline(1,1,'-', 5, curses.A_BOLD)
79
80 stdscr.idcok(1)
81 stdscr.idlok(1)
82 stdscr.immedok(1)
83 stdscr.insch('c')
84 stdscr.insdelln(1)
85 stdscr.insnstr('abc', 3)
86 stdscr.insnstr('abc', 3, curses.A_BOLD)
87 stdscr.insnstr(5, 5, 'abc', 3)
88 stdscr.insnstr(5, 5, 'abc', 3, curses.A_BOLD)
89
90 stdscr.insstr('def')
91 stdscr.insstr('def', curses.A_BOLD)
92 stdscr.insstr(5, 5, 'def')
93 stdscr.insstr(5, 5, 'def', curses.A_BOLD)
94 stdscr.is_linetouched(0)
95 stdscr.keypad(1)
96 stdscr.leaveok(1)
97 stdscr.move(3,3)
98 win.mvwin(2,2)
99 stdscr.nodelay(1)
100 stdscr.notimeout(1)
101 win2.overlay(win)
102 win2.overwrite(win)
103 stdscr.redrawln(1,2)
104
105 stdscr.scrollok(1)
106 stdscr.scroll()
107 stdscr.scroll(2)
108 stdscr.scroll(-3)
109
110 stdscr.move(12, 2)
111 stdscr.setscrreg(10,15)
112 win3 = stdscr.subwin(10,10)
113 win3 = stdscr.subwin(10,10, 5,5)
114 stdscr.syncok(1)
115 stdscr.timeout(5)
116 stdscr.touchline(5,5)
117 stdscr.touchline(5,5,0)
118 stdscr.vline('a', 3)
119 stdscr.vline('a', 3, curses.A_STANDOUT)
120 stdscr.vline(1,1, 'a', 3)
121 stdscr.vline(1,1, 'a', 3, curses.A_STANDOUT)
122
123 if hasattr(curses, 'resize'):
124 stdscr.resize()
125 if hasattr(curses, 'enclose'):
126 stdscr.enclose()
127
128
129def module_funcs(stdscr):
130 "Test module-level functions"
131
132 for func in [curses.baudrate, curses.beep, curses.can_change_color,
133 curses.cbreak, curses.def_prog_mode, curses.doupdate,
134 curses.filter, curses.flash, curses.flushinp,
135 curses.has_colors, curses.has_ic, curses.has_il,
136 curses.isendwin, curses.killchar, curses.longname,
137 curses.nocbreak, curses.noecho, curses.nonl,
138 curses.noqiflush, curses.noraw,
139 curses.reset_prog_mode, curses.termattrs,
140 curses.termname, curses.erasechar, curses.getsyx]:
141 func()
142
143 # Functions that actually need arguments
144 if curses.tigetstr("cnorm"):
145 curses.curs_set(1)
146 curses.delay_output(1)
147 curses.echo() ; curses.echo(1)
148
149 f = tempfile.TemporaryFile()
150 stdscr.putwin(f)
151 f.seek(0)
152 curses.getwin(f)
153 f.close()
154
155 curses.halfdelay(1)
156 curses.intrflush(1)
157 curses.meta(1)
158 curses.napms(100)
159 curses.newpad(50,50)
160 win = curses.newwin(5,5)
161 win = curses.newwin(5,5, 1,1)
162 curses.nl() ; curses.nl(1)
163 curses.putp('abc')
164 curses.qiflush()
165 curses.raw() ; curses.raw(1)
166 curses.setsyx(5,5)
167 curses.setupterm(fd=sys.__stdout__.fileno())
168 curses.tigetflag('hc')
169 curses.tigetnum('co')
170 curses.tigetstr('cr')
171 curses.tparm('cr')
172 curses.typeahead(sys.__stdin__.fileno())
173 curses.unctrl('a')
174 curses.ungetch('a')
175 curses.use_env(1)
176
177 # Functions only available on a few platforms
178 if curses.has_colors():
179 curses.start_color()
180 curses.init_pair(2, 1,1)
181 curses.color_content(1)
182 curses.color_pair(2)
183 curses.pair_content(curses.COLOR_PAIRS - 1)
184 curses.pair_number(0)
185
186 if hasattr(curses, 'use_default_colors'):
187 curses.use_default_colors()
188
189 if hasattr(curses, 'keyname'):
190 curses.keyname(13)
191
192 if hasattr(curses, 'has_key'):
193 curses.has_key(13)
194
195 if hasattr(curses, 'getmouse'):
196 curses.mousemask(curses.BUTTON1_PRESSED)
197 curses.mouseinterval(10)
198
199def unit_tests():
200 from curses import ascii
201 for ch, expected in [('a', 'a'), ('A', 'A'),
202 (';', ';'), (' ', ' '),
203 ('\x7f', '^?'), ('\n', '^J'), ('\0', '^@'),
204 # Meta-bit characters
205 ('\x8a', '!^J'), ('\xc1', '!A'),
206 ]:
207 if ascii.unctrl(ch) != expected:
208 print 'curses.unctrl fails on character', repr(ch)
209
210
211
212def main(stdscr):
213 curses.savetty()
214 try:
215 module_funcs(stdscr)
216 window_funcs(stdscr)
217 finally:
218 curses.resetty()
219
220
221if __name__ == '__main__':
222 curses.wrapper(main)
223 unit_tests()
224else:
225 try:
226 stdscr = curses.initscr()
227 main(stdscr)
228 finally:
229 curses.endwin()
230
231 unit_tests()