/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2003, International Business Machines Corporation and
+ * Copyright (c) 1997-2009, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
TESTCASE(1,TestComplexExample);
TESTCASE(2,TestClosures);
TESTCASE(3,TestPatterns);
+ TESTCASE(4,TestChoiceFormatToPatternOverflow);
default: name = ""; break;
}
}
}
//form->parse(res1, f, parse_pos);
res2 = " ??? ";
- it_out << ix << " -> " << res1 << " -> " << res2 << endl;
+ it_logln(UnicodeString("") + ix + UnicodeString(" -> ") + res1 + UnicodeString(" -> ") + res2);
}
//Testing ==operator
const double filelimits[] = {0,1,2};
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()
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;
}
UnicodeString str;
UnicodeString res1, res2;
pattform->toPattern( res1 );
- it_out << "MessageFormat toPattern: " << res1 << endl;
+ it_logln("MessageFormat toPattern: " + res1);
fileform->toPattern( res1 );
- it_out << "ChoiceFormat toPattern: " << res1 << endl;
- if (res1 == "-1.0#are corrupted files|0.0#are no files|1.0#is one file|2.0#are {2} files") {
- it_out << "toPattern tested!" << endl;
+ it_logln("ChoiceFormat toPattern: " + res1);
+ 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!");
}
delete pattform;
return;
}
- it_out << i << " -> " << res2 << endl;
+ it_logln(i + UnicodeString(" -> ") + res2);
if (res2 != checkstr[i - start]) {
it_errln("*** test_complex_example res string");
- it_out << "*** " << i << " -> '" << res2 << "' unlike '" << checkstr[i] << "' ! " << endl;
+ it_errln(UnicodeString("*** ") + i + UnicodeString(" -> '") + res2 + UnicodeString("' unlike '") + checkstr[i] + UnicodeString("' ! "));
}
}
- it_out << endl;
+ it_logln();
- it_out << "------ additional testing in complex test ------" << endl << endl;
+ it_logln("------ additional testing in complex test ------");
+ it_logln();
//
int32_t retCount;
const double* retLimits = fileform->getLimits( retCount );
&& (retLimits[1] == 0.0)
&& (retLimits[2] == 1.0)
&& (retLimits[3] == 2.0)) {
- it_out << "getLimits tested!" << endl;
+ it_logln("getLimits tested!");
}else{
it_errln("*** getLimits unexpected result!");
}
&& (retFormats[1] == "are no files")
&& (retFormats[2] == "is one file")
&& (retFormats[3] == "are {2} files")) {
- it_out << "getFormats tested!" << endl;
+ it_logln("getFormats tested!");
}else{
it_errln("*** getFormats unexpected result!");
}
};
fileform->applyPattern("0#is no folder|1#is one folder|2#are many folders", status );
- if (status == U_ZERO_ERROR) it_out << "status applyPattern OK!" << endl;
+ if (status == U_ZERO_ERROR)
+ it_logln("status applyPattern OK!");
if (!chkstatus( status, "*** test_complex_example pattform" )) {
delete fileform;
delete filenumform;
delete pattform;
return;
}
- it_out << i << " -> " << res2 << endl;
+ it_logln(UnicodeString() + i + UnicodeString(" -> ") + res2);
if (res2 != checkstr2[i]) {
it_errln("*** test_complex_example res string");
- it_out << "*** " << i << " -> '" << res2 << "' unlike '" << checkstr2[i] << "' ! " << endl;
+ it_errln(UnicodeString("*** ") + i + UnicodeString(" -> '") + res2 + UnicodeString("' unlike '") + checkstr2[i] + UnicodeString("' ! "));
}
}
it_errln("*** test-choiceFormat not allocatable!");
}else{
if (*form_A == *form_A2) {
- it_out << "operator== tested." << endl;
+ it_logln("operator== tested.");
}else{
it_errln("*** operator==");
}
if (*form_A != *form_B) {
- it_out << "operator!= tested." << endl;
+ it_logln("operator!= tested.");
}else{
it_errln("*** operator!=");
}
it_errln("*** ChoiceFormat->clone is nil.");
}else{
if ((*form_A3 == *form_A) && (*form_A3 != *form_B)) {
- it_out << "method clone tested." << endl;
+ it_logln("method clone tested.");
}else{
it_errln("*** ChoiceFormat clone or operator==, or operator!= .");
}
form_Assigned = *form_B;
ok = ok && (form_Assigned != *form_A) && (form_Assigned == *form_B);
if (ok) {
- it_out << "copy constructor and operator= tested." << endl;
+ it_logln("copy constructor and operator= tested.");
}else{
it_errln("*** copy constructor or operator= or operator == or operator != .");
}
}
form_pat.toPattern( res1 );
- if (res1 == "0.0#none|1.0#one|2.0#many") {
- it_out << "ChoiceFormat contructor( newPattern, status) tested" << endl;
+ 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_out << "ChoiceFormat adoptChoices tested" << endl;
- }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_out << "ChoiceFormat adoptChoices toPattern: " << res1 << endl;
- if (res1 == "3.0#third|4.0#forth") {
- it_out << "ChoiceFormat adoptChoices tested" << endl;
+ it_logln(UnicodeString("ChoiceFormat adoptChoices toPattern: ") + res1);
+ if (res1 == "3#third|4#forth") {
+ it_logln("ChoiceFormat adoptChoices tested");
}else{
it_errln("*** ChoiceFormat adoptChoices result!");
}
status = U_ZERO_ERROR;
double arg_double = 3.0;
res1 = form_pat.format( arg_double, str, fpos );
- it_out << "ChoiceFormat format:" << res1 << endl;
+ it_logln(UnicodeString("ChoiceFormat format:") + res1);
if (res1 != "third") it_errln("*** ChoiceFormat format (double, ...) result!");
+ str = "";
+ fpos = 0;
+ status = U_ZERO_ERROR;
+ int64_t arg_64 = 3;
+ res1 = form_pat.format( arg_64, str, fpos );
+ it_logln(UnicodeString("ChoiceFormat format:") + res1);
+ if (res1 != "third") it_errln("*** ChoiceFormat format (int64_t, ...) result!");
+
str = "";
fpos = 0;
status = U_ZERO_ERROR;
int32_t arg_long = 3;
res1 = form_pat.format( arg_long, str, fpos );
- it_out << "ChoiceFormat format:" << res1 << endl;
+ it_logln(UnicodeString("ChoiceFormat format:") + res1);
if (res1 != "third") it_errln("*** ChoiceFormat format (int32_t, ...) result!");
Formattable ft( (int32_t)3 );
delete pattform;
return;
}
- it_out << "ChoiceFormat format:" << res1 << endl;
+ it_logln(UnicodeString("ChoiceFormat format:") + res1);
if (res1 != "third") it_errln("*** ChoiceFormat format (Formattable, ...) result!");
Formattable fta[] = { (int32_t)3 };
delete pattform;
return;
}
- it_out << "ChoiceFormat format:" << res1 << endl;
+ it_logln(UnicodeString("ChoiceFormat format:") + res1);
if (res1 != "third") it_errln("*** ChoiceFormat format (Formattable[], cnt, ...) result!");
ParsePosition parse_pos = 0;
form_pat.parse( parsetext, result, parse_pos );
double rd = (result.getType() == Formattable::kLong) ? result.getLong() : result.getDouble();
if (rd == 3.0) {
- it_out << "parse( ..., ParsePos ) tested." << endl;
+ it_logln("parse( ..., ParsePos ) tested.");
}else{
it_errln("*** ChoiceFormat parse( ..., ParsePos )!");
}
form_pat.parse( parsetext, result, status );
rd = (result.getType() == Formattable::kLong) ? result.getLong() : result.getDouble();
if (rd == 3.0) {
- it_out << "parse( ..., UErrorCode ) tested." << endl;
+ it_logln("parse( ..., UErrorCode ) tested.");
}else{
it_errln("*** ChoiceFormat parse( ..., UErrorCode )!");
}
}
*/
- it_out << endl;
+ it_logln();
delete fileform;
delete filenumform;
// '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");
0, 0, 0, 0, 0, 0);
}
+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 */