ICU-1083 Put the ucmpe32 test with similar tests.

X-SVN-Rev: 5796
This commit is contained in:
George Rhoten 2001-09-18 22:53:27 +00:00
parent 0a96b6ab50
commit 03fa48368c
3 changed files with 120 additions and 225 deletions

View file

@ -29,7 +29,6 @@ void addUTF8Test(TestNode** root);
void addUTransTest(TestNode** root);
void addPUtilTest(TestNode** root);
void addCompactArrayTest(TestNode** root);
void addCompactArrayExTest(TestNode** root);
void addTestDeprecatedAPI(TestNode** root);
void addUCharTransformTest(TestNode** root);
@ -48,7 +47,6 @@ void addAllTests(TestNode** root)
addUTransTest(root);
addPUtilTest(root);
addCompactArrayTest(root);
addCompactArrayExTest(root);
addTestDeprecatedAPI(root);
addUCharTransformTest(root);
}

View file

@ -292,10 +292,6 @@ SOURCE=.\susctest.c
# End Source File
# Begin Source File
SOURCE=.\ucmpetst.c
# End Source File
# Begin Source File
SOURCE=.\ucmptst.c
# End Source File
# Begin Source File

View file

@ -14,16 +14,15 @@
*/
#include "unicode/utypes.h"
#include "ucmp16.h"
#include "ucmp8.h"
#include "ucmp32.h"
#include "ucmpe32.h"
#include "cmemory.h"
#include "cintltst.h"
#include "ucol_imp.h"
static void TestUCMP16API(void);
static void TestUCMP8API(void);
static void TestUCMP32API(void);
static void TestUCMPE32API(void);
void addCompactArrayTest(TestNode** root);
@ -31,152 +30,8 @@ void addCompactArrayTest(TestNode** root);
void
addCompactArrayTest(TestNode** root)
{
addTest(root, &TestUCMP16API, "ucmptst/TestUCMP16API");
addTest(root, &TestUCMP8API, "ucmptst/TestUCMP8API");
addTest(root, &TestUCMP32API, "ucmptst/TestUCMP32API");
}
static void TestUCMP16API(){
int16_t newValues[]={
0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09,
0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09,
0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09,
0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09,
0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09,
0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09,
0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09,
};
uint16_t indexArray[]={
0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65,
};
uint16_t *values;
CompactShortArray* ucmp16Array=NULL;
CompactShortArray ucmp16Array1;
CompactShortArray ucmp16Array2;
int32_t count=0, i=0;
int16_t const TEST_DEFAULT_VALUE = 0xff;
/*ucmp16_open*/
log_verbose("Testing ucmp16_open()\n");
ucmp16Array=ucmp16_open(TEST_DEFAULT_VALUE);
if(ucmp16Array == NULL){
log_err("ERROR: ucmp16_open() failed\n");
}
if(ucmp16_getDefaultValue(ucmp16Array) != TEST_DEFAULT_VALUE ||
(int32_t)ucmp16_getCount(ucmp16Array) != (int32_t)ucmp16_getkUnicodeCount()) {
log_err("ERROR: ucmp16_open failed\n");
}
/*ucmp16_init*/
log_verbose("Testing ucmp16_init()\n");
ucmp16_init(&ucmp16Array1, TEST_DEFAULT_VALUE);
if(ucmp16_getDefaultValue(&ucmp16Array1) == 0x0000 ||
(int32_t)ucmp16_getCount(&ucmp16Array1) != (int32_t)ucmp16_getkUnicodeCount() ||
ucmp16_getIndex(&ucmp16Array1) == NULL ||
ucmp16_getArray(&ucmp16Array1) == NULL ||
ucmp16Array->fBogus != FALSE){
log_err("Error: ucmp16_init() failed\n");
}
/*ucmp16_initBogus*/
log_verbose("Testing ucmp16_initBogus()\n");
ucmp16_initBogus(&ucmp16Array2);
if(ucmp16_getDefaultValue(&ucmp16Array2) != 0x0000 ||
(int32_t)ucmp16_getCount(&ucmp16Array2) != ucmp16Array2.fCount ||
ucmp16_getIndex(&ucmp16Array2) != NULL ||
ucmp16_getArray(&ucmp16Array2) != NULL ||
ucmp16Array2.fBogus != TRUE){
log_err("Error: ucmp16_initBogus() failed\n");
}
/*ucmp16_getDefaultValue*/
if(ucmp16_getDefaultValue(ucmp16Array) != ucmp16_getDefaultValue(&ucmp16Array1) ||
ucmp16_getDefaultValue(ucmp16Array) == ucmp16_getDefaultValue(&ucmp16Array2) ){
log_err("Error in ucmp16_getDefaultValue()\n");
}
/*ucmp16_getkBlockCount*/
if(ucmp16_getkBlockCount() != 128 ){
log_err("Error in ucmp16_getkBlockCount()\n");
}
ucmp16_close(ucmp16Array);
ucmp16_close(&ucmp16Array1);
ucmp16_close(&ucmp16Array2);
/*ucmp_compact, ucmp16_set*/
log_verbose("Testing ucmp16_set\n");
ucmp16Array=ucmp16_open(TEST_DEFAULT_VALUE);
if(ucmp16Array->fCompact == TRUE){
log_err("Error: ucmp16_open failed Got compact for expanded data\n");
}
ucmp16_compact(ucmp16Array);
if(ucmp16Array->fCompact != TRUE){
log_err("Error: ucmp16_compact failed\n");
}
/* ucmp16_set*/
ucmp16_set(ucmp16Array, 0, TEST_DEFAULT_VALUE);
values=(uint16_t*)ucmp16_getArray(ucmp16Array);
if(values[0] != TEST_DEFAULT_VALUE){
log_err("ERROR: ucmp16_set() failed\n");
}
if(ucmp16Array->fCompact == TRUE){
log_err("Error: ucmp16_set didn't expand the compact data\n");
}
/*ucmp16_set where the value != defaultValue*/
ucmp16_compact(ucmp16Array);
ucmp16_set(ucmp16Array, 0, 0xfe);
values=(uint16_t*)ucmp16_getArray(ucmp16Array);
if(values[0] != 0xfe){
log_err("ERROR: ucmp16_set() failed\n");
}
/*ucmp16_setRange*/
ucmp16_compact(ucmp16Array);
ucmp16_setRange(ucmp16Array, 0, 10, 0xff);
values=(uint16_t*)ucmp16_getArray(ucmp16Array);
for(i=0; i<10; i++){
if(values[0] != 0xff){
log_err("ERROR: ucmp16_set() failed\n");
break;
}
}
/*ucmp16_setRange where the value != defaultValue*/
ucmp16_compact(ucmp16Array);
ucmp16_setRange(ucmp16Array, 0, 10, 0xfe);
values=(uint16_t*)ucmp16_getArray(ucmp16Array);
for(i=0; i<10; i++){
if(values[0] != 0xfe){
log_err("ERROR: ucmp16_set() failed\n");
break;
}
}
ucmp16_close(ucmp16Array);
/*ucmp16_openAlias*/
log_verbose("Testing ucmp16_openAlias()\n");
count=sizeof(newValues)/sizeof(newValues[0]);
ucmp16Array=ucmp16_openAlias(indexArray, newValues, count, 0xFE);
if(ucmp16_getDefaultValue(ucmp16Array) != 0x00fe ||
(int32_t)ucmp16_getCount(ucmp16Array) != count ||
ucmp16Array->fAlias != TRUE ||
memcmp(ucmp16_getArray(ucmp16Array), newValues, count) != 0 ||
memcmp(ucmp16_getIndex(ucmp16Array), indexArray, count) != 0 ) {
log_err("Error: ucmp16_openAlias() failed\n");
}
ucmp16_close(ucmp16Array);
addTest(root, &TestUCMP8API, "ucmptst/TestUCMP8API");
addTest(root, &TestUCMPE32API, "ucmptst/TestUCMPE32API");
}
static void TestUCMP8API(){
@ -270,81 +125,127 @@ static void TestUCMP8API(){
ucmp8_close(&ucmp8Array2);
}
static void TestUCMP32API(){
CompactIntArray* ucmp32Array=NULL;
void addCompactArrayTest(TestNode** root);
struct {
UChar lead;
UChar trail;
int32_t value;
} testCmpe32array[] = {
{ 0x0, 0x0020, 0x00000020 },
{ 0x0, 0x0040, 0x00000040 },
{ 0x0, 0x004B, 0x0000004B },
{ 0x0, 0x00AC, 0x000000AC },
{ 0x0, 0x0400, 0x00000400 },
{ 0x0, 0xa123, 0x0000a123 },
{ 0x0, 0xeeee, 0x0000eeee },
{ 0xd800, 0xdc00, 0x0001000 },
{ 0xd900, 0xdc00, 0x0005000 }
};
static void fillup(CompactEIntArray *a) {
int32_t i = 0;
for(i = 0; i<sizeof(testCmpe32array)/sizeof(testCmpe32array[0]); i++) {
if(testCmpe32array[i].lead == 0) {
ucmpe32_set32(a, testCmpe32array[i].trail, testCmpe32array[i].value);
} else {
ucmpe32_setSurrogate(a, testCmpe32array[i].lead, testCmpe32array[i].trail, testCmpe32array[i].value);
}
}
}
static void query(CompactEIntArray *a) {
int32_t i = 0;
int32_t result = 0;
for(i = 0; i<sizeof(testCmpe32array)/sizeof(testCmpe32array[0]); i++) {
if(testCmpe32array[i].lead == 0) {
result = ucmpe32_get(a, testCmpe32array[i].trail);
if(result != testCmpe32array[i].value) {
log_err("Wrong value for %04X, expected %08X, got %08X\n",
testCmpe32array[i].trail, testCmpe32array[i].value, result);
}
} else {
if(a->fCompact == TRUE) {
result = ucmpe32_get(a, testCmpe32array[i].lead);
result = ucmpe32_getSurrogate(a, result, testCmpe32array[i].trail);
if(result != ucmpe32_getSurrogateEx(a, testCmpe32array[i].lead, testCmpe32array[i].trail)) {
log_err("results for getsurrogate and getsurrogateex do not match in compacted array\n");
}
} else {
result = ucmpe32_getSurrogateEx(a, testCmpe32array[i].lead, testCmpe32array[i].trail);
}
if(result != testCmpe32array[i].value) {
log_err("Wrong value for %04X %04X, expected %08X, got %08X\n",
testCmpe32array[i].lead, testCmpe32array[i].trail, testCmpe32array[i].value, result);
}
}
}
}
static void TestUCMPE32API(){
CompactEIntArray *ucmpe32Array=NULL, *ucmpe32Clone = NULL;
int32_t i=0;
int32_t *values;
/*int32_t *values;*/
int32_t const TEST_DEFAULT_VALUE = 0xFFFF;
UErrorCode status = U_ZERO_ERROR;
/*ucmp32_open*/
log_verbose("Testing ucmp32_open()\n");
ucmp32Array=ucmp32_open(TEST_DEFAULT_VALUE);
if(ucmp32Array == NULL){
log_err("ERROR: ucmp32_open() failed\n");
}
if( (int32_t)ucmp32_getCount(ucmp32Array) != (int32_t)ucmp32_getkUnicodeCount()) {
log_err("ERROR: ucmp32_open or ucmp_getCount() failed failed\n");
}
/*ucmp32_getkBlockCount*/
if(ucmp32_getkBlockCount() != 128 ){
log_err("Error in ucmp32_getkBlockCount()\n");
}
if(ucmp32_getArray(ucmp32Array) == NULL ||
ucmp32_getIndex(ucmp32Array) == NULL ){
log_err("Error in ucmp32_open of ucmp32_getArray() or ucmp32_getIndex()\n");
}
/*ucmp32_compact*/
if(ucmp32Array->fCompact == TRUE){
log_err("Error: ucmp32_open failed Got compact for expanded data\n");
}
ucmp32_compact(ucmp32Array, 1);
if(ucmp32Array->fCompact != TRUE){
log_err("Error: ucmp32_compact failed\n");
}
/* ucmp32_set*/
ucmp32_set(ucmp32Array, 0, TEST_DEFAULT_VALUE);
values=(int32_t*)ucmp32_getArray(ucmp32Array);
if(values[0] != TEST_DEFAULT_VALUE){
log_err("ERROR: ucmp32_set() failed\n");
}
if(ucmp32Array->fCompact == TRUE){
log_err("Error: ucmp32_set didn't expand\n");
}
/*ucmp32_set where the value != defaultValue*/
ucmp32_compact(ucmp32Array, 1);
ucmp32_set(ucmp32Array, 0, 0xFFFE);
values=(int32_t*)ucmp32_getArray(ucmp32Array);
if(values[0] != 0xFFFE){
log_err("ERROR: ucmp32_set() failed\n");
}
/*ucmpe32_open*/
log_verbose("Testing ucmpe32_open()\n");
ucmpe32Array=ucmpe32_open(UCOL_NOT_FOUND, UCOL_SPECIAL_FLAG | (SURROGATE_TAG<<24), &status);
if(U_FAILURE(status) || ucmpe32Array == NULL){
log_err("ERROR: ucmpe32_open() failed\n");
status = U_ZERO_ERROR;
} else {
fillup(ucmpe32Array);
query(ucmpe32Array);
/*ucmp32_setRange*/
ucmp32_compact(ucmp32Array, 1);
ucmp32_setRange(ucmp32Array, 0, 10, 0xFFFF);
values=(int32_t*)ucmp32_getArray(ucmp32Array);
for(i=0; i<10; i++){
if(values[0] != 0xFFFF){
log_err("ERROR: ucmp32_set() failed\n");
break;
log_verbose("Testing ucmpe32_clone()\n");
ucmpe32Clone=ucmpe32_clone(ucmpe32Array, &status);
if(U_FAILURE(status) || ucmpe32Clone == NULL){
log_err("ERROR: ucmpe32_clone() failed\n");
status = U_ZERO_ERROR;
} else {
query(ucmpe32Clone);
ucmpe32_close(ucmpe32Clone);
ucmpe32Clone = NULL;
}
log_verbose("Testing ucmpe32_flattenMem()\n");
{
UMemoryStream *MS = uprv_mstrm_openNew(65536);
int32_t size = ucmpe32_flattenMem(ucmpe32Array, MS);
int32_t len = 0;
const uint8_t *buff = NULL;
if(size > 0) {
log_err("Managed to flatten uncompacted array\n");
}
}
if(ucmp32Array->fCompact == TRUE){
log_err("Error: ucmp32_setRange didn't expand\n");
}
/*ucmp32_setRange where the value != defaultValue*/
ucmp32_compact(ucmp32Array, 1);
ucmp32_setRange(ucmp32Array, 0, 10, 0xFFFE);
values=(int32_t*)ucmp32_getArray(ucmp32Array);
for(i=0; i<10; i++){
if(values[0] != 0xFFFE){
log_err("ERROR: ucmp32_set() failed\n");
break;
ucmpe32_compact(ucmpe32Array);
query(ucmpe32Array);
/* try after compacting */
size = ucmpe32_flattenMem(ucmpe32Array, MS);
buff = uprv_mstrm_getBuffer(MS, &len);
if(size == 0 || len == 0 || buff == NULL) {
log_err("Unable to flatten!\n");
} else {
log_verbose("Testing ucmpe32_openFromData()\n");
ucmpe32Clone = ucmpe32_openFromData(&buff, &status);
if(U_FAILURE(status) || ucmpe32Clone == NULL){
log_err("ERROR: ucmpe32_openFromData() failed\n");
status = U_ZERO_ERROR;
} else {
query(ucmpe32Clone);
ucmpe32_close(ucmpe32Clone);
ucmpe32Clone = NULL;
}
}
}
ucmpe32_close(ucmpe32Array);
}
ucmp32_close(ucmp32Array);
}