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