]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/ctestfw/tstdtmod.cpp
1 /********************************************************************
3 * Copyright (c) 2002-2014, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 /* Created by weiv 05/09/2002 */
11 #include "unicode/tstdtmod.h"
15 TestLog::~TestLog() {}
17 IcuTestErrorCode::~IcuTestErrorCode() {
18 // Safe because our handleFailure() does not throw exceptions.
19 if(isFailure()) { handleFailure(); }
22 UBool
IcuTestErrorCode::logIfFailureAndReset(const char *fmt
, ...) {
27 vsprintf(buffer
, fmt
, ap
);
29 UnicodeString
msg(testName
, -1, US_INV
);
30 msg
.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV
));
31 msg
.append(UNICODE_STRING_SIMPLE(" - ")).append(UnicodeString(buffer
, -1, US_INV
));
41 UBool
IcuTestErrorCode::logDataIfFailureAndReset(const char *fmt
, ...) {
46 vsprintf(buffer
, fmt
, ap
);
48 UnicodeString
msg(testName
, -1, US_INV
);
49 msg
.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV
));
50 msg
.append(UNICODE_STRING_SIMPLE(" - ")).append(UnicodeString(buffer
, -1, US_INV
));
51 testClass
.dataerrln(msg
);
60 void IcuTestErrorCode::handleFailure() const {
61 // testClass.errln("%s failure - %s", testName, errorName());
62 UnicodeString
msg(testName
, -1, US_INV
);
63 msg
.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV
));
65 if (get() == U_MISSING_RESOURCE_ERROR
|| get() == U_FILE_ACCESS_ERROR
) {
66 testClass
.dataerrln(msg
);
72 TestDataModule
*TestDataModule::getTestDataModule(const char* name
, TestLog
& log
, UErrorCode
&status
)
74 if(U_FAILURE(status
)) {
77 TestDataModule
*result
= NULL
;
79 // TODO: probe for resource bundle and then for XML.
80 // According to that, construct an appropriate driver object
82 result
= new RBTestDataModule(name
, log
, status
);
83 if(U_SUCCESS(status
)) {
91 TestDataModule::TestDataModule(const char* name
, TestLog
& log
, UErrorCode
& /*status*/)
98 TestDataModule::~TestDataModule() {
104 const char * TestDataModule::getName() const
111 RBTestDataModule::~RBTestDataModule()
113 ures_close(fTestData
);
114 ures_close(fModuleBundle
);
119 RBTestDataModule::RBTestDataModule(const char* name
, TestLog
& log
, UErrorCode
& status
)
120 : TestDataModule(name
, log
, status
),
127 fDataTestValid
= TRUE
;
128 fModuleBundle
= getTestBundle(name
, status
);
130 fTestData
= ures_getByKey(fModuleBundle
, "TestData", NULL
, &status
);
131 fNumberOfTests
= ures_getSize(fTestData
);
132 fInfoRB
= ures_getByKey(fModuleBundle
, "Info", NULL
, &status
);
133 if(status
!= U_ZERO_ERROR
) {
134 log
.errln(UNICODE_STRING_SIMPLE("Unable to initalize test data - missing mandatory description resources!"));
135 fDataTestValid
= FALSE
;
137 fInfo
= new RBDataMap(fInfoRB
, status
);
142 UBool
RBTestDataModule::getInfo(const DataMap
*& info
, UErrorCode
&/*status*/) const
152 TestData
* RBTestDataModule::createTestData(int32_t index
, UErrorCode
&status
) const
154 TestData
*result
= NULL
;
155 UErrorCode intStatus
= U_ZERO_ERROR
;
157 if(fDataTestValid
== TRUE
) {
158 // Both of these resources get adopted by a TestData object.
159 UResourceBundle
*DataFillIn
= ures_getByIndex(fTestData
, index
, NULL
, &status
);
160 UResourceBundle
*headers
= ures_getByKey(fInfoRB
, "Headers", NULL
, &intStatus
);
162 if(U_SUCCESS(status
)) {
163 result
= new RBTestData(DataFillIn
, headers
, status
);
165 if(U_SUCCESS(status
)) {
171 ures_close(DataFillIn
);
175 status
= U_MISSING_RESOURCE_ERROR
;
180 TestData
* RBTestDataModule::createTestData(const char* name
, UErrorCode
&status
) const
182 TestData
*result
= NULL
;
183 UErrorCode intStatus
= U_ZERO_ERROR
;
185 if(fDataTestValid
== TRUE
) {
186 // Both of these resources get adopted by a TestData object.
187 UResourceBundle
*DataFillIn
= ures_getByKey(fTestData
, name
, NULL
, &status
);
188 UResourceBundle
*headers
= ures_getByKey(fInfoRB
, "Headers", NULL
, &intStatus
);
190 if(U_SUCCESS(status
)) {
191 result
= new RBTestData(DataFillIn
, headers
, status
);
192 if(U_SUCCESS(status
)) {
198 ures_close(DataFillIn
);
202 status
= U_MISSING_RESOURCE_ERROR
;
209 //Get test data from ResourceBundles
211 RBTestDataModule::getTestBundle(const char* bundleName
, UErrorCode
&status
)
213 if(U_SUCCESS(status
)) {
214 UResourceBundle
*testBundle
= NULL
;
215 const char* icu_data
= fLog
.getTestDataPath(status
);
216 if (testBundle
== NULL
) {
217 testBundle
= ures_openDirect(icu_data
, bundleName
, &status
);
218 if (status
!= U_ZERO_ERROR
) {
219 fLog
.dataerrln(UNICODE_STRING_SIMPLE("Could not load test data from resourcebundle: ") + UnicodeString(bundleName
, -1, US_INV
));
220 fDataTestValid
= FALSE
;