/* ******************************************************************************* * Copyright (C) 2002-2010, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ /** * Port From: ICU4C v2.1 : Collate/CollationDummyTest * Source File: $ICU4CRoot/source/test/intltest/allcoll.cpp * $ICU4CRoot/source/test/cintltst/callcoll.c **/ package com.ibm.icu.dev.test.collator; import java.util.Locale; import com.ibm.icu.dev.test.TestFmwk; import com.ibm.icu.text.CollationElementIterator; import com.ibm.icu.text.CollationKey; import com.ibm.icu.text.Collator; import com.ibm.icu.text.Normalizer; import com.ibm.icu.text.RuleBasedCollator; public class CollationDummyTest extends TestFmwk { public static void main(String[] args) throws Exception { new CollationDummyTest().run(args); // new CollationDummyTest().TestVariableTop(); } //testSourceCases[][] and testTargetCases[][], testCases[][] are ported from the file callcoll.c in icu4c private static char[][] testSourceCases = { {0x61, 0x62, 0x27, 0x63}, {0x63, 0x6f, 0x2d, 0x6f, 0x70}, {0x61, 0x62}, {0x61, 0x6d, 0x70, 0x65, 0x72, 0x73, 0x61, 0x64}, {0x61, 0x6c, 0x6c}, {0x66, 0x6f, 0x75, 0x72}, {0x66, 0x69, 0x76, 0x65}, {0x31}, {0x31}, {0x31}, // 10 {0x32}, {0x32}, {0x48, 0x65, 0x6c, 0x6c, 0x6f}, {0x61, 0x3c, 0x62}, {0x61, 0x3c, 0x62}, {0x61, 0x63, 0x63}, {0x61, 0x63, 0x48, 0x63}, // simple test {0x70, 0x00EA, 0x63, 0x68, 0x65}, {0x61, 0x62, 0x63}, {0x61, 0x62, 0x63}, // 20 {0x61, 0x62, 0x63}, {0x61, 0x62, 0x63}, {0x61, 0x62, 0x63}, {0x61, 0x00E6, 0x63}, {0x61, 0x63, 0x48, 0x63}, // primary test {0x62, 0x6c, 0x61, 0x63, 0x6b}, {0x66, 0x6f, 0x75, 0x72}, {0x66, 0x69, 0x76, 0x65}, {0x31}, {0x61, 0x62, 0x63}, // 30 {0x61, 0x62, 0x63}, {0x61, 0x62, 0x63, 0x48}, {0x61, 0x62, 0x63}, {0x61, 0x63, 0x48, 0x63}, // 34 {0x61, 0x63, 0x65, 0x30}, {0x31, 0x30}, {0x70, 0x00EA,0x30} // 37 }; private static char[][] testTargetCases = { {0x61, 0x62, 0x63, 0x27}, {0x43, 0x4f, 0x4f, 0x50}, {0x61, 0x62, 0x63}, {0x26}, {0x26}, {0x34}, {0x35}, {0x6f, 0x6e, 0x65}, {0x6e, 0x6e, 0x65}, {0x70, 0x6e, 0x65}, // 10 {0x74, 0x77, 0x6f}, {0x75, 0x77, 0x6f}, {0x68, 0x65, 0x6c, 0x6c, 0x4f}, {0x61, 0x3c, 0x3d, 0x62}, {0x61, 0x62, 0x63}, {0x61, 0x43, 0x48, 0x63}, {0x61, 0x43, 0x48, 0x63}, // simple test {0x70, 0x00E9, 0x63, 0x68, 0x00E9}, {0x61, 0x62, 0x63}, {0x61, 0x42, 0x43}, // 20 {0x61, 0x62, 0x63, 0x68}, {0x61, 0x62, 0x64}, {0x00E4, 0x62, 0x63}, {0x61, 0x00C6, 0x63}, {0x61, 0x43, 0x48, 0x63}, // primary test {0x62, 0x6c, 0x61, 0x63, 0x6b, 0x2d, 0x62, 0x69, 0x72, 0x64}, {0x34}, {0x35}, {0x6f, 0x6e, 0x65}, {0x61, 0x62, 0x63}, {0x61, 0x42, 0x63}, // 30 {0x61, 0x62, 0x63, 0x68}, {0x61, 0x62, 0x64}, {0x61, 0x43, 0x48, 0x63}, // 34 {0x61, 0x63, 0x65, 0x30}, {0x31, 0x30}, {0x70, 0x00EB,0x30} // 37 }; private static char[][] testCases = { {0x61}, {0x41}, {0x00e4}, {0x00c4}, {0x61, 0x65}, {0x61, 0x45}, {0x41, 0x65}, {0x41, 0x45}, {0x00e6}, {0x00c6}, {0x62}, {0x63}, {0x7a} }; int[] results = { -1, -1, //Collator::GREATER, -1, -1, -1, -1, -1, 1, 1, -1, // 10 1, -1, 1, 1, -1, -1, -1, // test primary > 17 0, 0, 0, // 20 -1, -1, 0, 0, 0, -1, // test secondary > 26 0, 0, 0, 0, 0, // 30 0, -1, 0, // 34 0, 0, -1 }; final int MAX_TOKEN_LEN = 16; public RuleBasedCollator myCollation; public CollationDummyTest() { } protected void init() throws Exception{ String ruleset = "& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 "; // String ruleset = "& Four, 4"; myCollation = null; myCollation = new RuleBasedCollator(ruleset); } // perform test with strength tertiary public void TestTertiary() { int i = 0; myCollation.setStrength(Collator.TERTIARY); for (i = 0; i < 17 ; i++) { doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); } } // perform test with strength PRIMARY public void TestPrimary() { // problem in strcollinc for unfinshed contractions myCollation.setStrength(Collator.PRIMARY); for (int i = 17; i < 26 ; i++) { doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); } } //perform test with strength SECONDARY public void TestSecondary() { int i; myCollation.setStrength(Collator.SECONDARY); for (i = 26; i < 34; i++) { doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); } } // perform extra tests public void TestExtra() { int i, j; myCollation.setStrength(Collator.TERTIARY); for (i = 0; i < testCases.length - 1; i++) { for (j = i + 1; j < testCases.length; j += 1) { doTest(myCollation, testCases[i], testCases[j], -1); } } } public void TestIdentical() { int i; myCollation.setStrength(Collator.IDENTICAL); for (i= 34; i<37; i++) { doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); } } public void TestJB581() { String source = "THISISATEST."; String target = "Thisisatest."; Collator coll = null; try { coll = Collator.getInstance(Locale.ENGLISH); } catch (Exception e) { errln("ERROR: Failed to create the collator for : en_US\n"); return; } int result = coll.compare(source, target); // result is 1, secondary differences only for ignorable space characters if (result != 1) { errln("Comparing two strings with only secondary differences in C failed.\n"); return; } // To compare them with just primary differences coll.setStrength(Collator.PRIMARY); result = coll.compare(source, target); // result is 0 if (result != 0) { errln("Comparing two strings with no differences in C failed.\n"); return; } // Now, do the same comparison with keys CollationKey sourceKeyOut, targetKeyOut; sourceKeyOut = coll.getCollationKey(source); targetKeyOut = coll.getCollationKey(target); result = sourceKeyOut.compareTo(targetKeyOut); if (result != 0) { errln("Comparing two strings with sort keys in C failed.\n"); return; } } //TestSurrogates() is ported from cintltst/callcoll.c /** * Tests surrogate support. */ public void TestSurrogates() { String rules = "&z<'\ud800\udc00'<'\ud800\udc0a\u0308'