--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/icu/internaltests/conversion-test3.c Tue Nov 02 11:29:20 2010 +0100
@@ -0,0 +1,83 @@
+// 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>
+
+int main(int ac, char **av)
+{
+ 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;
+ int32_t len32;
+
+ const UChar *unibufbp;
+ UChar *unibufp;
+ UChar *unibuf = 0;
+
+ if (ac != 2) {
+ fprintf(stderr, "Usage: %s [jis7 | iso-2022-jp | iso-2022-jp-2 ]\n", av[0]);
+ exit(-1);
+ }
+
+ printf("Conversion testing for %s:\n\n", av[1]);
+ convto = ucnv_open(av[1], &err);
+ if (U_FAILURE(err)) {
+ fprintf(stderr, "ucnv_open error - exiting.\n");
+ exit(-1);
+ }
+ buf = (char *)malloc(1024);
+ memset(buf, 0, 1024);
+ unibuf = (UChar *)malloc(sizeof(UChar) * 4);
+ unibuf[0] = 0x3002;
+ unibuf[1] = 0xff71;
+ unibuf[2] = 0x3002;
+ /*
+ unibuf[0] = 0x4e02;
+ unibuf[1] = 0x0041;
+ unibuf[2] = 0xff71;
+ */
+
+ bufp = buf;
+ unibufp = unibuf;
+
+ printf("Checking ucnv_fromUnicode()...\n");
+ err = U_ZERO_ERROR;
+ ucnv_fromUnicode(convto, &bufp, (const char *)bufp + 1024,
+ (const UChar **)&unibufp,
+ (const UChar *)unibuf + 3,
+ NULL, (1 > 0), &err);
+ if (U_FAILURE(err)) {
+ fprintf(stderr, "conversion error!\n");
+ exit(-1);
+ }
+
+ for (i = 0; buf[i]; i++)
+ if (buf[i] == 0x1b)
+ printf("%3d %02x ESC\n", i, (unsigned char)buf[i]);
+ else
+ printf("%3d %02x %c\n", i, (unsigned char)buf[i], (unsigned char)buf[i]);
+
+ if (i > 2 && buf[i - 3] == '\x1b' && buf[i - 2] == '(' &&
+ (buf[i - 1] == 'J' || buf[i - 1] == 'B'))
+ printf("Conversion ended with ESC ( J or ESC ( B - success.\n");
+ else
+ printf("Conversion didn't end with ESC ( J or ESC ( B - failed.\n");
+
+
+ if (convto) ucnv_close(convto);
+
+ if (buf) delete[] buf;
+ if (unibuf) delete[] unibuf;
+}