]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/ctestfw/tstdtmod.cpp
1 /********************************************************************
3 * Copyright (c) 2002-2004, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 /* Created by weiv 05/09/2002 */
9 #include "unicode/tstdtmod.h"
12 TestDataModule
*TestDataModule::getTestDataModule(const char* name
, TestLog
& log
, UErrorCode
&status
)
14 if(U_FAILURE(status
)) {
17 TestDataModule
*result
= NULL
;
19 // TODO: probe for resource bundle and then for XML.
20 // According to that, construct an appropriate driver object
22 result
= new RBTestDataModule(name
, log
, status
);
23 if(U_SUCCESS(status
)) {
31 TestDataModule::TestDataModule(const char* name
, TestLog
& log
, UErrorCode
& /*status*/)
38 TestDataModule::~TestDataModule() {
44 const char * TestDataModule::getName() const
51 RBTestDataModule::~RBTestDataModule()
53 ures_close(fTestData
);
54 ures_close(fModuleBundle
);
59 RBTestDataModule::RBTestDataModule(const char* name
, TestLog
& log
, UErrorCode
& status
)
60 : TestDataModule(name
, log
, status
),
67 fDataTestValid
= TRUE
;
68 fModuleBundle
= getTestBundle(name
, status
);
70 fTestData
= ures_getByKey(fModuleBundle
, "TestData", NULL
, &status
);
71 fNumberOfTests
= ures_getSize(fTestData
);
72 fInfoRB
= ures_getByKey(fModuleBundle
, "Info", NULL
, &status
);
73 if(status
!= U_ZERO_ERROR
) {
74 log
.errln("Unable to initalize test data - missing mandatory description resources!");
75 fDataTestValid
= FALSE
;
77 fInfo
= new RBDataMap(fInfoRB
, status
);
82 UBool
RBTestDataModule::getInfo(const DataMap
*& info
, UErrorCode
&/*status*/) const
92 TestData
* RBTestDataModule::createTestData(int32_t index
, UErrorCode
&status
) const
94 TestData
*result
= NULL
;
95 UErrorCode intStatus
= U_ZERO_ERROR
;
97 if(fDataTestValid
== TRUE
) {
98 // Both of these resources get adopted by a TestData object.
99 UResourceBundle
*DataFillIn
= ures_getByIndex(fTestData
, index
, NULL
, &status
);
100 UResourceBundle
*headers
= ures_getByKey(fInfoRB
, "Headers", NULL
, &intStatus
);
102 if(U_SUCCESS(status
)) {
103 result
= new RBTestData(DataFillIn
, headers
, status
);
105 if(U_SUCCESS(status
)) {
111 ures_close(DataFillIn
);
115 status
= U_MISSING_RESOURCE_ERROR
;
120 TestData
* RBTestDataModule::createTestData(const char* name
, UErrorCode
&status
) const
122 TestData
*result
= NULL
;
123 UErrorCode intStatus
= U_ZERO_ERROR
;
125 if(fDataTestValid
== TRUE
) {
126 // Both of these resources get adopted by a TestData object.
127 UResourceBundle
*DataFillIn
= ures_getByKey(fTestData
, name
, NULL
, &status
);
128 UResourceBundle
*headers
= ures_getByKey(fInfoRB
, "Headers", NULL
, &intStatus
);
130 if(U_SUCCESS(status
)) {
131 result
= new RBTestData(DataFillIn
, headers
, status
);
132 if(U_SUCCESS(status
)) {
138 ures_close(DataFillIn
);
142 status
= U_MISSING_RESOURCE_ERROR
;
149 //Get test data from ResourceBundles
151 RBTestDataModule::getTestBundle(const char* bundleName
, UErrorCode
&status
)
153 if(U_SUCCESS(status
)) {
154 UResourceBundle
*testBundle
= NULL
;
155 const char* icu_data
= fLog
.getTestDataPath(status
);
156 if (testBundle
== NULL
) {
157 testBundle
= ures_openDirect(icu_data
, bundleName
, &status
);
158 if (status
!= U_ZERO_ERROR
) {
159 fLog
.errln(UnicodeString("Failed: could not load test data from resourcebundle: ") + UnicodeString(bundleName
));
160 fDataTestValid
= FALSE
;