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

« back to all changes in this revision

Viewing changes to source/test/intltest/ucdtest.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
 
 * COPYRIGHT: 
3
 
 * Copyright (c) 1997-2001, International Business Machines Corporation and
4
 
 * others. All Rights Reserved.
5
 
 ********************************************************************/
6
 
 
7
 
#include "ucdtest.h"
8
 
#include "unicode/unicode.h"
9
 
#include "unicode/ustring.h"
10
 
#include "unicode/uchar.h"
11
 
#include "cstring.h"
12
 
#include "uparse.h"
13
 
 
14
 
UnicodeTest::UnicodeTest()
15
 
{
16
 
}
17
 
 
18
 
UnicodeTest::~UnicodeTest()
19
 
{
20
 
}
21
 
 
22
 
void UnicodeTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
23
 
{
24
 
    if (exec) logln("TestSuite UnicodeTest: ");
25
 
    switch (index) {
26
 
        case 0: name = "TestUpperLower"; if (exec) TestUpperLower(); break;
27
 
        case 1: name = "TestLetterNumber"; if (exec) TestLetterNumber(); break;
28
 
        case 2: name = "TestMisc"; if (exec) TestMisc(); break;
29
 
        case 3: name = "TestUnicodeData"; if (exec) TestUnicodeData(); break;
30
 
        case 4: name = "TestCodeUnit"; if(exec) TestCodeUnit(); break;
31
 
        case 5: name = "TestCodePoint"; if(exec) TestCodePoint(); break;
32
 
        case 6: name = "TestCharLength"; if(exec) TestCharLength(); break;
33
 
        case 7: name = "TestIdentifier"; if(exec) TestIdentifier(); break;  
34
 
        case 8: name = "TestScript"; if(exec) TestScript(); break;  
35
 
        default: name = ""; break; //needed to end loop
36
 
    }
37
 
}
38
 
 
39
 
//====================================================
40
 
// private data used by the tests
41
 
//====================================================
42
 
 
43
 
const UChar  LAST_CHAR_CODE_IN_FILE = 0xFFFD;
44
 
const char tagStrings[] = "MnMcMeNdNlNoZsZlZpCcCfCsCoCnLuLlLtLmLoPcPdPsPePoSmScSkSoPiPf";
45
 
const int32_t tagValues[] =
46
 
    {
47
 
    /* Mn */ Unicode::NON_SPACING_MARK,
48
 
    /* Mc */ Unicode::COMBINING_SPACING_MARK,
49
 
    /* Me */ Unicode::ENCLOSING_MARK,
50
 
    /* Nd */ Unicode::DECIMAL_DIGIT_NUMBER,
51
 
    /* Nl */ Unicode::LETTER_NUMBER,
52
 
    /* No */ Unicode::OTHER_NUMBER,
53
 
    /* Zs */ Unicode::SPACE_SEPARATOR,
54
 
    /* Zl */ Unicode::LINE_SEPARATOR,
55
 
    /* Zp */ Unicode::PARAGRAPH_SEPARATOR,
56
 
    /* Cc */ Unicode::CONTROL,
57
 
    /* Cf */ Unicode::FORMAT,
58
 
    /* Cs */ Unicode::SURROGATE,
59
 
    /* Co */ Unicode::PRIVATE_USE,
60
 
    /* Cn */ Unicode::UNASSIGNED,
61
 
    /* Lu */ Unicode::UPPERCASE_LETTER,
62
 
    /* Ll */ Unicode::LOWERCASE_LETTER,
63
 
    /* Lt */ Unicode::TITLECASE_LETTER,
64
 
    /* Lm */ Unicode::MODIFIER_LETTER,
65
 
    /* Lo */ Unicode::OTHER_LETTER,
66
 
    /* Pc */ Unicode::CONNECTOR_PUNCTUATION,
67
 
    /* Pd */ Unicode::DASH_PUNCTUATION,
68
 
    /* Ps */ Unicode::START_PUNCTUATION,
69
 
    /* Pe */ Unicode::END_PUNCTUATION,
70
 
    /* Po */ Unicode::OTHER_PUNCTUATION,
71
 
    /* Sm */ Unicode::MATH_SYMBOL,
72
 
    /* Sc */ Unicode::CURRENCY_SYMBOL,
73
 
    /* Sk */ Unicode::MODIFIER_SYMBOL,
74
 
    /* So */ Unicode::OTHER_SYMBOL,
75
 
    /* Pi */ Unicode::INITIAL_PUNCTUATION,
76
 
    /* Pf */ Unicode::FINAL_PUNCTUATION
77
 
    };
78
 
const char dirStrings[][5] = {
79
 
    "L",
80
 
    "R",
81
 
    "EN",
82
 
    "ES",
83
 
    "ET",
84
 
    "AN",
85
 
    "CS",
86
 
    "B",
87
 
    "S",
88
 
    "WS",
89
 
    "ON",
90
 
    "LRE",
91
 
    "LRO",
92
 
    "AL",
93
 
    "RLE",
94
 
    "RLO",
95
 
    "PDF",
96
 
    "NSM",
97
 
    "BN"
98
 
};
99
 
 
100
 
