2001-11-13 19:45:55 +00:00
|
|
|
/********************************************************************
|
2006-07-03 07:40:30 +00:00
|
|
|
* COPYRIGHT:
|
|
|
|
* Copyright (c) 1997-2006, International Business Machines Corporation and
|
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
2002-09-21 00:43:14 +00:00
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_COLLATION
|
|
|
|
|
2001-11-13 19:45:55 +00:00
|
|
|
#include "cntabcol.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
|
|
|
ContractionTableTest::ContractionTableTest() {
|
2006-07-03 07:40:30 +00:00
|
|
|
testMapping = utrie_open(NULL, NULL, 0, 0, 0, TRUE);
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ContractionTableTest::~ContractionTableTest() {
|
2006-07-03 07:40:30 +00:00
|
|
|
utrie_close(testMapping);
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContractionTableTest::TestGrowTable(/* char* par */) {
|
2006-07-03 07:40:30 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
uint32_t i = 0, res = 0;
|
|
|
|
testTable = uprv_cnttab_open(testMapping, &status);
|
2001-11-13 19:45:55 +00:00
|
|
|
|
2006-07-03 07:40:30 +00:00
|
|
|
// fill up one contraction so that it has to expand
|
2001-11-13 19:45:55 +00:00
|
|
|
for(i = 0; i<65536; i++) {
|
2006-07-03 07:40:30 +00:00
|
|
|
uprv_cnttab_addContraction(testTable, 0, (UChar)i, i, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status));
|
|
|
|
break;
|
|
|
|
}
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
2006-07-03 07:40:30 +00:00
|
|
|
// test whether the filled up contraction really contains the data we input
|
|
|
|
if(U_SUCCESS(status)) {
|
|
|
|
for(i = 0; i<65536; i++) {
|
|
|
|
res = uprv_cnttab_getCE(testTable, 0, i, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(res != i) {
|
|
|
|
errln("Error: expected %i, got %i\n", i, res);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uprv_cnttab_close(testTable);
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContractionTableTest::TestSetContraction(){
|
2006-07-03 07:40:30 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
testTable = uprv_cnttab_open(testMapping, &status);
|
|
|
|
// This should make a new contraction
|
|
|
|
uprv_cnttab_setContraction(testTable, 1, 0, 0x41, 0x41, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error setting a non existing contraction error = %i (%s)\n", status, u_errorName(status));
|
|
|
|
}
|
|
|
|
// if we try to change the non existing offset, we should get an error
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
// currently this tests whether there is enough space, maybe it should test whether the element is actually in
|
|
|
|
// range. Also, maybe a silent growing should take place....
|
|
|
|
uprv_cnttab_setContraction(testTable, 1, 0x401, 0x41, 0x41, &status);
|
|
|
|
if(status != U_INDEX_OUTOFBOUNDS_ERROR) {
|
|
|
|
errln("changing a non-existing offset should have resulted in an error\n");
|
|
|
|
}
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
uprv_cnttab_close(testTable);
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContractionTableTest::TestAddATableElement(){
|
2006-07-03 07:40:30 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
testTable = uprv_cnttab_open(testMapping, &status);
|
|
|
|
uint32_t i = 0, res = 0;
|
2001-11-13 19:45:55 +00:00
|
|
|
|
2006-07-03 07:40:30 +00:00
|
|
|
// fill up one contraction so that it has to expand
|
2001-11-29 20:21:08 +00:00
|
|
|
for(i = 0; i<0x1000; i++) {
|
2006-07-03 07:40:30 +00:00
|
|
|
uprv_cnttab_addContraction(testTable, i, (UChar)i, i, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// test whether the filled up contraction really contains the data we input
|
|
|
|
if(U_SUCCESS(status)) {
|
|
|
|
for(i = 0; i<0x1000; i++) {
|
|
|
|
res = uprv_cnttab_getCE(testTable, i, 0, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(res != i) {
|
|
|
|
errln("Error: expected %i, got %i\n", i, res);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
2006-07-03 07:40:30 +00:00
|
|
|
uprv_cnttab_close(testTable);
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContractionTableTest::TestClone(){
|
2006-07-03 07:40:30 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
testTable = uprv_cnttab_open(testMapping, &status);
|
|
|
|
int32_t i = 0, res = 0;
|
|
|
|
// we must construct table in order to copy codepoints and CEs
|
|
|
|
// fill up one contraction so that it has to expand
|
|
|
|
for(i = 0; i<0x500; i++) {
|
|
|
|
uprv_cnttab_addContraction(testTable, i, (UChar)i, i, &status);
|
2001-11-13 19:45:55 +00:00
|
|
|
if(U_FAILURE(status)) {
|
2006-07-03 07:40:30 +00:00
|
|
|
errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status));
|
|
|
|
break;
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
2006-07-03 07:40:30 +00:00
|
|
|
}
|
|
|
|
uprv_cnttab_constructTable(testTable, 0, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error constructing table error = %i (%s)\n", status, u_errorName(status));
|
|
|
|
} else {
|
|
|
|
testClone = uprv_cnttab_clone(testTable, &status);
|
|
|
|
if(U_SUCCESS(status)) {
|
|
|
|
for(i = 0; i<0x500; i++) {
|
|
|
|
res = uprv_cnttab_getCE(testTable, i, 0, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error occurred at position %i, error = %i (%s)\n", i, status, u_errorName(status));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(res != i) {
|
|
|
|
errln("Error: expected %i, got %i\n", i, res);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
2006-07-03 07:40:30 +00:00
|
|
|
uprv_cnttab_close(testClone);
|
|
|
|
}
|
|
|
|
uprv_cnttab_close(testTable);
|
|
|
|
testTable = uprv_cnttab_open(testMapping, &status);
|
|
|
|
if(U_FAILURE(status)) {
|
|
|
|
errln("Error opening table error = %i (%s)\n", status, u_errorName(status));
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
2006-07-03 07:40:30 +00:00
|
|
|
uprv_cnttab_close(testTable);
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContractionTableTest::TestChangeContraction(){
|
2006-07-03 07:40:30 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
testTable = uprv_cnttab_open(testMapping, &status);
|
|
|
|
uint32_t i = 0, res = 0;
|
|
|
|
res = uprv_cnttab_changeContraction(testTable, 0, 0x41, 0xAB, &status);
|
|
|
|
if(res != 0) {
|
|
|
|
errln("found a non existing contraction!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < 0x20; i+=2) {
|
|
|
|
uprv_cnttab_addContraction(testTable, 0, (UChar)i, i, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = uprv_cnttab_changeContraction(testTable, 0, 0x41, 0xAB, &status);
|
2001-11-13 19:45:55 +00:00
|
|
|
if(res != UCOL_NOT_FOUND) {
|
2006-07-03 07:40:30 +00:00
|
|
|
errln("managed to change a non existing contraction!\n");
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
2006-07-03 07:40:30 +00:00
|
|
|
|
|
|
|
for(i = 1; i < 0x20; i+=2) {
|
|
|
|
res = uprv_cnttab_changeContraction(testTable, 0, (UChar)i, 0xAB, &status);
|
|
|
|
if(res != UCOL_NOT_FOUND) {
|
|
|
|
errln("managed to change a non existing contraction!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uprv_cnttab_close(testTable);
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContractionTableTest::TestChangeLastCE(){
|
2006-07-03 07:40:30 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
testTable = uprv_cnttab_open(testMapping, &status);
|
|
|
|
uint32_t res = uprv_cnttab_changeLastCE(testTable, 1, 0xABCD, &status);
|
|
|
|
if(res!=0) {
|
|
|
|
errln("managed to change the last CE in an non-existing contraction!\n");
|
|
|
|
}
|
|
|
|
uprv_cnttab_close(testTable);
|
2001-11-13 19:45:55 +00:00
|
|
|
}
|
|
|
|
|
2006-06-07 22:28:24 +00:00
|
|
|
void ContractionTableTest::TestErrorCodeChecking(){
|
|
|
|
UErrorCode status = U_REGEX_SET_CONTAINS_STRING;
|
|
|
|
|
|
|
|
uprv_cnttab_open(NULL, &status);
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
uprv_cnttab_clone(NULL, &status);
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
uprv_cnttab_changeLastCE(NULL, 0, 0, &status);
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
uprv_cnttab_insertContraction(NULL, 0, 0, 0, &status);
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
uprv_cnttab_addContraction(NULL, 0, 0, 0, &status);
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
uprv_cnttab_setContraction(NULL, 0, 0, 0, 0, &status);
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
uprv_cnttab_findCP(NULL, 0, 0, &status);
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
if (uprv_cnttab_getCE(NULL, 0, 0, &status) != UCOL_NOT_FOUND) {
|
|
|
|
errln("uprv_cnttab_getCE didn't return UCOL_NOT_FOUND\n");
|
|
|
|
}
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
if (uprv_cnttab_findCE(NULL, 0, 0, &status) != UCOL_NOT_FOUND) {
|
|
|
|
errln("uprv_cnttab_findCE didn't return UCOL_NOT_FOUND\n");
|
|
|
|
}
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
uprv_cnttab_isTailored(NULL, 0, NULL, &status);
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
uprv_cnttab_changeContraction(NULL, 0, 0, 0, &status);
|
|
|
|
if (status != U_REGEX_SET_CONTAINS_STRING) {
|
|
|
|
errln("Status was incorrectly modified to %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
}
|
2001-11-13 19:45:55 +00:00
|
|
|
|
|
|
|
void ContractionTableTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
|
|
|
|
{
|
|
|
|
if (exec) logln("TestSuite ContractionTableTest: ");
|
|
|
|
switch (index) {
|
|
|
|
case 0: name = "TestGrowTable"; if (exec) TestGrowTable(/* par */); break;
|
|
|
|
case 1: name = "TestSetContraction"; if (exec) TestSetContraction(/* par */); break;
|
|
|
|
case 2: name = "TestAddATableElement"; if (exec) TestAddATableElement(/* par */); break;
|
|
|
|
case 3: name = "TestClone"; if (exec) TestClone(/* par */); break;
|
|
|
|
case 4: name = "TestChangeContraction"; if (exec) TestChangeContraction(/* par */); break;
|
|
|
|
case 5: name = "TestChangeLastCE"; if (exec) TestChangeLastCE(/* par */); break;
|
2006-06-07 22:28:24 +00:00
|
|
|
case 6: name = "TestErrorCodeChecking"; if (exec) TestErrorCodeChecking(/* par */); break;
|
2001-11-13 19:45:55 +00:00
|
|
|
default: name = ""; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-21 00:43:14 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_COLLATION */
|