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