]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/ctestfw/tstdtmod.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 2002-2014, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
9 /* Created by weiv 05/09/2002 */
13 #include "unicode/tstdtmod.h"
17 TestLog::~TestLog() {}
19 IcuTestErrorCode::~IcuTestErrorCode() {
20 // Safe because our handleFailure() does not throw exceptions.
21 if(isFailure()) { handleFailure(); }
24 UBool
IcuTestErrorCode::logIfFailureAndReset(const char *fmt
, ...) {
29 vsprintf(buffer
, fmt
, ap
);
31 UnicodeString
msg(testName
, -1, US_INV
);
32 msg
.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV
));
33 msg
.append(UNICODE_STRING_SIMPLE(" - ")).append(UnicodeString(buffer
, -1, US_INV
));
43 UBool
IcuTestErrorCode::logDataIfFailureAndReset(const char *fmt
, ...) {
48 vsprintf(buffer
, fmt
, ap
);
50 UnicodeString
msg(testName
, -1, US_INV
);
51 msg
.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV
));
52 msg
.append(UNICODE_STRING_SIMPLE(" - ")).append(UnicodeString(buffer
, -1, US_INV
));
53 testClass
.dataerrln(msg
);
62 void IcuTestErrorCode::handleFailure() const {
63 // testClass.errln("%s failure - %s", testName, errorName());
64 UnicodeString
msg(testName
, -1, US_INV
);
65 msg
.append(UNICODE_STRING_SIMPLE(" failure: ")).append(UnicodeString(errorName(), -1, US_INV
));
67 if (get() == U_MISSING_RESOURCE_ERROR
|| get() == U_FILE_ACCESS_ERROR
) {
68 testClass
.dataerrln(msg
);
74 TestDataModule
*TestDataModule::getTestDataModule(const char* name
, TestLog
& log
, UErrorCode
&status
)
76 if(U_FAILURE(status
)) {
79 TestDataModule
*result
= NULL
;
81 // TODO: probe for resource bundle and then for XML.
82 // According to that, construct an appropriate driver object
84 result
= new RBTestDataModule(name
, log
, status
);
85 if(U_SUCCESS(status
)) {
93 TestDataModule::TestDataModule(const char* name
, TestLog
& log
, UErrorCode
& /*status*/)
100 TestDataModule::~TestDataModule() {
106 const char * TestDataModule::getName() const
113 RBTestDataModule::~RBTestDataModule()
115 ures_close(fTestData
);
116 ures_close(fModuleBundle
);
121 RBTestDataModule::RBTestDataModule(const char* name
, TestLog
& log
, UErrorCode
& status
)
122 : TestDataModule(name
, log
, status
),
129 fDataTestValid
= TRUE
;
130 fModuleBundle
= getTestBundle(name
, status
);
132 fTestData
= ures_getByKey(fModuleBundle
, "TestData", NULL
, &status
);
133 fNumberOfTests
= ures_getSize(fTestData
);
134 fInfoRB
= ures_getByKey(fModuleBundle
, "Info", NULL
, &status
);
135 if(status
!= U_ZERO_ERROR
) {
136 log
.errln(UNICODE_STRING_SIMPLE("Unable to initalize test data - missing mandatory description resources!"));
137 fDataTestValid
= FALSE
;
139 fInfo
= new RBDataMap(fInfoRB
, status
);
144 UBool
RBTestDataModule::getInfo(const DataMap
*& info
, UErrorCode
&/*status*/) const
154 TestData
* RBTestDataModule::createTestData(int32_t index
, UErrorCode
&status
) const
156 TestData
*result
= NULL
;
157 UErrorCode intStatus
= U_ZERO_ERROR
;
159 if(fDataTestValid
== TRUE
) {
160 // Both of these resources get adopted by a TestData object.
161 UResourceBundle
*DataFillIn
= ures_getByIndex(fTestData
, index
, NULL
, &status
);
162 UResourceBundle
*headers
= ures_getByKey(fInfoRB
, "Headers", NULL
, &intStatus
);
164 if(U_SUCCESS(status
)) {
165 result
= new RBTestData(DataFillIn
, headers
, status
);
167 if(U_SUCCESS(status
)) {
173 ures_close(DataFillIn
);
177 status
= U_MISSING_RESOURCE_ERROR
;
182 TestData
* RBTestDataModule::createTestData(const char* name
, UErrorCode
&status
) const
184 TestData
*result
= NULL
;
185 UErrorCode intStatus
= U_ZERO_ERROR
;
187 if(fDataTestValid
== TRUE
) {
188 // Both of these resources get adopted by a TestData object.
189 UResourceBundle
*DataFillIn
= ures_getByKey(fTestData
, name
, NULL
, &status
);
190 UResourceBundle
*headers
= ures_getByKey(fInfoRB
, "Headers", NULL
, &intStatus
);
192 if(U_SUCCESS(status
)) {
193 result
= new RBTestData(DataFillIn
, headers
, status
);
194 if(U_SUCCESS(status
)) {
200 ures_close(DataFillIn
);
204 status
= U_MISSING_RESOURCE_ERROR
;
211 //Get test data from ResourceBundles
213 RBTestDataModule::getTestBundle(const char* bundleName
, UErrorCode
&status
)
215 if(U_SUCCESS(status
)) {
216 UResourceBundle
*testBundle
= NULL
;
217 const char* icu_data
= fLog
.getTestDataPath(status
);
218 if (testBundle
== NULL
) {
219 testBundle
= ures_openDirect(icu_data
, bundleName
, &status
);
220 if (status
!= U_ZERO_ERROR
) {
221 fLog
.dataerrln(UNICODE_STRING_SIMPLE("Could not load test data from resourcebundle: ") + UnicodeString(bundleName
, -1, US_INV
));
222 fDataTestValid
= FALSE
;