1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/tools/ctestfw/testdata.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,142 @@ 1.4 +/******************************************************************** 1.5 + * COPYRIGHT: 1.6 + * Copyright (c) 2002-2005, International Business Machines Corporation and 1.7 + * others. All Rights Reserved. 1.8 + ********************************************************************/ 1.9 + 1.10 +/* Created by weiv 05/09/2002 */ 1.11 + 1.12 +#include "unicode/testdata.h" 1.13 + 1.14 + 1.15 +TestData::TestData(const char* testName) 1.16 +: name(testName), 1.17 +fInfo(NULL), 1.18 +fCurrSettings(NULL), 1.19 +fCurrCase(NULL), 1.20 +fSettingsSize(0), 1.21 +fCasesSize(0), 1.22 +fCurrentSettings(0), 1.23 +fCurrentCase(0) 1.24 + 1.25 +{ 1.26 +} 1.27 + 1.28 +TestData::~TestData() { 1.29 + if(fInfo != NULL) { 1.30 + delete fInfo; 1.31 + } 1.32 + if(fCurrSettings != NULL) { 1.33 + delete fCurrSettings; 1.34 + } 1.35 + if(fCurrCase != NULL) { 1.36 + delete fCurrCase; 1.37 + } 1.38 +} 1.39 + 1.40 +const char * TestData::getName() const 1.41 +{ 1.42 + return name; 1.43 +} 1.44 + 1.45 + 1.46 + 1.47 +RBTestData::RBTestData(const char* testName) 1.48 +: TestData(testName), 1.49 +fData(NULL), 1.50 +fHeaders(NULL), 1.51 +fSettings(NULL), 1.52 +fCases(NULL) 1.53 +{ 1.54 +} 1.55 + 1.56 +RBTestData::RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status) 1.57 +: TestData(ures_getKey(data)), 1.58 +fData(data), 1.59 +fHeaders(headers), 1.60 +fSettings(NULL), 1.61 +fCases(NULL) 1.62 +{ 1.63 + UErrorCode intStatus = U_ZERO_ERROR; 1.64 + UResourceBundle *currHeaders = ures_getByKey(data, "Headers", NULL, &intStatus); 1.65 + if(intStatus == U_ZERO_ERROR) { 1.66 + ures_close(fHeaders); 1.67 + fHeaders = currHeaders; 1.68 + } else { 1.69 + intStatus = U_ZERO_ERROR; 1.70 + } 1.71 + fSettings = ures_getByKey(data, "Settings", NULL, &intStatus); 1.72 + fSettingsSize = ures_getSize(fSettings); 1.73 + UResourceBundle *info = ures_getByKey(data, "Info", NULL, &intStatus); 1.74 + if(U_SUCCESS(intStatus)) { 1.75 + fInfo = new RBDataMap(info, status); 1.76 + } else { 1.77 + intStatus = U_ZERO_ERROR; 1.78 + } 1.79 + fCases = ures_getByKey(data, "Cases", NULL, &status); 1.80 + fCasesSize = ures_getSize(fCases); 1.81 + 1.82 + ures_close(info); 1.83 +} 1.84 + 1.85 + 1.86 +RBTestData::~RBTestData() 1.87 +{ 1.88 + ures_close(fData); 1.89 + ures_close(fHeaders); 1.90 + ures_close(fSettings); 1.91 + ures_close(fCases); 1.92 +} 1.93 + 1.94 +UBool RBTestData::getInfo(const DataMap *& info, UErrorCode &/*status*/) const 1.95 +{ 1.96 + if(fInfo) { 1.97 + info = fInfo; 1.98 + return TRUE; 1.99 + } else { 1.100 + info = NULL; 1.101 + return FALSE; 1.102 + } 1.103 +} 1.104 + 1.105 +UBool RBTestData::nextSettings(const DataMap *& settings, UErrorCode &status) 1.106 +{ 1.107 + UErrorCode intStatus = U_ZERO_ERROR; 1.108 + UResourceBundle *data = ures_getByIndex(fSettings, fCurrentSettings++, NULL, &intStatus); 1.109 + if(U_SUCCESS(intStatus)) { 1.110 + // reset the cases iterator 1.111 + fCurrentCase = 0; 1.112 + if(fCurrSettings == NULL) { 1.113 + fCurrSettings = new RBDataMap(data, status); 1.114 + } else { 1.115 + ((RBDataMap *)fCurrSettings)->init(data, status); 1.116 + } 1.117 + ures_close(data); 1.118 + settings = fCurrSettings; 1.119 + return TRUE; 1.120 + } else { 1.121 + settings = NULL; 1.122 + return FALSE; 1.123 + } 1.124 +} 1.125 + 1.126 +UBool RBTestData::nextCase(const DataMap *& nextCase, UErrorCode &status) 1.127 +{ 1.128 + UErrorCode intStatus = U_ZERO_ERROR; 1.129 + UResourceBundle *currCase = ures_getByIndex(fCases, fCurrentCase++, NULL, &intStatus); 1.130 + if(U_SUCCESS(intStatus)) { 1.131 + if(fCurrCase == NULL) { 1.132 + fCurrCase = new RBDataMap(fHeaders, currCase, status); 1.133 + } else { 1.134 + ((RBDataMap *)fCurrCase)->init(fHeaders, currCase, status); 1.135 + } 1.136 + ures_close(currCase); 1.137 + nextCase = fCurrCase; 1.138 + return TRUE; 1.139 + } else { 1.140 + nextCase = NULL; 1.141 + return FALSE; 1.142 + } 1.143 +} 1.144 + 1.145 +