]> granicus.if.org Git - icu/blob
a1afd34a42418cd0896fae4531dcee66107085cd
[icu] /
1 /*
2  *******************************************************************************
3  * Copyright (C) 2006-2011, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7
8 package com.ibm.icu.tests;
9
10 import com.ibm.icu.text.CollationKey;
11 import com.ibm.icu.text.Collator;
12
13 public class CollationKeyTest extends ICUTestCase {
14
15     /*
16      * Test method for 'com.ibm.icu.text.CollationKey.hashCode()'
17      */
18     public void testHashCode() {
19         Collator c = Collator.getInstance();
20         c.setStrength(Collator.PRIMARY);
21         CollationKey k1 = c.getCollationKey("This");
22         CollationKey k2 = c.getCollationKey("this");
23         c.setStrength(Collator.TERTIARY);
24         CollationKey kn = c.getCollationKey("this");
25         testEHCS(k1, k2, kn);
26     }
27
28     /*
29      * Test method for 'com.ibm.icu.text.CollationKey.CollationKey(CollationKey)'
30      */
31     public void testCollationKey() {
32         // implicitly tested everywhere
33     }
34
35     /*
36      * Test method for 'com.ibm.icu.text.CollationKey.compareTo(CollationKey)'
37      */
38     public void testCompareToCollationKey() {
39         Collator c = Collator.getInstance();
40         c.setStrength(Collator.PRIMARY);
41         CollationKey k1 = c.getCollationKey("This");
42         CollationKey k2 = c.getCollationKey("this");
43         c.setStrength(Collator.TERTIARY);
44         CollationKey k3 = c.getCollationKey("this");
45         assertTrue(0 == k1.compareTo(k2));
46         assertFalse(0 == k1.compareTo(k3));
47     }
48
49     /*
50      * Test method for 'com.ibm.icu.text.CollationKey.compareTo(Object)'
51      */
52     public void testCompareToObject() {
53         Collator c = Collator.getInstance();
54         c.setStrength(Collator.PRIMARY);
55         CollationKey k1 = c.getCollationKey("This");
56         CollationKey k2 = c.getCollationKey("this");
57         assertTrue(0 == k1.compareTo(k2));
58     }
59
60     /*
61      * Test method for 'com.ibm.icu.text.CollationKey.equals(Object)'
62      */
63     public void testEqualsObject() {
64         Collator c = Collator.getInstance();
65         c.setStrength(Collator.PRIMARY);
66         CollationKey k1 = c.getCollationKey("This");
67         CollationKey k2 = c.getCollationKey("this");
68         assertTrue(k1.equals((Object)k2));
69     }
70
71     /*
72      * Test method for 'com.ibm.icu.text.CollationKey.toString()'
73      */
74     public void testToString() {
75         Collator c = Collator.getInstance();
76         c.setStrength(Collator.PRIMARY);
77         CollationKey k1 = c.getCollationKey("This");
78         assertNotNull(k1.toString());
79     }
80
81     /*
82      * Test method for 'com.ibm.icu.text.CollationKey.getSourceString()'
83      */
84     public void testGetSourceString() {
85         Collator c = Collator.getInstance();
86         c.setStrength(Collator.PRIMARY);
87         CollationKey k1 = c.getCollationKey("This");
88         assertEquals("This", k1.getSourceString());
89     }
90
91     /*
92      * Test method for 'com.ibm.icu.text.CollationKey.toByteArray()'
93      */
94     public void testToByteArray() {
95         Collator c = Collator.getInstance();
96         c.setStrength(Collator.PRIMARY);
97         CollationKey k1 = c.getCollationKey("This");
98         byte[] key = k1.toByteArray();
99         assertNotNull(key);
100         assertTrue(0 < key.length);
101     }
102 }