/***********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2004, International Business Machines Corporation
+ * Copyright (c) 1997-2009, International Business Machines Corporation
* and others. All Rights Reserved.
***********************************************************************/
CASE(18,Test4142938)
CASE(19,TestChoicePatternQuote)
CASE(20,Test4112104)
+ CASE(21,TestAPI)
default: name = ""; break;
}
}
UBool
-MessageFormatRegressionTest::failure(UErrorCode status, const char* msg)
+MessageFormatRegressionTest::failure(UErrorCode status, const char* msg, UBool possibleDataError)
{
if(U_FAILURE(status)) {
- errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ if (possibleDataError) {
+ dataerrln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ } else {
+ errln(UnicodeString("FAIL: ") + msg + " failed, error " + u_errorName(status));
+ }
return TRUE;
}
UnicodeString pat;
pat = fmt->toPattern(pat);
- UnicodeString exp("{0,choice,0.0#no files|1.0#one file|1.0< {0,number,integer} files}");
+ UnicodeString exp("{0,choice,0#no files|1#one file|1< {0,number,integer} files}");
if (pat != exp) {
errln("MessageFormat.toPattern failed");
errln("Exp: " + exp);
MessageFormat *messageFormatter = new MessageFormat("", status);
failure(status, "new MessageFormat");
+
+ const UBool possibleDataError = TRUE;
//try {
logln("Apply with pattern : " + pattern1);
FieldPosition pos(FieldPosition::DONT_CARE);
tempBuffer = messageFormatter->format(params, 1, tempBuffer, pos, status);
if(tempBuffer != "Impossible {1} has occurred -- status code is 7 and message is {2}." || failure(status, "MessageFormat::format"))
- errln("Tests arguments < substitution failed");
+ dataerrln("Tests arguments < substitution failed");
logln("Formatted with 7 : " + tempBuffer);
ParsePosition pp(0);
int32_t count = 0;
logln("Formatted with null : " + tempBuffer);*/
logln("Apply with pattern : " + pattern2);
messageFormatter->applyPattern(pattern2, status);
- failure(status, "messageFormatter->applyPattern");
+ failure(status, "messageFormatter->applyPattern", possibleDataError);
tempBuffer.remove();
tempBuffer = messageFormatter->format(params, 1, tempBuffer, pos, status);
if (tempBuffer != "Double ' Quotes 7 test and quoted {1} test plus other {2} stuff.")
- errln("quote format test (w/ params) failed.");
+ dataerrln("quote format test (w/ params) failed. - %s", u_errorName(status));
logln("Formatted with params : " + tempBuffer);
/*tempBuffer = messageFormatter->format(null);
for (int i = 0; i < 3; i++) {
UnicodeString pattern = patterns[i];
mf->applyPattern(pattern, status);
- failure(status, "mf->applyPattern");
+ failure(status, "mf->applyPattern", TRUE);
//try {
int32_t count = 0;
UErrorCode status = U_ZERO_ERROR;
UnicodeString pattern("-");
pattern += (UChar) 0x221E;
- pattern += "<are negative|0.0<are no or fraction|1.0#is one|1.0<is 1+|";
+ pattern += "<are negative|0<are no or fraction|1#is one|1<is 1+|";
pattern += (UChar) 0x221E;
pattern += "<are many.";
void MessageFormatRegressionTest::Test4118594()
{
UErrorCode status = U_ZERO_ERROR;
+ const UBool possibleDataError = TRUE;
MessageFormat *mf = new MessageFormat("{0}, {0}, {0}", status);
failure(status, "new MessageFormat");
UnicodeString forParsing("x, y, z");
if (objs[0].getString(str) != "z")
errln("argument0: \"" + objs[0].getString(str) + "\"");
mf->applyPattern("{0,number,#.##}, {0,number,#.#}", status);
- failure(status, "mf->applyPattern");
+ failure(status, "mf->applyPattern", possibleDataError);
//Object[] oldobjs = {new Double(3.1415)};
Formattable oldobjs [] = {Formattable(3.1415)};
UnicodeString result;
FieldPosition pos(FieldPosition::DONT_CARE);
result = mf->format( oldobjs, 1, result, pos, status );
- failure(status, "mf->format");
+ failure(status, "mf->format", possibleDataError);
pat.remove();
logln("pattern: \"" + mf->toPattern(pat) + "\"");
logln("text for parsing: \"" + result + "\"");
// result now equals "3.14, 3.1"
if (result != "3.14, 3.1")
- errln("result = " + result);
+ dataerrln("result = " + result + " - " + u_errorName(status));
//Object[] newobjs = mf.parse(result, new ParsePosition(0));
int32_t count1 = 0;
pp.setIndex(0);
Formattable *newobjs = mf->parse(result, pp, count1);
// newobjs now equals {new Double(3.1)}
- if (newobjs[0].getDouble() != 3.1)
- errln( UnicodeString("newobjs[0] = ") + newobjs[0].getDouble());
+ if (newobjs == NULL) {
+ dataerrln("Error calling MessageFormat::parse");
+ } else {
+ if (newobjs[0].getDouble() != 3.1)
+ errln( UnicodeString("newobjs[0] = ") + newobjs[0].getDouble());
+ }
delete [] objs;
delete [] newobjs;
UnicodeString patternText1("The disk \"{1}\" contains {0}.");
UnicodeString patternText2("There are {0} on the disk \"{1}\"");
UErrorCode status = U_ZERO_ERROR;
+ const UBool possibleDataError = TRUE;
MessageFormat *form1 = new MessageFormat(patternText1, status);
failure(status, "new MessageFormat");
MessageFormat *form2 = new MessageFormat(patternText2, status);
UnicodeString result;
logln(form1->format(testArgs, 2, result, bogus, status));
- failure(status, "form1->format");
+ failure(status, "form1->format", possibleDataError);
result.remove();
logln(form2->format(testArgs, 2, result, bogus, status));
- failure(status, "form1->format");
+ failure(status, "form1->format", possibleDataError);
delete form1;
delete form2;
};
FieldPosition pos(FieldPosition::DONT_CARE);
out = mf->format(objs, 1, out, pos, status);
- failure(status, "mf->format");
- if (SUFFIX[i] == "") {
- if (out != PREFIX[i])
- errln((UnicodeString)"" + i + ": Got \"" + out + "\"; Want \"" + PREFIX[i] + "\"");
- }
- else {
- if (!out.startsWith(PREFIX[i]) ||
- !out.endsWith(SUFFIX[i]))
- errln((UnicodeString)"" + i + ": Got \"" + out + "\"; Want \"" + PREFIX[i] + "\"...\"" +
- SUFFIX[i] + "\"");
+ if (!failure(status, "mf->format", TRUE)) {
+ if (SUFFIX[i] == "") {
+ if (out != PREFIX[i])
+ errln((UnicodeString)"" + i + ": Got \"" + out + "\"; Want \"" + PREFIX[i] + "\"");
+ }
+ else {
+ if (!out.startsWith(PREFIX[i]) ||
+ !out.endsWith(SUFFIX[i]))
+ errln((UnicodeString)"" + i + ": Got \"" + out + "\"; Want \"" + PREFIX[i] + "\"...\"" +
+ SUFFIX[i] + "\"");
+ }
}
}
delete format;
}
+void MessageFormatRegressionTest::TestAPI() {
+ UErrorCode status = U_ZERO_ERROR;
+ MessageFormat *format = new MessageFormat("", status);
+ failure(status, "new MessageFormat");
+
+ // Test adoptFormat
+ MessageFormat *fmt = new MessageFormat("",status);
+ format->adoptFormat("",fmt,status);
+ failure(status, "adoptFormat");
+
+ // Test getFormat
+ format->setFormat((int32_t)0,*fmt);
+ format->getFormat("",status);
+ failure(status, "getFormat");
+ delete format;
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */