Home | History | Annotate | Download | only in intltest
      1 /*
      2 *******************************************************************************
      3 * Copyright (C) 2015, International Business Machines Corporation and         *
      4 * others. All Rights Reserved.                                                *
      5 *******************************************************************************
      6 */
      7 #ifndef _NUMBER_FORMAT_TEST_TUPLE
      8 #define _NUMBER_FORMAT_TEST_TUPLE
      9 
     10 #include "unicode/utypes.h"
     11 
     12 #if !UCONFIG_NO_FORMATTING
     13 
     14 #include "decimalformatpattern.h"
     15 #include "unicode/decimfmt.h"
     16 #include "unicode/ucurr.h"
     17 
     18 #define NFTT_GET_FIELD(tuple, fieldName, defaultValue) ((tuple).fieldName##Flag ? (tuple).fieldName : (defaultValue))
     19 
     20 U_NAMESPACE_USE
     21 
     22 enum ENumberFormatTestTupleField {
     23     kLocale,
     24     kCurrency,
     25     kPattern,
     26     kFormat,
     27     kOutput,
     28     kComment,
     29     kMinIntegerDigits,
     30     kMaxIntegerDigits,
     31     kMinFractionDigits,
     32     kMaxFractionDigits,
     33     kMinGroupingDigits,
     34     kBreaks,
     35     kUseSigDigits,
     36     kMinSigDigits,
     37     kMaxSigDigits,
     38     kUseGrouping,
     39     kMultiplier,
     40     kRoundingIncrement,
     41     kFormatWidth,
     42     kPadCharacter,
     43     kUseScientific,
     44     kGrouping,
     45     kGrouping2,
     46     kRoundingMode,
     47     kCurrencyUsage,
     48     kMinimumExponentDigits,
     49     kExponentSignAlwaysShown,
     50     kDecimalSeparatorAlwaysShown,
     51     kPadPosition,
     52     kPositivePrefix,
     53     kPositiveSuffix,
     54     kNegativePrefix,
     55     kNegativeSuffix,
     56     kLocalizedPattern,
     57     kToPattern,
     58     kToLocalizedPattern,
     59     kStyle,
     60     kParse,
     61     kLenient,
     62     kPlural,
     63     kParseIntegerOnly,
     64     kDecimalPatternMatchRequired,
     65     kParseNoExponent,
     66     kOutputCurrency,
     67     kNumberFormatTestTupleFieldCount
     68 };
     69 
     70 /**
     71  * NumberFormatTestTuple represents the data for a single data driven test.
     72  * It consist of named fields each of which may or may not be set. Each field
     73  * has a particular meaning in the test. For more information on what each
     74  * field means and how the data drive tests work, please see
     75  * https://docs.google.com/document/d/1T2P0p953_Lh1pRwo-5CuPVrHlIBa_wcXElG-Hhg_WHM/edit?usp=sharing
     76  * Each field is optional. That is, a certain field may be unset for a given
     77  * test. The UBool fields ending in "Flag" indicate whether the corrresponding
     78  * field is set or not. TRUE means set; FALSE means unset. An unset field
     79  * generally means that the corresponding setter method is not called on
     80  * the NumberFormat object.
     81  */
     82 
     83 class NumberFormatTestTuple {
     84 public:
     85     Locale locale;
     86     UnicodeString currency;
     87     UnicodeString pattern;
     88     UnicodeString format;
     89     UnicodeString output;
     90     UnicodeString comment;
     91     int32_t minIntegerDigits;
     92     int32_t maxIntegerDigits;
     93     int32_t minFractionDigits;
     94     int32_t maxFractionDigits;
     95     int32_t minGroupingDigits;
     96     UnicodeString breaks;
     97     int32_t useSigDigits;
     98     int32_t minSigDigits;
     99     int32_t maxSigDigits;
    100     int32_t useGrouping;
    101     int32_t multiplier;
    102     double roundingIncrement;
    103     int32_t formatWidth;
    104     UnicodeString padCharacter;
    105     int32_t useScientific;
    106     int32_t grouping;
    107     int32_t grouping2;
    108     DecimalFormat::ERoundingMode roundingMode;
    109     UCurrencyUsage currencyUsage;
    110     int32_t minimumExponentDigits;
    111     int32_t exponentSignAlwaysShown;
    112     int32_t decimalSeparatorAlwaysShown;
    113     DecimalFormat::EPadPosition padPosition;
    114     UnicodeString positivePrefix;
    115     UnicodeString positiveSuffix;
    116     UnicodeString negativePrefix;
    117     UnicodeString negativeSuffix;
    118     UnicodeString localizedPattern;
    119     UnicodeString toPattern;
    120     UnicodeString toLocalizedPattern;
    121     UNumberFormatStyle style;
    122     UnicodeString parse;
    123     int32_t lenient;
    124     UnicodeString plural;
    125     int32_t parseIntegerOnly;
    126     int32_t decimalPatternMatchRequired;
    127     int32_t parseNoExponent;
    128     UnicodeString outputCurrency;
    129 
    130     UBool localeFlag;
    131     UBool currencyFlag;
    132     UBool patternFlag;
    133     UBool formatFlag;
    134     UBool outputFlag;
    135     UBool commentFlag;
    136     UBool minIntegerDigitsFlag;
    137     UBool maxIntegerDigitsFlag;
    138     UBool minFractionDigitsFlag;
    139     UBool maxFractionDigitsFlag;
    140     UBool minGroupingDigitsFlag;
    141     UBool breaksFlag;
    142     UBool useSigDigitsFlag;
    143     UBool minSigDigitsFlag;
    144     UBool maxSigDigitsFlag;
    145     UBool useGroupingFlag;
    146     UBool multiplierFlag;
    147     UBool roundingIncrementFlag;
    148     UBool formatWidthFlag;
    149     UBool padCharacterFlag;
    150     UBool useScientificFlag;
    151     UBool groupingFlag;
    152     UBool grouping2Flag;
    153     UBool roundingModeFlag;
    154     UBool currencyUsageFlag;
    155     UBool minimumExponentDigitsFlag;
    156     UBool exponentSignAlwaysShownFlag;
    157     UBool decimalSeparatorAlwaysShownFlag;
    158     UBool padPositionFlag;
    159     UBool positivePrefixFlag;
    160     UBool positiveSuffixFlag;
    161     UBool negativePrefixFlag;
    162     UBool negativeSuffixFlag;
    163     UBool localizedPatternFlag;
    164     UBool toPatternFlag;
    165     UBool toLocalizedPatternFlag;
    166     UBool styleFlag;
    167     UBool parseFlag;
    168     UBool lenientFlag;
    169     UBool pluralFlag;
    170     UBool parseIntegerOnlyFlag;
    171     UBool decimalPatternMatchRequiredFlag;
    172     UBool parseNoExponentFlag;
    173     UBool outputCurrencyFlag;
    174 
    175     NumberFormatTestTuple() {
    176         clear();
    177     }
    178 
    179     /**
    180      * Sets a particular field using the string representation of that field.
    181      * @param field the field to set.
    182      * @param fieldValue the string representation of the field value.
    183      * @param status error returned here such as when the string representation
    184      *  of the field value cannot be parsed.
    185      * @return TRUE on success or FALSE if an error was set in status.
    186      */
    187     UBool setField(
    188             ENumberFormatTestTupleField field,
    189             const UnicodeString &fieldValue,
    190             UErrorCode &status);
    191     /**
    192      * Clears a particular field.
    193      * @param field the field to clear.
    194      * @param status error set here.
    195      * @return TRUE on success or FALSE if error was set.
    196      */
    197     UBool clearField(
    198             ENumberFormatTestTupleField field,
    199             UErrorCode &status);
    200     /**
    201      * Clears every field.
    202      */
    203     void clear();
    204 
    205     /**
    206      * Returns the string representation of the test case this object
    207      * currently represents.
    208      * @param appendTo the result appended here.
    209      * @return appendTo
    210      */
    211     UnicodeString &toString(UnicodeString &appendTo) const;
    212 
    213     /**
    214      * Converts the name of a field to the corresponding enum value.
    215      * @param name the name of the field as a string.
    216      * @return the corresponding enum value or kNumberFormatTestFieldCount
    217      *   if name does not map to any recognized field name.
    218      */
    219     static ENumberFormatTestTupleField getFieldByName(const UnicodeString &name);
    220 private:
    221     const void *getFieldAddress(int32_t fieldId) const;
    222     void *getMutableFieldAddress(int32_t fieldId);
    223     void setFlag(int32_t fieldId, UBool value);
    224     UBool isFlag(int32_t fieldId) const;
    225 };
    226 
    227 #endif /* !UCONFIG_NO_FORMATTING */
    228 #endif
    229