ICU-2118 improve API coverage

X-SVN-Rev: 10393
This commit is contained in:
Ram Viswanadha 2002-11-27 02:11:42 +00:00
parent e42c1d0b80
commit 6996158d17
13 changed files with 447 additions and 17 deletions

View file

@ -37,11 +37,11 @@ T_FileStream_open(const char* filename, const char* mode)
}
}
/*
U_CAPI FileStream* U_EXPORT2
T_FileStream_wopen(const wchar_t* filename, const wchar_t* mode)
{
/* TBD: _wfopen is believed to be MS-specific? */
// TBD: _wfopen is believed to be MS-specific?
#if defined(WIN32) && !defined(__WINDOWS__)
FILE* result = _wfopen(filename, mode);
return (FileStream*)result;
@ -50,7 +50,7 @@ T_FileStream_wopen(const wchar_t* filename, const wchar_t* mode)
char *fn, *md;
FILE *result;
/* convert from wchar_t to char */
// convert from wchar_t to char
fnMbsSize = wcstombs(NULL, filename, ((size_t)-1) >> 1);
fn = (char*)uprv_malloc(fnMbsSize+2);
wcstombs(fn, filename, fnMbsSize);
@ -67,7 +67,7 @@ T_FileStream_wopen(const wchar_t* filename, const wchar_t* mode)
return (FileStream*)result;
#endif
}
*/
U_CAPI void U_EXPORT2
T_FileStream_close(FileStream* fileStream)
{
@ -211,5 +211,9 @@ T_FileStream_stderr(void)
return (FileStream*)stderr;
}
U_CAPI UBool U_EXPORT2
T_FileStream_remove(const char* fileName){
return (remove(fileName) == 0);
}

View file

@ -34,9 +34,10 @@ typedef struct _FileStream FileStream;
U_CAPI FileStream* U_EXPORT2
T_FileStream_open(const char* filename, const char* mode);
/*
U_CAPI FileStream* U_EXPORT2
T_FileStream_wopen(const wchar_t* filename, const wchar_t* mode);
*/
U_CAPI void U_EXPORT2
T_FileStream_close(FileStream* fileStream);
@ -97,6 +98,8 @@ T_FileStream_stdout(void);
U_CAPI FileStream* U_EXPORT2
T_FileStream_stderr(void);
U_CAPI UBool U_EXPORT2
T_FileStream_remove(const char* fileName);
#endif /* _FILESTRM*/

View file

@ -3390,6 +3390,17 @@ _MBCSFromUChar32(UConverterSharedData *sharedData,
}
}
#if 0
/**
* ################################################################
* #
* # This function has been moved to ucnv2022.c for inlining.
* # This implementation is here only for documentation purposes
* #
* ################################################################
*/
/**
* This version of _MBCSFromUChar32() is optimized for single-byte codepages.
* It does not handle the EBCDIC swaplfnl option (set in UConverter).
@ -3420,6 +3431,7 @@ _MBCSSingleFromUChar32(UConverterSharedData *sharedData,
return -1;
}
}
#endif
/* miscellaneous ------------------------------------------------------------ */

View file

