X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..729e4ab9bc6618bc3d8a898e575df7f4019e29ca:/icuSources/test/iotest/filetst.c diff --git a/icuSources/test/iotest/filetst.c b/icuSources/test/iotest/filetst.c index 1e908e42..b65dc34e 100644 --- a/icuSources/test/iotest/filetst.c +++ b/icuSources/test/iotest/filetst.c @@ -1,16 +1,16 @@ /* -********************************************************************** -* 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 -*/ + ********************************************************************** + * Copyright (C) 2004-2010, 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" @@ -18,8 +18,9 @@ #include "unicode/uloc.h" #include +#include -const char STANDARD_TEST_FILE[] = "iotest-c.txt"; +const char *STANDARD_TEST_FILE = "iotest-c.txt"; #if !UCONFIG_NO_FORMATTING @@ -97,7 +98,7 @@ static void TestFileFromICU(UFILE *myFile) { 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); + myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL); if (myFile == NULL) { log_err("Can't read test file."); @@ -233,6 +234,8 @@ static void TestFileFromICU(UFILE *myFile) { } u_fgets(myUString, 4, myFile); + myString[2] = '!'; + myString[3] = '!'; u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString)); if (myString == NULL || strcmp(myString, "\t\n") != 0) { log_err("u_fgets got \"%s\"\n", myString); @@ -310,7 +313,7 @@ static void TestFile(void) { /* FILE *standardFile;*/ log_verbose("Testing u_fopen\n"); - TestFileFromICU(u_fopen(STANDARD_TEST_FILE, "w", NULL, NULL)); + TestFileFromICU(u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL)); /* Don't know how to make this work without stdout or stderr */ /* @@ -318,6 +321,10 @@ static void TestFile(void) { standardFile = fopen(STANDARD_TEST_FILE, "wb"); TestFileFromICU(u_finit(standardFile, NULL, NULL)); fclose(standardFile); + + log_verbose("Testing u_fadopt\n"); + standardFile = fopen(STANDARD_TEST_FILE, "wb"); + TestFileFromICU(u_fadopt(standardFile, NULL, NULL)); */ } #endif @@ -902,6 +909,69 @@ static void TestCodepage(void) { } +static void TestCodepageFlush(void) { +#if UCONFIG_NO_LEGACY_CONVERSION + log_verbose("Skipping, legacy conversion is disabled."); +#else + UChar utf16String[] = { 0x39, 0x39, 0x39, 0x20, 0x65E0, 0x6CD6, 0x5728, 0x0000 }; + uint8_t inBuf[200]; + size_t inLen =0; + const char *enc = "IBM-1388"; /* GBK EBCDIC stateful */ + UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "wb", "en_US_POSIX", enc); + FILE *myCFile; + int shift = 0; + int i; + + if (myFile == NULL) { + log_err("Can't write test file %s\n", STANDARD_TEST_FILE); + return; + } + + u_fprintf(myFile, "%S", utf16String); + u_fclose(myFile); + + /* now read it back */ + myCFile = fopen(STANDARD_TEST_FILE, "rb"); + if (myCFile == NULL) { + log_err("Can't read test file."); + return; + } + + inLen = fread(inBuf, 1, 200, myCFile); + fclose(myCFile); + + if(inLen<=0) { + log_err("Failed during read of test file."); + return; + } + + /* check if shift in and out */ + for(i=0;i