001: /*
002: *******************************************************************************
003: * Copyright (C) 2006, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007:
008: package com.ibm.icu.tests;
009:
010: import java.util.Locale;
011:
012: import com.ibm.icu.text.CollationKey;
013: import com.ibm.icu.text.Collator;
014: import com.ibm.icu.util.ULocale;
015:
016: public class CollatorTest extends ICUTestCase {
017: private static final String s1 = "Fu\u0308nf"; // capital F + u + diaresis
018: private static final String s2 = "fu\u0308nf"; // u + diaresis
019: private static final String s3 = "f\u00fcnf"; // u-umlaut
020: private static final String s4 = "fu\u0308\u0316nf"; // u + diaresis above + grave below
021: private static final String s5 = "fu\u0316\u0308nf"; // u + grave below + diaresis above
022:
023: /*
024: * Test method for 'com.ibm.icu.text.Collator.hashCode()'
025: */
026: public void testHashCode() {
027: Collator c = Collator.getInstance();
028: c.setStrength(Collator.SECONDARY);
029: Collator c2 = Collator.getInstance();
030: c2.setStrength(Collator.SECONDARY);
031: Collator cn = Collator.getInstance();
032: cn.setStrength(Collator.TERTIARY);
033: testEHCS(c, c2, cn);
034: }
035:
036: /*
037: * Test method for 'com.ibm.icu.text.Collator.Collator(Collator)'
038: */
039: public void testCollator() {
040: // implicitly tested everywhere
041: }
042:
043: /*
044: * Test method for 'com.ibm.icu.text.Collator.setStrength(int)'
045: */
046: public void testSetStrength() {
047: Collator c = Collator.getInstance();
048: c.setStrength(Collator.PRIMARY);
049: assertTrue(0 == c.compare(s1, s2));
050: c.setStrength(Collator.SECONDARY);
051: assertTrue(0 == c.compare(s1, s2));
052: c.setStrength(Collator.TERTIARY);
053: assertTrue(0 < c.compare(s1, s2));
054: assertTrue(0 == c.compare(s2, s3));
055: c.setStrength(Collator.QUATERNARY);
056: assertTrue(0 > c.compare(s2, s3));
057: }
058:
059: /*
060: * Test method for 'com.ibm.icu.text.Collator.setDecomposition(int)'
061: */
062: public void testSetDecomposition() {
063: Collator c = Collator.getInstance();
064: c.setStrength(Collator.TERTIARY);
065: assertTrue(0 != c.compare(s4, s5));
066: c.setDecomposition(Collator.IDENTICAL);
067: assertTrue(0 == c.compare(s4, s5));
068: }
069:
070: /*
071: * Test method for 'com.ibm.icu.text.Collator.getInstance()'
072: */
073: public void testGetInstance() {
074: // implicitly tested everywhere
075: }
076:
077: /*
078: * Test method for 'com.ibm.icu.text.Collator.getInstance(ULocale)'
079: */
080: public void testGetInstanceULocale() {
081: Collator c = Collator.getInstance(ULocale.GERMANY);
082: assertNotNull(c);
083: }
084:
085: /*
086: * Test method for 'com.ibm.icu.text.Collator.getInstance(Locale)'
087: */
088: public void testGetInstanceLocale() {
089: Collator c = Collator.getInstance(Locale.GERMANY);
090: assertNotNull(c);
091: }
092:
093: /*
094: * Test method for 'com.ibm.icu.text.Collator.getAvailableLocales()'
095: */
096: public void testGetAvailableLocales() {
097: assertNotNull(Collator.getAvailableLocales());
098: }
099:
100: /*
101: * Test method for 'com.ibm.icu.text.Collator.getAvailableULocales()'
102: */
103: public void testGetAvailableULocales() {
104: assertNotNull(Collator.getAvailableULocales());
105: }
106:
107: /*
108: * Test method for 'com.ibm.icu.text.Collator.getKeywords()'
109: */
110: public void testGetKeywords() {
111: assertEquals(0, Collator.getKeywords().length);
112: }
113:
114: /*
115: * Test method for 'com.ibm.icu.text.Collator.getKeywordValues(String)'
116: */
117: public void testGetKeywordValues() {
118: assertEquals(0, Collator.getKeywordValues("").length);
119: }
120:
121: /*
122: * Test method for 'com.ibm.icu.text.Collator.getStrength()'
123: */
124: public void testGetStrength() {
125: Collator c = Collator.getInstance();
126: c.setStrength(Collator.PRIMARY);
127: assertEquals(Collator.PRIMARY, c.getStrength());
128: c.setStrength(Collator.SECONDARY);
129: assertEquals(Collator.SECONDARY, c.getStrength());
130: }
131:
132: /*
133: * Test method for 'com.ibm.icu.text.Collator.getDecomposition()'
134: */
135: public void testGetDecomposition() {
136: Collator c = Collator.getInstance();
137: c.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
138: assertEquals(Collator.CANONICAL_DECOMPOSITION, c
139: .getDecomposition());
140: c.setDecomposition(Collator.NO_DECOMPOSITION);
141: assertEquals(Collator.NO_DECOMPOSITION, c.getDecomposition());
142: }
143:
144: /*
145: * Test method for 'com.ibm.icu.text.Collator.compare(Object, Object)'
146: */
147: public void testCompareObjectObject() {
148: Collator c = Collator.getInstance();
149: c.setStrength(Collator.PRIMARY);
150: assertTrue(0 == c.compare((Object) s1, (Object) s2));
151: }
152:
153: /*
154: * Test method for 'com.ibm.icu.text.Collator.equals(String, String)'
155: */
156: public void testEqualsStringString() {
157: Collator c = Collator.getInstance();
158: c.setStrength(Collator.PRIMARY);
159: assertTrue(c.equals(s1, s2));
160: }
161:
162: /*
163: * Test method for 'com.ibm.icu.text.Collator.compare(String, String)'
164: */
165: public void testCompareStringString() {
166: Collator c = Collator.getInstance();
167: c.setStrength(Collator.PRIMARY);
168: assertTrue(0 == c.compare(s1, s2));
169: }
170:
171: /*
172: * Test method for 'com.ibm.icu.text.Collator.getCollationKey(String)'
173: */
174: public void testGetCollationKey() {
175: Collator c = Collator.getInstance();
176: c.setStrength(Collator.PRIMARY);
177: CollationKey k1 = c.getCollationKey(s1);
178: CollationKey k2 = c.getCollationKey(s2);
179: assertTrue(k1.equals(k2));
180: c.setStrength(Collator.TERTIARY);
181: k1 = c.getCollationKey(s1);
182: k2 = c.getCollationKey(s2);
183: assertFalse(k1.equals(k2));
184: }
185:
186: /*
187: * Test method for 'com.ibm.icu.text.Collator.toString()'
188: */
189: public void testToString() {
190: assertNotNull(Collator.getInstance().toString());
191: }
192:
193: /*
194: * Test method for 'com.ibm.icu.text.Collator.clone()'
195: */
196: public void testClone() {
197: // tested above
198: }
199:
200: /*
201: * Test method for 'com.ibm.icu.text.Collator.equals(Object)'
202: */
203: public void testEqualsObject() {
204: // tested above
205: }
206: }
|