2000-08-02 00:03:10 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2001-03-21 19:46:49 +00:00
|
|
|
* Copyright (c) 1998-2001, International Business Machines Corporation and
|
2000-08-02 00:03:10 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/*
|
|
|
|
* File test.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 07/28/2000 Madhu Creation
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "ucmp8.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cintltst.h"
|
2001-09-18 22:53:27 +00:00
|
|
|
#include "ucol_imp.h"
|
2000-08-02 00:03:10 +00:00
|
|
|
|
|
|
|
|
2001-01-31 23:17:51 +00:00
|
|
|
static void TestUCMP8API(void);
|
2000-08-02 00:03:10 +00:00
|
|
|
|
2001-05-31 23:07:40 +00:00
|
|
|
void addCompactArrayTest(TestNode** root);
|
2000-08-02 00:03:10 +00:00
|
|
|
|
|
|
|
|
2000-08-09 23:34:41 +00:00
|
|
|
void
|
2000-08-02 00:03:10 +00:00
|
|
|
addCompactArrayTest(TestNode** root)
|
|
|
|
{
|
2001-09-18 22:53:27 +00:00
|
|
|
addTest(root, &TestUCMP8API, "ucmptst/TestUCMP8API");
|
2002-04-03 23:06:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void query(CompactByteArray *array) {
|
|
|
|
int32_t i = 0;
|
|
|
|
const uint8_t *valuesSet=(uint8_t *)ucmp8_getArray(array);
|
|
|
|
for(i =0 ; i< 10; i++ ){
|
|
|
|
if(valuesSet[0] != (uint8_t)0xFD ){
|
|
|
|
log_err("ERROR: did not get the values expected values\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-08-02 00:03:10 +00:00
|
|
|
}
|
|
|
|
|
2000-11-21 18:05:36 +00:00
|
|
|
static void TestUCMP8API(){
|
2002-04-03 17:56:42 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-08-02 00:03:10 +00:00
|
|
|
CompactByteArray* ucmp8Array=NULL;
|
2002-04-03 23:06:38 +00:00
|
|
|
CompactByteArray* pAliaser=NULL;
|
|
|
|
CompactByteArray* pAdopter=NULL;
|
|
|
|
|
|
|
|
CompactByteArray aliaser;
|
|
|
|
CompactByteArray adopter;
|
|
|
|
|
|
|
|
|
2000-12-13 20:45:55 +00:00
|
|
|
CompactByteArray ucmp8Array1;
|
|
|
|
CompactByteArray ucmp8Array2;
|
2002-04-03 17:56:42 +00:00
|
|
|
CompactByteArray ucmp8Clone;
|
2002-04-04 22:33:08 +00:00
|
|
|
int8_t *values;
|
2000-08-11 02:08:59 +00:00
|
|
|
uint8_t *valuesSet;
|
2002-04-05 17:53:25 +00:00
|
|
|
static const int8_t TEST_DEFAULT_VALUE = (int8_t)0xFF;
|
2000-08-02 00:03:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*ucmp8_open*/
|
|
|
|
log_verbose("Testing ucmp8_open()\n");
|
|
|
|
ucmp8Array=ucmp8_open(TEST_DEFAULT_VALUE);
|
|
|
|
if(ucmp8Array == NULL){
|
|
|
|
log_err("ERROR: ucmp8_open() failed\n");
|
|
|
|
}
|
|
|
|
if( (int32_t)ucmp8_getCount(ucmp8Array) != (int32_t)ucmp8_getkUnicodeCount()) {
|
|
|
|
log_err("ERROR: ucmp8_open failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ucmp8_init*/
|
|
|
|
log_verbose("Testing ucmp8_init()\n");
|
2000-12-13 20:45:55 +00:00
|
|
|
ucmp8_init(&ucmp8Array1, TEST_DEFAULT_VALUE);
|
|
|
|
if( (int32_t)ucmp8_getCount(&ucmp8Array1) != (int32_t)ucmp8_getkUnicodeCount() ||
|
|
|
|
ucmp8_getIndex(&ucmp8Array1) == NULL ||
|
|
|
|
ucmp8_getArray(&ucmp8Array1) == NULL ||
|
|
|
|
ucmp8Array1.fBogus != FALSE){
|
2000-08-02 00:03:10 +00:00
|
|
|
log_err("Error: ucmp8_init() failed\n");
|
|
|
|
}
|
|
|
|
/*ucmp8_initBogus*/
|
|
|
|
log_verbose("Testing ucmp8_initBogus()\n");
|
2000-12-13 20:45:55 +00:00
|
|
|
ucmp8_initBogus(&ucmp8Array2);
|
|
|
|
if((int32_t)ucmp8_getCount(&ucmp8Array2) != ucmp8Array2.fCount ||
|
|
|
|
ucmp8_getIndex(&ucmp8Array2) != NULL ||
|
|
|
|
ucmp8_getArray(&ucmp8Array2) != NULL ||
|
|
|
|
ucmp8Array2.fBogus != TRUE){
|
2000-08-02 00:03:10 +00:00
|
|
|
log_err("Error: ucmp8_initBogus() failed\n");
|
|
|
|
}
|
|
|
|
/*ucmp8_getkBlockCount*/
|
|
|
|
if(ucmp8_getkBlockCount() != 128 ){
|
|
|
|
log_err("Error in ucmp8_getkBlockCount()\n");
|
|
|
|
}
|
2002-04-04 22:33:08 +00:00
|
|
|
values=(int8_t*)ucmp8_getArray(&ucmp8Array1);
|
2002-04-05 23:56:18 +00:00
|
|
|
if((uint8_t)values[0] != (uint8_t)TEST_DEFAULT_VALUE){
|
2000-08-02 00:03:10 +00:00
|
|
|
log_err("Error: getArray() or init failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ucmp8_compact*/
|
2000-12-13 20:45:55 +00:00
|
|
|
if(ucmp8Array1.fCompact == TRUE){
|
2000-08-02 00:03:10 +00:00
|
|
|
log_err("Error: ucmp8_open failed Got compact for expanded data\n");
|
|
|
|
}
|
2000-12-13 20:45:55 +00:00
|
|
|
ucmp8_compact(&ucmp8Array1, 1);
|
|
|
|
if(ucmp8Array1.fCompact != TRUE){
|
2000-08-02 00:03:10 +00:00
|
|
|
log_err("Error: ucmp8_compact failed\n");
|
|
|
|
}
|
|
|
|
/*ucmp8_set*/
|
2000-12-13 20:45:55 +00:00
|
|
|
ucmp8_set(&ucmp8Array1, 0, (uint8_t)0xFE);
|
|
|
|
valuesSet=(uint8_t*)ucmp8_getArray(&ucmp8Array1);
|
2000-08-11 02:08:59 +00:00
|
|
|
if(valuesSet[0] != (uint8_t)0xFE ){
|
2000-08-02 00:03:10 +00:00
|
|
|
log_err("ERROR: ucmp8_set() failed\n");
|
|
|
|
}
|
2000-12-13 20:45:55 +00:00
|
|
|
if(ucmp8Array1.fCompact == TRUE){
|
2000-08-02 18:02:16 +00:00
|
|
|
log_err("Error: ucmp8_set didn't expand the compact data \n");
|
|
|
|
}
|
2000-08-02 00:03:10 +00:00
|
|
|
|
|
|
|
/*ucmp8_set*/
|
2000-12-13 20:45:55 +00:00
|
|
|
ucmp8_compact(&ucmp8Array1, 1);
|
|
|
|
ucmp8_set(&ucmp8Array1, 0, (uint8_t)0xFD);
|
|
|
|
valuesSet=(uint8_t*)ucmp8_getArray(&ucmp8Array1);
|
2000-08-11 02:08:59 +00:00
|
|
|
if(valuesSet[0] != (uint8_t)0xFD ){
|
2000-08-02 00:03:10 +00:00
|
|
|
log_err("ERROR: ucmp8_set() failed\n");
|
|
|
|
}
|
2000-12-13 20:45:55 +00:00
|
|
|
if(ucmp8Array1.fCompact == TRUE){
|
2000-08-02 18:02:16 +00:00
|
|
|
log_err("Error: ucmp8_set didn't expand the compact data \n");
|
|
|
|
}
|
2000-08-02 00:03:10 +00:00
|
|
|
/*ucmp8_setRange*/
|
2000-12-13 20:45:55 +00:00
|
|
|
ucmp8_compact(&ucmp8Array1, 1);
|
|
|
|
ucmp8_setRange(&ucmp8Array1, 0, 10, (uint8_t)0xFD);
|
2002-04-03 23:06:38 +00:00
|
|
|
query(&ucmp8Array1);
|
2000-08-02 00:03:10 +00:00
|
|
|
|
2002-04-03 17:56:42 +00:00
|
|
|
log_verbose("Testing ucmp8_flattenMem()\n");
|
|
|
|
{
|
|
|
|
int32_t len = 0;
|
2004-09-17 04:19:30 +00:00
|
|
|
int32_t size = ucmp8_flattenMem(&ucmp8Array1, NULL);
|
|
|
|
uint8_t *buff = malloc(size);
|
2004-09-21 21:01:31 +00:00
|
|
|
uint8_t *buffLocation = buff;
|
2004-09-17 04:19:30 +00:00
|
|
|
len = ucmp8_flattenMem(&ucmp8Array1, buff);
|
2002-04-03 17:56:42 +00:00
|
|
|
|
2004-09-21 21:01:31 +00:00
|
|
|
if(size != len || size == 0 || len == 0 || buff == NULL) {
|
2002-04-03 17:56:42 +00:00
|
|
|
log_err("Unable to flatten!\n");
|
|
|
|
} else {
|
|
|
|
log_verbose("Testing ucmp8_initFromData()\n");
|
2004-10-15 06:23:05 +00:00
|
|
|
ucmp8_initFromData(&ucmp8Clone, (const uint8_t **)&buffLocation, &status);
|
2004-09-21 21:01:31 +00:00
|
|
|
if(U_FAILURE(status) || ucmp8_isBogus(&ucmp8Clone) == TRUE || (buffLocation-buff) != len){
|
2002-04-03 17:56:42 +00:00
|
|
|
log_err("ERROR: ucmp8_initFromData() failed\n");
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
} else {
|
2004-09-21 21:01:31 +00:00
|
|
|
query(&ucmp8Clone);
|
|
|
|
ucmp8_close(&ucmp8Clone);
|
2002-04-03 17:56:42 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-17 04:19:30 +00:00
|
|
|
free(buff);
|
2002-04-03 17:56:42 +00:00
|
|
|
}
|
|
|
|
|
2002-04-03 23:06:38 +00:00
|
|
|
/*
|
|
|
|
openAdopt, initAdopt, openAlias, initAlias
|
|
|
|
*/
|
|
|
|
log_verbose("Testing aliasers and adopters\n");
|
|
|
|
{
|
|
|
|
int32_t count = ucmp8_getCount(&ucmp8Array1);
|
|
|
|
const uint16_t *tIndex = ucmp8_getIndex(&ucmp8Array1);
|
|
|
|
const int8_t *tValues = ucmp8_getArray(&ucmp8Array1);
|
2002-07-29 21:04:18 +00:00
|
|
|
uint16_t *index = (uint16_t *)uprv_malloc(UCMP8_kIndexCount*sizeof(uint16_t));
|
2002-04-04 22:33:08 +00:00
|
|
|
|
2002-07-29 21:04:18 +00:00
|
|
|
values = (int8_t *)uprv_malloc(count);
|
2000-08-02 00:03:10 +00:00
|
|
|
|
2002-04-03 23:06:38 +00:00
|
|
|
memcpy(index, tIndex, UCMP8_kIndexCount*sizeof(uint16_t));
|
|
|
|
memcpy(values, tValues, count);
|
2001-09-18 22:53:27 +00:00
|
|
|
|
2002-04-03 23:06:38 +00:00
|
|
|
ucmp8_initAlias(&aliaser, index, values, count);
|
|
|
|
query(&aliaser);
|
|
|
|
ucmp8_close(&aliaser);
|
2001-09-18 22:53:27 +00:00
|
|
|
|
2002-04-03 23:06:38 +00:00
|
|
|
pAliaser = ucmp8_openAlias(index, values, count);
|
|
|
|
query(pAliaser);
|
|
|
|
ucmp8_close(pAliaser);
|
2001-09-18 22:53:27 +00:00
|
|
|
|
2002-07-29 21:04:18 +00:00
|
|
|
ucmp8_initAdopt(&adopter, index, values, count); /* TODO: BAD API. Adopted memory MUST be allocated with uprv_malloc */
|
2002-04-03 23:06:38 +00:00
|
|
|
query(&adopter);
|
|
|
|
ucmp8_close(&adopter);
|
2001-09-18 22:53:27 +00:00
|
|
|
|
2002-07-29 21:04:18 +00:00
|
|
|
index = (uint16_t *)uprv_malloc(UCMP8_kIndexCount*sizeof(uint16_t));
|
|
|
|
values = (int8_t *)uprv_malloc(count);
|
2001-09-18 22:53:27 +00:00
|
|
|
|
2002-04-03 23:06:38 +00:00
|
|
|
memcpy(index, tIndex, UCMP8_kIndexCount*sizeof(uint16_t));
|
|
|
|
memcpy(values, tValues, count);
|
|
|
|
|
2002-07-29 21:04:18 +00:00
|
|
|
pAdopter = ucmp8_openAdopt(index, values, count); /* TODO: BAD API */
|
2002-04-03 23:06:38 +00:00
|
|
|
query(pAdopter);
|
|
|
|
ucmp8_close(pAdopter);
|
2001-09-18 22:53:27 +00:00
|
|
|
|
2000-08-02 00:03:10 +00:00
|
|
|
}
|
2002-04-03 23:06:38 +00:00
|
|
|
ucmp8_close(&ucmp8Array1);
|
|
|
|
ucmp8_close(&ucmp8Array2);
|
|
|
|
ucmp8_close(ucmp8Array);
|
|
|
|
|
2000-08-15 23:24:07 +00:00
|
|
|
}
|
2002-04-03 23:06:38 +00:00
|
|
|
|
|
|
|
|