//====================================================
101
 
// test toUpperCase() and toLowerCase()
102
 
//====================================================
103
 
void UnicodeTest::TestUpperLower()
104
 
{
105
 
    U_STRING_DECL(upperTest, "abcdefg123hij.?:klmno", 21);
106
 
    U_STRING_DECL(lowerTest, "ABCDEFG123HIJ.?:KLMNO", 21);
107
 
    uint16_t i;
108
 
 
109
 
    U_STRING_INIT(upperTest, "abcdefg123hij.?:klmno", 21);
110
 
    U_STRING_INIT(lowerTest, "ABCDEFG123HIJ.?:KLMNO", 21);
111
 
 
112
 
//Checks LetterLike Symbols which were previously a source of confusion
113
 
//[Bertrand A. D. 02/04/98]
114
 
    for (i=0x2100;i<0x2138;i++)
115
 
    {
116
 
        if(i!=0x2126 && i!=0x212a && i!=0x212b)
117
 
        {
118
 
            if (i != Unicode::toLowerCase(i)) // itself
119
 
                errln("Failed case conversion with itself: " + UCharToUnicodeString(i));
120
 
            if (i != Unicode::toUpperCase(i))
121
 
                errln("Failed case conversion with itself: " + UCharToUnicodeString(i));
122
 
        }
123
 
    }
124
 
 
125
 
    for (i = 0; i < 21; i++) {
126
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
127
 
        if (Unicode::isLetter(upperTest[i]) && !Unicode::isLowerCase(upperTest[i]))
128
 
            errln("Failed isLowerCase test at " + UCharToUnicodeString(upperTest[i]));
129
 
        else if (Unicode::isLetter(lowerTest[i]) && !Unicode::isUpperCase(lowerTest[i]))
130
 
            errln("Failed isUpperCase test at " + UCharToUnicodeString(lowerTest[i]));
131
 
        else if (upperTest[i] != Unicode::toLowerCase(lowerTest[i]))
132
 
            errln("Failed case conversion : " + UCharToUnicodeString(upperTest[i]) + 
133
 
            " to " + UCharToUnicodeString(lowerTest[i]));
134
 
        else if (lowerTest[i] != Unicode::toUpperCase(upperTest[i]))
135
 
            errln("Failed case conversion : " + UCharToUnicodeString(upperTest[i]) +
136
 
            " to " + UCharToUnicodeString(lowerTest[i]));
137
 
        else if (upperTest[i] != Unicode::toLowerCase(upperTest[i])) // itself
138
 
            errln("Failed case conversion with itself: " + UCharToUnicodeString(upperTest[i]));
139
 
        else if (lowerTest[i] != Unicode::toUpperCase(lowerTest[i]))
140
 
            errln("Failed case conversion with itself: " + UCharToUnicodeString(lowerTest[i]));
141
 
    }
142
 
}
143
 
 
144
 
/* test isLetter() and isDigit() */
145
 
void UnicodeTest::TestLetterNumber()
146
 
{
147
 
    UChar i;
148
 
 
149
 
    for (i = 0x0041; i < 0x005B; i++) {
150
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
151
 
        if (!Unicode::isLetter(i))
152
 
            errln("Failed isLetter test at " + UCharToUnicodeString(i));
153
 
    }
154
 
    for (i = 0x0660; i < 0x066A; i++) {
155
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
156
 
        if (Unicode::isLetter(i))
157
 
            errln("Failed isLetter test with numbers at " + i);
158
 
    }
159
 
    for (i = 0x0660; i < 0x066A; i++) {
160
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
161
 
        if (!Unicode::isDigit(i))
162
 
            errln("Failed isNumber test at " + i);
163
 
    }
164
 
}
165
 
 
166
 
/* Tests for isDefined(), isBaseForm(), isSpaceChar() and getCellWidth() */
167
 
void UnicodeTest::TestMisc()
168
 