@ -19,6 +19,8 @@
#include "cintltst.h"
#include "unicode/ustring.h"
#include "cstring.h"
#include "filestrm.h"
#include "cmemory.h"
#define RESTEST_HEAP_CHECK 0
@ -28,7 +30,7 @@
static void TestOpenDirect(void);
static void TestFallback(void);
static void TestFileStream(void);
/*****************************************************************************/
const UChar kERROR[] = { 0x0045 /*E*/, 0x0052 /*'R'*/, 0x0052 /*'R'*/,
@ -91,7 +93,7 @@ void addResourceBundleTest(TestNode** root)
addTest(root, &TestResourceBundles, "tsutil/crestst/TestResourceBundle");
addTest(root, &TestFallback, "tsutil/crestst/TestFallback");
addTest(root, &TestAliasConflict, "tsutil/crestst/TestAliasConflict");
addTest(root, &TestFileStream, "tsutil/crestst/TestFileStream");
#ifdef ICU_URES_USE_DEPRECATES
addTest(root, &TestConstruction2, "tsutil/crestst/TestConstruction2");
#endif
@ -574,3 +576,100 @@ TestOpenDirect(void) {
ures_close(translit_index);
}
static void TestFileStream(void){
int32_t c = 0;
int32_t c1=0;
UErrorCode status = U_ZERO_ERROR;
const char* testdatapath = loadTestData(&status);
char* fileName = (char*) uprv_malloc(uprv_strlen(testdatapath) +10);
FileStream* stream = NULL;
/* these should not be closed */
FileStream* pStdin = T_FileStream_stdin();
FileStream* pStdout = T_FileStream_stdout();
FileStream* pStderr = T_FileStream_stderr();
const char* testline = "This is a test line";
int32_t bufLen =uprv_strlen(testline)+10;
char* buf = (char*) uprv_malloc(bufLen);
int32_t retLen = 0;
uprv_strcpy(fileName,testdatapath);
uprv_strcat(fileName,".dat");
stream = T_FileStream_open(fileName, "r");
if(stream==NULL){
log_data_err("T_FileStream_open failed to open %s\n",fileName);
}
if(!T_FileStream_file_exists(fileName)){
log_data_err("T_FileStream_file_exists failed to verify existence of %s \n",fileName);
}
T_FileStream_read(stream,&c,1);
if(c==0){
log_data_err("T_FileStream_read failed to read from %s \n",fileName);
}
T_FileStream_rewind(stream);
T_FileStream_read(stream,&c1,1);
if(c!=c1){
log_data_err("T_FileStream_rewind failed to rewind %s \n",fileName);
}
T_FileStream_rewind(stream);
c1 = T_FileStream_peek(stream);
if(c!=c1){
log_data_err("T_FileStream_peek failed to peekd %s \n",fileName);
}
c = T_FileStream_getc(stream);
T_FileStream_ungetc(c,stream);
if(c!= T_FileStream_getc(stream)){
log_data_err("T_FileStream_ungetc failed to d %s \n",fileName);
}
if(T_FileStream_size(stream)<=0){
log_data_err("T_FileStream_size failed to d %s \n",fileName);
}
T_FileStream_close(stream);
/* test writing function */
stream=NULL;
uprv_strcpy(fileName,testdatapath);
uprv_strcat(fileName,".tmp");
stream = T_FileStream_open(fileName,"w+r");
if(stream == NULL){
log_data_err("Could not open %s for writing\n",fileName);
}
c= '$';
T_FileStream_putc(stream,c);
T_FileStream_rewind(stream);
if(c != T_FileStream_getc(stream)){
log_data_err("T_FileStream_putc failed %s\n",fileName);
}
T_FileStream_rewind(stream);
T_FileStream_writeLine(stream,testline);
T_FileStream_rewind(stream);
T_FileStream_readLine(stream,buf,bufLen);
if(uprv_strncmp(testline, buf,uprv_strlen(buf))!=0){
log_data_err("T_FileStream_writeLine failed %s\n",fileName);
}
T_FileStream_rewind(stream);
T_FileStream_write(stream,testline,uprv_strlen(testline));
T_FileStream_rewind(stream);
retLen = T_FileStream_read(stream, buf, bufLen);
if(uprv_strncmp(testline, buf,retLen)!=0){
log_data_err("T_FileStream_write failed %s\n",fileName);
}
T_FileStream_close(stream);
T_FileStream_setError(stream);
if(!T_FileStream_remove(fileName)){
log_data_err("T_FileStream_remove failed to delete %s\n",fileName);
}
uprv_free(fileName);
uprv_free(buf);
}

View file

@ -203,7 +203,74 @@ Checks LetterLike Symbols which were previously a source of confusion
}
}
log_verbose("done testing upper Lower\n");
log_verbose("testing u_istitle\n");
{
UChar expected[] = {
0x1F88,
0x1F89,
0x1F8A,
0x1F8B,
0x1F8C,
0x1F8D,
0x1F8E,
0x1F8F,
0x1F88,
0x1F89,
0x1F8A,
0x1F8B,
0x1F8C,
0x1F8D,
0x1F8E,
0x1F8F,
0x1F98,
0x1F99,
0x1F9A,
0x1F9B,
0x1F9C,
0x1F9D,
0x1F9E,
0x1F9F,
0x1F98,
0x1F99,
0x1F9A,
0x1F9B,
0x1F9C,
0x1F9D,
0x1F9E,
0x1F9F,
0x1FA8,
0x1FA9,
0x1FAA,
0x1FAB,
0x1FAC,
0x1FAD,
0x1FAE,
0x1FAF,
0x1FA8,
0x1FA9,
0x1FAA,
0x1FAB,
0x1FAC,
0x1FAD,
0x1FAE,
0x1FAF,
0x1FBC,
0x1FBC,
0x1FCC,
0x1FCC,
0x1FFC,
0x1FFC,
};
int32_t num = sizeof(expected)/sizeof(expected[0]);
int32_t i=0;
for(;i<num;i++){
if(!u_istitle(expected[i])){
log_err("u_istitle failed for 0x%4X. Expected TRUE, got FALSE\n",expected[i]);
}
}
}
}
@ -428,6 +495,15 @@ static void TestMisc()
if(mask!=(U_CHAR_CATEGORY_COUNT<32 ? U_MASK(U_CHAR_CATEGORY_COUNT)-1: 0xffffffff)) {
log_err("error: problems with U_GC_Y_MASK constants\n");
}
{
UChar32 digit[10]={ 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039 };
int32_t i=0;
for(i=0;i<10;i++){
if(digit[i]!=u_forDigit(i,10)){
log_err("u_forDigit failed for %i. Expected: 0x%4X Got: 0x%4X\n",i,digit[i],u_forDigit(i,10));
}
}
}
}
/* Tests for isControl(u_iscntrl()) and isPrintable(u_isprint()) */
@ -2372,3 +2448,4 @@ TestPropertyValues(void) {
}
}
}

