home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / callcoll.c next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  26.0 KB  |  576 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 CALLCOLL.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *     Madhu Katragadda              Ported for C API
  19. *********************************************************************************
  20. */
  21. /**
  22.  * CollationDummyTest is a third level test class.  This tests creation of 
  23.  * a customized collator object.  For example, number 1 to be sorted 
  24.  * equlivalent to word 'one'.
  25.  */
  26. #include "utypes.h"
  27. #include "ucol.h"
  28. #include "uloc.h"
  29. #include "cintltst.h"
  30. #include "ccolltst.h"
  31. #include "callcoll.h"
  32. #include "ustring.h"
  33. #include <string.h>
  34. #include <memory.h>
  35. static UCollator *myCollation;
  36. static const UChar DEFAULTRULEARRAY[] =
  37. {
  38.           '=', '\'', (UChar)0x200B, '\'', '=', (UChar)0x200C, '=', (UChar)0x200D, '=', (UChar)0x200E, '=', (UChar)0x200F
  39.         , '=', (UChar)0x0001, '=', (UChar)0x0002, '=', (UChar)0x0003, '=', (UChar)0x0004
  40.         , '=', (UChar)0x0005, '=', (UChar)0x0006, '=', (UChar)0x0007, '=', (UChar)0x0008, '=', '\'', (UChar)0x0009, '\''
  41.         , '=', '\'', (UChar)0x000b, '\'',  '=', (UChar)0x000e       /* vt,, so */
  42.         , '=', (UChar)0x000f, '=', '\'', (UChar)0x0010, '\'',  '=', (UChar)0x0011, '=', (UChar)0x0012, '=', (UChar)0x0013 /* si, dle, dc1, dc2, dc3 */
  43.         , '=', (UChar)0x0014, '=', (UChar)0x0015, '=', (UChar)0x0016, '=', (UChar)0x0017, '=', (UChar)0x0018 /* dc4, nak, syn, etb, can */
  44.         , '=', (UChar)0x0019, '=', (UChar)0x001a, '=', (UChar)0x001b, '=', (UChar)0x001c, '=', (UChar)0x001d /* em, sub, esc, fs, gs */
  45.         , '=', (UChar)0x001e, '=', (UChar)0x001f, '=', (UChar)0x007f                   /* rs, us, del */
  46.         /* ....then the C1 Latin 1 reserved control codes */
  47.         , '=', (UChar)0x0080, '=', (UChar)0x0081, '=', (UChar)0x0082, '=', (UChar)0x0083, '=', (UChar)0x0084, '=', (UChar)0x0085
  48.         , '=', (UChar)0x0086, '=', (UChar)0x0087, '=', (UChar)0x0088, '=', (UChar)0x0089, '=', (UChar)0x008a, '=', (UChar)0x008b
  49.         , '=', (UChar)0x008c, '=', (UChar)0x008d, '=', (UChar)0x008e, '=', (UChar)0x008f, '=', (UChar)0x0090, '=', (UChar)0x0091
  50.         , '=', (UChar)0x0092, '=', (UChar)0x0093, '=', (UChar)0x0094, '=', (UChar)0x0095, '=', (UChar)0x0096, '=', (UChar)0x0097
  51.         , '=', (UChar)0x0098, '=', (UChar)0x0099, '=', (UChar)0x009a, '=', (UChar)0x009b, '=', (UChar)0x009c, '=', (UChar)0x009d
  52.         , '=', (UChar)0x009e, '=', (UChar)0x009f
  53.         /*  IGNORE except for secondary, tertiary difference */
  54.         /*  Spaces */
  55.         , ';', '\'', (UChar)0x0020, '\'', ';', '\'', (UChar)0x00A0, '\''                   /*  spaces */
  56.         , ';', '\'', (UChar)0x2000, '\'', ';', '\'', (UChar)0x2001, '\'', ';', '\'', (UChar)0x2002, '\'', ';', '\'', (UChar)0x2003, '\'', ';', '\'', (UChar)0x2004, '\''   /*  spaces */
  57.         , ';', '\'', (UChar)0x2005, '\'', ';', '\'', (UChar)0x2006, '\'', ';', '\'', (UChar)0x2007, '\'', ';', '\'', (UChar)0x2008, '\'', ';', '\'', (UChar)0x2009, '\''   /*  spaces */
  58.         , ';', '\'', (UChar)0x200A, '\'', ';', '\'', (UChar)0x3000, '\'', ';', '\'', (UChar)0xFEFF, '\''                 /*  spaces */
  59.         , ';', '\'', '\r', '\'',  ';', '\'', '\t', '\'',  ';', '\'', '\n', '\'', ';', '\'', '\f', '\'', ';', '\'', (UChar)0x000b, '\''   /*  whitespace */
  60.  
  61.         /*  Non-spacing accents */
  62.  
  63.         , ';', (UChar)0x0301          /*  non-spacing acute accent */
  64.         , ';', (UChar)0x0300          /*  non-spacing grave accent */
  65.         , ';', (UChar)0x0306          /*  non-spacing breve accent */
  66.         , ';', (UChar)0x0302          /*  non-spacing circumflex accent */
  67.         , ';', (UChar)0x030c          /*  non-spacing caron/hacek accent */
  68.         , ';', (UChar)0x030a          /*  non-spacing ring above accent */
  69.         , ';', (UChar)0x030d          /*  non-spacing vertical line above */
  70.         , ';', (UChar)0x0308          /*  non-spacing diaeresis accent */
  71.         , ';', (UChar)0x030b          /*  non-spacing double acute accent */
  72.         , ';', (UChar)0x0303          /*  non-spacing tilde accent */
  73.         , ';', (UChar)0x0307          /*  non-spacing dot above/overdot accent */
  74.         , ';', (UChar)0x0304          /*  non-spacing macron accent */
  75.         , ';', (UChar)0x0337          /*  non-spacing short slash overlay (overstruck diacritic) */
  76.         , ';', (UChar)0x0327          /*  non-spacing cedilla accent */
  77.         , ';', (UChar)0x0328          /*  non-spacing ogonek accent */
  78.         , ';', (UChar)0x0323          /*  non-spacing dot-below/underdot accent */
  79.         , ';', (UChar)0x0332          /*  non-spacing underscore/underline accent */
  80.         /*  with the rest of the general diacritical marks in binary order */
  81.         , ';', (UChar)0x0305          /*  non-spacing overscore/overline */
  82.         , ';', (UChar)0x0309          /*  non-spacing hook above */
  83.         , ';', (UChar)0x030e          /*  non-spacing double vertical line above */
  84.         , ';', (UChar)0x030f          /*  non-spacing double grave */
  85.         , ';', (UChar)0x0310          /*  non-spacing chandrabindu */
  86.         , ';', (UChar)0x0311          /*  non-spacing inverted breve */
  87.         , ';', (UChar)0x0312          /*  non-spacing turned comma above/cedilla above */
  88.         , ';', (UChar)0x0313          /*  non-spacing comma above */
  89.         , ';', (UChar)0x0314          /*  non-spacing reversed comma above */
  90.         , ';', (UChar)0x0315          /*  non-spacing comma above right */
  91.         , ';', (UChar)0x0316          /*  non-spacing grave below */
  92.         , ';', (UChar)0x0317          /*  non-spacing acute below */
  93.         , ';', (UChar)0x0318          /*  non-spacing left tack below */
  94.         , ';', (UChar)0x0319          /*  non-spacing tack below */
  95.         , ';', (UChar)0x031a          /*  non-spacing left angle above */
  96.         , ';', (UChar)0x031b          /*  non-spacing horn */
  97.         , ';', (UChar)0x031c          /*  non-spacing left half ring below */
  98.         , ';', (UChar)0x031d          /*  non-spacing up tack below */
  99.         , ';', (UChar)0x031e          /*  non-spacing down tack below */
  100.         , ';', (UChar)0x031f          /*  non-spacing plus sign below */
  101.         , ';', (UChar)0x0320          /*  non-spacing minus sign below */
  102.         , ';', (UChar)0x0321          /*  non-spacing palatalized hook below */
  103.         , ';', (UChar)0x0322          /*  non-spacing retroflex hook below */
  104.         , ';', (UChar)0x0324          /*  non-spacing double dot below */
  105.         , ';', (UChar)0x0325          /*  non-spacing ring below */
  106.         , ';', (UChar)0x0326          /*  non-spacing comma below */
  107.         , ';', (UChar)0x0329          /*  non-spacing vertical line below */
  108.         , ';', (UChar)0x032a          /*  non-spacing bridge below */
  109.         , ';', (UChar)0x032b          /*  non-spacing inverted double arch below */
  110.         , ';', (UChar)0x032c          /*  non-spacing hacek below */
  111.         , ';', (UChar)0x032d          /*  non-spacing circumflex below */
  112.         , ';', (UChar)0x032e          /*  non-spacing breve below */
  113.         , ';', (UChar)0x032f          /*  non-spacing inverted breve below */
  114.         , ';', (UChar)0x0330          /*  non-spacing tilde below */
  115.         , ';', (UChar)0x0331          /*  non-spacing macron below */
  116.         , ';', (UChar)0x0333          /*  non-spacing double underscore */
  117.         , ';', (UChar)0x0334          /*  non-spacing tilde overlay */
  118.         , ';', (UChar)0x0335          /*  non-spacing short bar overlay */
  119.         , ';', (UChar)0x0336          /*  non-spacing long bar overlay */
  120.         , ';', (UChar)0x0338          /*  non-spacing long slash overlay */
  121.         , ';', (UChar)0x0339          /*  non-spacing right half ring below */
  122.         , ';', (UChar)0x033a          /*  non-spacing inverted bridge below */
  123.         , ';', (UChar)0x033b          /*  non-spacing square below */
  124.         , ';', (UChar)0x033c          /*  non-spacing seagull below */
  125.         , ';', (UChar)0x033d          /*  non-spacing x above */
  126.         , ';', (UChar)0x033e          /*  non-spacing vertical tilde */
  127.         , ';', (UChar)0x033f          /*  non-spacing double overscore */
  128.         , ';', (UChar)0x0340          /*  non-spacing grave tone mark */
  129.         , ';', (UChar)0x0341          /*  non-spacing acute tone mark */
  130.         , ';', (UChar)0x0342, ';', (UChar)0x0343, ';', (UChar)0x0344, ';', (UChar)0x0345, ';', (UChar)0x0360, ';', (UChar)0x0361    /*  newer */
  131.         , ';', (UChar)0x0483, ';', (UChar)0x0484, ';', (UChar)0x0485, ';', (UChar)0x0486    /*  Cyrillic accents */
  132.  
  133.         , ';', (UChar)0x20D0, ';', (UChar)0x20D1, ';', (UChar)0x20D2           /*  symbol accents */
  134.         , ';', (UChar)0x20D3, ';', (UChar)0x20D4, ';', (UChar)0x20D5           /*  symbol accents */
  135.         , ';', (UChar)0x20D6, ';', (UChar)0x20D7, ';', (UChar)0x20D8           /*  symbol accents */
  136.         , ';', (UChar)0x20D9, ';', (UChar)0x20DA, ';', (UChar)0x20DB           /*  symbol accents */
  137.         , ';', (UChar)0x20DC, ';', (UChar)0x20DD, ';', (UChar)0x20DE           /*  symbol accents */
  138.         , ';', (UChar)0x20DF, ';', (UChar)0x20E0, ';', (UChar)0x20E1           /*  symbol accents */
  139.  
  140.         , ',', '\'', (UChar)0x002D, '\'', ';', (UChar)0x00AD                     /*  dashes */
  141.         , ';', (UChar)0x2010, ';', (UChar)0x2011, ';', (UChar)0x2012           /*  dashes */
  142.         , ';', (UChar)0x2013, ';', (UChar)0x2014, ';', (UChar)0x2015           /*  dashes */
  143.         , ';', (UChar)0x2212                                                       /*  dashes */
  144.  
  145.         /*  other punctuation */
  146.  
  147.         , '<', '\'', (UChar)0x005f, '\'' /*  underline/underscore (spacing) */
  148.         , '<', (UChar)0x00af          /*  overline or macron (spacing) */
  149. /*         , '<', (UChar)0x00ad          /* syllable hyphen (SHY) or soft hyphen */
  150.         , '<', '\'', (UChar)0x002c, '\''           /*  comma (spacing) */
  151.         , '<', '\'', (UChar)0x003b, '\''           /*  semicolon */
  152.         , '<', '\'', (UChar)0x003a, '\''           /*  colon */
  153.         , '<', '\'', (UChar)0x0021, '\''           /*  exclamation point */
  154.         , '<', (UChar)0x00a1                       /*  inverted exclamation point */
  155.         , '<', '\'', (UChar)0x003f, '\''           /*  question mark */
  156.         , '<', (UChar)0x00bf                       /*  inverted question mark */
  157.         , '<', '\'', (UChar)0x002f, '\''           /*  slash */
  158.         , '<', '\'', (UChar)0x002e, '\''           /*  period/full stop */
  159.         , '<', (UChar)0x00b4                       /*  acute accent (spacing) */
  160.         , '<', '\'', (UChar)0x0060, '\''           /*  grave accent (spacing) */
  161.         , '<', '\'', (UChar)0x005e, '\''           /*  circumflex accent (spacing) */
  162.         , '<', (UChar)0x00a8                       /*  diaresis/umlaut accent (spacing) */
  163.         , '<', '\'', (UChar)0x007e, '\''           /*  tilde accent (spacing) */
  164.         , '<', (UChar)0x00b7                       /*  middle dot (spacing) */
  165.         , '<', (UChar)0x00b8                       /*  cedilla accent (spacing) */
  166.         , '<', '\'', (UChar)0x0027, '\''           /*  apostrophe */
  167.         , '<', '\'', '"', '\''                       /*  quotation marks */
  168.         , '<', (UChar)0x00ab                       /*  left angle quotes */
  169.         , '<', (UChar)0x00bb                       /*  right angle quotes */
  170.         , '<', '\'', (UChar)0x0028, '\''           /*  left parenthesis */
  171.         , '<', '\'', (UChar)0x0029, '\''           /*  right parenthesis */
  172.         , '<', '\'', (UChar)0x005b, '\''           /*  left bracket */
  173.         , '<', '\'', (UChar)0x005d, '\''           /*  right bracket */
  174.         , '<', '\'', (UChar)0x007b, '\''           /*  left brace */
  175.         , '<', '\'', (UChar)0x007d, '\''           /*  right brace */
  176.         , '<', (UChar)0x00a7                       /*  section symbol */
  177.         , '<', (UChar)0x00b6                       /*  paragraph symbol */
  178.         , '<', (UChar)0x00a9                       /*  copyright symbol */
  179.         , '<', (UChar)0x00ae                       /*  registered trademark symbol */
  180.         , '<', '\'', (UChar)0x0040, '\''           /*  at sign */
  181.         , '<', (UChar)0x00a4                       /*  international currency symbol */
  182.         , '<', (UChar)0x00a2                       /*  cent sign */
  183.         , '<', '\'', (UChar)0x0024, '\''           /*  dollar sign */
  184.         , '<', (UChar)0x00a3                       /*  pound-sterling sign */
  185.         , '<', (UChar)0x00a5                       /*  yen sign */
  186.         , '<', '\'', (UChar)0x002a, '\''           /*  asterisk */
  187.         , '<', '\'', (UChar)0x005c, '\''           /*  backslash */
  188.         , '<', '\'', (UChar)0x0026, '\''           /*  ampersand */
  189.         , '<', '\'', (UChar)0x0023, '\''           /*  number sign */
  190.         , '<', '\'', (UChar)0x0025, '\''           /*  percent sign */
  191.         , '<', '\'', (UChar)0x002b, '\''           /*  plus sign */
  192. /*         , '<', (UChar)0x002d                    */ /* hyphen or minus sign */
  193.         , '<', (UChar)0x00b1                       /*  plus-or-minus sign */
  194.         , '<', (UChar)0x00f7                       /*  divide sign */
  195.         , '<', (UChar)0x00d7                       /*  multiply sign */
  196.         , '<', '\'', (UChar)0x003c, '\''           /*  less-than sign */
  197.         , '<', '\'', (UChar)0x003d, '\''           /*  equal sign */
  198.         , '<', '\'', (UChar)0x003e, '\''           /*  greater-than sign */
  199.         , '<', (UChar)0x00ac                       /*  end of line symbol/logical NOT symbol */
  200.         , '<', '\'', (UChar)0x007c, '\''           /*  vertical line/logical OR symbol */
  201.         , '<', (UChar)0x00a6                       /*  broken vertical line */
  202.         , '<', (UChar)0x00b0                       /*  degree symbol */
  203.         , '<', (UChar)0x00b5                       /*  micro symbol */
  204.  
  205.         /*  NUMERICS */
  206.  
  207.         , '<', '0', '<', '1', '<', '2', '<', '3', '<', '4', '<', '5', '<', '6', '<', '7', '<', '8', '<', '9' 
  208.         , '<', (UChar)0x00bc, '<', (UChar)0x00bd, '<', (UChar)0x00be    /*  1/4,1/2,3/4 fractions */
  209.  
  210.         /*  NON-IGNORABLES */
  211.         , '<', 'a', ',', 'A'
  212.         , '<', 'b', ',', 'B'
  213.         , '<', 'c', ',', 'C'
  214.         , '<', 'd', ',', 'D'
  215.         , '<', (UChar)0x00F0, ',', (UChar)0x00D0              /*  eth */
  216.         , '<', 'e', ',', 'E'
  217.         , '<', 'f', ',', 'F'
  218.         , '<', 'g', ',', 'G'
  219.         , '<', 'h', ',', 'H'
  220.         , '<', 'i', ',', 'I'
  221.         , '<', 'j', ',', 'J'
  222.         , '<', 'k', ',', 'K'
  223.         , '<', 'l', ',', 'L'
  224.         , '<', 'm', ',', 'M'
  225.         , '<', 'n', ',', 'N'
  226.         , '<', 'o', ',', 'O'
  227.         , '<', 'p', ',', 'P'
  228.         , '<', 'q', ',', 'Q'
  229.         , '<', 'r', ',', 'R'
  230.         , '<', 's', ',', 'S', '&', 'S', 'S', ',', (UChar)0x00DF /*  s-zet */
  231.         , '<', 't', ',', 'T'
  232.         , '&', 'T', 'H', ',', 0x00FE, '&', 'T', 'H', ',', (UChar)0x00DE  /*  thorn */
  233.         , '<', 'u', ',', 'U'
  234.         , '<', 'v', ',', 'V'
  235.         , '<', 'w', ',', 'W'
  236.         , '<', 'x', ',', 'X'
  237.         , '<', 'y', ',', 'Y'
  238.         , '<', 'z', ',', 'Z'
  239.         , '&', 'A', 'E', ',', (UChar)0x00C6                    /*  ae & AE ligature */
  240.         , '&', 'A', 'E', ',', (UChar)0x00E6
  241.         , '&', 'O', 'E', ',', (UChar)0x0152                    /*  oe & OE ligature */
  242.         , '&', 'O', 'E', ',', (UChar)0x0153
  243.         , (UChar)0x0000
  244. };
  245.  
  246. const UChar testSourceCases[][MAX_TOKEN_LEN] = {
  247.     {'a', 'b', '\'', 'c', 0},
  248.     {'c', 'o', '-', 'o', 'p', 0},
  249.     {'a', 'b', 0},
  250.     {'a', 'm', 'p', 'e', 'r', 's', 'a', 'd', 0},
  251.     {'a', 'l', 'l', 0},
  252.     {'f', 'o', 'u', 'r', 0},
  253.     {'f', 'i', 'v', 'e', 0},
  254.     {'1', 0},
  255.     {'1', 0},
  256.     {'1', 0},                                            /*  10 */
  257.     {'2', 0},
  258.     {'2', 0},
  259.     {'H', 'e', 'l', 'l', 'o', 0},
  260.     {'a', '<', 'b', 0},
  261.     {'a', '<', 'b', 0},
  262.     {'a', 'c', 'c', 0},
  263.     {'a', 'c', 'H', 'c', 0},  /*  simple test */
  264.     {'p', 0x00EA, 'c', 'h', 'e', 0},
  265.     {'a', 'b', 'c', 0},
  266.     {'a', 'b', 'c', 0},                                  /*  20 */
  267.     {'a', 'b', 'c', 0},
  268.     {'a', 'b', 'c', 0},
  269.     {'a', 'b', 'c', 0},
  270.     {'a', 0x00E6, 'c', 0},
  271.     {'a', 'c', 'H', 'c', 0},  /*  primary test */
  272.     {'b', 'l', 'a', 'c', 'k', 0},
  273.     {'f', 'o', 'u', 'r', 0},
  274.     {'f', 'i', 'v', 'e', 0},
  275.     {'1', 0},
  276.     {'a', 'b', 'c', 0},                                        /*  30 */
  277.     {'a', 'b', 'c', 0},                                  
  278.     {'a', 'b', 'c', 'H', 0},
  279.     {'a', 'b', 'c', 0},
  280.     {'a', 'c', 'H', 'c', 0},                              /*  34 */
  281.     {'a', 'c', 'e', '0'},
  282.     {'1', '0'},
  283.     {'p', 0x00EA,'0'}                                    /* 37     */
  284. };
  285.  
  286. const UChar testTargetCases[][MAX_TOKEN_LEN] = {
  287.     {'a', 'b', 'c', '\'', 0},
  288.     {'C', 'O', 'O', 'P', 0},
  289.     {'a', 'b', 'c', 0},
  290.     {'&', 0},
  291.     {'&', 0},
  292.     {'4', 0},
  293.     {'5', 0},
  294.     {'o', 'n', 'e', 0},
  295.     {'n', 'n', 'e', 0},
  296.     {'p', 'n', 'e', 0},                                  /*  10 */
  297.     {'t', 'w', 'o', 0},
  298.     {'u', 'w', 'o', 0},
  299.     {'h', 'e', 'l', 'l', 'O', 0},
  300.     {'a', '<', '=', 'b', 0},
  301.     {'a', 'b', 'c', 0},
  302.     {'a', 'C', 'H', 'c', 0},
  303.     {'a', 'C', 'H', 'c', 0},  /*  simple test */
  304.     {'p', (UChar)0x00E9, 'c', 'h', 0x00E9, 0},
  305.     {'a', 'b', 'c', 0},
  306.     {'a', 'B', 'C', 0},                                  /*  20 */
  307.     {'a', 'b', 'c', 'h', 0},
  308.     {'a', 'b', 'd', 0},
  309.     {(UChar)0x00E4, 'b', 'c', 0},
  310.     {'a', (UChar)0x00C6, 'c', 0},
  311.     {'a', 'C', 'H', 'c', 0},  /*  primary test */
  312.     {'b', 'l', 'a', 'c', 'k', '-', 'b', 'i', 'r', 'd', 0},
  313.     {'4', 0},
  314.     {'5', 0},
  315.     {'o', 'n', 'e', 0},
  316.     {'a', 'b', 'c', 0},
  317.     {'a', 'B', 'c', 0},                                  /*  30 */
  318.     {'a', 'b', 'c', 'h', 0},
  319.     {'a', 'b', 'd', 0},
  320.     {'a', 'C', 'H', 'c', 0},                                /*  34 */
  321.     {'a', 'c', 'e', '0'},
  322.     {'1', '0'},
  323.     {'p', (UChar)0x00EB,'0'}                                    /* 37 */
  324. };
  325.  
  326. const UCollationResult results[] = {
  327.     UCOL_LESS,
  328.     UCOL_GREATER,
  329.     UCOL_LESS,
  330.     UCOL_LESS,
  331.     UCOL_LESS,
  332.     UCOL_LESS,
  333.     UCOL_LESS,
  334.     UCOL_GREATER,
  335.     UCOL_GREATER,
  336.     UCOL_LESS,                                     /*  10 */
  337.     UCOL_GREATER,
  338.     UCOL_LESS,
  339.     UCOL_GREATER,
  340.     UCOL_GREATER,
  341.     UCOL_LESS,
  342.     UCOL_LESS,
  343.     UCOL_LESS,
  344.     /*  test primary > 17 */
  345.     UCOL_EQUAL,
  346.     UCOL_EQUAL,
  347.     UCOL_EQUAL,                                    /*  20 */
  348.     UCOL_LESS,
  349.     UCOL_LESS,
  350.     UCOL_EQUAL,
  351.     UCOL_EQUAL,
  352.     UCOL_EQUAL,
  353.     UCOL_LESS,
  354.     /*  test secondary > 26 */
  355.     UCOL_EQUAL,
  356.     UCOL_EQUAL,
  357.     UCOL_EQUAL,
  358.     UCOL_EQUAL,
  359.     UCOL_EQUAL,                                    /*  30 */
  360.     UCOL_EQUAL,
  361.     UCOL_LESS,
  362.     UCOL_EQUAL,                                     /*  34 */
  363.     UCOL_EQUAL,
  364.     UCOL_EQUAL,
  365.     UCOL_LESS                                        /* 37 */
  366. };
  367.  
  368. const UChar testCases[][MAX_TOKEN_LEN] =
  369. {
  370.     {'a', 0},
  371.     {'A', 0},
  372.     {'a', 'e', 0},
  373.     {'a', 'E', 0},
  374.     {'A', 'e', 0},
  375.     {'A', 'E', 0},
  376.     {(UChar)0x00e6, 0},
  377.     {(UChar)0x00c6, 0},
  378.     {'b', 0},
  379.     {'c', 0},
  380.     {'z', 0}
  381. };
  382.  
  383.  
  384. void addAllCollTest(TestNode** root)
  385. {
  386.     
  387.     
  388.     addTest(root, &TestPrimary, "tscoll/callcoll/TestPrimary");
  389.     addTest(root, &TestSecondary, "tscoll/callcoll/TestSecondary");
  390.     addTest(root, &TestTertiary, "tscoll/callcoll/TestTertiary");
  391.     addTest(root, &TestIdentical, "tscoll/callcoll/TestIdentical");
  392.     addTest(root, &TestExtra, "tscoll/callcoll/TestExtra");
  393.         
  394.  
  395. }
  396.  
  397. void doTest(UCollator* myCollation, const UChar source[], const UChar target[], UCollationResult result)
  398. {
  399.     int32_t sortklen;
  400.     UCollationResult compareResult = 0, keyResult = 0;
  401.     uint8_t *sortKey1 = 0, *sortKey2 = 0;
  402.     int res;
  403.     compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
  404.     
  405.     sortklen=ucol_getSortKey(myCollation, source, u_strlen(source),  NULL, 0);
  406.     sortKey1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  407.     ucol_getSortKey(myCollation, source, u_strlen(source), sortKey1, sortklen+1);
  408.     
  409.     sortklen=ucol_getSortKey(myCollation, target, u_strlen(target),  NULL, 0);
  410.     sortKey2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  411.     ucol_getSortKey(myCollation, target, u_strlen(target), sortKey2, sortklen+1);
  412.     
  413.     res = memcmp(sortKey1, sortKey2, sortklen) ;
  414.     if (res < 0) keyResult = -1;
  415.     else if (res > 0) keyResult = 1;
  416.     else keyResult = 0;
  417.     
  418.     reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
  419. }
  420.  
  421. void TestTertiary()
  422. {
  423.     int32_t len,i;
  424.     UChar *rules, *newRules;
  425.     UErrorCode status=U_ZERO_ERROR;
  426.     const char* str="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
  427.     newRules=(UChar*)malloc(sizeof(UChar*) * (strlen(str)+1));
  428.     u_uastrcpy(newRules, str);
  429.     len=u_strlen(DEFAULTRULEARRAY) + u_strlen(newRules);
  430.     rules=(UChar*)malloc(sizeof(UChar) * (len+1));
  431.     u_strcpy(rules, DEFAULTRULEARRAY);
  432.     u_strcat(rules, newRules);
  433.     myCollation=ucol_openRules(rules, u_strlen(rules), UCOL_NO_NORMALIZATION, UCOL_DEFAULT_STRENGTH, &status);
  434.     if(U_FAILURE(status)){
  435.         log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
  436.     }
  437.    
  438.    /* ucol_setNormalization(myCollation, UCOL_DEFAULT_NORMALIZATION); */
  439.     ucol_setStrength(myCollation, UCOL_TERTIARY);
  440.     for (i = 0; i < 17 ; i++)
  441.     {
  442.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  443.     }
  444.     free(newRules);
  445.     free(rules);
  446.     ucol_close(myCollation);
  447.     myCollation = 0;
  448. }
  449.  
  450. void TestPrimary( )
  451. {
  452.     int32_t len,i;
  453.     UChar *rules, *newRules;
  454.     UErrorCode status=U_ZERO_ERROR;
  455.     const char* str="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
  456.     
  457.     newRules=(UChar*)malloc(sizeof(UChar*) * strlen(str));
  458.     u_uastrcpy(newRules, str);
  459.     
  460.     len=u_strlen(DEFAULTRULEARRAY) + u_strlen(newRules);
  461.     rules=(UChar*)malloc(sizeof(UChar) * (len+1));
  462.     u_strcpy(rules, DEFAULTRULEARRAY);
  463.     u_strcat(rules, newRules);
  464.     myCollation=ucol_openRules(rules, u_strlen(rules), UCOL_NO_NORMALIZATION, UCOL_DEFAULT_STRENGTH, &status);
  465.     if(U_FAILURE(status)){
  466.         log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
  467.     }
  468.     ucol_setNormalization(myCollation, UCOL_DEFAULT_NORMALIZATION);
  469.     ucol_setStrength(myCollation, UCOL_PRIMARY);
  470.     
  471.     for (i = 17; i < 26 ; i++)
  472.     {
  473.         
  474.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  475.     }
  476.     free(newRules);
  477.     free(rules);
  478.     ucol_close(myCollation);
  479.     myCollation = 0;
  480. }
  481.  
  482. void TestSecondary()
  483. {
  484.     int32_t i;
  485.     int32_t len;
  486.     UChar *rules, *newRules;
  487.     UErrorCode status=U_ZERO_ERROR;
  488.     const char* str="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
  489.     
  490.     newRules=(UChar*)malloc(sizeof(UChar*) * strlen(str));
  491.     u_uastrcpy(newRules, str);
  492.     
  493.     len=u_strlen(DEFAULTRULEARRAY) + u_strlen(newRules);
  494.     rules=(UChar*)malloc(sizeof(UChar) * (len+1));
  495.     u_strcpy(rules, DEFAULTRULEARRAY);
  496.     u_strcat(rules, newRules);
  497.     
  498.     myCollation=ucol_openRules(rules, u_strlen(rules), UCOL_NO_NORMALIZATION, UCOL_DEFAULT_STRENGTH, &status);
  499.     if(U_FAILURE(status)){
  500.         log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
  501.     }
  502.     ucol_setStrength(myCollation, UCOL_SECONDARY);
  503.     for (i = 26; i < 34 ; i++)
  504.     {
  505.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  506.     }
  507.     free(newRules);
  508.     free(rules);
  509.     ucol_close(myCollation);
  510.     myCollation = 0;
  511. }
  512. void TestIdentical()
  513. {
  514.     int32_t i;
  515.     int32_t len;
  516.     UChar *rules = 0, *newRules = 0;
  517.     UErrorCode status=U_ZERO_ERROR;
  518.     const char* str="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
  519.  
  520.     newRules=(UChar*)malloc(sizeof(UChar*) * strlen(str));
  521.     u_uastrcpy(newRules, str);
  522.    
  523.     len=u_strlen(DEFAULTRULEARRAY) + u_strlen(newRules);
  524.     rules=(UChar*)malloc(sizeof(UChar) * (len+1));
  525.     u_strcpy(rules, DEFAULTRULEARRAY);
  526.     u_strcat(rules, newRules);
  527.     
  528.     myCollation=ucol_openRules(rules, u_strlen(rules), UCOL_NO_NORMALIZATION, UCOL_IDENTICAL, &status);
  529.     if(U_FAILURE(status)){
  530.         log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
  531.     }
  532.     for(i= 34; i<37; i++)
  533.     {
  534.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  535.     }
  536.     free(newRules);
  537.     free(rules);
  538.     ucol_close(myCollation);
  539.     myCollation = 0;
  540. }
  541. void TestExtra()
  542. {
  543.     int32_t i, j;
  544.     int32_t len;
  545.     UChar *rules, *newRules;
  546.     UErrorCode status = U_ZERO_ERROR;
  547.     const char* str="& C < ch, cH, Ch, CH & Five, 5 & Four, 4 & one, 1 & Ampersand; '&' & Two, 2 ";
  548.     newRules=(UChar*)malloc(sizeof(UChar*) * strlen(str));
  549.     u_uastrcpy(newRules, str);
  550.     log_verbose("Testing extra\n");
  551.     len=u_strlen(DEFAULTRULEARRAY) + u_strlen(newRules);
  552.     rules=(UChar*)malloc(sizeof(UChar) * (len+1));
  553.     u_strcpy(rules, DEFAULTRULEARRAY);
  554.     u_strcat(rules, newRules);
  555.     
  556.  
  557.     myCollation=ucol_openRules(rules, u_strlen(rules), UCOL_NO_NORMALIZATION, UCOL_DEFAULT_STRENGTH, &status);
  558.     if(U_FAILURE(status)){
  559.         log_err("ERROR: in creation of rule based collator :%s\n", myErrorName(status));
  560.     }
  561.     ucol_setNormalization(myCollation, UCOL_DEFAULT_NORMALIZATION); 
  562.     ucol_setStrength(myCollation, UCOL_TERTIARY);
  563.     for (i = 0; i < 10 ; i++)
  564.     {
  565.         for (j = i + 1; j < 11; j += 1)
  566.         {
  567.         
  568.             doTest(myCollation, testCases[i], testCases[j], UCOL_LESS);
  569.         }
  570.     }
  571.     free(newRules);
  572.     free(rules);
  573.     ucol_close(myCollation);
  574.     myCollation = 0;
  575. }
  576.