]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
374ca955 | 3 | * Copyright (C) 2002-2003 IBM, Inc. All Rights Reserved. |
b75a7d8f A |
4 | * |
5 | ********************************************************************/ | |
6 | /***************************************************************************** | |
7 | * File charperf.cpp | |
8 | * | |
9 | * Modification History: | |
10 | * Name Description | |
11 | * Syn Wee Quek First Version | |
12 | ****************************************************************************** | |
13 | */ | |
14 | ||
15 | /** | |
16 | * This program tests character properties performance. | |
17 | * APIs tested: | |
18 | * ICU4C | |
19 | * Windows | |
20 | */ | |
21 | ||
22 | #include "charperf.h" | |
23 | #include "uoptions.h" | |
24 | ||
25 | UOption options[] = { | |
26 | UOPTION_DEF("min", 'n', UOPT_REQUIRES_ARG), | |
27 | UOPTION_DEF("min", 'x', UOPT_REQUIRES_ARG), | |
28 | }; | |
29 | int MIN_OPTION_ = 0; | |
30 | int MAX_OPTION_ = 1; | |
31 | ||
32 | int main(int argc, const char *argv[]) | |
33 | { | |
34 | UErrorCode status = U_ZERO_ERROR; | |
35 | CharPerformanceTest test(argc, argv, status); | |
36 | if (U_FAILURE(status)){ | |
37 | return status; | |
38 | } | |
39 | if (test.run() == FALSE){ | |
40 | fprintf(stderr, "FAILED: Tests could not be run please check the " | |
41 | "arguments.\n"); | |
42 | return -1; | |
43 | } | |
44 | return 0; | |
45 | } | |
46 | ||
47 | CharPerformanceTest::CharPerformanceTest(int32_t argc, const char *argv[], | |
48 | UErrorCode &status) | |
49 | : UPerfTest(argc, argv, status) | |
50 | { | |
51 | if (status== U_ILLEGAL_ARGUMENT_ERROR){ | |
52 | fprintf(stderr,gUsageString, "charperf"); | |
53 | return; | |
54 | } | |
55 | if (U_FAILURE(status)){ | |
56 | fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n", | |
57 | u_errorName(status)); | |
58 | return; | |
59 | } | |
60 | ||
61 | if (_remainingArgc < 0) { | |
62 | // that means there are some -names not matched in the super class | |
63 | // first tag is always skipped in u_parseArgs | |
64 | int size = - _remainingArgc; | |
65 | argv += argc - size; | |
66 | argc = size; | |
67 | _remainingArgc = u_parseArgs(argc, (char**)argv, | |
68 | (int32_t)(sizeof(options)/sizeof(options[0])), options); | |
69 | } | |
70 | MIN_ = 0; | |
374ca955 A |
71 | if (sizeof(wchar_t) > 2) { |
72 | // for stdlibs like glibc that supports 32 bits wchar | |
73 | // we test for the whole unicode character set by default | |
74 | MAX_ = 0x10ffff; | |
75 | } | |
76 | else { | |
77 | MAX_ = 0xffff; | |
78 | } | |
79 | printf("MAX_ size will be 0x%x\n", MAX_); | |
b75a7d8f A |
80 | if (options[MIN_OPTION_].doesOccur) { |
81 | MIN_ = atoi(options[MIN_OPTION_].value); | |
82 | } | |
83 | if (options[MAX_OPTION_].doesOccur) { | |
84 | MAX_ = atoi(options[MAX_OPTION_].value); | |
85 | } | |
86 | } | |
87 | ||
88 | CharPerformanceTest::~CharPerformanceTest() | |
89 | { | |
90 | } | |
91 | ||
92 | UPerfFunction* CharPerformanceTest::runIndexedTest(int32_t index, UBool exec, | |
93 | const char *&name, | |
94 | char* par) | |
95 | { | |
96 | switch (index) { | |
97 | TESTCASE(0, TestIsAlpha); | |
98 | TESTCASE(1, TestIsUpper); | |
99 | TESTCASE(2, TestIsLower); | |
100 | TESTCASE(3, TestIsDigit); | |
101 | TESTCASE(4, TestIsSpace); | |
102 | TESTCASE(5, TestIsAlphaNumeric); | |
103 | TESTCASE(6, TestIsPrint); | |
104 | TESTCASE(7, TestIsControl); | |
105 | TESTCASE(8, TestToLower); | |
106 | TESTCASE(9, TestToUpper); | |
107 | TESTCASE(10, TestIsWhiteSpace); | |
108 | TESTCASE(11, TestStdLibIsAlpha); | |
109 | TESTCASE(12, TestStdLibIsUpper); | |
110 | TESTCASE(13, TestStdLibIsLower); | |
111 | TESTCASE(14, TestStdLibIsDigit); | |
112 | TESTCASE(15, TestStdLibIsSpace); | |
113 | TESTCASE(16, TestStdLibIsAlphaNumeric); | |
114 | TESTCASE(17, TestStdLibIsPrint); | |
115 | TESTCASE(18, TestStdLibIsControl); | |
116 | TESTCASE(19, TestStdLibToLower); | |
117 | TESTCASE(20, TestStdLibToUpper); | |
118 | TESTCASE(21, TestStdLibIsWhiteSpace); | |
119 | default: | |
120 | name = ""; | |
121 | return NULL; | |
122 | } | |
123 | return NULL; | |
124 | } | |
125 | ||
126 | UPerfFunction* CharPerformanceTest::TestIsAlpha() | |
127 | { | |
128 | return new CharPerfFunction(isAlpha, MIN_, MAX_); | |
129 | } | |
130 | ||
131 | UPerfFunction* CharPerformanceTest::TestIsUpper() | |
132 | { | |
133 | return new CharPerfFunction(isUpper, MIN_, MAX_); | |
134 | } | |
135 | ||
136 | UPerfFunction* CharPerformanceTest::TestIsLower() | |
137 | { | |
138 | return new CharPerfFunction(isLower, MIN_, MAX_); | |
139 | } | |
140 | ||
141 | UPerfFunction* CharPerformanceTest::TestIsDigit() | |
142 | { | |
143 | return new CharPerfFunction(isDigit, MIN_, MAX_); | |
144 | } | |
145 | ||
146 | UPerfFunction* CharPerformanceTest::TestIsSpace() | |
147 | { | |
148 | return new CharPerfFunction(isSpace, MIN_, MAX_); | |
149 | } | |
150 | ||
151 | UPerfFunction* CharPerformanceTest::TestIsAlphaNumeric() | |
152 | { | |
153 | return new CharPerfFunction(isAlphaNumeric, MIN_, MAX_); | |
154 | } | |
155 | ||
156 | /** | |
157 | * This test may be different since c lib has a type PUNCT and it is printable. | |
158 | * iswgraph is not used for testing since it is a subset of iswprint with the | |
159 | * exception of returning true for white spaces. no match found in icu4c. | |
160 | */ | |
161 | UPerfFunction* CharPerformanceTest::TestIsPrint() | |
162 | { | |
163 | return new CharPerfFunction(isPrint, MIN_, MAX_); | |
164 | } | |
165 | ||
166 | UPerfFunction* CharPerformanceTest::TestIsControl() | |
167 | { | |
168 | return new CharPerfFunction(isControl, MIN_, MAX_); | |
169 | } | |
170 | ||
171 | UPerfFunction* CharPerformanceTest::TestToLower() | |
172 | { | |
173 | return new CharPerfFunction(toLower, MIN_, MAX_); | |
174 | } | |
175 | ||
176 | UPerfFunction* CharPerformanceTest::TestToUpper() | |
177 | { | |
178 | return new CharPerfFunction(toUpper, MIN_, MAX_); | |
179 | } | |
180 | ||
181 | UPerfFunction* CharPerformanceTest::TestIsWhiteSpace() | |
182 | { | |
183 | return new CharPerfFunction(isWhiteSpace, MIN_, MAX_); | |
184 | } | |
185 | ||
186 | UPerfFunction* CharPerformanceTest::TestStdLibIsAlpha() | |
187 | { | |
188 | return new StdLibCharPerfFunction(StdLibIsAlpha, (wchar_t)MIN_, | |
189 | (wchar_t)MAX_); | |
190 | } | |
191 | ||
192 | UPerfFunction* CharPerformanceTest::TestStdLibIsUpper() | |
193 | { | |
194 | return new StdLibCharPerfFunction(StdLibIsUpper, (wchar_t)MIN_, | |
195 | (wchar_t)MAX_); | |
196 | } | |
197 | ||
198 | UPerfFunction* CharPerformanceTest::TestStdLibIsLower() | |
199 | { | |
200 | return new StdLibCharPerfFunction(StdLibIsLower, (wchar_t)MIN_, | |
201 | (wchar_t)MAX_); | |
202 | } | |
203 | ||
204 | UPerfFunction* CharPerformanceTest::TestStdLibIsDigit() | |
205 | { | |
206 | return new StdLibCharPerfFunction(StdLibIsDigit, (wchar_t)MIN_, | |
207 | (wchar_t)MAX_); | |
208 | } | |
209 | ||
210 | UPerfFunction* CharPerformanceTest::TestStdLibIsSpace() | |
211 | { | |
212 | return new StdLibCharPerfFunction(StdLibIsSpace, (wchar_t)MIN_, | |
213 | (wchar_t)MAX_); | |
214 | } | |
215 | ||
216 | UPerfFunction* CharPerformanceTest::TestStdLibIsAlphaNumeric() | |
217 | { | |
218 | return new StdLibCharPerfFunction(StdLibIsAlphaNumeric, (wchar_t)MIN_, | |
219 | (wchar_t)MAX_); | |
220 | } | |
221 | ||
222 | /** | |
223 | * This test may be different since c lib has a type PUNCT and it is printable. | |
224 | * iswgraph is not used for testing since it is a subset of iswprint with the | |
225 | * exception of returning true for white spaces. no match found in icu4c. | |
226 | */ | |
227 | UPerfFunction* CharPerformanceTest::TestStdLibIsPrint() | |
228 | { | |
229 | return new StdLibCharPerfFunction(StdLibIsPrint, (wchar_t)MIN_, | |
230 | (wchar_t)MAX_); | |
231 | } | |
232 | ||
233 | UPerfFunction* CharPerformanceTest::TestStdLibIsControl() | |
234 | { | |
235 | return new StdLibCharPerfFunction(StdLibIsControl, (wchar_t)MIN_, | |
236 | (wchar_t)MAX_); | |
237 | } | |
238 | ||
239 | UPerfFunction* CharPerformanceTest::TestStdLibToLower() | |
240 | { | |
241 | return new StdLibCharPerfFunction(StdLibToLower, (wchar_t)MIN_, | |
242 | (wchar_t)MAX_); | |
243 | } | |
244 | ||
245 | UPerfFunction* CharPerformanceTest::TestStdLibToUpper() | |
246 | { | |
247 | return new StdLibCharPerfFunction(StdLibToUpper, (wchar_t)MIN_, | |
248 | (wchar_t)MAX_); | |
249 | } | |
250 | ||
251 | UPerfFunction* CharPerformanceTest::TestStdLibIsWhiteSpace() | |
252 | { | |
253 | return new StdLibCharPerfFunction(StdLibIsWhiteSpace, (wchar_t)MIN_, | |
254 | (wchar_t)MAX_); | |
255 | } |