{
169
 
    const UChar sampleSpaces[] = {0x0020, 0x00a0, 0x2000, 0x2001, 0x2005};
170
 
    const UChar sampleNonSpaces[] = {0x61, 0x62, 0x63, 0x64, 0x74};
171
 
    const UChar sampleWhiteSpaces[] = {0x2008, 0x2009, 0x200a, 0x001c, 0x000c};
172
 
    const UChar sampleNonWhiteSpaces[] = {0x61, 0x62, 0x3c, 0x28, 0x3f};
173
 
    const UChar sampleUndefined[] = {0xfff1, 0xfff7, 0xfa30};
174
 
    const UChar sampleDefined[] = {0x523E, 0x4f88, 0xfffd};
175
 
    const UChar sampleBase[] = {0x0061, 0x0031, 0x03d2};
176
 
    const UChar sampleNonBase[] = {0x002B, 0x0020, 0x203B};
177
 
    const UChar sampleChars[] = {0x000a, 0x0045, 0x4e00, 0xDC00};
178
 
    const UChar sampleDigits[]= {0x0030, 0x0662, 0x0F23, 0x0ED5};
179
 
    const UChar sampleNonDigits[] = {0x0010, 0x0041, 0x0122, 0x68FE};
180
 
    const int32_t sampleDigitValues[] = {0, 2, 3, 5};
181
 
    const uint16_t sampleCellWidth[] = {Unicode::ZERO_WIDTH, 
182
 
                                        Unicode::HALF_WIDTH, 
183
 
                                        Unicode::FULL_WIDTH, 
184
 
                                        Unicode::NEUTRAL};
185
 
    int32_t i;
186
 
    for (i = 0; i < 5; i++) {
187
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
188
 
        if (!(Unicode::isSpaceChar(sampleSpaces[i])) ||
189
 
                (Unicode::isSpaceChar(sampleNonSpaces[i])))
190
 
            errln((UnicodeString)"Space char test error : " + (int32_t)sampleSpaces[i] +
191
 
            " or " + (int32_t)sampleNonSpaces[i]);
192
 
    }
193
 
    for (i = 0; i < 5; i++) {
194
 
//      log_ln("Testing for isWhitespace and nonWhitespaces\n");
195
 
        if (!(Unicode::isWhitespace(sampleWhiteSpaces[i])) ||
196
 
                (Unicode::isWhitespace(sampleNonWhiteSpaces[i])))
197
 
        {
198
 
            errln((UnicodeString)"White Space char test error : " + (int32_t)sampleWhiteSpaces[i] +
199
 
                "or" + (int32_t)sampleNonWhiteSpaces[i]);
200
 
        }
201
 
    }
202
 
    for (i = 0; i < 3; i++) {
203
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
204
 
        if ((Unicode::isDefined(sampleUndefined[i])) ||
205
 
                !(Unicode::isDefined(sampleDefined[i])))
206
 
            errln((UnicodeString)"Undefined char test error : " +
207
 
            (int32_t)sampleUndefined[i] + " or " + (int32_t)sampleDefined[i]);
208
 
    }
209
 
    for (i = 0; i < 3; i++) {
210
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
211
 
        if ((Unicode::isBaseForm(sampleNonBase[i])) ||
212
 
                !(Unicode::isBaseForm(sampleBase[i])))
213
 
            errln((UnicodeString)"Non-baseform char test error : " +
214
 
            (int32_t)sampleNonBase[i] + " or " + (int32_t)sampleBase[i]);
215
 
    }
216
 
    for (i = 0; i < 4; i++) {
217
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
218
 
        if (Unicode::getCellWidth(sampleChars[i]) != sampleCellWidth[i])
219
 
            errln((UnicodeString)"Cell width char test error : " +
220
 
            (int32_t)sampleChars[i]);
221
 
    }
222
 
    for (i = 0; i < 4; i++) {
223
 
        if ((Unicode::isDigit(sampleDigits[i]) && 
224
 
            (Unicode::digitValue(sampleDigits[i])!= sampleDigitValues[i])) ||
225
 
            (Unicode::isDigit(sampleNonDigits[i]))) {
226
 
            errln((UnicodeString)"Digit char test error : " +
227
 
            (int32_t)sampleDigits[i] + " or " + (int32_t)sampleNonDigits[i]);
228
 
        }
229
 
    }
230
 
}
231
 
 
232
 
/* Tests for isControl() and isPrintable() */
233
 
void UnicodeTest::TestControlPrint()
234
 
{
235
 
    const UChar sampleControl[] = {0x001b, 0x0097, 0x0082};
236
 
    const UChar sampleNonControl[] = {0x61, 0x0031, 0x00e2};
237
 
    const UChar samplePrintable[] = {0x0042, 0x005f, 0x2014};
238
 
    const UChar sampleNonPrintable[] = {0x200c, 0x009f, 0x001b};
239
 
    int32_t i;
240
 
    for (i = 0; i < 3; i++) {
241
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
242
 
        if (!(Unicode::isControl(sampleControl[i])) ||
243
 
                (Unicode::isControl(sampleNonControl[i])))
244
 
            errln((UnicodeString)"Control char test error : " + (int32_t)sampleControl[i] +
245
 
            " or " + (int32_t)sampleNonControl[i]);
246
 
    }
247
 
    for (i = 0; i < 3; i++) {
248
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
249
 
        if ((Unicode::isPrintable(samplePrintable[i])) ||
250
 
                !(Unicode::isPrintable(samplePrintable[i])))
251
 
            errln((UnicodeString)"Printable char test error : " +
252
 
            (int32_t)samplePrintable[i] + " or " + (int32_t)sampleNonPrintable[i]);
253
 
    }
254
 
}
255
 
 
256
 
/* Tests for isJavaIdentifierStart(), isJavaIdentifierPart(),
257
 
 * isUnicodeIdentifierStart() and isUnicodeIdentifierPart() */
258
 
void UnicodeTest::TestIdentifier()
259
 
