001: /*
002: *******************************************************************************
003: * Copyright (C) 2002-2005, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007:
008: /**
009: * Port From: ICU4C v2.1 : Collate/CollationEnglishTest
010: * Source File: $ICU4CRoot/source/test/intltest/encoll.cpp
011: **/package com.ibm.icu.dev.test.collator;
012:
013: import com.ibm.icu.dev.test.*;
014: import com.ibm.icu.text.*;
015:
016: import java.util.Locale;
017:
018: public class CollationEnglishTest extends TestFmwk {
019: public static void main(String[] args) throws Exception {
020: new CollationEnglishTest().run(args);
021: }
022:
023: private static char[][] testSourceCases = {
024: { 0x0061 /* 'a' */, 0x0062 /* 'b' */},
025: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
026: 0x0063 /* 'c' */, 0x006B /* 'k' */,
027: 0x002D /* '-' */, 0x0062 /* 'b' */,
028: 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
029: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
030: 0x0063 /* 'c' */, 0x006B /* 'k' */,
031: 0x0020 /* ' ' */, 0x0062 /* 'b' */,
032: 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
033: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
034: 0x0063 /* 'c' */, 0x006B /* 'k' */,
035: 0x002D /* '-' */, 0x0062 /* 'b' */,
036: 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
037: { 0x0048 /* 'H' */, 0x0065 /* 'e' */, 0x006C /* 'l' */,
038: 0x006C /* 'l' */, 0x006F /* 'o' */},
039: { 0x0041 /* 'A' */, 0x0042 /* 'B' */, 0x0043 /* 'C' */},
040: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
041: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
042: 0x0063 /* 'c' */, 0x006B /* 'k' */,
043: 0x0062 /* 'b' */, 0x0069 /* 'i' */,
044: 0x0072 /* 'r' */, 0x0064 /* 'd' */},
045: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
046: 0x0063 /* 'c' */, 0x006B /* 'k' */,
047: 0x002D /* '-' */, 0x0062 /* 'b' */,
048: 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
049: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
050: 0x0063 /* 'c' */, 0x006B /* 'k' */,
051: 0x002D /* '-' */, 0x0062 /* 'b' */,
052: 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
053: { 0x0070 /* 'p' */, 0x00EA, 0x0063 /* 'c' */,
054: 0x0068 /* 'h' */, 0x0065 /* 'e' */},
055: { 0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */,
056: 0x0068 /* 'h' */, 0x00E9 },
057: { 0x00C4, 0x0042 /* 'B' */, 0x0308, 0x0043 /* 'C' */,
058: 0x0308 },
059: { 0x0061 /* 'a' */, 0x0308, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
060: { 0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */,
061: 0x0068 /* 'h' */, 0x0065 /* 'e' */, 0x0072 /* 'r' */},
062: { 0x0072 /* 'r' */, 0x006F /* 'o' */, 0x006C /* 'l' */,
063: 0x0065 /* 'e' */, 0x0073 /* 's' */},
064: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
065: { 0x0041 /* 'A' */},
066: { 0x0041 /* 'A' */},
067: { 0x0061 /* 'a' */, 0x0062 /* 'b' */},
068: { 0x0074 /* 't' */, 0x0063 /* 'c' */, 0x006F /* 'o' */,
069: 0x006D /* 'm' */, 0x0070 /* 'p' */,
070: 0x0061 /* 'a' */, 0x0072 /* 'r' */,
071: 0x0065 /* 'e' */, 0x0070 /* 'p' */,
072: 0x006C /* 'l' */, 0x0061 /* 'a' */,
073: 0x0069 /* 'i' */, 0x006E /* 'n' */},
074: { 0x0061 /* 'a' */, 0x0062 /* 'b' */},
075: { 0x0061 /* 'a' */, 0x0023 /* '#' */, 0x0062 /* 'b' */},
076: { 0x0061 /* 'a' */, 0x0023 /* '#' */, 0x0062 /* 'b' */},
077: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
078: { 0x0041 /* 'A' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
079: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
080: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
081: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
082: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
083: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
084: { 0x00E6, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
085: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
086: { 0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
087: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
088: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
089: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
090: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
091: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
092: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
093: { 0x0061 /* 'a' */, 0x0063 /* 'c' */, 0x0048 /* 'H' */,
094: 0x0063 /* 'c' */},
095: { 0x0061 /* 'a' */, 0x0308, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
096: { 0x0074 /* 't' */, 0x0068 /* 'h' */, 0x0069 /* 'i' */,
097: 0x0302, 0x0073 /* 's' */},
098: { 0x0070 /* 'p' */, 0x00EA, 0x0063 /* 'c' */,
099: 0x0068 /* 'h' */, 0x0065 /* 'e' */},
100: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
101: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
102: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
103: { 0x0061 /* 'a' */, 0x00E6, 0x0063 /* 'c' */},
104: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
105: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
106: { 0x0061 /* 'a' */, 0x00E6, 0x0063 /* 'c' */},
107: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
108: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
109: { 0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */,
110: 0x0068 /* 'h' */, 0x00E9 } // 49
111: };
112:
113: private static char[][] testTargetCases = {
114: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
115: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
116: 0x0063 /* 'c' */, 0x006B /* 'k' */,
117: 0x0062 /* 'b' */, 0x0069 /* 'i' */,
118: 0x0072 /* 'r' */, 0x0064 /* 'd' */},
119: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
120: 0x0063 /* 'c' */, 0x006B /* 'k' */,
121: 0x002D /* '-' */, 0x0062 /* 'b' */,
122: 0x0069 /* 'i' */, 0x0072 /* 'r' */, 0x0064 /* 'd' */},
123: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
124: 0x0063 /* 'c' */, 0x006B /* 'k' */},
125: { 0x0068 /* 'h' */, 0x0065 /* 'e' */, 0x006C /* 'l' */,
126: 0x006C /* 'l' */, 0x006F /* 'o' */},
127: { 0x0041 /* 'A' */, 0x0042 /* 'B' */, 0x0043 /* 'C' */},
128: { 0x0041 /* 'A' */, 0x0042 /* 'B' */, 0x0043 /* 'C' */},
129: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
130: 0x0063 /* 'c' */, 0x006B /* 'k' */,
131: 0x0062 /* 'b' */, 0x0069 /* 'i' */,
132: 0x0072 /* 'r' */, 0x0064 /* 'd' */, 0x0073 /* 's' */},
133: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
134: 0x0063 /* 'c' */, 0x006B /* 'k' */,
135: 0x0062 /* 'b' */, 0x0069 /* 'i' */,
136: 0x0072 /* 'r' */, 0x0064 /* 'd' */, 0x0073 /* 's' */},
137: { 0x0062 /* 'b' */, 0x006C /* 'l' */, 0x0061 /* 'a' */,
138: 0x0063 /* 'c' */, 0x006B /* 'k' */,
139: 0x0062 /* 'b' */, 0x0069 /* 'i' */,
140: 0x0072 /* 'r' */, 0x0064 /* 'd' */},
141: { 0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */,
142: 0x0068 /* 'h' */, 0x00E9 },
143: { 0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */,
144: 0x0068 /* 'h' */, 0x0065 /* 'e' */, 0x0072 /* 'r' */},
145: { 0x00C4, 0x0042 /* 'B' */, 0x0308, 0x0043 /* 'C' */,
146: 0x0308 },
147: { 0x0041 /* 'A' */, 0x0308, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
148: { 0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */,
149: 0x0068 /* 'h' */, 0x0065 /* 'e' */},
150: { 0x0072 /* 'r' */, 0x006F /* 'o' */, 0x0302,
151: 0x006C /* 'l' */, 0x0065 /* 'e' */},
152: { 0x0041 /* 'A' */, 0x00E1, 0x0063 /* 'c' */, 0x0064 /* 'd' */},
153: { 0x0041 /* 'A' */, 0x00E1, 0x0063 /* 'c' */, 0x0064 /* 'd' */},
154: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
155: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
156: { 0x0054 /* 'T' */, 0x0043 /* 'C' */, 0x006F /* 'o' */,
157: 0x006D /* 'm' */, 0x0070 /* 'p' */,
158: 0x0061 /* 'a' */, 0x0072 /* 'r' */,
159: 0x0065 /* 'e' */, 0x0050 /* 'P' */,
160: 0x006C /* 'l' */, 0x0061 /* 'a' */,
161: 0x0069 /* 'i' */, 0x006E /* 'n' */},
162: { 0x0061 /* 'a' */, 0x0042 /* 'B' */, 0x0063 /* 'c' */},
163: { 0x0061 /* 'a' */, 0x0023 /* '#' */, 0x0042 /* 'B' */},
164: { 0x0061 /* 'a' */, 0x0026 /* '&' */, 0x0062 /* 'b' */},
165: { 0x0061 /* 'a' */, 0x0023 /* '#' */, 0x0063 /* 'c' */},
166: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
167: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
168: { 0x00C4, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
169: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
170: { 0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
171: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
172: { 0x00C4, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
173: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
174: { 0x00C4, 0x0062 /* 'b' */, 0x0063 /* 'c' */,
175: 0x0064 /* 'd' */, 0x0061 /* 'a' */},
176: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0023 /* '#' */,
177: 0x0063 /* 'c' */},
178: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
179: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x003D /* '=' */,
180: 0x0063 /* 'c' */},
181: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0064 /* 'd' */},
182: { 0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
183: { 0x0061 /* 'a' */, 0x0043 /* 'C' */, 0x0048 /* 'H' */,
184: 0x0063 /* 'c' */},
185: { 0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
186: { 0x0074 /* 't' */, 0x0068 /* 'h' */, 0x00EE, 0x0073 /* 's' */},
187: { 0x0070 /* 'p' */, 0x00E9, 0x0063 /* 'c' */,
188: 0x0068 /* 'h' */, 0x00E9 },
189: { 0x0061 /* 'a' */, 0x0042 /* 'B' */, 0x0043 /* 'C' */},
190: { 0x0061 /* 'a' */, 0x0062 /* 'b' */, 0x0064 /* 'd' */},
191: { 0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
192: { 0x0061 /* 'a' */, 0x00C6, 0x0063 /* 'c' */},
193: { 0x0061 /* 'a' */, 0x0042 /* 'B' */, 0x0064 /* 'd' */},
194: { 0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
195: { 0x0061 /* 'a' */, 0x00C6, 0x0063 /* 'c' */},
196: { 0x0061 /* 'a' */, 0x0042 /* 'B' */, 0x0064 /* 'd' */},
197: { 0x00E4, 0x0062 /* 'b' */, 0x0063 /* 'c' */},
198: { 0x0070 /* 'p' */, 0x00EA, 0x0063 /* 'c' */,
199: 0x0068 /* 'h' */, 0x0065 /* 'e' */} }; // 49
200:
201: private static int[] results = {
202: //-1:LESS; 0:EQUAL; 1:GREATER
203: -1, -1, /*Collator::GREATER,*/
204: -1, 1, 1, 0, -1, -1, -1, -1, /*Collator::GREATER,*//* 10 */
205: 1, -1, 0, -1, 1, 1, 1, -1, -1, -1, /* 20 */
206: -1, -1, -1, 1, 1, 1,
207: /* Test Tertiary > 26 */
208: -1, -1, 1, -1, /* 30 */
209: 1, 0, 1, -1, -1, -1,
210: /* test identical > 36 */
211: 0, 0,
212: /* test primary > 38 */
213: 0, 0, /* 40 */
214: -1, 0, 0,
215: /* test secondary > 43 */
216: -1, -1, 0, -1, -1, -1 // 49
217: };
218:
219: private static char[][] testBugs = { { 0x61 }, { 0x41 }, { 0x65 },
220: { 0x45 }, { 0x00e9 }, { 0x00e8 }, { 0x00ea }, { 0x00eb },
221: { 0x65, 0x61 }, { 0x78 } };
222:
223: // 0x0300 is grave, 0x0301 is acute
224: // the order of elements in this array must be different than the order in CollationFrenchTest
225: private static char[][] testAcute = { { 0x65, 0x65 },
226: { 0x65, 0x65, 0x0301 }, { 0x65, 0x65, 0x0301, 0x0300 },
227: { 0x65, 0x65, 0x0300 }, { 0x65, 0x65, 0x0300, 0x0301 },
228: { 0x65, 0x0301, 0x65 }, { 0x65, 0x0301, 0x65, 0x0301 },
229: { 0x65, 0x0301, 0x65, 0x0301, 0x0300 },
230: { 0x65, 0x0301, 0x65, 0x0300 },
231: { 0x65, 0x0301, 0x65, 0x0300, 0x0301 },
232: { 0x65, 0x0301, 0x0300, 0x65 },
233: { 0x65, 0x0301, 0x0300, 0x65, 0x0301 },
234: { 0x65, 0x0301, 0x0300, 0x65, 0x0301, 0x0300 },
235: { 0x65, 0x0301, 0x0300, 0x65, 0x0300 },
236: { 0x65, 0x0301, 0x0300, 0x65, 0x0300, 0x0301 },
237: { 0x65, 0x0300, 0x65 }, { 0x65, 0x0300, 0x65, 0x0301 },
238: { 0x65, 0x0300, 0x65, 0x0301, 0x0300 },
239: { 0x65, 0x0300, 0x65, 0x0300 },
240: { 0x65, 0x0300, 0x65, 0x0300, 0x0301 },
241: { 0x65, 0x0300, 0x0301, 0x65 },
242: { 0x65, 0x0300, 0x0301, 0x65, 0x0301 },
243: { 0x65, 0x0300, 0x0301, 0x65, 0x0301, 0x0300 },
244: { 0x65, 0x0300, 0x0301, 0x65, 0x0300 },
245: { 0x65, 0x0300, 0x0301, 0x65, 0x0300, 0x0301 } };
246:
247: private static char[][] testMore = {
248: { 0x0061 /* 'a' */, 0x0065 /* 'e' */}, { 0x00E6 },
249: { 0x00C6 }, { 0x0061 /* 'a' */, 0x0066 /* 'f' */},
250: { 0x006F /* 'o' */, 0x0065 /* 'e' */}, { 0x0153 },
251: { 0x0152 }, { 0x006F /* 'o' */, 0x0066 /* 'f' */}, };
252:
253: private Collator myCollation = null;
254:
255: public CollationEnglishTest() {
256: }
257:
258: protected void init() throws Exception {
259: myCollation = Collator.getInstance(Locale.ENGLISH);
260: }
261:
262: //performs test with strength PRIMARY
263: public void TestPrimary() {
264: int i;
265: myCollation.setStrength(Collator.PRIMARY);
266: for (i = 38; i < 43; i++) {
267: doTest(testSourceCases[i], testTargetCases[i], results[i]);
268: }
269: }
270:
271: //perform test with strength SECONDARY
272: public void TestSecondary() {
273: int i;
274: myCollation.setStrength(Collator.SECONDARY);
275: for (i = 43; i < 49; i++) {
276: doTest(testSourceCases[i], testTargetCases[i], results[i]);
277: }
278:
279: //test acute and grave ordering (compare to french collation)
280: int j;
281: int expected;
282: for (i = 0; i < testAcute.length; i++) {
283: for (j = 0; j < testAcute.length; j++) {
284: logln("i = " + i + "; j = " + j);
285: if (i < j)
286: expected = -1;
287: else if (i == j)
288: expected = 0;
289: else
290: // (i > j)
291: expected = 1;
292: doTest(testAcute[i], testAcute[j], expected);
293: }
294: }
295: }
296:
297: //perform test with strength TERTIARY
298: public void TestTertiary() {
299: int i = 0;
300: myCollation.setStrength(Collator.TERTIARY);
301: //for (i = 0; i < 38 ; i++) //attention: there is something wrong with 36, 37.
302: for (i = 0; i < 38; i++) {
303: doTest(testSourceCases[i], testTargetCases[i], results[i]);
304: }
305:
306: int j = 0;
307: for (i = 0; i < 10; i++) {
308: for (j = i + 1; j < 10; j++) {
309: doTest(testBugs[i], testBugs[j], -1);
310: }
311: }
312:
313: //test more interesting cases
314: int expected;
315: for (i = 0; i < testMore.length; i++) {
316: for (j = 0; j < testMore.length; j++) {
317: if (i < j)
318: expected = -1;
319: else if (i == j)
320: expected = 0;
321: else
322: // (i > j)
323: expected = 1;
324: doTest(testMore[i], testMore[j], expected);
325: }
326: }
327: }
328:
329: // main test routine, tests rules defined by the "en" locale
330: private void doTest(char[] source, char[] target, int result) {
331:
332: String s = new String(source);
333: String t = new String(target);
334: int compareResult = myCollation.compare(s, t);
335: CollationKey sortKey1, sortKey2;
336: sortKey1 = myCollation.getCollationKey(s);
337: sortKey2 = myCollation.getCollationKey(t);
338: int keyResult = sortKey1.compareTo(sortKey2);
339: reportCResult(s, t, sortKey1, sortKey2, compareResult,
340: keyResult, compareResult, result);
341:
342: }
343:
344: private void reportCResult(String source, String target,
345: CollationKey sourceKey, CollationKey targetKey,
346: int compareResult, int keyResult, int incResult,
347: int expectedResult) {
348: if (expectedResult < -1 || expectedResult > 1) {
349: errln("***** invalid call to reportCResult ****");
350: return;
351: }
352:
353: boolean ok1 = (compareResult == expectedResult);
354: boolean ok2 = (keyResult == expectedResult);
355: boolean ok3 = (incResult == expectedResult);
356:
357: if (ok1 && ok2 && ok3 && !isVerbose()) {
358: return;
359: } else {
360: String msg1 = ok1 ? "Ok: compare(\"" : "FAIL: compare(\"";
361: String msg2 = "\", \"";
362: String msg3 = "\") returned ";
363: String msg4 = "; expected ";
364:
365: String sExpect = new String("");
366: String sResult = new String("");
367: sResult = appendCompareResult(compareResult, sResult);
368: sExpect = appendCompareResult(expectedResult, sExpect);
369: if (ok1) {
370: logln(msg1 + source + msg2 + target + msg3 + sResult);
371: } else {
372: errln(msg1 + source + msg2 + target + msg3 + sResult
373: + msg4 + sExpect);
374: }
375:
376: msg1 = ok2 ? "Ok: key(\"" : "FAIL: key(\"";
377: msg2 = "\").compareTo(key(\"";
378: msg3 = "\")) returned ";
379: sResult = appendCompareResult(keyResult, sResult);
380: if (ok2) {
381: logln(msg1 + source + msg2 + target + msg3 + sResult);
382: } else {
383: errln(msg1 + source + msg2 + target + msg3 + sResult
384: + msg4 + sExpect);
385: msg1 = " ";
386: msg2 = " vs. ";
387: errln(msg1 + prettify(sourceKey) + msg2
388: + prettify(targetKey));
389: }
390:
391: msg1 = ok3 ? "Ok: incCompare(\"" : "FAIL: incCompare(\"";
392: msg2 = "\", \"";
393: msg3 = "\") returned ";
394:
395: sResult = appendCompareResult(incResult, sResult);
396:
397: if (ok3) {
398: logln(msg1 + source + msg2 + target + msg3 + sResult);
399: } else {
400: errln(msg1 + source + msg2 + target + msg3 + sResult
401: + msg4 + sExpect);
402: }
403: }
404: }
405:
406: private String appendCompareResult(int result, String target) {
407: if (result == -1) //LESS
408: {
409: target += "LESS";
410: } else if (result == 0) //EQUAL
411: {
412: target += "EQUAL";
413: } else if (result == 1) //GREATER
414: {
415: target += "GREATER";
416: } else {
417: String huh = "?";
418:
419: target += huh + result;
420: }
421: return target;
422: }
423:
424: String prettify(CollationKey sourceKey) {
425: int i;
426: byte[] bytes = sourceKey.toByteArray();
427: String target = "[";
428:
429: for (i = 0; i < bytes.length; i++) {
430: target += Integer.toHexString(bytes[i]);
431: target += " ";
432: }
433: target += "]";
434: return target;
435: }
436: }
|