intl/icu/source/tools/ctestfw/testdata.cpp

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial