12e5b6d6dSopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
22e5b6d6dSopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
32e5b6d6dSopenharmony_ci/***********************************************************************
42e5b6d6dSopenharmony_ci * COPYRIGHT:
52e5b6d6dSopenharmony_ci * Copyright (c) 1997-2010, International Business Machines Corporation
62e5b6d6dSopenharmony_ci * and others. All Rights Reserved.
72e5b6d6dSopenharmony_ci ***********************************************************************/
82e5b6d6dSopenharmony_ci
92e5b6d6dSopenharmony_ci#include "unicode/utypes.h"
102e5b6d6dSopenharmony_ci
112e5b6d6dSopenharmony_ci#if !UCONFIG_NO_FORMATTING
122e5b6d6dSopenharmony_ci
132e5b6d6dSopenharmony_ci#include "nmfmapts.h"
142e5b6d6dSopenharmony_ci
152e5b6d6dSopenharmony_ci#include "unicode/numfmt.h"
162e5b6d6dSopenharmony_ci#include "unicode/decimfmt.h"
172e5b6d6dSopenharmony_ci#include "unicode/locid.h"
182e5b6d6dSopenharmony_ci#include "unicode/unum.h"
192e5b6d6dSopenharmony_ci#include "unicode/strenum.h"
202e5b6d6dSopenharmony_ci
212e5b6d6dSopenharmony_ci// This is an API test, not a unit test.  It doesn't test very many cases, and doesn't
222e5b6d6dSopenharmony_ci// try to test the full functionality.  It just calls each function in the class and
232e5b6d6dSopenharmony_ci// verifies that it works on a basic level.
242e5b6d6dSopenharmony_ci
252e5b6d6dSopenharmony_civoid IntlTestNumberFormatAPI::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
262e5b6d6dSopenharmony_ci{
272e5b6d6dSopenharmony_ci    if (exec) logln("TestSuite NumberFormatAPI");
282e5b6d6dSopenharmony_ci    switch (index) {
292e5b6d6dSopenharmony_ci        case 0: name = "NumberFormat API test";
302e5b6d6dSopenharmony_ci                if (exec) {
312e5b6d6dSopenharmony_ci                    logln("NumberFormat API test---"); logln("");
322e5b6d6dSopenharmony_ci                    UErrorCode status = U_ZERO_ERROR;
332e5b6d6dSopenharmony_ci                    Locale saveLocale;
342e5b6d6dSopenharmony_ci                    Locale::setDefault(Locale::getEnglish(), status);
352e5b6d6dSopenharmony_ci                    if(U_FAILURE(status)) {
362e5b6d6dSopenharmony_ci                        errln("ERROR: Could not set default locale, test may not give correct results");
372e5b6d6dSopenharmony_ci                    }
382e5b6d6dSopenharmony_ci                    testAPI(/* par */);
392e5b6d6dSopenharmony_ci                    Locale::setDefault(saveLocale, status);
402e5b6d6dSopenharmony_ci                }
412e5b6d6dSopenharmony_ci                break;
422e5b6d6dSopenharmony_ci        case 1: name = "NumberFormatRegistration";
432e5b6d6dSopenharmony_ci                if (exec) {
442e5b6d6dSopenharmony_ci                    logln("NumberFormat Registration test---"); logln("");
452e5b6d6dSopenharmony_ci                    UErrorCode status = U_ZERO_ERROR;
462e5b6d6dSopenharmony_ci                    Locale saveLocale;
472e5b6d6dSopenharmony_ci                    Locale::setDefault(Locale::getEnglish(), status);
482e5b6d6dSopenharmony_ci                    if(U_FAILURE(status)) {
492e5b6d6dSopenharmony_ci                        errln("ERROR: Could not set default locale, test may not give correct results");
502e5b6d6dSopenharmony_ci                    }
512e5b6d6dSopenharmony_ci                    testRegistration();
522e5b6d6dSopenharmony_ci                    Locale::setDefault(saveLocale, status);
532e5b6d6dSopenharmony_ci                }
542e5b6d6dSopenharmony_ci                break;
552e5b6d6dSopenharmony_ci        default: name = ""; break;
562e5b6d6dSopenharmony_ci    }
572e5b6d6dSopenharmony_ci}
582e5b6d6dSopenharmony_ci
592e5b6d6dSopenharmony_ci/**
602e5b6d6dSopenharmony_ci * This test does round-trip testing (format -> parse -> format -> parse -> etc.) of
612e5b6d6dSopenharmony_ci * NumberFormat.
622e5b6d6dSopenharmony_ci */
632e5b6d6dSopenharmony_civoid IntlTestNumberFormatAPI::testAPI(/* char* par */)
642e5b6d6dSopenharmony_ci{
652e5b6d6dSopenharmony_ci    UErrorCode status = U_ZERO_ERROR;
662e5b6d6dSopenharmony_ci
672e5b6d6dSopenharmony_ci// ======= Test constructors
682e5b6d6dSopenharmony_ci
692e5b6d6dSopenharmony_ci    logln("Testing NumberFormat constructors");
702e5b6d6dSopenharmony_ci
712e5b6d6dSopenharmony_ci    NumberFormat *def = NumberFormat::createInstance(status);
722e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
732e5b6d6dSopenharmony_ci        dataerrln("ERROR: Could not create NumberFormat (default) - %s", u_errorName(status));
742e5b6d6dSopenharmony_ci    }
752e5b6d6dSopenharmony_ci
762e5b6d6dSopenharmony_ci    status = U_ZERO_ERROR;
772e5b6d6dSopenharmony_ci    NumberFormat *fr = NumberFormat::createInstance(Locale::getFrench(), status);
782e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
792e5b6d6dSopenharmony_ci        dataerrln("ERROR: Could not create NumberFormat (French) - %s", u_errorName(status));
802e5b6d6dSopenharmony_ci    }
812e5b6d6dSopenharmony_ci
822e5b6d6dSopenharmony_ci    NumberFormat *cur = NumberFormat::createCurrencyInstance(status);
832e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
842e5b6d6dSopenharmony_ci        dataerrln("ERROR: Could not create NumberFormat (currency, default) - %s", u_errorName(status));
852e5b6d6dSopenharmony_ci    }
862e5b6d6dSopenharmony_ci
872e5b6d6dSopenharmony_ci    status = U_ZERO_ERROR;
882e5b6d6dSopenharmony_ci    NumberFormat *cur_fr = NumberFormat::createCurrencyInstance(Locale::getFrench(), status);
892e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
902e5b6d6dSopenharmony_ci        dataerrln("ERROR: Could not create NumberFormat (currency, French) - %s", u_errorName(status));
912e5b6d6dSopenharmony_ci    }
922e5b6d6dSopenharmony_ci
932e5b6d6dSopenharmony_ci    NumberFormat *per = NumberFormat::createPercentInstance(status);
942e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
952e5b6d6dSopenharmony_ci        dataerrln("ERROR: Could not create NumberFormat (percent, default) - %s", u_errorName(status));
962e5b6d6dSopenharmony_ci    }
972e5b6d6dSopenharmony_ci
982e5b6d6dSopenharmony_ci    status = U_ZERO_ERROR;
992e5b6d6dSopenharmony_ci    NumberFormat *per_fr = NumberFormat::createPercentInstance(Locale::getFrench(), status);
1002e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
1012e5b6d6dSopenharmony_ci        dataerrln("ERROR: Could not create NumberFormat (percent, French) - %s", u_errorName(status));
1022e5b6d6dSopenharmony_ci    }
1032e5b6d6dSopenharmony_ci
1042e5b6d6dSopenharmony_ci// ======= Test equality
1052e5b6d6dSopenharmony_ciif (per_fr != NULL && cur_fr != NULL)
1062e5b6d6dSopenharmony_ci{
1072e5b6d6dSopenharmony_ci    logln("Testing equality operator");
1082e5b6d6dSopenharmony_ci
1092e5b6d6dSopenharmony_ci    if( *per_fr == *cur_fr || ! ( *per_fr != *cur_fr) ) {
1102e5b6d6dSopenharmony_ci        errln("ERROR: == failed");
1112e5b6d6dSopenharmony_ci    }
1122e5b6d6dSopenharmony_ci}
1132e5b6d6dSopenharmony_ci
1142e5b6d6dSopenharmony_ci// ======= Test various format() methods
1152e5b6d6dSopenharmony_ciif (cur_fr != NULL)
1162e5b6d6dSopenharmony_ci{
1172e5b6d6dSopenharmony_ci    logln("Testing various format() methods");
1182e5b6d6dSopenharmony_ci
1192e5b6d6dSopenharmony_ci    double d = -10456.0037;
1202e5b6d6dSopenharmony_ci    int32_t l = 100000000;
1212e5b6d6dSopenharmony_ci    Formattable fD(d);
1222e5b6d6dSopenharmony_ci    Formattable fL(l);
1232e5b6d6dSopenharmony_ci
1242e5b6d6dSopenharmony_ci    UnicodeString res1, res2, res3, res4, res5, res6;
1252e5b6d6dSopenharmony_ci    FieldPosition pos1(FieldPosition::DONT_CARE), pos2(FieldPosition::DONT_CARE), pos3(FieldPosition::DONT_CARE), pos4(FieldPosition::DONT_CARE);
1262e5b6d6dSopenharmony_ci
1272e5b6d6dSopenharmony_ci    res1 = cur_fr->format(d, res1);
1282e5b6d6dSopenharmony_ci    logln( (UnicodeString) "" + (int32_t) d + " formatted to " + res1);
1292e5b6d6dSopenharmony_ci
1302e5b6d6dSopenharmony_ci    res2 = cur_fr->format(l, res2);
1312e5b6d6dSopenharmony_ci    logln((UnicodeString) "" + (int32_t) l + " formatted to " + res2);
1322e5b6d6dSopenharmony_ci
1332e5b6d6dSopenharmony_ci    res3 = cur_fr->format(d, res3, pos1);
1342e5b6d6dSopenharmony_ci    logln( (UnicodeString) "" + (int32_t) d + " formatted to " + res3);
1352e5b6d6dSopenharmony_ci
1362e5b6d6dSopenharmony_ci    res4 = cur_fr->format(l, res4, pos2);
1372e5b6d6dSopenharmony_ci    logln((UnicodeString) "" + (int32_t) l + " formatted to " + res4);
1382e5b6d6dSopenharmony_ci
1392e5b6d6dSopenharmony_ci    status = U_ZERO_ERROR;
1402e5b6d6dSopenharmony_ci    res5 = cur_fr->format(fD, res5, pos3, status);
1412e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
1422e5b6d6dSopenharmony_ci        errln("ERROR: format(Formattable [double]) failed");
1432e5b6d6dSopenharmony_ci    }
1442e5b6d6dSopenharmony_ci    logln((UnicodeString) "" + (int32_t) fD.getDouble() + " formatted to " + res5);
1452e5b6d6dSopenharmony_ci
1462e5b6d6dSopenharmony_ci    status = U_ZERO_ERROR;
1472e5b6d6dSopenharmony_ci    res6 = cur_fr->format(fL, res6, pos4, status);
1482e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
1492e5b6d6dSopenharmony_ci        errln("ERROR: format(Formattable [long]) failed");
1502e5b6d6dSopenharmony_ci    }
1512e5b6d6dSopenharmony_ci    logln((UnicodeString) "" + fL.getLong() + " formatted to " + res6);
1522e5b6d6dSopenharmony_ci}
1532e5b6d6dSopenharmony_ci
1542e5b6d6dSopenharmony_ci// ======= Test parse()
1552e5b6d6dSopenharmony_ciif (fr != NULL)
1562e5b6d6dSopenharmony_ci{
1572e5b6d6dSopenharmony_ci    logln("Testing parse()");
1582e5b6d6dSopenharmony_ci
1592e5b6d6dSopenharmony_ci    double d = -10456.0037;
1602e5b6d6dSopenharmony_ci    UnicodeString text("-10,456.0037");
1612e5b6d6dSopenharmony_ci    Formattable result1, result2, result3;
1622e5b6d6dSopenharmony_ci    ParsePosition pos(0), pos01(0);
1632e5b6d6dSopenharmony_ci    fr->parseObject(text, result1, pos);
1642e5b6d6dSopenharmony_ci    if(result1.getType() != Formattable::kDouble && result1.getDouble() != d) {
1652e5b6d6dSopenharmony_ci        errln("ERROR: Roundtrip failed (via parse()) for " + text);
1662e5b6d6dSopenharmony_ci    }
1672e5b6d6dSopenharmony_ci    logln(text + " parsed into " + (int32_t) result1.getDouble());
1682e5b6d6dSopenharmony_ci
1692e5b6d6dSopenharmony_ci    fr->parse(text, result2, pos01);
1702e5b6d6dSopenharmony_ci    if(result2.getType() != Formattable::kDouble && result2.getDouble() != d) {
1712e5b6d6dSopenharmony_ci        errln("ERROR: Roundtrip failed (via parse()) for " + text);
1722e5b6d6dSopenharmony_ci    }
1732e5b6d6dSopenharmony_ci    logln(text + " parsed into " + (int32_t) result2.getDouble());
1742e5b6d6dSopenharmony_ci
1752e5b6d6dSopenharmony_ci    status = U_ZERO_ERROR;
1762e5b6d6dSopenharmony_ci    fr->parse(text, result3, status);
1772e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
1782e5b6d6dSopenharmony_ci        errln("ERROR: parse() failed");
1792e5b6d6dSopenharmony_ci    }
1802e5b6d6dSopenharmony_ci    if(result3.getType() != Formattable::kDouble && result3.getDouble() != d) {
1812e5b6d6dSopenharmony_ci        errln("ERROR: Roundtrip failed (via parse()) for " + text);
1822e5b6d6dSopenharmony_ci    }
1832e5b6d6dSopenharmony_ci    logln(text + " parsed into " + (int32_t) result3.getDouble());
1842e5b6d6dSopenharmony_ci}
1852e5b6d6dSopenharmony_ci
1862e5b6d6dSopenharmony_ci// ======= Test getters and setters
1872e5b6d6dSopenharmony_ciif (fr != NULL && def != NULL)
1882e5b6d6dSopenharmony_ci{
1892e5b6d6dSopenharmony_ci    logln("Testing getters and setters");
1902e5b6d6dSopenharmony_ci
1912e5b6d6dSopenharmony_ci    int32_t count = 0;
1922e5b6d6dSopenharmony_ci    const Locale *locales = NumberFormat::getAvailableLocales(count);
1932e5b6d6dSopenharmony_ci    logln((UnicodeString) "Got " + count + " locales" );
1942e5b6d6dSopenharmony_ci    for(int32_t i = 0; i < count; i++) {
1952e5b6d6dSopenharmony_ci        UnicodeString name(locales[i].getName(),"");
1962e5b6d6dSopenharmony_ci        logln(name);
1972e5b6d6dSopenharmony_ci    }
1982e5b6d6dSopenharmony_ci
1992e5b6d6dSopenharmony_ci    fr->setParseIntegerOnly( def->isParseIntegerOnly() );
2002e5b6d6dSopenharmony_ci    if(fr->isParseIntegerOnly() != def->isParseIntegerOnly() ) {
2012e5b6d6dSopenharmony_ci        errln("ERROR: setParseIntegerOnly() failed");
2022e5b6d6dSopenharmony_ci    }
2032e5b6d6dSopenharmony_ci
2042e5b6d6dSopenharmony_ci    fr->setGroupingUsed( def->isGroupingUsed() );
2052e5b6d6dSopenharmony_ci    if(fr->isGroupingUsed() != def->isGroupingUsed() ) {
2062e5b6d6dSopenharmony_ci        errln("ERROR: setGroupingUsed() failed");
2072e5b6d6dSopenharmony_ci    }
2082e5b6d6dSopenharmony_ci
2092e5b6d6dSopenharmony_ci    fr->setMaximumIntegerDigits( def->getMaximumIntegerDigits() );
2102e5b6d6dSopenharmony_ci    if(fr->getMaximumIntegerDigits() != def->getMaximumIntegerDigits() ) {
2112e5b6d6dSopenharmony_ci        errln("ERROR: setMaximumIntegerDigits() failed");
2122e5b6d6dSopenharmony_ci    }
2132e5b6d6dSopenharmony_ci
2142e5b6d6dSopenharmony_ci    fr->setMinimumIntegerDigits( def->getMinimumIntegerDigits() );
2152e5b6d6dSopenharmony_ci    if(fr->getMinimumIntegerDigits() != def->getMinimumIntegerDigits() ) {
2162e5b6d6dSopenharmony_ci        errln("ERROR: setMinimumIntegerDigits() failed");
2172e5b6d6dSopenharmony_ci    }
2182e5b6d6dSopenharmony_ci
2192e5b6d6dSopenharmony_ci    fr->setMaximumFractionDigits( def->getMaximumFractionDigits() );
2202e5b6d6dSopenharmony_ci    if(fr->getMaximumFractionDigits() != def->getMaximumFractionDigits() ) {
2212e5b6d6dSopenharmony_ci        errln("ERROR: setMaximumFractionDigits() failed");
2222e5b6d6dSopenharmony_ci    }
2232e5b6d6dSopenharmony_ci
2242e5b6d6dSopenharmony_ci    fr->setMinimumFractionDigits( def->getMinimumFractionDigits() );
2252e5b6d6dSopenharmony_ci    if(fr->getMinimumFractionDigits() != def->getMinimumFractionDigits() ) {
2262e5b6d6dSopenharmony_ci        errln("ERROR: setMinimumFractionDigits() failed");
2272e5b6d6dSopenharmony_ci    }
2282e5b6d6dSopenharmony_ci}
2292e5b6d6dSopenharmony_ci
2302e5b6d6dSopenharmony_ci// ======= Test getStaticClassID()
2312e5b6d6dSopenharmony_ci
2322e5b6d6dSopenharmony_ci    logln("Testing getStaticClassID()");
2332e5b6d6dSopenharmony_ci
2342e5b6d6dSopenharmony_ci    status = U_ZERO_ERROR;
2352e5b6d6dSopenharmony_ci    NumberFormat *test = new DecimalFormat(status);
2362e5b6d6dSopenharmony_ci    if(U_FAILURE(status)) {
2372e5b6d6dSopenharmony_ci        errcheckln(status, "ERROR: Couldn't create a NumberFormat - %s", u_errorName(status));
2382e5b6d6dSopenharmony_ci    }
2392e5b6d6dSopenharmony_ci
2402e5b6d6dSopenharmony_ci    if(test->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
2412e5b6d6dSopenharmony_ci        errln("ERROR: getDynamicClassID() didn't return the expected value");
2422e5b6d6dSopenharmony_ci    }
2432e5b6d6dSopenharmony_ci
2442e5b6d6dSopenharmony_ci    delete test;
2452e5b6d6dSopenharmony_ci    delete def;
2462e5b6d6dSopenharmony_ci    delete fr;
2472e5b6d6dSopenharmony_ci    delete cur;
2482e5b6d6dSopenharmony_ci    delete cur_fr;
2492e5b6d6dSopenharmony_ci    delete per;
2502e5b6d6dSopenharmony_ci    delete per_fr;
2512e5b6d6dSopenharmony_ci}
2522e5b6d6dSopenharmony_ci
2532e5b6d6dSopenharmony_ci#if !UCONFIG_NO_SERVICE
2542e5b6d6dSopenharmony_ci
2552e5b6d6dSopenharmony_ci#define SRC_LOC Locale::getFrance()
2562e5b6d6dSopenharmony_ci#define SWAP_LOC Locale::getUS()
2572e5b6d6dSopenharmony_ci
2582e5b6d6dSopenharmony_ciclass NFTestFactory : public SimpleNumberFormatFactory {
2592e5b6d6dSopenharmony_ci    NumberFormat* currencyStyle;
2602e5b6d6dSopenharmony_ci
2612e5b6d6dSopenharmony_cipublic:
2622e5b6d6dSopenharmony_ci    NFTestFactory()
2632e5b6d6dSopenharmony_ci        : SimpleNumberFormatFactory(SRC_LOC, true)
2642e5b6d6dSopenharmony_ci    {
2652e5b6d6dSopenharmony_ci        UErrorCode status = U_ZERO_ERROR;
2662e5b6d6dSopenharmony_ci        currencyStyle = NumberFormat::createInstance(SWAP_LOC, status);
2672e5b6d6dSopenharmony_ci    }
2682e5b6d6dSopenharmony_ci
2692e5b6d6dSopenharmony_ci    virtual ~NFTestFactory()
2702e5b6d6dSopenharmony_ci    {
2712e5b6d6dSopenharmony_ci        delete currencyStyle;
2722e5b6d6dSopenharmony_ci    }
2732e5b6d6dSopenharmony_ci
2742e5b6d6dSopenharmony_ci    virtual NumberFormat* createFormat(const Locale& /* loc */, UNumberFormatStyle formatType) override
2752e5b6d6dSopenharmony_ci    {
2762e5b6d6dSopenharmony_ci        if (formatType == UNUM_CURRENCY) {
2772e5b6d6dSopenharmony_ci            return currencyStyle->clone();
2782e5b6d6dSopenharmony_ci        }
2792e5b6d6dSopenharmony_ci        return NULL;
2802e5b6d6dSopenharmony_ci    }
2812e5b6d6dSopenharmony_ci
2822e5b6d6dSopenharmony_ci   virtual inline UClassID getDynamicClassID() const override
2832e5b6d6dSopenharmony_ci   {
2842e5b6d6dSopenharmony_ci       return (UClassID)&gID;
2852e5b6d6dSopenharmony_ci   }
2862e5b6d6dSopenharmony_ci
2872e5b6d6dSopenharmony_ci   static inline UClassID getStaticClassID()
2882e5b6d6dSopenharmony_ci   {
2892e5b6d6dSopenharmony_ci        return (UClassID)&gID;
2902e5b6d6dSopenharmony_ci   }
2912e5b6d6dSopenharmony_ci
2922e5b6d6dSopenharmony_ciprivate:
2932e5b6d6dSopenharmony_ci   static char gID;
2942e5b6d6dSopenharmony_ci};
2952e5b6d6dSopenharmony_ci
2962e5b6d6dSopenharmony_cichar NFTestFactory::gID = 0;
2972e5b6d6dSopenharmony_ci#endif
2982e5b6d6dSopenharmony_ci
2992e5b6d6dSopenharmony_civoid
3002e5b6d6dSopenharmony_ciIntlTestNumberFormatAPI::testRegistration()
3012e5b6d6dSopenharmony_ci{
3022e5b6d6dSopenharmony_ci#if !UCONFIG_NO_SERVICE
3032e5b6d6dSopenharmony_ci    UErrorCode status = U_ZERO_ERROR;
3042e5b6d6dSopenharmony_ci
3052e5b6d6dSopenharmony_ci    LocalPointer<NumberFormat> f0(NumberFormat::createInstance(SWAP_LOC, status));
3062e5b6d6dSopenharmony_ci    LocalPointer<NumberFormat> f1(NumberFormat::createInstance(SRC_LOC, status));
3072e5b6d6dSopenharmony_ci    LocalPointer<NumberFormat> f2(NumberFormat::createCurrencyInstance(SRC_LOC, status));
3082e5b6d6dSopenharmony_ci    URegistryKey key = NumberFormat::registerFactory(new NFTestFactory(), status);
3092e5b6d6dSopenharmony_ci    LocalPointer<NumberFormat> f3(NumberFormat::createCurrencyInstance(SRC_LOC, status));
3102e5b6d6dSopenharmony_ci    LocalPointer<NumberFormat> f3a(NumberFormat::createCurrencyInstance(SRC_LOC, status));
3112e5b6d6dSopenharmony_ci    LocalPointer<NumberFormat> f4(NumberFormat::createInstance(SRC_LOC, status));
3122e5b6d6dSopenharmony_ci
3132e5b6d6dSopenharmony_ci    LocalPointer<StringEnumeration> locs(NumberFormat::getAvailableLocales());
3142e5b6d6dSopenharmony_ci
3152e5b6d6dSopenharmony_ci    LocalUNumberFormatPointer uf3(unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(), NULL, &status));
3162e5b6d6dSopenharmony_ci    LocalUNumberFormatPointer uf4(unum_open(UNUM_DEFAULT, NULL, 0, SRC_LOC.getName(), NULL, &status));
3172e5b6d6dSopenharmony_ci
3182e5b6d6dSopenharmony_ci    const UnicodeString* res;
3192e5b6d6dSopenharmony_ci    for (res = locs->snext(status); res; res = locs->snext(status)) {
3202e5b6d6dSopenharmony_ci        logln(*res); // service is still in synch
3212e5b6d6dSopenharmony_ci    }
3222e5b6d6dSopenharmony_ci
3232e5b6d6dSopenharmony_ci    NumberFormat::unregister(key, status); // restore for other tests
3242e5b6d6dSopenharmony_ci    LocalPointer<NumberFormat> f5(NumberFormat::createCurrencyInstance(SRC_LOC, status));
3252e5b6d6dSopenharmony_ci    LocalUNumberFormatPointer uf5(unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(), NULL, &status));
3262e5b6d6dSopenharmony_ci
3272e5b6d6dSopenharmony_ci    if (U_FAILURE(status)) {
3282e5b6d6dSopenharmony_ci        dataerrln("Error creating instances.");
3292e5b6d6dSopenharmony_ci        return;
3302e5b6d6dSopenharmony_ci    } else {
3312e5b6d6dSopenharmony_ci        float n = 1234.567f;
3322e5b6d6dSopenharmony_ci        UnicodeString res0, res1, res2, res3, res4, res5;
3332e5b6d6dSopenharmony_ci        UChar ures3[50];
3342e5b6d6dSopenharmony_ci        UChar ures4[50];
3352e5b6d6dSopenharmony_ci        UChar ures5[50];
3362e5b6d6dSopenharmony_ci
3372e5b6d6dSopenharmony_ci        f0->format(n, res0);
3382e5b6d6dSopenharmony_ci        f1->format(n, res1);
3392e5b6d6dSopenharmony_ci        f2->format(n, res2);
3402e5b6d6dSopenharmony_ci        f3->format(n, res3);
3412e5b6d6dSopenharmony_ci        f4->format(n, res4);
3422e5b6d6dSopenharmony_ci        f5->format(n, res5);
3432e5b6d6dSopenharmony_ci
3442e5b6d6dSopenharmony_ci        unum_formatDouble(uf3.getAlias(), n, ures3, 50, NULL, &status);
3452e5b6d6dSopenharmony_ci        unum_formatDouble(uf4.getAlias(), n, ures4, 50, NULL, &status);
3462e5b6d6dSopenharmony_ci        unum_formatDouble(uf5.getAlias(), n, ures5, 50, NULL, &status);
3472e5b6d6dSopenharmony_ci
3482e5b6d6dSopenharmony_ci        logln((UnicodeString)"f0 swap int: " + res0);
3492e5b6d6dSopenharmony_ci        logln((UnicodeString)"f1 src int: " + res1);
3502e5b6d6dSopenharmony_ci        logln((UnicodeString)"f2 src cur: " + res2);
3512e5b6d6dSopenharmony_ci        logln((UnicodeString)"f3 reg cur: " + res3);
3522e5b6d6dSopenharmony_ci        logln((UnicodeString)"f4 reg int: " + res4);
3532e5b6d6dSopenharmony_ci        logln((UnicodeString)"f5 unreg cur: " + res5);
3542e5b6d6dSopenharmony_ci        log("uf3 reg cur: ");
3552e5b6d6dSopenharmony_ci        logln(ures3);
3562e5b6d6dSopenharmony_ci        log("uf4 reg int: ");
3572e5b6d6dSopenharmony_ci        logln(ures4);
3582e5b6d6dSopenharmony_ci        log("uf5 ureg cur: ");
3592e5b6d6dSopenharmony_ci        logln(ures5);
3602e5b6d6dSopenharmony_ci
3612e5b6d6dSopenharmony_ci        if (f3.getAlias() == f3a.getAlias()) {
3622e5b6d6dSopenharmony_ci            errln("did not get new instance from service");
3632e5b6d6dSopenharmony_ci            f3a.orphan();
3642e5b6d6dSopenharmony_ci        }
3652e5b6d6dSopenharmony_ci        if (res3 != res0) {
3662e5b6d6dSopenharmony_ci            errln("registered service did not match");
3672e5b6d6dSopenharmony_ci        }
3682e5b6d6dSopenharmony_ci        if (res4 != res1) {
3692e5b6d6dSopenharmony_ci            errln("registered service did not inherit");
3702e5b6d6dSopenharmony_ci        }
3712e5b6d6dSopenharmony_ci        if (res5 != res2) {
3722e5b6d6dSopenharmony_ci            errln("unregistered service did not match original");
3732e5b6d6dSopenharmony_ci        }
3742e5b6d6dSopenharmony_ci
3752e5b6d6dSopenharmony_ci        if (res0 != ures3) {
3762e5b6d6dSopenharmony_ci            errln("registered service did not match / unum");
3772e5b6d6dSopenharmony_ci        }
3782e5b6d6dSopenharmony_ci        if (res1 != ures4) {
3792e5b6d6dSopenharmony_ci            errln("registered service did not inherit / unum");
3802e5b6d6dSopenharmony_ci        }
3812e5b6d6dSopenharmony_ci        if (res2 != ures5) {
3822e5b6d6dSopenharmony_ci            errln("unregistered service did not match original / unum");
3832e5b6d6dSopenharmony_ci        }
3842e5b6d6dSopenharmony_ci    }
3852e5b6d6dSopenharmony_ci
3862e5b6d6dSopenharmony_ci    for (res = locs->snext(status); res; res = locs->snext(status)) {
3872e5b6d6dSopenharmony_ci        errln(*res); // service should be out of synch
3882e5b6d6dSopenharmony_ci    }
3892e5b6d6dSopenharmony_ci
3902e5b6d6dSopenharmony_ci    locs->reset(status); // now in synch again, we hope
3912e5b6d6dSopenharmony_ci    for (res = locs->snext(status); res; res = locs->snext(status)) {
3922e5b6d6dSopenharmony_ci        logln(*res);
3932e5b6d6dSopenharmony_ci    }
3942e5b6d6dSopenharmony_ci#endif
3952e5b6d6dSopenharmony_ci}
3962e5b6d6dSopenharmony_ci
3972e5b6d6dSopenharmony_ci
3982e5b6d6dSopenharmony_ci#endif /* #if !UCONFIG_NO_FORMATTING */
399