libcore
Revision | 9cca6a44c922649806cb8a79efc5f615f97e30a1 (tree) |
---|---|
Time | 2011-06-08 04:04:20 |
Author | Jean-Baptiste Queru <jbq@goog...> |
Commiter | Android Code Review |
Merge "Skip tests if it includes unsupported locale/charset" into gingerbread
@@ -423,14 +423,14 @@ public class InputStreamReaderTest extends TestCase { | ||
423 | 423 | "tests/api/java/io/testfile.txt"); |
424 | 424 | try { |
425 | 425 | reader = new InputStreamReader(in, "gb18030"); |
426 | + while ((c = reader.read()) != -1) { | |
427 | + sb.append((char) c); | |
428 | + } | |
429 | + assertEquals(source, sb.toString()); | |
426 | 430 | } catch (UnsupportedEncodingException e) { |
427 | 431 | System.out |
428 | 432 | .println("GB18030 is not supported, abort test InputStreamReaderTest.testSpecialCharsetReading()."); |
429 | 433 | } |
430 | - while ((c = reader.read()) != -1) { | |
431 | - sb.append((char) c); | |
432 | - } | |
433 | - assertEquals(source, sb.toString()); | |
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -17,6 +17,7 @@ | ||
17 | 17 | package org.apache.harmony.luni.tests.java.lang; |
18 | 18 | |
19 | 19 | import java.io.Serializable; |
20 | +import java.nio.charset.Charset; | |
20 | 21 | |
21 | 22 | import junit.framework.TestCase; |
22 | 23 |
@@ -97,10 +98,12 @@ public class StringBufferTest extends TestCase { | ||
97 | 98 | |
98 | 99 | buffer.append("abcde"); |
99 | 100 | assertEquals("abcde", buffer.toString()); |
100 | - buffer.setLength(1000); | |
101 | - byte[] bytes = buffer.toString().getBytes("GB18030"); | |
102 | - for (int i = 5; i < bytes.length; i++) { | |
103 | - assertEquals(0, bytes[i]); | |
101 | + if (Charset.isSupported("GB18030")) { | |
102 | + buffer.setLength(1000); | |
103 | + byte[] bytes = buffer.toString().getBytes("GB18030"); | |
104 | + for (int i = 5; i < bytes.length; i++) { | |
105 | + assertEquals(0, bytes[i]); | |
106 | + } | |
104 | 107 | } |
105 | 108 | |
106 | 109 | buffer.setLength(5); |
@@ -19,7 +19,7 @@ package org.apache.harmony.luni.tests.java.lang; | ||
19 | 19 | |
20 | 20 | import java.io.Serializable; |
21 | 21 | import java.util.Arrays; |
22 | - | |
22 | +import java.nio.charset.Charset; | |
23 | 23 | import junit.framework.TestCase; |
24 | 24 | |
25 | 25 | import org.apache.harmony.testframework.serialization.SerializationTest; |
@@ -1912,10 +1912,12 @@ public class StringBuilderTest extends TestCase { | ||
1912 | 1912 | sb.setLength(0); |
1913 | 1913 | sb.append("abcde"); |
1914 | 1914 | assertEquals("abcde", sb.toString()); |
1915 | - sb.setLength(1000); | |
1916 | - byte[] bytes = sb.toString().getBytes("GB18030"); | |
1917 | - for (int i = 5; i < bytes.length; i++) { | |
1918 | - assertEquals(0, bytes[i]); | |
1915 | + if (Charset.isSupported("GB18030")) { | |
1916 | + sb.setLength(1000); | |
1917 | + byte[] bytes = sb.toString().getBytes("GB18030"); | |
1918 | + for (int i = 5; i < bytes.length; i++) { | |
1919 | + assertEquals(0, bytes[i]); | |
1920 | + } | |
1919 | 1921 | } |
1920 | 1922 | |
1921 | 1923 | sb.setLength(5); |
@@ -29,6 +29,8 @@ import java.util.TimeZone; | ||
29 | 29 | |
30 | 30 | import org.apache.harmony.testframework.serialization.SerializationTest; |
31 | 31 | |
32 | +import tests.support.Support_Locale; | |
33 | + | |
32 | 34 | public class CalendarTest extends junit.framework.TestCase { |
33 | 35 | |
34 | 36 | Locale defaultLocale; |
@@ -653,12 +655,16 @@ public class CalendarTest extends junit.framework.TestCase { | ||
653 | 655 | */ |
654 | 656 | public void test_getInstance() { |
655 | 657 | // test getInstance(Locale) |
656 | - Calendar us_calendar = Calendar.getInstance(Locale.US); | |
657 | - Calendar ch_calendar = Calendar.getInstance(Locale.CHINESE); | |
658 | - assertEquals(Calendar.SUNDAY, us_calendar | |
659 | - .getFirstDayOfWeek()); | |
660 | - assertEquals(Calendar.MONDAY, ch_calendar | |
661 | - .getFirstDayOfWeek()); | |
658 | + if (Support_Locale.areLocalesAvailable(Locale.US)) { | |
659 | + Calendar us_calendar = Calendar.getInstance(Locale.US); | |
660 | + assertEquals(Calendar.SUNDAY, us_calendar | |
661 | + .getFirstDayOfWeek()); | |
662 | + } | |
663 | + if (Support_Locale.areLocalesAvailable(Locale.CHINESE)) { | |
664 | + Calendar ch_calendar = Calendar.getInstance(Locale.CHINESE); | |
665 | + assertEquals(Calendar.MONDAY, ch_calendar | |
666 | + .getFirstDayOfWeek()); | |
667 | + } | |
662 | 668 | |
663 | 669 | // test getInstance(Locale, TimeZone) |
664 | 670 | Calendar gmt_calendar = Calendar.getInstance(TimeZone |
@@ -1901,34 +1901,40 @@ public class ScannerTest extends TestCase { | ||
1901 | 1901 | * Different locale can only recognize corresponding locale sensitive |
1902 | 1902 | * string. ',' is used in many locales as group separator. |
1903 | 1903 | */ |
1904 | - s = new Scanner("23,456 23,456"); | |
1905 | - s.useLocale(Locale.GERMANY); | |
1906 | - try { | |
1907 | - s.nextBigInteger(10); | |
1908 | - fail("Should throw InputMismatchException"); | |
1909 | - } catch (InputMismatchException e) { | |
1910 | - // Expected | |
1904 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
1905 | + s = new Scanner("23,456 23,456"); | |
1906 | + s.useLocale(Locale.GERMANY); | |
1907 | + try { | |
1908 | + s.nextBigInteger(10); | |
1909 | + fail("Should throw InputMismatchException"); | |
1910 | + } catch (InputMismatchException e) { | |
1911 | + // Expected | |
1912 | + } | |
1913 | + s.useLocale(Locale.ENGLISH); | |
1914 | + // If exception is thrown out, input will not be advanced. | |
1915 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1916 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1911 | 1917 | } |
1912 | - s.useLocale(Locale.ENGLISH); | |
1913 | - // If exception is thrown out, input will not be advanced. | |
1914 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1915 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1916 | 1918 | |
1917 | 1919 | /* |
1918 | 1920 | * ''' is used in many locales as group separator. |
1919 | 1921 | */ |
1920 | - s = new Scanner("23'456 23'456"); | |
1921 | - s.useLocale(Locale.GERMANY); | |
1922 | - try { | |
1923 | - s.nextBigInteger(10); | |
1924 | - fail("Should throw InputMismatchException"); | |
1925 | - } catch (InputMismatchException e) { | |
1926 | - // Expected | |
1922 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
1923 | + s = new Scanner("23'456 23'456"); | |
1924 | + s.useLocale(Locale.GERMANY); | |
1925 | + try { | |
1926 | + s.nextBigInteger(10); | |
1927 | + fail("Should throw InputMismatchException"); | |
1928 | + } catch (InputMismatchException e) { | |
1929 | + // Expected | |
1930 | + } | |
1931 | + } | |
1932 | + if (Support_Locale.areLocalesAvailable(new Locale[] { new Locale("de", "CH") })) { | |
1933 | + s.useLocale(new Locale("de", "CH")); | |
1934 | + // If exception is thrown out, input will not be advanced. | |
1935 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1936 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1927 | 1937 | } |
1928 | - s.useLocale(new Locale("de", "CH")); | |
1929 | - // If exception is thrown out, input will not be advanced. | |
1930 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1931 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1932 | 1938 | |
1933 | 1939 | /* |
1934 | 1940 | * The input string has Arabic-Indic digits. |
@@ -1947,18 +1953,22 @@ public class ScannerTest extends TestCase { | ||
1947 | 1953 | * '.' is used in many locales as group separator. The input string |
1948 | 1954 | * has Arabic-Indic digits . |
1949 | 1955 | */ |
1950 | - s = new Scanner("23.45\u0666 23.456"); | |
1951 | - s.useLocale(Locale.CHINESE); | |
1952 | - try { | |
1953 | - s.nextBigInteger(10); | |
1954 | - fail("Should throw InputMismatchException"); | |
1955 | - } catch (InputMismatchException e) { | |
1956 | - // Expected | |
1956 | + if (Support_Locale.areLocalesAvailable(Locale.CHINESE)) { | |
1957 | + s = new Scanner("23.45\u0666 23.456"); | |
1958 | + s.useLocale(Locale.CHINESE); | |
1959 | + try { | |
1960 | + s.nextBigInteger(10); | |
1961 | + fail("Should throw InputMismatchException"); | |
1962 | + } catch (InputMismatchException e) { | |
1963 | + // Expected | |
1964 | + } | |
1965 | + } | |
1966 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
1967 | + s.useLocale(Locale.GERMANY); | |
1968 | + // If exception is thrown out, input will not be advanced. | |
1969 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1970 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1957 | 1971 | } |
1958 | - s.useLocale(Locale.GERMANY); | |
1959 | - // If exception is thrown out, input will not be advanced. | |
1960 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1961 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
1962 | 1972 | |
1963 | 1973 | // The input string starts with zero |
1964 | 1974 | s = new Scanner("03,456"); |
@@ -1984,26 +1994,32 @@ public class ScannerTest extends TestCase { | ||
1984 | 1994 | * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50' |
1985 | 1995 | * respectively, but they are not differentiated. |
1986 | 1996 | */ |
1987 | - s = new Scanner("12300"); | |
1988 | - s.useLocale(Locale.CHINESE); | |
1989 | - assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
1997 | + if (Support_Locale.areLocalesAvailable(Locale.CHINESE)) { | |
1998 | + s = new Scanner("12300"); | |
1999 | + s.useLocale(Locale.CHINESE); | |
2000 | + assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
1990 | 2001 | |
1991 | - s = new Scanner("123\u0966\u0966"); | |
1992 | - s.useLocale(Locale.CHINESE); | |
1993 | - assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
2002 | + s = new Scanner("123\u0966\u0966"); | |
2003 | + s.useLocale(Locale.CHINESE); | |
2004 | + assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
1994 | 2005 | |
1995 | - s = new Scanner("123\u0e50\u0e50"); | |
1996 | - s.useLocale(Locale.CHINESE); | |
1997 | - assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
2006 | + s = new Scanner("123\u0e50\u0e50"); | |
2007 | + s.useLocale(Locale.CHINESE); | |
2008 | + assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
2009 | + } | |
1998 | 2010 | |
1999 | - s = new Scanner("-123"); | |
2000 | - s.useLocale(new Locale("ar", "AE")); | |
2001 | - assertEquals(new BigInteger("-123"), s.nextBigInteger(10)); | |
2011 | + if (Support_Locale.areLocalesAvailable(new Locale[] {new Locale("ar", "AE")})) { | |
2012 | + s = new Scanner("-123"); | |
2013 | + s.useLocale(new Locale("ar", "AE")); | |
2014 | + assertEquals(new BigInteger("-123"), s.nextBigInteger(10)); | |
2015 | + } | |
2002 | 2016 | |
2003 | 2017 | |
2004 | - s = new Scanner("-123"); | |
2005 | - s.useLocale(new Locale("mk", "MK")); | |
2006 | - assertEquals(new BigInteger("-123"), s.nextBigInteger(10)); | |
2018 | + if (Support_Locale.areLocalesAvailable(new Locale[] { new Locale("mk", "MK")})) { | |
2019 | + s = new Scanner("-123"); | |
2020 | + s.useLocale(new Locale("mk", "MK")); | |
2021 | + assertEquals(new BigInteger("-123"), s.nextBigInteger(10)); | |
2022 | + } | |
2007 | 2023 | |
2008 | 2024 | s.close(); |
2009 | 2025 | try { |
@@ -2050,34 +2066,40 @@ public class ScannerTest extends TestCase { | ||
2050 | 2066 | * Different locale can only recognize corresponding locale sensitive |
2051 | 2067 | * string. ',' is used in many locales as group separator. |
2052 | 2068 | */ |
2053 | - s = new Scanner("23,456 23,456"); | |
2054 | - s.useLocale(Locale.GERMANY); | |
2055 | - try { | |
2056 | - s.nextBigInteger(); | |
2057 | - fail("Should throw InputMismatchException"); | |
2058 | - } catch (InputMismatchException e) { | |
2059 | - // Expected | |
2069 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
2070 | + s = new Scanner("23,456 23,456"); | |
2071 | + s.useLocale(Locale.GERMANY); | |
2072 | + try { | |
2073 | + s.nextBigInteger(); | |
2074 | + fail("Should throw InputMismatchException"); | |
2075 | + } catch (InputMismatchException e) { | |
2076 | + // Expected | |
2077 | + } | |
2078 | + s.useLocale(Locale.ENGLISH); | |
2079 | + // If exception is thrown out, input will not be advanced. | |
2080 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2081 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2060 | 2082 | } |
2061 | - s.useLocale(Locale.ENGLISH); | |
2062 | - // If exception is thrown out, input will not be advanced. | |
2063 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2064 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2065 | 2083 | |
2066 | 2084 | /* |
2067 | 2085 | * ''' is used in many locales as group separator. |
2068 | 2086 | */ |
2069 | - s = new Scanner("23'456 23'456"); | |
2070 | - s.useLocale(Locale.GERMANY); | |
2071 | - try { | |
2072 | - s.nextBigInteger(); | |
2073 | - fail("Should throw InputMismatchException"); | |
2074 | - } catch (InputMismatchException e) { | |
2075 | - // Expected | |
2087 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
2088 | + s = new Scanner("23'456 23'456"); | |
2089 | + s.useLocale(Locale.GERMANY); | |
2090 | + try { | |
2091 | + s.nextBigInteger(); | |
2092 | + fail("Should throw InputMismatchException"); | |
2093 | + } catch (InputMismatchException e) { | |
2094 | + // Expected | |
2095 | + } | |
2096 | + } | |
2097 | + if (Support_Locale.areLocalesAvailable(new Locale[] {new Locale("de", "CH")})) { | |
2098 | + s.useLocale(new Locale("de", "CH")); | |
2099 | + // If exception is thrown out, input will not be advanced. | |
2100 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2101 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2076 | 2102 | } |
2077 | - s.useLocale(new Locale("de", "CH")); | |
2078 | - // If exception is thrown out, input will not be advanced. | |
2079 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2080 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2081 | 2103 | |
2082 | 2104 | /* |
2083 | 2105 | * The input string has Arabic-Indic digits. |
@@ -2098,18 +2120,22 @@ public class ScannerTest extends TestCase { | ||
2098 | 2120 | * '.' is used in many locales as group separator. The input string |
2099 | 2121 | * has Arabic-Indic digits . |
2100 | 2122 | */ |
2101 | - s = new Scanner("23.45\u0666 23.456"); | |
2102 | - s.useLocale(Locale.CHINESE); | |
2103 | - try { | |
2104 | - s.nextBigInteger(); | |
2105 | - fail("Should throw InputMismatchException"); | |
2106 | - } catch (InputMismatchException e) { | |
2107 | - // Expected | |
2123 | + if (Support_Locale.areLocalesAvailable(Locale.CHINESE)) { | |
2124 | + s = new Scanner("23.45\u0666 23.456"); | |
2125 | + s.useLocale(Locale.CHINESE); | |
2126 | + try { | |
2127 | + s.nextBigInteger(); | |
2128 | + fail("Should throw InputMismatchException"); | |
2129 | + } catch (InputMismatchException e) { | |
2130 | + // Expected | |
2131 | + } | |
2132 | + } | |
2133 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
2134 | + s.useLocale(Locale.GERMANY); | |
2135 | + // If exception is thrown out, input will not be advanced. | |
2136 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2137 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2108 | 2138 | } |
2109 | - s.useLocale(Locale.GERMANY); | |
2110 | - // If exception is thrown out, input will not be advanced. | |
2111 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2112 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
2113 | 2139 | |
2114 | 2140 | // The input string starts with zero |
2115 | 2141 | s = new Scanner("03,456"); |
@@ -2136,25 +2162,31 @@ public class ScannerTest extends TestCase { | ||
2136 | 2162 | * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50' |
2137 | 2163 | * respectively, but they are not differentiated. |
2138 | 2164 | */ |
2139 | - s = new Scanner("12300"); | |
2140 | - s.useLocale(Locale.CHINESE); | |
2141 | - assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
2165 | + if (Support_Locale.areLocalesAvailable(Locale.CHINESE)) { | |
2166 | + s = new Scanner("12300"); | |
2167 | + s.useLocale(Locale.CHINESE); | |
2168 | + assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
2142 | 2169 | |
2143 | - s = new Scanner("123\u0966\u0966"); | |
2144 | - s.useLocale(Locale.CHINESE); | |
2145 | - assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
2170 | + s = new Scanner("123\u0966\u0966"); | |
2171 | + s.useLocale(Locale.CHINESE); | |
2172 | + assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
2146 | 2173 | |
2147 | - s = new Scanner("123\u0e50\u0e50"); | |
2148 | - s.useLocale(Locale.CHINESE); | |
2149 | - assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
2174 | + s = new Scanner("123\u0e50\u0e50"); | |
2175 | + s.useLocale(Locale.CHINESE); | |
2176 | + assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
2177 | + } | |
2150 | 2178 | |
2151 | - s = new Scanner("-123"); | |
2152 | - s.useLocale(new Locale("ar", "AE")); | |
2153 | - assertEquals(new BigInteger("-123"), s.nextBigInteger()); | |
2179 | + if (Support_Locale.areLocalesAvailable(new Locale[] {new Locale("ar", "AE")})) { | |
2180 | + s = new Scanner("-123"); | |
2181 | + s.useLocale(new Locale("ar", "AE")); | |
2182 | + assertEquals(new BigInteger("-123"), s.nextBigInteger()); | |
2183 | + } | |
2154 | 2184 | |
2155 | - s = new Scanner("-123"); | |
2156 | - s.useLocale(new Locale("mk", "MK")); | |
2157 | - assertEquals(new BigInteger("-123"), s.nextBigInteger()); | |
2185 | + if (Support_Locale.areLocalesAvailable(new Locale[] {new Locale("mk", "MK")})) { | |
2186 | + s = new Scanner("-123"); | |
2187 | + s.useLocale(new Locale("mk", "MK")); | |
2188 | + assertEquals(new BigInteger("-123"), s.nextBigInteger()); | |
2189 | + } | |
2158 | 2190 | |
2159 | 2191 | s.close(); |
2160 | 2192 | try { |
@@ -3412,40 +3444,46 @@ public class ScannerTest extends TestCase { | ||
3412 | 3444 | * Different locale can only recognize corresponding locale sensitive |
3413 | 3445 | * string. ',' is used in many locales as group separator. |
3414 | 3446 | */ |
3415 | - s = new Scanner("23,456 23,456"); | |
3416 | - s.useLocale(Locale.GERMANY); | |
3417 | - assertFalse(s.hasNextBigInteger(10)); | |
3418 | - try { | |
3419 | - s.nextBigInteger(10); | |
3420 | - fail("Should throw InputMismatchException"); | |
3421 | - } catch (InputMismatchException e) { | |
3422 | - // Expected | |
3447 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
3448 | + s = new Scanner("23,456 23,456"); | |
3449 | + s.useLocale(Locale.GERMANY); | |
3450 | + assertFalse(s.hasNextBigInteger(10)); | |
3451 | + try { | |
3452 | + s.nextBigInteger(10); | |
3453 | + fail("Should throw InputMismatchException"); | |
3454 | + } catch (InputMismatchException e) { | |
3455 | + // Expected | |
3456 | + } | |
3457 | + s.useLocale(Locale.ENGLISH); | |
3458 | + // If exception is thrown out, input will not be advanced. | |
3459 | + assertTrue(s.hasNextBigInteger(10)); | |
3460 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3461 | + assertTrue(s.hasNextBigInteger(10)); | |
3462 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3423 | 3463 | } |
3424 | - s.useLocale(Locale.ENGLISH); | |
3425 | - // If exception is thrown out, input will not be advanced. | |
3426 | - assertTrue(s.hasNextBigInteger(10)); | |
3427 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3428 | - assertTrue(s.hasNextBigInteger(10)); | |
3429 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3430 | 3464 | |
3431 | 3465 | /* |
3432 | 3466 | * ''' is used in many locales as group separator. |
3433 | 3467 | */ |
3434 | - s = new Scanner("23'456 23'456"); | |
3435 | - s.useLocale(Locale.GERMANY); | |
3436 | - assertFalse(s.hasNextBigInteger(10)); | |
3437 | - try { | |
3438 | - s.nextBigInteger(10); | |
3439 | - fail("Should throw InputMismatchException"); | |
3440 | - } catch (InputMismatchException e) { | |
3441 | - // Expected | |
3468 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
3469 | + s = new Scanner("23'456 23'456"); | |
3470 | + s.useLocale(Locale.GERMANY); | |
3471 | + assertFalse(s.hasNextBigInteger(10)); | |
3472 | + try { | |
3473 | + s.nextBigInteger(10); | |
3474 | + fail("Should throw InputMismatchException"); | |
3475 | + } catch (InputMismatchException e) { | |
3476 | + // Expected | |
3477 | + } | |
3478 | + } | |
3479 | + if (Support_Locale.areLocalesAvailable(new Locale[] {new Locale("de", "CH")})) { | |
3480 | + s.useLocale(new Locale("de", "CH")); | |
3481 | + // If exception is thrown out, input will not be advanced. | |
3482 | + assertTrue(s.hasNextBigInteger(10)); | |
3483 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3484 | + assertTrue(s.hasNextBigInteger(10)); | |
3485 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3442 | 3486 | } |
3443 | - s.useLocale(new Locale("de", "CH")); | |
3444 | - // If exception is thrown out, input will not be advanced. | |
3445 | - assertTrue(s.hasNextBigInteger(10)); | |
3446 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3447 | - assertTrue(s.hasNextBigInteger(10)); | |
3448 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3449 | 3487 | |
3450 | 3488 | /* |
3451 | 3489 | * The input string has Arabic-Indic digits. |
@@ -3467,21 +3505,25 @@ public class ScannerTest extends TestCase { | ||
3467 | 3505 | * '.' is used in many locales as group separator. The input string |
3468 | 3506 | * has Arabic-Indic digits . |
3469 | 3507 | */ |
3470 | - s = new Scanner("23.45\u0666 23.456"); | |
3471 | - s.useLocale(Locale.CHINESE); | |
3472 | - assertFalse(s.hasNextBigInteger(10)); | |
3473 | - try { | |
3474 | - s.nextBigInteger(10); | |
3475 | - fail("Should throw InputMismatchException"); | |
3476 | - } catch (InputMismatchException e) { | |
3477 | - // Expected | |
3508 | + if (Support_Locale.areLocalesAvailable(Locale.CHINESE)) { | |
3509 | + s = new Scanner("23.45\u0666 23.456"); | |
3510 | + s.useLocale(Locale.CHINESE); | |
3511 | + assertFalse(s.hasNextBigInteger(10)); | |
3512 | + try { | |
3513 | + s.nextBigInteger(10); | |
3514 | + fail("Should throw InputMismatchException"); | |
3515 | + } catch (InputMismatchException e) { | |
3516 | + // Expected | |
3517 | + } | |
3518 | + } | |
3519 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
3520 | + s.useLocale(Locale.GERMANY); | |
3521 | + // If exception is thrown out, input will not be advanced. | |
3522 | + assertTrue(s.hasNextBigInteger(10)); | |
3523 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3524 | + assertTrue(s.hasNextBigInteger(10)); | |
3525 | + assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3478 | 3526 | } |
3479 | - s.useLocale(Locale.GERMANY); | |
3480 | - // If exception is thrown out, input will not be advanced. | |
3481 | - assertTrue(s.hasNextBigInteger(10)); | |
3482 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3483 | - assertTrue(s.hasNextBigInteger(10)); | |
3484 | - assertEquals(new BigInteger("23456"), s.nextBigInteger(10)); | |
3485 | 3527 | |
3486 | 3528 | // The input string starts with zero |
3487 | 3529 | s = new Scanner("03,456"); |
@@ -3511,31 +3553,37 @@ public class ScannerTest extends TestCase { | ||
3511 | 3553 | * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50' |
3512 | 3554 | * respectively, but they are not differentiated. |
3513 | 3555 | */ |
3514 | - s = new Scanner("12300"); | |
3515 | - s.useLocale(Locale.CHINESE); | |
3516 | - assertTrue(s.hasNextBigInteger(10)); | |
3517 | - assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
3556 | + if (Support_Locale.areLocalesAvailable(Locale.CHINESE)) { | |
3557 | + s = new Scanner("12300"); | |
3558 | + s.useLocale(Locale.CHINESE); | |
3559 | + assertTrue(s.hasNextBigInteger(10)); | |
3560 | + assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
3518 | 3561 | |
3519 | - s = new Scanner("123\u0966\u0966"); | |
3520 | - s.useLocale(Locale.CHINESE); | |
3521 | - assertTrue(s.hasNextBigInteger(10)); | |
3522 | - assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
3562 | + s = new Scanner("123\u0966\u0966"); | |
3563 | + s.useLocale(Locale.CHINESE); | |
3564 | + assertTrue(s.hasNextBigInteger(10)); | |
3565 | + assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
3523 | 3566 | |
3524 | - s = new Scanner("123\u0e50\u0e50"); | |
3525 | - s.useLocale(Locale.CHINESE); | |
3526 | - assertTrue(s.hasNextBigInteger(10)); | |
3527 | - assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
3567 | + s = new Scanner("123\u0e50\u0e50"); | |
3568 | + s.useLocale(Locale.CHINESE); | |
3569 | + assertTrue(s.hasNextBigInteger(10)); | |
3570 | + assertEquals(new BigInteger("12300"), s.nextBigInteger(10)); | |
3571 | + } | |
3528 | 3572 | |
3529 | - s = new Scanner("-123"); | |
3530 | - s.useLocale(new Locale("ar", "AE")); | |
3531 | - assertTrue(s.hasNextBigInteger(10)); | |
3532 | - assertEquals(new BigInteger("-123"), s.nextBigInteger(10)); | |
3573 | + if (Support_Locale.areLocalesAvailable(new Locale[] {new Locale("ar", "AE")})) { | |
3574 | + s = new Scanner("-123"); | |
3575 | + s.useLocale(new Locale("ar", "AE")); | |
3576 | + assertTrue(s.hasNextBigInteger(10)); | |
3577 | + assertEquals(new BigInteger("-123"), s.nextBigInteger(10)); | |
3578 | + } | |
3533 | 3579 | |
3534 | 3580 | |
3535 | - s = new Scanner("-123"); | |
3536 | - s.useLocale(new Locale("mk", "MK")); | |
3537 | - assertTrue(s.hasNextBigInteger(10)); | |
3538 | - assertEquals(new BigInteger("-123"), s.nextBigInteger(10)); | |
3581 | + if (Support_Locale.areLocalesAvailable(new Locale[] { new Locale("mk", "MK")})) { | |
3582 | + s = new Scanner("-123"); | |
3583 | + s.useLocale(new Locale("mk", "MK")); | |
3584 | + assertTrue(s.hasNextBigInteger(10)); | |
3585 | + assertEquals(new BigInteger("-123"), s.nextBigInteger(10)); | |
3586 | + } | |
3539 | 3587 | } |
3540 | 3588 | |
3541 | 3589 | /** |
@@ -3618,40 +3666,46 @@ public class ScannerTest extends TestCase { | ||
3618 | 3666 | * Different locale can only recognize corresponding locale sensitive |
3619 | 3667 | * string. ',' is used in many locales as group separator. |
3620 | 3668 | */ |
3621 | - s = new Scanner("23,456 23,456"); | |
3622 | - s.useLocale(Locale.GERMANY); | |
3623 | - assertFalse(s.hasNextBigInteger()); | |
3624 | - try { | |
3625 | - s.nextBigInteger(); | |
3626 | - fail("Should throw InputMismatchException"); | |
3627 | - } catch (InputMismatchException e) { | |
3628 | - // Expected | |
3669 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
3670 | + s = new Scanner("23,456 23,456"); | |
3671 | + s.useLocale(Locale.GERMANY); | |
3672 | + assertFalse(s.hasNextBigInteger()); | |
3673 | + try { | |
3674 | + s.nextBigInteger(); | |
3675 | + fail("Should throw InputMismatchException"); | |
3676 | + } catch (InputMismatchException e) { | |
3677 | + // Expected | |
3678 | + } | |
3679 | + s.useLocale(Locale.ENGLISH); | |
3680 | + // If exception is thrown out, input will not be advanced. | |
3681 | + assertTrue(s.hasNextBigInteger()); | |
3682 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3683 | + assertTrue(s.hasNextBigInteger()); | |
3684 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3629 | 3685 | } |
3630 | - s.useLocale(Locale.ENGLISH); | |
3631 | - // If exception is thrown out, input will not be advanced. | |
3632 | - assertTrue(s.hasNextBigInteger()); | |
3633 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3634 | - assertTrue(s.hasNextBigInteger()); | |
3635 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3636 | 3686 | |
3637 | 3687 | /* |
3638 | 3688 | * ''' is used in many locales as group separator. |
3639 | 3689 | */ |
3640 | - s = new Scanner("23'456 23'456"); | |
3641 | - s.useLocale(Locale.GERMANY); | |
3642 | - assertFalse(s.hasNextBigInteger()); | |
3643 | - try { | |
3644 | - s.nextBigInteger(); | |
3645 | - fail("Should throw InputMismatchException"); | |
3646 | - } catch (InputMismatchException e) { | |
3647 | - // Expected | |
3690 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
3691 | + s = new Scanner("23'456 23'456"); | |
3692 | + s.useLocale(Locale.GERMANY); | |
3693 | + assertFalse(s.hasNextBigInteger()); | |
3694 | + try { | |
3695 | + s.nextBigInteger(); | |
3696 | + fail("Should throw InputMismatchException"); | |
3697 | + } catch (InputMismatchException e) { | |
3698 | + // Expected | |
3699 | + } | |
3700 | + } | |
3701 | + if (Support_Locale.areLocalesAvailable(new Locale[] { new Locale("de", "CH")})) { | |
3702 | + s.useLocale(new Locale("de", "CH")); | |
3703 | + // If exception is thrown out, input will not be advanced. | |
3704 | + assertTrue(s.hasNextBigInteger()); | |
3705 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3706 | + assertTrue(s.hasNextBigInteger()); | |
3707 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3648 | 3708 | } |
3649 | - s.useLocale(new Locale("de", "CH")); | |
3650 | - // If exception is thrown out, input will not be advanced. | |
3651 | - assertTrue(s.hasNextBigInteger()); | |
3652 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3653 | - assertTrue(s.hasNextBigInteger()); | |
3654 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3655 | 3709 | |
3656 | 3710 | /* |
3657 | 3711 | * The input string has Arabic-Indic digits. |
@@ -3674,21 +3728,25 @@ public class ScannerTest extends TestCase { | ||
3674 | 3728 | * '.' is used in many locales as group separator. The input string |
3675 | 3729 | * has Arabic-Indic digits . |
3676 | 3730 | */ |
3677 | - s = new Scanner("23.45\u0666 23.456"); | |
3678 | - s.useLocale(Locale.CHINESE); | |
3679 | - assertFalse(s.hasNextBigInteger()); | |
3680 | - try { | |
3681 | - s.nextBigInteger(); | |
3682 | - fail("Should throw InputMismatchException"); | |
3683 | - } catch (InputMismatchException e) { | |
3684 | - // Expected | |
3731 | + if (Support_Locale.areLocalesAvailable(Locale.CHINESE)) { | |
3732 | + s = new Scanner("23.45\u0666 23.456"); | |
3733 | + s.useLocale(Locale.CHINESE); | |
3734 | + assertFalse(s.hasNextBigInteger()); | |
3735 | + try { | |
3736 | + s.nextBigInteger(); | |
3737 | + fail("Should throw InputMismatchException"); | |
3738 | + } catch (InputMismatchException e) { | |
3739 | + // Expected | |
3740 | + } | |
3741 | + } | |
3742 | + if (Support_Locale.areLocalesAvailable(Locale.GERMANY)) { | |
3743 | + s.useLocale(Locale.GERMANY); | |
3744 | + // If exception is thrown out, input will not be advanced. | |
3745 | + assertTrue(s.hasNextBigInteger()); | |
3746 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3747 | + assertTrue(s.hasNextBigInteger()); | |
3748 | + assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3685 | 3749 | } |
3686 | - s.useLocale(Locale.GERMANY); | |
3687 | - // If exception is thrown out, input will not be advanced. | |
3688 | - assertTrue(s.hasNextBigInteger()); | |
3689 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3690 | - assertTrue(s.hasNextBigInteger()); | |
3691 | - assertEquals(new BigInteger("23456"), s.nextBigInteger()); | |
3692 | 3750 | |
3693 | 3751 | // The input string starts with zero |
3694 | 3752 | s = new Scanner("03,456"); |
@@ -3719,30 +3777,36 @@ public class ScannerTest extends TestCase { | ||
3719 | 3777 | * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50' |
3720 | 3778 | * respectively, but they are not differentiated. |
3721 | 3779 | */ |
3722 | - s = new Scanner("12300"); | |
3723 | - s.useLocale(Locale.CHINESE); | |
3724 | - assertTrue(s.hasNextBigInteger()); | |
3725 | - assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
3780 | + if (Support_Locale.areLocalesAvailable(Locale.CHINESE)) { | |
3781 | + s = new Scanner("12300"); | |
3782 | + s.useLocale(Locale.CHINESE); | |
3783 | + assertTrue(s.hasNextBigInteger()); | |
3784 | + assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
3726 | 3785 | |
3727 | - s = new Scanner("123\u0966\u0966"); | |
3728 | - s.useLocale(Locale.CHINESE); | |
3729 | - assertTrue(s.hasNextBigInteger()); | |
3730 | - assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
3786 | + s = new Scanner("123\u0966\u0966"); | |
3787 | + s.useLocale(Locale.CHINESE); | |
3788 | + assertTrue(s.hasNextBigInteger()); | |
3789 | + assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
3731 | 3790 | |
3732 | - s = new Scanner("123\u0e50\u0e50"); | |
3733 | - s.useLocale(Locale.CHINESE); | |
3734 | - assertTrue(s.hasNextBigInteger()); | |
3735 | - assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
3791 | + s = new Scanner("123\u0e50\u0e50"); | |
3792 | + s.useLocale(Locale.CHINESE); | |
3793 | + assertTrue(s.hasNextBigInteger()); | |
3794 | + assertEquals(new BigInteger("12300"), s.nextBigInteger()); | |
3795 | + } | |
3736 | 3796 | |
3737 | - s = new Scanner("-123"); | |
3738 | - s.useLocale(new Locale("ar", "AE")); | |
3739 | - assertTrue(s.hasNextBigInteger()); | |
3740 | - assertEquals(new BigInteger("-123"), s.nextBigInteger()); | |
3797 | + if (Support_Locale.areLocalesAvailable(new Locale[] {new Locale("ar", "AE")})) { | |
3798 | + s = new Scanner("-123"); | |
3799 | + s.useLocale(new Locale("ar", "AE")); | |
3800 | + assertTrue(s.hasNextBigInteger()); | |
3801 | + assertEquals(new BigInteger("-123"), s.nextBigInteger()); | |
3802 | + } | |
3741 | 3803 | |
3742 | - s = new Scanner("-123"); | |
3743 | - s.useLocale(new Locale("mk", "MK")); | |
3744 | - assertTrue(s.hasNextBigInteger()); | |
3745 | - assertEquals(new BigInteger("-123"), s.nextBigInteger()); | |
3804 | + if (Support_Locale.areLocalesAvailable(new Locale[] { new Locale("mk", "MK")})) { | |
3805 | + s = new Scanner("-123"); | |
3806 | + s.useLocale(new Locale("mk", "MK")); | |
3807 | + assertTrue(s.hasNextBigInteger()); | |
3808 | + assertEquals(new BigInteger("-123"), s.nextBigInteger()); | |
3809 | + } | |
3746 | 3810 | |
3747 | 3811 | s.close(); |
3748 | 3812 | try { |