]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/ctestfw/tstdtmod.cpp
1 /********************************************************************
3 * Copyright (c) 2002-2006, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 /* Created by weiv 05/09/2002 */
9 #include "unicode/tstdtmod.h"
12 TestLog::~TestLog() {}
14 TestDataModule
*TestDataModule::getTestDataModule(const char* name
, TestLog
& log
, UErrorCode
&status
)
16 if(U_FAILURE(status
)) {
19 TestDataModule
*result
= NULL
;
21 // TODO: probe for resource bundle and then for XML.
22 // According to that, construct an appropriate driver object
24 result
= new RBTestDataModule(name
, log
, status
);
25 if(U_SUCCESS(status
)) {
33 TestDataModule::TestDataModule(const char* name
, TestLog
& log
, UErrorCode
& /*status*/)
40 TestDataModule::~TestDataModule() {
46 const char * TestDataModule::getName() const
53 RBTestDataModule::~RBTestDataModule()
55 ures_close(fTestData
);
56 ures_close(fModuleBundle
);
61 RBTestDataModule::RBTestDataModule(const char* name
, TestLog
& log
, UErrorCode
& status
)
62 : TestDataModule(name
, log
, status
),
69 fDataTestValid
= TRUE
;
70 fModuleBundle
= getTestBundle(name
, status
);
72 fTestData
= ures_getByKey(fModuleBundle
, "TestData", NULL
, &status
);
73 fNumberOfTests
= ures_getSize(fTestData
);
74 fInfoRB
= ures_getByKey(fModuleBundle
, "Info", NULL
, &status
);
75 if(status
!= U_ZERO_ERROR
) {
76 log
.errln(UNICODE_STRING_SIMPLE("Unable to initalize test data - missing mandatory description resources!"));
77 fDataTestValid
= FALSE
;
79 fInfo
= new RBDataMap(fInfoRB
, status
);
84 UBool
RBTestDataModule::getInfo(const DataMap
*& info
, UErrorCode
&/*status*/) const
94 TestData
* RBTestDataModule::createTestData(int32_t index
, UErrorCode
&status
) const
96 TestData
*result
= NULL
;
97 UErrorCode intStatus
= U_ZERO_ERROR
;
99 if(fDataTestValid
== TRUE
) {
100 // Both of these resources get adopted by a TestData object.
101 UResourceBundle
*DataFillIn
= ures_getByIndex(fTestData
, index
, NULL
, &status
);
102 UResourceBundle
*headers
= ures_getByKey(fInfoRB
, "Headers", NULL
, &intStatus
);
104 if(U_SUCCESS(status
)) {
105 result
= new RBTestData(DataFillIn
, headers
, status
);
107 if(U_SUCCESS(status
)) {
113 ures_close(DataFillIn
);
117 status
= U_MISSING_RESOURCE_ERROR
;
122 TestData
* RBTestDataModule::createTestData(const char* name
, UErrorCode
&status
) const
124 TestData
*result
= NULL
;
125 UErrorCode intStatus
= U_ZERO_ERROR
;
127 if(fDataTestValid
== TRUE
) {
128 // Both of these resources get adopted by a TestData object.
129 UResourceBundle
*DataFillIn
= ures_getByKey(fTestData
, name
, NULL
, &status
);
130 UResourceBundle
*headers
= ures_getByKey(fInfoRB
, "Headers", NULL
, &intStatus
);
132 if(U_SUCCESS(status
)) {
133 result
= new RBTestData(DataFillIn
, headers
, status
);
134 if(U_SUCCESS(status
)) {
140 ures_close(DataFillIn
);
144 status
= U_MISSING_RESOURCE_ERROR
;
151 //Get test data from ResourceBundles
153 RBTestDataModule::getTestBundle(const char* bundleName
, UErrorCode
&status
)
155 if(U_SUCCESS(status
)) {
156 UResourceBundle
*testBundle
= NULL
;
157 const char* icu_data
= fLog
.getTestDataPath(status
);
158 if (testBundle
== NULL
) {
159 testBundle
= ures_openDirect(icu_data
, bundleName
, &status
);
160 if (status
!= U_ZERO_ERROR
) {
161 fLog
.errln(UNICODE_STRING_SIMPLE("Failed: could not load test data from resourcebundle: ") + UnicodeString(bundleName
, -1, US_INV
));
162 fDataTestValid
= FALSE
;