1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/tools/ctestfw/unicode/testdata.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +/******************************************************************** 1.5 + * COPYRIGHT: 1.6 + * Copyright (c) 2002-2006, International Business Machines Corporation and 1.7 + * others. All Rights Reserved. 1.8 + ********************************************************************/ 1.9 + 1.10 +/* Created by weiv 05/09/2002 */ 1.11 + 1.12 +/* Base class for data driven tests */ 1.13 + 1.14 +#ifndef U_TESTFW_TESTDATA 1.15 +#define U_TESTFW_TESTDATA 1.16 + 1.17 +#include "unicode/tstdtmod.h" 1.18 +#include "unicode/datamap.h" 1.19 + 1.20 + 1.21 + /** This is the class that abstracts one of the tests in a data file 1.22 + * It is usually instantiated using TestDataModule::CreateTestData method 1.23 + * This class provides two important methods: nextSettings and nextCase 1.24 + * Usually, one walks through all settings and executes all cases for 1.25 + * each setting. Each call to nextSettings resets the cases iterator. 1.26 + * Individual test cases have to have the same number of fields as the 1.27 + * number of entries in headers. Default headers can be specified in 1.28 + * the TestDataModule info section. The default headers will be overriden 1.29 + * by per-test headers. 1.30 + * Example: 1.31 + * DataMap *settings = NULL; 1.32 + * DataMap *cases = NULL; 1.33 + * while(nextSettings(settings, status)) { 1.34 + * // set settings for the subtest 1.35 + * while(nextCase(cases, status) { 1.36 + * // process testcase 1.37 + * } 1.38 + * } 1.39 + */ 1.40 + 1.41 +class T_CTEST_EXPORT_API TestData { 1.42 + const char* name; 1.43 + 1.44 +protected: 1.45 + DataMap *fInfo; 1.46 + DataMap *fCurrSettings; 1.47 + DataMap *fCurrCase; 1.48 + int32_t fSettingsSize; 1.49 + int32_t fCasesSize; 1.50 + int32_t fCurrentSettings; 1.51 + int32_t fCurrentCase; 1.52 + /** constructor - don't use */ 1.53 + TestData(const char* name); 1.54 + 1.55 +public: 1.56 + virtual ~TestData(); 1.57 + 1.58 + const char* getName() const; 1.59 + 1.60 + /** Get a pointer to an object owned DataMap that contains more information on this 1.61 + * TestData object. 1.62 + * Usual fields is "Description". 1.63 + * @param info pass in a const DataMap pointer. If no info, it will be set to NULL 1.64 + */ 1.65 + virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const = 0; 1.66 + 1.67 + /** Gets the next set of settings for the test. Resets the cases iterator. 1.68 + * DataMap is owned by the object and should not be deleted. 1.69 + * @param settings a DataMap pointer provided by the user. Will be NULL if 1.70 + * no more settings are available. 1.71 + * @param status for reporting unexpected errors. 1.72 + * @return A boolean, TRUE if there are settings, FALSE if there is no more 1.73 + * settings. 1.74 + */ 1.75 + virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status) = 0; 1.76 + 1.77 + /** Gets the next test case. 1.78 + * DataMap is owned by the object and should not be deleted. 1.79 + * @param data a DataMap pointer provided by the user. Will be NULL if 1.80 + * no more cases are available. 1.81 + * @param status for reporting unexpected errors. 1.82 + * @return A boolean, TRUE if there are cases, FALSE if there is no more 1.83 + * cases. 1.84 + */ 1.85 + virtual UBool nextCase(const DataMap *& data, UErrorCode &status) = 0; 1.86 +}; 1.87 + 1.88 +// implementation of TestData that uses resource bundles 1.89 + 1.90 +class T_CTEST_EXPORT_API RBTestData : public TestData { 1.91 + UResourceBundle *fData; 1.92 + UResourceBundle *fHeaders; 1.93 + UResourceBundle *fSettings; 1.94 + UResourceBundle *fCases; 1.95 + 1.96 +public: 1.97 + RBTestData(const char* name); 1.98 + RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status); 1.99 +private: 1.100 +// RBTestData() {}; 1.101 +// RBTestData(const RBTestData& original) {}; 1.102 + RBTestData& operator=(const RBTestData& /*original*/); 1.103 + 1.104 +public: 1.105 + virtual ~RBTestData(); 1.106 + 1.107 + virtual UBool getInfo(const DataMap *& info, UErrorCode &status) const; 1.108 + 1.109 + virtual UBool nextSettings(const DataMap *& settings, UErrorCode &status); 1.110 + virtual UBool nextCase(const DataMap *& nextCase, UErrorCode &status); 1.111 +}; 1.112 + 1.113 +#endif 1.114 +