1 /********************************************************************
3 * Copyright (c) 1997-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 #include "unicode/utypes.h"
9 #if !UCONFIG_NO_COLLATION
15 ContractionTableTest::ContractionTableTest() {
16 status
= U_ZERO_ERROR
;
17 /*testMapping = ucmpe32_open(0, 0, 0, &status);*/
18 testMapping
= utrie_open(NULL
, NULL
, 0, 0, 0, TRUE
);
21 ContractionTableTest::~ContractionTableTest() {
22 /*ucmpe32_close(testMapping);*/
23 utrie_close(testMapping
);
26 void ContractionTableTest::TestGrowTable(/* char* par */) {
27 uint32_t i
= 0, res
= 0;
28 testTable
= uprv_cnttab_open(testMapping
, &status
);
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
));
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
));
47 errln("Error: expected %i, got %i\n", i
, res
);
52 uprv_cnttab_close(testTable
);
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
));
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");
70 status
= U_ZERO_ERROR
;
71 uprv_cnttab_close(testTable
);
74 void ContractionTableTest::TestAddATableElement(){
75 testTable
= uprv_cnttab_open(testMapping
, &status
);
76 uint32_t i
= 0, res
= 0;
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
));
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
));
95 errln("Error: expected %i, got %i\n", i
, res
);
100 uprv_cnttab_close(testTable
);
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
));
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
));
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
));
128 errln("Error: expected %i, got %i\n", i
, res
);
133 uprv_cnttab_close(testClone
);
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
));
140 uprv_cnttab_close(testTable
);
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
);
148 errln("found a non existing contraction!\n");
151 for(i
= 0; i
< 0x20; i
+=2) {
152 uprv_cnttab_addContraction(testTable
, 0, (UChar
)i
, i
, &status
);
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");
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");
166 uprv_cnttab_close(testTable
);
169 void ContractionTableTest::TestChangeLastCE(){
170 testTable
= uprv_cnttab_open(testMapping
, &status
);
171 uint32_t res
= uprv_cnttab_changeLastCE(testTable
, 1, 0xABCD, &status
);
173 errln("managed to change the last CE in an non-existing contraction!\n");
175 uprv_cnttab_close(testTable
);
179 void ContractionTableTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
181 if (exec
) logln("TestSuite ContractionTableTest: ");
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;
193 #endif /* #if !UCONFIG_NO_COLLATION */