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