tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testdata.h (4151B)


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