scuffed-code/icu4c/source/test/intltest/nmfmtrt.h
George Rhoten e097e1b9ee ICU-8223 Add rule syntax for NaN, infinity and alternate decimal points.
Other issues addressed:
* Some performance enhancements were added for good measure. Creating new RuleBasedNumberFormat objects can take a long time due to all the rule parsing. This was ported from ICU4J.
* I fixed a potential infinite recursion problem when RuleBasedNumberFormat used NumberFormat.createInstance, which could occasionally depend on creating RuleBasedNumberFormat for itself, which was bad. This was ported from ICU4J.
* I fixed a potential memory leak due to lazy initialization of some RBNF data members in a multithreaded environment, which is fine in Java, but it's not okay in C++. We no longer cast away const due to this, which is good.
* There were some compiler warnings and errors found while trying to debug this code on my machine. I fixed those too.

X-SVN-Rev: 37810
2015-08-25 16:55:52 +00:00

78 lines
2.0 KiB
C++

/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2015, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
#ifndef _NUMBERFORMATROUNDTRIPTEST_
#define _NUMBERFORMATROUNDTRIPTEST_
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#include "unicode/numfmt.h"
#include "unicode/fmtable.h"
#include "intltest.h"
/**
* Performs round-trip tests for NumberFormat
**/
class NumberFormatRoundTripTest : public IntlTest {
// IntlTest override
void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
public:
static UBool verbose;
static UBool STRING_COMPARE;
static UBool EXACT_NUMERIC_COMPARE;
static UBool DEBUG_VAR;
static double MAX_ERROR;
static double max_numeric_error;
static double min_numeric_error;
void start(void);
void test(NumberFormat *fmt);
void test(NumberFormat *fmt, double value);
void test(NumberFormat *fmt, int32_t value);
void test(NumberFormat *fmt, const Formattable& value);
static double randomDouble(double range);
static double proportionalError(const Formattable& a, const Formattable& b);
static UnicodeString& typeOf(const Formattable& n, UnicodeString& result);
static UnicodeString& escape(UnicodeString& s);
static inline UBool
isDouble(const Formattable& n)
{ return (n.getType() == Formattable::kDouble); }
static inline UBool
isLong(const Formattable& n)
{ return (n.getType() == Formattable::kLong); }
/*
* Return a random uint32_t
**/
static uint32_t randLong();
/**
* Return a random double 0 <= x < 1.0
**/
static double randFraction()
{
return (double)randLong() / (double)0xFFFFFFFF;
}
protected:
UBool failure(UErrorCode status, const char* msg, UBool possibleDataError=FALSE);
};
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif // _NUMBERFORMATROUNDTRIPTEST_
//eof