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 com.ibm.icu.text.CollationKey;
011: import com.ibm.icu.text.Collator;
012:
013: public class CollationKeyTest extends ICUTestCase {
014:
015: /*
016: * Test method for 'com.ibm.icu.text.CollationKey.hashCode()'
017: */
018: public void testHashCode() {
019: Collator c = Collator.getInstance();
020: c.setStrength(Collator.PRIMARY);
021: CollationKey k1 = c.getCollationKey("This");
022: CollationKey k2 = c.getCollationKey("this");
023: c.setStrength(Collator.TERTIARY);
024: CollationKey kn = c.getCollationKey("this");
025: testEHCS(k1, k2, kn);
026: }
027:
028: /*
029: * Test method for 'com.ibm.icu.text.CollationKey.CollationKey(CollationKey)'
030: */
031: public void testCollationKey() {
032: // implicitly tested everywhere
033: }
034:
035: /*
036: * Test method for 'com.ibm.icu.text.CollationKey.compareTo(CollationKey)'
037: */
038: public void testCompareToCollationKey() {
039: Collator c = Collator.getInstance();
040: c.setStrength(Collator.PRIMARY);
041: CollationKey k1 = c.getCollationKey("This");
042: CollationKey k2 = c.getCollationKey("this");
043: c.setStrength(Collator.TERTIARY);
044: CollationKey k3 = c.getCollationKey("this");
045: assertTrue(0 == k1.compareTo(k2));
046: assertFalse(0 == k1.compareTo(k3));
047: }
048:
049: /*
050: * Test method for 'com.ibm.icu.text.CollationKey.compareTo(Object)'
051: */
052: public void testCompareToObject() {
053: Collator c = Collator.getInstance();
054: c.setStrength(Collator.PRIMARY);
055: CollationKey k1 = c.getCollationKey("This");
056: CollationKey k2 = c.getCollationKey("this");
057: assertTrue(0 == k1.compareTo((Object) k2));
058: }
059:
060: /*
061: * Test method for 'com.ibm.icu.text.CollationKey.equals(Object)'
062: */
063: public void testEqualsObject() {
064: Collator c = Collator.getInstance();
065: c.setStrength(Collator.PRIMARY);
066: CollationKey k1 = c.getCollationKey("This");
067: CollationKey k2 = c.getCollationKey("this");
068: assertTrue(k1.equals((Object) k2));
069: }
070:
071: /*
072: * Test method for 'com.ibm.icu.text.CollationKey.toString()'
073: */
074: public void testToString() {
075: Collator c = Collator.getInstance();
076: c.setStrength(Collator.PRIMARY);
077: CollationKey k1 = c.getCollationKey("This");
078: assertNotNull(k1.toString());
079: }
080:
081: /*
082: * Test method for 'com.ibm.icu.text.CollationKey.getSourceString()'
083: */
084: public void testGetSourceString() {
085: Collator c = Collator.getInstance();
086: c.setStrength(Collator.PRIMARY);
087: CollationKey k1 = c.getCollationKey("This");
088: assertEquals("This", k1.getSourceString());
089: }
090:
091: /*
092: * Test method for 'com.ibm.icu.text.CollationKey.toByteArray()'
093: */
094: public void testToByteArray() {
095: Collator c = Collator.getInstance();
096: c.setStrength(Collator.PRIMARY);
097: CollationKey k1 = c.getCollationKey("This");
098: byte[] key = k1.toByteArray();
099: assertNotNull(key);
100: assertTrue(0 < key.length);
101: }
102: }
|