]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/ctestfw/unicode/testdata.h
ICU-6.2.8.tar.gz
[apple/icu.git] / icuSources / tools / ctestfw / unicode / testdata.h
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 2002-2004, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6
7 /* Created by weiv 05/09/2002 */
8
9 /* Base class for data driven tests */
10
11 #ifndef U_TESTFW_TESTDATA
12 #define U_TESTFW_TESTDATA
13
14 #include "unicode/tstdtmod.h"
15 #include "unicode/datamap.h"
16
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.
26 * Example:
27 * DataMap *settings = NULL;
28 * DataMap *cases = NULL;
29 * while(nextSettings(settings, status)) {
30 * // set settings for the subtest
31 * while(nextCase(cases, status) {
32 * // process testcase
33 * }
34 * }
35 */
36
37 class T_CTEST_EXPORT_API TestData {
38 const char* name;
39
40 protected:
41 DataMap *fInfo;
42 DataMap *fCurrSettings;
43 DataMap *fCurrCase;
44 int32_t fSettingsSize;
45 int32_t fCasesSize;
46 int32_t fCurrentSettings;
47 int32_t fCurrentCase;
48 /** constructor - don't use */
49 TestData(const char* name);
50
51 public:
52 virtual ~TestData();
53
54 const char* getName() const;
55
56 /** Get a pointer to an object owned DataMap that contains more information on this
57 * TestData object.
58 * Usual fields is "Description".
59 * @param info pass in a const DataMap pointer. If no info, it will be set to NULL
60 */
61 virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const = 0;
62
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
69 * settings.
70 */
71 virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status) = 0;
72
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
79 * cases.
80 */
81 virtual UBool nextCase(const DataMap *& data, UErrorCode &status) = 0;
82 };
83
84 // implementation of TestData that uses resource bundles
85
86 class T_CTEST_EXPORT_API RBTestData : public TestData {
87 UResourceBundle *fData;
88 UResourceBundle *fHeaders;
89 UResourceBundle *fSettings;
90 UResourceBundle *fCases;
91
92 public:
93 RBTestData(const char* name);
94 RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status);
95 private:
96 // RBTestData() {};
97 // RBTestData(const RBTestData& original) {};
98 RBTestData& operator=(const RBTestData& /*original*/) {return *this;};
99
100 public:
101 virtual ~RBTestData();
102
103 virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const;
104
105 virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status);
106 virtual UBool nextCase(const DataMap *& nextCase, UErrorCode &status);
107 };
108
109 #endif