{
260
 
    const UChar sampleJavaIDStart[] = {0x0071, 0x00e4, 0x005f};
261
 
    const UChar sampleNonJavaIDStart[] = {0x0020, 0x2030, 0x0082};
262
 
    const UChar sampleUnicodeIDStart[] = {0x0250, 0x00e2, 0x0061};
263
 
    const UChar sampleNonUnicodeIDStart[] = {0x2000, 0x000a, 0x2019};
264
 
    const UChar sampleJavaIDPart[] = {0x005f, 0x0032, 0x0045};
265
 
    const UChar sampleNonJavaIDPart[] = {0x2030, 0x2020, 0x0020};
266
 
    const UChar sampleUnicodeIDPart[] = {0x005f, 0x0032, 0x0045};
267
 
    const UChar sampleNonUnicodeIDPart[] = {0x2030, 0x00a3, 0x0020};
268
 
    const UChar sampleIDIgnore[] = {0x0006, 0x0010, 0x206b};
269
 
    const UChar sampleNonIDIgnore[] = {0x0075, 0x00a3, 0x0061};
270
 
 
271
 
    int32_t i;
272
 
    for (i = 0; i < 3; i++) {
273
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
274
 
        if (!(Unicode::isJavaIdentifierStart(sampleJavaIDStart[i])) ||
275
 
                (Unicode::isJavaIdentifierStart(sampleNonJavaIDStart[i])))
276
 
            errln((UnicodeString)"Java ID Start char test error : " + (int32_t)sampleJavaIDStart[i] +
277
 
            " or " + (int32_t)sampleNonJavaIDStart[i]);
278
 
    }
279
 
    for (i = 0; i < 3; i++) {
280
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
281
 
        if (!(Unicode::isJavaIdentifierPart(sampleJavaIDPart[i])) ||
282
 
                (Unicode::isJavaIdentifierPart(sampleNonJavaIDPart[i])))
283
 
            errln((UnicodeString)"Java ID Part char test error : " + (int32_t)sampleJavaIDPart[i] +
284
 
            " or " + (int32_t)sampleNonJavaIDPart[i]);
285
 
    }
286
 
    for (i = 0; i < 3; i++) {
287
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
288
 
        if (!(Unicode::isUnicodeIdentifierStart(sampleUnicodeIDStart[i])) ||
289
 
                (Unicode::isUnicodeIdentifierStart(sampleNonUnicodeIDStart[i])))
290
 
            errln((UnicodeString)"Unicode ID Start char test error : " + (int32_t)sampleUnicodeIDStart[i] +
291
 
            " or " + (int32_t)sampleNonUnicodeIDStart[i]);
292
 
    }
293
 
    for (i = 0; i < 3; i++) {
294
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
295
 
        if (!(Unicode::isUnicodeIdentifierPart(sampleUnicodeIDPart[i])) ||
296
 
                (Unicode::isUnicodeIdentifierPart(sampleNonUnicodeIDPart[i])))
297
 
            errln((UnicodeString)"Unicode ID Part char test error : " + (int32_t)sampleUnicodeIDPart[i] +
298
 
            " or " + (int32_t)sampleNonUnicodeIDPart[i]);
299
 
    }
300
 
    for (i = 0; i < 3; i++) {
301
 
//      logln((UnicodeString)"testing " + (int32_t)i + "...");
302
 
        if (!(Unicode::isIdentifierIgnorable(sampleIDIgnore[i])) ||
303
 
                (Unicode::isIdentifierIgnorable(sampleNonIDIgnore[i])))
304
 
            errln((UnicodeString)"ID ignorable char test error : " + (int32_t)sampleIDIgnore[i] +
305
 
            " or " + (int32_t)sampleNonIDIgnore[i]);
306
 
    }
307
 
}
308
 
 
309
 
/* for each line of UnicodeData.txt, check some of the properties */
310
 
U_CAPI void U_CALLCONV
311
 
unicodeDataLineFn(void *context,
312
 
                  char *fields[][2], int32_t fieldCount,
313
 
                  UErrorCode *pErrorCode)
314
 
