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