From d2a68eaa189e4b6a5e5ac427a53860db3ef72872 Mon Sep 17 00:00:00 2001 From: Vladimir Weinstein Date: Tue, 28 Jun 2005 16:40:46 +0000 Subject: [PATCH] ICU-4587 test for C++ wrappers for ucol_cloneBinary and ucol_openBinary X-SVN-Rev: 18070 --- icu4c/source/test/intltest/dadrcoll.cpp | 30 ++++++++++++++++++++++--- icu4c/source/test/intltest/dadrcoll.h | 3 ++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/icu4c/source/test/intltest/dadrcoll.cpp b/icu4c/source/test/intltest/dadrcoll.cpp index 738ed1338e..811ef4411d 100644 --- a/icu4c/source/test/intltest/dadrcoll.cpp +++ b/icu4c/source/test/intltest/dadrcoll.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. ********************************************************************/ @@ -39,11 +39,13 @@ sequences(status) { driver = TestDataModule::getTestDataModule("DataDrivenCollationTest", *this, status); sequences.setDeleter(deleteSeqElement); + UCA = (RuleBasedCollator*)Collator::createInstance("root", status); } DataDrivenCollatorTest::~DataDrivenCollatorTest() { delete driver; + delete UCA; } void DataDrivenCollatorTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par */) @@ -162,7 +164,7 @@ DataDrivenCollatorTest::processArguments(Collator *col, const UChar *start, int3 } } -void +void DataDrivenCollatorTest::processTest(TestData *testData) { Collator *col = NULL; const UChar *arguments = NULL; @@ -201,7 +203,20 @@ DataDrivenCollatorTest::processTest(TestData *testData) { errln("No collator definition!"); } } - if(col != NULL) { + + int32_t cloneSize = 0; + uint8_t* cloneBuf = NULL; + RuleBasedCollator* clone = NULL; + if(col != NULL){ + RuleBasedCollator* rbc = (RuleBasedCollator*)col; + cloneSize = rbc->cloneBinary(NULL, 0, intStatus); + cloneBuf = (uint8_t*) malloc(cloneSize); + cloneSize = rbc->cloneBinary(cloneBuf, cloneSize, intStatus); + clone = new RuleBasedCollator(cloneBuf, cloneSize, UCA, intStatus); + if(U_FAILURE(intStatus)){ + errln("Could not clone the RuleBasedCollator. Error: %s", u_errorName(intStatus)); + intStatus= U_ZERO_ERROR; + } // get attributes testSetting = settings->getString("Arguments", intStatus); if(U_SUCCESS(intStatus)) { @@ -209,6 +224,9 @@ DataDrivenCollatorTest::processTest(TestData *testData) { argLen = testSetting.length(); arguments = testSetting.getBuffer(); processArguments(col, arguments, argLen); + if(clone != NULL){ + processArguments(clone, arguments, argLen); + } if(U_FAILURE(status)) { errln("Couldn't process arguments"); break; @@ -221,16 +239,22 @@ DataDrivenCollatorTest::processTest(TestData *testData) { UnicodeString sequence = currentCase->getString("sequence", status); if(U_SUCCESS(status)) { processSequence(col, sequence); + if(clone != NULL){ + processSequence(clone, sequence); + } } } } else { errln("Couldn't instantiate a collator!"); } + delete clone; + free(cloneBuf); delete col; col = NULL; } } + void DataDrivenCollatorTest::processSequence(Collator* col, const UnicodeString &sequence) { Collator::EComparisonResult relation = Collator::EQUAL; diff --git a/icu4c/source/test/intltest/dadrcoll.h b/icu4c/source/test/intltest/dadrcoll.h index c9e99257d2..b76f40db8d 100644 --- a/icu4c/source/test/intltest/dadrcoll.h +++ b/icu4c/source/test/intltest/dadrcoll.h @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2002-2004, International Business Machines Corporation and + * Copyright (c) 2002-2005, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -51,6 +51,7 @@ private: TestDataModule *driver; UErrorCode status; UVector sequences; + RuleBasedCollator *UCA; // needed for opening collators from binary images }; #endif /* #if !UCONFIG_NO_COLLATION */