-// Try out the RuleBasedBreakIterator constructors that take RBBIDataHeader*
-// (these are protected so we access them via a local class RBBIWithProtectedFunctions).
-// This is just a sanity check, not a thorough test (e.g. we don't check that the
-// first delete actually frees rulesCopy).
-void RBBIAPITest::TestCreateFromRBBIData() {
- // Get some handy RBBIData
- const char *brkName = "word"; // or "sent", "line", "char", etc.
- UErrorCode status = U_ZERO_ERROR;
- LocalUDataMemoryPointer data(udata_open(U_ICUDATA_BRKITR, "brk", brkName, &status));
- if ( U_SUCCESS(status) ) {
- const RBBIDataHeader * builtRules = (const RBBIDataHeader *)udata_getMemory(data.getAlias());
- uint32_t length = builtRules->fLength;
- RBBIWithProtectedFunctions * brkItr;
-
- // Try the memory-adopting constructor, need to copy the data first
- RBBIDataHeader * rulesCopy = (RBBIDataHeader *) uprv_malloc(length);
- if ( rulesCopy ) {
- uprv_memcpy( rulesCopy, builtRules, length );
-
- brkItr = new RBBIWithProtectedFunctions(rulesCopy, status);
- if ( U_SUCCESS(status) ) {
- delete brkItr; // this should free rulesCopy
- } else {
- errln("create RuleBasedBreakIterator from RBBIData (adopted): ICU Error \"%s\"\n", u_errorName(status) );
- status = U_ZERO_ERROR;// reset for the next test
- uprv_free( rulesCopy );
- }
- }