--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icu/internaltests/conversion-test-jp-3.c Tue Nov 02 11:29:20 2010 +0100
@@ -0,0 +1,96 @@
+// Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <unicode/utypes.h>
+#include <unicode/ucnv.h>
+#include <unicode/unistr.h>
+#include <unicode/translit.h>
+
+main()
+{
+ UBool ret = TRUE;
+ UConverter *convfrom = 0;
+ UConverter *convto = 0;
+ UErrorCode err = U_ZERO_ERROR;
+ UBool flush;
+ const char *cbufp;
+ char *bufp;
+ char *buf = 0;
+ int i, not_okay;
+
+ const UChar *unibufbp;
+ UChar *unibufp;
+ UChar *unibuf = 0;
+ UChar *saveunibuf;
+ UChar targetunibuf[18];
+
+ printf("Conversion test for empty single-byte-segment in ISO-2022-JP:\n\n");
+ convto = ucnv_open("iso-2022-jp", &err);
+ if (U_FAILURE(err)) {
+ fprintf(stderr, "ucnv_open error - exiting.\n");
+ exit(-1);
+ }
+ buf = (char *)malloc(1024);
+ memset(buf, 0, 1024);
+
+ /* ISO-2022-JP string with empty single-byte-segment. See 4987315. */
+ strcpy(buf, "$BJ#?t$N<u<h?M$O%3(B$B%s%^$G6h@Z$j$^$9!#(B");
+
+ /* Seventeen Unicode characters if convert from the above. */
+ targetunibuf[0] = 0x8907;
+ targetunibuf[1] = 0x6570;
+ targetunibuf[2] = 0x306e;
+ targetunibuf[3] = 0x53d7;
+ targetunibuf[4] = 0x53d6;
+ targetunibuf[5] = 0x4eba;
+ targetunibuf[6] = 0x306f;
+ targetunibuf[7] = 0x30b3;
+ targetunibuf[8] = 0x30f3;
+ targetunibuf[9] = 0x30de;
+ targetunibuf[10] = 0x3067;
+ targetunibuf[11] = 0x533a;
+ targetunibuf[12] = 0x5207;
+ targetunibuf[13] = 0x308a;
+ targetunibuf[14] = 0x307e;
+ targetunibuf[15] = 0x3059;
+ targetunibuf[16] = 0x3002;
+ targetunibuf[17] = 0;
+
+ saveunibuf = unibuf = (UChar *)malloc(sizeof(UChar) * 100);
+ memset(unibuf, 0, sizeof(UChar) * 100);
+
+ bufp = buf;
+ unibufp = unibuf;
+
+ printf("Converting by using ucnv_toUnicode()...\n");
+ ucnv_toUnicode(convto, &unibufp, (const UChar *)(unibuf + 100),
+ (const char **)&bufp, (const char *)(bufp + strlen(buf)), NULL,
+ TRUE, &err);
+
+ for (i = not_okay = 0; unibuf < unibufp; unibuf++, i++) {
+ if (i < 17 && *unibuf != targetunibuf[i]) {
+ printf("%3d U+%04X INCORRECT - expected U+%04X\n", i,
+ *unibuf, targetunibuf[i]);
+ not_okay = 1;
+ } else
+ printf("%3d U+%04X\n", i, *unibuf);
+ }
+
+ if (U_FAILURE(err)) {
+ fprintf(stderr, "conversion error!\n");
+ exit(-1);
+ }
+
+ if (not_okay || i > 17)
+ printf("Conversion done incorrectly - failed.\n");
+ else
+ printf("Conversion done correctly - success.\n");
+
+ if (convto) ucnv_close(convto);
+
+ if (buf) delete[] buf;
+ if (saveunibuf) delete[] saveunibuf;
+}