]> git.saurik.com Git - apple/icu.git/blame - icuSources/tools/ctestfw/testdata.cpp
ICU-6.2.14.tar.gz
[apple/icu.git] / icuSources / tools / ctestfw / testdata.cpp
CommitLineData
b75a7d8f
A
1/********************************************************************
2 * COPYRIGHT:
374ca955 3 * Copyright (c) 2002-2004, International Business Machines Corporation and
b75a7d8f
A
4 * others. All Rights Reserved.
5 ********************************************************************/
6
7/* Created by weiv 05/09/2002 */
8
374ca955 9#include "unicode/testdata.h"
b75a7d8f
A
10
11TestData::TestData(const char* name)
12: name(name),
13fInfo(NULL),
14fCurrSettings(NULL),
15fCurrCase(NULL),
16fSettingsSize(0),
17fCasesSize(0),
18fCurrentSettings(0),
19fCurrentCase(0)
20
21{
22}
23
24TestData::~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
36const char * TestData::getName() const
37{
38 return name;
39}
40
41
42
43RBTestData::RBTestData(const char* name)
44: TestData(name),
45fData(NULL),
46fHeaders(NULL),
47fSettings(NULL),
48fCases(NULL)
49{
50}
51
52RBTestData::RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status)
53: TestData(ures_getKey(data)),
54fData(data),
55fHeaders(headers),
56fSettings(NULL),
57fCases(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
82RBTestData::~RBTestData()
83{
84 ures_close(fData);
85 ures_close(fHeaders);
86 ures_close(fSettings);
87 ures_close(fCases);
88}
89
90UBool 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
101UBool 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
122UBool 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