home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / encoll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  22.1 KB  |  378 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 encoll.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *     Madhu Katragadda            Ported for C API
  19. *********************************************************************************
  20. /**
  21.  * CollationEnglishTest is a third level test class.  This tests the locale
  22.  * specific primary, secondary and tertiary rules.  For example, the ignorable
  23.  * character '-' in string "black-bird".  The en_US locale uses the default
  24.  * collation rules as its sorting sequence.
  25.  */
  26.  
  27. #include "utypes.h"
  28. #include "ucol.h"
  29. #include "uloc.h"
  30. #include "cintltst.h"
  31. #include "encoll.h"
  32. #include "ccolltst.h"
  33. #include "ustring.h"
  34. #include <string.h>
  35. #include <memory.h>
  36. static UCollator *myCollation = NULL;
  37. const static UChar testSourceCases[][MAX_TOKEN_LEN] = {
  38.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, 0},
  39.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x002D /* '-' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, 0},
  40.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x0020 /* ' ' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, 0},
  41.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x002D /* '-' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, 0},
  42.         {(UChar)0x0048 /* 'H' */, (UChar)0x0065 /* 'e' */, (UChar)0x006C /* 'l' */, (UChar)0x006C /* 'l' */, (UChar)0x006F /* 'o' */, 0},
  43.         {(UChar)0x0041 /* 'A' */, (UChar)0x0042 /* 'B' */, (UChar)0x0043 /* 'C' */, 0}, 
  44.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  45.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, 0},
  46.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x002D /* '-' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, 0},
  47.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x002D /* '-' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, 0},
  48.         {(UChar)0x0070 /* 'p' */, 0x00EA, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, (UChar)0x0065 /* 'e' */, 0},                                            
  49.         {(UChar)0x0070 /* 'p' */, 0x00E9, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, 0x00E9, 0},
  50.         {0x00C4, (UChar)0x0042 /* 'B' */, 0x0308, (UChar)0x0043 /* 'C' */, 0x0308, 0},
  51.         {(UChar)0x0061 /* 'a' */, 0x0308, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  52.         {(UChar)0x0070 /* 'p' */, 0x00E9, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, (UChar)0x0065 /* 'e' */, (UChar)0x0072 /* 'r' */, 0},
  53.         {(UChar)0x0072 /* 'r' */, (UChar)0x006F /* 'o' */, (UChar)0x006C /* 'l' */, (UChar)0x0065 /* 'e' */, (UChar)0x0073 /* 's' */, 0},
  54.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  55.         {(UChar)0x0041 /* 'A' */, 0},
  56.         {(UChar)0x0041 /* 'A' */, 0},
  57.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, 0},                                                                
  58.         {(UChar)0x0074 /* 't' */, (UChar)0x0063 /* 'c' */, (UChar)0x006F /* 'o' */, (UChar)0x006D /* 'm' */, (UChar)0x0070 /* 'p' */, (UChar)0x0061 /* 'a' */, (UChar)0x0072 /* 'r' */, (UChar)0x0065 /* 'e' */, (UChar)0x0070 /* 'p' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0069 /* 'i' */, (UChar)0x006E /* 'n' */, 0},
  59.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, 0}, 
  60.         {(UChar)0x0061 /* 'a' */, (UChar)0x0023 /* '#' */, (UChar)0x0062 /* 'b' */, 0},
  61.         {(UChar)0x0061 /* 'a' */, (UChar)0x0023 /* '#' */, (UChar)0x0062 /* 'b' */, 0},
  62.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  63.         {(UChar)0x0041 /* 'A' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},
  64.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},
  65.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},
  66.         {0x00E6, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},
  67.         {0x00E4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},                                            
  68.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  69.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  70.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  71.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  72.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  73.         {(UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x0048 /* 'H' */, (UChar)0x0063 /* 'c' */, 0},
  74.         {(UChar)0x0061 /* 'a' */, 0x0308, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  75.         {(UChar)0x0074 /* 't' */, (UChar)0x0068 /* 'h' */, (UChar)0x0069 /* 'i' */, 0x0302, (UChar)0x0073 /* 's' */, 0},
  76.         {(UChar)0x0070 /* 'p' */, 0x00EA, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, (UChar)0x0065 /* 'e' */},
  77.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},                                                         
  78.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  79.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  80.         {(UChar)0x0061 /* 'a' */, 0x00E6, (UChar)0x0063 /* 'c' */, 0},
  81.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  82.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  83.         {(UChar)0x0061 /* 'a' */, 0x00E6, (UChar)0x0063 /* 'c' */, 0},
  84.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  85.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},               
  86.         {(UChar)0x0070 /* 'p' */, 0x00E9, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, 0x00E9, 0}                                            
  87. };
  88.  
  89. const static UChar testTargetCases[][MAX_TOKEN_LEN] = {
  90.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  91.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, 0},
  92.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x002D /* '-' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, 0},
  93.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, 0},
  94.         {(UChar)0x0068 /* 'h' */, (UChar)0x0065 /* 'e' */, (UChar)0x006C /* 'l' */, (UChar)0x006C /* 'l' */, (UChar)0x006F /* 'o' */, 0},
  95.         {(UChar)0x0041 /* 'A' */, (UChar)0x0042 /* 'B' */, (UChar)0x0043 /* 'C' */, 0},
  96.         {(UChar)0x0041 /* 'A' */, (UChar)0x0042 /* 'B' */, (UChar)0x0043 /* 'C' */, 0},
  97.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, (UChar)0x0073 /* 's' */, 0},
  98.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, (UChar)0x0073 /* 's' */, 0},
  99.         {(UChar)0x0062 /* 'b' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0063 /* 'c' */, (UChar)0x006B /* 'k' */, (UChar)0x0062 /* 'b' */, (UChar)0x0069 /* 'i' */, (UChar)0x0072 /* 'r' */, (UChar)0x0064 /* 'd' */, 0},                             
  100.         {(UChar)0x0070 /* 'p' */, 0x00E9, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, 0x00E9, 0},
  101.         {(UChar)0x0070 /* 'p' */, 0x00E9, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, (UChar)0x0065 /* 'e' */, (UChar)0x0072 /* 'r' */, 0},
  102.         {0x00C4, (UChar)0x0042 /* 'B' */, 0x0308, (UChar)0x0043 /* 'C' */, 0x0308, 0},
  103.         {(UChar)0x0041 /* 'A' */, 0x0308, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  104.         {(UChar)0x0070 /* 'p' */, 0x00E9, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, (UChar)0x0065 /* 'e' */, 0},
  105.         {(UChar)0x0072 /* 'r' */, (UChar)0x006F /* 'o' */, 0x0302, (UChar)0x006C /* 'l' */, (UChar)0x0065 /* 'e' */, 0},
  106.         {(UChar)0x0041 /* 'A' */, 0x00E1, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, 0},
  107.         {(UChar)0x0041 /* 'A' */, 0x00E1, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, 0},
  108.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  109.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},                                                             
  110.         {(UChar)0x0054 /* 'T' */, (UChar)0x0043 /* 'C' */, (UChar)0x006F /* 'o' */, (UChar)0x006D /* 'm' */, (UChar)0x0070 /* 'p' */, (UChar)0x0061 /* 'a' */, (UChar)0x0072 /* 'r' */, (UChar)0x0065 /* 'e' */, (UChar)0x0050 /* 'P' */, (UChar)0x006C /* 'l' */, (UChar)0x0061 /* 'a' */, (UChar)0x0069 /* 'i' */, (UChar)0x006E /* 'n' */, 0},
  111.         {(UChar)0x0061 /* 'a' */, (UChar)0x0042 /* 'B' */, (UChar)0x0063 /* 'c' */, 0},
  112.         {(UChar)0x0061 /* 'a' */, (UChar)0x0023 /* '#' */, (UChar)0x0042 /* 'B' */, 0},
  113.         {(UChar)0x0061 /* 'a' */, (UChar)0x0026 /* '&' */, (UChar)0x0062 /* 'b' */, 0},
  114.         {(UChar)0x0061 /* 'a' */, (UChar)0x0023 /* '#' */, (UChar)0x0063 /* 'c' */, 0},
  115.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},
  116.         {0x00C4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},
  117.         {0x00E4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},
  118.         {0x00C4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},
  119.         {0x00C4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, (UChar)0x0064 /* 'd' */, (UChar)0x0061 /* 'a' */, 0},                                             
  120.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0023 /* '#' */, (UChar)0x0063 /* 'c' */, 0},
  121.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  122.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x003D /* '=' */, (UChar)0x0063 /* 'c' */, 0},
  123.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0064 /* 'd' */, 0},
  124.         {0x00E4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  125.         {(UChar)0x0061 /* 'a' */, (UChar)0x0043 /* 'C' */, (UChar)0x0048 /* 'H' */, (UChar)0x0063 /* 'c' */, 0},
  126.         {0x00E4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  127.         {(UChar)0x0074 /* 't' */, (UChar)0x0068 /* 'h' */, 0x00EE, (UChar)0x0073 /* 's' */, 0},
  128.         {(UChar)0x0070 /* 'p' */, 0x00E9, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, 0x00E9, 0},
  129.         {(UChar)0x0061 /* 'a' */, (UChar)0x0042 /* 'B' */, (UChar)0x0043 /* 'C' */, 0},                                                          
  130.         {(UChar)0x0061 /* 'a' */, (UChar)0x0062 /* 'b' */, (UChar)0x0064 /* 'd' */, 0},
  131.         {0x00E4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  132.         {(UChar)0x0061 /* 'a' */, 0x00C6, (UChar)0x0063 /* 'c' */, 0},
  133.         {(UChar)0x0061 /* 'a' */, (UChar)0x0042 /* 'B' */, (UChar)0x0064 /* 'd' */, 0},
  134.         {0x00E4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},
  135.         {(UChar)0x0061 /* 'a' */, 0x00C6, (UChar)0x0063 /* 'c' */, 0},
  136.         {(UChar)0x0061 /* 'a' */, (UChar)0x0042 /* 'B' */, (UChar)0x0064 /* 'd' */, 0},
  137.         {0x00E4, (UChar)0x0062 /* 'b' */, (UChar)0x0063 /* 'c' */, 0},          
  138.         {(UChar)0x0070 /* 'p' */, 0x00EA, (UChar)0x0063 /* 'c' */, (UChar)0x0068 /* 'h' */, (UChar)0x0065 /* 'e' */, 0}                                                 
  139. };
  140.  
  141. const static UCollationResult results[] = {
  142.         UCOL_LESS, 
  143.         UCOL_GREATER,
  144.         UCOL_LESS,
  145.         UCOL_GREATER,
  146.         UCOL_GREATER,
  147.         UCOL_EQUAL,
  148.         UCOL_LESS,
  149.         UCOL_LESS,
  150.         UCOL_LESS,
  151.         UCOL_GREATER,                                                          /* 10 */
  152.         UCOL_GREATER,
  153.         UCOL_LESS,
  154.         UCOL_EQUAL,
  155.         UCOL_LESS,
  156.         UCOL_GREATER,
  157.         UCOL_GREATER,
  158.         UCOL_GREATER,
  159.         UCOL_LESS,
  160.         UCOL_LESS,
  161.         UCOL_LESS,                                                             /* 20 */
  162.         UCOL_LESS,
  163.         UCOL_LESS,
  164.         UCOL_LESS,
  165.         UCOL_GREATER,
  166.         UCOL_GREATER,
  167.         UCOL_GREATER,
  168.         /* Test Tertiary  > 26 */
  169.         UCOL_LESS,
  170.         UCOL_LESS,
  171.         UCOL_GREATER,
  172.         UCOL_LESS,                                                             /* 30 */
  173.         UCOL_GREATER,
  174.         UCOL_EQUAL,
  175.         UCOL_GREATER,
  176.         UCOL_LESS,
  177.         UCOL_LESS,
  178.         UCOL_LESS,
  179.         /* test identical > 36 */
  180.         UCOL_EQUAL,
  181.         UCOL_EQUAL,
  182.         /* test primary > 38 */
  183.         UCOL_EQUAL,
  184.         UCOL_EQUAL,                                                            /* 40 */
  185.         UCOL_LESS,
  186.         UCOL_EQUAL,
  187.         UCOL_EQUAL,
  188.         /* test secondary > 43 */
  189.         UCOL_LESS,
  190.         UCOL_LESS,
  191.         UCOL_EQUAL,
  192.         UCOL_LESS,
  193.         UCOL_LESS, 
  194.         UCOL_LESS                                                                         /* 49 */
  195. };
  196.  
  197. const static UChar testBugs[][MAX_TOKEN_LEN] = {
  198.     {(UChar)0x0061 /* 'a' */, 0},
  199.     {(UChar)0x0041 /* 'A' */, 0},
  200.     {(UChar)0x0065 /* 'e' */, 0},
  201.     {(UChar)0x0045 /* 'E' */, 0},
  202.     {0x00e9, 0},
  203.     {0x00e8, 0},
  204.     {0x00ea, 0},
  205.     {0x00eb, 0},
  206.     {(UChar)0x0065 /* 'e' */, (UChar)0x0061 /* 'a' */, 0},
  207.     {(UChar)0x0078 /* 'x' */, 0}
  208.         
  209. };
  210.  
  211. /* 0x0300 is grave, 0x0301 is acute
  212.    the order of elements in this array must be different than the order in CollationFrenchTest */
  213. const static UChar testAcute[][MAX_TOKEN_LEN] = {
  214.     {(UChar)0x0065 /* 'e' */, (UChar)0x0065 /* 'e' */, 0},
  215.     {(UChar)0x0065 /* 'e' */, (UChar)0x0065 /* 'e' */, 0x0301, 0},
  216.     {(UChar)0x0065 /* 'e' */, (UChar)0x0065 /* 'e' */, 0x0301, 0x0300, 0},
  217.     {(UChar)0x0065 /* 'e' */, (UChar)0x0065 /* 'e' */, 0x0300, 0},
  218.     {(UChar)0x0065 /* 'e' */, (UChar)0x0065 /* 'e' */, 0x0300, 0x0301, 0},
  219.     {(UChar)0x0065 /* 'e' */, 0x0301, (UChar)0x0065 /* 'e' */, 0},
  220.     {(UChar)0x0065 /* 'e' */, 0x0301, (UChar)0x0065 /* 'e' */, 0x0301, 0},
  221.     {(UChar)0x0065 /* 'e' */, 0x0301, (UChar)0x0065 /* 'e' */, 0x0301, 0x0300, 0},
  222.     {(UChar)0x0065 /* 'e' */, 0x0301, (UChar)0x0065 /* 'e' */, 0x0300, 0},
  223.     {(UChar)0x0065 /* 'e' */, 0x0301, (UChar)0x0065 /* 'e' */, 0x0300, 0x0301, 0},
  224.     {(UChar)0x0065 /* 'e' */, 0x0301, 0x0300, (UChar)0x0065 /* 'e' */, 0},
  225.     {(UChar)0x0065 /* 'e' */, 0x0301, 0x0300, (UChar)0x0065 /* 'e' */, 0x0301, 0},
  226.     {(UChar)0x0065 /* 'e' */, 0x0301, 0x0300, (UChar)0x0065 /* 'e' */, 0x0301, 0x0300, 0},
  227.     {(UChar)0x0065 /* 'e' */, 0x0301, 0x0300, (UChar)0x0065 /* 'e' */, 0x0300, 0},
  228.     {(UChar)0x0065 /* 'e' */, 0x0301, 0x0300, (UChar)0x0065 /* 'e' */, 0x0300, 0x0301, 0},
  229.     {(UChar)0x0065 /* 'e' */, 0x0300, (UChar)0x0065 /* 'e' */, 0},
  230.     {(UChar)0x0065 /* 'e' */, 0x0300, (UChar)0x0065 /* 'e' */, 0x0301, 0},
  231.     {(UChar)0x0065 /* 'e' */, 0x0300, (UChar)0x0065 /* 'e' */, 0x0301, 0x0300, 0},
  232.     {(UChar)0x0065 /* 'e' */, 0x0300, (UChar)0x0065 /* 'e' */, 0x0300, 0},
  233.     {(UChar)0x0065 /* 'e' */, 0x0300, (UChar)0x0065 /* 'e' */, 0x0300, 0x0301, 0},
  234.     {(UChar)0x0065 /* 'e' */, 0x0300, 0x0301, (UChar)0x0065 /* 'e' */, 0},
  235.     {(UChar)0x0065 /* 'e' */, 0x0300, 0x0301, (UChar)0x0065 /* 'e' */, 0x0301, 0},
  236.     {(UChar)0x0065 /* 'e' */, 0x0300, 0x0301, (UChar)0x0065 /* 'e' */, 0x0301, 0x0300, 0},
  237.     {(UChar)0x0065 /* 'e' */, 0x0300, 0x0301, (UChar)0x0065 /* 'e' */, 0x0300, 0},
  238.     {(UChar)0x0065 /* 'e' */, 0x0300, 0x0301, (UChar)0x0065 /* 'e' */, 0x0300, 0x0301, 0}
  239. };
  240.  
  241. static const UChar testMore[][MAX_TOKEN_LEN] = {
  242.     {(UChar)0x0061 /* 'a' */, (UChar)0x0065 /* 'e' */, 0},
  243.     { 0x00E6, 0},
  244.     { 0x00C6, 0},
  245.     {(UChar)0x0061 /* 'a' */, (UChar)0x0066 /* 'f' */, 0},
  246.     {(UChar)0x006F /* 'o' */, (UChar)0x0065 /* 'e' */, 0},
  247.     { 0x0153, 0},
  248.     { 0x0152, 0},
  249.     {(UChar)0x006F /* 'o' */, (UChar)0x0066 /* 'f' */, 0},
  250. };
  251.  
  252.  
  253. void addEnglishCollTest(TestNode** root)
  254. {
  255.     
  256.     addTest(root, &TestPrimary, "tscoll/encoll/TestPrimary");
  257.     addTest(root, &TestSecondary, "tscoll/encoll/TestSecondary");
  258.     addTest(root, &TestTertiary, "tscoll/encoll/TestTertiary");
  259.  
  260. }
  261.  
  262. void doTest(UCollator* myCollation, const UChar source[], const UChar target[], UCollationResult result)
  263. {
  264.     int32_t sortklen, temp;
  265.     UCollationResult compareResult, keyResult;
  266.     uint8_t *sortKey1, *sortKey2;
  267.     
  268.     compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
  269.     
  270.     sortklen=ucol_getSortKey(myCollation, source, u_strlen(source),  NULL, 0);
  271.     sortKey1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  272.     ucol_getSortKey(myCollation, source, u_strlen(source), sortKey1, sortklen+1);
  273.     
  274.     sortklen=ucol_getSortKey(myCollation, target, u_strlen(target),  NULL, 0);
  275.     sortKey2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  276.     ucol_getSortKey(myCollation, target, u_strlen(target), sortKey2, sortklen+1);
  277.     
  278.  
  279.     temp= memcmp(sortKey1, sortKey2, sortklen);
  280.     if(temp < 0) keyResult=UCOL_LESS;
  281.     else if(temp > 0) keyResult= UCOL_GREATER;
  282.     else keyResult = UCOL_EQUAL;
  283.     reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
  284. }
  285.  
  286. void TestTertiary( )
  287. {
  288.     int32_t testMoreSize;
  289.     UCollationResult expected;
  290.     int32_t i,j;
  291.     UErrorCode status = U_ZERO_ERROR;
  292.     myCollation = ucol_open("en_US", &status);
  293.     if(U_FAILURE(status)){
  294.         log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
  295.     }
  296.     log_verbose("Testing English Collation with Tertiary strength\n");
  297.     ucol_setNormalization(myCollation, UCOL_DECOMP_CAN_COMP_COMPAT);
  298.     ucol_setStrength(myCollation, UCOL_TERTIARY);
  299.     for (i = 0; i < 38 ; i++)
  300.     {
  301.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  302.     }
  303.   
  304.  
  305.     j = 0;
  306.    for (i = 0; i < 10; i++)
  307.     {
  308.         for (j = i+1; j < 10; j++)
  309.         {
  310.             doTest(myCollation, testBugs[i], testBugs[j], UCOL_LESS);
  311.         }
  312.    }
  313.     /*test more interesting cases */
  314.     testMoreSize = sizeof(testMore) / sizeof(testMore[0]);
  315.     for (i = 0; i < testMoreSize; i++)
  316.     {
  317.         for (j = 0; j < testMoreSize; j++)
  318.         {
  319.             if (i <  j) expected = UCOL_LESS;
  320.             if (i == j) expected = UCOL_EQUAL;
  321.             if (i >  j) expected = UCOL_GREATER;
  322.             doTest(myCollation, testMore[i], testMore[j], expected );
  323.         }
  324.     }
  325. ucol_close(myCollation);
  326. }
  327.  
  328. void TestPrimary()
  329. {
  330.     
  331.     int32_t i;
  332.     UErrorCode status = U_ZERO_ERROR;
  333.     myCollation = ucol_open("en_US", &status);
  334.     if(U_FAILURE(status)){
  335.         log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
  336.     }
  337.     ucol_setNormalization(myCollation, UCOL_DECOMP_CAN_COMP_COMPAT);
  338.     ucol_setStrength(myCollation, UCOL_PRIMARY);
  339.     log_verbose("Testing English Collation with Primary strength\n");
  340.     for (i = 38; i < 43 ; i++)
  341.     {
  342.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  343.     }
  344.     ucol_close(myCollation);
  345. }
  346.  
  347. void TestSecondary()
  348. {
  349.     UCollationResult expected;
  350.     int32_t i,j, testAcuteSize;
  351.     UErrorCode status = U_ZERO_ERROR;
  352.     myCollation = ucol_open("en_US", &status);
  353.     if(U_FAILURE(status)){
  354.         log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
  355.     }
  356.     ucol_setStrength(myCollation, UCOL_SECONDARY);
  357.     log_verbose("Testing English Collation with Secondary strength\n");
  358.     for (i = 43; i < 49 ; i++)
  359.     {
  360.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  361.     }
  362.     
  363.  
  364.     /*test acute and grave ordering (compare to french collation) */
  365.     testAcuteSize = sizeof(testAcute) / sizeof(testAcute[0]);
  366.     for (i = 0; i < testAcuteSize; i++)
  367.     {
  368.         for (j = 0; j < testAcuteSize; j++)
  369.         {
  370.             if (i <  j) expected = UCOL_LESS;
  371.             if (i == j) expected = UCOL_EQUAL;
  372.             if (i >  j) expected = UCOL_GREATER;
  373.             doTest(myCollation, testAcute[i], testAcute[j], expected );
  374.         }
  375.     }
  376. ucol_close(myCollation);
  377. }
  378.