1 /* 2 * @test 3 * @bug 4351212 4 * @summary Verify that new getLCIDFromLocale method works 5 */ 6 7 import java.lang.reflect.Method; 8 import java.util.Locale; 9 10 public class GetLCIDFromLocale { 11 12 static Method getLCIDMethod = null; 13 public static void main(String args[]) { 14 try { 15 Class ttClass = Class.forName("sun.font.TrueTypeFont"); 16 getLCIDMethod = 17 ttClass.getDeclaredMethod("getLCIDFromLocale", 18 java.util.Locale.class); 19 getLCIDMethod.setAccessible(true); // its private 20 } catch (Exception e) { 21 e.printStackTrace(); 22 throw new RuntimeException("Reflection failed"); 23 } 24 if (getLCIDMethod == null) { 25 throw new RuntimeException("No method found"); 26 } 27 28 test(Locale.US, 0x0409); 29 test(Locale.GERMAN, 0x0407); 30 test(Locale.GERMANY, 0x0407); 31 test(new Locale("de", "AT"), 0x0c07); 32 test(new Locale("ar"), 0x0401); 33 test(new Locale("ar", "SA"), 0x0401); 34 test(new Locale("ar", "EG"), 0x0c01); 35 test(new Locale("??"), 0x0409); 36 test(new Locale("??", "??"), 0x0409); 37 test(Locale.KOREA, 0x0412); 38 } 39 40 private static void test(Locale locale, int expectedLCID) { 41 try { 42 short lcid = (Short)getLCIDMethod.invoke(null, locale); 43 System.out.println("lcid="+lcid+" expected="+expectedLCID); 44 if (lcid != expectedLCID) { 45 throw new RuntimeException(); 46 } 47 } catch (Exception e) { 48 e.printStackTrace(); 49 throw new RuntimeException("Method invocation exception"); 50 } 51 } 52 }