summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu-xetex/test/iotest
diff options
context:
space:
mode:
authorJonathan Kew <jfkthame@googlemail.com>2008-03-04 13:21:23 +0000
committerJonathan Kew <jfkthame@googlemail.com>2008-03-04 13:21:23 +0000
commitf483a5de9331a257f597282e611ecfb63f5ab118 (patch)
tree756baa5a727dd0438448eb380bb6ca81fb41d534 /Build/source/libs/icu-xetex/test/iotest
parente2603863b071e717675b6a69e97c45a42e55bf2c (diff)
remove old icu version
git-svn-id: svn://tug.org/texlive/trunk@6841 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/icu-xetex/test/iotest')
-rw-r--r--Build/source/libs/icu-xetex/test/iotest/.cvsignore7
-rw-r--r--Build/source/libs/icu-xetex/test/iotest/Makefile.in95
-rw-r--r--Build/source/libs/icu-xetex/test/iotest/filetst.c1454
-rw-r--r--Build/source/libs/icu-xetex/test/iotest/iotest.cpp836
-rw-r--r--Build/source/libs/icu-xetex/test/iotest/iotest.h42
-rw-r--r--Build/source/libs/icu-xetex/test/iotest/iotest.vcproj181
-rw-r--r--Build/source/libs/icu-xetex/test/iotest/stream.cpp135
-rw-r--r--Build/source/libs/icu-xetex/test/iotest/strtst.c790
-rw-r--r--Build/source/libs/icu-xetex/test/iotest/trnstst.c316
9 files changed, 0 insertions, 3856 deletions
diff --git a/Build/source/libs/icu-xetex/test/iotest/.cvsignore b/Build/source/libs/icu-xetex/test/iotest/.cvsignore
deleted file mode 100644
index 5e93198f84e..00000000000
--- a/Build/source/libs/icu-xetex/test/iotest/.cvsignore
+++ /dev/null
@@ -1,7 +0,0 @@
-*.d
-*.o
-Debug
-Release
-Makefile
-iotest
-iotest.exe
diff --git a/Build/source/libs/icu-xetex/test/iotest/Makefile.in b/Build/source/libs/icu-xetex/test/iotest/Makefile.in
deleted file mode 100644
index bfdbcf4c39f..00000000000
--- a/Build/source/libs/icu-xetex/test/iotest/Makefile.in
+++ /dev/null
@@ -1,95 +0,0 @@
-#******************************************************************************
-#
-# Copyright (C) 1999-2005, International Business Machines
-# Corporation and others. All Rights Reserved.
-#
-#******************************************************************************
-## Makefile.in for ICU - test/iotest
-
-## Source directory information
-srcdir = @srcdir@
-top_srcdir = @top_srcdir@
-
-top_builddir = ../..
-
-## All the flags and other definitions are included here.
-include $(top_builddir)/icudefs.mk
-
-## Build directory information
-subdir = test/iotest
-
-## Extra files to remove for 'make clean'
-CLEANFILES = *~ $(DEPS)
-
-## Target information
-TARGET = iotest$(EXEEXT)
-
-BUILDDIR := $(CURR_SRCCODE_FULL_DIR)/../../
-# Simplify the path for Unix
-BUILDDIR := $(BUILDDIR:test/iotest/../../=)
-# Simplify the path for Windows
-BUILDDIR := $(BUILDDIR:test\\iotest/../../=)
-# Simplify the path for Windows 98
-BUILDDIR := $(BUILDDIR:TEST\\IOTEST/../../=)
-
-ifneq ($(top_builddir),$(top_srcdir))
-CPPFLAGS += -I$(top_builddir)/common
-endif
-CPPFLAGS += -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(top_srcdir)/tools/ctestfw -I$(top_srcdir)/io
-DEFS += -D'U_TOPSRCDIR="$(top_srcdir)/"' -D'U_TOPBUILDDIR="$(BUILDDIR)"'
-LIBS = $(LIBCTESTFW) $(LIBICUTOOLUTIL) $(LIBICUIO) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M)
-
-OBJECTS = iotest.o stream.o strtst.o filetst.o trnstst.o
-
-DEPS = $(OBJECTS:.o=.d)
-
--include Makefile.local
-
-## List of phony targets
-.PHONY : all all-local install install-local clean clean-local \
-distclean distclean-local dist dist-local check check-local
-
-## Clear suffix list
-.SUFFIXES :
-
-## List of standard targets
-all: all-local
-install: install-local
-clean: clean-local
-distclean : distclean-local
-dist: dist-local
-check: all check-local
-
-all-local: $(TARGET)
-
-install-local:
-
-dist-local:
-
-clean-local:
- test -z "$(CLEANFILES)" || $(RMV) $(CLEANFILES)
- $(RMV) $(OBJECTS) $(TARGET)
-
-distclean-local: clean-local
- $(RMV) Makefile
-
-check-local: all-local
- $(INVOKE) ./$(TARGET) $(IOTEST_OPTS) || true
-
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
- cd $(top_builddir) \
- && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
-
-$(TARGET) : $(OBJECTS)
- $(LINK.cc) $(OUTOPT)$@ $^ $(LIBS)
-
-ifeq (,$(MAKECMDGOALS))
--include $(DEPS)
-else
-ifneq ($(patsubst %clean,,$(MAKECMDGOALS)),)
-ifneq ($(patsubst %install,,$(MAKECMDGOALS)),)
--include $(DEPS)
-endif
-endif
-endif
-
diff --git a/Build/source/libs/icu-xetex/test/iotest/filetst.c b/Build/source/libs/icu-xetex/test/iotest/filetst.c
deleted file mode 100644
index 1e908e42a1b..00000000000
--- a/Build/source/libs/icu-xetex/test/iotest/filetst.c
+++ /dev/null
@@ -1,1454 +0,0 @@
-/*
-**********************************************************************
-* Copyright (C) 2004-2006, International Business Machines
-* Corporation and others. All Rights Reserved.
-**********************************************************************
-* file name: filetst.c
-* encoding: US-ASCII
-* tab size: 8 (not used)
-* indentation:4
-*
-* created on: 2004apr06
-* created by: George Rhoten
-*/
-
-#include "iotest.h"
-#include "unicode/ustdio.h"
-#include "unicode/ustring.h"
-#include "unicode/uloc.h"
-
-#include <string.h>
-
-const char STANDARD_TEST_FILE[] = "iotest-c.txt";
-
-
-#if !UCONFIG_NO_FORMATTING
-static void TestFileFromICU(UFILE *myFile) {
- int32_t n[1];
- float myFloat = -1234.0;
- int32_t newValuePtr[1];
- double newDoubleValuePtr[1];
- UChar myUString[256];
- UChar uStringBuf[256];
- char myString[256] = "";
- char testBuf[256] = "";
- void *origPtr, *ptr;
- U_STRING_DECL(myStringOrig, "My-String", 9);
-
- U_STRING_INIT(myStringOrig, "My-String", 9);
- u_memset(myUString, 0x2a, sizeof(myUString)/sizeof(*myUString));
- u_memset(uStringBuf, 0x2a, sizeof(uStringBuf)/sizeof(*uStringBuf));
- memset(myString, '*', sizeof(myString)/sizeof(*myString));
- memset(testBuf, '*', sizeof(testBuf)/sizeof(*testBuf));
-
- if (myFile == NULL) {
- log_err("Can't write test file.\n");
- return;
- }
-
- *n = -1234;
- if (sizeof(void *) == 4) {
- origPtr = (void *)0xdeadbeef;
- } else if (sizeof(void *) == 8) {
- origPtr = (void *) INT64_C(0x1000200030004000);
- } else if (sizeof(void *) == 16) {
- /* iSeries */
- union {
- int32_t arr[4];
- void *ptr;
- } massiveBigEndianPtr = {{ 0x10002000, 0x30004000, 0x50006000, 0x70008000 }};
- origPtr = massiveBigEndianPtr.ptr;
- } else {
- log_err("sizeof(void*)=%d hasn't been tested before", (int)sizeof(void*));
- }
-
- /* Test fprintf */
- u_fprintf(myFile, "Signed decimal integer %%d: %d\n", *n);
- u_fprintf(myFile, "Signed decimal integer %%i: %i\n", *n);
- u_fprintf(myFile, "Unsigned octal integer %%o: %o\n", *n);
- u_fprintf(myFile, "Unsigned decimal integer %%u: %u\n", *n);
- u_fprintf(myFile, "Lowercase unsigned hexadecimal integer %%x: %x\n", *n);
- u_fprintf(myFile, "Uppercase unsigned hexadecimal integer %%X: %X\n", *n);
- u_fprintf(myFile, "Float %%f: %f\n", myFloat);
- u_fprintf(myFile, "Lowercase float %%e: %e\n", myFloat);
- u_fprintf(myFile, "Uppercase float %%E: %E\n", myFloat);
- u_fprintf(myFile, "Lowercase float %%g: %g\n", myFloat);
- u_fprintf(myFile, "Uppercase float %%G: %G\n", myFloat);
- u_fprintf(myFile, "Pointer %%p: %p\n", origPtr);
- u_fprintf(myFile, "Char %%c: %c\n", 'A');
- u_fprintf(myFile, "UChar %%C: %C\n", (UChar)0x0041); /*'A'*/
- u_fprintf(myFile, "String %%s: %s\n", "My-String");
- u_fprintf(myFile, "NULL String %%s: %s\n", NULL);
- u_fprintf(myFile, "Unicode String %%S: %S\n", myStringOrig);
- u_fprintf(myFile, "NULL Unicode String %%S: %S\n", NULL);
- u_fprintf(myFile, "Percent %%P (non-ANSI): %P\n", myFloat);
- u_fprintf(myFile, "Spell Out %%V (non-ANSI): %V\n", myFloat);
-
- if (u_feof(myFile)) {
- log_err("Got feof while writing the file.\n");
- }
-
- *n = 1;
- u_fprintf(myFile, "\t\nPointer to integer (Count) %%n: n=%d %n n=%d\n", *n, n, *n);
- u_fprintf(myFile, "Pointer to integer Value: %d\n", *n);
- u_fprintf(myFile, "This is a long test123456789012345678901234567890123456789012345678901234567890\n");
- *n = 1;
- u_fprintf(myFile, "\tNormal fprintf count: n=%d %n n=%d\n", (int)*n, (int*)n, (int)*n);
- fprintf(u_fgetfile(myFile), "\tNormal fprintf count value: n=%d\n", (int)*n); /* Should be 27 as stated later on. */
-
- u_fclose(myFile);
- myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, NULL);
-
- if (myFile == NULL) {
- log_err("Can't read test file.");
- return;
- }
-
- if (u_feof(myFile)) {
- log_err("Got feof while reading the file and not at the end of the file.\n");
- }
-
- myUString[0] = u_fgetc(myFile);
- if (myUString[0] != 0x53 /* S */) {
- log_err("u_fgetc 1 returned %X. Expected 'S'.", myString[0]);
- }
- u_fungetc(myUString[0], myFile);
- myUString[0] = u_fgetc(myFile);
- if (myUString[0] != 0x53 /* S */) {
- log_err("u_fgetc 2 returned %X. Expected 'S'.", myString[0]);
- }
- u_fungetc(myUString[0], myFile);
- myUString[0] = u_fgetc(myFile);
- if (myUString[0] != 0x53 /* S */) {
- log_err("u_fgetc 3 returned %X. Expected 'S'.", myString[0]);
- }
- u_fungetc(myUString[0], myFile);
- myUString[0] = u_fgetc(myFile);
- myUString[1] = (UChar)u_fgetcx(myFile); /* Mix getc and getcx and see what happens. */
- myUString[2] = u_fgetc(myFile);
- if (myUString[0] != 0x53 /* S */ && myUString[1] != 0x69 /* i */ && myUString[2] != 0x6E /* n */) {
- log_err("u_fgetcx returned \\u%04X\\u%04X\\u%04X. Expected 'Sin'.", myString[0], myString[1], myString[2]);
- }
- u_fungetc(myUString[2], myFile);
- u_fungetc(myUString[1], myFile);
- u_fungetc(myUString[0], myFile);
-
- *n = -1234;
-
- *newValuePtr = 1;
- u_fscanf(myFile, "Signed decimal integer %%d: %d\n", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%d Got: %d, Expected: %d\n", *newValuePtr, *n);
- }
- *newValuePtr = 1;
- u_fscanf(myFile, "Signed decimal integer %%i: %i\n", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%i Got: %i, Expected: %i\n", *newValuePtr, *n);
- }
- *newValuePtr = 1;
- u_fscanf(myFile, "Unsigned octal integer %%o: %o\n", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%o Got: %o, Expected: %o\n", *newValuePtr, *n);
- }
- *newValuePtr = 1;
- u_fscanf(myFile, "Unsigned decimal integer %%u: %u\n", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%u Got: %u, Expected: %u\n", *newValuePtr, *n);
- }
- *newValuePtr = 1;
- u_fscanf(myFile, "Lowercase unsigned hexadecimal integer %%x: %x\n", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%x Got: %x, Expected: %x\n", *newValuePtr, *n);
- }
- *newValuePtr = 1;
- u_fscanf(myFile, "Uppercase unsigned hexadecimal integer %%X: %X\n", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%X Got: %X, Expected: %X\n", *newValuePtr, *n);
- }
- *newDoubleValuePtr = -1.0;
- u_fscanf(myFile, "Float %%f: %lf\n", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%f Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
- }
- *newDoubleValuePtr = -1.0;
- u_fscanf(myFile, "Lowercase float %%e: %le\n", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%e Got: %e, Expected: %e\n", *newDoubleValuePtr, myFloat);
- }
- *newDoubleValuePtr = -1.0;
- u_fscanf(myFile, "Uppercase float %%E: %lE\n", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%E Got: %E, Expected: %E\n", *newDoubleValuePtr, myFloat);
- }
- *newDoubleValuePtr = -1.0;
- u_fscanf(myFile, "Lowercase float %%g: %lg\n", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%g Got: %g, Expected: %g\n", *newDoubleValuePtr, myFloat);
- }
- *newDoubleValuePtr = -1.0;
- u_fscanf(myFile, "Uppercase float %%G: %lG\n", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%G Got: %G, Expected: %G\n", *newDoubleValuePtr, myFloat);
- }
- ptr = NULL;
- u_fscanf(myFile, "Pointer %%p: %p\n", &ptr);
- if (ptr != origPtr) {
- log_err("%%p Got: %p, Expected: %p\n", ptr, origPtr);
- }
- u_fscanf(myFile, "Char %%c: %c\n", myString);
- if (*myString != 'A') {
- log_err("%%c Got: %c, Expected: A\n", *myString);
- }
- u_fscanf(myFile, "UChar %%C: %C\n", myUString);
- if (*myUString != (UChar)0x0041) { /*'A'*/
- log_err("%%C Got: %C, Expected: A\n", *myUString);
- }
- u_fscanf(myFile, "String %%s: %s\n", myString);
- if (strcmp(myString, "My-String")) {
- log_err("%%s Got: %s, Expected: My String\n", myString);
- }
- u_fscanf(myFile, "NULL String %%s: %s\n", myString);
- if (strcmp(myString, "(null)")) {
- log_err("%%s Got: %s, Expected: My String\n", myString);
- }
- u_fscanf(myFile, "Unicode String %%S: %S\n", myUString);
- u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
- if (strcmp(myString, "My-String")) {
- log_err("%%S Got: %S, Expected: My String\n", myUString);
- }
- u_fscanf(myFile, "NULL Unicode String %%S: %S\n", myUString);
- u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
- if (strcmp(myString, "(null)")) {
- log_err("%%S Got: %S, Expected: My String\n", myUString);
- }
- *newDoubleValuePtr = -1.0;
- u_fscanf(myFile, "Percent %%P (non-ANSI): %P\n", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%P Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
- }
- *newDoubleValuePtr = -1.0;
- u_fscanf(myFile, "Spell Out %%V (non-ANSI): %V\n", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%V Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
- }
-
- u_fgets(myUString, 4, myFile);
- u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
- if (myString == NULL || strcmp(myString, "\t\n") != 0) {
- log_err("u_fgets got \"%s\"\n", myString);
- }
-
- if (u_fgets(myUString, sizeof(myUString)/sizeof(*myUString), myFile) != myUString) {
- log_err("u_fgets did not return myUString\n");
- }
- u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
- if (myString == NULL || strcmp(myString, "Pointer to integer (Count) %n: n=1 n=1\n") != 0) {
- log_err("u_fgets got \"%s\"\n", myString);
- }
-
- if (u_fgets(myUString, sizeof(myUString)/sizeof(*myUString), myFile) != myUString) {
- log_err("u_fgets did not return myUString\n");
- }
- u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
- if (myString == NULL || strcmp(myString, "Pointer to integer Value: 37\n") != 0) {
- log_err("u_fgets got \"%s\"\n", myString);
- }
-
- if (u_fgets(myUString, sizeof(myUString)/sizeof(*myUString), myFile) != myUString) {
- log_err("u_fgets did not return myUString\n");
- }
- u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
- if (myString == NULL || strcmp(myString, "This is a long test123456789012345678901234567890123456789012345678901234567890\n") != 0) {
- log_err("u_fgets got \"%s\"\n", myString);
- }
-
- if (u_fgets(myUString, 0, myFile) != NULL) {
- log_err("u_fgets got \"%s\" and it should have returned NULL\n", myString);
- }
-
- if (u_fgets(myUString, 1, myFile) != myUString) {
- log_err("u_fgets did not return myUString\n");
- }
- u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
- if (myString == NULL || strcmp(myString, "") != 0) {
- log_err("u_fgets got \"%s\"\n", myString);
- }
-
- if (u_fgets(myUString, 2, myFile) != myUString) {
- log_err("u_fgets did not return myUString\n");
- }
- u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
- if (myString == NULL || strcmp(myString, "\t") != 0) {
- log_err("u_fgets got \"%s\"\n", myString);
- }
-
- u_austrncpy(myString, u_fgets(myUString, sizeof(myUString)/sizeof(*myUString), myFile),
- sizeof(myUString)/sizeof(*myUString));
- if (strcmp(myString, "Normal fprintf count: n=1 n=1\n") != 0) {
- log_err("u_fgets got \"%s\"\n", myString);
- }
-
- if (u_feof(myFile)) {
- log_err("Got feof while reading the file and not at the end of the file.\n");
- }
- u_austrncpy(myString, u_fgets(myUString, sizeof(myUString)/sizeof(*myUString), myFile),
- sizeof(myUString)/sizeof(*myUString));
- if (strcmp(myString, "\tNormal fprintf count value: n=27\n") != 0) {
- log_err("u_fgets got \"%s\"\n", myString);
- }
- if (!u_feof(myFile)) {
- log_err("Did not get feof while reading the end of the file.\n");
- }
- if (u_fscanf(myFile, "%S\n", myUString) != 0) {
- log_err("u_fscanf read data while reading the end of the file.\n");
- }
-
- u_fclose(myFile);
-}
-
-static void TestFile(void) {
-/* FILE *standardFile;*/
-
- log_verbose("Testing u_fopen\n");
- TestFileFromICU(u_fopen(STANDARD_TEST_FILE, "w", NULL, NULL));
-
-/* Don't know how to make this work without stdout or stderr */
-/*
- log_verbose("Testing u_finit\n");
- standardFile = fopen(STANDARD_TEST_FILE, "wb");
- TestFileFromICU(u_finit(standardFile, NULL, NULL));
- fclose(standardFile);
-*/
-}
-#endif
-
-static void StdinBuffering(void) {
-#if 0
- UChar buff[255];
- int32_t num = 0;
- UFILE *uStdIn = NULL;
- UFILE *uStdOut = NULL;
- uStdIn = u_finit(stdin, NULL, NULL);
- uStdOut = u_finit(stdout, NULL, NULL);
- if (uStdIn == NULL)
- return;
-
- buff[0] = 0x40;
- buff[1] = 0;
- u_fgets(buff, sizeof(buff)/sizeof(buff[0]), uStdIn);
- u_fprintf(uStdOut, "%S\n", buff);
- u_fscanf(uStdIn, "%d", &num);
- u_fprintf(uStdOut, "%d\n", num);
- u_fscanf(uStdIn, "%d", &num);
- u_fprintf(uStdOut, "%d\n", num);
-#else
- log_verbose("Test disabled because it requires user interaction");
-#endif
-}
-
-static void TestCodepageAndLocale(void) {
- UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, NULL);
- if (myFile == NULL) {
- log_err("Can't write test file.\n");
- return;
- }
- if (u_fgetcodepage(myFile) == NULL
- || strcmp(u_fgetcodepage(myFile), ucnv_getDefaultName()) != 0)
- {
- log_err("Didn't get the proper default codepage. Got %s expected: %s\n",
- u_fgetcodepage(myFile), ucnv_getDefaultName());
- }
-#if !UCONFIG_NO_FORMATTING
- if (u_fgetlocale(myFile) == NULL
- || strcmp(u_fgetlocale(myFile), uloc_getDefault()) != 0)
- {
- log_err("Didn't get the proper default locale. Got %s expected: %s\n",
- u_fgetlocale(myFile), uloc_getDefault());
- }
-#endif
- u_fclose(myFile);
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", "es", NULL);
- if (u_fgetcodepage(myFile) == NULL
- || strcmp(u_fgetcodepage(myFile), ucnv_getDefaultName()) != 0)
- {
- log_err("Didn't get the proper default codepage for \"es\". Got %s expected: iso-8859-1\n",
- u_fgetcodepage(myFile));
- }
-#if !UCONFIG_NO_FORMATTING
- if (u_fgetlocale(myFile) == NULL
- || strcmp(u_fgetlocale(myFile), "es") != 0)
- {
- log_err("Didn't get the proper default locale. Got %s expected: %s\n",
- u_fgetlocale(myFile), "es");
- }
-#endif
- u_fclose(myFile);
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, "UTF-16");
- if (u_fgetcodepage(myFile) == NULL
- || strcmp(u_fgetcodepage(myFile), "UTF-16") != 0)
- {
- log_err("Didn't get the proper default codepage for \"en\". Got %s expected: iso-8859-1\n",
- u_fgetcodepage(myFile));
- }
-#if !UCONFIG_NO_FORMATTING
- if (u_fgetlocale(myFile) == NULL
- || strcmp(u_fgetlocale(myFile), uloc_getDefault()) != 0)
- {
- log_err("Didn't get the proper default locale. Got %s expected: %s\n",
- u_fgetlocale(myFile), uloc_getDefault());
- }
-#endif
- u_fclose(myFile);
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", "zh", "UTF-16");
- if (u_fgetcodepage(myFile) == NULL
- || strcmp(u_fgetcodepage(myFile), "UTF-16") != 0)
- {
- log_err("Didn't get the proper default codepage for \"en\". Got %s expected: iso-8859-1\n",
- u_fgetcodepage(myFile));
- }
-#if !UCONFIG_NO_FORMATTING
- if (u_fgetlocale(myFile) == NULL
- || strcmp(u_fgetlocale(myFile), "zh") != 0)
- {
- log_err("Didn't get the proper default locale. Got %s expected: %s\n",
- u_fgetlocale(myFile), "zh");
- }
-#endif
- u_fclose(myFile);
-}
-
-
-static void TestfgetsBuffers(void) {
- UChar buffer[2048];
- UChar expectedBuffer[2048];
- static const char testStr[] = "This is a test string that tests u_fgets. It makes sure that we don't try to read too much!";
- UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, "UTF-16");
- int32_t expectedSize = (int32_t)strlen(testStr);
- int32_t readSize;
- int32_t repetitions;
-
- if (myFile == NULL) {
- log_err("Can't write test file.\n");
- return;
- }
-
- u_fputc(0x3BC, myFile);
- if (u_fputc(0x110000, myFile) != U_EOF) {
- log_err("u_fputc should return U_EOF for 0x110000.\n");
- }
- if (u_fputc((UChar32)0xFFFFFFFFu, myFile) != U_EOF) {
- log_err("u_fputc should return U_EOF for 0xFFFFFFFF.\n");
- }
- u_fputc(0xFF41, myFile);
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- u_memset(expectedBuffer, 0, sizeof(expectedBuffer)/sizeof(expectedBuffer[0]));
- u_uastrncpy(buffer, testStr, expectedSize+1);
- for (repetitions = 0; repetitions < 16; repetitions++) {
- u_file_write(buffer, expectedSize, myFile);
- u_strcat(expectedBuffer, buffer);
- }
- u_fclose(myFile);
-
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, "UTF-16");
- if (u_fgetc(myFile) != 0x3BC) {
- log_err("The first character is wrong\n");
- }
- if (u_fgetc(myFile) != 0xFF41) {
- log_err("The second character is wrong\n");
- }
- if (u_fgets(buffer, sizeof(buffer)/sizeof(buffer[0]), myFile) != buffer) {
- log_err("Didn't get the buffer back\n");
- return;
- }
- readSize = u_strlen(buffer);
- if (readSize != expectedSize*repetitions) {
- log_err("Buffer is the wrong size. Got %d Expected %d\n", u_strlen(buffer), expectedSize*repetitions);
- }
- if (buffer[(expectedSize*repetitions) + 1] != 0xBEEF) {
- log_err("u_fgets wrote too much data\n");
- }
- if (u_strcmp(buffer, expectedBuffer) != 0) {
- log_err("Did get expected string back\n");
- }
- if (strcmp(u_fgetcodepage(myFile), "UTF-16") != 0) {
- log_err("Got %s instead of UTF-16\n", u_fgetcodepage(myFile));
- }
- u_fclose(myFile);
-
- log_verbose("Now trying a multi-byte encoding (UTF-8).\n");
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, "UTF-8");
-
- u_fputc(0x3BC, myFile);
- u_fputc(0xFF41, myFile);
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- u_memset(expectedBuffer, 0, sizeof(expectedBuffer)/sizeof(expectedBuffer[0]));
- u_uastrncpy(buffer, testStr, expectedSize+1);
- for (repetitions = 0; repetitions < 16; repetitions++) {
- u_file_write(buffer, expectedSize, myFile);
- u_strcat(expectedBuffer, buffer);
- }
- u_fclose(myFile);
-
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, "UTF-8");
- if (strcmp(u_fgetcodepage(myFile), "UTF-8") != 0) {
- log_err("Got %s instead of UTF-8\n", u_fgetcodepage(myFile));
- }
- if (u_fgetc(myFile) != 0x3BC) {
- log_err("The first character is wrong\n");
- }
- if (u_fgetc(myFile) != 0xFF41) {
- log_err("The second character is wrong\n");
- }
- if (u_fgets(buffer, sizeof(buffer)/sizeof(buffer[0]), myFile) != buffer) {
- log_err("Didn't get the buffer back\n");
- return;
- }
- readSize = u_strlen(buffer);
- if (readSize != expectedSize*repetitions) {
- log_err("Buffer is the wrong size. Got %d Expected %d\n", u_strlen(buffer), expectedSize*repetitions);
- }
- if (buffer[(expectedSize*repetitions) + 1] != 0xBEEF) {
- log_err("u_fgets wrote too much data\n");
- }
- if (u_strcmp(buffer, expectedBuffer) != 0) {
- log_err("Did get expected string back\n");
- }
- u_fclose(myFile);
-
-
- log_verbose("Now trying a multi-byte encoding (UTF-8) with a really small buffer.\n");
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, "UTF-8");
-
- u_fputc(0xFF41, myFile);
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- u_memset(expectedBuffer, 0, sizeof(expectedBuffer)/sizeof(expectedBuffer[0]));
- u_uastrncpy(buffer, testStr, expectedSize+1);
- for (repetitions = 0; repetitions < 1; repetitions++) {
- u_file_write(buffer, expectedSize, myFile);
- u_strcat(expectedBuffer, buffer);
- }
- u_fclose(myFile);
-
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, "UTF-8");
- if (u_fgets(buffer, 2, myFile) != buffer) {
- log_err("Didn't get the buffer back\n");
- return;
- }
- readSize = u_strlen(buffer);
- if (readSize != 1) {
- log_err("Buffer is the wrong size. Got %d Expected %d\n", u_strlen(buffer), 1);
- }
- if (buffer[0] != 0xFF41 || buffer[1] != 0) {
- log_err("Did get expected string back\n");
- }
- if (buffer[2] != 0xBEEF) {
- log_err("u_fgets wrote too much data\n");
- }
- u_fclose(myFile);
-
-}
-
-static void TestFileReadBuffering(void) {
- UChar buffer[1024];
- UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, "UTF-16");
- int32_t how_many;
- int32_t repetitions;
-
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- for (repetitions = 0; repetitions < 2; repetitions++) {
- u_file_write(buffer, sizeof(buffer)/sizeof(buffer[0]), myFile);
- }
-
- u_fclose(myFile);
- u_memset(buffer, 0xDEAD, sizeof(buffer)/sizeof(buffer[0]));
- myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, "UTF-16");
- how_many = u_file_read(buffer, 1024, myFile);
- if (how_many != 1024 || buffer[1023] != 0xBEEF) {
- log_err("u_file_read read too much or not enough data\n");
- }
- u_fclose(myFile);
-}
-
-static void TestfgetsLineCount(void) {
- UChar buffer[2048];
- UChar expectedBuffer[2048];
- char charBuffer[2048];
- static const char testStr[] = "This is a test string that tests u_fgets. It makes sure that we don't try to read too much!";
- UFILE *myFile = NULL;
- FILE *stdFile = fopen(STANDARD_TEST_FILE, "w");
- int32_t expectedSize = (int32_t)strlen(testStr);
- int32_t repetitions;
- int32_t nlRepetitions;
-
- if (stdFile == NULL) {
- log_err("Can't write test file.\n");
- return;
- }
- u_memset(expectedBuffer, 0, sizeof(expectedBuffer)/sizeof(expectedBuffer[0]));
-
- for (repetitions = 0; repetitions < 16; repetitions++) {
- fwrite(testStr, sizeof(testStr[0]), expectedSize, stdFile);
- for (nlRepetitions = 0; nlRepetitions < repetitions; nlRepetitions++) {
- fwrite("\n", sizeof(testStr[0]), 1, stdFile);
- }
- }
- fclose(stdFile);
-
- myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, NULL);
- stdFile = fopen(STANDARD_TEST_FILE, "r");
-
- for (;;) {
- char *returnedCharBuffer;
- UChar *returnedUCharBuffer;
-
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- returnedCharBuffer = fgets(charBuffer, sizeof(charBuffer)/sizeof(charBuffer[0]), stdFile);
- returnedUCharBuffer = u_fgets(buffer, sizeof(buffer)/sizeof(buffer[0]), myFile);
-
- if (!returnedCharBuffer && !returnedUCharBuffer) {
- /* Both returned NULL. stop. */
- break;
- }
- if (returnedCharBuffer != charBuffer) {
- log_err("Didn't get the charBuffer back\n");
- continue;
- }
- u_uastrncpy(expectedBuffer, charBuffer, (int32_t)strlen(charBuffer)+1);
- if (returnedUCharBuffer != buffer) {
- log_err("Didn't get the buffer back\n");
- continue;
- }
- if (u_strcmp(buffer, expectedBuffer) != 0) {
- log_err("buffers are different\n");
- }
- if (buffer[u_strlen(buffer)+1] != 0xBEEF) {
- log_err("u_fgets wrote too much\n");
- }
- }
- fclose(stdFile);
- u_fclose(myFile);
-}
-
-static void TestfgetsNewLineHandling(void) {
- UChar buffer[256];
- static const UChar testUStr[][16] = {
- {0x000D, 0},
- {0x000D, 0x000A, 0},
- {0x000D, 0},
- {0x000D, 0},
- {0x0085, 0},
- {0x000A, 0},
- {0x000D, 0},
- {0x000B, 0},
- {0x000C, 0},
- {0x000C, 0},
- {0x2028, 0},
- {0x0085, 0},
- {0x2029, 0},
- {0x0085, 0},
-
- {0x008B, 0x000D, 0},
- {0x00A0, 0x000D, 0x000A, 0},
- {0x3000, 0x000D, 0},
- {0xd800, 0xdfff, 0x000D, 0},
- {0x00AB, 0x0085, 0},
- {0x00AC, 0x000A, 0},
- {0x00AD, 0x000D, 0},
- {0x00BA, 0x000B, 0},
- {0x00AB, 0x000C, 0},
- {0x00B1, 0x000C, 0},
- {0x30BB, 0x2028, 0},
- {0x00A5, 0x0085, 0},
- {0x0080, 0x2029, 0},
- {0x00AF, 0x0085, 0}
-
- };
- UFILE *myFile = NULL;
- int32_t lineIdx;
-
- myFile = u_fopen(STANDARD_TEST_FILE, "wb", NULL, "UTF-8");
- if (myFile == NULL) {
- log_err("Can't write test file.\n");
- return;
- }
- for (lineIdx = 0; lineIdx < (int32_t)(sizeof(testUStr)/sizeof(testUStr[0])); lineIdx++) {
- u_file_write(testUStr[lineIdx], u_strlen(testUStr[lineIdx]), myFile);
- }
- u_fclose(myFile);
-
- myFile = u_fopen(STANDARD_TEST_FILE, "rb", NULL, "UTF-8");
-
- for (lineIdx = 0; lineIdx < (int32_t)(sizeof(testUStr)/sizeof(testUStr[0])); lineIdx++) {
- UChar *returnedUCharBuffer;
-
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- returnedUCharBuffer = u_fgets(buffer, sizeof(buffer)/sizeof(buffer[0]), myFile);
-
- if (!returnedUCharBuffer) {
- /* Returned NULL. stop. */
- break;
- }
- if (u_strcmp(buffer, testUStr[lineIdx]) != 0) {
- log_err("buffers are different at index = %d\n", lineIdx);
- }
- if (buffer[u_strlen(buffer)+1] != 0xBEEF) {
- log_err("u_fgets wrote too much\n");
- }
- }
- if (lineIdx != (int32_t)(sizeof(testUStr)/sizeof(testUStr[0]))) {
- log_err("u_fgets read too much\n");
- }
- if (u_fgets(buffer, sizeof(buffer)/sizeof(buffer[0]), myFile) != NULL) {
- log_err("u_file_write wrote too much\n");
- }
- u_fclose(myFile);
-}
-
-static void TestLineCount(const char *prefixLine, const char *line, int32_t numRepititions) {
- UChar buffer[64];
- UChar expectedBuffer[64];
- int32_t lineLen = strlen(line);
- UChar *returnedUCharBuffer;
- int32_t repetitions;
- UFILE *myFile = NULL;
- FILE *stdFile = fopen(STANDARD_TEST_FILE, "wb");
-
- if (stdFile == NULL) {
- log_err("Can't write test file.\n");
- return;
- }
- /* Write a prefix line and then write a bunch of lines */
- fwrite(prefixLine, strlen(prefixLine), 1, stdFile);
- for (repetitions = 0; repetitions < numRepititions; repetitions++) {
- fwrite(line, lineLen, 1, stdFile);
- }
- fclose(stdFile);
-
- myFile = u_fopen(STANDARD_TEST_FILE, "rb", NULL, NULL);
- if (myFile == NULL) {
- log_err("Can't read test file.\n");
- return;
- }
-
- /* Read the prefix line. This can make sure that a Windows newline is either on a boundary or before it. */
- u_uastrncpy(expectedBuffer, prefixLine, (int32_t)strlen(prefixLine)+1);
- returnedUCharBuffer = u_fgets(buffer, sizeof(buffer)/sizeof(buffer[0]), myFile);
- if (u_strcmp(returnedUCharBuffer, expectedBuffer) != 0) {
- log_err("prefix buffer is different. prefix=\"%s\"\n", prefixLine);
- return;
- }
-
- u_uastrncpy(expectedBuffer, line, (int32_t)strlen(line)+1);
- for (repetitions = 0; ; repetitions++) {
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
- returnedUCharBuffer = u_fgets(buffer, sizeof(buffer)/sizeof(buffer[0]), myFile);
-
- if (!returnedUCharBuffer) {
- /* returned NULL. stop. */
- break;
- }
- if (u_strcmp(buffer, expectedBuffer) != 0) {
- log_err("buffers are different at count %d\n", repetitions);
- }
- if (buffer[u_strlen(buffer)+1] != 0xBEEF) {
- log_err("u_fgets wrote too much\n");
- }
- }
- if (repetitions != numRepititions) {
- log_err("got wrong number of lines. got=%d expected=%d\n", repetitions, numRepititions);
- }
- u_fclose(myFile);
-}
-
-static void TestfgetsNewLineCount(void) {
- /* This makes sure that lines are correctly handled between buffer boundaries. */
- TestLineCount("\n", "\n", 1024); /* Unix newlines */
- TestLineCount("\r\n", "\r\n", 1024);/* Windows newlines */
- TestLineCount("a\r\n", "\r\n", 1024);/* Windows newlines offset by 1 byte */
- TestLineCount("\r\n", "a\r\n", 1024);/* Windows newlines offset with data */
- TestLineCount("\n", "a\n", 1024); /* Unix newlines offset with data */
- TestLineCount("\n", "\r\n", 1024); /* a mixed number of lines. */
-}
-
-static void TestFgetsLineBuffering(void) {
- UChar buffer[2003]; /* Use a non-power of 2 or 10 */
- UChar *returnedUCharBuffer;
- int32_t repetitions;
- UFILE *myFile = NULL;
- FILE *stdFile = fopen(STANDARD_TEST_FILE, "wb");
-
- if (stdFile == NULL) {
- log_err("Can't write test file.\n");
- return;
- }
- u_memset(buffer, 0xBEEF, sizeof(buffer)/sizeof(buffer[0]));
-
- /* Write one very long line */
- for (repetitions = 0; repetitions < ((sizeof(buffer)/sizeof(buffer[0]))*2); repetitions++) {
- fwrite(repetitions ? "1" : "2", 1, 1, stdFile);
- }
- fclose(stdFile);
-
- myFile = u_fopen(STANDARD_TEST_FILE, "rb", NULL, NULL);
- if (myFile == NULL) {
- log_err("Can't read test file.\n");
- return;
- }
-
- /* Read part of one very long line */
- returnedUCharBuffer = u_fgets(buffer, (sizeof(buffer)/sizeof(buffer[0]))-1, myFile);
- if (u_strlen(returnedUCharBuffer) != ((sizeof(buffer)/sizeof(buffer[0]))-2)) {
- log_err("Line is wrong length. Got %d. Expected %d.\n",
- u_strlen(returnedUCharBuffer), ((sizeof(buffer)/sizeof(buffer[0]))-2));
- }
- /* We better not read too much */
- if (buffer[(sizeof(buffer)/sizeof(buffer[0]))-1] != 0xBEEF) {
- log_err("Too much data was written\n");
- }
-
- u_fclose(myFile);
-}
-
-
-static void TestCodepage(void) {
- UFILE *myFile = NULL;
- static const UChar strABAccentA[] = { 0x0041, 0x0042, 0x00C1, 0x0043, 0};
- static const UChar strBadConversion[] = { 0x0041, 0x0042, 0xfffd, 0x0043, 0};
- UChar testBuf[sizeof(strABAccentA)/sizeof(strABAccentA[0])*2]; /* *2 to see if too much was */
- char convName[UCNV_MAX_CONVERTER_NAME_LENGTH];
- int32_t retVal;
- UErrorCode status = U_ZERO_ERROR;
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, "absurd converter that can't be opened");
-
- if (myFile) {
- log_err("Recieved a UFILE * with an invalid codepage parameter\n");
- u_fclose(myFile);
- }
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, "ISO-8859-1");
- if (myFile == NULL) {
- log_err("Can't write test file for iso-8859-1.\n");
- return;
- }
- if (strcmp("ISO-8859-1", u_fgetcodepage(myFile)) != 0) {
- log_err("Couldn't get ISO-8859-1 back as opened codepage\n");
- }
- u_file_write(strABAccentA, u_strlen(strABAccentA), myFile);
- u_fclose(myFile);
-
- /* Now see what we got wrote */
- myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, NULL);
- if (u_fsetcodepage("ISO-8859-1", myFile) != 0) {
- log_err("u_fsetcodepage didn't set the codepage\n");
- }
- retVal = u_file_read(testBuf, u_strlen(strABAccentA), myFile);
- if (u_strncmp(strABAccentA, testBuf, u_strlen(strABAccentA)) != 0) {
- log_err("The test data was read and written differently!\n");
- }
- if (retVal != u_strlen(strABAccentA)) {
- log_err("The test data returned different lengths. Got: %d, Expected %d\n", retVal, u_strlen(strABAccentA));
- }
- u_fclose(myFile);
-
- /* What happens on invalid input? */
- myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, "ISO-8859-1");
- if (strcmp(ucnv_getName(u_fgetConverter(myFile), &status), "ISO-8859-1") != 0) {
- log_err("u_fgetConverter returned %s\n", ucnv_getName(u_fgetConverter(myFile), &status));
- }
- if (u_fsetcodepage("UTF-8", myFile) != 0) {
- log_err("u_fsetcodepage didn't set the codepage to UTF-8\n");
- }
- if (strcmp(ucnv_getName(u_fgetConverter(myFile), &status), "UTF-8") != 0) {
- log_err("u_fgetConverter returned %s\n", ucnv_getName(u_fgetConverter(myFile), &status));
- }
- retVal = u_file_read(testBuf, u_strlen(strBadConversion), myFile);
- if (u_strncmp(strBadConversion, testBuf, u_strlen(strBadConversion)) != 0) {
- log_err("The test data wasn't subsituted as expected\n");
- }
- u_fclose(myFile);
-
- /* Can't currently swap codepages midstream */
- myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, "ISO-8859-1");
- strcpy(convName, u_fgetcodepage(myFile));
- u_file_read(testBuf, 1, myFile);
- if (u_fsetcodepage("UTF-8", myFile) == 0) {
- log_err("u_fsetcodepage set the codepage after reading a byte\n");
- }
- retVal = u_file_read(testBuf + 1, u_strlen(strABAccentA) - 1, myFile);
- if (u_strncmp(strABAccentA, testBuf, u_strlen(strABAccentA)) != 0) {
- log_err("u_fsetcodepage changed the codepages after writing data\n");
- }
- if ((retVal + 1) != u_strlen(strABAccentA)) {
- log_err("The test data returned different lengths. Got: %d, Expected %d\n", retVal, u_strlen(strABAccentA));
- }
- u_frewind(myFile);
- retVal = u_file_read(testBuf, u_strlen(strABAccentA), myFile);
- if (u_strncmp(strABAccentA, testBuf, u_strlen(strABAccentA)) != 0) {
- log_err("The test data was read and written differently!\n");
- }
- if (retVal != u_strlen(strABAccentA)) {
- log_err("The test data returned different lengths. Got: %d, Expected %d\n", retVal, u_strlen(strABAccentA));
- }
- u_fclose(myFile);
-
-}
-
-#if !UCONFIG_NO_FORMATTING
-static void TestFilePrintCompatibility(void) {
- UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "wb", "en_US_POSIX", NULL);
- FILE *myCFile;
- int32_t num;
- char cVal;
- static const UChar emptyStr[] = {0};
- char readBuf[512] = "";
- char testBuf[512] = "";
-
- if (myFile == NULL) {
- log_err("Can't write test file.\n");
- return;
- }
-#if !UCONFIG_NO_FORMATTING
- if (strcmp(u_fgetlocale(myFile), "en_US_POSIX") != 0) {
- log_err("Got %s instead of en_US_POSIX for locale\n", u_fgetlocale(myFile));
- }
-#endif
-
- /* Compare against C API compatibility */
- for (num = -STANDARD_TEST_NUM_RANGE; num < STANDARD_TEST_NUM_RANGE; num++) {
- u_fprintf(myFile, "%x ", num);
- u_fprintf(myFile, "%X ", num);
- u_fprintf(myFile, "%o ", num);
- u_fprintf(myFile, "%d ", num);
- u_fprintf(myFile, "%i ", num);
- u_fprintf(myFile, "%f ", (double)num);
-/* u_fprintf(myFile, "%e ", (double)num);
- u_fprintf(myFile, "%E ", (double)num);*/
- u_fprintf(myFile, "%g ", (double)num);
- u_fprintf(myFile, "%G", (double)num);
- u_fputs(emptyStr, myFile);
- }
-
- u_fprintf_u(myFile, NEW_LINE);
-
- for (num = 0; num < 0x80; num++) {
- u_fprintf(myFile, "%c", num);
- }
-
- u_fclose(myFile);
- myCFile = fopen(STANDARD_TEST_FILE, "rb");
- if (myCFile == NULL) {
- log_err("Can't read test file.");
- return;
- }
-
- for (num = -STANDARD_TEST_NUM_RANGE; num < STANDARD_TEST_NUM_RANGE; num++) {
- fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%x", (int)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%x Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }
-
- fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%X", (int)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%X Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }
-
- fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%o", (int)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%o Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }
-
- /* fprintf is not compatible on all platforms e.g. the iSeries */
- fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%d", (int)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%d Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }
-
- fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%i", (int)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%i Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }
-
- fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%f", (double)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%f Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }
-
-/* fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%e", (double)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%e Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }
-
- fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%E", (double)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%E Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }*/
-
- fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%g", (double)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%g Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }
-
- fscanf(myCFile, "%s", readBuf);
- sprintf(testBuf, "%G", (double)num);
- if (strcmp(readBuf, testBuf) != 0) {
- log_err("%%G Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
- }
- }
-
- /* Properly eat the newlines */
- for (num = 0; num < (int32_t)strlen(C_NEW_LINE); num++) {
- fscanf(myCFile, "%c", &cVal);
- if (cVal != C_NEW_LINE[num]) {
- log_err("OS newline error\n");
- }
- }
- for (num = 0; num < (int32_t)strlen(C_NEW_LINE); num++) {
- fscanf(myCFile, "%c", &cVal);
- if (cVal != C_NEW_LINE[num]) {
- log_err("ustdio newline error\n");
- }
- }
-
- for (num = 0; num < 0x80; num++) {
- cVal = -1;
- fscanf(myCFile, "%c", &cVal);
- if (num != cVal) {
- log_err("%%c Got: 0x%x, Expected: 0x%x\n", cVal, num);
- }
- }
- fclose(myCFile);
-}
-#endif
-
-#define TestFPrintFormat(uFormat, uValue, cFormat, cValue) \
- myFile = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL);\
- if (myFile == NULL) {\
- log_err("Can't write test file for %s.\n", uFormat);\
- return;\
- }\
- /* Reinitialize the buffer to verify null termination works. */\
- u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));\
- memset(buffer, '*', sizeof(buffer)/sizeof(*buffer));\
- \
- uNumPrinted = u_fprintf(myFile, uFormat, uValue);\
- u_fclose(myFile);\
- myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);\
- u_fgets(uBuffer, sizeof(uBuffer)/sizeof(*uBuffer), myFile);\
- u_fclose(myFile);\
- u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(*uBuffer));\
- cNumPrinted = sprintf(buffer, cFormat, cValue);\
- if (strcmp(buffer, compBuffer) != 0) {\
- log_err("%" uFormat " Got: \"%s\", Expected: \"%s\"\n", compBuffer, buffer);\
- }\
- if (cNumPrinted != uNumPrinted) {\
- log_err("%" uFormat " number printed Got: %d, Expected: %d\n", uNumPrinted, cNumPrinted);\
- }\
- if (buffer[uNumPrinted+1] != '*') {\
- log_err("%" uFormat " too much stored\n");\
- }\
-
-#if !UCONFIG_NO_FORMATTING
-static void TestFprintfFormat(void) {
- static const UChar abcUChars[] = {0x61,0x62,0x63,0};
- static const char abcChars[] = "abc";
- UChar uBuffer[256];
- char buffer[256];
- char compBuffer[256];
- int32_t uNumPrinted;
- int32_t cNumPrinted;
- UFILE *myFile;
-
- TestFPrintFormat("%8S", abcUChars, "%8s", abcChars);
- TestFPrintFormat("%-8S", abcUChars, "%-8s", abcChars);
- TestFPrintFormat("%.2S", abcUChars, "%.2s", abcChars); /* strlen is 3 */
-
- TestFPrintFormat("%8s", abcChars, "%8s", abcChars);
- TestFPrintFormat("%-8s", abcChars, "%-8s", abcChars);
- TestFPrintFormat("%.2s", abcChars, "%.2s", abcChars); /* strlen is 3 */
-
- TestFPrintFormat("%8c", (char)'e', "%8c", (char)'e');
- TestFPrintFormat("%-8c", (char)'e', "%-8c", (char)'e');
-
- TestFPrintFormat("%8C", (UChar)0x65, "%8c", (char)'e');
- TestFPrintFormat("%-8C", (UChar)0x65, "%-8c", (char)'e');
-
- TestFPrintFormat("%f", 1.23456789, "%f", 1.23456789);
- TestFPrintFormat("%f", 12345.6789, "%f", 12345.6789);
- TestFPrintFormat("%f", 123456.789, "%f", 123456.789);
- TestFPrintFormat("%f", 1234567.89, "%f", 1234567.89);
- TestFPrintFormat("%10f", 1.23456789, "%10f", 1.23456789);
- TestFPrintFormat("%-10f", 1.23456789, "%-10f", 1.23456789);
- TestFPrintFormat("%10f", 123.456789, "%10f", 123.456789);
- TestFPrintFormat("%10.4f", 123.456789, "%10.4f", 123.456789);
- TestFPrintFormat("%-10f", 123.456789, "%-10f", 123.456789);
-
-/* TestFPrintFormat("%g", 12345.6789, "%g", 12345.6789);
- TestFPrintFormat("%g", 123456.789, "%g", 123456.789);
- TestFPrintFormat("%g", 1234567.89, "%g", 1234567.89);
- TestFPrintFormat("%G", 123456.789, "%G", 123456.789);
- TestFPrintFormat("%G", 1234567.89, "%G", 1234567.89);*/
- TestFPrintFormat("%10g", 1.23456789, "%10g", 1.23456789);
- TestFPrintFormat("%10.4g", 1.23456789, "%10.4g", 1.23456789);
- TestFPrintFormat("%-10g", 1.23456789, "%-10g", 1.23456789);
- TestFPrintFormat("%10g", 123.456789, "%10g", 123.456789);
- TestFPrintFormat("%-10g", 123.456789, "%-10g", 123.456789);
-
- TestFPrintFormat("%8x", 123456, "%8x", 123456);
- TestFPrintFormat("%-8x", 123456, "%-8x", 123456);
- TestFPrintFormat("%08x", 123456, "%08x", 123456);
-
- TestFPrintFormat("%8X", 123456, "%8X", 123456);
- TestFPrintFormat("%-8X", 123456, "%-8X", 123456);
- TestFPrintFormat("%08X", 123456, "%08X", 123456);
- TestFPrintFormat("%#x", 123456, "%#x", 123456);
- TestFPrintFormat("%#x", -123456, "%#x", -123456);
-
- TestFPrintFormat("%8o", 123456, "%8o", 123456);
- TestFPrintFormat("%-8o", 123456, "%-8o", 123456);
- TestFPrintFormat("%08o", 123456, "%08o", 123456);
- TestFPrintFormat("%#o", 123, "%#o", 123);
- TestFPrintFormat("%#o", -123, "%#o", -123);
-
- TestFPrintFormat("%8u", 123456, "%8u", 123456);
- TestFPrintFormat("%-8u", 123456, "%-8u", 123456);
- TestFPrintFormat("%08u", 123456, "%08u", 123456);
- TestFPrintFormat("%8u", -123456, "%8u", -123456);
- TestFPrintFormat("%-8u", -123456, "%-8u", -123456);
- TestFPrintFormat("%.5u", 123456, "%.5u", 123456);
- TestFPrintFormat("%.6u", 123456, "%.6u", 123456);
- TestFPrintFormat("%.7u", 123456, "%.7u", 123456);
-
- TestFPrintFormat("%8d", 123456, "%8d", 123456);
- TestFPrintFormat("%-8d", 123456, "%-8d", 123456);
- TestFPrintFormat("%08d", 123456, "%08d", 123456);
- TestFPrintFormat("% d", 123456, "% d", 123456);
- TestFPrintFormat("% d", -123456, "% d", -123456);
-
- TestFPrintFormat("%8i", 123456, "%8i", 123456);
- TestFPrintFormat("%-8i", 123456, "%-8i", 123456);
- TestFPrintFormat("%08i", 123456, "%08i", 123456);
-
- log_verbose("Get really crazy with the formatting.\n");
-
- TestFPrintFormat("%-#12x", 123, "%-#12x", 123);
- TestFPrintFormat("%-#12x", -123, "%-#12x", -123);
- TestFPrintFormat("%#12x", 123, "%#12x", 123);
- TestFPrintFormat("%#12x", -123, "%#12x", -123);
-
- TestFPrintFormat("%-+12d", 123, "%-+12d", 123);
- TestFPrintFormat("%-+12d", -123, "%-+12d", -123);
- TestFPrintFormat("%- 12d", 123, "%- 12d", 123);
- TestFPrintFormat("%- 12d", -123, "%- 12d", -123);
- TestFPrintFormat("%+12d", 123, "%+12d", 123);
- TestFPrintFormat("%+12d", -123, "%+12d", -123);
- TestFPrintFormat("% 12d", 123, "% 12d", 123);
- TestFPrintFormat("% 12d", -123, "% 12d", -123);
- TestFPrintFormat("%12d", 123, "%12d", 123);
- TestFPrintFormat("%12d", -123, "%12d", -123);
- TestFPrintFormat("%.12d", 123, "%.12d", 123);
- TestFPrintFormat("%.12d", -123, "%.12d", -123);
-
- TestFPrintFormat("%-+12.1f", 1.234, "%-+12.1f", 1.234);
- TestFPrintFormat("%-+12.1f", -1.234, "%-+12.1f", -1.234);
- TestFPrintFormat("%- 12.10f", 1.234, "%- 12.10f", 1.234);
- TestFPrintFormat("%- 12.1f", -1.234, "%- 12.1f", -1.234);
- TestFPrintFormat("%+12.1f", 1.234, "%+12.1f", 1.234);
- TestFPrintFormat("%+12.1f", -1.234, "%+12.1f", -1.234);
- TestFPrintFormat("% 12.1f", 1.234, "% 12.1f", 1.234);
- TestFPrintFormat("% 12.1f", -1.234, "% 12.1f", -1.234);
- TestFPrintFormat("%12.1f", 1.234, "%12.1f", 1.234);
- TestFPrintFormat("%12.1f", -1.234, "%12.1f", -1.234);
- TestFPrintFormat("%.2f", 1.234, "%.2f", 1.234);
- TestFPrintFormat("%.2f", -1.234, "%.2f", -1.234);
- TestFPrintFormat("%3f", 1.234, "%3f", 1.234);
- TestFPrintFormat("%3f", -1.234, "%3f", -1.234);
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL);
- /* Reinitialize the buffer to verify null termination works. */
- u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
- memset(buffer, '*', sizeof(buffer)/sizeof(*buffer));
-
- uNumPrinted = u_fprintf(myFile, "%d % d %d", -1234, 1234, 1234);
- u_fclose(myFile);
- myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
- u_fgets(uBuffer, sizeof(uBuffer)/sizeof(*uBuffer), myFile);
- u_fclose(myFile);
- u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(*uBuffer));
- cNumPrinted = sprintf(buffer, "%d % d %d", -1234, 1234, 1234);
- if (strcmp(buffer, compBuffer) != 0) {
- log_err("%%d %% d %%d Got: \"%s\", Expected: \"%s\"\n", compBuffer, buffer);
- }
- if (cNumPrinted != uNumPrinted) {
- log_err("%%d %% d %%d number printed Got: %d, Expected: %d\n", uNumPrinted, cNumPrinted);
- }
- if (buffer[uNumPrinted+1] != '*') {
- log_err("%%d %% d %%d too much stored\n");
- }
-}
-#endif
-
-#undef TestFPrintFormat
-
-#if !UCONFIG_NO_FORMATTING
-static void TestFScanSetFormat(const char *format, const UChar *uValue, const char *cValue, UBool expectedToPass) {
- UFILE *myFile;
- UChar uBuffer[256];
- char buffer[256];
- char compBuffer[256];
- int32_t uNumScanned;
- int32_t cNumScanned;
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, NULL);
- if (myFile == NULL) {
- log_err("Can't write test file for %s.\n", format);
- return;
- }
- /* Reinitialize the buffer to verify null termination works. */
- u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
- uBuffer[sizeof(uBuffer)/sizeof(*uBuffer)-1] = 0;
- memset(buffer, '*', sizeof(buffer)/sizeof(*buffer));
- buffer[sizeof(buffer)/sizeof(*buffer)-1] = 0;
-
- u_fprintf(myFile, "%S", uValue);
- u_fclose(myFile);
- myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
- uNumScanned = u_fscanf(myFile, format, uBuffer);
- u_fclose(myFile);
- if (expectedToPass) {
- u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(*uBuffer));
- cNumScanned = sscanf(cValue, format, buffer);
- if (strncmp(buffer, compBuffer, sizeof(buffer)/sizeof(*buffer)) != 0) {
- log_err("%s Got: \"%s\", Expected: \"%s\"\n", format, compBuffer, buffer);
- }
- if (cNumScanned != uNumScanned) {
- log_err("%s number printed Got: %d, Expected: %d\n", format, uNumScanned, cNumScanned);
- }
- if (uNumScanned > 0 && uBuffer[u_strlen(uBuffer)+1] != 0x2a) {
- log_err("%s too much stored\n", format);
- }
- }
- else {
- if (uNumScanned != 0 || uBuffer[0] != 0x2a || uBuffer[1] != 0x2a) {
- log_err("%s too much stored on a failure\n", format);
- }
- }
-}
-#endif
-
-#if !UCONFIG_NO_FORMATTING
-static void TestFScanset(void) {
- static const UChar abcUChars[] = {0x61,0x62,0x63,0x63,0x64,0x65,0x66,0x67,0};
- static const char abcChars[] = "abccdefg";
-
- TestFScanSetFormat("%[bc]S", abcUChars, abcChars, TRUE);
- TestFScanSetFormat("%[cb]S", abcUChars, abcChars, TRUE);
-
- TestFScanSetFormat("%[ab]S", abcUChars, abcChars, TRUE);
- TestFScanSetFormat("%[ba]S", abcUChars, abcChars, TRUE);
-
- TestFScanSetFormat("%[ab]", abcUChars, abcChars, TRUE);
- TestFScanSetFormat("%[ba]", abcUChars, abcChars, TRUE);
-
- TestFScanSetFormat("%[abcdefgh]", abcUChars, abcChars, TRUE);
- TestFScanSetFormat("%[;hgfedcba]", abcUChars, abcChars, TRUE);
-
- TestFScanSetFormat("%[^a]", abcUChars, abcChars, TRUE);
- TestFScanSetFormat("%[^e]", abcUChars, abcChars, TRUE);
- TestFScanSetFormat("%[^ed]", abcUChars, abcChars, TRUE);
- TestFScanSetFormat("%[^dc]", abcUChars, abcChars, TRUE);
- TestFScanSetFormat("%[^e] ", abcUChars, abcChars, TRUE);
-
- TestFScanSetFormat("%1[ab] ", abcUChars, abcChars, TRUE);
- TestFScanSetFormat("%2[^f]", abcUChars, abcChars, TRUE);
-
- TestFScanSetFormat("%[qrst]", abcUChars, abcChars, TRUE);
-
- /* Extra long string for testing */
- TestFScanSetFormat(" %[qrst]",
- abcUChars, abcChars, TRUE);
-
- TestFScanSetFormat("%[a-]", abcUChars, abcChars, TRUE);
-
- /* Bad format */
- TestFScanSetFormat("%[f-a]", abcUChars, abcChars, FALSE);
- TestFScanSetFormat("%[c-a]", abcUChars, abcChars, FALSE);
- TestFScanSetFormat("%[a", abcUChars, abcChars, FALSE);
- /* The following is not deterministic on Windows */
-/* TestFScanSetFormat("%[a-", abcUChars, abcChars);*/
-
- /* TODO: Need to specify precision with a "*" */
-}
-#endif
-#if !UCONFIG_NO_FORMATTING
-static void TestBadFScanfFormat(const char *format, const UChar *uValue, const char *cValue) {
- UFILE *myFile;
- UChar uBuffer[256];
- int32_t uNumScanned;
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, NULL);
- if (myFile == NULL) {
- log_err("Can't write test file for %s.\n", format);
- return;
- }
- /* Reinitialize the buffer to verify null termination works. */
- u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
- uBuffer[sizeof(uBuffer)/sizeof(*uBuffer)-1] = 0;
-
- u_fprintf(myFile, "%S", uValue);
- u_fclose(myFile);
- myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
- uNumScanned = u_fscanf(myFile, format, uBuffer);
- u_fclose(myFile);
- if (uNumScanned != 0 || uBuffer[0] != 0x2a || uBuffer[1] != 0x2a) {
- log_err("%s too much stored on a failure\n", format);
- }
-}
-#endif
-#if !UCONFIG_NO_FORMATTING
-static void TestBadScanfFormat(void) {
- static const UChar abcUChars[] = {0x61,0x62,0x63,0x63,0x64,0x65,0x66,0x67,0};
- static const char abcChars[] = "abccdefg";
-
- TestBadFScanfFormat("%[] ", abcUChars, abcChars);
-}
-#endif
-#if !UCONFIG_NO_FORMATTING
-static void Test_u_vfprintf(const char *expectedResult, const char *format, ...) {
- UChar uBuffer[256];
- UChar uBuffer2[256];
- va_list ap;
- int32_t count;
- UFILE *myFile;
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", "UTF-8");
- if (!myFile) {
- log_err("Test file can't be opened\n");
- return;
- }
-
- va_start(ap, format);
- count = u_vfprintf(myFile, format, ap);
- va_end(ap);
-
- u_fclose(myFile);
-
-
- myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", "UTF-8");
- if (!myFile) {
- log_err("Test file can't be opened\n");
- return;
- }
- u_fgets(uBuffer, sizeof(uBuffer)/sizeof(*uBuffer), myFile);
- u_uastrcpy(uBuffer2, expectedResult);
- if (u_strcmp(uBuffer, uBuffer2) != 0) {
- log_err("Got two different results for \"%s\" expected \"%s\"\n", format, expectedResult);
- }
- u_fclose(myFile);
-
-
- myFile = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL);
- if (!myFile) {
- log_err("Test file can't be opened\n");
- return;
- }
- u_uastrcpy(uBuffer, format);
-
- va_start(ap, format);
- count = u_vfprintf_u(myFile, uBuffer, ap);
- va_end(ap);
-
- u_fclose(myFile);
-
-
- myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);
- if (!myFile) {
- log_err("Test file can't be opened\n");
- return;
- }
- u_fgets(uBuffer, sizeof(uBuffer)/sizeof(*uBuffer), myFile);
- u_uastrcpy(uBuffer2, expectedResult);
- if (u_strcmp(uBuffer, uBuffer2) != 0) {
- log_err("Got two different results for \"%s\" expected \"%s\"\n", format, expectedResult);
- }
- u_fclose(myFile);
-}
-
-static void TestVargs(void) {
- Test_u_vfprintf("8 9 a B 8.9", "%d %u %x %X %.1f", 8, 9, 10, 11, 8.9);
-}
-#endif
-
-static void TestUnicodeFormat(void)
-{
-#if !UCONFIG_NO_FORMATTING
- /* 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 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");
- }
-#endif
-}
-
-
-U_CFUNC void
-addFileTest(TestNode** root) {
-#if !UCONFIG_NO_FORMATTING
- addTest(root, &TestFile, "file/TestFile");
-#endif
- addTest(root, &StdinBuffering, "file/StdinBuffering");
- addTest(root, &TestfgetsBuffers, "file/TestfgetsBuffers");
- addTest(root, &TestFileReadBuffering, "file/TestFileReadBuffering");
- addTest(root, &TestfgetsLineCount, "file/TestfgetsLineCount");
- addTest(root, &TestfgetsNewLineHandling, "file/TestfgetsNewLineHandling");
- addTest(root, &TestfgetsNewLineCount, "file/TestfgetsNewLineCount");
- addTest(root, &TestFgetsLineBuffering, "file/TestFgetsLineBuffering");
- addTest(root, &TestCodepage, "file/TestCodepage");
-#if !UCONFIG_NO_FORMATTING
- addTest(root, &TestCodepageAndLocale, "file/TestCodepageAndLocale");
- addTest(root, &TestFprintfFormat, "file/TestFprintfFormat");
- addTest(root, &TestFScanset, "file/TestFScanset");
- addTest(root, &TestFilePrintCompatibility, "file/TestFilePrintCompatibility");
- addTest(root, &TestBadScanfFormat, "file/TestBadScanfFormat");
- addTest(root, &TestVargs, "file/TestVargs");
- addTest(root, &TestUnicodeFormat, "file/TestUnicodeFormat");
-#endif
-}
diff --git a/Build/source/libs/icu-xetex/test/iotest/iotest.cpp b/Build/source/libs/icu-xetex/test/iotest/iotest.cpp
deleted file mode 100644
index 748ae3584d8..00000000000
--- a/Build/source/libs/icu-xetex/test/iotest/iotest.cpp
+++ /dev/null
@@ -1,836 +0,0 @@
-/*
-**********************************************************************
-* Copyright (C) 2002-2006, International Business Machines
-* Corporation and others. All Rights Reserved.
-**********************************************************************
-* file name: iotest.cpp
-* encoding: US-ASCII
-* tab size: 8 (not used)
-* indentation:4
-*
-* created on: 2002feb21
-* created by: George Rhoten
-*/
-
-
-#include "unicode/ustdio.h"
-#include "unicode/uclean.h"
-
-#include "unicode/ucnv.h"
-#include "unicode/uchar.h"
-#include "unicode/unistr.h"
-#include "unicode/ustring.h"
-#include "ustr_cnv.h"
-#include "iotest.h"
-#include "unicode/tstdtmod.h"
-#include "putilimp.h"
-
-#include <string.h>
-#include <stdlib.h>
-
-class DataDrivenLogger : public TestLog {
- static const char* fgDataDir;
- static char *fgTestDataPath;
-
-public:
- static void cleanUp() {
- if (fgTestDataPath) {
- free(fgTestDataPath);
- fgTestDataPath = NULL;
- }
- }
- virtual void errln( const UnicodeString &message ) {
- char buffer[4000];
- message.extract(0, message.length(), buffer, sizeof(buffer));
- buffer[3999] = 0; /* NULL terminate */
- log_err(buffer);
- }
-
- static const char * pathToDataDirectory(void)
- {
-
- if(fgDataDir != NULL) {
- return fgDataDir;
- }
-
- /* U_TOPSRCDIR is set by the makefiles on UNIXes when building cintltst and intltst
- // to point to the top of the build hierarchy, which may or
- // may not be the same as the source directory, depending on
- // the configure options used. At any rate,
- // set the data path to the built data from this directory.
- // The value is complete with quotes, so it can be used
- // as-is as a string constant.
- */
- #if defined (U_TOPSRCDIR)
- {
- fgDataDir = U_TOPSRCDIR U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
- }
- #else
-
- /* On Windows, the file name obtained from __FILE__ includes a full path.
- * This file is "wherever\icu\source\test\cintltst\cintltst.c"
- * Change to "wherever\icu\source\data"
- */
- {
- static char p[sizeof(__FILE__) + 10];
- char *pBackSlash;
- int i;
-
- strcpy(p, __FILE__);
- /* We want to back over three '\' chars. */
- /* Only Windows should end up here, so looking for '\' is safe. */
- for (i=1; i<=3; i++) {
- pBackSlash = strrchr(p, U_FILE_SEP_CHAR);
- if (pBackSlash != NULL) {
- *pBackSlash = 0; /* Truncate the string at the '\' */
- }
- }
-
- if (pBackSlash != NULL) {
- /* We found and truncated three names from the path.
- * Now append "source\data" and set the environment
- */
- strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING );
- fgDataDir = p;
- }
- else {
- /* __FILE__ on MSVC7 does not contain the directory */
- FILE *file = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r");
- if (file) {
- fclose(file);
- fgDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
- }
- else {
- fgDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING;
- }
- }
- }
- #endif
-
- return fgDataDir;
-
- }
-
- static const char* loadTestData(UErrorCode& err){
- if( fgTestDataPath == NULL){
- const char* directory=NULL;
- UResourceBundle* test =NULL;
- char* tdpath=NULL;
- const char* tdrelativepath;
-
-#if defined (U_TOPBUILDDIR)
- tdrelativepath = "test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
- directory = U_TOPBUILDDIR;
-#else
- tdrelativepath = ".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
- directory = pathToDataDirectory();
-#endif
-
- tdpath = (char*) malloc(sizeof(char) *(( strlen(directory) * strlen(tdrelativepath)) + 100));
-
-
- /* u_getDataDirectory shoul return \source\data ... set the
- * directory to ..\source\data\..\test\testdata\out\testdata
- */
- strcpy(tdpath, directory);
- strcat(tdpath, tdrelativepath);
- strcat(tdpath,"testdata");
-
- test=ures_open(tdpath, "testtypes", &err);
-
- if(U_FAILURE(err)){
- err = U_FILE_ACCESS_ERROR;
- log_err("Could not load testtypes.res in testdata bundle with path %s - %s\n", tdpath, u_errorName(err));
- return "";
- }
- ures_close(test);
- fgTestDataPath = tdpath;
- }
- return fgTestDataPath;
- }
-
- virtual const char* getTestDataPath(UErrorCode& err) {
- return loadTestData(err);
- }
-};
-
-const char* DataDrivenLogger::fgDataDir = NULL;
-char* DataDrivenLogger::fgTestDataPath = NULL;
-
-static int64_t
-uto64(const UChar *buffer)
-{
- int64_t result = 0;
- /* iterate through buffer */
- while(*buffer) {
- /* read the next digit */
- result *= 16;
- if (!u_isxdigit(*buffer)) {
- log_err("\\u%04X is not a valid hex digit for this test\n", (UChar)*buffer);
- }
- result += *buffer - 0x0030 - (*buffer >= 0x0041 ? (*buffer >= 0x0061 ? 39 : 7) : 0);
- buffer++;
- }
- return result;
-}
-
-
-U_CDECL_BEGIN
-static void U_CALLCONV DataDrivenPrintf(void)
-{
-#if !UCONFIG_NO_FORMATTING
- UErrorCode errorCode;
- TestDataModule *dataModule;
- TestData *testData;
- const DataMap *testCase;
- DataDrivenLogger logger;
- UChar uBuffer[512];
- char cBuffer[512];
- char cFormat[sizeof(cBuffer)];
- char cExpected[sizeof(cBuffer)];
- UnicodeString tempStr;
- UChar format[512];
- UChar expectedResult[512];
- UChar argument[512];
- int32_t i;
- int8_t i8;
- int16_t i16;
- int32_t i32;
- int64_t i64;
- double dbl;
- int32_t uBufferLenReturned;
-
- const char *fileLocale = "en_US_POSIX";
- int32_t uFileBufferLenReturned;
- UFILE *testFile;
-
- errorCode=U_ZERO_ERROR;
- dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode);
- if(U_SUCCESS(errorCode)) {
- testData=dataModule->createTestData("printf", errorCode);
- if(U_SUCCESS(errorCode)) {
- for(i=0; testData->nextCase(testCase, errorCode); ++i) {
- if(U_FAILURE(errorCode)) {
- log_err("error retrieving icuio/printf test case %d - %s\n",
- i, u_errorName(errorCode));
- errorCode=U_ZERO_ERROR;
- continue;
- }
- testFile = u_fopen(STANDARD_TEST_FILE, "w", fileLocale, "UTF-8");
- if (!testFile) {
- log_err("Can't open test file - %s\n",
- STANDARD_TEST_FILE);
- continue;
- }
- u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0]));
- uBuffer[sizeof(uBuffer)/sizeof(uBuffer[0])-1] = 0;
- tempStr=testCase->getString("format", errorCode);
- tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode);
- tempStr=testCase->getString("result", errorCode);
- tempStr.extract(expectedResult, sizeof(expectedResult)/sizeof(expectedResult[0]), errorCode);
- tempStr=testCase->getString("argument", errorCode);
- tempStr.extract(argument, sizeof(argument)/sizeof(argument[0]), errorCode);
- u_austrncpy(cBuffer, format, sizeof(cBuffer));
- if(U_FAILURE(errorCode)) {
- log_err("error retrieving icuio/printf test case %d - %s\n",
- i, u_errorName(errorCode));
- errorCode=U_ZERO_ERROR;
- continue;
- }
- log_verbose("Test %d: format=\"%s\"\n", i, cBuffer);
- switch (testCase->getString("argumentType", errorCode)[0]) {
- case 0x64: // 'd' double
- dbl = atof(u_austrcpy(cBuffer, argument));
- uBufferLenReturned = u_sprintf_u(uBuffer, format, dbl);
- uFileBufferLenReturned = u_fprintf_u(testFile, format, dbl);
- break;
- case 0x31: // '1' int8_t
- i8 = (int8_t)uto64(argument);
- uBufferLenReturned = u_sprintf_u(uBuffer, format, i8);
- uFileBufferLenReturned = u_fprintf_u(testFile, format, i8);
- break;
- case 0x32: // '2' int16_t
- i16 = (int16_t)uto64(argument);
- uBufferLenReturned = u_sprintf_u(uBuffer, format, i16);
- uFileBufferLenReturned = u_fprintf_u(testFile, format, i16);
- break;
- case 0x34: // '4' int32_t
- i32 = (int32_t)uto64(argument);
- uBufferLenReturned = u_sprintf_u(uBuffer, format, i32);
- uFileBufferLenReturned = u_fprintf_u(testFile, format, i32);
- break;
- case 0x38: // '8' int64_t
- i64 = uto64(argument);
- uBufferLenReturned = u_sprintf_u(uBuffer, format, i64);
- uFileBufferLenReturned = u_fprintf_u(testFile, format, i64);
- break;
- case 0x73: // 's' char *
- u_austrncpy(cBuffer, argument, sizeof(cBuffer));
- uBufferLenReturned = u_sprintf_u(uBuffer, format, cBuffer);
- uFileBufferLenReturned = u_fprintf_u(testFile, format, cBuffer);
- break;
- case 0x53: // 'S' UChar *
- uBufferLenReturned = u_sprintf_u(uBuffer, format, argument);
- uFileBufferLenReturned = u_fprintf_u(testFile, format, argument);
- break;
- default:
- uBufferLenReturned = 0;
- uFileBufferLenReturned = 0;
- log_err("Unknown type %c for test %d\n", testCase->getString("argumentType", errorCode)[0], i);
- }
- if (u_strcmp(uBuffer, expectedResult) != 0) {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- u_austrncpy(cFormat, format, sizeof(cFormat));
- u_austrncpy(cExpected, expectedResult, sizeof(cExpected));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE string test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n",
- i, cFormat, cBuffer, cExpected);
- }
- if (uBuffer[uBufferLenReturned-1] == 0
- || uBuffer[uBufferLenReturned] != 0
- || uBuffer[uBufferLenReturned+1] != 0x2A
- || uBuffer[uBufferLenReturned+2] != 0x2A)
- {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE test case %d - \"%s\" wrong amount of characters was written. Got %d.\n",
- i, cBuffer, uBufferLenReturned);
- }
- u_fclose(testFile);
- testFile = u_fopen(STANDARD_TEST_FILE, "r", fileLocale, "UTF-8");
- if (!testFile) {
- log_err("Can't open test file - %s\n",
- STANDARD_TEST_FILE);
- }
- uBuffer[0]=0;
- u_fgets(uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]), testFile);
- if (u_strcmp(uBuffer, expectedResult) != 0) {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- u_austrncpy(cFormat, format, sizeof(cFormat));
- u_austrncpy(cExpected, expectedResult, sizeof(cExpected));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE file test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n",
- i, cFormat, cBuffer, cExpected);
- }
- if (uFileBufferLenReturned != uBufferLenReturned)
- {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE uFileBufferLenReturned(%d) != uBufferLenReturned(%d)\n",
- uFileBufferLenReturned, uBufferLenReturned);
- }
-
- if(U_FAILURE(errorCode)) {
- log_err("error running icuio/printf test case %d - %s\n",
- i, u_errorName(errorCode));
- errorCode=U_ZERO_ERROR;
- continue;
- }
- u_fclose(testFile);
- }
- delete testData;
- }
- delete dataModule;
- }
- else {
- log_err("Failed: could not load test icuio data\n");
- }
-#endif
-}
-U_CDECL_END
-
-U_CDECL_BEGIN
-static void U_CALLCONV DataDrivenScanf(void)
-{
-#if !UCONFIG_NO_FORMATTING
- UErrorCode errorCode;
- TestDataModule *dataModule;
- TestData *testData;
- const DataMap *testCase;
- DataDrivenLogger logger;
- UChar uBuffer[512];
- char cBuffer[512];
- char cExpected[sizeof(cBuffer)];
- UnicodeString tempStr;
- UChar format[512];
- UChar expectedResult[512];
- UChar argument[512];
- int32_t i;
- int8_t i8, expected8;
- int16_t i16, expected16;
- int32_t i32, expected32;
- int64_t i64, expected64;
- double dbl, expectedDbl;
- volatile float flt, expectedFlt; // Use volatile in order to get around an Intel compiler issue.
- int32_t uBufferLenReturned;
-
- //const char *fileLocale = "en_US_POSIX";
- //int32_t uFileBufferLenReturned;
- //UFILE *testFile;
-
- errorCode=U_ZERO_ERROR;
- dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode);
- if(U_SUCCESS(errorCode)) {
- testData=dataModule->createTestData("scanf", errorCode);
- if(U_SUCCESS(errorCode)) {
- for(i=0; testData->nextCase(testCase, errorCode); ++i) {
- if(U_FAILURE(errorCode)) {
- log_err("error retrieving icuio/printf test case %d - %s\n",
- i, u_errorName(errorCode));
- errorCode=U_ZERO_ERROR;
- continue;
- }
-/* testFile = u_fopen(STANDARD_TEST_FILE, "w", fileLocale, "UTF-8");
- if (!testFile) {
- log_err("Can't open test file - %s\n",
- STANDARD_TEST_FILE);
- }*/
- u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0]));
- uBuffer[sizeof(uBuffer)/sizeof(uBuffer[0])-1] = 0;
- tempStr=testCase->getString("format", errorCode);
- tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode);
- tempStr=testCase->getString("result", errorCode);
- tempStr.extract(expectedResult, sizeof(expectedResult)/sizeof(expectedResult[0]), errorCode);
- tempStr=testCase->getString("argument", errorCode);
- tempStr.extract(argument, sizeof(argument)/sizeof(argument[0]), errorCode);
- u_austrncpy(cBuffer, format, sizeof(cBuffer));
- if(U_FAILURE(errorCode)) {
- log_err("error retrieving icuio/printf test case %d - %s\n",
- i, u_errorName(errorCode));
- errorCode=U_ZERO_ERROR;
- continue;
- }
- log_verbose("Test %d: format=\"%s\"\n", i, cBuffer);
- switch (testCase->getString("argumentType", errorCode)[0]) {
- case 0x64: // 'd' double
- expectedDbl = atof(u_austrcpy(cBuffer, expectedResult));
- uBufferLenReturned = u_sscanf_u(argument, format, &dbl);
- //uFileBufferLenReturned = u_fscanf_u(testFile, format, dbl);
- if (dbl != expectedDbl) {
- log_err("error in scanf test case[%d] Got: %f Exp: %f\n",
- i, dbl, expectedDbl);
- }
- break;
- case 0x66: // 'f' float
- expectedFlt = (float)atof(u_austrcpy(cBuffer, expectedResult));
- uBufferLenReturned = u_sscanf_u(argument, format, &flt);
- //uFileBufferLenReturned = u_fscanf_u(testFile, format, flt);
- if (flt != expectedFlt) {
- log_err("error in scanf test case[%d] Got: %f Exp: %f\n",
- i, flt, expectedFlt);
- }
- break;
- case 0x31: // '1' int8_t
- expected8 = (int8_t)uto64(expectedResult);
- uBufferLenReturned = u_sscanf_u(argument, format, &i8);
- //uFileBufferLenReturned = u_fscanf_u(testFile, format, i8);
- if (i8 != expected8) {
- log_err("error in scanf test case[%d] Got: %02X Exp: %02X\n",
- i, i8, expected8);
- }
- break;
- case 0x32: // '2' int16_t
- expected16 = (int16_t)uto64(expectedResult);
- uBufferLenReturned = u_sscanf_u(argument, format, &i16);
- //uFileBufferLenReturned = u_fscanf_u(testFile, format, i16);
- if (i16 != expected16) {
- log_err("error in scanf test case[%d] Got: %04X Exp: %04X\n",
- i, i16, expected16);
- }
- break;
- case 0x34: // '4' int32_t
- expected32 = (int32_t)uto64(expectedResult);
- uBufferLenReturned = u_sscanf_u(argument, format, &i32);
- //uFileBufferLenReturned = u_fscanf_u(testFile, format, i32);
- if (i32 != expected32) {
- log_err("error in scanf test case[%d] Got: %08X Exp: %08X\n",
- i, i32, expected32);
- }
- break;
- case 0x38: // '8' int64_t
- expected64 = uto64(expectedResult);
- uBufferLenReturned = u_sscanf_u(argument, format, &i64);
- //uFileBufferLenReturned = u_fscanf_u(testFile, format, i64);
- if (i64 != expected64) {
- log_err("error in scanf 64-bit. Test case = %d\n", i);
- }
- break;
- case 0x73: // 's' char *
- u_austrcpy(cExpected, expectedResult);
- uBufferLenReturned = u_sscanf_u(argument, format, cBuffer);
- //uFileBufferLenReturned = u_fscanf_u(testFile, format, cBuffer);
- if (strcmp(cBuffer, cExpected) != 0) {
- log_err("error in scanf char * string. Got \"%s\" Expected \"%s\". Test case = %d\n", cBuffer, cExpected, i);
- }
- break;
- case 0x53: // 'S' UChar *
- uBufferLenReturned = u_sscanf_u(argument, format, uBuffer);
- //uFileBufferLenReturned = u_fscanf_u(testFile, format, argument);
- if (u_strcmp(uBuffer, expectedResult) != 0) {
- u_austrcpy(cExpected, format);
- u_austrcpy(cBuffer, uBuffer);
- log_err("error in scanf UChar * string %s Got: \"%s\". Test case = %d\n", cExpected, cBuffer, i);
- }
- break;
- default:
- uBufferLenReturned = 0;
- //uFileBufferLenReturned = 0;
- log_err("Unknown type %c for test %d\n", testCase->getString("argumentType", errorCode)[0], i);
- }
- if (uBufferLenReturned != 1) {
- log_err("error scanf converted %d arguments. Test case = %d\n", uBufferLenReturned, i);
- }
-/* if (u_strcmp(uBuffer, expectedResult) != 0) {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- u_austrncpy(cFormat, format, sizeof(cFormat));
- u_austrncpy(cExpected, expectedResult, sizeof(cExpected));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE string test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n",
- i, cFormat, cBuffer, cExpected);
- }
- if (uBuffer[uBufferLenReturned-1] == 0
- || uBuffer[uBufferLenReturned] != 0
- || uBuffer[uBufferLenReturned+1] != 0x2A
- || uBuffer[uBufferLenReturned+2] != 0x2A)
- {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE test case %d - \"%s\" wrong amount of characters was written. Got %d.\n",
- i, cBuffer, uBufferLenReturned);
- }*/
-/* u_fclose(testFile);
- testFile = u_fopen(STANDARD_TEST_FILE, "r", fileLocale, "UTF-8");
- if (!testFile) {
- log_err("Can't open test file - %s\n",
- STANDARD_TEST_FILE);
- }
- uBuffer[0];
- u_fgets(uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]), testFile);
- if (u_strcmp(uBuffer, expectedResult) != 0) {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- u_austrncpy(cFormat, format, sizeof(cFormat));
- u_austrncpy(cExpected, expectedResult, sizeof(cExpected));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE file test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n",
- i, cFormat, cBuffer, cExpected);
- }
- if (uFileBufferLenReturned != uBufferLenReturned)
- {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE uFileBufferLenReturned(%d) != uBufferLenReturned(%d)\n",
- uFileBufferLenReturned, uBufferLenReturned);
- }
-*/
- if(U_FAILURE(errorCode)) {
- log_err("error running icuio/printf test case %d - %s\n",
- i, u_errorName(errorCode));
- errorCode=U_ZERO_ERROR;
- continue;
- }
-// u_fclose(testFile);
- }
- delete testData;
- }
- delete dataModule;
- }
- else {
- log_err("Failed: could not load test icuio data\n");
- }
-#endif
-}
-U_CDECL_END
-
-U_CDECL_BEGIN
-static void U_CALLCONV DataDrivenPrintfPrecision(void)
-{
-#if !UCONFIG_NO_FORMATTING
- UErrorCode errorCode;
- TestDataModule *dataModule;
- TestData *testData;
- const DataMap *testCase;
- DataDrivenLogger logger;
- UChar uBuffer[512];
- char cBuffer[512];
- char cFormat[sizeof(cBuffer)];
- char cExpected[sizeof(cBuffer)];
- UnicodeString tempStr;
- UChar format[512];
- UChar expectedResult[512];
- UChar argument[512];
- int32_t precision;
- int32_t i;
- int8_t i8;
- int16_t i16;
- int32_t i32;
- int64_t i64;
- double dbl;
- int32_t uBufferLenReturned;
-
- errorCode=U_ZERO_ERROR;
- dataModule=TestDataModule::getTestDataModule("icuio", logger, errorCode);
- if(U_SUCCESS(errorCode)) {
- testData=dataModule->createTestData("printfPrecision", errorCode);
- if(U_SUCCESS(errorCode)) {
- for(i=0; testData->nextCase(testCase, errorCode); ++i) {
- if(U_FAILURE(errorCode)) {
- log_err("error retrieving icuio/printf test case %d - %s\n",
- i, u_errorName(errorCode));
- errorCode=U_ZERO_ERROR;
- continue;
- }
- u_memset(uBuffer, 0x2A, sizeof(uBuffer)/sizeof(uBuffer[0]));
- uBuffer[sizeof(uBuffer)/sizeof(uBuffer[0])-1] = 0;
- tempStr=testCase->getString("format", errorCode);
- tempStr.extract(format, sizeof(format)/sizeof(format[0]), errorCode);
- tempStr=testCase->getString("result", errorCode);
- tempStr.extract(expectedResult, sizeof(expectedResult)/sizeof(expectedResult[0]), errorCode);
- tempStr=testCase->getString("argument", errorCode);
- tempStr.extract(argument, sizeof(argument)/sizeof(argument[0]), errorCode);
- precision=testCase->getInt28("precision", errorCode);
- u_austrncpy(cBuffer, format, sizeof(cBuffer));
- if(U_FAILURE(errorCode)) {
- log_err("error retrieving icuio/printf test case %d - %s\n",
- i, u_errorName(errorCode));
- errorCode=U_ZERO_ERROR;
- continue;
- }
- log_verbose("Test %d: format=\"%s\"\n", i, cBuffer);
- switch (testCase->getString("argumentType", errorCode)[0]) {
- case 0x64: // 'd' double
- dbl = atof(u_austrcpy(cBuffer, argument));
- uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, dbl);
- break;
- case 0x31: // '1' int8_t
- i8 = (int8_t)uto64(argument);
- uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i8);
- break;
- case 0x32: // '2' int16_t
- i16 = (int16_t)uto64(argument);
- uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i16);
- break;
- case 0x34: // '4' int32_t
- i32 = (int32_t)uto64(argument);
- uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i32);
- break;
- case 0x38: // '8' int64_t
- i64 = uto64(argument);
- uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, i64);
- break;
- case 0x73: // 's' char *
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, cBuffer);
- break;
- case 0x53: // 'S' UChar *
- uBufferLenReturned = u_sprintf_u(uBuffer, format, precision, argument);
- break;
- default:
- uBufferLenReturned = 0;
- log_err("Unknown type %c for test %d\n", testCase->getString("argumentType", errorCode)[0], i);
- }
- if (u_strcmp(uBuffer, expectedResult) != 0) {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- u_austrncpy(cFormat, format, sizeof(cFormat));
- u_austrncpy(cExpected, expectedResult, sizeof(cExpected));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE test case %d \"%s\" - Got: \"%s\" Expected: \"%s\"\n",
- i, cFormat, cBuffer, cExpected);
- }
- if (uBuffer[uBufferLenReturned-1] == 0
- || uBuffer[uBufferLenReturned] != 0
- || uBuffer[uBufferLenReturned+1] != 0x2A
- || uBuffer[uBufferLenReturned+2] != 0x2A)
- {
- u_austrncpy(cBuffer, uBuffer, sizeof(cBuffer));
- cBuffer[sizeof(cBuffer)-1] = 0;
- log_err("FAILURE test case %d - \"%s\" wrong amount of characters was written. Got %d.\n",
- i, cBuffer, uBufferLenReturned);
- }
- if(U_FAILURE(errorCode)) {
- log_err("error running icuio/printf test case %d - %s\n",
- i, u_errorName(errorCode));
- errorCode=U_ZERO_ERROR;
- continue;
- }
- }
- delete testData;
- }
- delete dataModule;
- }
- else {
- log_err("Failed: could not load test icuio data\n");
- }
-#endif
-}
-U_CDECL_END
-
-static void addAllTests(TestNode** root) {
- addFileTest(root);
- addStringTest(root);
- addTranslitTest(root);
-
-#if !UCONFIG_NO_FORMATTING
- addTest(root, &DataDrivenPrintf, "datadriv/DataDrivenPrintf");
- addTest(root, &DataDrivenPrintfPrecision, "datadriv/DataDrivenPrintfPrecision");
- addTest(root, &DataDrivenScanf, "datadriv/DataDrivenScanf");
-#endif
- addStreamTests(root);
-}
-
-/* returns the path to icu/source/data/out */
-static const char *ctest_dataOutDir()
-{
- static const char *dataOutDir = NULL;
-
- if(dataOutDir) {
- return dataOutDir;
- }
-
- /* U_TOPBUILDDIR is set by the makefiles on UNIXes when building cintltst and intltst
- // to point to the top of the build hierarchy, which may or
- // may not be the same as the source directory, depending on
- // the configure options used. At any rate,
- // set the data path to the built data from this directory.
- // The value is complete with quotes, so it can be used
- // as-is as a string constant.
- */
-#if defined (U_TOPBUILDDIR)
- {
- dataOutDir = U_TOPBUILDDIR "data"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
- }
-#else
-
- /* On Windows, the file name obtained from __FILE__ includes a full path.
- * This file is "wherever\icu\source\test\cintltst\cintltst.c"
- * Change to "wherever\icu\source\data"
- */
- {
- static char p[sizeof(__FILE__) + 20];
- char *pBackSlash;
- int i;
-
- strcpy(p, __FILE__);
- /* We want to back over three '\' chars. */
- /* Only Windows should end up here, so looking for '\' is safe. */
- for (i=1; i<=3; i++) {
- pBackSlash = strrchr(p, U_FILE_SEP_CHAR);
- if (pBackSlash != NULL) {
- *pBackSlash = 0; /* Truncate the string at the '\' */
- }
- }
-
- if (pBackSlash != NULL) {
- /* We found and truncated three names from the path.
- * Now append "source\data" and set the environment
- */
- strcpy(pBackSlash, U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING);
- dataOutDir = p;
- }
- else {
- /* __FILE__ on MSVC7 does not contain the directory */
- FILE *file = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "Makefile.in", "r");
- if (file) {
- fclose(file);
- dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
- }
- else {
- dataOutDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING "data" U_FILE_SEP_STRING "out" U_FILE_SEP_STRING;
- }
- }
- }
-#endif
-
- return dataOutDir;
-}
-
-/* ctest_setICU_DATA - if the ICU_DATA environment variable is not already
- * set, try to deduce the directory in which ICU was built,
- * and set ICU_DATA to "icu/source/data" in that location.
- * The intent is to allow the tests to have a good chance
- * of running without requiring that the user manually set
- * ICU_DATA. Common data isn't a problem, since it is
- * picked up via a static (build time) reference, but the
- * tests dynamically load some data.
- */
-static void ctest_setICU_DATA() {
-
- /* No location for the data dir was identifiable.
- * Add other fallbacks for the test data location here if the need arises
- */
- if (getenv("ICU_DATA") == NULL) {
- /* If ICU_DATA isn't set, set it to the usual location */
- u_setDataDirectory(ctest_dataOutDir());
- }
-}
-
-int main(int argc, char* argv[])
-{
- int32_t nerrors = 0;
- TestNode *root = NULL;
- UErrorCode errorCode = U_ZERO_ERROR;
- UDate startTime, endTime;
- int32_t diffTime;
-
- startTime = uprv_getUTCtime();
-
- /* Check whether ICU will initialize without forcing the build data directory into
- * the ICU_DATA path. Success here means either the data dll contains data, or that
- * this test program was run with ICU_DATA set externally. Failure of this check
- * is normal when ICU data is not packaged into a shared library.
- *
- * Whether or not this test succeeds, we want to cleanup and reinitialize
- * with a data path so that data loading from individual files can be tested.
- */
- u_init(&errorCode);
- if (U_FAILURE(errorCode)) {
- fprintf(stderr,
- "#### Note: ICU Init without build-specific setDataDirectory() failed.\n");
- }
- u_cleanup();
- errorCode = U_ZERO_ERROR;
-
- /* Initialize ICU */
- ctest_setICU_DATA(); /* u_setDataDirectory() must happen Before u_init() */
- u_init(&errorCode);
- if (U_FAILURE(errorCode)) {
- fprintf(stderr,
- "#### ERROR! %s: u_init() failed with status = \"%s\".\n"
- "*** Check the ICU_DATA environment variable and \n"
- "*** check that the data files are present.\n", argv[0], u_errorName(errorCode));
- return 1;
- }
-
- fprintf(stdout, "Default charset for this run is %s\n", ucnv_getDefaultName());
-
- addAllTests(&root);
- nerrors = processArgs(root, argc, argv);
-
-#if 1
- {
- FILE* fileToRemove = fopen(STANDARD_TEST_FILE, "r");
- /* This should delete any temporary files. */
- if (fileToRemove) {
- fclose(fileToRemove);
- if (remove(STANDARD_TEST_FILE) != 0) {
- /* Maybe someone didn't close the file correctly. */
- fprintf(stderr, "FAIL: Could not delete %s\n", STANDARD_TEST_FILE);
- nerrors += 1;
- }
- }
- }
-#endif
-
- cleanUpTestTree(root);
- DataDrivenLogger::cleanUp();
- u_cleanup();
-
- endTime = uprv_getUTCtime();
- diffTime = (int32_t)(endTime - startTime);
- printf("Elapsed Time: %02d:%02d:%02d.%03d\n",
- (int)((diffTime%U_MILLIS_PER_DAY)/U_MILLIS_PER_HOUR),
- (int)((diffTime%U_MILLIS_PER_HOUR)/U_MILLIS_PER_MINUTE),
- (int)((diffTime%U_MILLIS_PER_MINUTE)/U_MILLIS_PER_SECOND),
- (int)(diffTime%U_MILLIS_PER_SECOND));
-
- return nerrors;
-}
diff --git a/Build/source/libs/icu-xetex/test/iotest/iotest.h b/Build/source/libs/icu-xetex/test/iotest/iotest.h
deleted file mode 100644
index 6d522dc435d..00000000000
--- a/Build/source/libs/icu-xetex/test/iotest/iotest.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
-**********************************************************************
-* Copyright (C) 2004-2005, International Business Machines
-* Corporation and others. All Rights Reserved.
-**********************************************************************
-* file name: iotest.h
-* encoding: US-ASCII
-* tab size: 8 (not used)
-* indentation:4
-*
-* created on: 2004apr06
-* created by: George Rhoten
-*/
-
-#ifndef IOTEST_H
-#define IOTEST_H 1
-
-#include "unicode/utypes.h"
-#include "unicode/ctest.h"
-
-U_CFUNC void
-addStringTest(TestNode** root);
-
-U_CFUNC void
-addFileTest(TestNode** root);
-
-U_CFUNC void
-addTranslitTest(TestNode** root);
-
-U_CFUNC void
-addStreamTests(TestNode** root);
-
-U_CDECL_BEGIN
-extern const UChar NEW_LINE[];
-extern const char C_NEW_LINE[];
-extern const char STANDARD_TEST_FILE[];
-U_CDECL_END
-
-#define STANDARD_TEST_NUM_RANGE 1000
-
-
-#endif
diff --git a/Build/source/libs/icu-xetex/test/iotest/iotest.vcproj b/Build/source/libs/icu-xetex/test/iotest/iotest.vcproj
deleted file mode 100644
index 68ea46e094a..00000000000
--- a/Build/source/libs/icu-xetex/test/iotest/iotest.vcproj
+++ /dev/null
@@ -1,181 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="7.10"
- Name="iotest"
- ProjectGUID="{E4993E82-D68A-46CA-BAE0-9D35E172E46F}"
- SccProjectName=""
- SccLocalPath="">
- <Platforms>
- <Platform
- Name="Win32"/>
- </Platforms>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory=".\Debug"
- IntermediateDirectory=".\Debug"
- ConfigurationType="1"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- ImproveFloatingPointConsistency="TRUE"
- AdditionalIncludeDirectories="..\..\..\include;..\..\tools\ctestfw;..\..\common"
- PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
- BufferSecurityCheck="TRUE"
- DisableLanguageExtensions="TRUE"
- TreatWChar_tAsBuiltInType="TRUE"
- PrecompiledHeaderFile=".\Debug/iotest.pch"
- AssemblerListingLocation=".\Debug/"
- ObjectFile=".\Debug/"
- ProgramDataBaseFileName=".\Debug/"
- BrowseInformation="1"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"
- DebugInformationFormat="4"
- CompileAs="0"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- OutputFile=".\Debug/iotest.exe"
- LinkIncremental="0"
- SuppressStartupBanner="TRUE"
- GenerateDebugInformation="TRUE"
- ProgramDatabaseFile=".\Debug/iotest.pdb"
- SubSystem="1"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"
- TypeLibraryName=".\Debug/iotest.tlb"
- HeaderFileName=""/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1033"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCXMLDataGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- <Tool
- Name="VCManagedWrapperGeneratorTool"/>
- <Tool
- Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory=".\Release"
- IntermediateDirectory=".\Release"
- ConfigurationType="1"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="FALSE"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- ImproveFloatingPointConsistency="TRUE"
- AdditionalIncludeDirectories="..\..\..\include;..\..\tools\ctestfw;..\..\common"
- PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
- StringPooling="TRUE"
- RuntimeLibrary="2"
- DisableLanguageExtensions="TRUE"
- TreatWChar_tAsBuiltInType="TRUE"
- PrecompiledHeaderFile=".\Release/iotest.pch"
- AssemblerListingLocation=".\Release/"
- ObjectFile=".\Release/"
- ProgramDataBaseFileName=".\Release/"
- WarningLevel="3"
- SuppressStartupBanner="TRUE"
- CompileAs="0"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- OutputFile=".\Release/iotest.exe"
- LinkIncremental="1"
- SuppressStartupBanner="TRUE"
- ProgramDatabaseFile=".\Release/iotest.pdb"
- SubSystem="1"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"
- TypeLibraryName=".\Release/iotest.tlb"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1033"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCXMLDataGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- <Tool
- Name="VCManagedWrapperGeneratorTool"/>
- <Tool
- Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx">
- <File
- RelativePath=".\filetst.c">
- </File>
- <File
- RelativePath=".\iotest.cpp">
- </File>
- <File
- RelativePath=".\stream.cpp">
- <FileConfiguration
- Name="Debug|Win32">
- <Tool
- Name="VCCLCompilerTool"
- DisableLanguageExtensions="FALSE"/>
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32">
- <Tool
- Name="VCCLCompilerTool"
- DisableLanguageExtensions="FALSE"/>
- </FileConfiguration>
- </File>
- <File
- RelativePath=".\strtst.c">
- </File>
- <File
- RelativePath=".\trnstst.c">
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx">
- <File
- RelativePath=".\iotest.h">
- </File>
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/Build/source/libs/icu-xetex/test/iotest/stream.cpp b/Build/source/libs/icu-xetex/test/iotest/stream.cpp
deleted file mode 100644
index ccc70632235..00000000000
--- a/Build/source/libs/icu-xetex/test/iotest/stream.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
-**********************************************************************
-* Copyright (C) 2002-2006, International Business Machines
-* Corporation and others. All Rights Reserved.
-**********************************************************************
-* file name: iotest.cpp
-* encoding: US-ASCII
-* tab size: 8 (not used)
-* indentation:4
-*
-* created on: 2002feb21
-* created by: George Rhoten
-*/
-
-
-#include "unicode/ustream.h"
-
-#include "unicode/ucnv.h"
-#include "unicode/ustring.h"
-#include "ustr_cnv.h"
-#include "iotest.h"
-
-#if U_IOSTREAM_SOURCE >= 199711
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define USE_SSTREAM 1
-#include <sstream>
-#else
-// <strstream> is deprecated on some platforms, and the compiler complains very loudly if you use it.
-#include <strstream>
-#endif
-using namespace std;
-#elif U_IOSTREAM_SOURCE >= 198506
-#include <strstream.h>
-#endif
-
-#include <string.h>
-
-U_CDECL_BEGIN
-#ifdef U_WINDOWS
-const UChar NEW_LINE[] = {0x0d,0x0a,0};
-const char C_NEW_LINE[] = {0x0d,0x0a,0};
-#define UTF8_NEW_LINE "\x0d\x0a"
-#else
-const UChar NEW_LINE[] = {0x0a,0};
-const char C_NEW_LINE[] = {'\n',0};
-#define UTF8_NEW_LINE "\x0a"
-#endif
-U_CDECL_END
-
-U_CDECL_BEGIN
-static void U_CALLCONV TestStream(void)
-{
-#if U_IOSTREAM_SOURCE >= 198506
- const UChar thisMu[] = { 0x74, 0x48, 0x69, 0x73, 0x3BC, 0};
- const UChar mu[] = { 0x6D, 0x75, 0};
- UnicodeString str1 = UNICODE_STRING_SIMPLE("str1");
- UnicodeString str2 = UNICODE_STRING_SIMPLE(" <<");
- UnicodeString str3 = UNICODE_STRING_SIMPLE("2");
- UnicodeString str4 = UNICODE_STRING_SIMPLE(" UTF-8 ");
- UnicodeString inStr = UNICODE_STRING_SIMPLE(" UTF-8 ");
- UnicodeString inStr2;
- char defConvName[UCNV_MAX_CONVERTER_NAME_LENGTH*2];
- char inStrC[128];
- UErrorCode status = U_ZERO_ERROR;
- UConverter *defConv;
- static const char testStr[] = "\x42\x65\x67\x69\x6E\x6E\x69\x6E\x67\x20\x6F\x66\x20\x74\x65\x73\x74\x20\x73\x74\x72\x31\x20\x20\x20\x3C\x3C\x32\x31\x20" UTF8_NEW_LINE "\x20\x55\x54\x46\x2D\x38\x20\xCE\xBC\xF0\x90\x80\x81\xF0\x90\x80\x82";
-
- str4.append((UChar32)0x03BC); /* mu */
- str4.append((UChar32)0x10001);
- str4.append((UChar32)0x10002);
-
- /* release the default converter and use utf-8 for a bit */
- defConv = u_getDefaultConverter(&status);
- if (U_FAILURE(status)) {
- log_err("Can't get default converter\n");
- return;
- }
- ucnv_close(defConv);
- strncpy(defConvName, ucnv_getDefaultName(), sizeof(defConvName)/sizeof(defConvName[0]));
- ucnv_setDefaultName("UTF-8");
-
- static const char * const TESTSTRING = "\x20\x74\x48\x69\x73\xCE\xBC\xE2\x80\x82\x20\x6D\x75\x20\x77\x6F\x72\x6C\x64";
-#ifdef USE_SSTREAM
- ostringstream outTestStream;
- istringstream inTestStream(TESTSTRING);
-#else
- char testStreamBuf[512];
- ostrstream outTestStream(testStreamBuf, sizeof(testStreamBuf));
- istrstream inTestStream(TESTSTRING, 0);
-
- /* initialize testStreamBuf */
- memset(testStreamBuf, '*', sizeof(testStreamBuf));
- testStreamBuf[sizeof(testStreamBuf)-1] = 0;
-#endif
-
- outTestStream << "\x42\x65\x67\x69\x6E\x6E\x69\x6E\x67\x20\x6F\x66\x20\x74\x65\x73\x74\x20";
- outTestStream << str1 << "\x20\x20" << str2 << str3 << "\x31\x20" << UTF8_NEW_LINE << str4 << ends;
-#ifdef USE_SSTREAM
- string tempStr = outTestStream.str();
- const char *testStreamBuf = tempStr.c_str();
-#endif
- if (strcmp(testStreamBuf, testStr) != 0) {
- log_err("Got: \"%s\", Expected: \"%s\"\n", testStreamBuf, testStr);
- }
-
- inTestStream >> inStr >> inStr2;
- if (inStr.compare(thisMu) != 0) {
- u_austrncpy(inStrC, inStr.getBuffer(), inStr.length());
- inStrC[inStr.length()] = 0;
- log_err("Got: \"%s\", Expected: \"tHis\\u03BC\"\n", inStrC);
- }
- if (inStr2.compare(mu) != 0) {
- u_austrncpy(inStrC, inStr.getBuffer(), inStr.length());
- inStrC[inStr.length()] = 0;
- log_err("Got: \"%s\", Expected: \"mu\"\n", inStrC);
- }
-
- /* return the default converter to the original state. */
- ucnv_setDefaultName(defConvName);
- defConv = u_getDefaultConverter(&status);
- if (U_FAILURE(status)) {
- log_err("Can't get default converter");
- return;
- }
- ucnv_close(defConv);
-#else
- log_info("U_IOSTREAM_SOURCE is disabled\n");
-#endif
-}
-U_CDECL_END
-
-U_CFUNC void addStreamTests(TestNode** root) {
- addTest(root, &TestStream, "stream/TestStream");
-}
-
diff --git a/Build/source/libs/icu-xetex/test/iotest/strtst.c b/Build/source/libs/icu-xetex/test/iotest/strtst.c
deleted file mode 100644
index 0412f25efb2..00000000000
--- a/Build/source/libs/icu-xetex/test/iotest/strtst.c
+++ /dev/null
@@ -1,790 +0,0 @@
-/*
-**********************************************************************
-* Copyright (C) 2004-2006, International Business Machines
-* Corporation and others. All Rights Reserved.
-**********************************************************************
-* file name: strtst.c
-* encoding: US-ASCII
-* tab size: 8 (not used)
-* indentation:4
-*
-* created on: 2004apr06
-* created by: George Rhoten
-*/
-
-#include "unicode/ustdio.h"
-#include "unicode/ustring.h"
-#include "iotest.h"
-
-#include <string.h>
-
-static void TestString(void) {
-#if !UCONFIG_NO_FORMATTING
- int32_t n[1];
- float myFloat = -1234.0;
- int32_t newValuePtr[1];
- double newDoubleValuePtr[1];
- UChar myUString[512];
- UChar uStringBuf[512];
- char myString[512] = "";
- int32_t retVal;
- void *origPtr, *ptr;
- U_STRING_DECL(myStringOrig, "My-String", 9);
-
- U_STRING_INIT(myStringOrig, "My-String", 9);
- u_memset(myUString, 0x0a, sizeof(myUString)/ sizeof(*myUString));
- u_memset(uStringBuf, 0x0a, sizeof(uStringBuf) / sizeof(*uStringBuf));
-
- *n = -1234;
- if (sizeof(void *) == 4) {
- origPtr = (void *)0xdeadbeef;
- } else if (sizeof(void *) == 8) {
- origPtr = (void *) INT64_C(0x1000200030004000);
- } else if (sizeof(void *) == 16) {
- /* iSeries */
- union {
- int32_t arr[4];
- void *ptr;
- } massiveBigEndianPtr = {{ 0x10002000, 0x30004000, 0x50006000, 0x70008000 }};
- origPtr = massiveBigEndianPtr.ptr;
- } else {
- log_err("sizeof(void*)=%d hasn't been tested before", (int)sizeof(void*));
- }
-
- /* Test sprintf */
- u_sprintf(uStringBuf, "Signed decimal integer d: %d", *n);
- *newValuePtr = 1;
- u_sscanf(uStringBuf, "Signed decimal integer d: %d", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%d Got: %d, Expected: %d\n", *newValuePtr, *n);
- }
-
- u_sprintf(uStringBuf, "Signed decimal integer i: %i", *n);
- *newValuePtr = 1;
- u_sscanf(uStringBuf, "Signed decimal integer i: %i", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%i Got: %i, Expected: %i\n", *newValuePtr, *n);
- }
-
- u_sprintf(uStringBuf, "Unsigned octal integer o: %o", *n);
- *newValuePtr = 1;
- u_sscanf(uStringBuf, "Unsigned octal integer o: %o", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%o Got: %o, Expected: %o\n", *newValuePtr, *n);
- }
-
- u_sprintf(uStringBuf, "Unsigned decimal integer %%u: %u", *n);
- *newValuePtr = 1;
- u_sscanf(uStringBuf, "Unsigned decimal integer %%u: %u", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%u Got: %u, Expected: %u\n", *newValuePtr, *n);
- }
-
- u_sprintf(uStringBuf, "Lowercase unsigned hexadecimal integer x: %x", *n);
- *newValuePtr = 1;
- u_sscanf(uStringBuf, "Lowercase unsigned hexadecimal integer x: %x", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%x Got: %x, Expected: %x\n", *newValuePtr, *n);
- }
-
- u_sprintf(uStringBuf, "Uppercase unsigned hexadecimal integer X: %X", *n);
- *newValuePtr = 1;
- u_sscanf(uStringBuf, "Uppercase unsigned hexadecimal integer X: %X", newValuePtr);
- if (*n != *newValuePtr) {
- log_err("%%X Got: %X, Expected: %X\n", *newValuePtr, *n);
- }
-
- u_sprintf(uStringBuf, "Float f: %f", myFloat);
- *newDoubleValuePtr = -1.0;
- u_sscanf(uStringBuf, "Float f: %lf", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%f Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
- }
-
- u_sprintf(uStringBuf, "Lowercase float e: %e", myFloat);
- *newDoubleValuePtr = -1.0;
- u_sscanf(uStringBuf, "Lowercase float e: %le", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%e Got: %e, Expected: %e\n", *newDoubleValuePtr, myFloat);
- }
-
- u_sprintf(uStringBuf, "Uppercase float E: %E", myFloat);
- *newDoubleValuePtr = -1.0;
- u_sscanf(uStringBuf, "Uppercase float E: %lE", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%E Got: %E, Expected: %E\n", *newDoubleValuePtr, myFloat);
- }
-
- u_sprintf(uStringBuf, "Lowercase float g: %g", myFloat);
- *newDoubleValuePtr = -1.0;
- u_sscanf(uStringBuf, "Lowercase float g: %lg", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%g Got: %g, Expected: %g\n", *newDoubleValuePtr, myFloat);
- }
-
- u_sprintf(uStringBuf, "Uppercase float G: %G", myFloat);
- *newDoubleValuePtr = -1.0;
- u_sscanf(uStringBuf, "Uppercase float G: %lG", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%G Got: %G, Expected: %G\n", *newDoubleValuePtr, myFloat);
- }
-
- ptr = NULL;
- u_sprintf(uStringBuf, "Pointer %%p: %p\n", origPtr);
- u_sscanf(uStringBuf, "Pointer %%p: %p\n", &ptr);
- if (ptr != origPtr || u_strlen(uStringBuf) != 13+(sizeof(void*)*2)) {
- log_err("%%p Got: %p, Expected: %p\n", ptr, origPtr);
- }
-
- u_sprintf(uStringBuf, "Char c: %c", 'A');
- u_sscanf(uStringBuf, "Char c: %c", myString);
- if (*myString != 'A') {
- log_err("%%c Got: %c, Expected: A\n", *myString);
- }
-
- u_sprintf(uStringBuf, "UChar %%C: %C", (UChar)0x0041); /*'A'*/
- u_sscanf(uStringBuf, "UChar %%C: %C", myUString);
- if (*myUString != (UChar)0x0041) { /*'A'*/
- log_err("%%C Got: %C, Expected: A\n", *myUString);
- }
-
- u_sprintf(uStringBuf, "String %%s: %s", "My-String");
- u_sscanf(uStringBuf, "String %%s: %s", myString);
- if (strcmp(myString, "My-String")) {
- log_err("%%s Got: %s, Expected: My-String\n", myString);
- }
- if (uStringBuf[20] != 0) {
- log_err("String not terminated. Got %c\n", uStringBuf[20] );
- }
- u_sprintf(uStringBuf, "NULL String %%s: %s", NULL);
- u_sscanf(uStringBuf, "NULL String %%s: %s", myString);
- if (strcmp(myString, "(null)")) {
- log_err("%%s Got: %s, Expected: My-String\n", myString);
- }
-
- u_sprintf(uStringBuf, "Unicode String %%S: %S", myStringOrig);
- u_sscanf(uStringBuf, "Unicode String %%S: %S", myUString);
- u_austrncpy(myString, myUString, sizeof(myString)/sizeof(*myString));
- if (strcmp(myString, "My-String")) {
- log_err("%%S Got: %s, Expected: My String\n", myString);
- }
-
- u_sprintf(uStringBuf, "NULL Unicode String %%S: %S", NULL);
- u_sscanf(uStringBuf, "NULL Unicode String %%S: %S", myUString);
- u_austrncpy(myString, myUString, sizeof(myString)/sizeof(*myString));
- if (strcmp(myString, "(null)")) {
- log_err("%%S Got: %s, Expected: (null)\n", myString);
- }
-
- u_sprintf(uStringBuf, "Percent %%P (non-ANSI): %P", myFloat);
- *newDoubleValuePtr = -1.0;
- u_sscanf(uStringBuf, "Percent %%P (non-ANSI): %P", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%P Got: %P, Expected: %P\n", *newDoubleValuePtr, myFloat);
- }
-
- u_sprintf(uStringBuf, "Spell Out %%V (non-ANSI): %V", myFloat);
- *newDoubleValuePtr = -1.0;
- u_sscanf(uStringBuf, "Spell Out %%V (non-ANSI): %V", newDoubleValuePtr);
- if (myFloat != *newDoubleValuePtr) {
- log_err("%%V Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
- }
-
- *newValuePtr = 1;
- u_sprintf(uStringBuf, "\t\nPointer to integer (Count) %%n: n=%d %n n=%d\n", *newValuePtr, newValuePtr, *newValuePtr);
- if (*newValuePtr != 37) {
- log_err("%%V Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
- }
-
-/* u_sscanf(uStringBuf, "Pointer %%p: %p\n", myFile);*/
-
- {
- static const char longStr[] = "This is a long test12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
-
- retVal = u_sprintf(uStringBuf, longStr);
- u_austrncpy(myString, uStringBuf, sizeof(uStringBuf)/sizeof(*uStringBuf));
- if (strcmp(myString, longStr)) {
- log_err("%%S Got: %s, Expected: %s\n", myString, longStr);
- }
- if (retVal != (int32_t)strlen(longStr)) {
- log_err("%%S returned different sizes. Got: %d Expected: %d\n", retVal, strlen(longStr));
- }
-
- retVal = u_sprintf(uStringBuf, "%s", longStr);
- u_austrncpy(myString, uStringBuf, sizeof(uStringBuf)/sizeof(*uStringBuf));
- if (strcmp(myString, longStr)) {
- log_err("%%S Got: %s, Expected: %s\n", myString, longStr);
- }
- if (retVal != (int32_t)strlen(longStr)) {
- log_err("%%S returned different sizes. Got: %d Expected: %d\n", retVal, strlen(longStr));
- }
-
- u_uastrncpy(myUString, longStr, sizeof(longStr)/sizeof(*longStr));
- u_sprintf_u(uStringBuf, myUString);
- if (u_strcmp(myUString, uStringBuf)) {
- log_err("%%S Long strings differ. Expected: %s\n", longStr);
- }
-
- u_uastrncpy(myUString, longStr, sizeof(longStr)/sizeof(*longStr));
- retVal = u_sprintf_u(uStringBuf, myUString+10);
- if (u_strcmp(myUString+10, uStringBuf)) {
- log_err("%%S Long strings differ. Expected: %s\n", longStr + 10);
- }
- if (retVal != (int32_t)strlen(longStr + 10)) {
- log_err("%%S returned different sizes. Got: %d Expected: %d\n", retVal, strlen(longStr));
- }
-
- u_memset(uStringBuf, 1, sizeof(longStr)/sizeof(*longStr));
- u_uastrncpy(myUString, longStr, sizeof(longStr)/sizeof(*longStr));
- retVal = u_snprintf_u(uStringBuf, 10, myUString);
- if (u_strncmp(myUString, uStringBuf, 10) || uStringBuf[10] != 1 || retVal != 10) {
- log_err("%%S Long strings differ. Expected the first 10 characters of %s\n", longStr);
- }
- }
-#endif
-}
-
-static void TestLocalizedString(void) {
-#if !UCONFIG_NO_FORMATTING
- UChar testStr[256];
- UChar uBuffer[256];
- char cBuffer[256];
- int32_t numResult = -1;
- const char *locale;
- UFILE *strFile = u_fstropen(testStr, sizeof(testStr)/sizeof(testStr[0]), "en_US");
-
- if (!strFile) {
- log_err("u_fstropen failed to work\n");
- return;
- }
- u_fprintf(strFile, "%d", 1234);
- u_frewind(strFile);
- u_fscanf(strFile, "%d", &numResult);
- u_uastrcpy(uBuffer,"1,234");
- u_austrcpy(cBuffer,testStr);
- if (u_strcmp(testStr, uBuffer) != 0) {
- log_err("u_fprintf failed to work on an en string Got: %s\n", cBuffer);
- }
- if (numResult != 1234) {
- log_err("u_fscanf failed to work on an en string Got: %d\n", numResult);
- }
-
- u_frewind(strFile);
- locale = u_fgetlocale(strFile);
- if (locale == NULL || strcmp(locale, "en_US") != 0) {
- log_err("u_fgetlocale didn't return \"en\" Got: %d\n", u_fgetlocale(strFile));
- }
- u_fsetlocale(strFile, "de_DE");
- locale = u_fgetlocale(strFile);
- if (locale == NULL || strcmp(locale, "de_DE") != 0) {
- log_err("u_fgetlocale didn't return \"de\" Got: %d\n", u_fgetlocale(strFile));
- }
-
- u_fprintf(strFile, "%d", 1234);
- u_frewind(strFile);
- numResult = -1;
- u_fscanf(strFile, "%d", &numResult);
- u_fclose(strFile);
- u_uastrcpy(uBuffer,"1.234");
- u_austrcpy(cBuffer,testStr);
- if (u_strcmp(testStr, uBuffer) != 0) {
- log_err("u_fprintf failed to work on a de string Got: %s\n", cBuffer);
- }
- if (numResult != 1234) {
- log_err("u_fscanf failed to work on a de string Got: %d\n", numResult);
- }
-
- strFile = u_fstropen(testStr, sizeof(testStr)/sizeof(testStr[0]), NULL);
- u_fprintf(strFile, "%d", 1234);
- u_frewind(strFile);
- numResult = -1;
- u_fscanf(strFile, "%d", &numResult);
- u_fclose(strFile);
- if (numResult != 1234) {
- log_err("u_fscanf failed to work on a default locale string Got: %d, Expected: 1234\n", numResult);
- }
- if (u_fstropen(testStr, -1, NULL) != NULL) {
- log_err("u_fstropen returned a UFILE* on a negative buffer size\n", numResult);
- }
-#endif
-}
-
-#if !UCONFIG_NO_FORMATTING
-#define Test_u_snprintf(limit, format, value, expectedSize, expectedStr) \
- u_uastrncpy(testStr, "xxxxxxxxxxxxxx", sizeof(testStr)/sizeof(testStr[0]));\
- size = u_snprintf(testStr, limit, format, value);\
- u_austrncpy(cTestResult, testStr, sizeof(cTestResult)/sizeof(cTestResult[0]));\
- if (size != expectedSize || strcmp(cTestResult, expectedStr) != 0) {\
- log_err("Unexpected formatting. size=%d expectedSize=%d cTestResult=%s expectedStr=%s\n",\
- size, expectedSize, cTestResult, expectedStr);\
- }\
- else {\
- log_verbose("Got: %s\n", cTestResult);\
- }\
-
-#endif
-
-static void TestSnprintf(void) {
-#if !UCONFIG_NO_FORMATTING
- UChar testStr[256];
- char cTestResult[256];
- int32_t size;
-
- Test_u_snprintf(0, "%d", 123, 0, "xxxxxxxxxxxxxx");
- Test_u_snprintf(2, "%d", 123, 2, "12xxxxxxxxxxxx");
- Test_u_snprintf(3, "%d", 123, 3, "123xxxxxxxxxxx");
- Test_u_snprintf(4, "%d", 123, 3, "123");
-
- Test_u_snprintf(0, "%s", "abcd", 0, "xxxxxxxxxxxxxx");
- Test_u_snprintf(3, "%s", "abcd", 3, "abcxxxxxxxxxxx");
- Test_u_snprintf(4, "%s", "abcd", 4, "abcdxxxxxxxxxx");
- Test_u_snprintf(5, "%s", "abcd", 4, "abcd");
-
- Test_u_snprintf(0, "%e", 12.34, 0, "xxxxxxxxxxxxxx");
- Test_u_snprintf(1, "%e", 12.34, 1, "1xxxxxxxxxxxxx");
- Test_u_snprintf(2, "%e", 12.34, 2, "1.xxxxxxxxxxxx");
- Test_u_snprintf(3, "%e", 12.34, 3, "1.2xxxxxxxxxxx");
- Test_u_snprintf(5, "%e", 12.34, 5, "1.234xxxxxxxxx");
- Test_u_snprintf(6, "%e", 12.34, 6, "1.2340xxxxxxxx");
- Test_u_snprintf(8, "%e", 12.34, 8, "1.234000xxxxxx");
- Test_u_snprintf(9, "%e", 12.34, 9, "1.234000exxxxx");
- Test_u_snprintf(10, "%e", 12.34, 10, "1.234000e+xxxx");
- Test_u_snprintf(11, "%e", 12.34, 11, "1.234000e+0xxx");
- Test_u_snprintf(13, "%e", 12.34, 13, "1.234000e+001x");
- Test_u_snprintf(14, "%e", 12.34, 13, "1.234000e+001");
-#endif
-}
-
-#define TestSPrintFormat(uFormat, uValue, cFormat, cValue) \
- /* Reinitialize the buffer to verify null termination works. */\
- u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));\
- memset(buffer, '*', sizeof(buffer)/sizeof(*buffer));\
- \
- uNumPrinted = u_sprintf(uBuffer, uFormat, uValue);\
- u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]));\
- cNumPrinted = sprintf(buffer, cFormat, cValue);\
- if (strcmp(buffer, compBuffer) != 0) {\
- log_err("%" uFormat " Got: \"%s\", Expected: \"%s\"\n", compBuffer, buffer);\
- }\
- if (cNumPrinted != uNumPrinted) {\
- log_err("%" uFormat " number printed Got: %d, Expected: %d\n", uNumPrinted, cNumPrinted);\
- }\
- if (buffer[uNumPrinted+1] != '*') {\
- log_err("%" uFormat " too much stored\n");\
- }\
-
-static void TestSprintfFormat(void) {
-#if !UCONFIG_NO_FORMATTING
- static const UChar abcUChars[] = {0x61,0x62,0x63,0};
- static const char abcChars[] = "abc";
- UChar uBuffer[256];
- char buffer[256];
- char compBuffer[256];
- int32_t uNumPrinted;
- int32_t cNumPrinted;
-
-
- TestSPrintFormat("%8S", abcUChars, "%8s", abcChars);
- TestSPrintFormat("%-8S", abcUChars, "%-8s", abcChars);
- TestSPrintFormat("%.2S", abcUChars, "%.2s", abcChars); /* strlen is 3 */
-
- TestSPrintFormat("%8s", abcChars, "%8s", abcChars);
- TestSPrintFormat("%-8s", abcChars, "%-8s", abcChars);
- TestSPrintFormat("%.2s", abcChars, "%.2s", abcChars); /* strlen is 3 */
-
- TestSPrintFormat("%8c", (char)'e', "%8c", (char)'e');
- TestSPrintFormat("%-8c", (char)'e', "%-8c", (char)'e');
-
- TestSPrintFormat("%8C", (UChar)0x65, "%8c", (char)'e');
- TestSPrintFormat("%-8C", (UChar)0x65, "%-8c", (char)'e');
-
- TestSPrintFormat("%f", 1.23456789, "%f", 1.23456789);
- TestSPrintFormat("%f", 12345.6789, "%f", 12345.6789);
- TestSPrintFormat("%f", 123456.789, "%f", 123456.789);
- TestSPrintFormat("%f", 1234567.89, "%f", 1234567.89);
- TestSPrintFormat("%10f", 1.23456789, "%10f", 1.23456789);
- TestSPrintFormat("%-10f", 1.23456789, "%-10f", 1.23456789);
- TestSPrintFormat("%10f", 123.456789, "%10f", 123.456789);
- TestSPrintFormat("%10.4f", 123.456789, "%10.4f", 123.456789);
- TestSPrintFormat("%-10f", 123.456789, "%-10f", 123.456789);
-
-/* TestSPrintFormat("%g", 12345.6789, "%g", 12345.6789);
- TestSPrintFormat("%g", 123456.789, "%g", 123456.789);
- TestSPrintFormat("%g", 1234567.89, "%g", 1234567.89);
- TestSPrintFormat("%G", 123456.789, "%G", 123456.789);
- TestSPrintFormat("%G", 1234567.89, "%G", 1234567.89);*/
- TestSPrintFormat("%10g", 1.23456789, "%10g", 1.23456789);
- TestSPrintFormat("%10.4g", 1.23456789, "%10.4g", 1.23456789);
- TestSPrintFormat("%-10g", 1.23456789, "%-10g", 1.23456789);
- TestSPrintFormat("%10g", 123.456789, "%10g", 123.456789);
- TestSPrintFormat("%-10g", 123.456789, "%-10g", 123.456789);
-
- TestSPrintFormat("%8x", 123456, "%8x", 123456);
- TestSPrintFormat("%-8x", 123456, "%-8x", 123456);
- TestSPrintFormat("%08x", 123456, "%08x", 123456);
-
- TestSPrintFormat("%8X", 123456, "%8X", 123456);
- TestSPrintFormat("%-8X", 123456, "%-8X", 123456);
- TestSPrintFormat("%08X", 123456, "%08X", 123456);
- TestSPrintFormat("%#x", 123456, "%#x", 123456);
- TestSPrintFormat("%#x", -123456, "%#x", -123456);
-
- TestSPrintFormat("%8o", 123456, "%8o", 123456);
- TestSPrintFormat("%-8o", 123456, "%-8o", 123456);
- TestSPrintFormat("%08o", 123456, "%08o", 123456);
- TestSPrintFormat("%#o", 123, "%#o", 123);
- TestSPrintFormat("%#o", -123, "%#o", -123);
-
- TestSPrintFormat("%8u", 123456, "%8u", 123456);
- TestSPrintFormat("%-8u", 123456, "%-8u", 123456);
- TestSPrintFormat("%08u", 123456, "%08u", 123456);
- TestSPrintFormat("%8u", -123456, "%8u", -123456);
- TestSPrintFormat("%-8u", -123456, "%-8u", -123456);
- TestSPrintFormat("%.5u", 123456, "%.5u", 123456);
- TestSPrintFormat("%.6u", 123456, "%.6u", 123456);
- TestSPrintFormat("%.7u", 123456, "%.7u", 123456);
-
- TestSPrintFormat("%8d", 123456, "%8d", 123456);
- TestSPrintFormat("%-8d", 123456, "%-8d", 123456);
- TestSPrintFormat("%08d", 123456, "%08d", 123456);
- TestSPrintFormat("% d", 123456, "% d", 123456);
- TestSPrintFormat("% d", -123456, "% d", -123456);
-
- TestSPrintFormat("%8i", 123456, "%8i", 123456);
- TestSPrintFormat("%-8i", 123456, "%-8i", 123456);
- TestSPrintFormat("%08i", 123456, "%08i", 123456);
-
- log_verbose("Get really crazy with the formatting.\n");
-
- TestSPrintFormat("%-#12x", 123, "%-#12x", 123);
- TestSPrintFormat("%-#12x", -123, "%-#12x", -123);
- TestSPrintFormat("%#12x", 123, "%#12x", 123);
- TestSPrintFormat("%#12x", -123, "%#12x", -123);
-
- TestSPrintFormat("%-+12d", 123, "%-+12d", 123);
- TestSPrintFormat("%-+12d", -123, "%-+12d", -123);
- TestSPrintFormat("%- 12d", 123, "%- 12d", 123);
- TestSPrintFormat("%- 12d", -123, "%- 12d", -123);
- TestSPrintFormat("%+12d", 123, "%+12d", 123);
- TestSPrintFormat("%+12d", -123, "%+12d", -123);
- TestSPrintFormat("% 12d", 123, "% 12d", 123);
- TestSPrintFormat("% 12d", -123, "% 12d", -123);
- TestSPrintFormat("%12d", 123, "%12d", 123);
- TestSPrintFormat("%12d", -123, "%12d", -123);
- TestSPrintFormat("%.12d", 123, "%.12d", 123);
- TestSPrintFormat("%.12d", -123, "%.12d", -123);
-
- TestSPrintFormat("%-+12.1f", 1.234, "%-+12.1f", 1.234);
- TestSPrintFormat("%-+12.1f", -1.234, "%-+12.1f", -1.234);
- TestSPrintFormat("%- 12.10f", 1.234, "%- 12.10f", 1.234);
- TestSPrintFormat("%- 12.1f", -1.234, "%- 12.1f", -1.234);
- TestSPrintFormat("%+12.1f", 1.234, "%+12.1f", 1.234);
- TestSPrintFormat("%+12.1f", -1.234, "%+12.1f", -1.234);
- TestSPrintFormat("% 12.1f", 1.234, "% 12.1f", 1.234);
- TestSPrintFormat("% 12.1f", -1.234, "% 12.1f", -1.234);
- TestSPrintFormat("%12.1f", 1.234, "%12.1f", 1.234);
- TestSPrintFormat("%12.1f", -1.234, "%12.1f", -1.234);
- TestSPrintFormat("%.2f", 1.234, "%.2f", 1.234);
- TestSPrintFormat("%.2f", -1.234, "%.2f", -1.234);
- TestSPrintFormat("%3f", 1.234, "%3f", 1.234);
- TestSPrintFormat("%3f", -1.234, "%3f", -1.234);
-#endif
-}
-
-#undef TestSPrintFormat
-
-static void TestStringCompatibility(void) {
-#if !UCONFIG_NO_FORMATTING
- UChar myUString[256];
- UChar uStringBuf[256];
- char myString[256] = "";
- char testBuf[256] = "";
- int32_t num;
-
- u_memset(myUString, 0x0a, sizeof(myUString)/ sizeof(*myUString));
- u_memset(uStringBuf, 0x0a, sizeof(uStringBuf) / sizeof(*uStringBuf));
-
- /* Compare against C API compatibility */
- for (num = -STANDARD_TEST_NUM_RANGE; num < STANDARD_TEST_NUM_RANGE; num++) {
- sprintf(testBuf, "%x", (int)num);
- u_sprintf(uStringBuf, "%x", num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%x Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }
-
- sprintf(testBuf, "%X", (int)num);
- u_sprintf(uStringBuf, "%X", num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%X Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }
-
- sprintf(testBuf, "%o", (int)num);
- u_sprintf(uStringBuf, "%o", num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%o Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }
-
- /* sprintf is not compatible on all platforms e.g. the iSeries*/
- sprintf(testBuf, "%d", (int)num);
- u_sprintf(uStringBuf, "%d", num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%d Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }
-
- sprintf(testBuf, "%i", (int)num);
- u_sprintf(uStringBuf, "%i", num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%i Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }
-
- sprintf(testBuf, "%f", (double)num);
- u_sprintf(uStringBuf, "%f", (double)num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%f Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }
-
-/* sprintf(testBuf, "%e", (double)num);
- u_sprintf(uStringBuf, "%e", (double)num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%e Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }
-
- sprintf(testBuf, "%E", (double)num);
- u_sprintf(uStringBuf, "%E", (double)num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%E Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }*/
-
- sprintf(testBuf, "%g", (double)num);
- u_sprintf(uStringBuf, "%g", (double)num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%g Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }
-
- sprintf(testBuf, "%G", (double)num);
- u_sprintf(uStringBuf, "%G", (double)num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (strcmp(myString, testBuf) != 0) {
- log_err("%%G Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
- }
- }
-
- for (num = 0; num < 0x80; num++) {
- testBuf[0] = (char)0xFF;
- uStringBuf[0] = (UChar)0xfffe;
- sprintf(testBuf, "%c", (char)num);
- u_sprintf(uStringBuf, "%c", num);
- u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
- if (testBuf[0] != myString[0] || myString[0] != num) {
- log_err("%%c Got: 0x%x, Expected: 0x%x\n", myString[0], testBuf[0]);
- }
- }
-#endif
-}
-
-static void TestSScanSetFormat(const char *format, const UChar *uValue, const char *cValue, UBool expectedToPass) {
-#if !UCONFIG_NO_FORMATTING
- UChar uBuffer[256];
- char buffer[256];
- char compBuffer[256];
- int32_t uNumScanned;
- int32_t cNumScanned;
-
- /* Reinitialize the buffer to verify null termination works. */
- u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
- uBuffer[sizeof(uBuffer)/sizeof(*uBuffer)-1] = 0;
- memset(buffer, '*', sizeof(buffer)/sizeof(*buffer));
- buffer[sizeof(buffer)/sizeof(*buffer)-1] = 0;
-
- uNumScanned = u_sscanf(uValue, format, uBuffer);
- if (expectedToPass) {
- u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]));
- cNumScanned = sscanf(cValue, format, buffer);
- if (strncmp(buffer, compBuffer, sizeof(uBuffer)/sizeof(uBuffer[0])) != 0) {
- log_err("%s Got: \"%s\", Expected: \"%s\"\n", format, compBuffer, buffer);
- }
- if (cNumScanned != uNumScanned) {
- log_err("%s number scanned Got: %d, Expected: %d\n", format, uNumScanned, cNumScanned);
- }
- if (uNumScanned > 0 && uBuffer[u_strlen(uBuffer)+1] != 0x2a) {
- log_err("%s too much stored\n", format);
- }
- }
- else {
- if (uNumScanned != 0 || uBuffer[0] != 0x2a || uBuffer[1] != 0x2a) {
- log_err("%s too much stored on a failure\n", format);
- }
- }
-#endif
-}
-
-static void TestSScanset(void) {
-#if !UCONFIG_NO_FORMATTING
- static const UChar abcUChars[] = {0x61,0x62,0x63,0x63,0x64,0x65,0x66,0x67,0};
- static const char abcChars[] = "abccdefg";
-
- TestSScanSetFormat("%[bc]S", abcUChars, abcChars, TRUE);
- TestSScanSetFormat("%[cb]S", abcUChars, abcChars, TRUE);
-
- TestSScanSetFormat("%[ab]S", abcUChars, abcChars, TRUE);
- TestSScanSetFormat("%[ba]S", abcUChars, abcChars, TRUE);
-
- TestSScanSetFormat("%[ab]", abcUChars, abcChars, TRUE);
- TestSScanSetFormat("%[ba]", abcUChars, abcChars, TRUE);
-
- TestSScanSetFormat("%[abcdefgh]", abcUChars, abcChars, TRUE);
- TestSScanSetFormat("%[;hgfedcba]", abcUChars, abcChars, TRUE);
-
- TestSScanSetFormat("%[^a]", abcUChars, abcChars, TRUE);
- TestSScanSetFormat("%[^e]", abcUChars, abcChars, TRUE);
- TestSScanSetFormat("%[^ed]", abcUChars, abcChars, TRUE);
- TestSScanSetFormat("%[^dc]", abcUChars, abcChars, TRUE);
- TestSScanSetFormat("%[^e] ", abcUChars, abcChars, TRUE);
-
- TestSScanSetFormat("%1[ab] ", abcUChars, abcChars, TRUE);
- TestSScanSetFormat("%2[^f]", abcUChars, abcChars, TRUE);
-
- TestSScanSetFormat("%[qrst]", abcUChars, abcChars, TRUE);
-
- /* Extra long string for testing */
- TestSScanSetFormat(" %[qrst]",
- abcUChars, abcChars, TRUE);
-
- TestSScanSetFormat("%[a-]", abcUChars, abcChars, TRUE);
-
- /* Bad format */
- TestSScanSetFormat("%[a", abcUChars, abcChars, FALSE);
- TestSScanSetFormat("%[f-a]", abcUChars, abcChars, FALSE);
- TestSScanSetFormat("%[c-a]", abcUChars, abcChars, FALSE);
- /* The following is not deterministic on Windows */
-/* TestSScanSetFormat("%[a-", abcUChars, abcChars);*/
-
- /* TODO: Need to specify precision with a "*" */
-#endif
-}
-
-static void TestBadSScanfFormat(const char *format, const UChar *uValue, const char *cValue) {
-#if !UCONFIG_NO_FORMATTING
- UChar uBuffer[256];
- int32_t uNumScanned;
-
- /* Reinitialize the buffer to verify null termination works. */
- u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));
- uBuffer[sizeof(uBuffer)/sizeof(*uBuffer)-1] = 0;
-
- uNumScanned = u_sscanf(uValue, format, uBuffer);
- if (uNumScanned != 0 || uBuffer[0] != 0x2a || uBuffer[1] != 0x2a) {
- log_err("%s too much stored on a failure\n", format);
- }
-#endif
-}
-
-static void TestBadScanfFormat(void) {
-#if !UCONFIG_NO_FORMATTING
- static const UChar abcUChars[] = {0x61,0x62,0x63,0x63,0x64,0x65,0x66,0x67,0};
- static const char abcChars[] = "abccdefg";
-
- TestBadSScanfFormat("%[] ", abcUChars, abcChars);
-#endif
-}
-
-static void Test_u_vfprintf(const char *expectedResult, const char *format, ...) {
-#if !UCONFIG_NO_FORMATTING
- UChar uBuffer[256];
- UChar uBuffer2[256];
- va_list ap;
- int32_t count;
-
- va_start(ap, format);
- count = u_vsprintf(uBuffer, format, ap);
- va_end(ap);
- u_uastrcpy(uBuffer2, expectedResult);
- if (u_strcmp(uBuffer, uBuffer2) != 0) {
- log_err("Got two different results for \"%s\" expected \"%s\"\n", format, expectedResult);
- }
-
- u_uastrcpy(uBuffer2, format);
- va_start(ap, format);
- count = u_vsprintf_u(uBuffer, uBuffer2, ap);
- va_end(ap);
- u_uastrcpy(uBuffer2, expectedResult);
- if (u_strcmp(uBuffer, uBuffer2) != 0) {
- log_err("Got two different results for \"%s\" expected \"%s\"\n", format, expectedResult);
- }
-#endif
-}
-
-static void TestVargs(void) {
-#if !UCONFIG_NO_FORMATTING
- Test_u_vfprintf("8 9 a B 8.9", "%d %u %x %X %.1f", 8, 9, 10, 11, 8.9);
-#endif
-}
-
-static void TestCount(void) {
-#if !UCONFIG_NO_FORMATTING
- static const UChar x15[] = { 0x78, 0x31, 0x35, 0 };
- UChar testStr[16];
- UChar character;
- int16_t i16 = -1;
- int32_t i32 = -1, actual_count, actual_result;
- int64_t i64 = -1;
- u_uastrcpy(testStr, "1233456789");
- if (u_sscanf(testStr, "%*3[123]%n%*[1-9]", &i32) != 0) {
- log_err("test 1: scanf did not return 0\n");
- }
- if (i32 != 3) {
- log_err("test 1: scanf returned %hd instead of 3\n", i32);
- }
- if (u_sscanf(testStr, "%*4[123]%hn%*[1-9]", &i16) != 0) {
- log_err("test 2: scanf did not return 0\n");
- }
- if (i16 != 4) {
- log_err("test 2: scanf returned %d instead of 4\n", i16);
- }
- if (u_sscanf(testStr, "%*[123]%*[1-9]%lln", &i64) != 0) {
- log_err("test 3: scanf did not return 0\n");
- }
- if (i64 != 10) {
- log_err("test 3: scanf did not return 10\n", i64);
- }
- actual_result = u_sscanf(x15, "%C%d%n", &character, &i32, &actual_count);
- if (actual_result != 2) {
- log_err("scanf should return 2, but returned %d\n", actual_result);
- }
- if (character != 0x78) {
- log_err("scanf should return 0x78 for the character, but returned %X\n", character);
- }
- if (i32 != 15) {
- log_err("scanf should return 15 for the number, but returned %d\n", i32);
- }
- if (actual_count != 3) {
- log_err("scanf should return 3 for actual_count, but returned %d\n", actual_count);
- }
-#endif
-}
-
-U_CFUNC void
-addStringTest(TestNode** root) {
-#if !UCONFIG_NO_FORMATTING
- addTest(root, &TestString, "string/TestString");
- addTest(root, &TestLocalizedString, "string/TestLocalizedString");
- addTest(root, &TestSprintfFormat, "string/TestSprintfFormat");
- addTest(root, &TestSnprintf, "string/TestSnprintf");
- addTest(root, &TestSScanset, "string/TestSScanset");
- addTest(root, &TestStringCompatibility, "string/TestStringCompatibility");
- addTest(root, &TestBadScanfFormat, "string/TestBadScanfFormat");
- addTest(root, &TestVargs, "string/TestVargs");
- addTest(root, &TestCount, "string/TestCount");
-#endif
-}
-
-
diff --git a/Build/source/libs/icu-xetex/test/iotest/trnstst.c b/Build/source/libs/icu-xetex/test/iotest/trnstst.c
deleted file mode 100644
index 8f6101323f8..00000000000
--- a/Build/source/libs/icu-xetex/test/iotest/trnstst.c
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
-**********************************************************************
-* Copyright (C) 2005-2005, International Business Machines
-* Corporation and others. All Rights Reserved.
-**********************************************************************
-* file name: strtst.c
-* created by: George Rhoten
-*/
-
-#include "iotest.h"
-#include "unicode/ustdio.h"
-#include "unicode/utrans.h"
-#include "unicode/ustring.h"
-
-static void TestTranslitOps(void)
-{
-#if !UCONFIG_NO_TRANSLITERATION
- UFILE *f;
- UErrorCode err = U_ZERO_ERROR;
- UTransliterator *a = NULL, *b = NULL, *c = NULL;
-
- log_verbose("opening a transliterator and UFILE for testing\n");
-
- f = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL);
- if(f == NULL)
- {
- log_err("Couldn't open test file for writing\n");
- return;
- }
-
- a = utrans_open("Latin-Greek", UTRANS_FORWARD, NULL, -1, NULL, &err);
- if(U_FAILURE(err))
- {
- log_err("Error opening transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
-
- log_verbose("setting a transliterator\n");
- b = u_fsettransliterator(f, U_WRITE, a, &err);
- if(U_FAILURE(err))
- {
- log_err("Error setting transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- if(b != NULL)
- {
- log_err("Error, a transliterator was already set!\n");
- }
-
- b = u_fsettransliterator(NULL, U_WRITE, a, &err);
- if(err != U_ILLEGAL_ARGUMENT_ERROR)
- {
- log_err("Error setting transliterator on NULL file err=%s\n", u_errorName(err));
- }
-
- if(b != a)
- {
- log_err("Error getting the same transliterator was not returned on NULL file\n");
- }
-
- err = U_FILE_ACCESS_ERROR;
- b = u_fsettransliterator(f, U_WRITE, a, &err);
- if(err != U_FILE_ACCESS_ERROR)
- {
- log_err("Error setting transliterator on error status err=%s\n", u_errorName(err));
- }
-
- if(b != a)
- {
- log_err("Error getting the same transliterator on error status\n");
- }
- err = U_ZERO_ERROR;
-
-
- log_verbose("un-setting transliterator (setting to null)\n");
- c = u_fsettransliterator(f, U_WRITE, NULL, &err);
- if(U_FAILURE(err))
- {
- log_err("Err setting transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- if(c != a)
- {
- log_err("Err, transliterator that came back was not the original one.\n");
- }
-
- log_verbose("Trying to set read transliterator (should fail)\n");
- b = u_fsettransliterator(f, U_READ, NULL, &err);
- if(err != U_UNSUPPORTED_ERROR)
- {
- log_err("Should have U_UNSUPPORTED_ERROR setting Read transliterator but got %s - REVISIT AND UPDATE TEST\n", u_errorName(err));
- u_fclose(f);
- return;
- }
- else
- {
- log_verbose("Got %s error (expected) setting READ transliterator.\n", u_errorName(err));
- err = U_ZERO_ERROR;
- }
-
-
- utrans_close(c);
- u_fclose(f);
-#endif
-}
-
-static void TestTranslitFileOut(void)
-{
-#if !UCONFIG_NO_FORMATTING
-#if !UCONFIG_NO_TRANSLITERATION
- UFILE *f;
- UErrorCode err = U_ZERO_ERROR;
- UTransliterator *a = NULL, *b = NULL, *c = NULL;
- FILE *infile;
- UChar compare[] = { 0xfeff, 0x03a3, 0x03c4, 0x03b5, 0x03c6, 0x1f00, 0x03bd, 0x03bf, 0x03c2, 0x043C, 0x0000 };
- UChar ubuf[256];
- int len;
-
- log_verbose("opening a transliterator and UFILE for testing\n");
-
- f = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", "utf-16");
- if(f == NULL)
- {
- log_err("Couldn't open test file for writing\n");
- return;
- }
-
- a = utrans_open("Latin-Greek", UTRANS_FORWARD, NULL, -1, NULL, &err);
- if(U_FAILURE(err))
- {
- log_err("Err opening transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- log_verbose("setting a transliterator\n");
- b = u_fsettransliterator(f, U_WRITE, a, &err);
- if(U_FAILURE(err))
- {
- log_err("Err setting transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- if(b != NULL)
- {
- log_err("Err, a transliterator was already set!\n");
- }
-
- u_fprintf(f, "Stephanos");
-
- c = utrans_open("Latin-Cyrillic", UTRANS_FORWARD, NULL, -1, NULL, &err);
- if(U_FAILURE(err))
- {
- log_err("Err opening transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- log_verbose("setting a transliterator\n");
- b = u_fsettransliterator(f, U_WRITE, c, &err);
- if(U_FAILURE(err))
- {
- log_err("Err setting transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- if(b != a)
- {
- log_err("Error: a different transliterator was returned!\n");
- }
- utrans_close(b);
-
- u_fprintf(f, "m");
-
- u_fclose(f);
-
- log_verbose("Re reading test file to verify transliteration\n");
- infile = fopen(STANDARD_TEST_FILE, "rb");
- if(infile == NULL)
- {
- log_err("Couldn't reopen test file\n");
- return;
- }
-
- len=fread(ubuf, sizeof(UChar), u_strlen(compare), infile);
- log_verbose("Read %d UChars\n", len);
- if(len != u_strlen(compare))
- {
- log_err("Wanted %d UChars from file, got %d\n", u_strlen(compare), len);
- }
- ubuf[len]=0;
-
- if(u_strlen(compare) != u_strlen(ubuf))
- {
- log_err("Wanted %d UChars from file, but u_strlen() returns %d\n", u_strlen(compare), len);
- }
-
- if(u_strcmp(compare, ubuf))
- {
- log_err("Read string doesn't match expected.\n");
- }
- else
- {
- log_verbose("Read string matches expected.\n");
- }
-
- fclose(infile);
-#endif
-#endif
-}
-
-static void TestTranslitStringOut(void)
-{
-#if !UCONFIG_NO_FORMATTING
-#if !UCONFIG_NO_TRANSLITERATION
- UFILE *f;
- UErrorCode err = U_ZERO_ERROR;
- UTransliterator *a = NULL, *b = NULL, *c = NULL;
- UChar compare[] = { 0x03a3, 0x03c4, 0x03b5, 0x03c6, 0x1f00, 0x03bd, 0x03bf, 0x03c2, 0x043C, 0x0000 };
- UChar ubuf[256];
-
- log_verbose("opening a transliterator and UFILE for testing\n");
-
- f = u_fstropen(ubuf, sizeof(ubuf)/sizeof(ubuf[0]), "en_US_POSIX");
- if(f == NULL)
- {
- log_err("Couldn't open test file for writing\n");
- return;
- }
-
- a = utrans_open("Latin-Greek", UTRANS_FORWARD, NULL, -1, NULL, &err);
- if(U_FAILURE(err))
- {
- log_err("Err opening transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- log_verbose("setting a transliterator\n");
- b = u_fsettransliterator(f, U_WRITE, a, &err);
- if(U_FAILURE(err))
- {
- log_err("Err setting transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- if(b != NULL)
- {
- log_err("Err, a transliterator was already set!\n");
- }
-
- u_fprintf(f, "Stephanos");
-
- c = utrans_open("Latin-Cyrillic", UTRANS_FORWARD, NULL, -1, NULL, &err);
- if(U_FAILURE(err))
- {
- log_err("Err opening transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- log_verbose("setting a transliterator\n");
- b = u_fsettransliterator(f, U_WRITE, c, &err);
- if(U_FAILURE(err))
- {
- log_err("Err setting transliterator %s\n", u_errorName(err));
- u_fclose(f);
- return;
- }
-
- if(b != a)
- {
- log_err("Error: a different transliterator was returned!\n");
- }
- utrans_close(b);
-
- u_fprintf(f, "m");
-
- u_fclose(f);
-
- if(u_strlen(compare) != u_strlen(ubuf))
- {
- log_err("Wanted %d UChars from file, but u_strlen() returns %d\n", u_strlen(compare), u_strlen(ubuf));
- }
-
- if(u_strcmp(compare, ubuf))
- {
- log_err("Read string doesn't match expected.\n");
- }
- else
- {
- log_verbose("Read string matches expected.\n");
- }
-#endif
-#endif
-}
-
-U_CFUNC void
-addTranslitTest(TestNode** root) {
-#if !UCONFIG_NO_TRANSLITERATION
- addTest(root, &TestTranslitOps, "translit/ops");
-#if !UCONFIG_NO_FORMATTING
- addTest(root, &TestTranslitFileOut, "translit/fileOut");
- addTest(root, &TestTranslitStringOut, "translit/stringOut");
-#endif
-#endif
-}