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