ICU-1880 modified casing test so that it uses TestDataDriver
X-SVN-Rev: 8586
This commit is contained in:
parent
7472bb4fd2
commit
8675a148e2
@ -24,6 +24,7 @@
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/ubrk.h"
|
||||
#include "ustrtest.h"
|
||||
#include "tedadrvr.h"
|
||||
|
||||
void
|
||||
StringCaseTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char * /*par*/) {
|
||||
@ -309,6 +310,40 @@ StringCaseTest::TestCaseConversion()
|
||||
|
||||
void
|
||||
StringCaseTest::TestTitleCasing() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UBreakIterator *iter;
|
||||
char cLocaleID[100];
|
||||
const int32_t capacity = 4; // 4 test values per test case
|
||||
int32_t noOfElements = 0;
|
||||
UnicodeString testcase[4], result;
|
||||
int32_t type;
|
||||
TestDataDriver *driver = TestDataDriver::createTestInstance("casing", status);
|
||||
if(U_SUCCESS(status)) {
|
||||
driver->getTest("titlecasing", status);
|
||||
while(noOfElements = driver->getNextTestCase(testcase, 4, status)) {
|
||||
testcase[2].extract(0, 0x7fffffff, cLocaleID, sizeof(cLocaleID), "");
|
||||
type = TestDataDriver::utoi(testcase[3]);
|
||||
|
||||
if(type<0) {
|
||||
iter=0;
|
||||
} else {
|
||||
iter=ubrk_open((UBreakIteratorType)type, cLocaleID, testcase[0].getBuffer(), testcase[0].length(), &status);
|
||||
}
|
||||
|
||||
if(U_FAILURE(status)) {
|
||||
errln("error: TestTitleCasing() ubrk_open(%d) failed for test case from casing.res: %s", type, u_errorName(status));
|
||||
} else {
|
||||
result=testcase[0];
|
||||
result.toTitle((BreakIterator *)iter, Locale(cLocaleID));
|
||||
if(result!=testcase[1]) {
|
||||
errln("error: TestTitleCasing() got a wrong result for test case from casing.res");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete driver;
|
||||
|
||||
#if 0
|
||||
char cLocaleID[100];
|
||||
UnicodeString in, expect, result, localeID;
|
||||
UResourceBundle *casing, *titlecasing, *test, *res;
|
||||
@ -378,4 +413,5 @@ StringCaseTest::TestTitleCasing() {
|
||||
}
|
||||
|
||||
ures_close(casing);
|
||||
#endif
|
||||
}
|
||||
|
25
icu4c/source/test/testdata/casing.txt
vendored
25
icu4c/source/test/testdata/casing.txt
vendored
@ -5,17 +5,22 @@
|
||||
//*
|
||||
//*******************************************************************************
|
||||
|
||||
// test data file for string casing
|
||||
|
||||
casing {
|
||||
TestPurpose { "This is test data file for string casing" }
|
||||
|
||||
TestDataParsing { "each item is an array with"
|
||||
"input string, result string, locale ID, break iterator"
|
||||
"the break iterator is specified as an int, same as in UBreakIteratorType:"
|
||||
"0=UBRK_CHARACTER 1=UBRK_WORD 2=UBRK_LINE 3=UBRK_SENTENCE 4=UBRK_TITLE -1=default"
|
||||
}
|
||||
TestData {
|
||||
titlecasing {
|
||||
// each item is an array with
|
||||
// input string, result string, locale ID, break iterator
|
||||
// the break iterator is specified as an int, same as in UBreakIteratorType:
|
||||
// 0=UBRK_CHARACTER 1=UBRK_WORD 2=UBRK_LINE 3=UBRK_SENTENCE 4=UBRK_TITLE -1=default
|
||||
{ {" tHe QUIcK bRoWn"} {" The Quick Brown"} {""} :int{4} }
|
||||
{ {"DŽDždžLJLjljNJNjnj"} {"DžDžDžLjLjLjNjNjNj"} {""} :int{0} } // UBRK_CHARACTER
|
||||
{ {"ljubav ljubav"} {"Ljubav Ljubav"} {""} :int{-1} } // Lj vs. L+j
|
||||
{ {"'oH dOn'T tItLeCaSe AfTeR lEtTeR+'"} {"'Oh Don't Titlecase After Letter+'"} {""} :int{-1} }
|
||||
TestCases {
|
||||
{ " tHe QUIcK bRoWn", " The Quick Brown", "", "4" },
|
||||
{ "DŽDždžLJLjljNJNjnj", "DžDžDžLjLjLjNjNjNj", "", "0" }, // UBRK_CHARACTER
|
||||
{ "ljubav ljubav", "Ljubav Ljubav", "", "-1" }, // Lj vs. L+j
|
||||
{ "'oH dOn'T tItLeCaSe AfTeR lEtTeR+'", "'Oh Don't Titlecase After Letter+'", "", "-1" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user