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