~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/test/iotest/iotest.cpp

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  
2
 
**********************************************************************
3
 
*   Copyright (C) 2002-2002, International Business Machines
4
 
*   Corporation and others.  All Rights Reserved.
5
 
**********************************************************************
6
 
*   file name:  iotest.cpp
7
 
*   encoding:   US-ASCII
8
 
*   tab size:   8 (not used)
9
 
*   indentation:4
10
 
*
11
 
*   created on: 2002feb21
12
 
*   created by: George Rhoten
13
 
*/
14
 
 
15
 
 
16
 
#include "unicode/ustdio.h"
17
 
#include "unicode/ustream.h"
18
 
#include "unicode/uclean.h"
19
 
 
20
 
#include "unicode/ucnv.h"
21
 
#include "unicode/unistr.h"
22
 
#include "unicode/ustring.h"
23
 
#include "unicode/ctest.h"
24
 
#include "unicode/utrans.h"
25
 
#include "ustr_imp.h"
26
 
 
27
 
#if U_IOSTREAM_SOURCE >= 199711
28
 
#include <iostream>
29
 
#include <strstream>
30
 
using namespace std;
31
 
#elif U_IOSTREAM_SOURCE >= 198506
32
 
#include <iostream.h>
33
 
#include <strstream.h>
34
 
#endif
35
 
 
36
 
#include <string.h>
37
 
 
38
 
static char STANDARD_TEST_FILE[] = "iotest-c.txt";
39
 
static const int32_t STANDARD_TEST_NUM_RANGE = 1000;
40
 
 
41
 
#ifdef WIN32
42
 
static const UChar NEW_LINE[] = {0x0d,0x0a,0};
43
 
#define C_NEW_LINE "\r\n"
44
 
#else
45
 
static const UChar NEW_LINE[] = {0x0a,0};
46
 
#define C_NEW_LINE "\n"
47
 
#endif
48
 
 
49
 
