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