From 2333b126c14fdf5c9672dc91f2a1648b115cff30 Mon Sep 17 00:00:00 2001 From: Michael Ow Date: Tue, 12 Oct 2010 16:38:38 +0000 Subject: [PATCH] ICU-6845 Improve the code coverage in ICU4C. X-SVN-Rev: 28790 --- icu4c/source/test/cintltst/ucnvseltst.c | 38 +++++++++++++++++++++++++ icu4c/source/test/intltest/strtest.cpp | 6 ++++ icu4c/source/test/intltest/tstnorm.cpp | 27 ++++++++++++++++++ icu4c/source/test/intltest/tstnorm.h | 1 + 4 files changed, 72 insertions(+) diff --git a/icu4c/source/test/cintltst/ucnvseltst.c b/icu4c/source/test/cintltst/ucnvseltst.c index 32ed2d95633..7f892663f06 100644 --- a/icu4c/source/test/cintltst/ucnvseltst.c +++ b/icu4c/source/test/cintltst/ucnvseltst.c @@ -22,6 +22,7 @@ #include "unicode/ustring.h" #include "cmemory.h" #include "cstring.h" +#include "propsvec.h" #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) @@ -30,11 +31,13 @@ #define TDSRCPATH ".." U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING static void TestSelector(void); +static void TestUPropsVector(void); void addCnvSelTest(TestNode** root); /* Declaration required to suppress compiler warnings. */ void addCnvSelTest(TestNode** root) { addTest(root, &TestSelector, "tsconv/ucnvseltst/TestSelector"); + addTest(root, &TestUPropsVector, "tsconv/ucnvseltst/TestUPropsVector"); } static const char **gAvailableNames = NULL; @@ -500,3 +503,38 @@ static void TestSelector() uset_close(excluded_sets[i]); } } + +/* Improve code coverage of UPropsVectors */ +static void TestUPropsVector() { + uint32_t value; + UErrorCode errorCode = U_ILLEGAL_ARGUMENT_ERROR; + UPropsVectors *pv = upvec_open(100, &errorCode); + if (pv != NULL) { + log_err("Should have returned NULL if UErrorCode is an error."); + return; + } + errorCode = U_ZERO_ERROR; + pv = upvec_open(-1, &errorCode); + if (pv != NULL || U_SUCCESS(errorCode)) { + log_err("Should have returned NULL if column is less than 0.\n"); + return; + } + errorCode = U_ZERO_ERROR; + pv = upvec_open(100, &errorCode); + if (pv == NULL || U_FAILURE(errorCode)) { + log_err("Unable to open UPropsVectors.\n"); + return; + } + + if (upvec_getValue(pv, 0, 1) != 0) { + log_err("upvec_getValue should return 0.\n"); + } + if (upvec_getRow(pv, 0, NULL, NULL) == NULL) { + log_err("upvec_getRow should not return NULL.\n"); + } + if (upvec_getArray(pv, NULL, NULL) != NULL) { + log_err("upvec_getArray should return NULL.\n"); + } + + upvec_close(pv); +} diff --git a/icu4c/source/test/intltest/strtest.cpp b/icu4c/source/test/intltest/strtest.cpp index b18d0930351..0b13ec31166 100644 --- a/icu4c/source/test/intltest/strtest.cpp +++ b/icu4c/source/test/intltest/strtest.cpp @@ -545,6 +545,12 @@ StringTest::TestCharString() { if (0 != strcmp(longStr, chStr.data()) || (int32_t)strlen(longStr) != chStr.length()) { errln("CharString(longStr) failed."); } + CharString test("Test", errorCode); + CharString copy(test,errorCode); + copy.copyFrom(chStr, errorCode); + if (0 != strcmp(longStr, copy.data()) || (int32_t)strlen(longStr) != copy.length()) { + errln("CharString.copyFrom() failed."); + } StringPiece sp(chStr.toStringPiece()); sp.remove_prefix(4); chStr.append(sp, errorCode).append(chStr, errorCode); diff --git a/icu4c/source/test/intltest/tstnorm.cpp b/icu4c/source/test/intltest/tstnorm.cpp index f8ee483b413..a88e5c7efe8 100644 --- a/icu4c/source/test/intltest/tstnorm.cpp +++ b/icu4c/source/test/intltest/tstnorm.cpp @@ -56,6 +56,7 @@ void BasicNormalizerTest::runIndexedTest(int32_t index, UBool exec, CASE(17,TestCustomComp); CASE(18,TestCustomFCC); #endif + CASE(19,TestFilteredNormalizer2Coverage); default: name = ""; break; } } @@ -1448,4 +1449,30 @@ BasicNormalizerTest::TestCustomFCC() { } } +/* Improve code coverage of Normalizer2 */ +void +BasicNormalizerTest::TestFilteredNormalizer2Coverage() { + UErrorCode errorCode = U_ZERO_ERROR; + const Normalizer2 *nfcNorm2=Normalizer2Factory::getNFCInstance(errorCode); + UnicodeSet filter(UNICODE_STRING_SIMPLE("[^\\u00a0-\\u00ff]"), errorCode); + UnicodeString newString1 = UNICODE_STRING_SIMPLE("[^\\u0100-\\u01ff]"); + UnicodeString newString2 = UNICODE_STRING_SIMPLE("[^\\u0200-\\u02ff]"); + FilteredNormalizer2 fn2(*nfcNorm2, filter); + + UChar32 char32 = 0x0054; + + if (fn2.isInert(char32)) { + errln("FilteredNormalizer2.isInert() failed."); + } + + if (fn2.hasBoundaryAfter(char32)) { + errln("FilteredNormalizer2.hasBoundaryAfter() failed."); + } + + fn2.append(newString1, newString2, errorCode); + if (U_FAILURE(errorCode)) { + errln("FilteredNormalizer2.append() failed."); + } +} + #endif /* #if !UCONFIG_NO_NORMALIZATION */ diff --git a/icu4c/source/test/intltest/tstnorm.h b/icu4c/source/test/intltest/tstnorm.h index 1fb82a064a2..793155541ae 100644 --- a/icu4c/source/test/intltest/tstnorm.h +++ b/icu4c/source/test/intltest/tstnorm.h @@ -44,6 +44,7 @@ public: void TestSkippable(); void TestCustomComp(); void TestCustomFCC(); + void TestFilteredNormalizer2Coverage(); private: UnicodeString canonTests[24][3];