home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / cjaptst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  4.6 KB  |  131 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 CJAPTST.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *     Madhu Katragadda            Ported for C API
  19. *********************************************************************************
  20. /**
  21.  * CollationKannaTest 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 "ccolltst.h"
  32. #include "cjaptst.h"
  33. #include "ustring.h"
  34. #include "string.h"
  35. #include <memory.h>
  36. static UCollator *myCollation;
  37. const static UChar testSourceCases[][MAX_TOKEN_LEN] = {
  38.     {0x0041/*'A'*/, 0x0300, 0x0301, 0x0000},
  39.     {0x0041/*'A'*/, 0x0300, 0x0316, 0x0000},
  40.     {0x0041/*'A'*/, 0x0300, 0x0000},
  41.     {0x00C0, 0x0301, 0x0000},
  42.     {0x00C0, 0x0316, 0x0000},
  43.     {0xff9E, 0x0000},
  44.     {0x3042, 0x0000},
  45.     {0x30A2, 0x0000},
  46.     {0x3042, 0x3042, 0x0000},
  47.     {0x30A2, 0x30FC, 0x0000},
  48.     {0x30A2, 0x30FC, 0x30C8, 0x0000}                               /*  11 */
  49. };
  50.  
  51. const static UChar testTargetCases[][MAX_TOKEN_LEN] = {
  52.     {0x0041/*'A'*/, 0x0301, 0x0300, 0x0000},
  53.     {0x0041/*'A'*/, 0x0316, 0x0300, 0x0000},
  54.     {0x00C0, 0},
  55.     {0x0041/*'A'*/, 0x0301, 0x0300, 0x0000},
  56.     {0x0041/*'A'*/, 0x0316, 0x0300, 0x0000},
  57.     {0xFF9F, 0x0000},
  58.     {0x30A2, 0x0000},
  59.     {0x3042, 0x3042, 0x0000},
  60.     {0x30A2, 0x30FC, 0x0000},
  61.     {0x30A2, 0x30FC, 0x30C8, 0x0000},
  62.     {0x3042, 0x3042, 0x3089, 0x0000}                              /*  11 */
  63. };
  64.  
  65. const static UCollationResult results[] = {
  66.     UCOL_GREATER,
  67.     UCOL_EQUAL,
  68.     UCOL_EQUAL,
  69.     UCOL_GREATER,
  70.     UCOL_EQUAL,
  71.     UCOL_LESS,
  72.     UCOL_LESS,
  73.     UCOL_LESS,
  74.     UCOL_LESS,
  75.     UCOL_LESS,
  76.     UCOL_LESS                                          /*  11 */
  77. };
  78.  
  79.  
  80. void addKannaCollTest(TestNode** root)
  81. {
  82.  
  83.     addTest(root, &TestTertiary, "tscoll/cjacoll/TestTertiary");
  84.  
  85. }
  86. void doTest(UCollator* myCollation, const UChar source[], const UChar target[], UCollationResult result)
  87. {
  88.     int32_t sortklen, temp;
  89.     UCollationResult compareResult, keyResult;
  90.     uint8_t *sortKey1, *sortKey2;
  91.     
  92.     compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
  93.     
  94.     sortklen=ucol_getSortKey(myCollation, source, u_strlen(source),  NULL, 0);
  95.     sortKey1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  96.     ucol_getSortKey(myCollation, source, u_strlen(source), sortKey1, sortklen+1);
  97.     
  98.     sortklen=ucol_getSortKey(myCollation, target, u_strlen(target),  NULL, 0);
  99.     sortKey2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  100.     ucol_getSortKey(myCollation, target, u_strlen(target), sortKey2, sortklen+1);
  101.     
  102.  
  103.     temp= memcmp(sortKey1, sortKey2, sortklen);
  104.     if(temp < 0) keyResult=UCOL_LESS;
  105.     else if(temp > 0) keyResult= UCOL_GREATER;
  106.     else keyResult = UCOL_EQUAL;
  107.     reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
  108. }
  109.  
  110. void TestTertiary( )
  111. {
  112.     
  113.     int32_t i;
  114.     UErrorCode status = U_ZERO_ERROR;
  115.     myCollation = ucol_open("ja_JP", &status);
  116.     if(U_FAILURE(status)){
  117.         log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
  118.     }
  119.     log_verbose("Testing Kanna(Japan) Collation with Tertiary strength\n");
  120.     ucol_setNormalization(myCollation, UCOL_DECOMP_COMPAT_COMP_CAN);
  121.     ucol_setStrength(myCollation, UCOL_TERTIARY);
  122.     for (i = 0; i < 11 ; i++)
  123.     {
  124.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  125.     }
  126.     ucol_close(myCollation);
  127. }
  128.  
  129.  
  130.  
  131.