< prev index next >

test/jdk/java/text/Collator/DummyTest.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  * @library /java/text/testlib
 27  * @summary test Dummy Collation

 28  */
 29 
 30 import java.text.Collator;
 31 import java.text.RuleBasedCollator;
 32 




 33 /*
 34 (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
 35 (C) Copyright IBM Corp. 1996 - All Rights Reserved
 36 
 37   The original version of this source code and documentation is copyrighted and
 38 owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
 39 provided under terms of a License Agreement between Taligent and Sun. This
 40 technology is protected by multiple US and International patents. This notice and
 41 attribution to Taligent may not be removed.
 42   Taligent is a registered trademark of Taligent, Inc.
 43 */
 44 
 45 public class DummyTest extends CollatorTest {
 46 
 47     public static void main(String[] args) throws Exception {
 48         new DummyTest().run(args);
 49     }
 50 
 51     private static final String DEFAULTRULES =
 52         "='\u200B'=\u200C=\u200D=\u200E=\u200F"
 53         // Control Characters
 54         + "=\u0000 =\u0001 =\u0002 =\u0003 =\u0004" //null, .. eot
 55         + "=\u0005 =\u0006 =\u0007 =\u0008 ='\u0009'" //enq, ...
 56         + "='\u000b' =\u000e" //vt,, so
 57         + "=\u000f ='\u0010' =\u0011 =\u0012 =\u0013" //si, dle, dc1, dc2, dc3
 58         + "=\u0014 =\u0015 =\u0016 =\u0017 =\u0018" //dc4, nak, syn, etb, can
 59         + "=\u0019 =\u001a =\u001b =\u001c =\u001d" //em, sub, esc, fs, gs
 60         + "=\u001e =\u001f =\u007f"                   //rs, us, del
 61         //....then the C1 Latin 1 reserved control codes
 62         + "=\u0080 =\u0081 =\u0082 =\u0083 =\u0084 =\u0085"
 63         + "=\u0086 =\u0087 =\u0088 =\u0089 =\u008a =\u008b"
 64         + "=\u008c =\u008d =\u008e =\u008f =\u0090 =\u0091"
 65         + "=\u0092 =\u0093 =\u0094 =\u0095 =\u0096 =\u0097"
 66         + "=\u0098 =\u0099 =\u009a =\u009b =\u009c =\u009d"
 67         + "=\u009e =\u009f"
 68         // IGNORE except for secondary, tertiary difference
 69         // Spaces

365          1, -1,  1,  1, -1, -1, -1
366     };
367 
368 
369     private static final String[] testData = {
370         "a",
371         "A",
372         "\u00e4",
373         "\u00c4",
374         "ae",
375         "aE",
376         "Ae",
377         "AE",
378         "\u00e6",
379         "\u00c6",
380         "b",
381         "c",
382         "z"
383     };
384 

385     public void TestPrimary() {
386         doTest(getCollator(), Collator.PRIMARY,
387                primarySourceData, primaryTargetData, primaryResults);
388     }
389 

390     public void TestSecondary() {
391         doTest(getCollator(), Collator.SECONDARY,
392                secondarySourceData, secondaryTargetData, secondaryResults);
393     }
394 

