author | dholmes |
Wed, 06 Nov 2019 21:18:42 -0500 | |
changeset 58956 | 9a0a5e70eeb2 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
38786
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
1 |
/* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
4 |
* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
8 |
* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
13 |
* accompanied this code). |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
14 |
* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
18 |
* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
21 |
* questions. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
22 |
*/ |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
23 |
|
41127
186dce575463
8166553: undeclared dependencies for two IO tests
skovalev
parents:
38786
diff
changeset
|
24 |
/* |
38786
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
25 |
* @test |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
26 |
* @bug 8146156 |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
27 |
* @summary test whether conversion follows Locale.Category.FORMAT locale. |
41127
186dce575463
8166553: undeclared dependencies for two IO tests
skovalev
parents:
38786
diff
changeset
|
28 |
* @modules jdk.localedata |
38786
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
29 |
* @run main/othervm FormatLocale |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
30 |
*/ |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
31 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
32 |
import java.io.ByteArrayOutputStream; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
33 |
import java.io.PrintStream; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
34 |
import java.util.List; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
35 |
import java.util.Locale; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
36 |
import java.util.Locale.Category; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
37 |
import java.util.stream.IntStream; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
38 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
39 |
public class FormatLocale { |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
40 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
41 |
static final float src = 3.14f; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
42 |
static final List<Locale> formatLocale = List.of(Locale.US, Locale.FRANCE); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
43 |
static final List<String> expected = List.of("3.14", "3,14"); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
44 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
45 |
public static void main(String [] args) { |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
46 |
IntStream.range(0, formatLocale.size()).forEach(i -> { |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
47 |
Locale.setDefault(Locale.Category.FORMAT, formatLocale.get(i)); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
48 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
49 |
new PrintStream(baos).format("%.2f", src); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
50 |
if (!baos.toString().equals(expected.get(i))) { |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
51 |
throw new RuntimeException( |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
52 |
"Wrong conversion with PrintStream.format() in locale " |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
53 |
+ formatLocale.get(i) + |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
54 |
". Expected: " + expected.get(i) + |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
55 |
" Returned: " + baos.toString()); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
56 |
} |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
57 |
}); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
58 |
} |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
59 |
} |