1c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/******************************************************************** 2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * COPYRIGHT: 3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * Copyright (c) 2002-2005, International Business Machines Corporation and 4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * others. All Rights Reserved. 5c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott ********************************************************************/ 6c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 7c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/* Created by weiv 05/09/2002 */ 8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 9c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/* Base class for data driven tests */ 10c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 11c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifndef U_TESTFW_TESTMODULE 12c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define U_TESTFW_TESTMODULE 13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/unistr.h" 15c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/ures.h" 16c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/testtype.h" 17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/testdata.h" 18c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/datamap.h" 19c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "unicode/testlog.h" 20c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 21c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 22c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/* This class abstracts the actual organization of the 23c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * data for data driven tests 24c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */ 25c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 26c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 27c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass DataMap; 28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass TestData; 29c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 30c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 31c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/** Main data driven test class. Corresponds to one named data 32c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * unit (such as a resource bundle. It is instantiated using 33c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * a factory method getTestDataModule 34c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */ 35c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass T_CTEST_EXPORT_API TestDataModule { 36c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott const char* testName; 37c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 38c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprotected: 39c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott DataMap *fInfo; 40c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott TestLog& fLog; 41c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 42c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic: 43c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott /** Factory method. 44c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param name name of the test module. Usually name of a resource bundle or a XML file 45c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param log a logging class, used for internal error reporting. 46c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param status if something goes wrong, status will be set 47c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @return a TestDataModule object. Use it to get test data from it 48c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */ 49c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott static TestDataModule *getTestDataModule(const char* name, TestLog& log, UErrorCode &status); 50c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual ~TestDataModule(); 51c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 52c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprotected: 53c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott TestDataModule(const char* name, TestLog& log, UErrorCode& status); 54c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 55c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic: 56c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott /** Name of this TestData module. 57c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @return a name 58c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */ 59c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott const char * getName() const; 60c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 61c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott /** Get a pointer to an object owned DataMap that contains more information on this module 62c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * Usual fields are "Description", "LongDescription", "Settings". Also, if containing a 63c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * field "Headers" these will be used as the default headers, so that you don't have to 64c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * to specify per test headers. 65c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param info pass in a const DataMap pointer. If no info, it will be set to NULL 66c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */ 67c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const = 0; 68c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 69c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott /** Create a test data object from an index. Helpful for integrating tests with current 70c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * intltest framework which addresses the tests by index. 71c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param index index of the test to be instantiated 72c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @return an instantiated TestData object, ready to provide settings and cases for 73c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * the tests. 74c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */ 75c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual TestData* createTestData(int32_t index, UErrorCode &status) const = 0; 76c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 77c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott /** Create a test data object from a name. 78c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @param name name of the test to be instantiated 79c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * @return an instantiated TestData object, ready to provide settings and cases for 80c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * the tests. 81c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */ 82c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual TestData* createTestData(const char* name, UErrorCode &status) const = 0; 83c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}; 84c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 85c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottclass T_CTEST_EXPORT_API RBTestDataModule : public TestDataModule { 86c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic: 87c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual ~RBTestDataModule(); 88c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 89c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic: 90c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott RBTestDataModule(const char* name, TestLog& log, UErrorCode& status); 91c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 92c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottpublic: 93c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const; 94c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 95c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual TestData* createTestData(int32_t index, UErrorCode &status) const; 96c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott virtual TestData* createTestData(const char* name, UErrorCode &status) const; 97c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 98c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprivate: 99c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott UResourceBundle *getTestBundle(const char* bundleName, UErrorCode &status); 100c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 101c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottprivate: 102c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott UResourceBundle *fModuleBundle; 103c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott UResourceBundle *fTestData; 104c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott UResourceBundle *fInfoRB; 105c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott UBool fDataTestValid; 106c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott char *tdpath; 107c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 108c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/* const char* fTestName;*/ /* See name */ 109c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int32_t fNumberOfTests; 110c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 111c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}; 112c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 113c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 114c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif 115c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 116