OLD | NEW |
1 /*********************************************************************** | 1 /*********************************************************************** |
2 * COPYRIGHT: | 2 * COPYRIGHT: |
3 * Copyright (c) 1997-2011, International Business Machines Corporation | 3 * Copyright (c) 1997-2015, International Business Machines Corporation |
4 * and others. All Rights Reserved. | 4 * and others. All Rights Reserved. |
5 ***********************************************************************/ | 5 ***********************************************************************/ |
6 | 6 |
7 #include "unicode/utypes.h" | 7 #include "unicode/utypes.h" |
8 | 8 |
9 #if !UCONFIG_NO_FORMATTING | 9 #if !UCONFIG_NO_FORMATTING |
10 | 10 |
11 #include "nmfmtrt.h" | 11 #include "nmfmtrt.h" |
12 | 12 |
13 #include "unicode/dcfmtsym.h" | 13 #include "unicode/dcfmtsym.h" |
14 #include "unicode/decimfmt.h" | 14 #include "unicode/decimfmt.h" |
15 #include "unicode/locid.h" | 15 #include "unicode/locid.h" |
16 #include "putilimp.h" | 16 #include "putilimp.h" |
17 | 17 |
18 #include <float.h> | 18 #include <float.h> |
19 #include <stdio.h> // for sprintf | 19 #include <stdio.h> // for sprintf |
20 #include <stdlib.h> | 20 #include <stdlib.h> |
21 | 21 |
22 // ***************************************************************************** | 22 // ***************************************************************************** |
23 // class NumberFormatRoundTripTest | 23 // class NumberFormatRoundTripTest |
24 // ***************************************************************************** | 24 // ***************************************************************************** |
25 | 25 |
26 UBool NumberFormatRoundTripTest::verbose = FALSE; | 26 UBool NumberFormatRoundTripTest::verbose = FALSE; |
27 UBool NumberFormatRoundTripTest::STRING_COMPARE = TRUE; | 27 UBool NumberFormatRoundTripTest::STRING_COMPARE = TRUE; |
28 UBool NumberFormatRoundTripTest::EXACT_NUMERIC_COMPARE = FALSE; | 28 UBool NumberFormatRoundTripTest::EXACT_NUMERIC_COMPARE = FALSE; |
29 UBool NumberFormatRoundTripTest::DEBUG = FALSE; | 29 UBool NumberFormatRoundTripTest::DEBUG_VAR = FALSE; |
30 double NumberFormatRoundTripTest::MAX_ERROR = 1e-14; | 30 double NumberFormatRoundTripTest::MAX_ERROR = 1e-14; |
31 double NumberFormatRoundTripTest::max_numeric_error = 0.0; | 31 double NumberFormatRoundTripTest::max_numeric_error = 0.0; |
32 double NumberFormatRoundTripTest::min_numeric_error = 1.0; | 32 double NumberFormatRoundTripTest::min_numeric_error = 1.0; |
33 | 33 |
34 #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); log
ln((UnicodeString)""); test(); } break; | 34 #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); log
ln((UnicodeString)""); test(); } break; |
35 | 35 |
36 void NumberFormatRoundTripTest::runIndexedTest( int32_t index, UBool exec, const
char* &name, char* /*par*/ ) | 36 void NumberFormatRoundTripTest::runIndexedTest( int32_t index, UBool exec, const
char* &name, char* /*par*/ ) |
37 { | 37 { |
38 // if (exec) logln((UnicodeString)"TestSuite NumberFormatRoundTripTest"); | 38 // if (exec) logln((UnicodeString)"TestSuite NumberFormatRoundTripTest"); |
39 switch (index) { | 39 switch (index) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 236 } |
237 UErrorCode status = U_ZERO_ERROR; | 237 UErrorCode status = U_ZERO_ERROR; |
238 UnicodeString s, s2, temp; | 238 UnicodeString s, s2, temp; |
239 if(isDouble(value)) | 239 if(isDouble(value)) |
240 s = fmt->format(value.getDouble(), s); | 240 s = fmt->format(value.getDouble(), s); |
241 else | 241 else |
242 s = fmt->format(value.getLong(), s); | 242 s = fmt->format(value.getLong(), s); |
243 | 243 |
244 Formattable n; | 244 Formattable n; |
245 UBool show = verbose; | 245 UBool show = verbose; |
246 if(DEBUG) | 246 if(DEBUG_VAR) |
247 logln(/*value.getString(temp) +*/ " F> " + escape(s)); | 247 logln(/*value.getString(temp) +*/ " F> " + escape(s)); |
248 | 248 |
249 fmt->parse(s, n, status); | 249 fmt->parse(s, n, status); |
250 failure(status, "fmt->parse"); | 250 failure(status, "fmt->parse"); |
251 if(DEBUG) | 251 if(DEBUG_VAR) |
252 logln(escape(s) + " P> " /*+ n.getString(temp)*/); | 252 logln(escape(s) + " P> " /*+ n.getString(temp)*/); |
253 | 253 |
254 if(isDouble(n)) | 254 if(isDouble(n)) |
255 s2 = fmt->format(n.getDouble(), s2); | 255 s2 = fmt->format(n.getDouble(), s2); |
256 else | 256 else |
257 s2 = fmt->format(n.getLong(), s2); | 257 s2 = fmt->format(n.getLong(), s2); |
258 | 258 |
259 if(DEBUG) | 259 if(DEBUG_VAR) |
260 logln(/*n.getString(temp) +*/ " F> " + escape(s2)); | 260 logln(/*n.getString(temp) +*/ " F> " + escape(s2)); |
261 | 261 |
262 if(STRING_COMPARE) { | 262 if(STRING_COMPARE) { |
263 if (s != s2) { | 263 if (s != s2) { |
264 errln("*** STRING ERROR \"" + escape(s) + "\" != \"" + escape(s2) +
"\""); | 264 errln("*** STRING ERROR \"" + escape(s) + "\" != \"" + escape(s2) +
"\""); |
265 show = TRUE; | 265 show = TRUE; |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 if(EXACT_NUMERIC_COMPARE) { | 269 if(EXACT_NUMERIC_COMPARE) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 s += "+U"; | 348 s += "+U"; |
349 char temp[16]; | 349 char temp[16]; |
350 sprintf(temp, "%4X", c); // might not work | 350 sprintf(temp, "%4X", c); // might not work |
351 s += temp; | 351 s += temp; |
352 } | 352 } |
353 } | 353 } |
354 return s; | 354 return s; |
355 } | 355 } |
356 | 356 |
357 #endif /* #if !UCONFIG_NO_FORMATTING */ | 357 #endif /* #if !UCONFIG_NO_FORMATTING */ |
OLD | NEW |