From bf8b9dad77b494d4a803329a50258d41867e7a27 Mon Sep 17 00:00:00 2001 From: Ram Viswanadha Date: Thu, 30 Jun 2005 22:45:24 +0000 Subject: [PATCH] ICU-4452 improve api coverage X-SVN-Rev: 18103 --- icu4c/source/test/cintltst/capitst.c | 51 +++++++++++++++++ icu4c/source/test/cintltst/capitst.h | 7 ++- icu4c/source/test/cintltst/usettest.c | 10 +++- icu4c/source/test/intltest/calregts.cpp | 5 +- icu4c/source/test/intltest/itrbnf.cpp | 23 ++++++-- icu4c/source/test/intltest/numfmtst.cpp | 53 ++++++++++++++++++ icu4c/source/test/intltest/numfmtst.h | 4 ++ icu4c/source/test/intltest/tchcfmt.cpp | 10 +++- icu4c/source/test/intltest/tfsmalls.cpp | 73 ++++++++++++++++++++++--- icu4c/source/test/intltest/transtst.cpp | 8 +++ 10 files changed, 227 insertions(+), 17 deletions(-) diff --git a/icu4c/source/test/cintltst/capitst.c b/icu4c/source/test/cintltst/capitst.c index 39a4588626..9f5049f071 100644 --- a/icu4c/source/test/cintltst/capitst.c +++ b/icu4c/source/test/cintltst/capitst.c @@ -114,6 +114,7 @@ void addCollAPITest(TestNode** root) /*addTest(root, &TestGetDefaultRules, "tscoll/capitst/TestGetDefaultRules");*/ addTest(root, &TestDecomposition, "tscoll/capitst/TestDecomposition"); addTest(root, &TestSafeClone, "tscoll/capitst/TestSafeClone"); + addTest(root, &TestCloneBinary, "tscoll/capitst/TestCloneBinary"); addTest(root, &TestGetSetAttr, "tscoll/capitst/TestGetSetAttr"); addTest(root, &TestBounds, "tscoll/capitst/TestBounds"); addTest(root, &TestGetLocale, "tscoll/capitst/TestGetLocale"); @@ -756,6 +757,56 @@ void TestSafeClone() { free(test2); } +void TestCloneBinary(){ + UErrorCode err = U_ZERO_ERROR; + UCollator * col = ucol_open("en_US", &err); + UCollator * c; + int32_t size; + uint8_t * buffer; + + if (U_FAILURE(err)) { + log_data_err("Couldn't open collator. Error: %s\n", u_errorName(err)); + return; + } + + size = ucol_cloneBinary(col, NULL, 0, &err); + if(U_FAILURE(err)) { + log_err("ucol_cloneBinary - couldn't check size. Error: %s\n", u_errorName(err)); + return; + } + + buffer = (uint8_t *) malloc(size); + ucol_cloneBinary(col, buffer, size, &err); + if(U_FAILURE(err)) { + log_err("ucol_cloneBinary - couldn't clone.. Error: %s\n", u_errorName(err)); + free(buffer); + return; + } + + /* hwo to check binary result ? */ + + c = ucol_openBinary(buffer, size, col, &err); + if(U_FAILURE(err)) { + log_err("ucol_openBinary failed. Error: %s\n", u_errorName(err)); + } else { + UChar t[] = {0x41, 0x42, 0x43, 0}; /* ABC */ + uint8_t *k1, *k2; + int l1, l2; + l1 = ucol_getSortKey(col, t, -1, NULL,0); + l2 = ucol_getSortKey(c, t, -1, NULL,0); + k1 = (uint8_t *) malloc(sizeof(uint8_t) * l1); + k2 = (uint8_t *) malloc(sizeof(uint8_t) * l2); + ucol_getSortKey(col, t, -1, k1, l1); + ucol_getSortKey(col, t, -1, k2, l2); + if (strcmp(k1,k2) != 0){ + log_err("ucol_openBinary - new collator should equal to old one\n"); + }; + free(k1); + free(k2); + } + free(buffer); + return; +} /* ---------------------------------------------------------------------------- ctor -- Tests the getSortKey diff --git a/icu4c/source/test/cintltst/capitst.h b/icu4c/source/test/cintltst/capitst.h index e9885f540c..0bb5fd005f 100644 --- a/icu4c/source/test/cintltst/capitst.h +++ b/icu4c/source/test/cintltst/capitst.h @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation and + * Copyright (c) 1997-2005, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** @@ -71,6 +71,11 @@ **/ void TestSafeClone(void); + /** + * Test ucol_cloneBinary(), ucol_openBinary() + **/ + void TestCloneBinary(void); + /** * Test getting bounds for a sortkey */ diff --git a/icu4c/source/test/cintltst/usettest.c b/icu4c/source/test/cintltst/usettest.c index 0d5e702042..d0d5656ebf 100644 --- a/icu4c/source/test/cintltst/usettest.c +++ b/icu4c/source/test/cintltst/usettest.c @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (c) 2002-2004, International Business Machines +* Copyright (c) 2002-2005, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** */ @@ -155,6 +155,14 @@ static void TestAPI() { } expect(set, "0123456789ABCDEFabcdef", "GHIjkl{bc}", NULL); + /* [ab] */ + uset_clear(set); + uset_addAllCodePoints(set, STR_ab, STR_ab_LEN); + expect(set, "ab", "def{ab}", NULL); + if (uset_containsAllCodePoints(set, STR_bc, STR_bc_LEN)){ + log_err("set should not conatin all characters of \"bc\" \n"); + } + /* [] */ set2 = uset_open(1, 1); uset_clear(set2); diff --git a/icu4c/source/test/intltest/calregts.cpp b/icu4c/source/test/intltest/calregts.cpp index 3b2a98c2ad..d38bf8a947 100644 --- a/icu4c/source/test/intltest/calregts.cpp +++ b/icu4c/source/test/intltest/calregts.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation and + * Copyright (c) 1997-2005, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -539,6 +539,9 @@ void CalendarRegressionTest::dowTest(UBool lenient) errln("FAIL: actual minimum differs from minimum"); } if(cal->getActualMinimum(Calendar::DAY_OF_WEEK, status) != min) { + errln("FAIL: actual minimum (Calendar::DAY_OF_WEEK, status) differs from minimum"); + } + if(cal->getActualMinimum(Calendar::DAY_OF_WEEK) != min) { errln("FAIL: actual minimum (Calendar::DAY_OF_WEEK) differs from minimum"); } if(((Calendar*)cal)->getActualMinimum(UCAL_DAY_OF_WEEK, status) != min) { diff --git a/icu4c/source/test/intltest/itrbnf.cpp b/icu4c/source/test/intltest/itrbnf.cpp index 658d27895f..9d424b8aa4 100644 --- a/icu4c/source/test/intltest/itrbnf.cpp +++ b/icu4c/source/test/intltest/itrbnf.cpp @@ -231,6 +231,14 @@ IntlTestRBNF::TestAPI() { logln("Formatted 4, expected " + expected + " got " + result); } + result.remove(); + FieldPosition pos; + formatter->format((int64_t)4, result, pos, status = U_ZERO_ERROR); + if(result != expected) { + errln("Formatted 4 int64_t, expected " + expected + " got " + result); + } else { + logln("Formatted 4 int64_t, expected " + expected + " got " + result); + } // clean up logln("Cleaning up"); @@ -1522,10 +1530,17 @@ IntlTestRBNF::TestLocalizations(void) Locale locale0("en__VALLEY@turkey=gobblegobble"); Locale locale1("de_DE_FOO"); Locale locale2("ja_JP"); - logln(formatter0.getRuleSetDisplayName(0, locale0)); - logln(formatter0.getRuleSetDisplayName(0, locale1)); - logln(formatter0.getRuleSetDisplayName(0, locale2)); - // TODO: check against intended result + UnicodeString name = formatter0.getRuleSetName(0); + if ( formatter0.getRuleSetDisplayName(0, locale0) == "Main" + && formatter0.getRuleSetDisplayName(0, locale1) == "das Main" + && formatter0.getRuleSetDisplayName(0, locale2) == "%main" + && formatter0.getRuleSetDisplayName(name, locale0) == "Main" + && formatter0.getRuleSetDisplayName(name, locale1) == "das Main" + && formatter0.getRuleSetDisplayName(name, locale2) == "%main"){ + logln("getRuleSetDisplayName tested"); + }else { + errln("failed to getRuleSetDisplayName"); + } } for (i = 0; i < formatter0.getNumberOfRuleSetDisplayNameLocales(); ++i) { diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp index 630e52fa09..9e3298872e 100644 --- a/icu4c/source/test/intltest/numfmtst.cpp +++ b/icu4c/source/test/intltest/numfmtst.cpp @@ -76,6 +76,8 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n CASE(27,TestCases); CASE(28,TestCurrencyNames); + CASE(29,TestCurrencyAmount); + CASE(30,TestCurrencyUnit); default: name = ""; break; } @@ -110,6 +112,19 @@ NumberFormatTest::TestAPI(void) status = U_ZERO_ERROR; } + result.remove(); + int64_t ll = 12; + test->format(ll, result); + if (result != "12.00"){ + errln("format int64_t error"); + } + result.remove(); + FieldPosition pos2; + test->format(ll, result, pos2); + if (result != "12.00"){ + errln("format int64_t error"); + } + delete test; } } @@ -1456,6 +1471,43 @@ void NumberFormatTest::TestCurrencyNames(void) { // TODO add more tests later } +void NumberFormatTest::TestCurrencyUnit(void){ + UErrorCode ec = U_ZERO_ERROR; + static const UChar USD[] = {85, 83, 68, 0}; /*USD*/ + CurrencyUnit cu(USD, ec); + assertSuccess("CurrencyUnit", ec); + + const UChar * r = cu.getISOCurrency(); // who is the buffer owner ? + assertEquals("getISOCurrency()", USD, r); + + CurrencyUnit cu2(cu); + if (!(cu2 == cu)){ + errln("CurrencyUnit copy constructed object should be same"); + } + + CurrencyUnit * cu3 = (CurrencyUnit *)cu.clone(); + if (!(*cu3 == cu)){ + errln("CurrencyUnit cloned object should be same"); + } +} + +void NumberFormatTest::TestCurrencyAmount(void){ + UErrorCode ec = U_ZERO_ERROR; + static const UChar USD[] = {85, 83, 68, 0}; /*USD*/ + CurrencyAmount ca(9, USD, ec); + assertSuccess("CurrencyAmount", ec); + + CurrencyAmount ca2(ca); + if (!(ca2 == ca)){ + errln("CurrencyAmount copy constructed object should be same"); + } + + CurrencyAmount *ca3 = (CurrencyAmount *)ca.clone(); + if (!(ca2 == ca)){ + errln("CurrencyAmount cloned object should be same"); + } +} + void NumberFormatTest::TestSymbolsWithBadLocale(void) { Locale locDefault; Locale locBad("x-crazy_ZZ_MY_SPECIAL_ADMINISTRATION_REGION_NEEDS_A_SPECIAL_VARIANT_WITH_A_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_REALLY_LONG_NAME"); @@ -1990,6 +2042,7 @@ void NumberFormatTest::expectCurrency(NumberFormat& nf, const Locale& locale, assertSuccess("ucurr_forLocale", ec); fmt.setCurrency(curr, ec); assertSuccess("DecimalFormat::setCurrency", ec); + fmt.setCurrency(curr); //Deprecated variant, for coverage only } UnicodeString s; fmt.format(value, s); diff --git a/icu4c/source/test/intltest/numfmtst.h b/icu4c/source/test/intltest/numfmtst.h index f451cf8e1c..f9d7dfaaba 100644 --- a/icu4c/source/test/intltest/numfmtst.h +++ b/icu4c/source/test/intltest/numfmtst.h @@ -102,6 +102,10 @@ class NumberFormatTest: public CalendarTimeZoneTest { void TestCurrencyNames(void); + void TestCurrencyAmount(void); + + void TestCurrencyUnit(void); + void TestSymbolsWithBadLocale(void); void TestAdoptDecimalFormatSymbols(void); diff --git a/icu4c/source/test/intltest/tchcfmt.cpp b/icu4c/source/test/intltest/tchcfmt.cpp index 6e9954361a..82d237d510 100644 --- a/icu4c/source/test/intltest/tchcfmt.cpp +++ b/icu4c/source/test/intltest/tchcfmt.cpp @@ -1,7 +1,7 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2003, International Business Machines Corporation and + * Copyright (c) 1997-2005, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -393,6 +393,14 @@ TestChoiceFormat::TestComplexExample( void ) it_logln(UnicodeString("ChoiceFormat format:") + res1); if (res1 != "third") it_errln("*** ChoiceFormat format (double, ...) result!"); + str = ""; + fpos = 0; + status = U_ZERO_ERROR; + int64_t arg_64 = 3; + res1 = form_pat.format( arg_64, str, fpos ); + it_logln(UnicodeString("ChoiceFormat format:") + res1); + if (res1 != "third") it_errln("*** ChoiceFormat format (int64_t, ...) result!"); + str = ""; fpos = 0; status = U_ZERO_ERROR; diff --git a/icu4c/source/test/intltest/tfsmalls.cpp b/icu4c/source/test/intltest/tfsmalls.cpp index 6764992053..8d1407a533 100644 --- a/icu4c/source/test/intltest/tfsmalls.cpp +++ b/icu4c/source/test/intltest/tfsmalls.cpp @@ -1,7 +1,7 @@ /*********************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation + * Copyright (c) 1997-2005, International Business Machines Corporation * and others. All Rights Reserved. ***********************************************************************/ @@ -159,6 +159,7 @@ void test_FieldPosition( void ) void test_Formattable( void ) { + UErrorCode status = U_ZERO_ERROR; Formattable* ftp = new Formattable(); if (!ftp || !(ftp->getType() == Formattable::kLong) || !(ftp->getLong() == 0)) { it_errln("*** Formattable constructor or getType or getLong"); @@ -169,6 +170,13 @@ void test_Formattable( void ) fta.setLong(1); ftb.setLong(2); if ((fta != ftb) || !(fta == ftb)) { it_logln("FT setLong, operator== and operator!= tested."); + status = U_ZERO_ERROR; + fta.getLong(&status); + if ( status == U_INVALID_FORMAT_ERROR){ + it_errln("*** FT getLong(UErrorCode* status) failed on real Long"); + } else { + it_logln("FT getLong(UErrorCode* status) tested."); + } }else{ it_errln("*** Formattable setLong or operator== or !="); } @@ -185,22 +193,52 @@ void test_Formattable( void ) }else{ it_errln("*** FT set- or getDouble"); } - + + fta.getDate(status = U_ZERO_ERROR); + if (status != U_INVALID_FORMAT_ERROR){ + it_errln("*** FT getDate with status should fail on non-Date"); + } fta.setDate( 4.0 ); if ((fta.getType() == Formattable::kDate) && (fta.getDate() == 4.0)) { - it_logln("FT set- and getDate tested."); + it_logln("FT set- and getDate tested."); + status = U_ZERO_ERROR; + fta.getDate(status); + if ( status == U_INVALID_FORMAT_ERROR){ + it_errln("*** FT getDate with status failed on real Date"); + } else { + it_logln("FT getDate with status tested."); + } }else{ it_errln("*** FT set- or getDate"); } - fta.setString("abc"); - UnicodeString res; - if ((fta.getType() == Formattable::kString) && (fta.getString(res) == "abc")) { - it_logln("FT set- and getString tested."); - }else{ - it_errln("*** FT set- or getString"); + status = U_ZERO_ERROR; + fta.getLong(&status); + if (status != U_INVALID_FORMAT_ERROR){ + it_errln("*** FT getLong(UErrorCode* status) should fail on non-Long"); } + fta.setString("abc"); + const Formattable ftc(fta); + UnicodeString res; + + { + UBool t; + t = (fta.getType() == Formattable::kString) + && (fta.getString(res) == "abc") + && (fta.getString() == "abc"); + res = fta.getString(status = U_ZERO_ERROR); + t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc"); + res = ftc.getString(status = U_ZERO_ERROR); + t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc"); + ftc.getString(res,status = U_ZERO_ERROR); + t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc"); + if (t) { + it_logln("FT set- and getString tested."); + }else{ + it_errln("*** FT set- or getString"); + } + } UnicodeString ucs = "unicode-string"; UnicodeString* ucs_ptr = new UnicodeString("pointed-to-unicode-string"); @@ -237,12 +275,29 @@ void test_Formattable( void ) } if (same) { it_logln("FT getArray tested"); + res_array = ft_arr.getArray( res_cnt, status = U_ZERO_ERROR); + if (status == U_INVALID_FORMAT_ERROR){ + it_errln("*** FT getArray with status failed on real array"); + } else { + it_logln("FT getArray with status tested on real array"); + } }else{ it_errln("*** FT getArray comparison"); } }else{ it_errln(UnicodeString("*** FT getArray count res_cnt=") + res_cnt + UnicodeString("ft_cnt=") + ft_cnt); } + + res_array = fta.getArray(res_cnt, status = U_ZERO_ERROR); + if (status == U_INVALID_FORMAT_ERROR){ + if (res_cnt == 0 && res_array == NULL){ + it_logln("FT getArray with status tested on non array"); + } else { + it_errln("*** FT getArray with status return values are not consistent"); + } + } else { + it_errln("*** FT getArray with status should fail on non-array"); + } Formattable *pf; diff --git a/icu4c/source/test/intltest/transtst.cpp b/icu4c/source/test/intltest/transtst.cpp index 38fb671f53..619dc3d3f2 100644 --- a/icu4c/source/test/intltest/transtst.cpp +++ b/icu4c/source/test/intltest/transtst.cpp @@ -669,6 +669,14 @@ void TransliteratorTest::TestFiltering(void) { } else { logln(UnicodeString("FAIL: \"") + s + "\", wanted \"" + exp + "\""); } + + // ICU4C ONLY. Do not find Transliterator.orphanFilter() in ICU4J. + UnicodeFilter *f = hex->orphanFilter(); + if (f == NULL){ + errln("FAIL: orphanFilter() should get a UnicodeFilter"); + } else { + delete f; + } delete hex; }