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