From 4ced8981208a1605339b43f4a3b80faf96dbc572 Mon Sep 17 00:00:00 2001 From: Ram Viswanadha Date: Fri, 20 Oct 2000 02:47:14 +0000 Subject: [PATCH] ICU-673 Added tests for short target and source buffers X-SVN-Rev: 2746 --- icu4c/source/test/cintltst/nucnvtst.c | 144 +++++++++++++++++++++++++- 1 file changed, 140 insertions(+), 4 deletions(-) diff --git a/icu4c/source/test/cintltst/nucnvtst.c b/icu4c/source/test/cintltst/nucnvtst.c index ce93db40f1b..7f1be5a6a6f 100644 --- a/icu4c/source/test/cintltst/nucnvtst.c +++ b/icu4c/source/test/cintltst/nucnvtst.c @@ -1306,6 +1306,136 @@ void TestISO_2022_JP_Next() { +} +void +TestSmallTargetBuffer(const uint16_t* source, const UChar* sourceLimit,UConverter* cnv, char* cnvName){ + const UChar* uSource; + const UChar* uSourceLimit; + const char* cSource; + const char* cSourceLimit; + UChar *uTargetLimit =NULL; + UChar *uTarget; + char *cTarget; + const char *cTargetLimit; + char *cBuf; + UChar *uBuf,*test; + int32_t uBufSize = 120; + int len=0; + UErrorCode errorCode=U_ZERO_ERROR; + uBuf = (UChar*)malloc(uBufSize * sizeof(UChar)*5); + cBuf =(char*)malloc(uBufSize * sizeof(char) * 10); + uSource = (UChar*) source; + uSourceLimit=(const UChar*)sourceLimit; + cTarget = cBuf; + uTarget = uBuf; + cSource = cBuf; + cTargetLimit = cBuf; + uTargetLimit = uBuf; + + + do{ + + cTargetLimit = cTargetLimit+ 1; + ucnv_fromUnicode( cnv , &cTarget, cTargetLimit,&uSource,uSourceLimit,NULL,FALSE, &errorCode); + if(errorCode==U_BUFFER_OVERFLOW_ERROR){ + errorCode=U_ZERO_ERROR; + continue; + } + + if(U_FAILURE(errorCode)){ + log_err("ucnv_toUnicode conversion failed reason %s\n", u_errorName(errorCode)); + return; + } + + }while (uSource