#include "unicode/format.h"
#include "unicode/decimfmt.h"
+#include "unicode/localpointer.h"
#include "unicode/locid.h"
#include "unicode/msgfmt.h"
#include "unicode/numfmt.h"
TESTCASE_AUTO(TestApostropheMode);
TESTCASE_AUTO(TestCompatibleApostrophe);
TESTCASE_AUTO(testCoverage);
+ TESTCASE_AUTO(testGetFormatNames);
TESTCASE_AUTO(TestTrimArgumentName);
TESTCASE_AUTO(TestSelectOrdinal);
TESTCASE_AUTO_END;
delete msgfmt;
}
+void TestMessageFormat::testGetFormatNames() {
+ IcuTestErrorCode errorCode(*this, "testGetFormatNames");
+ MessageFormat msgfmt("Hello, {alice,number} {oops,date,full} {zip,spellout} World.", Locale::getRoot(), errorCode);
+ if(errorCode.logIfFailureAndReset("MessageFormat() failed")) {
+ return;
+ }
+ LocalPointer<StringEnumeration> names(msgfmt.getFormatNames(errorCode));
+ if(errorCode.logIfFailureAndReset("msgfmt.getFormatNames() failed")) {
+ return;
+ }
+ const UnicodeString *name;
+ name = names->snext(errorCode);
+ if (name == NULL || errorCode.isFailure()) {
+ errln("msgfmt.getFormatNames()[0] failed: %s", errorCode.errorName());
+ errorCode.reset();
+ return;
+ }
+ if (!assertEquals("msgfmt.getFormatNames()[0]", UNICODE_STRING_SIMPLE("alice"), *name)) {
+ return;
+ }
+ name = names->snext(errorCode);
+ if (name == NULL || errorCode.isFailure()) {
+ errln("msgfmt.getFormatNames()[1] failed: %s", errorCode.errorName());
+ errorCode.reset();
+ return;
+ }
+ if (!assertEquals("msgfmt.getFormatNames()[1]", UNICODE_STRING_SIMPLE("oops"), *name)) {
+ return;
+ }
+ name = names->snext(errorCode);
+ if (name == NULL || errorCode.isFailure()) {
+ errln("msgfmt.getFormatNames()[2] failed: %s", errorCode.errorName());
+ errorCode.reset();
+ return;
+ }
+ if (!assertEquals("msgfmt.getFormatNames()[2]", UNICODE_STRING_SIMPLE("zip"), *name)) {
+ return;
+ }
+ name = names->snext(errorCode);
+ if (name != NULL) {
+ errln(UnicodeString("msgfmt.getFormatNames()[3] should be NULL but is: ") + *name);
+ return;
+ }
+}
+
void TestMessageFormat::TestTrimArgumentName() {
// ICU 4.8 allows and ignores white space around argument names and numbers.
IcuTestErrorCode errorCode(*this, "TestTrimArgumentName");