1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT:
385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2009, International Business Machines Corporation and
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * others. All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef _NUMBERFORMATROUNDTRIPTEST_
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define _NUMBERFORMATROUNDTRIPTEST_
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/numfmt.h"
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/fmtable.h"
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "intltest.h"
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Performs round-trip tests for NumberFormat
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru **/
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass NumberFormatRoundTripTest : public IntlTest {
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // IntlTest override
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par );
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic:
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UBool verbose;
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UBool STRING_COMPARE;
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UBool EXACT_NUMERIC_COMPARE;
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UBool DEBUG;
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static double MAX_ERROR;
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static double max_numeric_error;
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static double min_numeric_error;
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void start(void);
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void test(NumberFormat *fmt);
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void test(NumberFormat *fmt, double value);
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void test(NumberFormat *fmt, int32_t value);
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void test(NumberFormat *fmt, const Formattable& value);
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static double randomDouble(double range);
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static double proportionalError(const Formattable& a, const Formattable& b);
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UnicodeString& typeOf(const Formattable& n, UnicodeString& result);
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UnicodeString& escape(UnicodeString& s);
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static inline UBool
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    isDouble(const Formattable& n)
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { return (n.getType() == Formattable::kDouble); }
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static inline UBool
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    isLong(const Formattable& n)
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { return (n.getType() == Formattable::kLong); }
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Return a random uint32_t
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     **/
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static uint32_t randLong();
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Return a random double 0 <= x < 1.0
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     **/
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static double randFraction()
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return (double)randLong() / (double)0xFFFFFFFF;
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprotected:
7085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UBool failure(UErrorCode status, const char* msg, UBool possibleDataError=FALSE);
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_FORMATTING */
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif // _NUMBERFORMATROUNDTRIPTEST_
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//eof
78