< prev index next >

test/jdk/java/util/PluggableLocale/LocaleNameProviderTest.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2013, 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  *









  25  */
  26 
  27 import java.text.*;
  28 import java.util.*;
  29 import sun.util.locale.provider.*;
  30 import sun.util.resources.*;






  31 
  32 public class LocaleNameProviderTest extends ProviderTest {
  33 
  34     public static void main(String[] s) {
  35         new LocaleNameProviderTest();
  36     }
  37 
  38     LocaleNameProviderTest() {
  39         checkAvailLocValidityTest();
  40         variantFallbackTest();
  41     }
  42 
  43     void checkAvailLocValidityTest() {
  44         com.bar.LocaleNameProviderImpl lnp = new com.bar.LocaleNameProviderImpl();
  45         Locale[] availloc = Locale.getAvailableLocales();
  46         Locale[] testloc = availloc.clone();
  47         List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getLocaleNameProvider().getAvailableLocales());
  48         List<Locale> providerloc = Arrays.asList(lnp.getAvailableLocales());
  49 
  50         for (Locale target: availloc) {
  51             // pure JRE implementation
  52             OpenListResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getLocaleNames(target);
  53             boolean jreSupportsTarget = jreimplloc.contains(target);
  54 
  55             for (Locale test: testloc) {
  56                 // codes
  57                 String lang = test.getLanguage();
  58                 String ctry = test.getCountry();
  59                 String vrnt = test.getVariant();
  60 
  61                 // the localized name
  62                 String langresult = test.getDisplayLanguage(target);
  63                 String ctryresult = test.getDisplayCountry(target);
  64                 String vrntresult = test.getDisplayVariant(target);


 104                     jreSupportsTarget && jresvrnt != null);
 105             }
 106         }
 107     }
 108 
 109     void variantFallbackTest() {
 110         Locale YY = new Locale("yy", "YY", "YYYY");
 111         Locale YY_suffix = new Locale("yy", "YY", "YYYY_suffix");
 112         String retVrnt = null;
 113         String message = "variantFallbackTest() succeeded.";
 114 
 115 
 116         try {
 117             YY.getDisplayVariant(YY_suffix);
 118             message = "variantFallbackTest() failed. Either provider wasn't invoked, or invoked without suffix.";
 119         } catch (RuntimeException re) {
 120             retVrnt = re.getMessage();
 121             if (YY_suffix.getVariant().equals(retVrnt)) {
 122                 System.out.println(message);
 123                 return;
 124 }
 125             message = "variantFallbackTest() failed. Returned variant: "+retVrnt;
 126         }
 127 
 128         throw new RuntimeException(message);
 129     }
 130 }
   1 /*
   2  * Copyright (c) 2007, 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 /*
  25  * @test
  26  * @bug 4052440 8000273 8062588 8210406
  27  * @summary LocaleNameProvider tests
  28  * @library providersrc/foobarutils
  29  *          providersrc/barprovider
  30  * @modules java.base/sun.util.locale.provider
  31  *          java.base/sun.util.resources
  32  * @build com.foobar.Utils
  33  *        com.bar.*
  34  * @run main/othervm -Djava.locale.providers=JRE,SPI LocaleNameProviderTest
  35  */
  36 
  37 import java.util.Arrays;
  38 import java.util.List;
  39 import java.util.Locale;
  40 import java.util.MissingResourceException;
  41 
  42 import com.bar.LocaleNameProviderImpl;
  43 
  44 import sun.util.locale.provider.LocaleProviderAdapter;
  45 import sun.util.locale.provider.ResourceBundleBasedAdapter;
  46 import sun.util.resources.OpenListResourceBundle;
  47 
  48 public class LocaleNameProviderTest extends ProviderTest {
  49 
  50     public static void main(String[] s) {
  51         new LocaleNameProviderTest();
  52     }
  53 
  54     LocaleNameProviderTest() {
  55         checkAvailLocValidityTest();
  56         variantFallbackTest();
  57     }
  58 
  59     void checkAvailLocValidityTest() {
  60         LocaleNameProviderImpl lnp = new LocaleNameProviderImpl();
  61         Locale[] availloc = Locale.getAvailableLocales();
  62         Locale[] testloc = availloc.clone();
  63         List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getLocaleNameProvider().getAvailableLocales());
  64         List<Locale> providerloc = Arrays.asList(lnp.getAvailableLocales());
  65 
  66         for (Locale target: availloc) {
  67             // pure JRE implementation
  68             OpenListResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getLocaleNames(target);
  69             boolean jreSupportsTarget = jreimplloc.contains(target);
  70 
  71             for (Locale test: testloc) {
  72                 // codes
  73                 String lang = test.getLanguage();
  74                 String ctry = test.getCountry();
  75                 String vrnt = test.getVariant();
  76 
  77                 // the localized name
  78                 String langresult = test.getDisplayLanguage(target);
  79                 String ctryresult = test.getDisplayCountry(target);
  80                 String vrntresult = test.getDisplayVariant(target);


 120                     jreSupportsTarget && jresvrnt != null);
 121             }
 122         }
 123     }
 124 
 125     void variantFallbackTest() {
 126         Locale YY = new Locale("yy", "YY", "YYYY");
 127         Locale YY_suffix = new Locale("yy", "YY", "YYYY_suffix");
 128         String retVrnt = null;
 129         String message = "variantFallbackTest() succeeded.";
 130 
 131 
 132         try {
 133             YY.getDisplayVariant(YY_suffix);
 134             message = "variantFallbackTest() failed. Either provider wasn't invoked, or invoked without suffix.";
 135         } catch (RuntimeException re) {
 136             retVrnt = re.getMessage();
 137             if (YY_suffix.getVariant().equals(retVrnt)) {
 138                 System.out.println(message);
 139                 return;
 140             }
 141             message = "variantFallbackTest() failed. Returned variant: "+retVrnt;
 142         }
 143 
 144         throw new RuntimeException(message);
 145     }
 146 }
< prev index next >