]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
3 | * Copyright (c) 1997-2001, International Business Machines Corporation and | |
4 | * others. All Rights Reserved. | |
5 | ********************************************************************/ | |
6 | ||
7 | #include "unicode/utypes.h" | |
8 | ||
9 | #if !UCONFIG_NO_COLLATION | |
10 | ||
11 | #include "cntabcol.h" | |
12 | ||
13 | U_NAMESPACE_USE | |
14 | ||
15 | ContractionTableTest::ContractionTableTest() { | |
16 | status = U_ZERO_ERROR; | |
17 | /*testMapping = ucmpe32_open(0, 0, 0, &status);*/ | |
18 | testMapping = utrie_open(NULL, NULL, 0, 0, TRUE); | |
19 | } | |
20 | ||
21 | ContractionTableTest::~ContractionTableTest() { | |
22 | /*ucmpe32_close(testMapping);*/ | |
23 | utrie_close(testMapping); | |
24 | } | |
25 | ||
26 | void ContractionTableTest::TestGrowTable(/* char* par */) { | |
27 | uint32_t i = 0, res = 0; | |
28 | testTable = uprv_cnttab_open(testMapping, &status); | |
29 | ||
30 | // fill up one contraction so that it has to expand | |
31 | for(i = 0; i<65536; i++) { | |
32 | uprv_cnttab_addContraction(testTable, 0, (UChar)i, i, &status); | |
33 | if(U_FAILURE(status)) { | |
34 | errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status)); | |
35 | break; | |
36 | } | |
37 | } | |
38 | // test whether the filled up contraction really contains the data we input | |
39 | if(U_SUCCESS(status)) { | |
40 | for(i = 0; i<65536; i++) { | |
41 | res = uprv_cnttab_getCE(testTable, 0, i, &status); | |
42 | if(U_FAILURE(status)) { | |
43 | errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status)); | |
44 | break; | |
45 | } | |
46 | if(res != i) { | |
47 | errln("Error: expected %i, got %i\n", i, res); | |
48 | break; | |
49 | } | |
50 | } | |
51 | } | |
52 | uprv_cnttab_close(testTable); | |
53 | } | |
54 | ||
55 | void ContractionTableTest::TestSetContraction(){ | |
56 | testTable = uprv_cnttab_open(testMapping, &status); | |
57 | // This should make a new contraction | |
58 | uprv_cnttab_setContraction(testTable, 1, 0, 0x41, 0x41, &status); | |
59 | if(U_FAILURE(status)) { | |
60 | errln("Error setting a non existing contraction error = %i (%s)\n", status, u_errorName(status)); | |
61 | } | |
62 | // if we try to change the non existing offset, we should get an error | |
63 | status = U_ZERO_ERROR; | |
64 | // currently this tests whether there is enough space, maybe it should test whether the element is actually in | |
65 | // range. Also, maybe a silent growing should take place.... | |
66 | uprv_cnttab_setContraction(testTable, 1, 0x401, 0x41, 0x41, &status); | |
67 | if(status != U_INDEX_OUTOFBOUNDS_ERROR) { | |
68 | errln("changing a non-existing offset should have resulted in an error\n"); | |
69 | } | |
70 | status = U_ZERO_ERROR; | |
71 | uprv_cnttab_close(testTable); | |
72 | } | |
73 | ||
74 | void ContractionTableTest::TestAddATableElement(){ | |
75 | testTable = uprv_cnttab_open(testMapping, &status); | |
76 | uint32_t i = 0, res = 0; | |
77 | ||
78 | // fill up one contraction so that it has to expand | |
79 | for(i = 0; i<0x1000; i++) { | |
80 | uprv_cnttab_addContraction(testTable, i, (UChar)i, i, &status); | |
81 | if(U_FAILURE(status)) { | |
82 | errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status)); | |
83 | break; | |
84 | } | |
85 | } | |
86 | // test whether the filled up contraction really contains the data we input | |
87 | if(U_SUCCESS(status)) { | |
88 | for(i = 0; i<0x1000; i++) { | |
89 | res = uprv_cnttab_getCE(testTable, i, 0, &status); | |
90 | if(U_FAILURE(status)) { | |
91 | errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status)); | |
92 | break; | |
93 | } | |
94 | if(res != i) { | |
95 | errln("Error: expected %i, got %i\n", i, res); | |
96 | break; | |
97 | } | |
98 | } | |
99 | } | |
100 | uprv_cnttab_close(testTable); | |
101 | } | |
102 | ||
103 | void ContractionTableTest::TestClone(){ | |
104 | testTable = uprv_cnttab_open(testMapping, &status); | |
105 | int32_t i = 0, res = 0; | |
106 | // we must construct table in order to copy codepoints and CEs | |
107 | // fill up one contraction so that it has to expand | |
108 | for(i = 0; i<0x500; i++) { | |
109 | uprv_cnttab_addContraction(testTable, i, (UChar)i, i, &status); | |
110 | if(U_FAILURE(status)) { | |
111 | errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status)); | |
112 | break; | |
113 | } | |
114 | } | |
115 | uprv_cnttab_constructTable(testTable, 0, &status); | |
116 | if(U_FAILURE(status)) { | |
117 | errln("Error constructing table error = %i (%s)\n", status, u_errorName(status)); | |
118 | } else { | |
119 | testClone = uprv_cnttab_clone(testTable, &status); | |
120 | if(U_SUCCESS(status)) { | |
121 | for(i = 0; i<0x500; i++) { | |
122 | res = uprv_cnttab_getCE(testTable, i, 0, &status); | |
123 | if(U_FAILURE(status)) { | |
124 | errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status)); | |
125 | break; | |
126 | } | |
127 | if(res != i) { | |
128 | errln("Error: expected %i, got %i\n", i, res); | |
129 | break; | |
130 | } | |
131 | } | |
132 | } | |
133 | uprv_cnttab_close(testClone); | |
134 | } | |
135 | uprv_cnttab_close(testTable); | |
136 | testTable = uprv_cnttab_open(testMapping, &status); | |
137 | if(U_FAILURE(status)) { | |
138 | errln("Error opening table error = %i (%s)\n", status, u_errorName(status)); | |
139 | } | |
140 | uprv_cnttab_close(testTable); | |
141 | } | |
142 | ||
143 | void ContractionTableTest::TestChangeContraction(){ | |
144 | testTable = uprv_cnttab_open(testMapping, &status); | |
145 | uint32_t i = 0, res = 0; | |
146 | res = uprv_cnttab_changeContraction(testTable, 0, 0x41, 0xAB, &status); | |
147 | if(res != 0) { | |
148 | errln("found a non existing contraction!\n"); | |
149 | } | |
150 | ||
151 | for(i = 0; i < 0x20; i+=2) { | |
152 | uprv_cnttab_addContraction(testTable, 0, (UChar)i, i, &status); | |
153 | } | |
154 | ||
155 | res = uprv_cnttab_changeContraction(testTable, 0, 0x41, 0xAB, &status); | |
156 | if(res != UCOL_NOT_FOUND) { | |
157 | errln("managed to change a non existing contraction!\n"); | |
158 | } | |
159 | ||
160 | for(i = 1; i < 0x20; i+=2) { | |
161 | res = uprv_cnttab_changeContraction(testTable, 0, (UChar)i, 0xAB, &status); | |
162 | if(res != UCOL_NOT_FOUND) { | |
163 | errln("managed to change a non existing contraction!\n"); | |
164 | } | |
165 | } | |
166 | uprv_cnttab_close(testTable); | |
167 | } | |
168 | ||
169 | void ContractionTableTest::TestChangeLastCE(){ | |
170 | testTable = uprv_cnttab_open(testMapping, &status); | |
171 | uint32_t res = uprv_cnttab_changeLastCE(testTable, 1, 0xABCD, &status); | |
172 | if(res!=0) { | |
173 | errln("managed to change the last CE in an non-existing contraction!\n"); | |
174 | } | |
175 | uprv_cnttab_close(testTable); | |
176 | } | |
177 | ||
178 | ||
179 | void ContractionTableTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) | |
180 | { | |
181 | if (exec) logln("TestSuite ContractionTableTest: "); | |
182 | switch (index) { | |
183 | case 0: name = "TestGrowTable"; if (exec) TestGrowTable(/* par */); break; | |
184 | case 1: name = "TestSetContraction"; if (exec) TestSetContraction(/* par */); break; | |
185 | case 2: name = "TestAddATableElement"; if (exec) TestAddATableElement(/* par */); break; | |
186 | case 3: name = "TestClone"; if (exec) TestClone(/* par */); break; | |
187 | case 4: name = "TestChangeContraction"; if (exec) TestChangeContraction(/* par */); break; | |
188 | case 5: name = "TestChangeLastCE"; if (exec) TestChangeLastCE(/* par */); break; | |
189 | default: name = ""; break; | |
190 | } | |
191 | } | |
192 | ||
193 | #endif /* #if !UCONFIG_NO_COLLATION */ |