1/******************************************************************** 2 * COPYRIGHT: 3 * Copyright (c) 2002-2005, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ********************************************************************/ 6 7/* Created by weiv 05/09/2002 */ 8 9#include "unicode/testdata.h" 10 11 12TestData::TestData(const char* testName) 13: name(testName), 14fInfo(NULL), 15fCurrSettings(NULL), 16fCurrCase(NULL), 17fSettingsSize(0), 18fCasesSize(0), 19fCurrentSettings(0), 20fCurrentCase(0) 21 22{ 23} 24 25TestData::~TestData() { 26 if(fInfo != NULL) { 27 delete fInfo; 28 } 29 if(fCurrSettings != NULL) { 30 delete fCurrSettings; 31 } 32 if(fCurrCase != NULL) { 33 delete fCurrCase; 34 } 35} 36 37const char * TestData::getName() const 38{ 39 return name; 40} 41 42 43 44RBTestData::RBTestData(const char* testName) 45: TestData(testName), 46fData(NULL), 47fHeaders(NULL), 48fSettings(NULL), 49fCases(NULL) 50{ 51} 52 53RBTestData::RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status) 54: TestData(ures_getKey(data)), 55fData(data), 56fHeaders(headers), 57fSettings(NULL), 58fCases(NULL) 59{ 60 UErrorCode intStatus = U_ZERO_ERROR; 61 UResourceBundle *currHeaders = ures_getByKey(data, "Headers", NULL, &intStatus); 62 if(intStatus == U_ZERO_ERROR) { 63 ures_close(fHeaders); 64 fHeaders = currHeaders; 65 } else { 66 intStatus = U_ZERO_ERROR; 67 } 68 fSettings = ures_getByKey(data, "Settings", NULL, &intStatus); 69 fSettingsSize = ures_getSize(fSettings); 70 UResourceBundle *info = ures_getByKey(data, "Info", NULL, &intStatus); 71 if(U_SUCCESS(intStatus)) { 72 fInfo = new RBDataMap(info, status); 73 } else { 74 intStatus = U_ZERO_ERROR; 75 } 76 fCases = ures_getByKey(data, "Cases", NULL, &status); 77 fCasesSize = ures_getSize(fCases); 78 79 ures_close(info); 80} 81 82 83RBTestData::~RBTestData() 84{ 85 ures_close(fData); 86 ures_close(fHeaders); 87 ures_close(fSettings); 88 ures_close(fCases); 89} 90 91UBool RBTestData::getInfo(const DataMap *& info, UErrorCode &/*status*/) const 92{ 93 if(fInfo) { 94 info = fInfo; 95 return TRUE; 96 } else { 97 info = NULL; 98 return FALSE; 99 } 100} 101 102UBool RBTestData::nextSettings(const DataMap *& settings, UErrorCode &status) 103{ 104 UErrorCode intStatus = U_ZERO_ERROR; 105 UResourceBundle *data = ures_getByIndex(fSettings, fCurrentSettings++, NULL, &intStatus); 106 if(U_SUCCESS(intStatus)) { 107 // reset the cases iterator 108 fCurrentCase = 0; 109 if(fCurrSettings == NULL) { 110 fCurrSettings = new RBDataMap(data, status); 111 } else { 112 ((RBDataMap *)fCurrSettings)->init(data, status); 113 } 114 ures_close(data); 115 settings = fCurrSettings; 116 return TRUE; 117 } else { 118 settings = NULL; 119 return FALSE; 120 } 121} 122 123UBool RBTestData::nextCase(const DataMap *& nextCase, UErrorCode &status) 124{ 125 UErrorCode intStatus = U_ZERO_ERROR; 126 UResourceBundle *currCase = ures_getByIndex(fCases, fCurrentCase++, NULL, &intStatus); 127 if(U_SUCCESS(intStatus)) { 128 if(fCurrCase == NULL) { 129 fCurrCase = new RBDataMap(fHeaders, currCase, status); 130 } else { 131 ((RBDataMap *)fCurrCase)->init(fHeaders, currCase, status); 132 } 133 ures_close(currCase); 134 nextCase = fCurrCase; 135 return TRUE; 136 } else { 137 nextCase = NULL; 138 return FALSE; 139 } 140} 141 142 143