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******************************************************************************* 52e5b6d6dSopenharmony_ci* Copyright (C) 1997-2015, International Business Machines Corporation and * 62e5b6d6dSopenharmony_ci* others. All Rights Reserved. * 72e5b6d6dSopenharmony_ci******************************************************************************* 82e5b6d6dSopenharmony_ci* 92e5b6d6dSopenharmony_ci* File COMPACTDECIMALFORMATTEST.CPP 102e5b6d6dSopenharmony_ci* 112e5b6d6dSopenharmony_ci******************************************************************************** 122e5b6d6dSopenharmony_ci*/ 132e5b6d6dSopenharmony_ci#include <stdio.h> 142e5b6d6dSopenharmony_ci#include <stdlib.h> 152e5b6d6dSopenharmony_ci 162e5b6d6dSopenharmony_ci#include "intltest.h" 172e5b6d6dSopenharmony_ci 182e5b6d6dSopenharmony_ci#if !UCONFIG_NO_FORMATTING 192e5b6d6dSopenharmony_ci 202e5b6d6dSopenharmony_ci#include "unicode/compactdecimalformat.h" 212e5b6d6dSopenharmony_ci#include "unicode/unum.h" 222e5b6d6dSopenharmony_ci#include "cmemory.h" 232e5b6d6dSopenharmony_ci 242e5b6d6dSopenharmony_citypedef struct ExpectedResult { 252e5b6d6dSopenharmony_ci double value; 262e5b6d6dSopenharmony_ci // Invariant characters, will be converted to UTF-16 and then unescaped. 272e5b6d6dSopenharmony_ci const char *expected; 282e5b6d6dSopenharmony_ci} ExpectedResult; 292e5b6d6dSopenharmony_ci 302e5b6d6dSopenharmony_cistatic const char *kShortStr = "Short"; 312e5b6d6dSopenharmony_cistatic const char *kLongStr = "Long"; 322e5b6d6dSopenharmony_ci 332e5b6d6dSopenharmony_cistatic ExpectedResult kEnglishShort[] = { 342e5b6d6dSopenharmony_ci {0.0, "0"}, 352e5b6d6dSopenharmony_ci {0.17, "0.17"}, 362e5b6d6dSopenharmony_ci {1.0, "1"}, 372e5b6d6dSopenharmony_ci {1234.0, "1.2K"}, 382e5b6d6dSopenharmony_ci {12345.0, "12K"}, 392e5b6d6dSopenharmony_ci {123456.0, "120K"}, 402e5b6d6dSopenharmony_ci {1234567.0, "1.2M"}, 412e5b6d6dSopenharmony_ci {12345678.0, "12M"}, 422e5b6d6dSopenharmony_ci {123456789.0, "120M"}, 432e5b6d6dSopenharmony_ci {1.23456789E9, "1.2B"}, 442e5b6d6dSopenharmony_ci {1.23456789E10, "12B"}, 452e5b6d6dSopenharmony_ci {1.23456789E11, "120B"}, 462e5b6d6dSopenharmony_ci {1.23456789E12, "1.2T"}, 472e5b6d6dSopenharmony_ci {1.23456789E13, "12T"}, 482e5b6d6dSopenharmony_ci {1.23456789E14, "120T"}, 492e5b6d6dSopenharmony_ci {1.23456789E15, "1200T"}}; 502e5b6d6dSopenharmony_ci 512e5b6d6dSopenharmony_cistatic ExpectedResult kSerbianShort[] = { 522e5b6d6dSopenharmony_ci {1234.0, "1,2\\u00a0\\u0445\\u0438\\u0459."}, 532e5b6d6dSopenharmony_ci {12345.0, "12\\u00a0\\u0445\\u0438\\u0459."}, 542e5b6d6dSopenharmony_ci {20789.0, "21\\u00a0\\u0445\\u0438\\u0459."}, 552e5b6d6dSopenharmony_ci {123456.0, "120\\u00a0\\u0445\\u0438\\u0459."}, 562e5b6d6dSopenharmony_ci {1234567.0, "1,2\\u00A0\\u043C\\u0438\\u043B."}, 572e5b6d6dSopenharmony_ci {12345678.0, "12\\u00A0\\u043C\\u0438\\u043B."}, 582e5b6d6dSopenharmony_ci {123456789.0, "120\\u00A0\\u043C\\u0438\\u043B."}, 592e5b6d6dSopenharmony_ci {1.23456789E9, "1,2\\u00A0\\u043C\\u043B\\u0440\\u0434."}, 602e5b6d6dSopenharmony_ci {1.23456789E10, "12\\u00A0\\u043C\\u043B\\u0440\\u0434."}, 612e5b6d6dSopenharmony_ci {1.23456789E11, "120\\u00A0\\u043C\\u043B\\u0440\\u0434."}, 622e5b6d6dSopenharmony_ci {1.23456789E12, "1,2\\u00A0\\u0431\\u0438\\u043B."}, 632e5b6d6dSopenharmony_ci {1.23456789E13, "12\\u00A0\\u0431\\u0438\\u043B."}, 642e5b6d6dSopenharmony_ci {1.23456789E14, "120\\u00A0\\u0431\\u0438\\u043B."}, 652e5b6d6dSopenharmony_ci {1.23456789E15, "1200\\u00A0\\u0431\\u0438\\u043B."}}; 662e5b6d6dSopenharmony_ci 672e5b6d6dSopenharmony_cistatic ExpectedResult kSerbianLong[] = { 682e5b6d6dSopenharmony_ci {1234.0, "1,2 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0435"}, // 10^3 few 692e5b6d6dSopenharmony_ci {12345.0, "12 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0430"}, // 10^3 other 702e5b6d6dSopenharmony_ci {21789.0, "22 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0435"}, // 10^3 few 712e5b6d6dSopenharmony_ci {123456.0, "120 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0430"}, // 10^3 other 722e5b6d6dSopenharmony_ci {999999.0, "1 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D"}, // 10^6 one 732e5b6d6dSopenharmony_ci {1234567.0, "1,2 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, // 10^6 few 742e5b6d6dSopenharmony_ci {12345678.0, "12 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, // 10^6 other 752e5b6d6dSopenharmony_ci {123456789.0, "120 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, // 10^6 other 762e5b6d6dSopenharmony_ci {1.23456789E9, "1,2 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0435"}, // 10^9 few 772e5b6d6dSopenharmony_ci {1.23456789E10, "12 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0438"}, // 10^9 other 782e5b6d6dSopenharmony_ci {2.08901234E10, "21 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0430"}, // 10^9 one 792e5b6d6dSopenharmony_ci {2.18901234E10, "22 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0435"}, // 10^9 few 802e5b6d6dSopenharmony_ci {1.23456789E11, "120 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0438"}, // 10^9 other 812e5b6d6dSopenharmony_ci {1.23456789E12, "1,2 \\u0431\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, // 10^12 few 822e5b6d6dSopenharmony_ci {1.23456789E13, "12 \\u0431\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, // 10^12 other 832e5b6d6dSopenharmony_ci {1.23456789E14, "120 \\u0431\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, // 10^12 other 842e5b6d6dSopenharmony_ci {1.23456789E15, "1200 \\u0431\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}}; // 10^12 other 852e5b6d6dSopenharmony_ci 862e5b6d6dSopenharmony_cistatic ExpectedResult kSerbianLongNegative[] = { 872e5b6d6dSopenharmony_ci {-1234.0, "-1,2 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0435"}, 882e5b6d6dSopenharmony_ci {-12345.0, "-12 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0430"}, 892e5b6d6dSopenharmony_ci {-21789.0, "-22 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0435"}, 902e5b6d6dSopenharmony_ci {-123456.0, "-120 \\u0445\\u0438\\u0459\\u0430\\u0434\\u0430"}, 912e5b6d6dSopenharmony_ci {-999999.0, "-1 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D"}, 922e5b6d6dSopenharmony_ci {-1234567.0, "-1,2 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, 932e5b6d6dSopenharmony_ci {-12345678.0, "-12 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, 942e5b6d6dSopenharmony_ci {-123456789.0, "-120 \\u043C\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, 952e5b6d6dSopenharmony_ci {-1.23456789E9, "-1,2 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0435"}, 962e5b6d6dSopenharmony_ci {-1.23456789E10, "-12 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0438"}, 972e5b6d6dSopenharmony_ci {-2.08901234E10, "-21 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0430"}, 982e5b6d6dSopenharmony_ci {-2.18901234E10, "-22 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0435"}, 992e5b6d6dSopenharmony_ci {-1.23456789E11, "-120 \\u043C\\u0438\\u043B\\u0438\\u0458\\u0430\\u0440\\u0434\\u0438"}, 1002e5b6d6dSopenharmony_ci {-1.23456789E12, "-1,2 \\u0431\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, 1012e5b6d6dSopenharmony_ci {-1.23456789E13, "-12 \\u0431\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, 1022e5b6d6dSopenharmony_ci {-1.23456789E14, "-120 \\u0431\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}, 1032e5b6d6dSopenharmony_ci {-1.23456789E15, "-1200 \\u0431\\u0438\\u043B\\u0438\\u043E\\u043D\\u0430"}}; 1042e5b6d6dSopenharmony_ci 1052e5b6d6dSopenharmony_cistatic ExpectedResult kJapaneseShort[] = { 1062e5b6d6dSopenharmony_ci {1234.0, "1200"}, 1072e5b6d6dSopenharmony_ci {12345.0, "1.2\\u4E07"}, 1082e5b6d6dSopenharmony_ci {123456.0, "12\\u4E07"}, 1092e5b6d6dSopenharmony_ci {1234567.0, "120\\u4E07"}, 1102e5b6d6dSopenharmony_ci {12345678.0, "1200\\u4E07"}, 1112e5b6d6dSopenharmony_ci {123456789.0, "1.2\\u5104"}, 1122e5b6d6dSopenharmony_ci {1.23456789E9, "12\\u5104"}, 1132e5b6d6dSopenharmony_ci {1.23456789E10, "120\\u5104"}, 1142e5b6d6dSopenharmony_ci {1.23456789E11, "1200\\u5104"}, 1152e5b6d6dSopenharmony_ci {1.23456789E12, "1.2\\u5146"}, 1162e5b6d6dSopenharmony_ci {1.23456789E13, "12\\u5146"}, 1172e5b6d6dSopenharmony_ci {1.23456789E14, "120\\u5146"}, 1182e5b6d6dSopenharmony_ci {1.23456789E15, "1200\\u5146"}, 1192e5b6d6dSopenharmony_ci {1.23456789E16, "1.2\\u4EAC"}, 1202e5b6d6dSopenharmony_ci {1.23456789E17, "12\\u4EAC"}, 1212e5b6d6dSopenharmony_ci {1.23456789E18, "120\\u4EAC"}, 1222e5b6d6dSopenharmony_ci {1.23456789E19, "1200\\u4EAC"}}; 1232e5b6d6dSopenharmony_ci 1242e5b6d6dSopenharmony_cistatic ExpectedResult kSwahiliShort[] = { 1252e5b6d6dSopenharmony_ci {1234.0, "elfu\\u00a01.2"}, 1262e5b6d6dSopenharmony_ci {12345.0, "elfu\\u00a012"}, 1272e5b6d6dSopenharmony_ci {123456.0, "elfu\\u00a0120"}, 1282e5b6d6dSopenharmony_ci {1234567.0, "1.2M"}, 1292e5b6d6dSopenharmony_ci {12345678.0, "12M"}, 1302e5b6d6dSopenharmony_ci {123456789.0, "120M"}, 1312e5b6d6dSopenharmony_ci {1.23456789E9, "1.2B"}, 1322e5b6d6dSopenharmony_ci {1.23456789E10, "12B"}, 1332e5b6d6dSopenharmony_ci {1.23456789E11, "120B"}, 1342e5b6d6dSopenharmony_ci {1.23456789E12, "1.2T"}, 1352e5b6d6dSopenharmony_ci {1.23456789E13, "12T"}, 1362e5b6d6dSopenharmony_ci {1.23456789E15, "1200T"}}; 1372e5b6d6dSopenharmony_ci 1382e5b6d6dSopenharmony_cistatic ExpectedResult kCsShort[] = { 1392e5b6d6dSopenharmony_ci {1000.0, "1\\u00a0tis."}, 1402e5b6d6dSopenharmony_ci {1500.0, "1,5\\u00a0tis."}, 1412e5b6d6dSopenharmony_ci {5000.0, "5\\u00a0tis."}, 1422e5b6d6dSopenharmony_ci {23000.0, "23\\u00a0tis."}, 1432e5b6d6dSopenharmony_ci {127123.0, "130\\u00a0tis."}, 1442e5b6d6dSopenharmony_ci {1271234.0, "1,3\\u00a0mil."}, 1452e5b6d6dSopenharmony_ci {12712345.0, "13\\u00a0mil."}, 1462e5b6d6dSopenharmony_ci {127123456.0, "130\\u00a0mil."}, 1472e5b6d6dSopenharmony_ci {1.27123456E9, "1,3\\u00a0mld."}, 1482e5b6d6dSopenharmony_ci {1.27123456E10, "13\\u00a0mld."}, 1492e5b6d6dSopenharmony_ci {1.27123456E11, "130\\u00a0mld."}, 1502e5b6d6dSopenharmony_ci {1.27123456E12, "1,3\\u00a0bil."}, 1512e5b6d6dSopenharmony_ci {1.27123456E13, "13\\u00a0bil."}, 1522e5b6d6dSopenharmony_ci {1.27123456E14, "130\\u00a0bil."}}; 1532e5b6d6dSopenharmony_ci 1542e5b6d6dSopenharmony_cistatic ExpectedResult kSkLong[] = { 1552e5b6d6dSopenharmony_ci {1000.0, "1 tis\\u00edc"}, 1562e5b6d6dSopenharmony_ci {1572.0, "1,6 tis\\u00edca"}, 1572e5b6d6dSopenharmony_ci {5184.0, "5,2 tis\\u00edca"}}; 1582e5b6d6dSopenharmony_ci 1592e5b6d6dSopenharmony_cistatic ExpectedResult kSwahiliShortNegative[] = { 1602e5b6d6dSopenharmony_ci {-1234.0, "elfu\\u00a0-1.2"}, 1612e5b6d6dSopenharmony_ci {-12345.0, "elfu\\u00a0-12"}, 1622e5b6d6dSopenharmony_ci {-123456.0, "elfu\\u00a0-120"}, 1632e5b6d6dSopenharmony_ci {-1234567.0, "-1.2M"}, 1642e5b6d6dSopenharmony_ci {-12345678.0, "-12M"}, 1652e5b6d6dSopenharmony_ci {-123456789.0, "-120M"}, 1662e5b6d6dSopenharmony_ci {-1.23456789E9, "-1.2B"}, 1672e5b6d6dSopenharmony_ci {-1.23456789E10, "-12B"}, 1682e5b6d6dSopenharmony_ci {-1.23456789E11, "-120B"}, 1692e5b6d6dSopenharmony_ci {-1.23456789E12, "-1.2T"}, 1702e5b6d6dSopenharmony_ci {-1.23456789E13, "-12T"}, 1712e5b6d6dSopenharmony_ci {-1.23456789E15, "-1200T"}}; 1722e5b6d6dSopenharmony_ci 1732e5b6d6dSopenharmony_cistatic ExpectedResult kArabicLong[] = { 1742e5b6d6dSopenharmony_ci {-5300.0, "\\u061C-\\u0665\\u066B\\u0663 \\u0623\\u0644\\u0641"}}; 1752e5b6d6dSopenharmony_ci 1762e5b6d6dSopenharmony_cistatic ExpectedResult kChineseCurrencyTestData[] = { 1772e5b6d6dSopenharmony_ci {1.0, "\\u00A51"}, 1782e5b6d6dSopenharmony_ci {12.0, "\\u00A512"}, 1792e5b6d6dSopenharmony_ci {123.0, "\\u00A5120"}, 1802e5b6d6dSopenharmony_ci {1234.0, "\\u00A51200"}, 1812e5b6d6dSopenharmony_ci {12345.0, "\\u00A51.2\\u4E07"}, 1822e5b6d6dSopenharmony_ci {123456.0, "\\u00A512\\u4E07"}, 1832e5b6d6dSopenharmony_ci {1234567.0, "\\u00A5120\\u4E07"}, 1842e5b6d6dSopenharmony_ci {12345678.0, "\\u00A51200\\u4E07"}, 1852e5b6d6dSopenharmony_ci {123456789.0, "\\u00A51.2\\u4EBF"}, 1862e5b6d6dSopenharmony_ci {1234567890.0, "\\u00A512\\u4EBF"}, 1872e5b6d6dSopenharmony_ci {12345678901.0, "\\u00A5120\\u4EBF"}, 1882e5b6d6dSopenharmony_ci {123456789012.0, "\\u00A51200\\u4EBF"}, 1892e5b6d6dSopenharmony_ci {1234567890123.0, "\\u00A51.2\\u4E07\\u4EBF"}, 1902e5b6d6dSopenharmony_ci {12345678901234.0, "\\u00A512\\u4E07\\u4EBF"}, 1912e5b6d6dSopenharmony_ci {123456789012345.0, "\\u00A5120\\u4E07\\u4EBF"}, 1922e5b6d6dSopenharmony_ci}; 1932e5b6d6dSopenharmony_cistatic ExpectedResult kGermanCurrencyTestData[] = { 1942e5b6d6dSopenharmony_ci {1.0, "1\\u00A0\\u20AC"}, 1952e5b6d6dSopenharmony_ci {12.0, "12\\u00A0\\u20AC"}, 1962e5b6d6dSopenharmony_ci {123.0, "120\\u00A0\\u20AC"}, 1972e5b6d6dSopenharmony_ci {1234.0, "1200\\u00A0\\u20AC"}, 1982e5b6d6dSopenharmony_ci {12345.0, "12.000\\u00A0\\u20AC"}, 1992e5b6d6dSopenharmony_ci {123456.0, "120.000\\u00A0\\u20AC"}, 2002e5b6d6dSopenharmony_ci {1234567.0, "1,2\\u00A0Mio.\\u00A0\\u20AC"}, 2012e5b6d6dSopenharmony_ci {12345678.0, "12\\u00A0Mio.\\u00A0\\u20AC"}, 2022e5b6d6dSopenharmony_ci {123456789.0, "120\\u00A0Mio.\\u00A0\\u20AC"}, 2032e5b6d6dSopenharmony_ci {1234567890.0, "1,2\\u00A0Mrd.\\u00A0\\u20AC"}, 2042e5b6d6dSopenharmony_ci {12345678901.0, "12\\u00A0Mrd.\\u00A0\\u20AC"}, 2052e5b6d6dSopenharmony_ci {123456789012.0, "120\\u00A0Mrd.\\u00A0\\u20AC"}, 2062e5b6d6dSopenharmony_ci {1234567890123.0, "1,2\\u00A0Bio.\\u00A0\\u20AC"}, 2072e5b6d6dSopenharmony_ci {12345678901234.0, "12\\u00A0Bio.\\u00A0\\u20AC"}, 2082e5b6d6dSopenharmony_ci {123456789012345.0, "120\\u00A0Bio.\\u00A0\\u20AC"}, 2092e5b6d6dSopenharmony_ci}; 2102e5b6d6dSopenharmony_cistatic ExpectedResult kEnglishCurrencyTestData[] = { 2112e5b6d6dSopenharmony_ci {1.0, "$1"}, 2122e5b6d6dSopenharmony_ci {12.0, "$12"}, 2132e5b6d6dSopenharmony_ci {123.0, "$120"}, 2142e5b6d6dSopenharmony_ci {1234.0, "$1.2K"}, 2152e5b6d6dSopenharmony_ci {12345.0, "$12K"}, 2162e5b6d6dSopenharmony_ci {123456.0, "$120K"}, 2172e5b6d6dSopenharmony_ci {1234567.0, "$1.2M"}, 2182e5b6d6dSopenharmony_ci {12345678.0, "$12M"}, 2192e5b6d6dSopenharmony_ci {123456789.0, "$120M"}, 2202e5b6d6dSopenharmony_ci {1234567890.0, "$1.2B"}, 2212e5b6d6dSopenharmony_ci {12345678901.0, "$12B"}, 2222e5b6d6dSopenharmony_ci {123456789012.0, "$120B"}, 2232e5b6d6dSopenharmony_ci {1234567890123.0, "$1.2T"}, 2242e5b6d6dSopenharmony_ci {12345678901234.0, "$12T"}, 2252e5b6d6dSopenharmony_ci {123456789012345.0, "$120T"}, 2262e5b6d6dSopenharmony_ci}; 2272e5b6d6dSopenharmony_ci 2282e5b6d6dSopenharmony_ci 2292e5b6d6dSopenharmony_ciclass CompactDecimalFormatTest : public IntlTest { 2302e5b6d6dSopenharmony_cipublic: 2312e5b6d6dSopenharmony_ci CompactDecimalFormatTest() { 2322e5b6d6dSopenharmony_ci } 2332e5b6d6dSopenharmony_ci 2342e5b6d6dSopenharmony_ci void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=0) override; 2352e5b6d6dSopenharmony_ciprivate: 2362e5b6d6dSopenharmony_ci void TestEnglishShort(); 2372e5b6d6dSopenharmony_ci void TestSerbianShort(); 2382e5b6d6dSopenharmony_ci void TestSerbianLong(); 2392e5b6d6dSopenharmony_ci void TestSerbianLongNegative(); 2402e5b6d6dSopenharmony_ci void TestJapaneseShort(); 2412e5b6d6dSopenharmony_ci void TestSwahiliShort(); 2422e5b6d6dSopenharmony_ci void TestCsShort(); 2432e5b6d6dSopenharmony_ci void TestSkLong(); 2442e5b6d6dSopenharmony_ci void TestSwahiliShortNegative(); 2452e5b6d6dSopenharmony_ci void TestEnglishCurrency(); 2462e5b6d6dSopenharmony_ci void TestGermanCurrency(); 2472e5b6d6dSopenharmony_ci void TestChineseCurrency(); 2482e5b6d6dSopenharmony_ci void TestArabicLong(); 2492e5b6d6dSopenharmony_ci void TestFieldPosition(); 2502e5b6d6dSopenharmony_ci void TestDefaultSignificantDigits(); 2512e5b6d6dSopenharmony_ci void TestAPIVariants(); 2522e5b6d6dSopenharmony_ci void TestBug12975(); 2532e5b6d6dSopenharmony_ci 2542e5b6d6dSopenharmony_ci void CheckLocale( 2552e5b6d6dSopenharmony_ci const Locale& locale, UNumberCompactStyle style, 2562e5b6d6dSopenharmony_ci const ExpectedResult* expectedResults, int32_t expectedResultLength); 2572e5b6d6dSopenharmony_ci void CheckLocaleWithCurrency(const Locale& locale, UNumberCompactStyle style, const UChar* currency, 2582e5b6d6dSopenharmony_ci const ExpectedResult* expectedResults, int32_t expectedResultLength); 2592e5b6d6dSopenharmony_ci void CheckExpectedResult( 2602e5b6d6dSopenharmony_ci const CompactDecimalFormat* cdf, const ExpectedResult* expectedResult, 2612e5b6d6dSopenharmony_ci const char* description); 2622e5b6d6dSopenharmony_ci CompactDecimalFormat* createCDFInstance(const Locale& locale, UNumberCompactStyle style, UErrorCode& status); 2632e5b6d6dSopenharmony_ci static const char *StyleStr(UNumberCompactStyle style); 2642e5b6d6dSopenharmony_ci}; 2652e5b6d6dSopenharmony_ci 2662e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::runIndexedTest( 2672e5b6d6dSopenharmony_ci int32_t index, UBool exec, const char *&name, char *) { 2682e5b6d6dSopenharmony_ci if (exec) { 2692e5b6d6dSopenharmony_ci logln("TestSuite CompactDecimalFormatTest: "); 2702e5b6d6dSopenharmony_ci } 2712e5b6d6dSopenharmony_ci TESTCASE_AUTO_BEGIN; 2722e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestEnglishShort); 2732e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestSerbianShort); 2742e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestSerbianLong); 2752e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestSerbianLongNegative); 2762e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestJapaneseShort); 2772e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestSwahiliShort); 2782e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestEnglishCurrency); 2792e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestGermanCurrency); 2802e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestChineseCurrency); 2812e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestCsShort); 2822e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestSkLong); 2832e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestSwahiliShortNegative); 2842e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestArabicLong); 2852e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestFieldPosition); 2862e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestDefaultSignificantDigits); 2872e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestAPIVariants); 2882e5b6d6dSopenharmony_ci TESTCASE_AUTO(TestBug12975); 2892e5b6d6dSopenharmony_ci TESTCASE_AUTO_END; 2902e5b6d6dSopenharmony_ci} 2912e5b6d6dSopenharmony_ci 2922e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestEnglishShort() { 2932e5b6d6dSopenharmony_ci CheckLocale("en", UNUM_SHORT, kEnglishShort, UPRV_LENGTHOF(kEnglishShort)); 2942e5b6d6dSopenharmony_ci} 2952e5b6d6dSopenharmony_ci 2962e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestSerbianShort() { 2972e5b6d6dSopenharmony_ci CheckLocale("sr", UNUM_SHORT, kSerbianShort, UPRV_LENGTHOF(kSerbianShort)); 2982e5b6d6dSopenharmony_ci} 2992e5b6d6dSopenharmony_ci 3002e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestSerbianLong() { 3012e5b6d6dSopenharmony_ci CheckLocale("sr", UNUM_LONG, kSerbianLong, UPRV_LENGTHOF(kSerbianLong)); 3022e5b6d6dSopenharmony_ci} 3032e5b6d6dSopenharmony_ci 3042e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestSerbianLongNegative() { 3052e5b6d6dSopenharmony_ci CheckLocale("sr", UNUM_LONG, kSerbianLongNegative, UPRV_LENGTHOF(kSerbianLongNegative)); 3062e5b6d6dSopenharmony_ci} 3072e5b6d6dSopenharmony_ci 3082e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestJapaneseShort() { 3092e5b6d6dSopenharmony_ci CheckLocale(Locale::getJapan(), UNUM_SHORT, kJapaneseShort, UPRV_LENGTHOF(kJapaneseShort)); 3102e5b6d6dSopenharmony_ci} 3112e5b6d6dSopenharmony_ci 3122e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestSwahiliShort() { 3132e5b6d6dSopenharmony_ci CheckLocale("sw", UNUM_SHORT, kSwahiliShort, UPRV_LENGTHOF(kSwahiliShort)); 3142e5b6d6dSopenharmony_ci} 3152e5b6d6dSopenharmony_ci 3162e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestEnglishCurrency() { 3172e5b6d6dSopenharmony_ci CheckLocaleWithCurrency( 3182e5b6d6dSopenharmony_ci "en", UNUM_SHORT, u"USD", kEnglishCurrencyTestData, UPRV_LENGTHOF(kEnglishCurrencyTestData)); 3192e5b6d6dSopenharmony_ci} 3202e5b6d6dSopenharmony_ci 3212e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestGermanCurrency() { 3222e5b6d6dSopenharmony_ci CheckLocaleWithCurrency( 3232e5b6d6dSopenharmony_ci "de", UNUM_SHORT, u"EUR", kGermanCurrencyTestData, UPRV_LENGTHOF(kGermanCurrencyTestData)); 3242e5b6d6dSopenharmony_ci} 3252e5b6d6dSopenharmony_ci 3262e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestChineseCurrency() { 3272e5b6d6dSopenharmony_ci CheckLocaleWithCurrency( 3282e5b6d6dSopenharmony_ci "zh", UNUM_SHORT, u"CNY", kChineseCurrencyTestData, UPRV_LENGTHOF(kChineseCurrencyTestData)); 3292e5b6d6dSopenharmony_ci} 3302e5b6d6dSopenharmony_ci 3312e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestFieldPosition() { 3322e5b6d6dSopenharmony_ci // Swahili uses prefixes which forces offsets in field position to change 3332e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 3342e5b6d6dSopenharmony_ci LocalPointer<CompactDecimalFormat> cdf(createCDFInstance("sw", UNUM_SHORT, status)); 3352e5b6d6dSopenharmony_ci if (U_FAILURE(status)) { 3362e5b6d6dSopenharmony_ci dataerrln("Unable to create format object - %s", u_errorName(status)); 3372e5b6d6dSopenharmony_ci return; 3382e5b6d6dSopenharmony_ci } 3392e5b6d6dSopenharmony_ci FieldPosition fp(UNUM_INTEGER_FIELD); 3402e5b6d6dSopenharmony_ci UnicodeString result; 3412e5b6d6dSopenharmony_ci cdf->format(1234567.0, result, fp); 3422e5b6d6dSopenharmony_ci UnicodeString subString = result.tempSubString(fp.getBeginIndex(), fp.getEndIndex() - fp.getBeginIndex()); 3432e5b6d6dSopenharmony_ci if (subString != UnicodeString("1", -1, US_INV)) { 3442e5b6d6dSopenharmony_ci errln(UnicodeString("Expected 1, got ") + subString); 3452e5b6d6dSopenharmony_ci } 3462e5b6d6dSopenharmony_ci} 3472e5b6d6dSopenharmony_ci 3482e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestCsShort() { 3492e5b6d6dSopenharmony_ci CheckLocale("cs", UNUM_SHORT, kCsShort, UPRV_LENGTHOF(kCsShort)); 3502e5b6d6dSopenharmony_ci} 3512e5b6d6dSopenharmony_ci 3522e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestSkLong() { 3532e5b6d6dSopenharmony_ci // In CLDR we have: 3542e5b6d6dSopenharmony_ci // 1000 { 3552e5b6d6dSopenharmony_ci // few{"0"} 3562e5b6d6dSopenharmony_ci // one{"0"} 3572e5b6d6dSopenharmony_ci // other{"0"} 3582e5b6d6dSopenharmony_ci CheckLocale("sk", UNUM_LONG, kSkLong, UPRV_LENGTHOF(kSkLong)); 3592e5b6d6dSopenharmony_ci} 3602e5b6d6dSopenharmony_ci 3612e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestSwahiliShortNegative() { 3622e5b6d6dSopenharmony_ci CheckLocale("sw", UNUM_SHORT, kSwahiliShortNegative, UPRV_LENGTHOF(kSwahiliShortNegative)); 3632e5b6d6dSopenharmony_ci} 3642e5b6d6dSopenharmony_ci 3652e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestArabicLong() { 3662e5b6d6dSopenharmony_ci CheckLocale("ar-EG", UNUM_LONG, kArabicLong, UPRV_LENGTHOF(kArabicLong)); 3672e5b6d6dSopenharmony_ci} 3682e5b6d6dSopenharmony_ci 3692e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestDefaultSignificantDigits() { 3702e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 3712e5b6d6dSopenharmony_ci LocalPointer<CompactDecimalFormat> cdf(CompactDecimalFormat::createInstance("en", UNUM_SHORT, status)); 3722e5b6d6dSopenharmony_ci if (U_FAILURE(status)) { 3732e5b6d6dSopenharmony_ci dataerrln("Unable to create format object - %s", u_errorName(status)); 3742e5b6d6dSopenharmony_ci return; 3752e5b6d6dSopenharmony_ci } 3762e5b6d6dSopenharmony_ci // We are expecting two significant digits for compact formats with one or two zeros, 3772e5b6d6dSopenharmony_ci // and rounded to the unit for compact formats with three or more zeros. 3782e5b6d6dSopenharmony_ci UnicodeString actual; 3792e5b6d6dSopenharmony_ci assertEquals("Default significant digits", u"123K", cdf->format(123456, actual.remove())); 3802e5b6d6dSopenharmony_ci assertEquals("Default significant digits", u"12K", cdf->format(12345, actual.remove())); 3812e5b6d6dSopenharmony_ci assertEquals("Default significant digits", u"1.2K", cdf->format(1234, actual.remove())); 3822e5b6d6dSopenharmony_ci assertEquals("Default significant digits", u"123", cdf->format(123, actual.remove())); 3832e5b6d6dSopenharmony_ci} 3842e5b6d6dSopenharmony_ci 3852e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestAPIVariants() { 3862e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 3872e5b6d6dSopenharmony_ci LocalPointer<CompactDecimalFormat> cdf(CompactDecimalFormat::createInstance("en", UNUM_SHORT, status)); 3882e5b6d6dSopenharmony_ci if (U_FAILURE(status)) { 3892e5b6d6dSopenharmony_ci dataerrln("Unable to create format object - %s", u_errorName(status)); 3902e5b6d6dSopenharmony_ci return; 3912e5b6d6dSopenharmony_ci } 3922e5b6d6dSopenharmony_ci UnicodeString actual; 3932e5b6d6dSopenharmony_ci FieldPosition pos; 3942e5b6d6dSopenharmony_ci FieldPositionIterator posIter; 3952e5b6d6dSopenharmony_ci UnicodeString expected("123K", -1, US_INV); 3962e5b6d6dSopenharmony_ci pos.setField(UNUM_INTEGER_FIELD); 3972e5b6d6dSopenharmony_ci 3982e5b6d6dSopenharmony_ci actual.remove(); 3992e5b6d6dSopenharmony_ci pos.setBeginIndex(0); 4002e5b6d6dSopenharmony_ci pos.setEndIndex(0); 4012e5b6d6dSopenharmony_ci cdf->format((double)123456.0, actual, pos); 4022e5b6d6dSopenharmony_ci if (actual != expected || pos.getEndIndex() != 3) { 4032e5b6d6dSopenharmony_ci errln(UnicodeString("Fail format(double,UnicodeString&,FieldPosition&): Expected: \"") + expected + "\", pos 3; " + 4042e5b6d6dSopenharmony_ci "Got: \"" + actual + "\", pos " + pos.getEndIndex()); 4052e5b6d6dSopenharmony_ci } 4062e5b6d6dSopenharmony_ci 4072e5b6d6dSopenharmony_ci actual.remove(); 4082e5b6d6dSopenharmony_ci pos.setBeginIndex(0); 4092e5b6d6dSopenharmony_ci pos.setEndIndex(0); 4102e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 4112e5b6d6dSopenharmony_ci cdf->format((double)123456.0, actual, pos, status); 4122e5b6d6dSopenharmony_ci if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { 4132e5b6d6dSopenharmony_ci errln(UnicodeString("Fail format(double,UnicodeString&,FieldPosition&,UErrorCode&): Expected: \"") + expected + "\", pos 3, status U_ZERO_ERROR; " + 4142e5b6d6dSopenharmony_ci "Got: \"" + actual + "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); 4152e5b6d6dSopenharmony_ci } 4162e5b6d6dSopenharmony_ci 4172e5b6d6dSopenharmony_ci actual.remove(); 4182e5b6d6dSopenharmony_ci pos.setBeginIndex(0); 4192e5b6d6dSopenharmony_ci pos.setEndIndex(0); 4202e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 4212e5b6d6dSopenharmony_ci cdf->format((double)123456.0, actual, &posIter, status); 4222e5b6d6dSopenharmony_ci posIter.next(pos); 4232e5b6d6dSopenharmony_ci if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { 4242e5b6d6dSopenharmony_ci errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&,UErrorCode&): Expected: \"") + expected + "\", first pos 3, status U_ZERO_ERROR; " + 4252e5b6d6dSopenharmony_ci "Got: \"" + actual + "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); 4262e5b6d6dSopenharmony_ci } 4272e5b6d6dSopenharmony_ci 4282e5b6d6dSopenharmony_ci actual.remove(); 4292e5b6d6dSopenharmony_ci pos.setBeginIndex(0); 4302e5b6d6dSopenharmony_ci pos.setEndIndex(0); 4312e5b6d6dSopenharmony_ci cdf->format((int32_t)123456, actual, pos); 4322e5b6d6dSopenharmony_ci if (actual != expected || pos.getEndIndex() != 3) { 4332e5b6d6dSopenharmony_ci errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&): Expected: \"") + expected + "\", pos 3; " + 4342e5b6d6dSopenharmony_ci "Got: \"" + actual + "\", pos " + pos.getEndIndex()); 4352e5b6d6dSopenharmony_ci } 4362e5b6d6dSopenharmony_ci 4372e5b6d6dSopenharmony_ci actual.remove(); 4382e5b6d6dSopenharmony_ci pos.setBeginIndex(0); 4392e5b6d6dSopenharmony_ci pos.setEndIndex(0); 4402e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 4412e5b6d6dSopenharmony_ci cdf->format((int32_t)123456, actual, pos, status); 4422e5b6d6dSopenharmony_ci if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { 4432e5b6d6dSopenharmony_ci errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&,UErrorCode&): Expected: \"") + expected + "\", pos 3, status U_ZERO_ERROR; " + 4442e5b6d6dSopenharmony_ci "Got: \"" + actual + "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); 4452e5b6d6dSopenharmony_ci } 4462e5b6d6dSopenharmony_ci 4472e5b6d6dSopenharmony_ci actual.remove(); 4482e5b6d6dSopenharmony_ci pos.setBeginIndex(0); 4492e5b6d6dSopenharmony_ci pos.setEndIndex(0); 4502e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 4512e5b6d6dSopenharmony_ci cdf->format((int32_t)123456, actual, &posIter, status); 4522e5b6d6dSopenharmony_ci posIter.next(pos); 4532e5b6d6dSopenharmony_ci if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { 4542e5b6d6dSopenharmony_ci errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&,UErrorCode&): Expected: \"") + expected + "\", first pos 3, status U_ZERO_ERROR; " + 4552e5b6d6dSopenharmony_ci "Got: \"" + actual + "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); 4562e5b6d6dSopenharmony_ci } 4572e5b6d6dSopenharmony_ci 4582e5b6d6dSopenharmony_ci actual.remove(); 4592e5b6d6dSopenharmony_ci pos.setBeginIndex(0); 4602e5b6d6dSopenharmony_ci pos.setEndIndex(0); 4612e5b6d6dSopenharmony_ci cdf->format((int64_t)123456, actual, pos); 4622e5b6d6dSopenharmony_ci if (actual != expected || pos.getEndIndex() != 3) { 4632e5b6d6dSopenharmony_ci errln(UnicodeString("Fail format(int64_t,UnicodeString&,FieldPosition&): Expected: \"") + expected + "\", pos 3; " + 4642e5b6d6dSopenharmony_ci "Got: \"" + actual + "\", pos " + pos.getEndIndex()); 4652e5b6d6dSopenharmony_ci } 4662e5b6d6dSopenharmony_ci 4672e5b6d6dSopenharmony_ci actual.remove(); 4682e5b6d6dSopenharmony_ci pos.setBeginIndex(0); 4692e5b6d6dSopenharmony_ci pos.setEndIndex(0); 4702e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 4712e5b6d6dSopenharmony_ci cdf->format((int64_t)123456, actual, pos, status); 4722e5b6d6dSopenharmony_ci if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { 4732e5b6d6dSopenharmony_ci errln(UnicodeString("Fail format(int64_t,UnicodeString&,FieldPosition&,UErrorCode&): Expected: \"") + expected + "\", pos 3, status U_ZERO_ERROR; " + 4742e5b6d6dSopenharmony_ci "Got: \"" + actual + "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); 4752e5b6d6dSopenharmony_ci } 4762e5b6d6dSopenharmony_ci 4772e5b6d6dSopenharmony_ci actual.remove(); 4782e5b6d6dSopenharmony_ci pos.setBeginIndex(0); 4792e5b6d6dSopenharmony_ci pos.setEndIndex(0); 4802e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 4812e5b6d6dSopenharmony_ci cdf->format((int64_t)123456, actual, &posIter, status); 4822e5b6d6dSopenharmony_ci posIter.next(pos); 4832e5b6d6dSopenharmony_ci if (actual != expected || pos.getEndIndex() != 3 || status != U_ZERO_ERROR) { 4842e5b6d6dSopenharmony_ci errln(UnicodeString("Fail format(int32_t,UnicodeString&,FieldPosition&,UErrorCode&): Expected: \"") + expected + "\", first pos 3, status U_ZERO_ERROR; " + 4852e5b6d6dSopenharmony_ci "Got: \"" + actual + "\", pos " + pos.getEndIndex() + ", status " + u_errorName(status)); 4862e5b6d6dSopenharmony_ci } 4872e5b6d6dSopenharmony_ci 4882e5b6d6dSopenharmony_ci} 4892e5b6d6dSopenharmony_ci 4902e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::TestBug12975() { 4912e5b6d6dSopenharmony_ci IcuTestErrorCode status(*this, "TestBug12975"); 4922e5b6d6dSopenharmony_ci Locale locale("it"); 4932e5b6d6dSopenharmony_ci LocalPointer<CompactDecimalFormat> cdf(CompactDecimalFormat::createInstance(locale, UNUM_SHORT, status)); 4942e5b6d6dSopenharmony_ci if (assertSuccess("", status, true, __FILE__, __LINE__)) { 4952e5b6d6dSopenharmony_ci UnicodeString resultCdf; 4962e5b6d6dSopenharmony_ci cdf->format(12000, resultCdf); 4972e5b6d6dSopenharmony_ci LocalPointer<DecimalFormat> df((DecimalFormat*) DecimalFormat::createInstance(locale, status)); 4982e5b6d6dSopenharmony_ci UnicodeString resultDefault; 4992e5b6d6dSopenharmony_ci df->format(12000, resultDefault); 5002e5b6d6dSopenharmony_ci assertEquals("CompactDecimalFormat should use default pattern when compact pattern is unavailable", 5012e5b6d6dSopenharmony_ci resultDefault, resultCdf); 5022e5b6d6dSopenharmony_ci } 5032e5b6d6dSopenharmony_ci} 5042e5b6d6dSopenharmony_ci 5052e5b6d6dSopenharmony_ci 5062e5b6d6dSopenharmony_ci// End test cases. Helpers: 5072e5b6d6dSopenharmony_ci 5082e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::CheckLocale(const Locale& locale, UNumberCompactStyle style, const ExpectedResult* expectedResults, int32_t expectedResultLength) { 5092e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 5102e5b6d6dSopenharmony_ci LocalPointer<CompactDecimalFormat> cdf(createCDFInstance(locale, style, status)); 5112e5b6d6dSopenharmony_ci if (U_FAILURE(status)) { 5122e5b6d6dSopenharmony_ci dataerrln("Unable to create format object - %s", u_errorName(status)); 5132e5b6d6dSopenharmony_ci return; 5142e5b6d6dSopenharmony_ci } 5152e5b6d6dSopenharmony_ci char description[256]; 5162e5b6d6dSopenharmony_ci sprintf(description,"%s - %s", locale.getName(), StyleStr(style)); 5172e5b6d6dSopenharmony_ci for (int32_t i = 0; i < expectedResultLength; i++) { 5182e5b6d6dSopenharmony_ci CheckExpectedResult(cdf.getAlias(), &expectedResults[i], description); 5192e5b6d6dSopenharmony_ci } 5202e5b6d6dSopenharmony_ci} 5212e5b6d6dSopenharmony_ci 5222e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::CheckLocaleWithCurrency(const Locale& locale, UNumberCompactStyle style, 5232e5b6d6dSopenharmony_ci const UChar* currency, 5242e5b6d6dSopenharmony_ci const ExpectedResult* expectedResults, 5252e5b6d6dSopenharmony_ci int32_t expectedResultLength) { 5262e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 5272e5b6d6dSopenharmony_ci LocalPointer<CompactDecimalFormat> cdf(createCDFInstance(locale, style, status)); 5282e5b6d6dSopenharmony_ci if (U_FAILURE(status)) { 5292e5b6d6dSopenharmony_ci dataerrln("Unable to create format object - %s", u_errorName(status)); 5302e5b6d6dSopenharmony_ci return; 5312e5b6d6dSopenharmony_ci } 5322e5b6d6dSopenharmony_ci cdf->setCurrency(currency, status); 5332e5b6d6dSopenharmony_ci assertSuccess("Failed to set currency", status); 5342e5b6d6dSopenharmony_ci char description[256]; 5352e5b6d6dSopenharmony_ci sprintf(description,"%s - %s", locale.getName(), StyleStr(style)); 5362e5b6d6dSopenharmony_ci for (int32_t i = 0; i < expectedResultLength; i++) { 5372e5b6d6dSopenharmony_ci CheckExpectedResult(cdf.getAlias(), &expectedResults[i], description); 5382e5b6d6dSopenharmony_ci } 5392e5b6d6dSopenharmony_ci} 5402e5b6d6dSopenharmony_ci 5412e5b6d6dSopenharmony_civoid CompactDecimalFormatTest::CheckExpectedResult( 5422e5b6d6dSopenharmony_ci const CompactDecimalFormat* cdf, const ExpectedResult* expectedResult, const char* description) { 5432e5b6d6dSopenharmony_ci UnicodeString actual; 5442e5b6d6dSopenharmony_ci cdf->format(expectedResult->value, actual); 5452e5b6d6dSopenharmony_ci UnicodeString expected(expectedResult->expected, -1, US_INV); 5462e5b6d6dSopenharmony_ci expected = expected.unescape(); 5472e5b6d6dSopenharmony_ci if (actual != expected) { 5482e5b6d6dSopenharmony_ci errln(UnicodeString("Fail: Expected: ") + expected 5492e5b6d6dSopenharmony_ci + UnicodeString(" Got: ") + actual 5502e5b6d6dSopenharmony_ci + UnicodeString(" for: ") + UnicodeString(description)); 5512e5b6d6dSopenharmony_ci } 5522e5b6d6dSopenharmony_ci} 5532e5b6d6dSopenharmony_ci 5542e5b6d6dSopenharmony_ciCompactDecimalFormat* 5552e5b6d6dSopenharmony_ciCompactDecimalFormatTest::createCDFInstance(const Locale& locale, UNumberCompactStyle style, UErrorCode& status) { 5562e5b6d6dSopenharmony_ci CompactDecimalFormat* result = CompactDecimalFormat::createInstance(locale, style, status); 5572e5b6d6dSopenharmony_ci if (U_FAILURE(status)) { 5582e5b6d6dSopenharmony_ci return NULL; 5592e5b6d6dSopenharmony_ci } 5602e5b6d6dSopenharmony_ci // All tests are written for two significant digits, so we explicitly set here 5612e5b6d6dSopenharmony_ci // in case default significant digits change. 5622e5b6d6dSopenharmony_ci result->setMaximumSignificantDigits(2); 5632e5b6d6dSopenharmony_ci return result; 5642e5b6d6dSopenharmony_ci} 5652e5b6d6dSopenharmony_ci 5662e5b6d6dSopenharmony_ciconst char *CompactDecimalFormatTest::StyleStr(UNumberCompactStyle style) { 5672e5b6d6dSopenharmony_ci if (style == UNUM_SHORT) { 5682e5b6d6dSopenharmony_ci return kShortStr; 5692e5b6d6dSopenharmony_ci } 5702e5b6d6dSopenharmony_ci return kLongStr; 5712e5b6d6dSopenharmony_ci} 5722e5b6d6dSopenharmony_ci 5732e5b6d6dSopenharmony_ciextern IntlTest *createCompactDecimalFormatTest() { 5742e5b6d6dSopenharmony_ci return new CompactDecimalFormatTest(); 5752e5b6d6dSopenharmony_ci} 5762e5b6d6dSopenharmony_ci 5772e5b6d6dSopenharmony_ci#endif 578