/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2005, International Business Machines Corporation and
+ * Copyright (c) 1997-2011, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
TESTCASE(1,TestComplexExample);
TESTCASE(2,TestClosures);
TESTCASE(3,TestPatterns);
+ TESTCASE(4,TestChoiceFormatToPatternOverflow);
default: name = ""; break;
}
}
errln("ERROR: ==operator failed\n");
}
delete formequal;
-
-#ifdef U_USE_CHOICE_FORMAT_DEPRECATES
- //Testing adoptChoices()
- double *limitsToAdopt = (double *)uprv_malloc(7 * sizeof(double));
- UnicodeString *monthNamesToAdopt = new UnicodeString[7];
-
- uprv_arrayCopy(monthNames, monthNamesToAdopt, 7);
- uprv_memcpy(limitsToAdopt, limits, (size_t)(7 * sizeof(limits[0])));
-
- formnew->adoptChoices(limitsToAdopt, monthNamesToAdopt, 7);
- if(!(*formnew == *form)){
- errln("ERROR: ==Operator or adoptChoices failed\n");
- }
-#endif
-
delete formnew;
-
+
//Testing getLimits()
- double *gotLimits=0;
int32_t count=0;
- gotLimits=(double*)form->getLimits(count);
+ const double *gotLimits=form->getLimits(count);
+#if 1 // ICU 4.8 deprecates and disables the ChoiceFormat getters.
+ if(count != 0 || gotLimits != NULL) {
+ errln("getLimits() returns something, should be disabled");
+ }
+ const UnicodeString *gotFormats=form->getFormats(count);
+ if(count != 0 || gotFormats != NULL) {
+ errln("getFormats() returns something, should be disabled");
+ }
+ const UBool *gotClosures=form->getClosures(count);
+ if(count != 0 || gotClosures != NULL) {
+ errln("getClosures() returns something, should be disabled");
+ }
+#else
if(count != 7){
errln("getLimits didn't update the count correctly\n");
}
errln((UnicodeString)"getLimits didn't get the limits correctly. Expected " + limits[ix] + " Got " + gotLimits[ix]);
}
}
- //Testing getFormat()
+ //Testing getFormats()
count=0;
- UnicodeString *gotFormats=0;
- gotFormats=(UnicodeString*)form->getFormats(count);
+ const UnicodeString *gotFormats=form->getFormats(count);
if(count != 7){
errln("getFormats didn't update the count correctly\n");
}
errln((UnicodeString)"getFormats didn't get the Formats correctly. Expected " + monthNames[ix] + " Got " + gotFormats[ix]);
}
}
-
-
+#endif
+
delete form;
-
}
void
Format* filenumform = NumberFormat::createInstance( status );
if (!filenumform) {
- it_errln("*** test_complex_example filenumform");
+ dataerrln((UnicodeString)"*** test_complex_example filenumform - " + u_errorName(status));
delete fileform;
return;
}
it_logln("MessageFormat toPattern: " + res1);
fileform->toPattern( res1 );
it_logln("ChoiceFormat toPattern: " + res1);
- if (res1 == "-1.0#are corrupted files|0.0#are no files|1.0#is one file|2.0#are {2} files") {
+ if (res1 == "-1#are corrupted files|0#are no files|1#is one file|2#are {2} files") {
it_logln("toPattern tested!");
}else{
it_errln("*** ChoiceFormat to Pattern result!");
it_logln("------ additional testing in complex test ------");
it_logln();
//
+#if 0 // ICU 4.8 deprecates and disables the ChoiceFormat getters.
int32_t retCount;
const double* retLimits = fileform->getLimits( retCount );
if ((retCount == 4) && (retLimits)
}else{
it_errln("*** getFormats unexpected result!");
}
+#endif
UnicodeString checkstr2[] = {
"There is no folder on Disk_A",
}
form_pat.toPattern( res1 );
- if (res1 == "0.0#none|1.0#one|2.0#many") {
+ if (res1 == "0#none|1#one|2#many") {
it_logln("ChoiceFormat contructor( newPattern, status) tested");
}else{
it_errln("*** ChoiceFormat contructor( newPattern, status) or toPattern result!");
}
-#ifdef U_USE_CHOICE_FORMAT_DEPRECATES
- double* d_a = (double *)uprv_malloc(2 * sizeof(double));
- if (!d_a) { it_errln("*** allocation error."); return; }
- d_a[0] = 1.0; d_a[1] = 2.0;
-
- UnicodeString* s_a = new UnicodeString[2];
- if (!s_a) { it_errln("*** allocation error."); return; }
- s_a[0] = "first"; s_a[1] = "second";
-
- form_pat.adoptChoices( d_a, s_a, 2 );
- form_pat.toPattern( res1 );
- it_out << "ChoiceFormat adoptChoices toPattern: " << res1 << endl;
- if (res1 == "1.0#first|2.0#second") {
- it_logln("ChoiceFormat adoptChoices tested");
- }else{
- it_errln("*** ChoiceFormat adoptChoices result!");
- }
-#endif
-
double d_a2[] = { 3.0, 4.0 };
UnicodeString s_a2[] = { "third", "forth" };
form_pat.setChoices( d_a2, s_a2, 2 );
form_pat.toPattern( res1 );
it_logln(UnicodeString("ChoiceFormat adoptChoices toPattern: ") + res1);
- if (res1 == "3.0#third|4.0#forth") {
+ if (res1 == "3#third|4#forth") {
it_logln("ChoiceFormat adoptChoices tested");
}else{
it_errln("*** ChoiceFormat adoptChoices result!");
// 'fmt2' is created using a pattern; it should be equivalent
UErrorCode status = U_ZERO_ERROR;
- const char* PAT = "0.0#,1)|1.0#[1,2]|2.0<(2,3]|3.0<(3,4)|4.0#[4,5)|5.0#[5,";
+ const char* PAT = "0#,1)|1#[1,2]|2<(2,3]|3<(3,4)|4#[4,5)|5#[5,";
ChoiceFormat fmt2(PAT, status);
if (U_FAILURE(status)) {
errln("FAIL: ChoiceFormat constructor failed");
errln("FAIL: fmt1 != fmt2");
}
+#if 0 // ICU 4.8 deprecates and disables the ChoiceFormat getters.
int32_t i;
int32_t count2 = 0;
const double *limits2 = fmt2.getLimits(count2);
}
}
}
+#endif
// Now test both format objects
UnicodeString exp[] = {
1.0, "b",
1.0 + 1e-9, "c");
+#if 0 // ICU 4.8 only checks the pattern syntax, not whether the ranges make sense.
// Try an invalid pattern that isolates a single value.
// [-Inf,1.0) [1.0,1.0) [1.0,+Inf]
_testPattern("0.0#a|1.0#b|1.0#c", FALSE,
// [-Inf,2.0) [2.0,1.0) [1.0,+Inf]
_testPattern("0.0#a|2.0#b|1.0#c", FALSE,
0, 0, 0, 0, 0, 0);
+#endif
+}
+
+void TestChoiceFormat::TestChoiceFormatToPatternOverflow()
+{
+ static const double limits[] = {0.1e-78, 1e13, 0.1e78};
+ UnicodeString monthNames[] = { "one", "two", "three" };
+ ChoiceFormat fmt(limits, monthNames, sizeof(limits)/sizeof(limits[0]));
+ UnicodeString patStr, expectedPattern1("1e-79#one|10000000000000#two|1e+77#three"),
+ expectedPattern2("1e-079#one|10000000000000#two|1e+077#three");
+ fmt.toPattern(patStr);
+ if (patStr != expectedPattern1 && patStr != expectedPattern2) {
+ errln("ChoiceFormat returned \"" + patStr + "\" instead of \"" + expectedPattern1 + " or " + expectedPattern2 + "\"");
+ }
}
#endif /* #if !UCONFIG_NO_FORMATTING */