home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / cfintst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  4.8 KB  |  134 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 CFINTST.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *     Madhu Katragadda            Ported for C API
  19. *********************************************************************************
  20. /**
  21.  * CollationFinnishTest 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 "cfintst.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.     {0x0077/*'w'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000},
  39.     {0x0076/*'v'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000},
  40.     {0x0061/*'a'*/, 0x00FC, 0x0062/*'b'*/, 0x0065/*'e'*/, 0x0063/*'c'*/, 0x006b/*'k'*/, 0x0000},
  41.     {0x004c/*'L'*/, 0x00E5, 0x0076/*'v'*/, 0x0069/*'i'*/, 0x0000},
  42.     {0x0077/*'w'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000}
  43. };
  44.  
  45. const static UChar testTargetCases[][MAX_TOKEN_LEN] = {
  46.     {0x0076/*'v'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000},
  47.     {0x0077/*'w'*/, 0x0061/*'a'*/, 0x0079/*'y'*/, 0x0000},
  48.     {0x0061/*'a'*/, 0x0078/*'x'*/, 0x0062/*'b'*/, 0x0065/*'e'*/, 0x0063/*'c'*/, 0x006b/*'k'*/, 0x0000},
  49.     {0x004c/*'L'*/, 0x00E4, 0x0077/*'w'*/, 0x0065/*'e'*/, 0x0000},
  50.     {0x0076/*'v'*/, 0x0061/*'a'*/, 0x0074/*'t'*/, 0x0000}
  51. };
  52.  
  53. const static UCollationResult results[] = {
  54.     UCOL_GREATER,
  55.     UCOL_LESS,
  56.     UCOL_GREATER,
  57.     UCOL_LESS,
  58.     /* test primary > 4*/
  59.     UCOL_EQUAL
  60. };
  61.  
  62.  
  63.  
  64. void addFinnishCollTest(TestNode** root)
  65. {
  66.     
  67.     
  68.     addTest(root, &TestPrimary, "tscoll/cficoll/TestPrimary");
  69.     addTest(root, &TestTertiary, "tscoll/cficoll/TestTertiary");
  70.     
  71.  
  72.  
  73. }
  74. void doTest(UCollator* myCollation, const UChar source[], const UChar target[], UCollationResult result)
  75. {
  76.     int32_t sortklen, temp;
  77.     UCollationResult compareResult, keyResult;
  78.     uint8_t *sortKey1, *sortKey2;
  79.     
  80.     compareResult = ucol_strcoll(myCollation, source, u_strlen(source), target, u_strlen(target));
  81.     
  82.     sortklen=ucol_getSortKey(myCollation, source, u_strlen(source),  NULL, 0);
  83.     sortKey1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  84.     ucol_getSortKey(myCollation, source, u_strlen(source), sortKey1, sortklen+1);
  85.     
  86.     sortklen=ucol_getSortKey(myCollation, target, u_strlen(target),  NULL, 0);
  87.     sortKey2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  88.     ucol_getSortKey(myCollation, target, u_strlen(target), sortKey2, sortklen+1);
  89.     
  90.  
  91.     temp= memcmp(sortKey1, sortKey2, sortklen);
  92.     if(temp < 0) keyResult=UCOL_LESS;
  93.     else if(temp > 0) keyResult= UCOL_GREATER;
  94.     else keyResult = UCOL_EQUAL;
  95.     reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
  96. }
  97.  
  98. void TestTertiary( )
  99. {
  100.     
  101.     int32_t i;
  102.     UErrorCode status = U_ZERO_ERROR;
  103.     myCollation = ucol_open("fi_FI", &status);
  104.     if(U_FAILURE(status)){
  105.         log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
  106.     }
  107.     log_verbose("Testing Finnish Collation with Tertiary strength\n");
  108.     ucol_setStrength(myCollation, UCOL_TERTIARY);
  109.     for (i = 0; i < 4 ; i++)
  110.     {
  111.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  112.     }
  113.     ucol_close(myCollation);
  114. }
  115.  
  116. void TestPrimary()
  117. {
  118.     
  119.     int32_t i;
  120.     UErrorCode status = U_ZERO_ERROR;
  121.     myCollation = ucol_open("fi_FI", &status);
  122.     if(U_FAILURE(status)){
  123.         log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
  124.     }
  125.     log_verbose("Testing Finnish Collation with Tertiary strength\n");
  126.     ucol_setStrength(myCollation, UCOL_PRIMARY);
  127.     for (i = 4; i < 4; i++)
  128.     {
  129.         doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
  130.     }
  131.     ucol_close(myCollation);
  132. }
  133.  
  134.