< prev index next >

test/jdk/java/text/Collator/Test4401726.java

Print this page

  1 /*
  2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  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 /**
 25  * @test
 26  * @bug 4401726
 27  * @author John O'Conner
 28  * @library /java/text/testlib
 29  * @summary Regression tests for Collation and associated classes

 30  */
 31 
 32 
 33 import java.text.*;
 34 import java.util.Locale;
 35 import java.util.Vector;
 36 
 37 public class Test4401726 extends CollatorTest {
 38 
 39     public static void main(String[] args) throws Exception {
 40         new Test4401726().run(args);
 41     }
 42 

 43    public void TestSetOffSet() {
 44 
 45        int[] expected = {0, -1, 65536};
 46        int[] actual = new int[expected.length];
 47 
 48         try {
 49             String rule = "< a, A < d; D";
 50 
 51             RuleBasedCollator rbc = new RuleBasedCollator(rule);
 52             String str = "aD";
 53             CollationElementIterator iterator =
 54                 rbc.getCollationElementIterator(str);
 55 
 56             iterator.setOffset(0);
 57             actual[0] = iterator.getOffset();
 58             actual[1] = iterator.previous();
 59             iterator.setOffset(0);
 60             actual[2] = iterator.next();
 61 
 62             if (compareArray(expected, actual) == false) {
 63                 errln("Failed.");
 64             }
 65 
 66             str = "a";
 67             iterator = rbc.getCollationElementIterator(str);
 68             iterator.setOffset(0);
 69             actual[0] = iterator.getOffset();
 70             actual[1] = iterator.previous();
 71             iterator.setOffset(0);
 72             actual[2] = iterator.next();
 73 
 74             if (compareArray(expected, actual) == false) {
 75                 errln("Failed.");
 76             }
 77 
 78         } catch (ParseException e) {
 79             errln("Unexpected ParseException: " + e);
 80         }
 81 
 82 
 83     }
 84 
 85     boolean compareArray(int[] expected, int[] actual) {
 86         boolean retVal = false;
 87         if (expected.length == actual.length) {
 88             int errors = 0;
 89             for(int x=0; x< expected.length; ++x) {
 90                 if (expected[x] != actual[x]) {
 91                     ++errors;
 92                 }
 93             }
 94             if (errors == 0) retVal = true;
 95         }
 96         return retVal;
 97     }
 98 }

  1 /*
  2  * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  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 /**
 25  * @test
 26  * @bug 4401726
 27  * @author John O'Conner
 28  * @library /java/text/testlib
 29  * @summary Regression tests for Collation and associated classes
 30  * @run junit Test4401726
 31  */
 32 
 33 
 34 import java.text.*;
 35 import java.util.Locale;
 36 import java.util.Vector;
 37 
 38 import org.junit.jupiter.api.Test;
 39 
 40 import static org.junit.jupiter.api.Assertions.fail;
 41 
 42 public class Test4401726 {
 43 
 44     @Test
 45    public void TestSetOffSet() {
 46 
 47        int[] expected = {0, -1, 65536};
 48        int[] actual = new int[expected.length];
 49 
 50         try {
 51             String rule = "< a, A < d; D";
 52 
 53             RuleBasedCollator rbc = new RuleBasedCollator(rule);
 54             String str = "aD";
 55             CollationElementIterator iterator =
 56                 rbc.getCollationElementIterator(str);
 57 
 58             iterator.setOffset(0);
 59             actual[0] = iterator.getOffset();
 60             actual[1] = iterator.previous();
 61             iterator.setOffset(0);
 62             actual[2] = iterator.next();
 63 
 64             if (compareArray(expected, actual) == false) {
 65                 fail("Failed.");
 66             }
 67 
 68             str = "a";
 69             iterator = rbc.getCollationElementIterator(str);
 70             iterator.setOffset(0);
 71             actual[0] = iterator.getOffset();
 72             actual[1] = iterator.previous();
 73             iterator.setOffset(0);
 74             actual[2] = iterator.next();
 75 
 76             if (compareArray(expected, actual) == false) {
 77                 fail("Failed.");
 78             }
 79 
 80         } catch (ParseException e) {
 81             fail("Unexpected ParseException: " + e);
 82         }
 83 
 84 
 85     }
 86 
 87     boolean compareArray(int[] expected, int[] actual) {
 88         boolean retVal = false;
 89         if (expected.length == actual.length) {
 90             int errors = 0;
 91             for(int x=0; x< expected.length; ++x) {
 92                 if (expected[x] != actual[x]) {
 93                     ++errors;
 94                 }
 95             }
 96             if (errors == 0) retVal = true;
 97         }
 98         return retVal;
 99     }
100 }
< prev index next >