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 /* Base class for data driven tests */
11 #ifndef U_TESTFW_TESTDATA
12 #define U_TESTFW_TESTDATA
14 #include "unicode/tstdtmod.h"
15 #include "unicode/datamap.h"
17 /** This is the class that abstracts one of the tests in a data file
18 * It is usually instantiated using TestDataModule::CreateTestData method
19 * This class provides two important methods: nextSettings and nextCase
20 * Usually, one walks through all settings and executes all cases for
21 * each setting. Each call to nextSettings resets the cases iterator.
22 * Individual test cases have to have the same number of fields as the
23 * number of entries in headers. Default headers can be specified in
24 * the TestDataModule info section. The default headers will be overriden
25 * by per-test headers.
27 * DataMap *settings = NULL;
28 * DataMap *cases = NULL;
29 * while(nextSettings(settings, status)) {
30 * // set settings for the subtest
31 * while(nextCase(cases, status) {
37 class T_CTEST_EXPORT_API TestData
{
42 DataMap
*fCurrSettings
;
44 int32_t fSettingsSize
;
46 int32_t fCurrentSettings
;
48 /** constructor - don't use */
49 TestData(const char* name
);
54 const char* getName() const;
56 /** Get a pointer to an object owned DataMap that contains more information on this
58 * Usual fields is "Description".
59 * @param info pass in a const DataMap pointer. If no info, it will be set to NULL
61 virtual UBool
getInfo(const DataMap
*& info
, UErrorCode
&status
) const = 0;
63 /** Gets the next set of settings for the test. Resets the cases iterator.
64 * DataMap is owned by the object and should not be deleted.
65 * @param settings a DataMap pointer provided by the user. Will be NULL if
66 * no more settings are available.
67 * @param status for reporting unexpected errors.
68 * @return A boolean, TRUE if there are settings, FALSE if there is no more
71 virtual UBool
nextSettings(const DataMap
*& settings
, UErrorCode
&status
) = 0;
73 /** Gets the next test case.
74 * DataMap is owned by the object and should not be deleted.
75 * @param data a DataMap pointer provided by the user. Will be NULL if
76 * no more cases are available.
77 * @param status for reporting unexpected errors.
78 * @return A boolean, TRUE if there are cases, FALSE if there is no more
81 virtual UBool
nextCase(const DataMap
*& data
, UErrorCode
&status
) = 0;
84 // implementation of TestData that uses resource bundles
86 class T_CTEST_EXPORT_API RBTestData
: public TestData
{
87 UResourceBundle
*fData
;
88 UResourceBundle
*fHeaders
;
89 UResourceBundle
*fSettings
;
90 UResourceBundle
*fCases
;
93 RBTestData(const char* name
);
94 RBTestData(UResourceBundle
*data
, UResourceBundle
*headers
, UErrorCode
& status
);
97 // RBTestData(const RBTestData& original) {};
98 RBTestData
& operator=(const RBTestData
& /*original*/) {return *this;};
101 virtual ~RBTestData();
103 virtual UBool
getInfo(const DataMap
*& info
, UErrorCode
&status
) const;
105 virtual UBool
nextSettings(const DataMap
*& settings
, UErrorCode
&status
);
106 virtual UBool
nextCase(const DataMap
*& nextCase
, UErrorCode
&status
);