diff --git a/icu4c/source/test/iotest/filetst.c b/icu4c/source/test/iotest/filetst.c index fc32978319..1a98d899df 100644 --- a/icu4c/source/test/iotest/filetst.c +++ b/icu4c/source/test/iotest/filetst.c @@ -1387,6 +1387,38 @@ static void TestVargs(void) { } #endif +static void TestUnicodeFormat(void) +{ + /* Make sure that invariant conversion doesn't happen on the _u formats. */ + UChar myUString[256]; + UFILE *myFile; + static const UChar TEST_STR[] = { 0x03BC, 0x0025, 0x0024, 0}; + static const UChar EXPECTED_STR[] = { 0x03BC, 0x03BC, 0x0025, 0x0024, 0}; + static const UChar PERCENT_S[] = { 0x03BC, 0x0025, 0x0053, 0}; + + u_memset(myUString, 0x2a, sizeof(myUString)/sizeof(*myUString)); + + myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, "UTF-8"); + if (!myFile) { + log_err("Test file can't be opened\n"); + return; + } + u_fprintf_u(myFile, PERCENT_S, TEST_STR); + u_fclose(myFile); + + myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, "UTF-8"); + if (!myFile) { + log_err("Test file can't be opened\n"); + return; + } + u_fscanf_u(myFile, PERCENT_S, myUString); + u_fclose(myFile); + if (u_strcmp(TEST_STR, myUString) != 0) { + log_err("u_fscanf_u doesn't work.\n"); + } +} + + U_CFUNC void addFileTest(TestNode** root) { #if !UCONFIG_NO_FORMATTING @@ -1408,4 +1440,5 @@ addFileTest(TestNode** root) { addTest(root, &TestBadScanfFormat, "file/TestBadScanfFormat"); addTest(root, &TestVargs, "file/TestVargs"); #endif + addTest(root, &TestUnicodeFormat, "file/TestUnicodeFormat"); } diff --git a/icu4c/source/test/testdata/icuio.txt b/icu4c/source/test/testdata/icuio.txt index 3931d768b8..f33ce79e49 100644 --- a/icu4c/source/test/testdata/icuio.txt +++ b/icu4c/source/test/testdata/icuio.txt @@ -48,6 +48,12 @@ icuio { { "%-5.3s", "abc ", "s", "abcdef" } { "%5.3s", " a", "s", "a" } { "%-5.3s", "a ", "s", "a" } + { "%.3P", "120.000%", "d", "1.2" } + { "%.0P", "120%", "d", "1.2" } + { "%.3P", "1.200%", "d", "0.012" } + { "%.0P", "1%", "d", "0.012" } + { "%04.0P", "001%", "d", "0.012" } + { "%+4.0P", " +1%", "d", "0.012" } { "%e", "1.200000e+000", "d", "1.2" } { "%e", "1.234568e+006", "d", "1234567.89" } { "%E", "1.234568E+006", "d", "1234567.89" }