{
315
 
    char *end;
316
 
    uint32_t value;
317
 
    UChar32 c;
318
 
    int8_t type;
319
 
    UnicodeTest *me=(UnicodeTest *)context;
320
 
 
321
 
    if(U_FAILURE(*pErrorCode)) {
322
 
        me->errln("error: unicodeDataLineFn called with pErrorCode=%d\n", pErrorCode);
323
 
        return;
324
 
    }
325
 
 
326
 
    if(fieldCount != 15) {
327
 
        me->errln("error in UnicodeData.txt: The data format changed. fieldCount=%lu and it should be 15\n", fieldCount);
328
 
        *pErrorCode = U_PARSE_ERROR;
329
 
        return;
330
 
    }
331
 
 
332
 
    /* get the character code, field 0 */
333
 
    c=(UChar32)uprv_strtoul(fields[0][0], &end, 16);
334
 
    if(end<=fields[0][0] || end!=fields[0][1]) {
335
 
        me->errln("error: syntax error in field 0 at %s\n" + UnicodeString(fields[0][0], ""));
336
 
        *pErrorCode = U_PARSE_ERROR;
337
 
        return;
338
 
    }
339
 
    if((uint32_t)c>=0x110000) {
340
 
        me->errln("error in UnicodeData.txt: code point %lu out of range\n", c);
341
 
        *pErrorCode = U_PARSE_ERROR;
342
 
        return;
343
 
    }
344
 
 
345
 
    /* get general category, field 2 */
346
 
    *fields[2][1]=0;
347
 
    type = (int8_t)tagValues[me->MakeProp(fields[2][0])];
348
 
    if(Unicode::getType(c)!=type) {
349
 
        me->errln("error: Unicode::getType(U+%04lx)==%u instead of %u\n", c, Unicode::getType(c), type);
350
 
        *pErrorCode = U_PARSE_ERROR;
351
 
        return;
352
 
    }
353
 
 
354
 
    /* get canonical combining class, field 3 */
355
 
    value=(uint32_t)uprv_strtoul(fields[3][0], &end, 10);
356
 
    if(end<=fields[3][0] || end!=fields[3][1]) {
357
 
        me->errln("error: syntax error in field 3 at code 0x%lx\n", c);
358
 
        *pErrorCode = U_PARSE_ERROR;
359
 
        return;
360
 
    }
361
 
    if(value>255) {
362
 
        me->errln("error in UnicodeData.txt: combining class %lu out of range\n", value);
363
 
        *pErrorCode = U_PARSE_ERROR;
364
 
        return;
365
 
    }
366
 
    if(value!=Unicode::getCombiningClass(c)) {
367
 
        me->errln("error: Unicode::getCombiningClass(U+%04lx)==%hu instead of %lu\n", c, Unicode::getCombiningClass(c), value);
368
 
        *pErrorCode = U_PARSE_ERROR;
369
 
        return;
370
 
    }
371
 
 
372
 
    /* get BiDi category, field 4 */
373
 
    *fields[4][1]=0;
374
 
    if(Unicode::characterDirection(c)!=me->MakeDir(fields[4][0])) {
375
 
        me->errln("error: Unicode::characterDirection(U+%04lx)==%u instead of %u (%s)\n", c, Unicode::characterDirection(c), me->MakeDir(fields[4][0]), fields[4][0]);
376
 
        *pErrorCode = U_PARSE_ERROR;
377
 
        return;
378
 
    }
379
 
 
380
 
    /* get uppercase mapping, field 12 */
381
 
    if(fields[12][0]!=fields[12][1]) {
382
 
        value=(uint32_t)uprv_strtoul(fields[12][0], &end, 16);
383
 
        if(end!=fields[12][1]) {
384
 
            me->errln("error: syntax error in field 12 at code 0x%lx\n", c);
385
 
            *pErrorCode = U_PARSE_ERROR;
386
 
            return;
387
 
        }
388
 
        if((UChar32)value!=Unicode::toUpperCase(c)) {
389
 
            me->errln("error: Unicode::toUpperCase(U+%04lx)==U+%04lx instead of U+%04lx\n", c, Unicode::toUpperCase(c), value);
390
 
            *pErrorCode = U_PARSE_ERROR;
391
 
            return;
392
 
        }
393
 
    } else {
394
 
        /* no case mapping: the API must map the code point to itself */
395
 
        if(c!=Unicode::toUpperCase(c)) {
396
 
            me->errln("error: U+%04lx does not have an uppercase mapping but Unicode::toUpperCase()==U+%04lx\n", c, Unicode::toUpperCase(c));
397
 
            *pErrorCode = U_PARSE_ERROR;
398
 
            return;
399
 
        }
400
 
    }
401
 
 
402
 
    /* get lowercase mapping, field 13 */
403
 
    if(fields[13][0]!=fields[13][1]) {
404
 
        value=(uint32_t)uprv_strtoul(fields[13][0], &end, 16);
405
 
        if(end!=fields[13][1]) {
406
 
            me->errln("error: syntax error in field 13 at code 0x%lx\n", c);
407
 
            *pErrorCode = U_PARSE_ERROR;
408
 
            return;
409
 
        }
410
 
        if((UChar32)value!=Unicode::toLowerCase(c)) {
411
 
            me->errln("error: Unicode::toLowerCase(U+%04lx)==U+%04lx instead of U+%04lx\n", c, Unicode::toLowerCase(c), value);
412
 
            *pErrorCode = U_PARSE_ERROR;
413
 
            return;
414
 
        }
415
 
    } else {
416
 
        /* no case mapping: the API must map the code point to itself */
417
 
        if(c!=Unicode::toLowerCase(c)) {
418
 
            me->errln("error: U+%04lx does not have a lowercase mapping but Unicode::toLowerCase()==U+%04lx\n", c, Unicode::toLowerCase(c));
419
 
            *pErrorCode = U_PARSE_ERROR;
420
 
            return;
421
 
        }
422
 
    }
423
 
 
424
 
    /* get titlecase mapping, field 14 */
425
 
    if(fields[14][0]!=fields[14][1]) {
426
 
        value=(uint32_t)uprv_strtoul(fields[14][0], &end, 16);
427
 
        if(end!=fields[14][1]) {
428
 
            me->errln("error: syntax error in field 14 at code 0x%lx\n", c);
429
 
            *pErrorCode = U_PARSE_ERROR;
430
 
            return;
431
 
        }
432
 
        if((UChar32)value!=Unicode::toTitleCase(c)) {
433
 
            me->errln("error: Unicode::toTitleCase(U+%04lx)==U+%04lx instead of U+%04lx\n", c, Unicode::toTitleCase(c), value);
434
 
            *pErrorCode = U_PARSE_ERROR;
435
 
            return;
436
 
        }
437
 
    } else {
438
 
        /* no case mapping: the API must map the code point to itself */
439
 
        if(c!=Unicode::toTitleCase(c)) {
440
 
            me->errln("error: U+%04lx does not have a titlecase mapping but Unicode::toTitleCase()==U+%04lx\n", c, Unicode::toTitleCase(c));
441
 
            *pErrorCode = U_PARSE_ERROR;
442
 
            return;
443
 
        }
444
 
    }
445
 
}
446
 
 
447
 