View file

@ -2808,7 +2808,25 @@ UBool testConvertFromUnicode(const UChar *source, int sourceLen, const uint8_t
&status);
} while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (sourceLimit < realSourceEnd)) );
/* allow failure codes for the stop callback */
if(status==U_INVALID_CHAR_FOUND || status == U_ILLEGAL_CHAR_FOUND){
UChar errChars[50]; /* should be sufficient */
int8_t len = 50;
UErrorCode err = U_ZERO_ERROR;
const UChar* limit= NULL;
const UChar* start= NULL;
ucnv_getInvalidUChars(conv,errChars, &len, &err);
if(U_FAILURE(err)){
log_err("ucnv_getInvalidUChars failed with error : %s\n",u_errorName(err));
}
/* src points to limit of invalid chars */
limit = src;
/* length of in invalid chars should be equal to returned length*/
start = src - len;
if(u_strncmp(errChars,start,len)!=0){
log_err("ucnv_getInvalidUChars did not return the correct invalid chars for encoding %s \n", ucnv_getName(conv,&err));
}
}
/* allow failure codes for the stop callback */
if(U_FAILURE(status) &&
(callback != UCNV_FROM_U_CALLBACK_STOP || (status != U_INVALID_CHAR_FOUND && status != U_ILLEGAL_CHAR_FOUND)))
{
@ -2986,7 +3004,25 @@ UBool testConvertToUnicode( const uint8_t *source, int sourcelen, const UChar *e
(UBool)(srcLimit == realSourceEnd), /* flush if we're at the end of the source data */
&status);
} while ( (status == U_BUFFER_OVERFLOW_ERROR) || (U_SUCCESS(status) && (srcLimit < realSourceEnd)) ); /* while we just need another buffer */
if(status==U_INVALID_CHAR_FOUND || status == U_ILLEGAL_CHAR_FOUND){
char errChars[50]; /* should be sufficient */
int8_t len = 50;
UErrorCode err = U_ZERO_ERROR;
const uint8_t* limit= NULL;
const uint8_t* start= NULL;
ucnv_getInvalidChars(conv,errChars, &len, &err);
if(U_FAILURE(err)){
log_err("ucnv_getInvalidChars failed with error : %s\n",u_errorName(err));
}
/* src points to limit of invalid chars */
limit = src;
/* length of in invalid chars should be equal to returned length*/
start = src - len;
if(uprv_strncmp(errChars,(char*)start,len)!=0){
log_err("ucnv_getInvalidChars did not return the correct invalid chars for encoding %s \n", ucnv_getName(conv,&err));
}
}
/* allow failure codes for the stop callback */
if(U_FAILURE(status) &&
(callback != UCNV_TO_U_CALLBACK_STOP || (status != U_INVALID_CHAR_FOUND && status != U_ILLEGAL_CHAR_FOUND && status != U_TRUNCATED_CHAR_FOUND)))

