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 4049325 4073127 4083270 4106034 4108126
26 @summary test Resource Bundle
27 @build TestResource TestResource_de TestResource_fr TestResource_fr_CH
28 @build TestResource_it FakeTestResource
29 @run main ResourceBundleTest
30 */
31 /*
32 *
33 *
34 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
35 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
36 *
37 * Portions copyright (c) 2007 Sun Microsystems, Inc.
38 * All Rights Reserved.
39 *
40 * The original version of this source code and documentation
41 * is copyrighted and owned by Taligent, Inc., a wholly-owned
42 * subsidiary of IBM. These materials are provided under terms
43 * of a License Agreement between Taligent and Sun. This technology
44 * is protected by multiple US and International patents.
45 *
46 * This notice and attribution to Taligent may not be removed.
47 * Taligent is a registered trademark of Taligent, Inc.
48 *
49 * Permission to use, copy, modify, and distribute this software
50 * and its documentation for NON-COMMERCIAL purposes and without
51 * fee is hereby granted provided that this copyright notice
52 * appears in all copies. Please refer to the file "copyright.html"
53 * for further important copyright and licensing information.
54 *
55 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
56 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
57 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
58 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
59 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
60 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
61 *
62 */
63
64 import java.text.*;
65 import java.util.*;
66 import java.io.*;
67
68 public class ResourceBundleTest extends RBTestFmwk {
69 public static void main(String[] args) throws Exception {
70 new ResourceBundleTest().run(args);
71 }
72
73 public ResourceBundleTest() {
74 makePropertiesFile();
75 }
76
77 public void TestResourceBundle() {
78 Locale saveDefault = Locale.getDefault();
79 Locale.setDefault(new Locale("fr", "FR"));
80
81 // load up the resource bundle, and make sure we got the right one
82 ResourceBundle bundle = ResourceBundle.getBundle("TestResource");
83 if (!bundle.getClass().getName().equals("TestResource_fr"))
84 errln("Expected TestResource_fr, got " + bundle.getClass().getName());
85
117 errln("TestResource_fr returned the wrong value for one of the elements in \"All\"");
118
119 // This resource is defined in neither TestResource not TestResource_fr
120 try {
121 test3 = bundle.getObject("Is");
122 errln("TestResource_fr returned a value for \"Is\" when it shouldn't: got " + test3);
123 }
124 catch (MissingResourceException e) {
125 }
126
127 String[] keys = { "Now", "Time", "For", "All", "Good", "Men", "Come" };
128 checkKeys(bundle.getKeys(), keys);
129
130 Locale.setDefault(saveDefault);
131 }
132
133 public void TestListResourceBundle() {
134 // load up the resource and check to make sure we got the right class
135 // (we don't define be_BY or be, so we fall back on the root default)
136 ResourceBundle bundle = ResourceBundle.getBundle("TestResource",
137 new Locale("be", "BY"));
138 if (!bundle.getClass().getName().equals("TestResource"))
139 errln("Expected TestResource, got " + bundle.getClass().getName());
140
141 doListResourceBundleTest(bundle);
142 }
143
144 /**
145 * @bug 4073127
146 * Repeat TestListResourceBundle on TestResource_it, which is a ListResourceBundle
147 * with NO contents. It should gracefully inherit everything from the root
148 * TestResource.
149 */
150 public void TestEmptyListResourceBundle() {
151 ResourceBundle bundle = ResourceBundle.getBundle("TestResource",
152 new Locale("it", "IT"));
153 doListResourceBundleTest(bundle);
154 }
155
156 private void doListResourceBundleTest(ResourceBundle bundle) {
157 // load up the resource and check to make sure we got the right class
251 * @bug 4108126
252 */
253 public void TestGetLocale() {
254 // try to find TestResource_fr_CH. Should get fr_CH as its locale
255 ResourceBundle test = ResourceBundle.getBundle("TestResource",
256 new Locale("fr", "CH", ""));
257 Locale locale = test.getLocale();
258 if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
259 errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);
260
261 // try to find TestResource_fr_BE, which doesn't exist. Should get fr as its locale
262 test = ResourceBundle.getBundle("TestResource",
263 new Locale("fr", "BE", ""));
264 locale = test.getLocale();
265 if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
266 errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);
267
268 // try to find TestResource_iw_IL, which doesn't exist. Should get root locale
269 // as its locale
270 test = ResourceBundle.getBundle("TestResource",
271 new Locale("iw", "IL", ""));
272 locale = test.getLocale();
273 if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
274 errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
275 + locale);
276 }
277
278 /*
279 * @bug 4083270
280 */
281 public void TestNonSubclass() {
282 // ResourceBundle.getBundle should never return an object that isn't an instance
283 // of ResourceBundle or one of its subclasses. We have a class called FakeTestResource
284 // in this package that isn't a ResourceBundle. If we get that back, we barf.
285 // (Actually, at the time I fixed this bug, getResource() would throw a
286 // ClassCastException in that case.)
287 // There's also a properties file called FakeTestResource; we should get back a
288 // PropertyResourceBundle pointing to that file.
289 Object test1 = ResourceBundle.getBundle("FakeTestResource",
290 Locale.US);
291
|
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 4049325 4073127 4083270 4106034 4108126 8027930
26 @summary test Resource Bundle
27 @build TestResource TestResource_de TestResource_fr TestResource_fr_CH
28 @build TestResource_it FakeTestResource
29 @run main ResourceBundleTest
30 */
31 /*
32 *
33 *
34 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
35 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
36 *
37 * Portions copyright (c) 2007 Sun Microsystems, Inc.
38 * All Rights Reserved.
39 *
40 * The original version of this source code and documentation
41 * is copyrighted and owned by Taligent, Inc., a wholly-owned
42 * subsidiary of IBM. These materials are provided under terms
43 * of a License Agreement between Taligent and Sun. This technology
44 * is protected by multiple US and International patents.
45 *
46 * This notice and attribution to Taligent may not be removed.
47 * Taligent is a registered trademark of Taligent, Inc.
48 *
49 * Permission to use, copy, modify, and distribute this software
50 * and its documentation for NON-COMMERCIAL purposes and without
51 * fee is hereby granted provided that this copyright notice
52 * appears in all copies. Please refer to the file "copyright.html"
53 * for further important copyright and licensing information.
54 *
55 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
56 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
57 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
58 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
59 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
60 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
61 *
62 */
63
64 import java.text.*;
65 import java.util.*;
66 import static java.util.ResourceBundle.Control;
67 import java.io.*;
68
69 public class ResourceBundleTest extends RBTestFmwk {
70 public static void main(String[] args) throws Exception {
71 new ResourceBundleTest().run(args);
72 }
73
74 public ResourceBundleTest() {
75 makePropertiesFile();
76 }
77
78 public void TestResourceBundle() {
79 Locale saveDefault = Locale.getDefault();
80 Locale.setDefault(new Locale("fr", "FR"));
81
82 // load up the resource bundle, and make sure we got the right one
83 ResourceBundle bundle = ResourceBundle.getBundle("TestResource");
84 if (!bundle.getClass().getName().equals("TestResource_fr"))
85 errln("Expected TestResource_fr, got " + bundle.getClass().getName());
86
118 errln("TestResource_fr returned the wrong value for one of the elements in \"All\"");
119
120 // This resource is defined in neither TestResource not TestResource_fr
121 try {
122 test3 = bundle.getObject("Is");
123 errln("TestResource_fr returned a value for \"Is\" when it shouldn't: got " + test3);
124 }
125 catch (MissingResourceException e) {
126 }
127
128 String[] keys = { "Now", "Time", "For", "All", "Good", "Men", "Come" };
129 checkKeys(bundle.getKeys(), keys);
130
131 Locale.setDefault(saveDefault);
132 }
133
134 public void TestListResourceBundle() {
135 // load up the resource and check to make sure we got the right class
136 // (we don't define be_BY or be, so we fall back on the root default)
137 ResourceBundle bundle = ResourceBundle.getBundle("TestResource",
138 new Locale("be", "BY"),
139 Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
140 if (!bundle.getClass().getName().equals("TestResource"))
141 errln("Expected TestResource, got " + bundle.getClass().getName());
142
143 doListResourceBundleTest(bundle);
144 }
145
146 /**
147 * @bug 4073127
148 * Repeat TestListResourceBundle on TestResource_it, which is a ListResourceBundle
149 * with NO contents. It should gracefully inherit everything from the root
150 * TestResource.
151 */
152 public void TestEmptyListResourceBundle() {
153 ResourceBundle bundle = ResourceBundle.getBundle("TestResource",
154 new Locale("it", "IT"));
155 doListResourceBundleTest(bundle);
156 }
157
158 private void doListResourceBundleTest(ResourceBundle bundle) {
159 // load up the resource and check to make sure we got the right class
253 * @bug 4108126
254 */
255 public void TestGetLocale() {
256 // try to find TestResource_fr_CH. Should get fr_CH as its locale
257 ResourceBundle test = ResourceBundle.getBundle("TestResource",
258 new Locale("fr", "CH", ""));
259 Locale locale = test.getLocale();
260 if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
261 errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);
262
263 // try to find TestResource_fr_BE, which doesn't exist. Should get fr as its locale
264 test = ResourceBundle.getBundle("TestResource",
265 new Locale("fr", "BE", ""));
266 locale = test.getLocale();
267 if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
268 errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);
269
270 // try to find TestResource_iw_IL, which doesn't exist. Should get root locale
271 // as its locale
272 test = ResourceBundle.getBundle("TestResource",
273 new Locale("iw", "IL", ""),
274 Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
275 locale = test.getLocale();
276 if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
277 errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
278 + locale);
279 }
280
281 /*
282 * @bug 4083270
283 */
284 public void TestNonSubclass() {
285 // ResourceBundle.getBundle should never return an object that isn't an instance
286 // of ResourceBundle or one of its subclasses. We have a class called FakeTestResource
287 // in this package that isn't a ResourceBundle. If we get that back, we barf.
288 // (Actually, at the time I fixed this bug, getResource() would throw a
289 // ClassCastException in that case.)
290 // There's also a properties file called FakeTestResource; we should get back a
291 // PropertyResourceBundle pointing to that file.
292 Object test1 = ResourceBundle.getBundle("FakeTestResource",
293 Locale.US);
294
|