/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2011, International Business Machines Corporation and
+ * Copyright (c) 1997-2016, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************
*
#include "cintltst.h"
#include "cmsgtst.h"
#include "cformtst.h"
+#include "cmemory.h"
static const char* const txt_testCasePatterns[] = {
"Quotes '', '{', a {0,number,integer} '{'0}",
strings_initialized = FALSE;
}
+#if (U_PLATFORM == U_PF_LINUX) /* add platforms here .. */
+/* Keep the #if above in sync with the one below that has the same "add platforms here .." comment. */
+#else
/* Platform dependent test to detect if this type will return NULL when interpreted as a pointer. */
static UBool returnsNullForType(int firstParam, ...) {
UBool isNULL;
va_end(marker);
return isNULL;
}
+#endif
/* Test u_formatMessage() with various test patterns() */
static void MessageFormatTest( void )
austrdup(result), austrdup(testResultStrings[i]) );
}
-#if U_PLATFORM_IS_DARWIN_BASED || (U_PLATFORM == U_PF_LINUX) /* add platforms here .. */
+#if (U_PLATFORM == U_PF_LINUX) /* add platforms here .. */
log_verbose("Skipping potentially crashing test for mismatched varargs.\n");
#else
log_verbose("Note: the next is a platform dependent test. If it crashes, add an exclusion for your platform near %s:%d\n", __FILE__, __LINE__);
result, 256, &status,
string, 1/7.0,
789.0+1000*(56+60*(34+60*12)));
+ (void)length; /* Suppress set but not used warning. */
u_austrncpy(cresult, result, sizeof(cresult));
int32_t length=0;
UErrorCode status = U_ZERO_ERROR;
- u_uastrncpy(pattern, PAT, sizeof(pattern)/sizeof(pattern[0]));
+ u_uastrncpy(pattern, PAT, UPRV_LENGTHOF(pattern));
/* Test umsg_open */
f1 = umsg_open(pattern,length,NULL,NULL,&status);
UChar result[128] = {0};
UChar expected[sizeof(expectedChars)];
- u_uastrncpy(pattern, patChars, sizeof(pattern)/sizeof(pattern[0]));
- u_uastrncpy(expected, expectedChars, sizeof(expected)/sizeof(expected[0]));
+ u_uastrncpy(pattern, patChars, UPRV_LENGTHOF(pattern));
+ u_uastrncpy(expected, expectedChars, UPRV_LENGTHOF(expected));
- u_formatMessage("en_US", pattern, 6, result, sizeof(result)/sizeof(result[0]), &status, arg);
+ u_formatMessage("en_US", pattern, 6, result, UPRV_LENGTHOF(result), &status, arg);
if (U_FAILURE(status)) {
log_err("u_formatMessage method failed. Error: %s \n",u_errorName(status));
}
}
}
+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, UPRV_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");
}