View file

@ -735,10 +735,10 @@ static void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize )
const uint8_t expectedMaltese913[] = { 0x53, 0x61, 0xB1, 0xB1, 0x61 };
/* LMBCS */
const UChar LMBCSUChars[] = { 0x0027, 0x010A, 0x0000, 0x0127, 0x2666 };
const uint8_t expectedLMBCS[] = { 0x27, 0x06, 0x04, 0x00, 0x01, 0x73, 0x01, 0x04 };
int32_t toLMBCSOffs[] = { 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x04 };
int32_t fmLMBCSOffs[] = { 0x0000, 0x0001, 0x0003, 0x0004, 0x0006};
const UChar LMBCSUChars[] = { 0x0027, 0x010A, 0x0000, 0x0127, 0x2666, 0x0220 };
const uint8_t expectedLMBCS[] = { 0x27, 0x06, 0x04, 0x00, 0x01, 0x73, 0x01, 0x04, 0x14, 0x02, 0x20 };
int32_t toLMBCSOffs[] = { 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x04 , 0x05, 0x05, 0x05 };
int32_t fmLMBCSOffs[] = { 0x0000, 0x0001, 0x0003, 0x0004, 0x0006, 0x0008};
/*********************************** START OF CODE finally *************/
gInBufferSize = insize;

View file

