1 /********************************************************************
3 * Copyright (c) 2002-2005, 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"
18 /** This is the class that abstracts one of the tests in a data file
19 * It is usually instantiated using TestDataModule::CreateTestData method
20 * This class provides two important methods: nextSettings and nextCase
21 * Usually, one walks through all settings and executes all cases for
22 * each setting. Each call to nextSettings resets the cases iterator.
23 * Individual test cases have to have the same number of fields as the
24 * number of entries in headers. Default headers can be specified in
25 * the TestDataModule info section. The default headers will be overriden
26 * by per-test headers.
28 * DataMap *settings = NULL;
29 * DataMap *cases = NULL;
30 * while(nextSettings(settings, status)) {
31 * // set settings for the subtest
32 * while(nextCase(cases, status) {
38 class T_CTEST_EXPORT_API TestData
{
43 DataMap
*fCurrSettings
;
45 int32_t fSettingsSize
;
47 int32_t fCurrentSettings
;
49 /** constructor - don't use */
50 TestData(const char* name
);
55 const char* getName() const;
57 /** Get a pointer to an object owned DataMap that contains more information on this
59 * Usual fields is "Description".
60 * @param info pass in a const DataMap pointer. If no info, it will be set to NULL
62 virtual UBool
getInfo(const DataMap
*& info
, UErrorCode
&status
) const = 0;
64 /** Gets the next set of settings for the test. Resets the cases iterator.
65 * DataMap is owned by the object and should not be deleted.
66 * @param settings a DataMap pointer provided by the user. Will be NULL if
67 * no more settings are available.
68 * @param status for reporting unexpected errors.
69 * @return A boolean, TRUE if there are settings, FALSE if there is no more
72 virtual UBool
nextSettings(const DataMap
*& settings
, UErrorCode
&status
) = 0;
74 /** Gets the next test case.
75 * DataMap is owned by the object and should not be deleted.
76 * @param data a DataMap pointer provided by the user. Will be NULL if
77 * no more cases are available.
78 * @param status for reporting unexpected errors.
79 * @return A boolean, TRUE if there are cases, FALSE if there is no more
82 virtual UBool
nextCase(const DataMap
*& data
, UErrorCode
&status
) = 0;
85 // implementation of TestData that uses resource bundles
87 class T_CTEST_EXPORT_API RBTestData
: public TestData
{
88 UResourceBundle
*fData
;
89 UResourceBundle
*fHeaders
;
90 UResourceBundle
*fSettings
;
91 UResourceBundle
*fCases
;
94 RBTestData(const char* name
);
95 RBTestData(UResourceBundle
*data
, UResourceBundle
*headers
, UErrorCode
& status
);
98 // RBTestData(const RBTestData& original) {};
99 RBTestData
& operator=(const RBTestData
& /*original*/) {return *this;};
102 virtual ~RBTestData();
104 virtual UBool
getInfo(const DataMap
*& info
, UErrorCode
&status
) const;
106 virtual UBool
nextSettings(const DataMap
*& settings
, UErrorCode
&status
);
107 virtual UBool
nextCase(const DataMap
*& nextCase
, UErrorCode
&status
);