/*
*******************************************************************************
*
-* Copyright (C) 1999-2011, International Business Machines
+* Copyright (C) 1999-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
break;
case Formattable::kObject:
+ // Unused argument number. Read and ignore a pointer argument.
+ va_arg(ap, void*);
+ break;
+
default:
- // This will never happen because MessageFormat doesn't
- // support kObject. When MessageFormat is changed to
- // understand MeasureFormats, modify this code to do the
- // right thing. [alan]
+ // Unknown/unsupported argument type.
U_ASSERT(FALSE);
*status=U_ILLEGAL_ARGUMENT_ERROR;
break;
#include "cmsgtst.h"
#include "cformtst.h"
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+
static const char* const txt_testCasePatterns[] = {
"Quotes '', '{', a {0,number,integer} '{'0}",
"Quotes '', '{', a {0,number,integer} '{'0}",
}
}
+static void TestMessageWithUnusedArgNumber() {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ U_STRING_DECL(pattern, "abc {1} def", 11);
+ UChar x[2] = { 0x78, 0 }; // "x"
+ UChar y[2] = { 0x79, 0 }; // "y"
+ U_STRING_DECL(expected, "abc y def", 9);
+ UChar result[20];
+ int32_t length;
+
+ U_STRING_INIT(pattern, "abc {1} def", 11);
+ U_STRING_INIT(expected, "abc y def", 9);
+ length = u_formatMessage("en", pattern, -1, result, LENGTHOF(result), &errorCode, x, y);
+ if (U_FAILURE(errorCode) || length != u_strlen(expected) || u_strcmp(result, expected) != 0) {
+ log_err("u_formatMessage(pattern with only {1}, 2 args) failed: result length %d, UErrorCode %s \n",
+ (int)length, u_errorName(errorCode));
+ }
+}
+
static void TestErrorChaining(void) {
UErrorCode status = U_USELESS_COLLATOR_ERROR;
addTest(root, &TestParseMessageWithValist, "tsformat/cmsgtst/TestParseMessageWithValist");
addTest(root, &TestJ904, "tsformat/cmsgtst/TestJ904");
addTest(root, &MessageLength, "tsformat/cmsgtst/MessageLength");
+ addTest(root, &TestMessageWithUnusedArgNumber, "tsformat/cmsgtst/TestMessageWithUnusedArgNumber");
addTest(root, &TestErrorChaining, "tsformat/cmsgtst/TestErrorChaining");
addTest(root, &TestMsgFormatSelect, "tsformat/cmsgtst/TestMsgFormatSelect");
}