1 |
27 |
unneback |
//=================================================================
|
2 |
|
|
//
|
3 |
|
|
// ctype.c
|
4 |
|
|
//
|
5 |
|
|
// General testcase for C library ctype functions
|
6 |
|
|
//
|
7 |
|
|
//=================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//=================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): ctarpy, jlarmour
|
44 |
|
|
// Contributors:
|
45 |
|
|
// Date: 2000-04-14
|
46 |
|
|
// Description: Contains general testcode for C library ctype functions
|
47 |
|
|
//
|
48 |
|
|
//
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
|
51 |
|
|
// INCLUDES
|
52 |
|
|
|
53 |
|
|
#include <stdlib.h>
|
54 |
|
|
#include <ctype.h>
|
55 |
|
|
#include <cyg/infra/testcase.h>
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
// FUNCTIONS
|
59 |
|
|
|
60 |
|
|
int
|
61 |
|
|
main( int argc, char *argv[] )
|
62 |
|
|
{
|
63 |
|
|
int c; // character we use as a parameter
|
64 |
|
|
|
65 |
|
|
CYG_TEST_INIT();
|
66 |
|
|
|
67 |
|
|
CYG_TEST_INFO( "Starting tests from testcase " __FILE__ " for C library "
|
68 |
|
|
"<ctype.h> functions" );
|
69 |
|
|
|
70 |
|
|
// Check isalnum
|
71 |
|
|
c = 't';
|
72 |
|
|
CYG_TEST_PASS_FAIL( isalnum(c), "isalnum('t')");
|
73 |
|
|
c = '2';
|
74 |
|
|
CYG_TEST_PASS_FAIL( isalnum(c), "isalnum('2')");
|
75 |
|
|
c = 2;
|
76 |
|
|
CYG_TEST_PASS_FAIL( !isalnum(c), "!isalnum(2)");
|
77 |
|
|
c = 127;
|
78 |
|
|
CYG_TEST_PASS_FAIL( !isalnum(c), "!isalnum(127)");
|
79 |
|
|
|
80 |
|
|
// Check isalpha
|
81 |
|
|
c = 'A';
|
82 |
|
|
CYG_TEST_PASS_FAIL( isalpha(c), "isalpha('A')");
|
83 |
|
|
c = 'a';
|
84 |
|
|
CYG_TEST_PASS_FAIL( isalpha(c), "isalpha('a')");
|
85 |
|
|
c = '2';
|
86 |
|
|
CYG_TEST_PASS_FAIL( !isalpha(c), "!isalpha('2')");
|
87 |
|
|
c = '\n';
|
88 |
|
|
CYG_TEST_PASS_FAIL( !isalpha(c), "!isalpha('newline')");
|
89 |
|
|
|
90 |
|
|
// Check iscntrl
|
91 |
|
|
c = 'a';
|
92 |
|
|
CYG_TEST_PASS_FAIL( !iscntrl(c), "!iscntrl('a')");
|
93 |
|
|
c = 7;
|
94 |
|
|
CYG_TEST_PASS_FAIL( iscntrl(c), "iscntrl('7')");
|
95 |
|
|
c = '\n';
|
96 |
|
|
CYG_TEST_PASS_FAIL( iscntrl(c), "iscntrl(newline)");
|
97 |
|
|
c = 0x7F;
|
98 |
|
|
CYG_TEST_PASS_FAIL( iscntrl(c), "iscntrl(0x7F)");
|
99 |
|
|
|
100 |
|
|
// Check isdigit
|
101 |
|
|
c = '2';
|
102 |
|
|
CYG_TEST_PASS_FAIL( isdigit(c), "isdigit('2')");
|
103 |
|
|
c = '0';
|
104 |
|
|
CYG_TEST_PASS_FAIL( isdigit(c), "isdigit('0')");
|
105 |
|
|
c = 't';
|
106 |
|
|
CYG_TEST_PASS_FAIL( !isdigit(c), "!isdigit('t')");
|
107 |
|
|
|
108 |
|
|
// Check isgraph
|
109 |
|
|
c = ')';
|
110 |
|
|
CYG_TEST_PASS_FAIL( isgraph(c), "isgraph(')')");
|
111 |
|
|
c = '~';
|
112 |
|
|
CYG_TEST_PASS_FAIL( isgraph(c), "isgraph('~')");
|
113 |
|
|
c = '9';
|
114 |
|
|
CYG_TEST_PASS_FAIL( isgraph(c), "isgraph('9')");
|
115 |
|
|
c = 9;
|
116 |
|
|
CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(9)");
|
117 |
|
|
c = ' ';
|
118 |
|
|
CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(' ')");
|
119 |
|
|
c = '\t';
|
120 |
|
|
CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(tab)");
|
121 |
|
|
c = '\n';
|
122 |
|
|
CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(newline)");
|
123 |
|
|
c = 0x7F;
|
124 |
|
|
CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(DEL)");
|
125 |
|
|
c = 200;
|
126 |
|
|
CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(200)");
|
127 |
|
|
c = '\0';
|
128 |
|
|
CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(NUL)");
|
129 |
|
|
|
130 |
|
|
// Check islower
|
131 |
|
|
c = 'J';
|
132 |
|
|
CYG_TEST_PASS_FAIL( !islower(c), "islower('J')");
|
133 |
|
|
c = 'j';
|
134 |
|
|
CYG_TEST_PASS_FAIL( islower(c), "islower('j')");
|
135 |
|
|
c = '5';
|
136 |
|
|
CYG_TEST_PASS_FAIL( !islower(c), "!islower(5)");
|
137 |
|
|
|
138 |
|
|
// Check isprint
|
139 |
|
|
c = ' ';
|
140 |
|
|
CYG_TEST_PASS_FAIL( isprint(c), "isprint(' ')");
|
141 |
|
|
c = 'x';
|
142 |
|
|
CYG_TEST_PASS_FAIL( isprint(c), "isprint('x')");
|
143 |
|
|
c = '\b';
|
144 |
|
|
CYG_TEST_PASS_FAIL( !isprint(c), "!isprint(backspace)");
|
145 |
|
|
|
146 |
|
|
// Check ispunct
|
147 |
|
|
c = '.';
|
148 |
|
|
CYG_TEST_PASS_FAIL( ispunct(c), "ispunct('.')");
|
149 |
|
|
c = '#';
|
150 |
|
|
CYG_TEST_PASS_FAIL( ispunct(c), "ispunct('#')");
|
151 |
|
|
c = '@';
|
152 |
|
|
CYG_TEST_PASS_FAIL( ispunct(c), "ispunct('@')");
|
153 |
|
|
c = 'f';
|
154 |
|
|
CYG_TEST_PASS_FAIL( !ispunct(c), "!ispunct('f')");
|
155 |
|
|
c = '7';
|
156 |
|
|
CYG_TEST_PASS_FAIL( !ispunct(c), "!ispunct('7')");
|
157 |
|
|
c = '\n';
|
158 |
|
|
CYG_TEST_PASS_FAIL( !ispunct(c), "!ispunct('newline')");
|
159 |
|
|
|
160 |
|
|
// Check isspace
|
161 |
|
|
c = ' ';
|
162 |
|
|
CYG_TEST_PASS_FAIL( isspace(c), "isspace(' ')");
|
163 |
|
|
c = '\t';
|
164 |
|
|
CYG_TEST_PASS_FAIL( isspace(c), "isspace(tab)");
|
165 |
|
|
c = '\r';
|
166 |
|
|
CYG_TEST_PASS_FAIL( isspace(c), "isspace(return)");
|
167 |
|
|
c = '\v';
|
168 |
|
|
CYG_TEST_PASS_FAIL( isspace(c), "isspace(vertical tab)");
|
169 |
|
|
c = '\n';
|
170 |
|
|
CYG_TEST_PASS_FAIL( isspace(c), "isspace(newline)");
|
171 |
|
|
c = 'd';
|
172 |
|
|
CYG_TEST_PASS_FAIL( !isspace(c), "!isspace('d')");
|
173 |
|
|
c = ',';
|
174 |
|
|
CYG_TEST_PASS_FAIL( !isspace(c), "!isspace(',')");
|
175 |
|
|
|
176 |
|
|
// Check isupper
|
177 |
|
|
c = 'A';
|
178 |
|
|
CYG_TEST_PASS_FAIL( isupper(c), "isupper('A')");
|
179 |
|
|
c = 'a';
|
180 |
|
|
CYG_TEST_PASS_FAIL( !isupper(c), "!isupper('a')");
|
181 |
|
|
c = '2';
|
182 |
|
|
CYG_TEST_PASS_FAIL( !isupper(c), "!isupper('2')");
|
183 |
|
|
c = '\b';
|
184 |
|
|
CYG_TEST_PASS_FAIL( !isupper(c), "!isupper(backspace)");
|
185 |
|
|
|
186 |
|
|
// Check isxdigit
|
187 |
|
|
c = 'f';
|
188 |
|
|
CYG_TEST_PASS_FAIL( isxdigit(c), "isxdigit('f')");
|
189 |
|
|
c = 'D';
|
190 |
|
|
CYG_TEST_PASS_FAIL( isxdigit(c), "isxdigit('D')");
|
191 |
|
|
c = '1';
|
192 |
|
|
CYG_TEST_PASS_FAIL( isxdigit(c), "isxdigit('1')");
|
193 |
|
|
c = '0';
|
194 |
|
|
CYG_TEST_PASS_FAIL( isxdigit(c), "isxdigit('0')");
|
195 |
|
|
c = 'g';
|
196 |
|
|
CYG_TEST_PASS_FAIL( !isxdigit(c), "!isxdigit('g')");
|
197 |
|
|
c = 'x';
|
198 |
|
|
CYG_TEST_PASS_FAIL( !isxdigit(c), "!isxdigit('x')");
|
199 |
|
|
|
200 |
|
|
// Check tolower
|
201 |
|
|
c = 'F';
|
202 |
|
|
CYG_TEST_PASS_FAIL( tolower(c) == 'f', "tolower('F')");
|
203 |
|
|
c = 'g';
|
204 |
|
|
CYG_TEST_PASS_FAIL( tolower(c) == 'g', "tolower('g')");
|
205 |
|
|
c = '3';
|
206 |
|
|
CYG_TEST_PASS_FAIL( tolower(c) == '3', "tolower('3')");
|
207 |
|
|
|
208 |
|
|
// Check toupper
|
209 |
|
|
c = 'f';
|
210 |
|
|
CYG_TEST_PASS_FAIL( toupper(c) == 'F', "toupper('f')");
|
211 |
|
|
c = 'G';
|
212 |
|
|
CYG_TEST_PASS_FAIL( toupper(c) == 'G', "toupper('G')");
|
213 |
|
|
c = ',';
|
214 |
|
|
CYG_TEST_PASS_FAIL( toupper(c) == ',', "toupper(',')");
|
215 |
|
|
|
216 |
|
|
CYG_TEST_FINISH( "Finished tests from testcase " __FILE__ " for C library "
|
217 |
|
|
"<ctype.h> functions" );
|
218 |
|
|
} // main()
|
219 |
|
|
|
220 |
|
|
// EOF ctype.c
|