OLD | NEW |
(Empty) | |
| 1 /******************************************************************** |
| 2 * COPYRIGHT: |
| 3 * Copyright (c) 1997-2009, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. |
| 5 ********************************************************************/ |
| 6 /*******************************************************************************
* |
| 7 * |
| 8 * File CDETST.C |
| 9 * |
| 10 * Modification History: |
| 11 * Name Description |
| 12 * Madhu Katragadda Ported for C API |
| 13 ********************************************************************************
*/ |
| 14 /** |
| 15 * CollationGermanTest is a third level test class. This tests the locale |
| 16 * specific primary, secondary and tertiary rules. For example, the ignorable |
| 17 * character '-' in string "black-bird". The en_US locale uses the default |
| 18 * collation rules as its sorting sequence. |
| 19 */ |
| 20 |
| 21 #include <stdlib.h> |
| 22 |
| 23 #include "unicode/utypes.h" |
| 24 |
| 25 #if !UCONFIG_NO_COLLATION |
| 26 |
| 27 #include "unicode/ucol.h" |
| 28 #include "unicode/uloc.h" |
| 29 #include "cintltst.h" |
| 30 #include "cdetst.h" |
| 31 #include "ccolltst.h" |
| 32 #include "callcoll.h" |
| 33 #include "unicode/ustring.h" |
| 34 #include "string.h" |
| 35 |
| 36 static UCollator *myCollation; |
| 37 const static UChar testSourceCases[][MAX_TOKEN_LEN] = |
| 38 { |
| 39 {0x0047/*'G'*/, 0x0072/*'r'*/, 0x00F6, 0x00DF, 0x0065/*'e'*/, 0x0000}, |
| 40 {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, |
| 41 {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000}, |
| 42 {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000}, |
| 43 {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000}, |
| 44 {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, |
| 45 {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt i
n primary here */ |
| 46 {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt i
n primary here*/ |
| 47 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x00DF, 0x0065/
*'e'*/, 0x0000}, |
| 48 {0x0065/*'e'*/, 0x0066/*'f'*/, 0x0067/*'g'*/, 0x0000}, |
| 49 {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt i
n primary here*/ |
| 50 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x00DF, 0x0065/
*'e'*/, 0x0000} |
| 51 }; |
| 52 |
| 53 const static UChar testTargetCases[][MAX_TOKEN_LEN] = |
| 54 { |
| 55 {0x0047/*'G'*/, 0x0072/*'r'*/, 0x006f/*'o'*/, 0x0073/*'s'*/, 0x0073/*'s'*/,
0x0069/*'i'*/, 0x0073/*'s'*/, 0x0074/*'t'*/, 0x0000}, |
| 56 {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, |
| 57 {0x0054/*'T'*/, 0x006f/*'o'*/, 0x006e/*'n'*/, 0x0000}, |
| 58 {0x0054/*'T'*/, 0x006f/*'o'*/, 0x0064/*'d'*/, 0x0000}, |
| 59 {0x0054/*'T'*/, 0x006f/*'o'*/, 0x0066/*'f'*/, 0x0075/*'u'*/, 0x0000}, |
| 60 {0x0041/*'A'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, |
| 61 {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
/*doubt in primary here*/ |
| 62 {0x0061/*'a'*/, 0x0065/*'e'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
/*doubt in primary here*/ |
| 63 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x0073/*'s'*/,
0x0073/*'s'*/, 0x0065/*'e'*/, 0x0000}, |
| 64 {0x0065/*'e'*/, 0x0066/*'f'*/, 0x0067/*'g'*/, 0x0000}, |
| 65 {0x0061/*'a'*/, 0x0065/*'e'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
/*doubt in primary here*/ |
| 66 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x0073/*'s'*/,
0x0073/*'s'*/, 0x0065/*'e'*/, 0x0000} |
| 67 }; |
| 68 |
| 69 const static UCollationResult results[][2] = |
| 70 { |
| 71 /* Primary*/ /* Tertiary*/ |
| 72 { UCOL_LESS, UCOL_LESS }, /*should be UCOL_GREATER for pri
mary*/ |
| 73 { UCOL_EQUAL, UCOL_LESS }, |
| 74 { UCOL_GREATER, UCOL_GREATER }, |
| 75 { UCOL_GREATER, UCOL_GREATER }, |
| 76 { UCOL_GREATER, UCOL_GREATER }, |
| 77 { UCOL_EQUAL, UCOL_LESS }, |
| 78 { UCOL_EQUAL, UCOL_EQUAL }, /*should be UCOL_GREATER for prima
ry*/ |
| 79 { UCOL_LESS, UCOL_LESS }, /*should be UCOL_GREATER for primary
*/ |
| 80 { UCOL_EQUAL, UCOL_GREATER }, |
| 81 { UCOL_EQUAL, UCOL_EQUAL }, |
| 82 { UCOL_LESS, UCOL_LESS }, /*should be UCOL_GREATER for primary*
/ |
| 83 { UCOL_EQUAL, UCOL_GREATER } |
| 84 }; |
| 85 |
| 86 |
| 87 |
| 88 |
| 89 void addGermanCollTest(TestNode** root) |
| 90 { |
| 91 |
| 92 |
| 93 addTest(root, &TestTertiary, "tscoll/cdetst/TestTertiary"); |
| 94 addTest(root, &TestPrimary, "tscoll/cdetst/TestPrimary"); |
| 95 |
| 96 |
| 97 |
| 98 } |
| 99 |
| 100 static void TestTertiary( ) |
| 101 { |
| 102 |
| 103 int32_t i; |
| 104 UErrorCode status = U_ZERO_ERROR; |
| 105 myCollation = ucol_open("de_DE", &status); |
| 106 if(U_FAILURE(status)){ |
| 107 log_err_status(status, "ERROR: in creation of rule based collator: %s\n"
, myErrorName(status)); |
| 108 return; |
| 109 } |
| 110 log_verbose("Testing German Collation with Tertiary strength\n"); |
| 111 ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); |
| 112 ucol_setStrength(myCollation, UCOL_TERTIARY); |
| 113 for (i = 0; i < 12 ; i++) |
| 114 { |
| 115 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][1
]); |
| 116 } |
| 117 ucol_close(myCollation); |
| 118 } |
| 119 |
| 120 static void TestPrimary() |
| 121 { |
| 122 |
| 123 int32_t i; |
| 124 UErrorCode status = U_ZERO_ERROR; |
| 125 myCollation = ucol_open("de_DE", &status); |
| 126 if(U_FAILURE(status)){ |
| 127 log_err_status(status, "ERROR: %s: in creation of rule based collator: %
s\n", __FILE__, myErrorName(status)); |
| 128 return; |
| 129 } |
| 130 log_verbose("Testing German Collation with primary strength\n"); |
| 131 ucol_setStrength(myCollation, UCOL_PRIMARY); |
| 132 for (i = 0; i < 12 ; i++) |
| 133 { |
| 134 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][0
]); |
| 135 } |
| 136 ucol_close(myCollation); |
| 137 } |
| 138 |
| 139 #endif /* #if !UCONFIG_NO_COLLATION */ |
OLD | NEW |