summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu/icu-src/source/test/intltest/numbertest_doubleconversion.cpp
blob: a52865d8d3d66ee85dd988152252fd8fd013e674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html

#include "unicode/utypes.h"

#if !UCONFIG_NO_FORMATTING && !UPRV_INCOMPLETE_CPP11_SUPPORT

#include "numbertest.h"
#include "double-conversion.h"

using namespace double_conversion;

void DoubleConversionTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *) {
    if (exec) {
        logln("TestSuite DoubleConversionTest: ");
    }
    TESTCASE_AUTO_BEGIN;
        TESTCASE_AUTO(testDoubleConversionApi);
    TESTCASE_AUTO_END;
}

void DoubleConversionTest::testDoubleConversionApi() {
    double v = 87.65;
    char buffer[DoubleToStringConverter::kBase10MaximalLength + 1];
    bool sign;
    int32_t length;
    int32_t point;

    DoubleToStringConverter::DoubleToAscii(
        v,
        DoubleToStringConverter::DtoaMode::SHORTEST,
        0,
        buffer,
        sizeof(buffer),
        &sign,
        &length,
        &point
    );

    UnicodeString result(buffer, length);
    assertEquals("Digits", u"8765", result);
    assertEquals("Scale", 2, point);
}

#endif /* #if !UCONFIG_NO_FORMATTING */