1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*
  24  * @test
  25  * @bug 8177552
  26  * @summary Checks the behaviour of Unicode BCP 47 U Extension with
  27  *          compact number format
  28  * @modules jdk.localedata
  29  * @run testng/othervm TestUExtensionOverride
  30  */
  31 import java.text.NumberFormat;
  32 import java.text.ParseException;
  33 import java.util.Locale;
  34 import org.testng.annotations.DataProvider;
  35 import org.testng.annotations.Test;
  36 
  37 public class TestUExtensionOverride {
  38 
  39     @DataProvider(name = "compactFormatData")
  40     Object[][] compactFormatData() {
  41         return new Object[][]{
  42             // locale, number, formatted string
  43 
  44             // -nu
  45             {Locale.forLanguageTag("en-US-u-nu-deva"), 12345, "\u0967\u0968K"},
  46             {Locale.forLanguageTag("en-US-u-nu-sinh"), 12345, "\u0de7\u0de8K"},
  47             {Locale.forLanguageTag("en-US-u-nu-zzzz"), 12345, "12K"},
  48             // -rg
  49             {Locale.forLanguageTag("fr-FR-u-rg-cazzzz"), 1234567,
  50                 "1\u00a0234\u00a0567"},
  51             {Locale.forLanguageTag("fr-FR-u-rg-cazzzz"), 1234567890,
  52                 "1\u00a0G"},
  53             // -nu and -rg
  54             {Locale.forLanguageTag("en-US-u-nu-deva-rg-dezzzz"), 12345,
  55                 "\u0967\u0968K"},
  56             {Locale.forLanguageTag("fr-FR-u-nu-zzzz-rg-cazzzz"), 1234567890,
  57                 "1\u00a0Md"},
  58             {Locale.forLanguageTag("fr-FR-u-nu-zzzz-rg-zzzz"), 12345,
  59                 "12\u00a0k"},
  60             {Locale.forLanguageTag("fr-FR-u-rg-cazzzz-nu-deva"), 12345,
  61                 "\u0967\u0968\u00a0k"},};
  62     }
  63 
  64     @DataProvider(name = "compactParseData")
  65     Object[][] compactParseData() {
  66         return new Object[][]{
  67             // locale, parse string, parsed number
  68 
  69             // -nu
  70             {Locale.forLanguageTag("en-US-u-nu-deva"),
  71                 "\u0967\u0968K", 12000L},
  72             {Locale.forLanguageTag("en-US-u-nu-sinh"),
  73                 "\u0de7\u0de8K", 12000L},
  74             {Locale.forLanguageTag("en-US-u-nu-zzzz"),
  75                 "12K", 12000L},
  76             // -rg
  77             {Locale.forLanguageTag("fr-FR-u-rg-cazzzz"),
  78                 "1\u00a0G", 1000000000L},
  79             // -nu and -rg
  80             {Locale.forLanguageTag("en-US-u-nu-deva-rg-dezzzz"),
  81                 "\u0967\u0968K", 12000L},
  82             {Locale.forLanguageTag("fr-FR-u-nu-zzzz-rg-cazzzz"),
  83                 "1\u00a0Md", 1000000000L},
  84             {Locale.forLanguageTag("fr-FR-u-nu-zzzz-rg-zzzz"),
  85                 "12\u00a0k", 12000L},
  86             {Locale.forLanguageTag("fr-FR-u-rg-cazzzz-nu-deva"),
  87                 "\u0967\u0968\u00a0k", 12000L},};
  88     }
  89 
  90     @Test(dataProvider = "compactFormatData")
  91     public void testFormat(Locale locale, double num,
  92             String expected) {
  93         NumberFormat cnf = NumberFormat.getCompactNumberInstance(locale,
  94                 NumberFormat.Style.SHORT);
  95         CompactFormatAndParseHelper.testFormat(cnf, num, expected);
  96     }
  97 
  98     @Test(dataProvider = "compactParseData")
  99     public void testParse(Locale locale, String parseString,
 100             Number expected) throws ParseException {
 101         NumberFormat cnf = NumberFormat.getCompactNumberInstance(locale,
 102                 NumberFormat.Style.SHORT);
 103         CompactFormatAndParseHelper.testParse(cnf, parseString, expected, null, null);
 104     }
 105 
 106 }