michael@0: /******************************************************************** michael@0: * COPYRIGHT: michael@0: * Copyright (c) 2002-2006, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ********************************************************************/ michael@0: michael@0: /* Created by weiv 05/09/2002 */ michael@0: michael@0: /* Base class for data driven tests */ michael@0: michael@0: #ifndef U_TESTFW_TESTDATA michael@0: #define U_TESTFW_TESTDATA michael@0: michael@0: #include "unicode/tstdtmod.h" michael@0: #include "unicode/datamap.h" michael@0: michael@0: michael@0: /** This is the class that abstracts one of the tests in a data file michael@0: * It is usually instantiated using TestDataModule::CreateTestData method michael@0: * This class provides two important methods: nextSettings and nextCase michael@0: * Usually, one walks through all settings and executes all cases for michael@0: * each setting. Each call to nextSettings resets the cases iterator. michael@0: * Individual test cases have to have the same number of fields as the michael@0: * number of entries in headers. Default headers can be specified in michael@0: * the TestDataModule info section. The default headers will be overriden michael@0: * by per-test headers. michael@0: * Example: michael@0: * DataMap *settings = NULL; michael@0: * DataMap *cases = NULL; michael@0: * while(nextSettings(settings, status)) { michael@0: * // set settings for the subtest michael@0: * while(nextCase(cases, status) { michael@0: * // process testcase michael@0: * } michael@0: * } michael@0: */ michael@0: michael@0: class T_CTEST_EXPORT_API TestData { michael@0: const char* name; michael@0: michael@0: protected: michael@0: DataMap *fInfo; michael@0: DataMap *fCurrSettings; michael@0: DataMap *fCurrCase; michael@0: int32_t fSettingsSize; michael@0: int32_t fCasesSize; michael@0: int32_t fCurrentSettings; michael@0: int32_t fCurrentCase; michael@0: /** constructor - don't use */ michael@0: TestData(const char* name); michael@0: michael@0: public: michael@0: virtual ~TestData(); michael@0: michael@0: const char* getName() const; michael@0: michael@0: /** Get a pointer to an object owned DataMap that contains more information on this michael@0: * TestData object. michael@0: * Usual fields is "Description". michael@0: * @param info pass in a const DataMap pointer. If no info, it will be set to NULL michael@0: */ michael@0: virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const = 0; michael@0: michael@0: /** Gets the next set of settings for the test. Resets the cases iterator. michael@0: * DataMap is owned by the object and should not be deleted. michael@0: * @param settings a DataMap pointer provided by the user. Will be NULL if michael@0: * no more settings are available. michael@0: * @param status for reporting unexpected errors. michael@0: * @return A boolean, TRUE if there are settings, FALSE if there is no more michael@0: * settings. michael@0: */ michael@0: virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status) = 0; michael@0: michael@0: /** Gets the next test case. michael@0: * DataMap is owned by the object and should not be deleted. michael@0: * @param data a DataMap pointer provided by the user. Will be NULL if michael@0: * no more cases are available. michael@0: * @param status for reporting unexpected errors. michael@0: * @return A boolean, TRUE if there are cases, FALSE if there is no more michael@0: * cases. michael@0: */ michael@0: virtual UBool nextCase(const DataMap *& data, UErrorCode &status) = 0; michael@0: }; michael@0: michael@0: // implementation of TestData that uses resource bundles michael@0: michael@0: class T_CTEST_EXPORT_API RBTestData : public TestData { michael@0: UResourceBundle *fData; michael@0: UResourceBundle *fHeaders; michael@0: UResourceBundle *fSettings; michael@0: UResourceBundle *fCases; michael@0: michael@0: public: michael@0: RBTestData(const char* name); michael@0: RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status); michael@0: private: michael@0: // RBTestData() {}; michael@0: // RBTestData(const RBTestData& original) {}; michael@0: RBTestData& operator=(const RBTestData& /*original*/); michael@0: michael@0: public: michael@0: virtual ~RBTestData(); michael@0: michael@0: virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const; michael@0: michael@0: virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status); michael@0: virtual UBool nextCase(const DataMap *& nextCase, UErrorCode &status); michael@0: }; michael@0: michael@0: #endif michael@0: