1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 2002-2006, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
9 /* Created by weiv 05/09/2002 */
11 /* Base class for data driven tests */
13 #ifndef U_TESTFW_TESTDATA
14 #define U_TESTFW_TESTDATA
16 #include "unicode/tstdtmod.h"
17 #include "unicode/datamap.h"
20 /** This is the class that abstracts one of the tests in a data file
21 * It is usually instantiated using TestDataModule::CreateTestData method
22 * This class provides two important methods: nextSettings and nextCase
23 * Usually, one walks through all settings and executes all cases for
24 * each setting. Each call to nextSettings resets the cases iterator.
25 * Individual test cases have to have the same number of fields as the
26 * number of entries in headers. Default headers can be specified in
27 * the TestDataModule info section. The default headers will be overriden
28 * by per-test headers.
30 * DataMap *settings = NULL;
31 * DataMap *cases = NULL;
32 * while(nextSettings(settings, status)) {
33 * // set settings for the subtest
34 * while(nextCase(cases, status) {
40 class T_CTEST_EXPORT_API TestData
{
45 DataMap
*fCurrSettings
;
47 int32_t fSettingsSize
;
49 int32_t fCurrentSettings
;
51 /** constructor - don't use */
52 TestData(const char* name
);
57 const char* getName() const;
59 /** Get a pointer to an object owned DataMap that contains more information on this
61 * Usual fields is "Description".
62 * @param info pass in a const DataMap pointer. If no info, it will be set to NULL
64 virtual UBool
getInfo(const DataMap
*& info
, UErrorCode
&status
) const = 0;
66 /** Gets the next set of settings for the test. Resets the cases iterator.
67 * DataMap is owned by the object and should not be deleted.
68 * @param settings a DataMap pointer provided by the user. Will be NULL if
69 * no more settings are available.
70 * @param status for reporting unexpected errors.
71 * @return A boolean, TRUE if there are settings, FALSE if there is no more
74 virtual UBool
nextSettings(const DataMap
*& settings
, UErrorCode
&status
) = 0;
76 /** Gets the next test case.
77 * DataMap is owned by the object and should not be deleted.
78 * @param data a DataMap pointer provided by the user. Will be NULL if
79 * no more cases are available.
80 * @param status for reporting unexpected errors.
81 * @return A boolean, TRUE if there are cases, FALSE if there is no more
84 virtual UBool
nextCase(const DataMap
*& data
, UErrorCode
&status
) = 0;
87 // implementation of TestData that uses resource bundles
89 class T_CTEST_EXPORT_API RBTestData
: public TestData
{
90 UResourceBundle
*fData
;
91 UResourceBundle
*fHeaders
;
92 UResourceBundle
*fSettings
;
93 UResourceBundle
*fCases
;
96 RBTestData(const char* name
);
97 RBTestData(UResourceBundle
*data
, UResourceBundle
*headers
, UErrorCode
& status
);
100 // RBTestData(const RBTestData& original) {};
101 RBTestData
& operator=(const RBTestData
& /*original*/);
104 virtual ~RBTestData();
106 virtual UBool
getInfo(const DataMap
*& info
, UErrorCode
&status
) const;
108 virtual UBool
nextSettings(const DataMap
*& settings
, UErrorCode
&status
);
109 virtual UBool
nextCase(const DataMap
*& nextCase
, UErrorCode
&status
);