Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * COPYRIGHT: |
michael@0 | 3 | * Copyright (c) 2002-2006, International Business Machines Corporation and |
michael@0 | 4 | * others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************/ |
michael@0 | 6 | |
michael@0 | 7 | /* Created by weiv 05/09/2002 */ |
michael@0 | 8 | |
michael@0 | 9 | /* Base class for data driven tests */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef U_TESTFW_TESTDATA |
michael@0 | 12 | #define U_TESTFW_TESTDATA |
michael@0 | 13 | |
michael@0 | 14 | #include "unicode/tstdtmod.h" |
michael@0 | 15 | #include "unicode/datamap.h" |
michael@0 | 16 | |
michael@0 | 17 | |
michael@0 | 18 | /** This is the class that abstracts one of the tests in a data file |
michael@0 | 19 | * It is usually instantiated using TestDataModule::CreateTestData method |
michael@0 | 20 | * This class provides two important methods: nextSettings and nextCase |
michael@0 | 21 | * Usually, one walks through all settings and executes all cases for |
michael@0 | 22 | * each setting. Each call to nextSettings resets the cases iterator. |
michael@0 | 23 | * Individual test cases have to have the same number of fields as the |
michael@0 | 24 | * number of entries in headers. Default headers can be specified in |
michael@0 | 25 | * the TestDataModule info section. The default headers will be overriden |
michael@0 | 26 | * by per-test headers. |
michael@0 | 27 | * Example: |
michael@0 | 28 | * DataMap *settings = NULL; |
michael@0 | 29 | * DataMap *cases = NULL; |
michael@0 | 30 | * while(nextSettings(settings, status)) { |
michael@0 | 31 | * // set settings for the subtest |
michael@0 | 32 | * while(nextCase(cases, status) { |
michael@0 | 33 | * // process testcase |
michael@0 | 34 | * } |
michael@0 | 35 | * } |
michael@0 | 36 | */ |
michael@0 | 37 | |
michael@0 | 38 | class T_CTEST_EXPORT_API TestData { |
michael@0 | 39 | const char* name; |
michael@0 | 40 | |
michael@0 | 41 | protected: |
michael@0 | 42 | DataMap *fInfo; |
michael@0 | 43 | DataMap *fCurrSettings; |
michael@0 | 44 | DataMap *fCurrCase; |
michael@0 | 45 | int32_t fSettingsSize; |
michael@0 | 46 | int32_t fCasesSize; |
michael@0 | 47 | int32_t fCurrentSettings; |
michael@0 | 48 | int32_t fCurrentCase; |
michael@0 | 49 | /** constructor - don't use */ |
michael@0 | 50 | TestData(const char* name); |
michael@0 | 51 | |
michael@0 | 52 | public: |
michael@0 | 53 | virtual ~TestData(); |
michael@0 | 54 | |
michael@0 | 55 | const char* getName() const; |
michael@0 | 56 | |
michael@0 | 57 | /** Get a pointer to an object owned DataMap that contains more information on this |
michael@0 | 58 | * TestData object. |
michael@0 | 59 | * Usual fields is "Description". |
michael@0 | 60 | * @param info pass in a const DataMap pointer. If no info, it will be set to NULL |
michael@0 | 61 | */ |
michael@0 | 62 | virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const = 0; |
michael@0 | 63 | |
michael@0 | 64 | /** Gets the next set of settings for the test. Resets the cases iterator. |
michael@0 | 65 | * DataMap is owned by the object and should not be deleted. |
michael@0 | 66 | * @param settings a DataMap pointer provided by the user. Will be NULL if |
michael@0 | 67 | * no more settings are available. |
michael@0 | 68 | * @param status for reporting unexpected errors. |
michael@0 | 69 | * @return A boolean, TRUE if there are settings, FALSE if there is no more |
michael@0 | 70 | * settings. |
michael@0 | 71 | */ |
michael@0 | 72 | virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status) = 0; |
michael@0 | 73 | |
michael@0 | 74 | /** Gets the next test case. |
michael@0 | 75 | * DataMap is owned by the object and should not be deleted. |
michael@0 | 76 | * @param data a DataMap pointer provided by the user. Will be NULL if |
michael@0 | 77 | * no more cases are available. |
michael@0 | 78 | * @param status for reporting unexpected errors. |
michael@0 | 79 | * @return A boolean, TRUE if there are cases, FALSE if there is no more |
michael@0 | 80 | * cases. |
michael@0 | 81 | */ |
michael@0 | 82 | virtual UBool nextCase(const DataMap *& data, UErrorCode &status) = 0; |
michael@0 | 83 | }; |
michael@0 | 84 | |
michael@0 | 85 | // implementation of TestData that uses resource bundles |
michael@0 | 86 | |
michael@0 | 87 | class T_CTEST_EXPORT_API RBTestData : public TestData { |
michael@0 | 88 | UResourceBundle *fData; |
michael@0 | 89 | UResourceBundle *fHeaders; |
michael@0 | 90 | UResourceBundle *fSettings; |
michael@0 | 91 | UResourceBundle *fCases; |
michael@0 | 92 | |
michael@0 | 93 | public: |
michael@0 | 94 | RBTestData(const char* name); |
michael@0 | 95 | RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status); |
michael@0 | 96 | private: |
michael@0 | 97 | // RBTestData() {}; |
michael@0 | 98 | // RBTestData(const RBTestData& original) {}; |
michael@0 | 99 | RBTestData& operator=(const RBTestData& /*original*/); |
michael@0 | 100 | |
michael@0 | 101 | public: |
michael@0 | 102 | virtual ~RBTestData(); |
michael@0 | 103 | |
michael@0 | 104 | virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const; |
michael@0 | 105 | |
michael@0 | 106 | virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status); |
michael@0 | 107 | virtual UBool nextCase(const DataMap *& nextCase, UErrorCode &status); |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | #endif |
michael@0 | 111 |