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