395     public void TestTertiary() {
396         Collator col = getCollator();
397 
398         doTest(col, Collator.TERTIARY,
399                tertiarySourceData, tertiaryTargetData, tertiaryResults);
400 
401         for (int i = 0; i < testData.length-1; i++) {
402             for (int j = i+1; j < testData.length; j++) {
403                 doTest(col, testData[i], testData[j], -1);
404             }
405         }
406     }
407 
408     private RuleBasedCollator myCollation = null;
409     private Collator getCollator() {
410         if (myCollation == null) {
411             try {
412                 myCollation = new RuleBasedCollator
413                     (DEFAULTRULES + "& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ");
414             } catch (Exception foo) {
415                 errln("Collator creation failed.");
416                 myCollation = (RuleBasedCollator)Collator.getInstance();
417             }
418         }
419         return myCollation;
420     }
421 }

  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  * @library /java/text/testlib
 27  * @summary test Dummy Collation
 28  * @run junit DummyTest
 29  */
 30 
 31 import java.text.Collator;
 32 import java.text.RuleBasedCollator;
 33 
 34 import org.junit.jupiter.api.Test;
 35 
 36 import static org.junit.jupiter.api.Assertions.fail;
 37 
 38 /*
 39 (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
 40 (C) Copyright IBM Corp. 1996 - All Rights Reserved
 41 
 42   The original version of this source code and documentation is copyrighted and
 43 owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
 44 provided under terms of a License Agreement between Taligent and Sun. This
 45 technology is protected by multiple US and International patents. This notice and
 46 attribution to Taligent may not be removed.
 47   Taligent is a registered trademark of Taligent, Inc.
 48 */
 49 
 50 public class DummyTest {




 51 
 52     private static final String DEFAULTRULES =
 53         "='\u200B'=\u200C=\u200D=\u200E=\u200F"
 54         // Control Characters
 55         + "=\u0000 =\u0001 =\u0002 =\u0003 =\u0004" //null, .. eot
 56         + "=\u0005 =\u0006 =\u0007 =\u0008 ='\u0009'" //enq, ...
 57         + "='\u000b' =\u000e" //vt,, so
 58         + "=\u000f ='\u0010' =\u0011 =\u0012 =\u0013" //si, dle, dc1, dc2, dc3
 59         + "=\u0014 =\u0015 =\u0016 =\u0017 =\u0018" //dc4, nak, syn, etb, can
 60         + "=\u0019 =\u001a =\u001b =\u001c =\u001d" //em, sub, esc, fs, gs
 61         + "=\u001e =\u001f =\u007f"                   //rs, us, del
 62         //....then the C1 Latin 1 reserved control codes
 63         + "=\u0080 =\u0081 =\u0082 =\u0083 =\u0084 =\u0085"
 64         + "=\u0086 =\u0087 =\u0088 =\u0089 =\u008a =\u008b"
 65         + "=\u008c =\u008d =\u008e =\u008f =\u0090 =\u0091"
 66         + "=\u0092 =\u0093 =\u0094 =\u0095 =\u0096 =\u0097"
 67         + "=\u0098 =\u0099 =\u009a =\u009b =\u009c =\u009d"
 68         + "=\u009e =\u009f"
 69         // IGNORE except for secondary, tertiary difference
 70         // Spaces

366          1, -1,  1,  1, -1, -1, -1
367     };
368 
369 
370     private static final String[] testData = {
371         "a",
372         "A",
373         "\u00e4",
374         "\u00c4",
375         "ae",
376         "aE",
377         "Ae",
378         "AE",
379         "\u00e6",
380         "\u00c6",
381         "b",
382         "c",
383         "z"
384     };
385 
386     @Test
387     public void TestPrimary() {
388         TestUtils.doCollatorTest(getCollator(), Collator.PRIMARY,
389                primarySourceData, primaryTargetData, primaryResults);
390     }
391 
392     @Test
393     public void TestSecondary() {
394         TestUtils.doCollatorTest(getCollator(), Collator.SECONDARY,
395                secondarySourceData, secondaryTargetData, secondaryResults);
396     }
397 
398     @Test
399     public void TestTertiary() {
400         Collator col = getCollator();
401 
402         TestUtils.doCollatorTest(col, Collator.TERTIARY,
403                tertiarySourceData, tertiaryTargetData, tertiaryResults);
404 
405         for (int i = 0; i < testData.length-1; i++) {
406             for (int j = i+1; j < testData.length; j++) {
407                 TestUtils.doCollatorTest(col, testData[i], testData[j], -1);
408             }
409         }
410     }
411 
412     private RuleBasedCollator myCollation = null;
413     private Collator getCollator() {
414         if (myCollation == null) {
415             try {
416                 myCollation = new RuleBasedCollator
417                     (DEFAULTRULES + "& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ");
418             } catch (Exception foo) {
419                 fail("Collator creation failed.");
420                 myCollation = (RuleBasedCollator)Collator.getInstance();
421             }
422         }
423         return myCollation;
424     }
425 }
< prev index next >