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