static void TestFileFromICU(UFILE *myFile) {
50
 
    int32_t n[1];
51
 
    float myFloat = -1234.0;
52
 
    UDate myDate = 0.0;
53
 
    UDate dec_31_1969 = -57600000.000000; /* TODO: These are not correct */
54
 
    UDate midnight = 86400000.000000; /* TODO: These are not correct */
55
 
    UDate myNewDate = -1.0;
56
 
    int32_t newValuePtr[1];
57
 
    double newDoubleValuePtr[1];
58
 
    UChar myUString[256];
59
 
    UChar uStringBuf[256];
60
 
    char myString[256] = "";
61
 
    char testBuf[256] = "";
62
 
 
63
 
    u_memset(myUString, 0x2a, sizeof(myUString)/sizeof(*myUString));
64
 
    u_memset(uStringBuf, 0x2a, sizeof(uStringBuf)/sizeof(*uStringBuf));
65
 
    memset(myString, 0x2a, sizeof(myString)/sizeof(*myString));
66
 
    memset(testBuf, 0x2a, sizeof(testBuf)/sizeof(*testBuf));
67
 
 
68
 
    if (myFile == NULL) {
69
 
        log_err("Can't write test file.");
70
 
        return;
71
 
    }
72
 
 
73
 
    *n = -1234;
74
 
 
75
 
    /* Test fprintf */
76
 
    u_fprintf(myFile, "Signed decimal integer %%d: %d\n", *n);
77
 
    u_fprintf(myFile, "Signed decimal integer %%i: %i\n", *n);
78
 
    u_fprintf(myFile, "Unsigned octal integer %%o: %o\n", *n);
79
 
    u_fprintf(myFile, "Unsigned decimal integer %%u: %u\n", *n);
80
 
    u_fprintf(myFile, "Lowercase unsigned hexadecimal integer %%x: %x\n", *n);
81
 
    u_fprintf(myFile, "Uppercase unsigned hexadecimal integer %%X: %X\n", *n);
82
 
    u_fprintf(myFile, "Float %%f: %f\n", myFloat);
83
 
    u_fprintf(myFile, "Lowercase float %%e: %e\n", myFloat);
84
 
    u_fprintf(myFile, "Uppercase float %%E: %E\n", myFloat);
85
 
    u_fprintf(myFile, "Lowercase float %%g: %g\n", myFloat);
86
 
    u_fprintf(myFile, "Uppercase float %%G: %G\n", myFloat);
87
 
//    u_fprintf(myFile, "Pointer %%p: %p\n", myFile);
88
 
    u_fprintf(myFile, "Char %%c: %c\n", 'A');
89
 
    u_fprintf(myFile, "UChar %%K (non-ANSI, should be %%C for Microsoft?): %K\n", L'A');
90
 
    u_fprintf(myFile, "String %%s: %s\n", "My-String");
91
 
    u_fprintf(myFile, "NULL String %%s: %s\n", NULL);
92
 
    u_fprintf(myFile, "Unicode String %%U (non-ANSI, should be %%S for Microsoft?): %U\n", L"My-String");
93
 
    u_fprintf(myFile, "NULL Unicode String %%U (non-ANSI, should be %%S for Microsoft?): %U\n", NULL);
94
 
    u_fprintf(myFile, "Date %%D (non-ANSI): %D\n", myDate);
95
 
    u_fprintf(myFile, "Time %%T (non-ANSI): %T\n", myDate);
96
 
    u_fprintf(myFile, "Percent %%P (non-ANSI): %P\n", myFloat);
97
 
    u_fprintf(myFile, "Currency %%M (non-ANSI): %M\n", myFloat);
98
 
    u_fprintf(myFile, "Spell Out %%V (non-ANSI): %V\n", myFloat);
99
 
 
100
 
    *n = 1;
101
 
    u_fprintf(myFile, "\t\nPointer to integer (Count) %%n: n=%d %n n=%d\n", *n, n, *n);
102
 
    u_fprintf(myFile, "Pointer to integer Value: %d\n", *n);
103
 
    *n = 1;
104
 
    fprintf(u_fgetfile(myFile), "\tNormal fprintf count: n=%d %n n=%d\n", *n ,n, *n);
105
 
    fprintf(u_fgetfile(myFile), "\tNormal fprintf count value: n=%d\n", *n);
106
 
 
107
 
    u_fclose(myFile);
108
 
    myFile = u_fopen(STANDARD_TEST_FILE, "r", NULL, NULL);
109
 
 
110
 
    if (myFile == NULL) {
111
 
        log_err("Can't read test file.");
112
 
        return;
113
 
    }
114
 
 
115
 
    *n = -1234;
116
 
 
117
 
    myString[0] = u_fgetc(myFile);
118
 
    if (myString[0] != 0x53 /* S */) {
119
 
        log_err("u_fgetc 1 returned %X. Expected 'S'.", myString[0]);
120
 
    }
121
 
    u_fungetc(myString[0], myFile);
122
 
    myString[0] = u_fgetc(myFile);
123
 
    if (myString[0] != 0x53 /* S */) {
124
 
        log_err("u_fgetc 2 returned %X. Expected 'S'.", myString[0]);
125
 
    }
126
 
    u_fungetc(myString[0], myFile);
127
 
    myString[0] = u_fgetc(myFile);
128
 
    if (myString[0] != 0x53 /* S */) {
129
 
        log_err("u_fgetc 3 returned %X. Expected 'S'.", myString[0]);
130
 
    }
131
 
    u_fungetc(myString[0], myFile);
132
 
 
133
 
    *newValuePtr = 1;
134
 
    u_fscanf(myFile, "Signed decimal integer %%d: %d\n", newValuePtr);
135
 
    if (*n != *newValuePtr) {
136
 
        log_err("%%d Got: %d, Expected: %d\n", *newValuePtr, *n);
137
 
    }
138
 
    *newValuePtr = 1;
139
 
    u_fscanf(myFile, "Signed decimal integer %%i: %i\n", newValuePtr);
140
 
    if (*n != *newValuePtr) {
141
 
        log_err("%%i Got: %i, Expected: %i\n", *newValuePtr, *n);
142
 
    }
143
 
    *newValuePtr = 1;
144
 
    u_fscanf(myFile, "Unsigned octal integer %%o: %o\n", newValuePtr);
145
 
    if (*n != *newValuePtr) {
146
 
        log_err("%%o Got: %o, Expected: %o\n", *newValuePtr, *n);
147
 
    }
148
 
    *newValuePtr = 1;
149
 
    u_fscanf(myFile, "Unsigned decimal integer %%u: %u\n", newValuePtr);
150
 
    if (*n != *newValuePtr) {
151
 
        log_err("%%u Got: %u, Expected: %u\n", *newValuePtr, *n);
152
 
    }
153
 
    *newValuePtr = 1;
154
 
    u_fscanf(myFile, "Lowercase unsigned hexadecimal integer %%x: %x\n", newValuePtr);
155
 
    if (*n != *newValuePtr) {
156
 
        log_err("%%x Got: %x, Expected: %x\n", *newValuePtr, *n);
157
 
    }
158
 
    *newValuePtr = 1;
159
 
    u_fscanf(myFile, "Uppercase unsigned hexadecimal integer %%X: %X\n", newValuePtr);
160
 
    if (*n != *newValuePtr) {
161
 
        log_err("%%X Got: %X, Expected: %X\n", *newValuePtr, *n);
162
 
    }
163
 
    *newDoubleValuePtr = -1.0;
164
 
    u_fscanf(myFile, "Float %%f: %f\n", newDoubleValuePtr);
165
 
    if (myFloat != *newDoubleValuePtr) {
166
 
        log_err("%%f Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
167
 
    }
168
 
    *newDoubleValuePtr = -1.0;
169
 
    u_fscanf(myFile, "Lowercase float %%e: %e\n", newDoubleValuePtr);
170
 
    if (myFloat != *newDoubleValuePtr) {
171
 
        log_err("%%e Got: %e, Expected: %e\n", *newDoubleValuePtr, myFloat);
172
 
    }
173
 
    *newDoubleValuePtr = -1.0;
174
 
    u_fscanf(myFile, "Uppercase float %%E: %E\n", newDoubleValuePtr);
175
 
    if (myFloat != *newDoubleValuePtr) {
176
 
        log_err("%%E Got: %E, Expected: %E\n", *newDoubleValuePtr, myFloat);
177
 
    }
178
 
    *newDoubleValuePtr = -1.0;
179
 
    u_fscanf(myFile, "Lowercase float %%g: %g\n", newDoubleValuePtr);
180
 
    if (myFloat != *newDoubleValuePtr) {
181
 
        log_err("%%g Got: %g, Expected: %g\n", *newDoubleValuePtr, myFloat);
182
 
    }
183
 
    *newDoubleValuePtr = -1.0;
184
 
    u_fscanf(myFile, "Uppercase float %%G: %G\n", newDoubleValuePtr);
185
 
    if (myFloat != *newDoubleValuePtr) {
186
 
        log_err("%%G Got: %G, Expected: %G\n", *newDoubleValuePtr, myFloat);
187
 
    }
188
 
//  u_fscanf(myFile, "Pointer %%p: %p\n", newDoubleValue);
189
 
    u_fscanf(myFile, "Char %%c: %c\n", myString);
190
 
    if (*myString != 'A') {
191
 
        log_err("%%c Got: %c, Expected: A\n", *myString);
192
 
    }
193
 
    u_fscanf(myFile, "UChar %%K (non-ANSI, should be %%C for Microsoft?): %K\n", myUString);
194
 
    if (*myUString != L'A') {
195
 
        log_err("%%C Got: %C, Expected: A\n", *myUString);
196
 
    }
197
 
    u_fscanf(myFile, "String %%s: %s\n", myString);
198
 
    if (strcmp(myString, "My-String")) {
199
 
        log_err("%%s Got: %s, Expected: My String\n", myString);
200
 
    }
201
 
    u_fscanf(myFile, "NULL String %%s: %s\n", myString);
202
 
    if (strcmp(myString, "(null)")) {
203
 
        log_err("%%s Got: %s, Expected: My String\n", myString);
204
 
    }
205
 
    u_fscanf(myFile, "Unicode String %%U (non-ANSI, should be %%S for Microsoft?): %U\n", myUString);
206
 
    u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
207
 
    if (strcmp(myString, "My-String")) {
208
 
        log_err("%%S Got: %S, Expected: My String\n", myUString);
209
 
    }
210
 
    u_fscanf(myFile, "NULL Unicode String %%U (non-ANSI, should be %%S for Microsoft?): %U\n", myUString);
211
 
    u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
212
 
    if (strcmp(myString, "(null)")) {
213
 
        log_err("%%S Got: %S, Expected: My String\n", myUString);
214
 
    }
215
 
    myNewDate = -1.0;
216
 
    u_fscanf(myFile, "Date %%D (non-ANSI): %D\n", &myNewDate);
217
 
    if (myNewDate != dec_31_1969) {
218
 
        log_err("%%D Got: %f, Expected: %f\n", myNewDate, dec_31_1969);
219
 
    }
220
 
    myNewDate = -1.0;
221
 
    u_fscanf(myFile, "Time %%T (non-ANSI): %T\n", &myNewDate);
222
 
    if (myNewDate != midnight) {
223
 
        log_err("%%T Got: %f, Expected: %f\n", myNewDate, midnight);
224
 
    }
225
 
    *newDoubleValuePtr = -1.0;
226
 
    u_fscanf(myFile, "Percent %%P (non-ANSI): %P\n", newDoubleValuePtr);
227
 
    if (myFloat != *newDoubleValuePtr) {
228
 
        log_err("%%P Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
229
 
    }
230
 
    *newDoubleValuePtr = -1.0;
231
 
    u_fscanf(myFile, "Currency %%M (non-ANSI): %M\n", newDoubleValuePtr);
232
 
    if (myFloat != *newDoubleValuePtr) {
233
 
        log_err("%%P Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
234
 
    }
235
 
    *newDoubleValuePtr = -1.0;
236
 
    u_fscanf(myFile, "Spell Out %%V (non-ANSI): %V\n", newDoubleValuePtr);
237
 
    if (myFloat != *newDoubleValuePtr) {
238
 
        log_err("%%V Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
239
 
    }
240
 
 
241
 
    u_fgets(myFile, 4, myUString);
242
 
    u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
243
 
    if (myString == NULL || strcmp(myString, "\t\n") != 0) {
244
 
        log_err("u_fgets got \"%s\"\n", myString);
245
 
    }
246
 
 
247
 
    if (u_fgets(myFile, sizeof(myUString)/sizeof(*myUString), myUString) != myUString) {
248
 
        log_err("u_fgets did not return myUString\n");
249
 
    }
250
 
    u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
251
 
    if (myString == NULL || strcmp(myString, "Pointer to integer (Count) %n: n=1  n=1\n") != 0) {
252
 
        log_err("u_fgets got \"%s\"\n", myString);
253
 
    }
254
 
 
255
 
    if (u_fgets(myFile, sizeof(myUString)/sizeof(*myUString), myUString) != myUString) {
256
 
        log_err("u_fgets did not return myUString\n");
257
 
    }
258
 
    u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
259
 
    if (myString == NULL || strcmp(myString, "Pointer to integer Value: 37\n") != 0) {
260
 
        log_err("u_fgets got \"%s\"\n", myString);
261
 
    }
262
 
 
263
 
    if (u_fgets(myFile, 0, myUString) != NULL) {
264
 
        log_err("u_fgets got \"%s\" and it should have returned NULL\n", myString);
265
 
    }
266
 
 
267
 
    if (u_fgets(myFile, 1, myUString) != myUString) {
268
 
        log_err("u_fgets did not return myUString\n");
269
 
    }
270
 
    u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
271
 
    if (myString == NULL || strcmp(myString, "") != 0) {
272
 
        log_err("u_fgets got \"%s\"\n", myString);
273
 
    }
274
 
 
275
 
    if (u_fgets(myFile, 2, myUString) != myUString) {
276
 
        log_err("u_fgets did not return myUString\n");
277
 
    }
278
 
    u_austrncpy(myString, myUString, sizeof(myUString)/sizeof(*myUString));
279
 
    if (myString == NULL || strcmp(myString, "\t") != 0) {
280
 
        log_err("u_fgets got \"%s\"\n", myString);
281
 
    }
282
 
 
283
 
    u_fclose(myFile);
284
 
}
285
 
 
286
 
static void TestFile() {
287
 
/*    FILE *standardFile;*/
288
 
 
289
 
    log_verbose("Testing u_fopen\n");
290
 
    TestFileFromICU(u_fopen(STANDARD_TEST_FILE, "w", NULL, NULL));
291
 
 
292
 
/* Don't know how to make this work without stdout or stderr */
293
 
/*
294
 
    log_verbose("Testing u_finit\n");
295
 
    standardFile = fopen(STANDARD_TEST_FILE, "wb");
296
 
    TestFileFromICU(u_finit(standardFile, NULL, NULL));
297
 
    fclose(standardFile);
298
 
*/
299
 
}
300
 
 
301
 
static void TestCodepage() {
302
 
    UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "w", NULL, NULL);
303
 
    if (u_fgetcodepage(myFile) == NULL
304
 
        || strcmp(u_fgetcodepage(myFile), ucnv_getDefaultName()) != 0)
305
 
    {
306
 
        log_err("Didn't get the proper default codepage. Got %s expected: %s\n",
307
 
            u_fgetcodepage(myFile), ucnv_getDefaultName());
308
 
    }
309
 
    u_fclose(myFile);
310
 
 
311
 
    myFile = u_fopen(STANDARD_TEST_FILE, "w", "en", NULL);
312
 
    if (u_fgetcodepage(myFile) == NULL
313
 
        || strcmp(u_fgetcodepage(myFile), "ISO-8859-1") != 0)
314
 
    {
315
 
        log_err("Didn't get the proper default codepage for \"en\". Got %s expected: iso-8859-1\n",
316
 
            u_fgetcodepage(myFile));
317
 
    }
318
 
    u_fclose(myFile);
319
 
}
320
 
 
321
 
 
322
 
static void TestFilePrintCompatibility() {
323
 
    UFILE *myFile = u_fopen(STANDARD_TEST_FILE, "wb", "en_US_POSIX", NULL);
324
 
    FILE *myCFile;
325
 
    int32_t num;
326
 
    char cVal;
327
 
    static const UChar emptyStr[] = {0};
328
 
    char readBuf[512] = "";
329
 
    char testBuf[512] = "";
330
 
 
331
 
    if (myFile == NULL) {
332
 
        log_err("Can't read test file.");
333
 
        return;
334
 
    }
335
 
 
336
 
    /* Compare against C API compatibility */
337
 
    for (num = -STANDARD_TEST_NUM_RANGE; num < STANDARD_TEST_NUM_RANGE; num++) {
338
 
        u_fprintf(myFile, "%x ", num);
339
 
        u_fprintf(myFile, "%X ", num);
340
 
        u_fprintf(myFile, "%o ", num);
341
 
        u_fprintf(myFile, "%d ", num);
342
 
        u_fprintf(myFile, "%i ", num);
343
 
        u_fprintf(myFile, "%f ", (double)num);
344
 
        u_fprintf(myFile, "%e ", (double)num);
345
 
        u_fprintf(myFile, "%E ", (double)num);
346
 
        u_fprintf(myFile, "%g ", (double)num);
347
 
        u_fprintf(myFile, "%G", (double)num);
348
 
        u_fputs(emptyStr, myFile);
349
 
    }
350
 
 
351
 
    u_fprintf_u(myFile, NEW_LINE);
352
 
 
353
 
    for (num = 0; num < 0x80; num++) {
354
 
        u_fprintf(myFile, "%c", num);
355
 
    }
356
 
 
357
 
    u_fclose(myFile);
358
 
    myCFile = fopen(STANDARD_TEST_FILE, "rb");
359
 
    if (myCFile == NULL) {
360
 
        log_err("Can't read test file.");
361
 
        return;
362
 
    }
363
 
 
364
 
    for (num = -STANDARD_TEST_NUM_RANGE; num < STANDARD_TEST_NUM_RANGE; num++) {
365
 
        fscanf(myCFile, "%s", readBuf);
366
 
        sprintf(testBuf, "%x", num);
367
 
        if (strcmp(readBuf, testBuf) != 0) {
368
 
            log_err("%%x Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
369
 
        }
370
 
 
371
 
        fscanf(myCFile, "%s", readBuf);
372
 
        sprintf(testBuf, "%X", num);
373
 
        if (strcmp(readBuf, testBuf) != 0) {
374
 
            log_err("%%X Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
375
 
        }
376
 
 
377
 
        fscanf(myCFile, "%s", readBuf);
378
 
        sprintf(testBuf, "%o", num);
379
 
        if (strcmp(readBuf, testBuf) != 0) {
380
 
            log_err("%%o Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
381
 
        }
382
 
 
383
 
        /* fprintf is not compatible on all platforms e.g. the iSeries */
384
 
        fscanf(myCFile, "%s", readBuf);
385
 
        sprintf(testBuf, "%d", num);
386
 
        if (strcmp(readBuf, testBuf) != 0) {
387
 
            log_err("%%d Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
388
 
        }
389
 
 
390
 
        fscanf(myCFile, "%s", readBuf);
391
 
        sprintf(testBuf, "%i", num);
392
 
        if (strcmp(readBuf, testBuf) != 0) {
393
 
            log_err("%%i Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
394
 
        }
395
 
 
396
 
        fscanf(myCFile, "%s", readBuf);
397
 
        sprintf(testBuf, "%f", (double)num);
398
 
        if (strcmp(readBuf, testBuf) != 0) {
399
 
            log_err("%%f Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
400
 
        }
401
 
 
402
 
        fscanf(myCFile, "%s", readBuf);
403
 
        sprintf(testBuf, "%e", (double)num);
404
 
        if (strcmp(readBuf, testBuf) != 0) {
405
 
            log_err("%%e Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
406
 
        }
407
 
 
408
 
        fscanf(myCFile, "%s", readBuf);
409
 
        sprintf(testBuf, "%E", (double)num);
410
 
        if (strcmp(readBuf, testBuf) != 0) {
411
 
            log_err("%%E Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
412
 
        }
413
 
 
414
 
        fscanf(myCFile, "%s", readBuf);
415
 
        sprintf(testBuf, "%g", (double)num);
416
 
        if (strcmp(readBuf, testBuf) != 0) {
417
 
            log_err("%%g Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
418
 
        }
419
 
 
420
 
        fscanf(myCFile, "%s", readBuf);
421
 
        sprintf(testBuf, "%G", (double)num);
422
 
        if (strcmp(readBuf, testBuf) != 0) {
423
 
            log_err("%%G Got: \"%s\", Expected: \"%s\"\n", readBuf, testBuf);
424
 
        }
425
 
    }
426
 
 
427
 
    /* Properly eat the newlines */
428
 
    for (num = 0; num < u_strlen(NEW_LINE); num++) {
429
 
        fscanf(myCFile, "%c", &cVal);
430
 
        if (cVal != NEW_LINE[num]) {
431
 
            log_err("OS newline error\n");
432
 
        }
433
 
    }
434
 
    for (num = 0; num < u_strlen(NEW_LINE); num++) {
435
 
        fscanf(myCFile, "%c", &cVal);
436
 
        if (cVal != NEW_LINE[num]) {
437
 
            log_err("ustdio newline error\n");
438
 
        }
439
 
    }
440
 
 
441
 
    for (num = 0; num < 0x80; num++) {
442
 
        cVal = -1;
443
 
        fscanf(myCFile, "%c", &cVal);
444
 
        if (num != cVal) {
445
 
            log_err("%%c Got: 0x%x, Expected: 0x%x\n", cVal, num);
446
 
        }
447
 
    }
448
 
    fclose(myCFile);
449
 
}
450
 
 
451
 
#define TestFPrintFormat(uFormat, uValue, cFormat, cValue) \
452
 
    myFile = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL);\
453
 
    /* Reinitialize the buffer to verify null termination works. */\
454
 
    u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));\
455
 
    memset(buffer, 0x2a, sizeof(buffer)/sizeof(*buffer));\
456
 
    \
457
 
    uNumPrinted = u_fprintf(myFile, uFormat, uValue);\
458
 
    u_fclose(myFile);\
459
 
    myFile = u_fopen(STANDARD_TEST_FILE, "r", "en_US_POSIX", NULL);\
460
 
    u_fgets(myFile, sizeof(uBuffer)/sizeof(*uBuffer), uBuffer);\
461
 
    u_fclose(myFile);\
462
 
    u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(*uBuffer));\
463
 
    cNumPrinted = sprintf(buffer, cFormat, cValue);\
464
 
    if (strcmp(buffer, compBuffer) != 0) {\
465
 
        log_err("%" uFormat " Got: \"%s\", Expected: \"%s\"\n", compBuffer, buffer);\
466
 
    }\
467
 
    if (cNumPrinted != uNumPrinted) {\
468
 
        log_err("%" uFormat " number printed Got: %d, Expected: %d\n", uNumPrinted, cNumPrinted);\
469
 
    }\
470
 
 
471
 
 
472
 
static void TestFprintfFormat() {
473
 
    static const UChar abcUChars[] = {0x61,0x62,0x63,0};
474
 
    static const char abcChars[] = "abc";
475
 
    UChar uBuffer[256];
476
 
    char buffer[256];
477
 
    char compBuffer[256];
478
 
    int32_t uNumPrinted;
479
 
    int32_t cNumPrinted;
480
 
    UFILE *myFile;
481
 
 
482
 
    TestFPrintFormat("%8U", abcUChars, "%8s", abcChars);
483
 
    TestFPrintFormat("%-8U", abcUChars, "%-8s", abcChars);
484
 
 
485
 
    TestFPrintFormat("%8s", abcChars, "%8s", abcChars);
486
 
    TestFPrintFormat("%-8s", abcChars, "%-8s", abcChars);
487
 
 
488
 
    TestFPrintFormat("%8c", 0x65, "%8c", 0x65);
489
 
    TestFPrintFormat("%-8c", 0x65, "%-8c", 0x65);
490
 
 
491
 
    TestFPrintFormat("%8K", (UChar)0x65, "%8c", (char)0x65);
492
 
    TestFPrintFormat("%-8K", (UChar)0x65, "%-8c", (char)0x65);
493
 
 
494
 
    TestFPrintFormat("%10f", 1.23456789, "%10f", 1.23456789);
495
 
    TestFPrintFormat("%-10f", 1.23456789, "%-10f", 1.23456789);
496
 
    TestFPrintFormat("%10f", 123.456789, "%10f", 123.456789);
497
 
    TestFPrintFormat("%-10f", 123.456789, "%-10f", 123.456789);
498
 
 
499
 
    TestFPrintFormat("%10e", 1.23456789, "%10e", 1.23456789);
500
 
    TestFPrintFormat("%-10e", 1.23456789, "%-10e", 1.23456789);
501
 
    TestFPrintFormat("%10e", 123.456789, "%10e", 123.456789);
502
 
    TestFPrintFormat("%-10e", 123.456789, "%-10e", 123.456789);
503
 
 
504
 
    TestFPrintFormat("%10g", 1.23456789, "%10g", 1.23456789);
505
 
    TestFPrintFormat("%-10g", 1.23456789, "%-10g", 1.23456789);
506
 
    TestFPrintFormat("%10g", 123.456789, "%10g", 123.456789);
507
 
    TestFPrintFormat("%-10g", 123.456789, "%-10g", 123.456789);
508
 
 
509
 
    TestFPrintFormat("%8x", 123456, "%8x", 123456);
510
 
    TestFPrintFormat("%-8x", 123456, "%-8x", 123456);
511
 
 
512
 
    TestFPrintFormat("%8X", 123456, "%8X", 123456);
513
 
    TestFPrintFormat("%-8X", 123456, "%-8X", 123456);
514
 
    TestFPrintFormat("%#x", 123456, "%#x", 123456);
515
 
    TestFPrintFormat("%#x", -123456, "%#x", -123456);
516
 
 
517
 
    TestFPrintFormat("%8o", 123456, "%8o", 123456);
518
 
    TestFPrintFormat("%-8o", 123456, "%-8o", 123456);
519
 
    TestFPrintFormat("%#o", 123, "%#o", 123);
520
 
    TestFPrintFormat("%#o", -123, "%#o", -123);
521
 
 
522
 
    TestFPrintFormat("%8u", 123456, "%8u", 123456);
523
 
    TestFPrintFormat("%-8u", 123456, "%-8u", 123456);
524
 
    TestFPrintFormat("%8u", -123456, "%8u", -123456);
525
 
    TestFPrintFormat("%-8u", -123456, "%-8u", -123456);
526
 
 
527
 
    TestFPrintFormat("%8d", 123456, "%8d", 123456);
528
 
    TestFPrintFormat("%-8d", 123456, "%-8d", 123456);
529
 
    TestFPrintFormat("% d", 123456, "% d", 123456);
530
 
    TestFPrintFormat("% d", -123456, "% d", -123456);
531
 
 
532
 
    TestFPrintFormat("%8i", 123456, "%8i", 123456);
533
 
    TestFPrintFormat("%-8i", 123456, "%-8i", 123456);
534
 
 
535
 
    log_verbose("Get really crazy with the formatting.\n");
536
 
 
537
 
    TestFPrintFormat("%-#12x", 123, "%-#12x", 123);
538
 
    TestFPrintFormat("%-#12x", -123, "%-#12x", -123);
539
 
    TestFPrintFormat("%#12x", 123, "%#12x", 123);
540
 
    TestFPrintFormat("%#12x", -123, "%#12x", -123);
541
 
 
542
 
    TestFPrintFormat("%-+12d", 123,  "%-+12d", 123);
543
 
    TestFPrintFormat("%-+12d", -123, "%-+12d", -123);
544
 
    TestFPrintFormat("%- 12d", 123,  "%- 12d", 123);
545
 
    TestFPrintFormat("%- 12d", -123, "%- 12d", -123);
546
 
    TestFPrintFormat("%+12d", 123,   "%+12d", 123);
547
 
    TestFPrintFormat("%+12d", -123,  "%+12d", -123);
548
 
    TestFPrintFormat("% 12d", 123,   "% 12d", 123);
549
 
    TestFPrintFormat("% 12d", -123,  "% 12d", -123);
550
 
    TestFPrintFormat("%12d", 123,    "%12d", 123);
551
 
    TestFPrintFormat("%12d", -123,   "%12d", -123);
552
 
 
553
 
    TestFPrintFormat("%-+12.1e", 1.234,  "%-+12.1e", 1.234);
554
 
    TestFPrintFormat("%-+12.1e", -1.234, "%-+12.1e", -1.234);
555
 
    TestFPrintFormat("%- 12.1e", 1.234,  "%- 12.1e", 1.234);
556
 
    TestFPrintFormat("%- 12.1e", -1.234, "%- 12.1e", -1.234);
557
 
    TestFPrintFormat("%+12.1e", 1.234,   "%+12.1e", 1.234);
558
 
    TestFPrintFormat("%+12.1e", -1.234,  "%+12.1e", -1.234);
559
 
    TestFPrintFormat("% 12.1e", 1.234,   "% 12.1e", 1.234);
560
 
    TestFPrintFormat("% 12.1e", -1.234,  "% 12.1e", -1.234);
561
 
    TestFPrintFormat("%12.1e", 1.234,    "%12.1e", 1.234);
562
 
    TestFPrintFormat("%12.1e", -1.234,   "%12.1e", -1.234);
563
 
    TestFPrintFormat("%.2e", 1.234,      "%.2e", 1.234);
564
 
    TestFPrintFormat("%.2e", -1.234,     "%.2e", -1.234);
565
 
    TestFPrintFormat("%3e", 1.234,       "%3e", 1.234);
566
 
    TestFPrintFormat("%3e", -1.234,      "%3e", -1.234);
567
 
 
568
 
    TestFPrintFormat("%-+12.1f", 1.234,  "%-+12.1f", 1.234);
569
 
    TestFPrintFormat("%-+12.1f", -1.234, "%-+12.1f", -1.234);
570
 
    TestFPrintFormat("%- 12.1f", 1.234,  "%- 12.1f", 1.234);
571
 
    TestFPrintFormat("%- 12.1f", -1.234, "%- 12.1f", -1.234);
572
 
    TestFPrintFormat("%+12.1f", 1.234,   "%+12.1f", 1.234);
573
 
    TestFPrintFormat("%+12.1f", -1.234,  "%+12.1f", -1.234);
574
 
    TestFPrintFormat("% 12.1f", 1.234,   "% 12.1f", 1.234);
575
 
    TestFPrintFormat("% 12.1f", -1.234,  "% 12.1f", -1.234);
576
 
    TestFPrintFormat("%12.1f", 1.234,    "%12.1f", 1.234);
577
 
    TestFPrintFormat("%12.1f", -1.234,   "%12.1f", -1.234);
578
 
    TestFPrintFormat("%.2f", 1.234,      "%.2f", 1.234);
579
 
    TestFPrintFormat("%.2f", -1.234,     "%.2f", -1.234);
580
 
    TestFPrintFormat("%3f", 1.234,       "%3f", 1.234);
581
 
    TestFPrintFormat("%3f", -1.234,      "%3f", -1.234);
582
 
}
583
 
 
584
 
#undef TestFPrintFormat
585
 
 
586
 
static void TestString() {
587
 
    int32_t n[1];
588
 
    float myFloat = -1234.0;
589
 
    UDate myDate = 0.0;
590
 
    UDate dec_31_1969 = -57600000.000000; /* TODO: These are not correct */
591
 
    UDate midnight = 86400000.000000; /* TODO: These are not correct */
592
 
    UDate myNewDate = -1.0;
593
 
    int32_t newValuePtr[1];
594
 
    double newDoubleValuePtr[1];
595
 
    UChar myUString[512];
596
 
    UChar uStringBuf[512];
597
 
    char myString[512] = "";
598
 
    char testBuf[512] = "";
599
 
 
600
 
    u_memset(myUString, 0x0a, sizeof(myUString)/ sizeof(*myUString));
601
 
    u_memset(uStringBuf, 0x0a, sizeof(uStringBuf) / sizeof(*uStringBuf));
602
 
 
603
 
    *n = -1234;
604
 
 
605
 
    /* Test sprintf */
606
 
    u_sprintf(uStringBuf, NULL, "Signed decimal integer d: %d", *n);
607
 
    *newValuePtr = 1;
608
 
    u_sscanf(uStringBuf, NULL, "Signed decimal integer d: %d", newValuePtr);
609
 
    if (*n != *newValuePtr) {
610
 
        log_err("%%d Got: %d, Expected: %d\n", *newValuePtr, *n);
611
 
    }
612
 
 
613
 
    u_sprintf(uStringBuf, NULL, "Signed decimal integer i: %i", *n);
614
 
    *newValuePtr = 1;
615
 
    u_sscanf(uStringBuf, NULL, "Signed decimal integer i: %i", newValuePtr);
616
 
    if (*n != *newValuePtr) {
617
 
        log_err("%%i Got: %i, Expected: %i\n", *newValuePtr, *n);
618
 
    }
619
 
 
620
 
    u_sprintf(uStringBuf, NULL, "Unsigned octal integer o: %o", *n);
621
 
    *newValuePtr = 1;
622
 
    u_sscanf(uStringBuf, NULL, "Unsigned octal integer o: %o", newValuePtr);
623
 
    if (*n != *newValuePtr) {
624
 
        log_err("%%o Got: %o, Expected: %o\n", *newValuePtr, *n);
625
 
    }
626
 
 
627
 
    u_sprintf(uStringBuf, NULL, "Unsigned decimal integer %%u: %u", *n);
628
 
    *newValuePtr = 1;
629
 
    u_sscanf(uStringBuf, NULL, "Unsigned decimal integer %%u: %u", newValuePtr);
630
 
    if (*n != *newValuePtr) {
631
 
        log_err("%%u Got: %u, Expected: %u\n", *newValuePtr, *n);
632
 
    }
633
 
 
634
 
    u_sprintf(uStringBuf, NULL, "Lowercase unsigned hexadecimal integer x: %x", *n);
635
 
    *newValuePtr = 1;
636
 
    u_sscanf(uStringBuf, NULL, "Lowercase unsigned hexadecimal integer x: %x", newValuePtr);
637
 
    if (*n != *newValuePtr) {
638
 
        log_err("%%x Got: %x, Expected: %x\n", *newValuePtr, *n);
639
 
    }
640
 
 
641
 
    u_sprintf(uStringBuf, NULL, "Uppercase unsigned hexadecimal integer X: %X", *n);
642
 
    *newValuePtr = 1;
643
 
    u_sscanf(uStringBuf, NULL, "Uppercase unsigned hexadecimal integer X: %X", newValuePtr);
644
 
    if (*n != *newValuePtr) {
645
 
        log_err("%%X Got: %X, Expected: %X\n", *newValuePtr, *n);
646
 
    }
647
 
 
648
 
    u_sprintf(uStringBuf, NULL, "Float f: %f", myFloat);
649
 
    *newDoubleValuePtr = -1.0;
650
 
    u_sscanf(uStringBuf, NULL, "Float f: %f", newDoubleValuePtr);
651
 
    if (myFloat != *newDoubleValuePtr) {
652
 
        log_err("%%f Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
653
 
    }
654
 
 
655
 
    u_sprintf(uStringBuf, NULL, "Lowercase float e: %e", myFloat);
656
 
    *newDoubleValuePtr = -1.0;
657
 
    u_sscanf(uStringBuf, NULL, "Lowercase float e: %e", newDoubleValuePtr);
658
 
    if (myFloat != *newDoubleValuePtr) {
659
 
        log_err("%%e Got: %e, Expected: %e\n", *newDoubleValuePtr, myFloat);
660
 
    }
661
 
 
662
 
    u_sprintf(uStringBuf, NULL, "Uppercase float E: %E", myFloat);
663
 
    *newDoubleValuePtr = -1.0;
664
 
    u_sscanf(uStringBuf, NULL, "Uppercase float E: %E", newDoubleValuePtr);
665
 
    if (myFloat != *newDoubleValuePtr) {
666
 
        log_err("%%E Got: %E, Expected: %E\n", *newDoubleValuePtr, myFloat);
667
 
    }
668
 
 
669
 
    u_sprintf(uStringBuf, NULL, "Lowercase float g: %g", myFloat);
670
 
    *newDoubleValuePtr = -1.0;
671
 
    u_sscanf(uStringBuf, NULL, "Lowercase float g: %g", newDoubleValuePtr);
672
 
    if (myFloat != *newDoubleValuePtr) {
673
 
        log_err("%%g Got: %g, Expected: %g\n", *newDoubleValuePtr, myFloat);
674
 
    }
675
 
 
676
 
    u_sprintf(uStringBuf, NULL, "Uppercase float G: %G", myFloat);
677
 
    *newDoubleValuePtr = -1.0;
678
 
    u_sscanf(uStringBuf, NULL, "Uppercase float G: %G", newDoubleValuePtr);
679
 
    if (myFloat != *newDoubleValuePtr) {
680
 
        log_err("%%G Got: %G, Expected: %G\n", *newDoubleValuePtr, myFloat);
681
 
    }
682
 
 
683
 
//    u_sprintf(uStringBuf, NULL, "Pointer %%p: %p\n", myFile);
684
 
    u_sprintf(uStringBuf, NULL, "Char c: %c", 'A');
685
 
    u_sscanf(uStringBuf, NULL, "Char c: %c", myString);
686
 
    if (*myString != 'A') {
687
 
        log_err("%%c Got: %c, Expected: A\n", *myString);
688
 
    }
689
 
 
690
 
    u_sprintf(uStringBuf, NULL, "UChar %%K (non-ANSI, should be %%C for Microsoft?): %K", L'A');
691
 
    u_sscanf(uStringBuf, NULL, "UChar %%K (non-ANSI, should be %%C for Microsoft?): %K", myUString);
692
 
    if (*myUString != L'A') {
693
 
        log_err("%%C Got: %C, Expected: A\n", *myUString);
694
 
    }
695
 
 
696
 
    u_sprintf(uStringBuf, NULL, "String %%s: %s", "My-String");
697
 
    u_sscanf(uStringBuf, NULL, "String %%s: %s", myString);
698
 
    if (strcmp(myString, "My-String")) {
699
 
        log_err("%%s Got: %s, Expected: My-String\n", myString);
700
 
    }
701
 
    if (uStringBuf[20] != 0) {
702
 
        log_err("String not terminated. Got %c\n", uStringBuf[20] );
703
 
    }
704
 
    u_sprintf(uStringBuf, NULL, "NULL String %%s: %s", NULL);
705
 
    u_sscanf(uStringBuf, NULL, "NULL String %%s: %s", myString);
706
 
    if (strcmp(myString, "(null)")) {
707
 
        log_err("%%s Got: %s, Expected: My-String\n", myString);
708
 
    }
709
 
 
710
 
    u_sprintf(uStringBuf, NULL, "Unicode String %%U (non-ANSI, should be %%S for Microsoft?): %U", L"My-String");
711
 
    u_sscanf(uStringBuf, NULL, "Unicode String %%U (non-ANSI, should be %%S for Microsoft?): %U", myUString);
712
 
    u_austrncpy(myString, myUString, sizeof(myString)/sizeof(*myString));
713
 
    if (strcmp(myString, "My-String")) {
714
 
        log_err("%%U Got: %s, Expected: My String\n", myString);
715
 
    }
716
 
 
717
 
    u_sprintf(uStringBuf, NULL, "NULL Unicode String %%U (non-ANSI, should be %%S for Microsoft?): %U", NULL);
718
 
    u_sscanf(uStringBuf, NULL, "NULL Unicode String %%U (non-ANSI, should be %%S for Microsoft?): %U", myUString);
719
 
    u_austrncpy(myString, myUString, sizeof(myString)/sizeof(*myString));
720
 
    if (strcmp(myString, "(null)")) {
721
 
        log_err("%%U Got: %s, Expected: (null)\n", myString);
722
 
    }
723
 
 
724
 
    u_sprintf(uStringBuf, NULL, "Date %%D (non-ANSI): %D", myDate);
725
 
    myNewDate = -1.0;
726
 
    u_sscanf(uStringBuf, NULL, "Date %%D (non-ANSI): %D", &myNewDate);
727
 
    if (myNewDate != dec_31_1969) {
728
 
        log_err("%%D Got: %f, Expected: %f\n", myNewDate, dec_31_1969);
729
 
    }
730
 
 
731
 
    u_sprintf(uStringBuf, NULL, "Time %%T (non-ANSI): %T", myDate);
732
 
    myNewDate = -1.0;
733
 
    u_sscanf(uStringBuf, NULL, "Time %%T (non-ANSI): %T", &myNewDate);
734
 
    if (myNewDate != midnight) {
735
 
        log_err("%%T Got: %f, Expected: %f\n", myNewDate, midnight);
736
 
    }
737
 
 
738
 
    u_sprintf(uStringBuf, NULL, "Percent %%P (non-ANSI): %P", myFloat);
739
 
    *newDoubleValuePtr = -1.0;
740
 
    u_sscanf(uStringBuf, NULL, "Percent %%P (non-ANSI): %P", newDoubleValuePtr);
741
 
    if (myFloat != *newDoubleValuePtr) {
742
 
        log_err("%%P Got: %P, Expected: %P\n", *newDoubleValuePtr, myFloat);
743
 
    }
744
 
 
745
 
    u_sprintf(uStringBuf, NULL, "Currency %%M (non-ANSI): %M", myFloat);
746
 
    *newDoubleValuePtr = -1.0;
747
 
    u_sscanf(uStringBuf, NULL, "Currency %%M (non-ANSI): %M", newDoubleValuePtr);
748
 
    if (myFloat != *newDoubleValuePtr) {
749
 
        log_err("%%P Got: %P, Expected: %P\n", *newDoubleValuePtr, myFloat);
750
 
    }
751
 
 
752
 
    u_sprintf(uStringBuf, NULL, "Spell Out %%V (non-ANSI): %V", myFloat);
753
 
    *newDoubleValuePtr = -1.0;
754
 
    u_sscanf(uStringBuf, NULL, "Spell Out %%V (non-ANSI): %V", newDoubleValuePtr);
755
 
    if (myFloat != *newDoubleValuePtr) {
756
 
        log_err("%%V Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
757
 
    }
758
 
 
759
 
    *newValuePtr = 1;
760
 
    u_sprintf(uStringBuf, NULL, "\t\nPointer to integer (Count) %%n: n=%d %n n=%d\n", *newValuePtr, newValuePtr, *newValuePtr);
761
 
    if (*newValuePtr != 37) {
762
 
        log_err("%%V Got: %f, Expected: %f\n", *newDoubleValuePtr, myFloat);
763
 
    }
764
 
 
765
 
 
766
 
//  u_sscanf(uStringBuf, NULL, "Pointer %%p: %p\n", myFile);
767
 
}
768
 
 
769
 
#define Test_u_snprintf(limit, format, value, expectedSize, expectedStr) \
770
 
    u_uastrncpy(testStr, "xxxxxxxxxxxxxx", sizeof(testStr)/sizeof(testStr[0]));\
771
 
    size = u_snprintf(testStr, limit, "en_US_POSIX", format, value);\
772
 
    u_austrncpy(cTestResult, testStr, sizeof(cTestResult)/sizeof(cTestResult[0]));\
773
 
    if (size != expectedSize || strcmp(cTestResult, expectedStr) != 0) {\
774
 
        log_err("Unexpected formatting. size=%d expectedSize=%d cTestResult=%s expectedStr=%s\n",\
775
 
            size, expectedSize, cTestResult, expectedStr);\
776
 
    }\
777
 
    else {\
778
 
        log_verbose("Got: %s\n", cTestResult);\
779
 
    }\
780
 
 
781
 
 
782
 
static void TestSnprintf() {
783
 
    UChar testStr[256];
784
 
    char cTestResult[256];
785
 
    int32_t size;
786
 
 
787
 
    Test_u_snprintf(0, "%d", 123, 0, "xxxxxxxxxxxxxx");
788
 
    Test_u_snprintf(2, "%d", 123, 2, "12xxxxxxxxxxxx");
789
 
    Test_u_snprintf(3, "%d", 123, 3, "123xxxxxxxxxxx");
790
 
    Test_u_snprintf(4, "%d", 123, 3, "123");
791
 
 
792
 
    Test_u_snprintf(0, "%s", "abcd", 0, "xxxxxxxxxxxxxx");
793
 
    Test_u_snprintf(3, "%s", "abcd", 3, "abcxxxxxxxxxxx");
794
 
    Test_u_snprintf(4, "%s", "abcd", 4, "abcdxxxxxxxxxx");
795
 
    Test_u_snprintf(5, "%s", "abcd", 4, "abcd");
796
 
 
797
 
    Test_u_snprintf(0, "%e", 12.34, 0, "xxxxxxxxxxxxxx");
798
 
    Test_u_snprintf(1, "%e", 12.34, 1, "1xxxxxxxxxxxxx");
799
 
    Test_u_snprintf(2, "%e", 12.34, 2, "1.xxxxxxxxxxxx");
800
 
    Test_u_snprintf(3, "%e", 12.34, 3, "1.2xxxxxxxxxxx");
801
 
    Test_u_snprintf(5, "%e", 12.34, 5, "1.234xxxxxxxxx");
802
 
    Test_u_snprintf(6, "%e", 12.34, 6, "1.2340xxxxxxxx");
803
 
    Test_u_snprintf(8, "%e", 12.34, 8, "1.234000xxxxxx");
804
 
    Test_u_snprintf(9, "%e", 12.34, 9, "1.234000exxxxx");
805
 
    Test_u_snprintf(10, "%e", 12.34, 10, "1.234000e+xxxx");
806
 
    Test_u_snprintf(11, "%e", 12.34, 11, "1.234000e+0xxx");
807
 
    Test_u_snprintf(13, "%e", 12.34, 13, "1.234000e+001x");
808
 
    Test_u_snprintf(14, "%e", 12.34, 13, "1.234000e+001");
809
 
}
810
 
 
811
 
#define TestSPrintFormat(uFormat, uValue, cFormat, cValue) \
812
 
    /* Reinitialize the buffer to verify null termination works. */\
813
 
    u_memset(uBuffer, 0x2a, sizeof(uBuffer)/sizeof(*uBuffer));\
814
 
    memset(buffer, 0x2a, sizeof(buffer)/sizeof(*buffer));\
815
 
    \
816
 
    uNumPrinted = u_sprintf(uBuffer, "en_US_POSIX", uFormat, uValue);\
817
 
    u_austrncpy(compBuffer, uBuffer, sizeof(uBuffer)/sizeof(uBuffer[0]));\
818
 
    cNumPrinted = sprintf(buffer, cFormat, cValue);\
819
 
    if (strcmp(buffer, compBuffer) != 0) {\
820
 
        log_err("%" uFormat " Got: \"%s\", Expected: \"%s\"\n", compBuffer, buffer);\
821
 
    }\
822
 
    if (cNumPrinted != uNumPrinted) {\
823
 
        log_err("%" uFormat " number printed Got: %d, Expected: %d\n", uNumPrinted, cNumPrinted);\
824
 
    }\
825
 
 
826
 
 
827
 
static void TestSprintfFormat() {
828
 
    static const UChar abcUChars[] = {0x61,0x62,0x63,0};
829
 
    static const char abcChars[] = "abc";
830
 
    UChar uBuffer[256];
831
 
    char buffer[256];
832
 
    char compBuffer[256];
833
 
    int32_t uNumPrinted;
834
 
    int32_t cNumPrinted;
835
 
 
836
 
    TestSPrintFormat("%8U", abcUChars, "%8s", abcChars);
837
 
    TestSPrintFormat("%-8U", abcUChars, "%-8s", abcChars);
838
 
 
839
 
    TestSPrintFormat("%8s", abcChars, "%8s", abcChars);
840
 
    TestSPrintFormat("%-8s", abcChars, "%-8s", abcChars);
841
 
 
842
 
    TestSPrintFormat("%8c", 0x65, "%8c", 0x65);
843
 
    TestSPrintFormat("%-8c", 0x65, "%-8c", 0x65);
844
 
 
845
 
    TestSPrintFormat("%8K", (UChar)0x65, "%8c", (char)0x65);
846
 
    TestSPrintFormat("%-8K", (UChar)0x65, "%-8c", (char)0x65);
847
 
 
848
 
    TestSPrintFormat("%10f", 1.23456789, "%10f", 1.23456789);
849
 
    TestSPrintFormat("%-10f", 1.23456789, "%-10f", 1.23456789);
850
 
    TestSPrintFormat("%10f", 123.456789, "%10f", 123.456789);
851
 
    TestSPrintFormat("%-10f", 123.456789, "%-10f", 123.456789);
852
 
 
853
 
    TestSPrintFormat("%10e", 1.23456789, "%10e", 1.23456789);
854
 
    TestSPrintFormat("%-10e", 1.23456789, "%-10e", 1.23456789);
855
 
    TestSPrintFormat("%10e", 123.456789, "%10e", 123.456789);
856
 
    TestSPrintFormat("%-10e", 123.456789, "%-10e", 123.456789);
857
 
 
858
 
    TestSPrintFormat("%10g", 1.23456789, "%10g", 1.23456789);
859
 
    TestSPrintFormat("%-10g", 1.23456789, "%-10g", 1.23456789);
860
 
    TestSPrintFormat("%10g", 123.456789, "%10g", 123.456789);
861
 
    TestSPrintFormat("%-10g", 123.456789, "%-10g", 123.456789);
862
 
 
863
 
    TestSPrintFormat("%8x", 123456, "%8x", 123456);
864
 
    TestSPrintFormat("%-8x", 123456, "%-8x", 123456);
865
 
 
866
 
    TestSPrintFormat("%8X", 123456, "%8X", 123456);
867
 
    TestSPrintFormat("%-8X", 123456, "%-8X", 123456);
868
 
    TestSPrintFormat("%#x", 123456, "%#x", 123456);
869
 
    TestSPrintFormat("%#x", -123456, "%#x", -123456);
870
 
 
871
 
    TestSPrintFormat("%8o", 123456, "%8o", 123456);
872
 
    TestSPrintFormat("%-8o", 123456, "%-8o", 123456);
873
 
    TestSPrintFormat("%#o", 123, "%#o", 123);
874
 
    TestSPrintFormat("%#o", -123, "%#o", -123);
875
 
 
876
 
    TestSPrintFormat("%8u", 123456, "%8u", 123456);
877
 
    TestSPrintFormat("%-8u", 123456, "%-8u", 123456);
878
 
    TestSPrintFormat("%8u", -123456, "%8u", -123456);
879
 
    TestSPrintFormat("%-8u", -123456, "%-8u", -123456);
880
 
 
881
 
    TestSPrintFormat("%8d", 123456, "%8d", 123456);
882
 
    TestSPrintFormat("%-8d", 123456, "%-8d", 123456);
883
 
    TestSPrintFormat("% d", 123456, "% d", 123456);
884
 
    TestSPrintFormat("% d", -123456, "% d", -123456);
885
 
 
886
 
    TestSPrintFormat("%8i", 123456, "%8i", 123456);
887
 
    TestSPrintFormat("%-8i", 123456, "%-8i", 123456);
888
 
 
889
 
    log_verbose("Get really crazy with the formatting.\n");
890
 
 
891
 
    TestSPrintFormat("%-#12x", 123, "%-#12x", 123);
892
 
    TestSPrintFormat("%-#12x", -123, "%-#12x", -123);
893
 
    TestSPrintFormat("%#12x", 123, "%#12x", 123);
894
 
    TestSPrintFormat("%#12x", -123, "%#12x", -123);
895
 
 
896
 
    TestSPrintFormat("%-+12d", 123,  "%-+12d", 123);
897
 
    TestSPrintFormat("%-+12d", -123, "%-+12d", -123);
898
 
    TestSPrintFormat("%- 12d", 123,  "%- 12d", 123);
899
 
    TestSPrintFormat("%- 12d", -123, "%- 12d", -123);
900
 
    TestSPrintFormat("%+12d", 123,   "%+12d", 123);
901
 
    TestSPrintFormat("%+12d", -123,  "%+12d", -123);
902
 
    TestSPrintFormat("% 12d", 123,   "% 12d", 123);
903
 
    TestSPrintFormat("% 12d", -123,  "% 12d", -123);
904
 
    TestSPrintFormat("%12d", 123,    "%12d", 123);
905
 
    TestSPrintFormat("%12d", -123,   "%12d", -123);
906
 
 
907
 
    TestSPrintFormat("%-+12.1e", 1.234,  "%-+12.1e", 1.234);
908
 
    TestSPrintFormat("%-+12.1e", -1.234, "%-+12.1e", -1.234);
909
 
    TestSPrintFormat("%- 12.1e", 1.234,  "%- 12.1e", 1.234);
910
 
    TestSPrintFormat("%- 12.1e", -1.234, "%- 12.1e", -1.234);
911
 
    TestSPrintFormat("%+12.1e", 1.234,   "%+12.1e", 1.234);
912
 
    TestSPrintFormat("%+12.1e", -1.234,  "%+12.1e", -1.234);
913
 
    TestSPrintFormat("% 12.1e", 1.234,   "% 12.1e", 1.234);
914
 
    TestSPrintFormat("% 12.1e", -1.234,  "% 12.1e", -1.234);
915
 
    TestSPrintFormat("%12.1e", 1.234,    "%12.1e", 1.234);
916
 
    TestSPrintFormat("%12.1e", -1.234,   "%12.1e", -1.234);
917
 
    TestSPrintFormat("%.2e", 1.234,      "%.2e", 1.234);
918
 
    TestSPrintFormat("%.2e", -1.234,     "%.2e", -1.234);
919
 
    TestSPrintFormat("%3e", 1.234,       "%3e", 1.234);
920
 
    TestSPrintFormat("%3e", -1.234,      "%3e", -1.234);
921
 
 
922
 
    TestSPrintFormat("%-+12.1f", 1.234,  "%-+12.1f", 1.234);
923
 
    TestSPrintFormat("%-+12.1f", -1.234, "%-+12.1f", -1.234);
924
 
    TestSPrintFormat("%- 12.1f", 1.234,  "%- 12.1f", 1.234);
925
 
    TestSPrintFormat("%- 12.1f", -1.234, "%- 12.1f", -1.234);
926
 
    TestSPrintFormat("%+12.1f", 1.234,   "%+12.1f", 1.234);
927
 
    TestSPrintFormat("%+12.1f", -1.234,  "%+12.1f", -1.234);
928
 
    TestSPrintFormat("% 12.1f", 1.234,   "% 12.1f", 1.234);
929
 
    TestSPrintFormat("% 12.1f", -1.234,  "% 12.1f", -1.234);
930
 
    TestSPrintFormat("%12.1f", 1.234,    "%12.1f", 1.234);
931
 
    TestSPrintFormat("%12.1f", -1.234,   "%12.1f", -1.234);
932
 
    TestSPrintFormat("%.2f", 1.234,      "%.2f", 1.234);
933
 
    TestSPrintFormat("%.2f", -1.234,     "%.2f", -1.234);
934
 
    TestSPrintFormat("%3f", 1.234,       "%3f", 1.234);
935
 
    TestSPrintFormat("%3f", -1.234,      "%3f", -1.234);
936
 
}
937
 
 
938
 
#undef TestSPrintFormat
939
 
 
940
 
static void TestStringCompatibility() {
941
 
    UChar myUString[256];
942
 
    UChar uStringBuf[256];
943
 
    char myString[256] = "";
944
 
    char testBuf[256] = "";
945
 
    int32_t num;
946
 
 
947
 
    u_memset(myUString, 0x0a, sizeof(myUString)/ sizeof(*myUString));
948
 
    u_memset(uStringBuf, 0x0a, sizeof(uStringBuf) / sizeof(*uStringBuf));
949
 
 
950
 
    /* Compare against C API compatibility */
951
 
    for (num = -STANDARD_TEST_NUM_RANGE; num < STANDARD_TEST_NUM_RANGE; num++) {
952
 
        sprintf(testBuf, "%x", num);
953
 
        u_sprintf(uStringBuf, NULL, "%x", num);
954
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
955
 
        if (strcmp(myString, testBuf) != 0) {
956
 
            log_err("%%x Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
957
 
        }
958
 
 
959
 
        sprintf(testBuf, "%X", num);
960
 
        u_sprintf(uStringBuf, NULL, "%X", num);
961
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
962
 
        if (strcmp(myString, testBuf) != 0) {
963
 
            log_err("%%X Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
964
 
        }
965
 
 
966
 
        sprintf(testBuf, "%o", num);
967
 
        u_sprintf(uStringBuf, NULL, "%o", num);
968
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
969
 
        if (strcmp(myString, testBuf) != 0) {
970
 
            log_err("%%o Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
971
 
        }
972
 
 
973
 
        /* sprintf is not compatible on all platforms e.g. the iSeries*/
974
 
        sprintf(testBuf, "%d", num);
975
 
        u_sprintf(uStringBuf, "en_US_POSIX", "%d", num);
976
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
977
 
        if (strcmp(myString, testBuf) != 0) {
978
 
            log_err("%%d Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
979
 
        }
980
 
 
981
 
        sprintf(testBuf, "%i", num);
982
 
        u_sprintf(uStringBuf, "en_US_POSIX", "%i", num);
983
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
984
 
        if (strcmp(myString, testBuf) != 0) {
985
 
            log_err("%%i Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
986
 
        }
987
 
 
988
 
        sprintf(testBuf, "%f", (double)num);
989
 
        u_sprintf(uStringBuf, "en_US_POSIX", "%f", (double)num);
990
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
991
 
        if (strcmp(myString, testBuf) != 0) {
992
 
            log_err("%%f Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
993
 
        }
994
 
 
995
 
        sprintf(testBuf, "%e", (double)num);
996
 
        u_sprintf(uStringBuf, "en_US_POSIX", "%e", (double)num);
997
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
998
 
        if (strcmp(myString, testBuf) != 0) {
999
 
            log_err("%%e Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
1000
 
        }
1001
 
 
1002
 
        sprintf(testBuf, "%E", (double)num);
1003
 
        u_sprintf(uStringBuf, "en_US_POSIX", "%E", (double)num);
1004
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
1005
 
        if (strcmp(myString, testBuf) != 0) {
1006
 
            log_err("%%E Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
1007
 
        }
1008
 
 
1009
 
        sprintf(testBuf, "%g", (double)num);
1010
 
        u_sprintf(uStringBuf, "en_US_POSIX", "%g", (double)num);
1011
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
1012
 
        if (strcmp(myString, testBuf) != 0) {
1013
 
            log_err("%%g Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
1014
 
        }
1015
 
 
1016
 
        sprintf(testBuf, "%G", (double)num);
1017
 
        u_sprintf(uStringBuf, "en_US_POSIX", "%G", (double)num);
1018
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
1019
 
        if (strcmp(myString, testBuf) != 0) {
1020
 
            log_err("%%G Got: \"%s\", Expected: \"%s\"\n", myString, testBuf);
1021
 
        }
1022
 
    }
1023
 
 
1024
 
    for (num = 0; num < 0x80; num++) {
1025
 
        testBuf[0] = (char)0xFF;
1026
 
        uStringBuf[0] = (UChar)0xfffe;
1027
 
        sprintf(testBuf, "%c", num);
1028
 
        u_sprintf(uStringBuf, NULL, "%c", num);
1029
 
        u_austrncpy(myString, uStringBuf, sizeof(myString)/sizeof(myString[0]));
1030
 
        if (testBuf[0] != uStringBuf[0] || uStringBuf[0] != num) {
1031
 
            log_err("%%c Got: 0x%x, Expected: 0x%x\n", myString[0], testBuf[0]);
1032
 
        }
1033
 
    }
1034
 
}
1035
 
 
1036
 
static void TestStream() {
1037
 
#if U_IOSTREAM_SOURCE >= 198506
1038
 
    char testStreamBuf[512];
1039
 
    const char *testStr = "Beginning of test str1   <<432 1" C_NEW_LINE " UTF-8 \xCE\xBC\xF0\x90\x80\x81\xF0\x90\x80\x82";
1040
 
    ostrstream outTestStream(testStreamBuf, sizeof(testStreamBuf));
1041
 
    istrstream inTestStream(" tHis\xCE\xBC\xE2\x80\x82 mu world", 0);
1042
 
    const UChar thisMu[] = { 0x74, 0x48, 0x69, 0x73, 0x3BC, 0};
1043
 
    const UChar mu[] = { 0x6D, 0x75, 0};
1044
 
    UnicodeString str1 = UNICODE_STRING_SIMPLE("str1");
1045
 
    UnicodeString str2 = UNICODE_STRING_SIMPLE(" <<");
1046
 
    UnicodeString str3 = UNICODE_STRING_SIMPLE("4");
1047
 
    UnicodeString str4 = UNICODE_STRING_SIMPLE(" UTF-8 ");
1048
 
    UnicodeString inStr = UNICODE_STRING_SIMPLE(" UTF-8 ");
1049
 
    UnicodeString inStr2;
1050
 
    char defConvName[UCNV_MAX_CONVERTER_NAME_LENGTH*2];
1051
 
    char inStrC[128];
1052
 
    UErrorCode status = U_ZERO_ERROR;
1053
 
    UConverter *defConv;
1054
 
 
1055
 
    str4.append((UChar32)0x03BC);   /* mu */
1056
 
    str4.append((UChar32)0x10001);
1057
 
    str4.append((UChar32)0x10002);
1058
 
 
1059
 
    /* release the default converter and use utf-8 for a bit */
1060
 
    defConv = u_getDefaultConverter(&status);
1061
 
    if (U_FAILURE(status)) {
1062
 
        log_err("Can't get default converter");
1063
 
        return;
1064
 
    }
1065
 
    ucnv_close(defConv);
1066
 
    strncpy(defConvName, ucnv_getDefaultName(), sizeof(defConvName)/sizeof(defConvName[0]));
1067
 
    ucnv_setDefaultName("UTF-8");
1068
 
 
1069
 
    outTestStream << "Beginning of test ";
1070
 
    outTestStream << str1 << "  " << str2 << str3 << 3 << "2 " << 1.0 << C_NEW_LINE << str4 << ends;
1071
 
    if (strcmp(testStreamBuf, testStr) != 0) {
1072
 
        log_err("Got: \"%s\", Expected: \"%s\"\n", testStreamBuf, testStr);
1073
 
    }
1074
 
    
1075
 
    inTestStream >> inStr >> inStr2;
1076
 
    if (inStr.compare(thisMu) != 0) {
1077
 
        u_austrncpy(inStrC, inStr.getBuffer(), inStr.length());
1078
 
        inStrC[inStr.length()] = 0;
1079
 
        log_err("Got: \"%s\", Expected: \"tHis\\u03BC\"\n", inStrC);
1080
 
    }
1081
 
    if (inStr2.compare(mu) != 0) {
1082
 
        u_austrncpy(inStrC, inStr.getBuffer(), inStr.length());
1083
 
        inStrC[inStr.length()] = 0;
1084
 
        log_err("Got: \"%s\", Expected: \"mu\"\n", inStrC);
1085
 
    }
1086
 
 
1087
 
    /* return the default converter to the original state. */
1088
 
    ucnv_setDefaultName(defConvName);
1089
 
    defConv = u_getDefaultConverter(&status);
1090
 
    if (U_FAILURE(status)) {
1091
 
        log_err("Can't get default converter");
1092
 
        return;
1093
 
    }
1094
 
    ucnv_close(defConv);
1095
 
#else
1096
 
    log_err("U_IOSTREAM_SOURCE is disabled");
1097
 
#endif
1098
 
}
1099
 
 
1100
 
static void TestTranslitOps()
1101
 
{
1102
 
    UFILE *f;
1103
 
    UErrorCode err = U_ZERO_ERROR;
1104
 
    UTransliterator *a = NULL, *b = NULL, *c = NULL;
1105
 
    
1106
 
    log_verbose("opening a transliterator and UFILE for testing\n");
1107
 
    
1108
 
    f = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", NULL);
1109
 
    if(f == NULL)
1110
 
    {
1111
 
        log_err("Couldn't open test file for writing");
1112
 
        return;
1113
 
    }
1114
 
    
1115
 
    a = utrans_open("Latin-Greek", UTRANS_FORWARD, NULL, -1, NULL, &err);
1116
 
    if(U_FAILURE(err))
1117
 
    {
1118
 
        log_err("Err opening transliterator %s\n", u_errorName(err));
1119
 
        u_fclose(f);
1120
 
        return;
1121
 
    }
1122
 
    
1123
 
    
1124
 
    log_verbose("setting a transliterator\n");
1125
 
    b = u_fsettransliterator(f, U_WRITE, a, &err);
1126
 
    if(U_FAILURE(err)) 
1127
 
    {
1128
 
        log_err("Err setting transliterator %s\n", u_errorName(err));
1129
 
        u_fclose(f);
1130
 
        return;
1131
 
    }
1132
 
    
1133
 
    if(b != NULL)
1134
 
    {
1135
 
        log_err("Err, a transliterator was already set!\n");
1136
 
    }
1137
 
    
1138
 
    log_verbose("un-setting transliterator (setting to null)\n");
1139
 
    c = u_fsettransliterator(f, U_WRITE, NULL, &err);
1140
 
    if(U_FAILURE(err)) 
1141
 
    {
1142
 
        log_err("Err setting transliterator %s\n", u_errorName(err));
1143
 
        u_fclose(f);
1144
 
        return;
1145
 
    }
1146
 
    
1147
 
    if(c != a)
1148
 
    {
1149
 
        log_err("Err, transliterator that came back was not the original one.\n");
1150
 
    }
1151
 
    
1152
 
    log_verbose("Trying to set read transliterator (should fail)\n");
1153
 
    b = u_fsettransliterator(f, U_READ, NULL, &err);
1154
 
    if(err != U_UNSUPPORTED_ERROR)
1155
 
    {
1156
 
        log_err("Should have U_UNSUPPORTED_ERROR setting  Read transliterator but got %s - REVISIT AND UPDATE TEST\n", u_errorName(err));
1157
 
        u_fclose(f);
1158
 
        return;
1159
 
    }
1160
 
    else
1161
 
    {
1162
 
        log_verbose("Got %s error (expected) setting READ transliterator.\n", u_errorName(err));
1163
 
        err = U_ZERO_ERROR;
1164
 
    }
1165
 
    
1166
 
    
1167
 
    utrans_close(c);
1168
 
    u_fclose(f);
1169
 
}
1170
 
 
1171
 
static void TestTranslitOut()
1172
 
{
1173
 
    UFILE *f;
1174
 
    UErrorCode err = U_ZERO_ERROR;
1175
 
    UTransliterator *a = NULL, *b = NULL, *c = NULL;
1176
 
    FILE *infile;
1177
 
    UChar compare[] = { 0xfeff, 0x03a3, 0x03c4, 0x03b5, 0x03c6, 0x1f00, 0x03bd, 0x03bf, 0x03c2, 0x0000 };
1178
 
    UChar ubuf[256];
1179
 
    int len;
1180
 
    
1181
 
    log_verbose("opening a transliterator and UFILE for testing\n");
1182
 
    
1183
 
    f = u_fopen(STANDARD_TEST_FILE, "w", "en_US_POSIX", "utf-16");
1184
 
    if(f == NULL)
1185
 
    {
1186
 
        log_err("Couldn't open test file for writing");
1187
 
        return;
1188
 
    }
1189
 
    
1190
 
    a = utrans_open("Latin-Greek", UTRANS_FORWARD, NULL, -1, NULL, &err);
1191
 
    if(U_FAILURE(err))
1192
 
    {
1193
 
        log_err("Err opening transliterator %s\n", u_errorName(err));
1194
 
        u_fclose(f);
1195
 
        return;
1196
 
    }
1197
 
    
1198
 
    log_verbose("setting a transliterator\n");
1199
 
    b = u_fsettransliterator(f, U_WRITE, a, &err);
1200
 
    if(U_FAILURE(err)) 
1201
 
    {
1202
 
        log_err("Err setting transliterator %s\n", u_errorName(err));
1203
 
        u_fclose(f);
1204
 
        return;
1205
 
    }
1206
 
    
1207
 
    if(b != NULL)
1208
 
    {
1209
 
        log_err("Err, a transliterator was already set!\n");
1210
 
    }
1211
 
    
1212
 
    u_fprintf(f, "%KStephanos", 0xFEFF);
1213
 
    
1214
 
    u_fclose(f);
1215
 
    
1216
 
    log_verbose("Re reading test file to verify transliteration\n");
1217
 
    infile = fopen(STANDARD_TEST_FILE, "rb");
1218
 
    if(infile == NULL)
1219
 
    {
1220
 
        log_err("Couldn't reopen test file\n");
1221
 
        return;
1222
 
    }
1223
 
    
1224
 
    len=fread(ubuf, sizeof(UChar), u_strlen(compare), infile);
1225
 
    log_verbose("Read %d UChars\n", len);
1226
 
    if(len != u_strlen(compare))
1227
 
    {
1228
 
        log_err("Wanted %d UChars from file, got %d\n", u_strlen(compare), len);
1229
 
    }
1230
 
    ubuf[len]=0;
1231
 
    
1232
 
    if(u_strlen(compare) != u_strlen(ubuf))
1233
 
    {
1234
 
        log_err("Wanted %d UChars from file, but u_strlen() returns %d\n", u_strlen(compare), len);
1235
 
    }
1236
 
    
1237
 
    if(u_strcmp(compare, ubuf))
1238
 
    {
1239
 
        log_err("Read string doesn't match expected.\n");
1240
 
    }
1241
 
    else
1242
 
    {
1243
 
        log_verbose("Read string matches expected.\n");
1244
 
    }
1245
 
    
1246
 
    fclose(infile);
1247
 
    
1248
 
}
1249
 
 
1250
 
static void addAllTests(TestNode** root) {
1251
 
    addTest(root, &TestFile, "file/TestFile");
1252
 
    addTest(root, &TestCodepage, "file/TestCodepage");
1253
 
    addTest(root, &TestFprintfFormat, "file/TestFprintfFormat");
1254
 
    addTest(root, &TestFilePrintCompatibility, "file/TestFilePrintCompatibility");
1255
 
    addTest(root, &TestString, "string/TestString");
1256
 
    addTest(root, &TestSprintfFormat, "string/TestSprintfFormat");
1257
 
    addTest(root, &TestSnprintf, "string/TestSnprintf");
1258
 
    addTest(root, &TestStringCompatibility, "string/TestStringCompatibility");
1259
 
    addTest(root, &TestStream, "stream/TestStream");
1260
 
 
1261
 
    addTest(root, &TestTranslitOps, "translit/ops");
1262
 
    addTest(root, &TestTranslitOut, "translit/out");
1263
 
}
1264
 
 
1265
 
int main(int argc, char* argv[])
1266
 
{
1267
 
    int32_t nerrors = 0;
1268
 
    TestNode *root = NULL;
1269
 
 
1270
 
    addAllTests(&root);
1271
 
    nerrors = processArgs(root, argc, argv);
1272
 
 
1273
 
    cleanUpTestTree(root);
1274
 
    u_cleanup();
1275
 
    return nerrors;
1276
 
}