Path: blob/master/test/jdk/java/text/Collator/Test4401726.java
41149 views
/*1* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 440172626* @author John O'Conner27* @library /java/text/testlib28* @summary Regression tests for Collation and associated classes29*/303132import java.text.*;33import java.util.Locale;34import java.util.Vector;3536public class Test4401726 extends CollatorTest {3738public static void main(String[] args) throws Exception {39new Test4401726().run(args);40}4142public void TestSetOffSet() {4344int[] expected = {0, -1, 65536};45int[] actual = new int[expected.length];4647try {48String rule = "< a, A < d; D";4950RuleBasedCollator rbc = new RuleBasedCollator(rule);51String str = "aD";52CollationElementIterator iterator =53rbc.getCollationElementIterator(str);5455iterator.setOffset(0);56actual[0] = iterator.getOffset();57actual[1] = iterator.previous();58iterator.setOffset(0);59actual[2] = iterator.next();6061if (compareArray(expected, actual) == false) {62errln("Failed.");63}6465str = "a";66iterator = rbc.getCollationElementIterator(str);67iterator.setOffset(0);68actual[0] = iterator.getOffset();69actual[1] = iterator.previous();70iterator.setOffset(0);71actual[2] = iterator.next();7273if (compareArray(expected, actual) == false) {74errln("Failed.");75}7677} catch (ParseException e) {78errln("Unexpected ParseException: " + e);79}808182}8384boolean compareArray(int[] expected, int[] actual) {85boolean retVal = false;86if (expected.length == actual.length) {87int errors = 0;88for(int x=0; x< expected.length; ++x) {89if (expected[x] != actual[x]) {90++errors;91}92}93if (errors == 0) retVal = true;94}95return retVal;96}97}9899100