OLD | NEW |
(Empty) | |
| 1 /******************************************************************** |
| 2 * COPYRIGHT: |
| 3 * Copyright (c) 1997-2009, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. |
| 5 ********************************************************************/ |
| 6 /*******************************************************************************
* |
| 7 * |
| 8 * File CCOLLTST.C |
| 9 * |
| 10 * Modification History: |
| 11 * Name Description |
| 12 * Madhu Katragadda Creation |
| 13 ********************************************************************************
* |
| 14 */ |
| 15 #include <stdio.h> |
| 16 |
| 17 #include "unicode/utypes.h" |
| 18 |
| 19 #if !UCONFIG_NO_COLLATION |
| 20 |
| 21 #include "cintltst.h" |
| 22 #include "ccolltst.h" |
| 23 #include "unicode/ucol.h" |
| 24 #include "unicode/ustring.h" |
| 25 #include "cmemory.h" |
| 26 |
| 27 void addCollTest(TestNode** root); |
| 28 |
| 29 void addCollTest(TestNode** root) |
| 30 { |
| 31 addCollAPITest(root); |
| 32 addCurrencyCollTest(root); |
| 33 addNormTest(root); |
| 34 addGermanCollTest(root); |
| 35 addSpanishCollTest(root); |
| 36 addFrenchCollTest(root); |
| 37 addKannaCollTest(root); |
| 38 addTurkishCollTest(root); |
| 39 addEnglishCollTest(root); |
| 40 addFinnishCollTest(root); |
| 41 |
| 42 /* WEIVTODO: return tests here */ |
| 43 addRuleBasedCollTest(root); |
| 44 addCollIterTest(root); |
| 45 addAllCollTest(root); |
| 46 addMiscCollTest(root); |
| 47 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO |
| 48 addSearchTest(root); |
| 49 #endif |
| 50 } |
| 51 |
| 52 |
| 53 |
| 54 /*Internal functions used*/ |
| 55 static char* dumpSk(uint8_t *sourceKey, char *sk) { |
| 56 uint32_t kLen = (uint32_t)strlen((const char *)sourceKey); |
| 57 uint32_t i = 0; |
| 58 |
| 59 *sk = 0; |
| 60 |
| 61 for(i = 0; i<kLen; i++) { |
| 62 sprintf(sk+2*i, "%02X", sourceKey[i]); |
| 63 } |
| 64 return sk; |
| 65 } |
| 66 |
| 67 static const char *getCompareResult(UCollationResult result) |
| 68 { |
| 69 if (result == UCOL_LESS) |
| 70 { |
| 71 return "LESS"; |
| 72 } |
| 73 else if (result == UCOL_EQUAL) |
| 74 { |
| 75 return "EQUAL"; |
| 76 } |
| 77 else if (result == UCOL_GREATER) |
| 78 { |
| 79 return "GREATER"; |
| 80 } |
| 81 return "invalid UCollationResult?"; |
| 82 } |
| 83 |
| 84 void reportCResult( const UChar source[], const UChar target[], |
| 85 uint8_t *sourceKey, uint8_t *targetKey, |
| 86 UCollationResult compareResult, |
| 87 UCollationResult keyResult, |
| 88 UCollationResult incResult, |
| 89 UCollationResult expectedResult ) |
| 90 { |
| 91 if (expectedResult < -1 || expectedResult > 1) |
| 92 { |
| 93 log_err("***** invalid call to reportCResult ****\n"); |
| 94 return; |
| 95 } |
| 96 |
| 97 if (compareResult != expectedResult) |
| 98 { |
| 99 log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(sourc
e,-1), aescstrdup(target,-1), |
| 100 getCompareResult(compareResult), getCompareResult(expectedResult) ); |
| 101 } |
| 102 |
| 103 if (incResult != expectedResult) |
| 104 { |
| 105 log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(so
urce,-1), aescstrdup(target,-1), |
| 106 getCompareResult(incResult), getCompareResult(expectedResult) ); |
| 107 } |
| 108 |
| 109 if (keyResult != expectedResult) |
| 110 { |
| 111 log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(so
urce,-1), aescstrdup(target,-1), |
| 112 getCompareResult(keyResult), getCompareResult(expectedResult) ); |
| 113 } |
| 114 |
| 115 if (keyResult != compareResult) |
| 116 { |
| 117 log_err("difference between sortkey and compare result for (%s , %s) Key
s: %s compare %s\n", aescstrdup(source,-1), aescstrdup(target,-1), |
| 118 getCompareResult(keyResult), getCompareResult(compareResult)); |
| 119 } |
| 120 |
| 121 if(keyResult != expectedResult || keyResult != compareResult) |
| 122 { |
| 123 char sk[10000]; |
| 124 log_verbose("SortKey1: %s\n", dumpSk(sourceKey, sk)); |
| 125 log_verbose("SortKey2: %s\n", dumpSk(targetKey, sk)); |
| 126 } |
| 127 } |
| 128 |
| 129 #endif /* #if !UCONFIG_NO_COLLATION */ |
OLD | NEW |