@ -68,7 +68,10 @@ void CanonicalIteratorTest::TestExhaustive() {
CanonicalIterator it("", status);
UChar32 i = 0;
UnicodeString s, decomp, comp;
// Test static and dynamic class IDs
if(it.getDynamicClassID() != CanonicalIterator::getStaticClassID()){
errln("CanonicalIterator::getStaticClassId ! = CanonicalIterator.getDynamicClassID");
}
for (i = 0; i < 0x10FFFF; quick?i+=0x10:++i) {
//for (i = 0xae00; i < 0xaf00; ++i) {

View file

@ -72,7 +72,9 @@ void CharIterTest::TestConstructionAndEquality() {
if (test1->hashCode() != test5->hashCode())
errln("hashCode() failed: identical objects have different hash codes");
if(test1->getLength() != testText.length()){
errln("getLength of CharacterIterator failed");
}
test1->getText(result1);
test1b->getText(result2);
test1c->getText(result3);

View file

@ -187,7 +187,7 @@ void NewResourceBundleTest::runIndexedTest( int32_t index, UBool exec, const cha
case 1: name = "TestConstruction"; if (exec) TestConstruction(); break;
case 2: name = "TestIteration"; if (exec) TestIteration(); break;
case 3: name = "TestOtherAPI"; if(exec) TestOtherAPI(); break;
case 4: name = "TestNewTypes"; if(exec) TestNewTypes(); break;
default: name = ""; break; //needed to end loop
}
}
@ -962,5 +962,153 @@ NewResourceBundleTest::record_fail()
err();
++fail;
}
void
NewResourceBundleTest::TestNewTypes() {
char action[256];
const char* testdatapath;
UErrorCode status = U_ZERO_ERROR;
uint8_t *binResult = NULL;
int32_t len = 0;
int32_t i = 0;
int32_t intResult = 0;
uint32_t uintResult = 0;
UChar expected[] = { 'a','b','c','\0','d','e','f' };
const char* expect ="tab:\t cr:\r ff:\f newline:\n backslash:\\\\ quote=\\\' doubleQuote=\\\" singlequoutes=''";
UChar uExpect[200];
testdatapath=loadTestData(status);
if(U_FAILURE(status))
{
logln("Could not load testdata.dat %s \n",u_errorName(status));
return;
}
ResourceBundle theBundle(testdatapath, "testtypes", status);
ResourceBundle bundle(testdatapath, Locale("te_IN"),status);
UnicodeString emptyStr = theBundle.getStringEx("emptystring", status);
if(!emptyStr.length()==0) {
logln("Empty string returned invalid value\n");
}
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
/* This test reads the string "abc\u0000def" from the bundle */
/* if everything is working correctly, the size of this string */
/* should be 7. Everything else is a wrong answer, esp. 3 and 6*/
strcpy(action, "getting and testing of string with embeded zero");
ResourceBundle res = theBundle.get("zerotest", status);
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(res.getType(), RES_STRING);
UnicodeString zeroString=res.getString(status);
if(U_SUCCESS(status)){
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(len, 7);
CONFIRM_NE(len, 3);
}
for(i=0;i<len;i++){
if(zeroString[i]!= expected[i]){
logln("Output didnot match Expected: \\u%4X Got: \\u%4X", expected[i], zeroString[i]);
}
}
strcpy(action, "getting and testing of binary type");
res = theBundle.get("binarytest", status);
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(res.getType(), RES_BINARY);
binResult=(uint8_t*)res.getBinary(len, status);
if(U_SUCCESS(status)){
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(len, 15);
for(i = 0; i<15; i++) {
CONFIRM_EQ(binResult[i], i);
}
}
strcpy(action, "getting and testing of imported binary type");
res = theBundle.get("importtest",status);
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(res.getType(), RES_BINARY);
binResult=(uint8_t*)res.getBinary(len, status);
if(U_SUCCESS(status)){
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(len, 15);
for(i = 0; i<15; i++) {
CONFIRM_EQ(binResult[i], i);
}
}
strcpy(action, "getting and testing of integer types");
res = theBundle.get("one", status);
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(res.getType(), RES_INT);
intResult=res.getInt(status);
uintResult = res.getUInt(status);
if(U_SUCCESS(status)){
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(uintResult, (uint32_t)intResult);
CONFIRM_EQ(intResult, 1);
}
strcpy(action, "getting minusone");
res = theBundle.get((const char*)"minusone", status);
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(res.getType(), RES_INT);
intResult=res.getInt(status);
uintResult = res.getUInt(status);
if(U_SUCCESS(status)){
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(uintResult, 0x0FFFFFFF); /* a 28 bit integer */
CONFIRM_EQ(intResult, -1);
CONFIRM_NE(uintResult, (uint32_t)intResult);
}
strcpy(action, "getting plusone");
res = theBundle.get("plusone",status);
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(res.getType(), RES_INT);
intResult=res.getInt(status);
uintResult = res.getUInt(status);
if(U_SUCCESS(status)){
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(uintResult, (uint32_t)intResult);
CONFIRM_EQ(intResult, 1);
}
res = theBundle.get("onehundredtwentythree",status);
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(res.getType(), RES_INT);
intResult=res.getInt(status);
if(U_SUCCESS(status)){
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
CONFIRM_EQ(intResult, 123);
}
/* this tests if escapes are preserved or not */
{
UnicodeString str = theBundle.getStringEx("testescape",status);
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
if(U_SUCCESS(status)){
if(str.compare(uExpect)!=0){
errln("Did not get the expected string for testescape\n");
}
}
}
/* test for jitterbug#1435 */
{
UnicodeString str = theBundle.getStringEx("test_underscores",status);
expect ="test message ....";
CONFIRM_UErrorCode(status, U_ZERO_ERROR);
if(str.compare(uExpect)!=0){
errln("Did not get the expected string for test_underscores.\n");
}
}
}
//eof

View file

@ -32,6 +32,8 @@ public:
void TestOtherAPI(void);
void TestNewTypes(void);
private:
/**
* The assignment operator has no real implementation.

View file

@ -638,6 +638,10 @@ BasicNormalizerTest::TestPreviousNext() {
// iterators
Normalizer iter(src, sizeof(src)/U_SIZEOF_UCHAR, UNORM_NFD);
// test getStaticClassID and getDynamicClassID
if(iter.getDynamicClassID() != Normalizer::getStaticClassID()){
errln("getStaticClassID != getDynamicClassID for Normalizer.");
}
UChar32Iterator iter32(expect, sizeof(expect)/4, EXPECT_MIDDLE);
UChar32 c1, c2;

View file

@ -777,6 +777,16 @@ TimeZoneTest::TestDisplayName()
errln("Fail: Expected " + UnicodeString(kData[i].expect) + "; got " + name);
logln("PST [with options]->" + name);
}
for (i=0; kData[i].expect[0] != '\0'; i++)
{
name.remove();
name = zone->getDisplayName(kData[i].useDst,
kData[i].style, name);
if (name.compare(kData[i].expect) != 0)
errln("Fail: Expected " + UnicodeString(kData[i].expect) + "; got " + name);
logln("PST [with options]->" + name);
}
// Make sure that we don't display the DST name by constructing a fake
// PST zone that has DST all year long.
@ -852,7 +862,14 @@ TimeZoneTest::TestDisplayName()
name.compare("GMT+0130") &&
name.compare("GMT+130"))
errln("Fail: Expected GMT+01:30 or something similar");
name.truncate(0);
zone2->getDisplayName(name);
logln("GMT+90min->" + name);
if (name.compare("GMT+01:30") &&
name.compare("GMT+1:30") &&
name.compare("GMT+0130") &&
name.compare("GMT+130"))
errln("Fail: Expected GMT+01:30 or something similar");
// clean up
delete zone;
delete zone2;
@ -1039,6 +1056,29 @@ void TimeZoneTest::TestCountries() {
errln("FAIL: " + laZone + " in JP = " + la);
errln("FAIL: " + tokyoZone + " in JP = " + tokyo);
}
StringEnumeration* s1 = TimeZone::createEnumeration("US");
StringEnumeration* s2 = TimeZone::createEnumeration("US");
for(i=0;i<n;++i){
const UnicodeString* id1 = s1->snext(ec);
if(id1==NULL || U_FAILURE(ec)){
errln("Failed to fetch next from TimeZone enumeration. Length returned : %i Current Index: %i", n,i);
}
TimeZone* tz1 = TimeZone::createTimeZone(*id1);
for(int j=0; j<n;++j){
const UnicodeString* id2 = s2->snext(ec);
if(id2==NULL || U_FAILURE(ec)){
errln("Failed to fetch next from TimeZone enumeration. Length returned : %i Current Index: %i", n,i);
}
TimeZone* tz2 = TimeZone::createTimeZone(*id2);
if(tz1->hasSameRules(*tz2)){
logln("ID1 : " + *id1+" == ID2 : " +*id2);
}
delete tz2;
}
delete tz1;
}
delete s1;
delete s2;
delete s;
}