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