/* tests for several properties */
448
 
void UnicodeTest::TestUnicodeData()
449
 
{
450
 
    char newPath[256];
451
 
    char backupPath[256];
452
 
    char *fields[15][2];
453
 
    UErrorCode errorCode = U_ZERO_ERROR;
454
 
 
455
 
    /* Look inside ICU_DATA first */
456
 
    strcpy(newPath, u_getDataDirectory());
457
 
    strcat(newPath, "unidata" U_FILE_SEP_STRING "UnicodeData.txt");
458
 
 
459
 
 
460
 
    // As a fallback, try to guess where the source data was located
461
 
    //   at the time ICU was built, and look there.
462
 
#   if defined (U_TOPSRCDIR)
463
 
        strcpy(backupPath, U_TOPSRCDIR  U_FILE_SEP_STRING "data");
464
 
#   else
465
 
        strcpy(backupPath, u_getDataDirectory());
466
 
        strcat(backupPath, ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data");
467
 
#   endif
468
 
    strcat(backupPath, U_FILE_SEP_STRING);
469
 
    strcat(backupPath, "unidata" U_FILE_SEP_STRING "UnicodeData.txt");
470
 
 
471
 
    u_parseDelimitedFile(newPath, ';', fields, 15, unicodeDataLineFn, this, &errorCode);
472
 
 
473
 
    if(errorCode==U_FILE_ACCESS_ERROR) {
474
 
        errorCode=U_ZERO_ERROR;
475
 
        u_parseDelimitedFile(backupPath, ';', fields, 15, unicodeDataLineFn, this, &errorCode);
476
 
 
477
 
    }
478
 
    if(U_FAILURE(errorCode)) {
479
 
        errln("error parsing UnicodeData.txt: %s\n" + UnicodeString(u_errorName(errorCode), ""));
480
 
        return;
481
 
    }
482
 
 
483
 
    // test Unicode::getCharName()
484
 
    // a more thorough test of u_charName() is in cintltst/cucdtst.c
485
 
    char buffer[100];
486
 
    int32_t length=Unicode::getCharName(0x284, buffer, (int32_t)sizeof(buffer));
487
 
 
488
 
    // use invariant-character conversion to Unicode
489
 
    UnicodeString name(buffer, length, "");
490
 
    if(name!=UNICODE_STRING("LATIN SMALL LETTER DOTLESS J WITH STROKE AND HOOK", 49)) {
491
 
        errln("Unicode character name lookup failed\n");
492
 
    }
493
 
 
494
 
    // test Unicode::isMirrored() and charMirror()
495
 
    // see also cintltst/cucdtest.c
496
 
    if(!(Unicode::isMirrored(0x28) && Unicode::isMirrored(0xbb) && Unicode::isMirrored(0x2045) && Unicode::isMirrored(0x232a) &&
497
 
         !Unicode::isMirrored(0x27) && !Unicode::isMirrored(0x61) && !Unicode::isMirrored(0x284) && !Unicode::isMirrored(0x3400)
498
 
        )
499
 
    ) {
500
 
        errln("Unicode::isMirrored() does not work correctly\n");
501
 
    }
502
 
 
503
 
    if(!(Unicode::charMirror(0x3c)==0x3e && Unicode::charMirror(0x5d)==0x5b && Unicode::charMirror(0x208d)==0x208e && Unicode::charMirror(0x3017)==0x3016 &&
504
 
         Unicode::charMirror(0x2e)==0x2e && Unicode::charMirror(0x6f3)==0x6f3 && Unicode::charMirror(0x301c)==0x301c && Unicode::charMirror(0xa4ab)==0xa4ab
505
 
        )
506
 
    ) {
507
 
        errln("Unicode::charMirror() does not work correctly\n");
508
 
    }
509
 
}
510
 
 
511
 
int32_t UnicodeTest::MakeProp(char* str) 
512
 
{
513
 
    int32_t result = 0;
514
 
    const char* matchPosition;
515
 
    
516
 
    matchPosition = strstr(tagStrings, str);
517
 
    if (matchPosition == 0) errln((UnicodeString)"unrecognized type letter " + str);
518
 
    else result = ((matchPosition - tagStrings) / 2);
519
 
    return result;
520
 
}
521
 
 
522
 
int32_t UnicodeTest::MakeDir(char* str) 
523
 
{
524
 
    int32_t pos = 0;
525
 
    for (pos = 0; pos < 19; pos++) {
526
 
        if (strcmp(str, dirStrings[pos]) == 0) {
527
 
            return pos;
528
 
        }
529
 
    }
530
 
    return -1;
531
 
}
532
 
/*Tests added by Madhu*/
533
 
 
534
 
/* Tests for isSingle(), isLead(), isTrial(), isSurrogate */
535
 
void UnicodeTest::TestCodeUnit(){
536
 
    const UChar codeunit[]={0x0000,0xe065,0x20ac,0xd7ff,0xd800,0xd841,0xd905,0xdbff,0xdc00,0xdc02,0xddee,0xdfff,0};
537
 
 
538
 
    int32_t i;
539
 
 
540
 
    for(i=0; i<(int32_t)(sizeof(codeunit)/sizeof(codeunit[0])); i++){
541
 
        UChar c=codeunit[i];
542
 
        UnicodeString msg;
543
 
        msg.append((UChar32)c);
544
 
        logln((UnicodeString)"Testing code unit value of " + prettify(msg));
545
 
        if(i<4){
546
 
            if(!(Unicode::isSingle(c)) || (Unicode::isLead(c)) || (Unicode::isTrail(c)) ||(Unicode::isSurrogate(c))){
547
 
                errln((UnicodeString)"ERROR:" + prettify(msg) + " is a single");
548
 
            }
549
 
 
550
 
        }
551
 
        if(i >= 4 && i< 8){
552
 
            if(!(Unicode::isLead(c)) || Unicode::isSingle(c) || Unicode::isTrail(c) || !(Unicode::isSurrogate(c))){
553
 
                errln((UnicodeString)"ERROR:" + prettify(msg) + " is a first surrogate");
554
 
            }
555
 
        }
556
 
        if(i >= 8 && i< 12){
557
 
            if(!(Unicode::isTrail(c)) || Unicode::isSingle(c) || Unicode::isLead(c) || !(Unicode::isSurrogate(c))){
558
 
                errln((UnicodeString)"ERROR:" + prettify(msg) + " is a second surrogate");
559
 
            }
560
 
        }
561
 
    }
562
 
 
563
 
}
564
 
/* Tests for isSurrogate(), isUnicodeChar(), isError(), isValid() */
565
 
void UnicodeTest::TestCodePoint(){
566
 
    const UChar32 codePoint[]={
567
 
        //surrogate, notvalid(codepoint), not a UnicodeChar, not Error
568
 
        0xd800,
569
 
        0xdbff,
570
 
        0xdc00,
571
 
        0xdfff,
572
 
        0xdc04,
573
 
        0xd821,
574
 
        //not a surrogate, valid, isUnicodeChar , not Error
575
 
        0x20ac,
576
 
        0xd7ff,
577
 
        0xe000,
578
 
        0xe123,
579
 
        0x0061,
580
 
        0xe065, 
581
 
        0x20402,
582
 
        0x24506,
583
 
        0x23456,
584
 
        0x20402,
585
 
        0x10402,
586
 
        0x23456,
587
 
        //not a surrogate, not valid, isUnicodeChar, isError
588
 
        0x0015,
589
 
        0x009f,
590
 
        //not a surrogate, not valid, not isUnicodeChar, isError
591
 
        0xffff,
592
 
        0xfffe,
593
 
    };
594
 
    int32_t i;
595
 
    for(i=0; i<(int32_t)(sizeof(codePoint)/sizeof(codePoint[0])); i++){
596
 
        UChar32 c=codePoint[i];
597
 
        UnicodeString msg;
598
 
        msg.append(c);
599
 
        logln((UnicodeString)"Testing code Point value of " + prettify(msg));
600
 
        if(i<6){
601
 
            if(!Unicode::isSurrogate(c)){
602
 
                errln((UnicodeString)"ERROR: isSurrogate() failed for" + prettify(msg));
603
 
            }
604
 
            if(Unicode::isValid(c)){
605
 
                errln((UnicodeString)"ERROR: isValid() failed for "+ prettify(msg));
606
 
            }
607
 
            if(Unicode::isUnicodeChar(c)){
608
 
                errln((UnicodeString)"ERROR: isUnicodeChar() failed for "+ prettify(msg));
609
 
            }
610
 
            if(Unicode::isError(c)){
611
 
                errln((UnicodeString)"ERROR: isError() failed for "+ prettify(msg));
612
 
            }
613
 
        }else if(i >=6 && i<18){
614
 
            if(Unicode::isSurrogate(c)){
615
 
                errln((UnicodeString)"ERROR: isSurrogate() failed for" + prettify(msg));
616
 
            }
617
 
            if(!Unicode::isValid(c)){
618
 
                errln((UnicodeString)"ERROR: isValid() failed for "+ prettify(msg));
619
 
            }
620
 
            if(!Unicode::isUnicodeChar(c)){
621
 
                errln((UnicodeString)"ERROR: isUnicodeChar() failed for "+ prettify(msg));
622
 
            }
623
 
            if(Unicode::isError(c)){
624
 
                errln((UnicodeString)"ERROR: isError() failed for "+ prettify(msg));
625
 
            }
626
 
        }else if(i >=18 && i<20){
627
 
            if(Unicode::isSurrogate(c)){
628
 
                errln((UnicodeString)"ERROR: isSurrogate() failed for" + prettify(msg));
629
 
            }
630
 
            if(Unicode::isValid(c)){
631
 
                errln((UnicodeString)"ERROR: isValid() failed for "+ prettify(msg));
632
 
            }
633
 
            if(!Unicode::isUnicodeChar(c)){
634
 
                errln((UnicodeString)"ERROR: isUnicodeChar() failed for "+ prettify(msg));
635
 
            }
636
 
            if(!Unicode::isError(c)){
637
 
                errln((UnicodeString)"ERROR: isError() failed for "+ prettify(msg));
638
 
            }
639
 
        }
640
 
        else if(i >=18 && i<(int32_t)(sizeof(codePoint)/sizeof(codePoint[0]))){
641
 
            if(Unicode::isSurrogate(c)){
642
 
                errln((UnicodeString)"ERROR: isSurrogate() failed for" + prettify(msg));
643
 
            }
644
 
            if(Unicode::isValid(c)){
645
 
                errln((UnicodeString)"ERROR: isValid() failed for "+ prettify(msg));
646
 
            }
647
 
            if(Unicode::isUnicodeChar(c)){
648
 
                errln((UnicodeString)"ERROR: isUnicodeChar() failed for "+ prettify(msg));
649
 
            }
650
 
            if(!Unicode::isError(c)){
651
 
                errln((UnicodeString)"ERROR: isError() failed for "+ prettify(msg));
652
 
            }
653
 
        }
654
 
    }
655
 
 
656
 
}
657
 
 
658
 
void UnicodeTest::TestCharLength()
659
 
{
660
 
    const int32_t codepoint[]={
661
 
        1, 0x0061,
662
 
        1, 0xe065,
663
 
        1, 0x20ac,
664
 
        2, 0x20402,
665
 
        2, 0x23456,
666
 
        2, 0x24506,
667
 
        2, 0x20402,
668
 
        2, 0x10402,
669
 
        1, 0xd7ff,
670
 
        1, 0xe000
671
 
    };
672
 
 
673
 
    int32_t i;
674
 
    UBool multiple;
675
 
    for(i=0; i<(int32_t)(sizeof(codepoint)/sizeof(codepoint[0])); i=(int16_t)(i+2)){
676
 
        UChar32 c=codepoint[i+1];
677
 
        UnicodeString msg;
678
 
        msg.append(c);
679
 
        if(Unicode::charLength(c) != codepoint[i]){
680
 
            errln((UnicodeString)"The no: of code units for" + prettify(msg)+
681
 
                ":- Expected: " + (int32_t)codepoint[i] + " Got: " + Unicode::charLength(c));
682
 
        }else{
683
 
            logln((UnicodeString)"The no: of code units for" + prettify(msg) + " is " + Unicode::charLength(c)); 
684
 
        }
685
 
        multiple=(UBool)(codepoint[i] == 1 ? FALSE : TRUE);
686
 
        if(Unicode::needMultipleUChar(c) != multiple){
687
 
            errln("ERROR: Unicode::needMultipleUChar() failed for" + prettify(msg));
688
 
        }
689
 
    }
690
 
}
691
 
 
692
 
/*
693
 
Various script value testing.
694
 
This makes sure that the Unicode::EUnicodeScript
695
 
and UCharScript enum values are the same.
696
 
*/
697
 
void UnicodeTest::TestScript()
698
 
{
699
 
    if ((int32_t)Unicode::kScriptCount != (int32_t)UBLOCK_COUNT) {
700
 
        errln("ERROR: Unicode::EUnicodeScript is not the same size as UCharScript");
701
 
    }
702
 
 
703
 
    if ((int32_t)Unicode::kBasicLatin != (int32_t)U_BASIC_LATIN) {
704
 
        errln("ERROR: Different Basic Latin values in EUnicodeScript and UCharScript");
705
 
    }
706
 
 
707
 
    if ((int32_t)Unicode::kHighSurrogate != (int32_t)U_HIGH_SURROGATES) {
708
 
        errln("ERROR: Different High Surrogate values in EUnicodeScript and UCharScript");
709
 
    }
710
 
 
711
 
    if ((int32_t)Unicode::kLowSurrogate != (int32_t)U_LOW_SURROGATES) {
712
 
        errln("ERROR: Different Low Surrogate values in EUnicodeScript and UCharScript");
713
 
    }
714
 
 
715
 
    if ((int32_t)Unicode::kCJKRadicalsSupplement != (int32_t)U_CJK_RADICALS_SUPPLEMENT) {
716
 
        errln("ERROR: Different CJK Radicals Supplement values in EUnicodeScript and UCharScript");
717
 
    }
718
 
 
719
 
    if ((int32_t)Unicode::kGreek != (int32_t)U_GREEK) {
720
 
        errln("ERROR: Different Greek values in EUnicodeScript and UCharScript");
721
 
    }
722
 
 
723
 
    if ((int32_t)Unicode::kThai != (int32_t)U_THAI) {
724
 
        errln("ERROR: Diffe rent Thai values in EUnicodeScript and UCharScript");
725
 
    }
726
 
}