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