michael@0: /******************************************************************** michael@0: * COPYRIGHT: michael@0: * Copyright (c) 2002-2005, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ********************************************************************/ michael@0: michael@0: /* Created by weiv 05/09/2002 */ michael@0: michael@0: #include "unicode/testdata.h" michael@0: michael@0: michael@0: TestData::TestData(const char* testName) michael@0: : name(testName), michael@0: fInfo(NULL), michael@0: fCurrSettings(NULL), michael@0: fCurrCase(NULL), michael@0: fSettingsSize(0), michael@0: fCasesSize(0), michael@0: fCurrentSettings(0), michael@0: fCurrentCase(0) michael@0: michael@0: { michael@0: } michael@0: michael@0: TestData::~TestData() { michael@0: if(fInfo != NULL) { michael@0: delete fInfo; michael@0: } michael@0: if(fCurrSettings != NULL) { michael@0: delete fCurrSettings; michael@0: } michael@0: if(fCurrCase != NULL) { michael@0: delete fCurrCase; michael@0: } michael@0: } michael@0: michael@0: const char * TestData::getName() const michael@0: { michael@0: return name; michael@0: } michael@0: michael@0: michael@0: michael@0: RBTestData::RBTestData(const char* testName) michael@0: : TestData(testName), michael@0: fData(NULL), michael@0: fHeaders(NULL), michael@0: fSettings(NULL), michael@0: fCases(NULL) michael@0: { michael@0: } michael@0: michael@0: RBTestData::RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status) michael@0: : TestData(ures_getKey(data)), michael@0: fData(data), michael@0: fHeaders(headers), michael@0: fSettings(NULL), michael@0: fCases(NULL) michael@0: { michael@0: UErrorCode intStatus = U_ZERO_ERROR; michael@0: UResourceBundle *currHeaders = ures_getByKey(data, "Headers", NULL, &intStatus); michael@0: if(intStatus == U_ZERO_ERROR) { michael@0: ures_close(fHeaders); michael@0: fHeaders = currHeaders; michael@0: } else { michael@0: intStatus = U_ZERO_ERROR; michael@0: } michael@0: fSettings = ures_getByKey(data, "Settings", NULL, &intStatus); michael@0: fSettingsSize = ures_getSize(fSettings); michael@0: UResourceBundle *info = ures_getByKey(data, "Info", NULL, &intStatus); michael@0: if(U_SUCCESS(intStatus)) { michael@0: fInfo = new RBDataMap(info, status); michael@0: } else { michael@0: intStatus = U_ZERO_ERROR; michael@0: } michael@0: fCases = ures_getByKey(data, "Cases", NULL, &status); michael@0: fCasesSize = ures_getSize(fCases); michael@0: michael@0: ures_close(info); michael@0: } michael@0: michael@0: michael@0: RBTestData::~RBTestData() michael@0: { michael@0: ures_close(fData); michael@0: ures_close(fHeaders); michael@0: ures_close(fSettings); michael@0: ures_close(fCases); michael@0: } michael@0: michael@0: UBool RBTestData::getInfo(const DataMap *& info, UErrorCode &/*status*/) const michael@0: { michael@0: if(fInfo) { michael@0: info = fInfo; michael@0: return TRUE; michael@0: } else { michael@0: info = NULL; michael@0: return FALSE; michael@0: } michael@0: } michael@0: michael@0: UBool RBTestData::nextSettings(const DataMap *& settings, UErrorCode &status) michael@0: { michael@0: UErrorCode intStatus = U_ZERO_ERROR; michael@0: UResourceBundle *data = ures_getByIndex(fSettings, fCurrentSettings++, NULL, &intStatus); michael@0: if(U_SUCCESS(intStatus)) { michael@0: // reset the cases iterator michael@0: fCurrentCase = 0; michael@0: if(fCurrSettings == NULL) { michael@0: fCurrSettings = new RBDataMap(data, status); michael@0: } else { michael@0: ((RBDataMap *)fCurrSettings)->init(data, status); michael@0: } michael@0: ures_close(data); michael@0: settings = fCurrSettings; michael@0: return TRUE; michael@0: } else { michael@0: settings = NULL; michael@0: return FALSE; michael@0: } michael@0: } michael@0: michael@0: UBool RBTestData::nextCase(const DataMap *& nextCase, UErrorCode &status) michael@0: { michael@0: UErrorCode intStatus = U_ZERO_ERROR; michael@0: UResourceBundle *currCase = ures_getByIndex(fCases, fCurrentCase++, NULL, &intStatus); michael@0: if(U_SUCCESS(intStatus)) { michael@0: if(fCurrCase == NULL) { michael@0: fCurrCase = new RBDataMap(fHeaders, currCase, status); michael@0: } else { michael@0: ((RBDataMap *)fCurrCase)->init(fHeaders, currCase, status); michael@0: } michael@0: ures_close(currCase); michael@0: nextCase = fCurrCase; michael@0: return TRUE; michael@0: } else { michael@0: nextCase = NULL; michael@0: return FALSE; michael@0: } michael@0: } michael@0: michael@0: