home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / ccolltst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  4.7 KB  |  167 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1996                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1999                    *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. ********************************************************************************
  13. *
  14. * File CCOLLTST.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *     Madhu Katragadda               Creation
  19. *********************************************************************************
  20. */
  21. #include "cintltst.h"
  22. #include "ccolltst.h"
  23. #include "ucol.h"
  24. #include <string.h>
  25. #include "ustring.h"
  26. #include <stdio.h>
  27.  
  28. void addCollAPITest(TestNode**);
  29. void addCurrencyTest(TestNode**);
  30. void addNormTest(TestNode**);
  31. void addDanishCollTest(TestNode**);
  32. void addGermanCollTest(TestNode**);
  33. void addSpanishCollTest(TestNode**);
  34. void addFrenchCollTest(TestNode**);
  35. void addKannaCollTest(TestNode**);
  36. void addTurkishCollTest(TestNode**);
  37. void addEnglishCollTest(TestNode**);
  38. void addAllCollTest(TestNode**);
  39.  
  40. void addRuleBasedCollTest(TestNode**);
  41. void addCollIterTest(TestNode**);
  42.  
  43. void addCollTest(TestNode** root)
  44. {
  45.     addCollAPITest(root);
  46.     addCurrencyTest(root);
  47.     addNormTest(root);
  48.     addDanishCollTest(root);
  49.     addGermanCollTest(root);
  50.     addSpanishCollTest(root);
  51.     addFrenchCollTest(root);
  52.     addKannaCollTest(root);
  53.     addTurkishCollTest(root);
  54.     addEnglishCollTest(root);
  55.     
  56.  
  57.     addRuleBasedCollTest(root);
  58.     addCollIterTest(root);
  59.     addAllCollTest(root);
  60. }
  61.  
  62.  
  63.  
  64. /*Internal functions used*/
  65.  
  66. void reportCResult( const UChar source[], const UChar target[], 
  67.                          uint8_t *sourceKey, uint8_t *targetKey,
  68.                          UCollationResult compareResult,
  69.                          UCollationResult keyResult,
  70.                          UCollationResult expectedResult )
  71. {
  72.     UChar *sResult, *sExpect;
  73.     sResult=(UChar*)malloc(sizeof(UChar) * 10);
  74.     sExpect=(UChar*)malloc(sizeof(UChar) * 10);
  75.     if (expectedResult < -1 || expectedResult > 1)
  76.     {
  77.         log_err("***** invalid call to reportCResult ****\n");
  78.         return;
  79.     }
  80.  
  81.     if (compareResult != expectedResult)
  82.     {
  83.         
  84.         appendCompareResult(compareResult, sResult);
  85.         appendCompareResult(expectedResult, sExpect);
  86.         log_err("Compare(%s , %s) returned: %s expected: %s\n", austrdup(source), austrdup(target),
  87.             austrdup(sResult), austrdup(sExpect) );
  88.     }
  89.  
  90.     if (keyResult != expectedResult)
  91.     {
  92.     
  93.         appendCompareResult(keyResult, sResult);
  94.         appendCompareResult(expectedResult, sExpect);
  95.  
  96.         log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", austrdup(source), austrdup(target), 
  97.             austrdup(sResult), austrdup(sExpect) );
  98.  
  99.     
  100.     }
  101.     free(sExpect);
  102.     free(sResult);
  103. }
  104.  
  105. UChar* appendCompareResult(UCollationResult result, UChar* target)
  106. {
  107.     if (result == UCOL_LESS)
  108.     {
  109.         u_uastrcpy(target, "LESS");
  110.     }
  111.     else if (result == UCOL_EQUAL)
  112.     {
  113.         u_uastrcpy(target, "EQUAL");
  114.     }
  115.     else if (result == UCOL_GREATER)
  116.     {
  117.         u_uastrcpy(target, "GREATER");
  118.     }
  119.     else
  120.     {
  121.         u_uastrcpy(target, "huh???");
  122.             
  123.     }
  124.  
  125.     return target;
  126. }
  127.  
  128. UChar* CharsToUChars(const char* chars)
  129. {
  130.     int unicode;
  131.     int i;
  132.     UChar *buffer;
  133.     UChar *alias;
  134.     int len = strlen(chars);
  135.     int count = 0;
  136.  
  137.     /* preflight */
  138.     for (i = 0; i < len;) {
  139.         if ((chars[i] == '\\') && (i+1 < len) && (chars[i+1] == 'u')) {
  140.             ++count;
  141.             i += 6;
  142.         } else {
  143.             ++count;
  144.             i++;
  145.         }
  146.     }
  147.  
  148.     buffer = (UChar*) malloc(sizeof(UChar) * (count + 1));
  149.     alias = buffer;
  150.     
  151.     for (i = 0; i < len;) {
  152.         if ((chars[i] == '\\') && (i+1 < len) && (chars[i+1] == 'u')) {
  153.             
  154.             sscanf(&(chars[i+2]), "%4X", &unicode);
  155.             *alias = (UChar)unicode;
  156.             i += 6;
  157.             ++alias;
  158.         } else {
  159.             *alias = (UChar)chars[i];
  160.             ++alias;
  161.             ++i;
  162.            }
  163.     }
  164.     *alias = 0x0000;
  165.     return buffer;
  166. }
  167.