BreakIteratorProviderTest.java revision 0
0N/A/*
0N/A * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/A/*
0N/A *
0N/A */
0N/A
0N/Aimport java.text.*;
0N/Aimport java.util.*;
0N/Aimport sun.text.resources.*;
0N/Aimport sun.util.*;
0N/Aimport sun.util.resources.*;
0N/A
0N/Apublic class BreakIteratorProviderTest extends ProviderTest {
0N/A
0N/A com.foo.BreakIteratorProviderImpl bip = new com.foo.BreakIteratorProviderImpl();
0N/A List<Locale> availloc = Arrays.asList(BreakIterator.getAvailableLocales());
0N/A List<Locale> providerloc = Arrays.asList(bip.getAvailableLocales());
0N/A List<Locale> jreloc = Arrays.asList(LocaleData.getAvailableLocales());
0N/A
0N/A private static final int CHARACTER_INDEX = 0;
0N/A private static final int WORD_INDEX = 1;
0N/A private static final int LINE_INDEX = 2;
0N/A private static final int SENTENCE_INDEX = 3;
0N/A
0N/A public static void main(String[] s) {
0N/A new BreakIteratorProviderTest();
0N/A }
0N/A
0N/A BreakIteratorProviderTest() {
0N/A availableLocalesTest();
0N/A objectValidityTest();
0N/A }
0N/A
0N/A void availableLocalesTest() {
0N/A Set<Locale> localesFromAPI = new HashSet<Locale>(availloc);
0N/A Set<Locale> localesExpected = new HashSet<Locale>(jreloc);
0N/A localesExpected.addAll(providerloc);
0N/A if (localesFromAPI.equals(localesExpected)) {
0N/A System.out.println("availableLocalesTest passed.");
0N/A } else {
0N/A throw new RuntimeException("availableLocalesTest failed");
0N/A }
0N/A }
0N/A
0N/A void objectValidityTest() {
0N/A
0N/A for (Locale target: availloc) {
0N/A // pure JRE implementation
0N/A ResourceBundle rb = ResourceBundle.getBundle(
0N/A "sun.text.resources.BreakIteratorInfo", target);
0N/A String[] classNames = rb.getStringArray("BreakIteratorClasses");
0N/A boolean jreSupportsLocale = jreloc.contains(target);
0N/A
0N/A // result object
0N/A String[] result = new String[4];
0N/A result[0] = BreakIterator.getCharacterInstance(target).getClass().getName();
0N/A result[1] = BreakIterator.getWordInstance(target).getClass().getName();
0N/A result[2] = BreakIterator.getLineInstance(target).getClass().getName();
0N/A result[3] = BreakIterator.getSentenceInstance(target).getClass().getName();
0N/A
0N/A // provider's object (if any)
0N/A String[] providersResult = new String[4];
0N/A if (providerloc.contains(target)) {
0N/A providersResult[0] = bip.getCharacterInstance(target).getClass().getName();
0N/A providersResult[1] = bip.getWordInstance(target).getClass().getName();
0N/A providersResult[2] = bip.getLineInstance(target).getClass().getName();
0N/A providersResult[3] = bip.getSentenceInstance(target).getClass().getName();
0N/A }
0N/A
0N/A // JRE
0N/A String[] jresResult = new String[4];
0N/A if (jreSupportsLocale) {
0N/A for (int i = 0; i < 4; i++) {
0N/A jresResult[i] = "java.text."+classNames[i];
0N/A }
0N/A }
0N/A
0N/A for (int i = 0; i < 4; i++) {
0N/A checkValidity(target, jresResult[i], providersResult[i], result[i], jreSupportsLocale);
0N/A }
0N/A }
0N/A }
0N/A}