diff --git a/icu4c/source/test/cintltst/cbiapts.c b/icu4c/source/test/cintltst/cbiapts.c index 86f3f793f26..c7a24d7d68d 100644 --- a/icu4c/source/test/cintltst/cbiapts.c +++ b/icu4c/source/test/cintltst/cbiapts.c @@ -604,20 +604,23 @@ static void TestBreakIteratorStatusVec() { TEST_ASSET_SUCCESS(status); TEST_ASSERT(bi != NULL); - pos = ubrk_next(bi); - TEST_ASSERT(pos == 1); + /* The TEST_ASSERT above should change too... */ + if (bi != NULL) { + pos = ubrk_next(bi); + TEST_ASSERT(pos == 1); - memset(vals, -1, sizeof(vals)); - numVals = ubrk_getRuleStatusVec(bi, vals, 10, &status); - TEST_ASSET_SUCCESS(status); - TEST_ASSERT(numVals == 2); - TEST_ASSERT(vals[0] == 100); - TEST_ASSERT(vals[1] == 300); - TEST_ASSERT(vals[2] == -1); + memset(vals, -1, sizeof(vals)); + numVals = ubrk_getRuleStatusVec(bi, vals, 10, &status); + TEST_ASSET_SUCCESS(status); + TEST_ASSERT(numVals == 2); + TEST_ASSERT(vals[0] == 100); + TEST_ASSERT(vals[1] == 300); + TEST_ASSERT(vals[2] == -1); - numVals = ubrk_getRuleStatusVec(bi, vals, 0, &status); - TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); - TEST_ASSERT(numVals == 2); + numVals = ubrk_getRuleStatusVec(bi, vals, 0, &status); + TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); + TEST_ASSERT(numVals == 2); + } ubrk_close(bi); } diff --git a/icu4c/source/test/cintltst/cmsccoll.c b/icu4c/source/test/cintltst/cmsccoll.c index 2128391a5a8..b400f960b14 100644 --- a/icu4c/source/test/cintltst/cmsccoll.c +++ b/icu4c/source/test/cintltst/cmsccoll.c @@ -4616,10 +4616,17 @@ static void TestTailorNULL( void ) { rlen = u_unescape(rule, rlz, RULE_BUFFER_LEN); coll = ucol_openRules(rlz, rlen, UCOL_DEFAULT, UCOL_DEFAULT,NULL, &status); - res = ucol_strcoll(coll, &a, 1, &null, 1); - if(res != UCOL_LESS) { - log_err("NULL was not tailored properly!\n"); + + if(U_FAILURE(status)) { + log_err("Could not open default collator!\n"); + } else { + res = ucol_strcoll(coll, &a, 1, &null, 1); + + if(res != UCOL_LESS) { + log_err("NULL was not tailored properly!\n"); + } } + ucol_close(coll); } diff --git a/icu4c/source/test/cintltst/cmsgtst.c b/icu4c/source/test/cintltst/cmsgtst.c index c41eee59557..cae8afb8b84 100644 --- a/icu4c/source/test/cintltst/cmsgtst.c +++ b/icu4c/source/test/cintltst/cmsgtst.c @@ -998,10 +998,11 @@ static void OpenMessageFormatTest(void) umsg_toPattern(f1,result,256,&status); if(U_FAILURE(status) ){ log_err("umsg_toPattern method failed. Error: %s \n",u_errorName(status)); - } - if(u_strcmp(result,pattern)!=0){ - u_UCharsToChars(result,cresult,256); - log_err("umsg_toPattern method failed. Expected: %s Got: %s \n",PAT,cresult); + } else { + if(u_strcmp(result,pattern)!=0){ + u_UCharsToChars(result,cresult,256); + log_err("umsg_toPattern method failed. Expected: %s Got: %s \n",PAT,cresult); + } } /* umsg_format umsg_parse */ diff --git a/icu4c/source/test/cintltst/cnmdptst.c b/icu4c/source/test/cintltst/cnmdptst.c index 5847aefc1ee..8b1f114c18b 100644 --- a/icu4c/source/test/cintltst/cnmdptst.c +++ b/icu4c/source/test/cintltst/cnmdptst.c @@ -417,25 +417,31 @@ static void TestCurrency(void) { str=NULL; currencyFmt = unum_open(UNUM_CURRENCY, NULL,0,locale[i],NULL, &status); + if(U_FAILURE(status)){ log_err("Error in the construction of number format with style currency:\n%s\n", myErrorName(status)); + } else { + lneed=0; + lneed= unum_formatDouble(currencyFmt, 1.50, NULL, lneed, NULL, &status); + if(status==U_BUFFER_OVERFLOW_ERROR){ + status=U_ZERO_ERROR; + str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); + pos.field = 0; + unum_formatDouble(currencyFmt, 1.50, str, lneed+1, &pos, &status); + } + + if(U_FAILURE(status)) { + log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) ); + } else { + u_charsToUChars(result[i], res, (int32_t)strlen(result[i])+1); + + if (u_strcmp(str, res) != 0){ + log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i], aescstrdup(str, -1), locale[i]); + } + } } - lneed=0; - lneed= unum_formatDouble(currencyFmt, 1.50, NULL, lneed, NULL, &status); - if(status==U_BUFFER_OVERFLOW_ERROR){ - status=U_ZERO_ERROR; - str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); - pos.field = 0; - unum_formatDouble(currencyFmt, 1.50, str, lneed+1, &pos, &status); - } - if(U_FAILURE(status)) { - log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) ); - } - u_charsToUChars(result[i], res, (int32_t)strlen(result[i])+1); - if (u_strcmp(str, res) != 0){ - log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i], aescstrdup(str, -1), locale[i]); - } + unum_close(currencyFmt); free(str); } @@ -475,27 +481,33 @@ static void TestCurrencyPreEuro(void) continue; } currencyFmt = unum_open(UNUM_CURRENCY, NULL,0,curID,NULL, &status); + if(U_FAILURE(status)){ log_err("Error in the construction of number format with style currency:\n%s\n", myErrorName(status)); + } else { + lneed=0; + lneed= unum_formatDouble(currencyFmt, 1.50, NULL, lneed, NULL, &status); + + if(status==U_BUFFER_OVERFLOW_ERROR){ + status=U_ZERO_ERROR; + str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); + pos.field = 0; + unum_formatDouble(currencyFmt, 1.50, str, lneed+1, &pos, &status); + } + + if(U_FAILURE(status)) { + log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) ); + } else { + res=(UChar*)malloc(sizeof(UChar) * (strlen(result[i])+1) ); + u_unescape(result[i],res,(int32_t)(strlen(result[i])+1)); + + if (u_strcmp(str, res) != 0){ + log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],aescstrdup(str, -1),locale[i]); + } + } } - lneed=0; - lneed= unum_formatDouble(currencyFmt, 1.50, NULL, lneed, NULL, &status); - if(status==U_BUFFER_OVERFLOW_ERROR){ - status=U_ZERO_ERROR; - str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); - pos.field = 0; - unum_formatDouble(currencyFmt, 1.50, str, lneed+1, &pos, &status); - } - if(U_FAILURE(status)) { - log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) ); - } - res=(UChar*)malloc(sizeof(UChar) * (strlen(result[i])+1) ); - u_unescape(result[i],res,(int32_t)(strlen(result[i])+1)); - if (u_strcmp(str, res) != 0){ - log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],aescstrdup(str, -1),locale[i]); - } - + unum_close(currencyFmt); free(str); free(res); @@ -539,41 +551,47 @@ static void TestCurrencyObject(void) if(U_FAILURE(status)){ log_err("Error in the construction of number format with style currency:\n%s\n", myErrorName(status)); - } - if (*currency[i]) { - u_uastrcpy(isoCode, currency[i]); - unum_setTextAttribute(currencyFmt, UNUM_CURRENCY_CODE, - isoCode, u_strlen(isoCode), &status); - if(U_FAILURE(status)) { - log_err("FAIL: can't set currency code %s\n", myErrorName(status) ); + } else { + if (*currency[i]) { + u_uastrcpy(isoCode, currency[i]); + unum_setTextAttribute(currencyFmt, UNUM_CURRENCY_CODE, + isoCode, u_strlen(isoCode), &status); + + if(U_FAILURE(status)) { + log_err("FAIL: can't set currency code %s\n", myErrorName(status) ); + } + } + + unum_getTextAttribute(currencyFmt, UNUM_CURRENCY_CODE, + isoCode, sizeof(isoCode), &status); + + if(U_FAILURE(status)) { + log_err("FAIL: can't get currency code %s\n", myErrorName(status) ); + } + + u_UCharsToChars(isoCode,cStr,u_strlen(isoCode)); + log_verbose("ISO code %s\n", cStr); + if (*currency[i] && uprv_strcmp(cStr, currency[i])) { + log_err("FAIL: currency should be %s, but is %s\n", currency[i], cStr); + } + + lneed=0; + lneed= unum_formatDouble(currencyFmt, 1234.56, NULL, lneed, NULL, &status); + if(status==U_BUFFER_OVERFLOW_ERROR){ + status=U_ZERO_ERROR; + str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); + pos.field = 0; + unum_formatDouble(currencyFmt, 1234.56, str, lneed+1, &pos, &status); + } + if(U_FAILURE(status)) { + log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) ); + } else { + res=(UChar*)malloc(sizeof(UChar) * (strlen(result[i])+1) ); + u_unescape(result[i],res, (int32_t)(strlen(result[i])+1)); + if (u_strcmp(str, res) != 0){ + log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],aescstrdup(str, -1),locale[i]); + } } - } - unum_getTextAttribute(currencyFmt, UNUM_CURRENCY_CODE, - isoCode, sizeof(isoCode), &status); - if(U_FAILURE(status)) { - log_err("FAIL: can't get currency code %s\n", myErrorName(status) ); - } - u_UCharsToChars(isoCode,cStr,u_strlen(isoCode)); - log_verbose("ISO code %s\n", cStr); - if (*currency[i] && uprv_strcmp(cStr, currency[i])) { - log_err("FAIL: currency should be %s, but is %s\n", currency[i], cStr); - } - - lneed=0; - lneed= unum_formatDouble(currencyFmt, 1234.56, NULL, lneed, NULL, &status); - if(status==U_BUFFER_OVERFLOW_ERROR){ - status=U_ZERO_ERROR; - str=(UChar*)malloc(sizeof(UChar) * (lneed+1) ); - pos.field = 0; - unum_formatDouble(currencyFmt, 1234.56, str, lneed+1, &pos, &status); - } - if(U_FAILURE(status)) { - log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status) ); - } - res=(UChar*)malloc(sizeof(UChar) * (strlen(result[i])+1) ); - u_unescape(result[i],res, (int32_t)(strlen(result[i])+1)); - if (u_strcmp(str, res) != 0){ - log_err("FAIL: Expected %s Got: %s for locale: %s\n", result[i],aescstrdup(str, -1),locale[i]); } unum_close(currencyFmt); @@ -593,16 +611,19 @@ static void TestRounding487(void) - very bad if you try to run the tests on machine where default locale is NOT "en_US" */ /* nnf = unum_open(UNUM_DEFAULT, NULL, &status); */ nnf = unum_open(UNUM_DEFAULT, NULL,0,"en_US",NULL, &status); + if(U_FAILURE(status)){ log_err("FAIL: failure in the construction of number format: %s\n", myErrorName(status)); + } else { + roundingTest(nnf, 0.00159999, 4, "0.0016"); + roundingTest(nnf, 0.00995, 4, "0.01"); + + roundingTest(nnf, 12.3995, 3, "12.4"); + + roundingTest(nnf, 12.4999, 0, "12"); + roundingTest(nnf, - 19.5, 0, "-20"); } - roundingTest(nnf, 0.00159999, 4, "0.0016"); - roundingTest(nnf, 0.00995, 4, "0.01"); - - roundingTest(nnf, 12.3995, 3, "12.4"); - - roundingTest(nnf, 12.4999, 0, "12"); - roundingTest(nnf, - 19.5, 0, "-20"); + unum_close(nnf); } @@ -652,19 +673,26 @@ static void TestDoubleAttribute(void) UNumberFormatAttribute attr; UNumberFormatStyle style= UNUM_DEFAULT; UNumberFormat *def; - def=unum_open(style, NULL,0,NULL,NULL, &status); + log_verbose("\nTesting get and set DoubleAttributes\n"); - attr=UNUM_ROUNDING_INCREMENT; - dvalue=unum_getDoubleAttribute(def, attr); - for (i = 0; i<9 ; i++) - { - dvalue = mydata[i]; - unum_setDoubleAttribute(def, attr, dvalue); - if(unum_getDoubleAttribute(def,attr)!=mydata[i]) - log_err("Fail: error in setting and getting double attributes for UNUM_ROUNDING_INCREMENT\n"); - else - log_verbose("Pass: setting and getting double attributes for UNUM_ROUNDING_INCREMENT works fine\n"); + def=unum_open(style, NULL,0,NULL,NULL, &status); + + if (U_FAILURE(status)) { + log_err("Fail: error creating a default number formatter\n"); + } else { + attr=UNUM_ROUNDING_INCREMENT; + dvalue=unum_getDoubleAttribute(def, attr); + for (i = 0; i<9 ; i++) + { + dvalue = mydata[i]; + unum_setDoubleAttribute(def, attr, dvalue); + if(unum_getDoubleAttribute(def,attr)!=mydata[i]) + log_err("Fail: error in setting and getting double attributes for UNUM_ROUNDING_INCREMENT\n"); + else + log_verbose("Pass: setting and getting double attributes for UNUM_ROUNDING_INCREMENT works fine\n"); + } } + unum_close(def); } diff --git a/icu4c/source/test/cintltst/cnumtst.c b/icu4c/source/test/cintltst/cnumtst.c index c5d8598ab23..9c65ca3f282 100644 --- a/icu4c/source/test/cintltst/cnumtst.c +++ b/icu4c/source/test/cintltst/cnumtst.c @@ -119,8 +119,13 @@ static void TestNumberFormat() status = U_ZERO_ERROR; log_verbose("Testing unum_open() with default style and locale\n"); def=unum_open(style, NULL,0,NULL, NULL,&status); + + /* Might as well pack it in now if we can't even get a default NumberFormat... */ if(U_FAILURE(status)) - log_err("Error in creating NumberFormat default using unum_open(): %s\n", myErrorName(status)); + { + log_err("Error in creating default NumberFormat using unum_open(): %s\n", myErrorName(status)); + return; + } log_verbose("\nTesting unum_open() with french locale and default style(decimal)\n"); fr=unum_open(style,NULL,0, "fr_FR",NULL, &status); diff --git a/icu4c/source/test/cintltst/reapits.c b/icu4c/source/test/cintltst/reapits.c index cf674d7868c..4e3cfb7c330 100644 --- a/icu4c/source/test/cintltst/reapits.c +++ b/icu4c/source/test/cintltst/reapits.c @@ -105,9 +105,13 @@ static void TestRegexCAPI(void) { TEST_ASSERT_SUCCESS(status); p = uregex_pattern(re, &len, &status); TEST_ASSERT_SUCCESS(status); - u_uastrncpy(pat, "abc*", sizeof(pat)/2); - TEST_ASSERT(u_strcmp(pat, p) == 0); - TEST_ASSERT(len==(int32_t)strlen("abc*")); + + /* The TEST_ASSERT_SUCCESS above should change too... */ + if(U_SUCCESS(status)) { + u_uastrncpy(pat, "abc*", sizeof(pat)/2); + TEST_ASSERT(u_strcmp(pat, p) == 0); + TEST_ASSERT(len==(int32_t)strlen("abc*")); + } uregex_close(re); @@ -181,17 +185,28 @@ static void TestRegexCAPI(void) { re = uregex_open(pat, -1, 0, NULL, &status); resultPat = uregex_pattern(re, &resultLen, &status); TEST_ASSERT_SUCCESS(status); - TEST_ASSERT(resultLen == -1); - TEST_ASSERT(u_strcmp(resultPat, pat) == 0); + + /* The TEST_ASSERT_SUCCESS above should change too... */ + if (U_SUCCESS(status)) { + TEST_ASSERT(resultLen == -1); + TEST_ASSERT(u_strcmp(resultPat, pat) == 0); + } + uregex_close(re); status = U_ZERO_ERROR; re = uregex_open(pat, 3, 0, NULL, &status); resultPat = uregex_pattern(re, &resultLen, &status); TEST_ASSERT_SUCCESS(status); - TEST_ASSERT(resultLen == 3); - TEST_ASSERT(u_strncmp(resultPat, pat, 3) == 0); - TEST_ASSERT(u_strlen(resultPat) == 3); + TEST_ASSERT_SUCCESS(status); + + /* The TEST_ASSERT_SUCCESS above should change too... */ + if (U_SUCCESS(status)) { + TEST_ASSERT(resultLen == 3); + TEST_ASSERT(u_strncmp(resultPat, pat, 3) == 0); + TEST_ASSERT(u_strlen(resultPat) == 3); + } + uregex_close(re); } @@ -740,21 +755,29 @@ static void TestRegexCAPI(void) { uregex_setText(re, textToSplit, -1, &status); TEST_ASSERT_SUCCESS(status); - memset(fields, -1, sizeof(fields)); - numFields = - uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 10, &status); - TEST_ASSERT_SUCCESS(status); - TEST_ASSERT(numFields == 3); - TEST_ASSERT_STRING("first ", fields[0], TRUE); - TEST_ASSERT_STRING(" second", fields[1], TRUE); - TEST_ASSERT_STRING(" third", fields[2], TRUE); - TEST_ASSERT(fields[3] == NULL); + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if (U_SUCCESS(status)) { + memset(fields, -1, sizeof(fields)); + numFields = + uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 10, &status); + TEST_ASSERT_SUCCESS(status); - spaceNeeded = u_strlen(textToSplit) - - (numFields - 1) + /* Field delimiters do not appear in output */ - numFields; /* Each field gets a NUL terminator */ + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { + TEST_ASSERT(numFields == 3); + TEST_ASSERT_STRING("first ", fields[0], TRUE); + TEST_ASSERT_STRING(" second", fields[1], TRUE); + TEST_ASSERT_STRING(" third", fields[2], TRUE); + TEST_ASSERT(fields[3] == NULL); + + spaceNeeded = u_strlen(textToSplit) - + (numFields - 1) + /* Field delimiters do not appear in output */ + numFields; /* Each field gets a NUL terminator */ + + TEST_ASSERT(spaceNeeded == requiredCapacity); + } + } - TEST_ASSERT(spaceNeeded == requiredCapacity); uregex_close(re); @@ -764,43 +787,51 @@ static void TestRegexCAPI(void) { uregex_setText(re, textToSplit, -1, &status); TEST_ASSERT_SUCCESS(status); - memset(fields, -1, sizeof(fields)); - numFields = - uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 2, &status); - TEST_ASSERT_SUCCESS(status); - TEST_ASSERT(numFields == 2); - TEST_ASSERT_STRING("first ", fields[0], TRUE); - TEST_ASSERT_STRING(" second: third", fields[1], TRUE); - TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); - - spaceNeeded = u_strlen(textToSplit) - - (numFields - 1) + /* Field delimiters do not appear in output */ - numFields; /* Each field gets a NUL terminator */ - - TEST_ASSERT(spaceNeeded == requiredCapacity); - - /* Split with a range of output buffer sizes. */ - spaceNeeded = u_strlen(textToSplit) - - (numFields - 1) + /* Field delimiters do not appear in output */ - numFields; /* Each field gets a NUL terminator */ - - for (sz=0; sz < spaceNeeded+1; sz++) { + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { memset(fields, -1, sizeof(fields)); - status = U_ZERO_ERROR; numFields = - uregex_split(re, buf, sz, &requiredCapacity, fields, 10, &status); - if (sz >= spaceNeeded) { - TEST_ASSERT_SUCCESS(status); + uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 2, &status); + TEST_ASSERT_SUCCESS(status); + + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { + TEST_ASSERT(numFields == 2); TEST_ASSERT_STRING("first ", fields[0], TRUE); - TEST_ASSERT_STRING(" second", fields[1], TRUE); - TEST_ASSERT_STRING(" third", fields[2], TRUE); - } else { - TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); + TEST_ASSERT_STRING(" second: third", fields[1], TRUE); + TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); + + spaceNeeded = u_strlen(textToSplit) - + (numFields - 1) + /* Field delimiters do not appear in output */ + numFields; /* Each field gets a NUL terminator */ + + TEST_ASSERT(spaceNeeded == requiredCapacity); + + /* Split with a range of output buffer sizes. */ + spaceNeeded = u_strlen(textToSplit) - + (numFields - 1) + /* Field delimiters do not appear in output */ + numFields; /* Each field gets a NUL terminator */ + + for (sz=0; sz < spaceNeeded+1; sz++) { + memset(fields, -1, sizeof(fields)); + status = U_ZERO_ERROR; + numFields = + uregex_split(re, buf, sz, &requiredCapacity, fields, 10, &status); + if (sz >= spaceNeeded) { + TEST_ASSERT_SUCCESS(status); + TEST_ASSERT_STRING("first ", fields[0], TRUE); + TEST_ASSERT_STRING(" second", fields[1], TRUE); + TEST_ASSERT_STRING(" third", fields[2], TRUE); + } else { + TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); + } + TEST_ASSERT(numFields == 3); + TEST_ASSERT(fields[3] == NULL); + TEST_ASSERT(spaceNeeded == requiredCapacity); + } } - TEST_ASSERT(numFields == 3); - TEST_ASSERT(fields[3] == NULL); - TEST_ASSERT(spaceNeeded == requiredCapacity); } + uregex_close(re); } @@ -826,20 +857,26 @@ static void TestRegexCAPI(void) { uregex_setText(re, textToSplit, -1, &status); TEST_ASSERT_SUCCESS(status); - memset(fields, -1, sizeof(fields)); - numFields = - uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 10, &status); - TEST_ASSERT_SUCCESS(status); - TEST_ASSERT(numFields == 5); - TEST_ASSERT_STRING("first ", fields[0], TRUE); - TEST_ASSERT_STRING("tag-a", fields[1], TRUE); - TEST_ASSERT_STRING(" second", fields[2], TRUE); - TEST_ASSERT_STRING("tag-b", fields[3], TRUE); - TEST_ASSERT_STRING(" third", fields[4], TRUE); - TEST_ASSERT(fields[5] == NULL); - spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /* "." at NUL positions */ - TEST_ASSERT(spaceNeeded == requiredCapacity); + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { + memset(fields, -1, sizeof(fields)); + numFields = + uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 10, &status); + TEST_ASSERT_SUCCESS(status); + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { + TEST_ASSERT(numFields == 5); + TEST_ASSERT_STRING("first ", fields[0], TRUE); + TEST_ASSERT_STRING("tag-a", fields[1], TRUE); + TEST_ASSERT_STRING(" second", fields[2], TRUE); + TEST_ASSERT_STRING("tag-b", fields[3], TRUE); + TEST_ASSERT_STRING(" third", fields[4], TRUE); + TEST_ASSERT(fields[5] == NULL); + spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /* "." at NUL positions */ + TEST_ASSERT(spaceNeeded == requiredCapacity); + } + } /* Split with too few output strings available (2) */ status = U_ZERO_ERROR; @@ -847,13 +884,17 @@ static void TestRegexCAPI(void) { numFields = uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 2, &status); TEST_ASSERT_SUCCESS(status); - TEST_ASSERT(numFields == 2); - TEST_ASSERT_STRING("first ", fields[0], TRUE); - TEST_ASSERT_STRING(" second third", fields[1], TRUE); - TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); - spaceNeeded = strlen("first . second third."); /* "." at NUL positions */ - TEST_ASSERT(spaceNeeded == requiredCapacity); + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { + TEST_ASSERT(numFields == 2); + TEST_ASSERT_STRING("first ", fields[0], TRUE); + TEST_ASSERT_STRING(" second third", fields[1], TRUE); + TEST_ASSERT(!memcmp(&fields[2],&minus1,sizeof(UChar*))); + + spaceNeeded = strlen("first . second third."); /* "." at NUL positions */ + TEST_ASSERT(spaceNeeded == requiredCapacity); + } /* Split with too few output strings available (3) */ status = U_ZERO_ERROR; @@ -861,14 +902,18 @@ static void TestRegexCAPI(void) { numFields = uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 3, &status); TEST_ASSERT_SUCCESS(status); - TEST_ASSERT(numFields == 3); - TEST_ASSERT_STRING("first ", fields[0], TRUE); - TEST_ASSERT_STRING("tag-a", fields[1], TRUE); - TEST_ASSERT_STRING(" second third", fields[2], TRUE); - TEST_ASSERT(!memcmp(&fields[3],&minus1,sizeof(UChar*))); - spaceNeeded = strlen("first .tag-a. second third."); /* "." at NUL positions */ - TEST_ASSERT(spaceNeeded == requiredCapacity); + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { + TEST_ASSERT(numFields == 3); + TEST_ASSERT_STRING("first ", fields[0], TRUE); + TEST_ASSERT_STRING("tag-a", fields[1], TRUE); + TEST_ASSERT_STRING(" second third", fields[2], TRUE); + TEST_ASSERT(!memcmp(&fields[3],&minus1,sizeof(UChar*))); + + spaceNeeded = strlen("first .tag-a. second third."); /* "." at NUL positions */ + TEST_ASSERT(spaceNeeded == requiredCapacity); + } /* Split with just enough output strings available (5) */ status = U_ZERO_ERROR; @@ -876,37 +921,48 @@ static void TestRegexCAPI(void) { numFields = uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 5, &status); TEST_ASSERT_SUCCESS(status); - TEST_ASSERT(numFields == 5); - TEST_ASSERT_STRING("first ", fields[0], TRUE); - TEST_ASSERT_STRING("tag-a", fields[1], TRUE); - TEST_ASSERT_STRING(" second", fields[2], TRUE); - TEST_ASSERT_STRING("tag-b", fields[3], TRUE); - TEST_ASSERT_STRING(" third", fields[4], TRUE); - TEST_ASSERT(!memcmp(&fields[5],&minus1,sizeof(UChar*))); - spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /* "." at NUL positions */ - TEST_ASSERT(spaceNeeded == requiredCapacity); + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { + TEST_ASSERT(numFields == 5); + TEST_ASSERT_STRING("first ", fields[0], TRUE); + TEST_ASSERT_STRING("tag-a", fields[1], TRUE); + TEST_ASSERT_STRING(" second", fields[2], TRUE); + TEST_ASSERT_STRING("tag-b", fields[3], TRUE); + TEST_ASSERT_STRING(" third", fields[4], TRUE); + TEST_ASSERT(!memcmp(&fields[5],&minus1,sizeof(UChar*))); + spaceNeeded = strlen("first .tag-a. second.tag-b. third."); /* "." at NUL positions */ + TEST_ASSERT(spaceNeeded == requiredCapacity); + } /* Split, end of text is a field delimiter. */ status = U_ZERO_ERROR; sz = strlen("first second"); uregex_setText(re, textToSplit, sz, &status); TEST_ASSERT_SUCCESS(status); - memset(fields, -1, sizeof(fields)); - numFields = - uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 9, &status); - TEST_ASSERT_SUCCESS(status); - TEST_ASSERT(numFields == 4); - TEST_ASSERT_STRING("first ", fields[0], TRUE); - TEST_ASSERT_STRING("tag-a", fields[1], TRUE); - TEST_ASSERT_STRING(" second", fields[2], TRUE); - TEST_ASSERT_STRING("tag-b", fields[3], TRUE); - TEST_ASSERT(fields[4] == NULL); - TEST_ASSERT(fields[8] == NULL); - TEST_ASSERT(!memcmp(&fields[9],&minus1,sizeof(UChar*))); - spaceNeeded = strlen("first .tag-a. second.tag-b."); /* "." at NUL positions */ - TEST_ASSERT(spaceNeeded == requiredCapacity); + + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { + memset(fields, -1, sizeof(fields)); + numFields = + uregex_split(re, buf, sizeof(buf)/2, &requiredCapacity, fields, 9, &status); + TEST_ASSERT_SUCCESS(status); + + /* The TEST_ASSERT_SUCCESS call above should change too... */ + if(U_SUCCESS(status)) { + TEST_ASSERT(numFields == 4); + TEST_ASSERT_STRING("first ", fields[0], TRUE); + TEST_ASSERT_STRING("tag-a", fields[1], TRUE); + TEST_ASSERT_STRING(" second", fields[2], TRUE); + TEST_ASSERT_STRING("tag-b", fields[3], TRUE); + TEST_ASSERT(fields[4] == NULL); + TEST_ASSERT(fields[8] == NULL); + TEST_ASSERT(!memcmp(&fields[9],&minus1,sizeof(UChar*))); + spaceNeeded = strlen("first .tag-a. second.tag-b."); /* "." at NUL positions */ + TEST_ASSERT(spaceNeeded == requiredCapacity); + } + } uregex_close(re); }