]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/datadrivennumberformattestsuite.h
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / datadrivennumberformattestsuite.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
2ca993e8
A
3/************************************************************************
4 * COPYRIGHT:
5 * Copyright (c) 2015, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 ************************************************************************/
8
9#ifndef _DATADRIVENNUMBERFORMATTESTSUITE_H__
10#define _DATADRIVENNUMBERFORMATTESTSUITE_H__
11
12#include "unicode/utypes.h"
13
14#if !UCONFIG_NO_FORMATTING
15
16#include "unicode/uobject.h"
17#include "unicode/unistr.h"
18#include "numberformattesttuple.h"
19#include "intltest.h"
20
21struct UCHARBUF;
22class IntlTest;
23
24/**
25 * Performs various in-depth test on NumberFormat
26 **/
27class DataDrivenNumberFormatTestSuite : public IntlTest {
28
29 public:
30 DataDrivenNumberFormatTestSuite() {
31 for (int32_t i = 0; i < UPRV_LENGTHOF(fPreviousFormatters); ++i) {
32 fPreviousFormatters[i] = NULL;
33 }
34 }
35
36 /**
37 * Runs the data driven test suite.
38 *
39 * @param fileName is the name of the file in the source/test/testdata.
40 * This should be just a filename such as "numberformattest.txt"
41 * @param runAllTests If TRUE, runs every test in fileName. if FALSE,
42 * skips the tests that are known to break for ICU4C.
43 */
44 void run(const char *fileName, UBool runAllTests);
45 virtual ~DataDrivenNumberFormatTestSuite();
46 protected:
47 /**
48 * Subclasses override this method to test formatting numbers.
49 * Subclasses must not override both isFormatPass methods.
50 * @param tuple the test data for current test. The format method can
51 * assume that the format and output fields are populated.
52 * @param appendErrorMessage any message describing failures appended
53 * here.
54 * @param status any error returned here.
55 * @return TRUE if test passed or FALSE if test failed.
56 */
57 virtual UBool isFormatPass(
58 const NumberFormatTestTuple &tuple,
59 UnicodeString &appendErrorMessage,
60 UErrorCode &status);
61
62
63 /**
64 * Subclasses override this method to test formatting numbers.
65 * Along with copy and assignment operators.
66 * @param tuple the test data for current test. The format method can
67 * assume that the format and output fields are populated.
68 * @param somePreviousFormatter A pointer to a previous formatter
69 * that the test framework owns. This formatter changes as tests
70 * are run. Subclasses should initialize a formatter and assign
71 * the newly initialized formatter to this formatter. In this way,
72 * assignment gets tested with multiple previous states.
73 * @param appendErrorMessage any message describing failures appended
74 * here.
75 * @param status any error returned here.
76 * @return TRUE if test passed or FALSE if test failed.
77 */
78 virtual UBool isFormatPass(
79 const NumberFormatTestTuple &tuple,
80 UObject *somePreviousFormatter,
81 UnicodeString &appendErrorMessage,
82 UErrorCode &status);
83 /**
84 * If subclass is testing formatting with copy and assignmet, it
85 * needs to override this method to return a newly allocated formatter.
86 */
87 virtual UObject *newFormatter(UErrorCode &status);
88
89 /**
90 * Tests toPattern method.
91 */
92 virtual UBool isToPatternPass(
93 const NumberFormatTestTuple &tuple,
94 UnicodeString &appendErrorMessage,
95 UErrorCode &status);
96 /**
97 * Test parsing.
98 */
99 virtual UBool isParsePass(
100 const NumberFormatTestTuple &tuple,
101 UnicodeString &appendErrorMessage,
102 UErrorCode &status);
103
104 /**
105 * Test parsing with currency.
106 */
107 virtual UBool isParseCurrencyPass(
108 const NumberFormatTestTuple &tuple,
109 UnicodeString &appendErrorMessage,
110 UErrorCode &status);
111
112 /**
113 * Test plural selection.
114 */
115 virtual UBool isSelectPass(
116 const NumberFormatTestTuple &tuple,
117 UnicodeString &appendErrorMessage,
118 UErrorCode &status);
119 private:
120 UnicodeString fFileLine;
121 int32_t fFileLineNumber;
122 UnicodeString fFileTestName;
123 NumberFormatTestTuple fTuple;
124 int32_t fFormatTestNumber;
125 UObject *fPreviousFormatters[13];
126
127 void setTupleField(UErrorCode &);
128 int32_t splitBy(
129 UnicodeString *columnValues,
130 int32_t columnValueCount,
131 UChar delimiter);
132 void showError(const char *message);
133 void showFailure(const UnicodeString &message);
134 void showLineInfo();
135 UBool breaksC();
136 UBool readLine(UCHARBUF *f, UErrorCode &);
137 UBool isPass(
138 const NumberFormatTestTuple &tuple,
139 UnicodeString &appendErrorMessage,
140 UErrorCode &status);
141};
142#endif /* !UCONFIG_NO_FORMATTING */
143#endif // _DATADRIVENNUMBERFORMATTESTSUITE_