home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / jacoll.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  3.3 KB  |  122 lines

  1.  
  2. /*
  3. ********************************************************************
  4. * COPYRIGHT: 
  5. * (C) Copyright Taligent, Inc., 1997
  6. * (C) Copyright International Business Machines Corporation, 1997 - 1998
  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. #ifndef _COLL
  14. #include "coll.h"
  15. #endif
  16.  
  17. #ifndef _TBLCOLL
  18. #include "tblcoll.h"
  19. #endif
  20.  
  21. #ifndef _UNISTR
  22. #include "unistr.h"
  23. #endif
  24.  
  25. #ifndef _SORTKEY
  26. #include "sortkey.h"
  27. #endif
  28.  
  29. #ifndef _JACOLL
  30. #include "jacoll.h"
  31. #endif
  32.  
  33. CollationKanaTest::CollationKanaTest()
  34. : myCollation(0)
  35. {
  36.     UErrorCode status = U_ZERO_ERROR;
  37.     myCollation = Collator::createInstance(Locale::JAPAN, status);
  38.     myCollation->setDecomposition(Normalizer::DECOMP);
  39. }
  40.  
  41. CollationKanaTest::~CollationKanaTest()
  42. {
  43.     delete myCollation;
  44. }
  45.  
  46. const UChar CollationKanaTest::testSourceCases[][CollationKanaTest::MAX_TOKEN_LEN] = {
  47.     {'A', 0x0300, 0x0301, 0},
  48.     {'A', 0x0300, 0x0316, 0},
  49.     {'A', 0x0300, 0},
  50.     {0x00C0, 0x0301, 0},
  51.     {0x00C0, 0x0316, 0},
  52.     {0xff9E, 0},
  53.     {0x3042, 0},
  54.     {0x30A2, 0},
  55.     {0x3042, 0x3042, 0},
  56.     {0x30A2, 0x30FC, 0},
  57.     {0x30A2, 0x30FC, 0x30C8, 0}                               // 11
  58. };
  59.  
  60. const UChar CollationKanaTest::testTargetCases[][CollationKanaTest::MAX_TOKEN_LEN] = {
  61.     {'A', 0x0301, 0x0300, 0},
  62.     {'A', 0x0316, 0x0300, 0},
  63.     {0x00C0, 0},
  64.     {'A', 0x0301, 0x0300, 0},
  65.     {'A', 0x0316, 0x0300, 0},
  66.     {0xFF9F, 0},
  67.     {0x30A2, 0},
  68.     {0x3042, 0x3042, 0},
  69.     {0x30A2, 0x30FC, 0},
  70.     {0x30A2, 0x30FC, 0x30C8, 0},
  71.     {0x3042, 0x3042, 0x3089, 0}                               // 11
  72. };
  73.  
  74. const Collator::EComparisonResult CollationKanaTest::results[] = {
  75.     Collator::GREATER,
  76.     Collator::EQUAL,
  77.     Collator::EQUAL,
  78.     Collator::GREATER,
  79.     Collator::EQUAL,
  80.     Collator::LESS,
  81.     Collator::LESS,
  82.     Collator::LESS,
  83.     Collator::LESS,
  84.     Collator::LESS,
  85.     Collator::LESS                                          // 11
  86. };
  87.  
  88. void CollationKanaTest::doTest( UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
  89. {
  90.     Collator::EComparisonResult compareResult = myCollation->compare(source, target);
  91.     CollationKey sortKey1, sortKey2;
  92.     UErrorCode key1status = U_ZERO_ERROR, key2status = U_ZERO_ERROR; //nos
  93.     myCollation->getCollationKey(source, /*nos*/ sortKey1, key1status );
  94.     myCollation->getCollationKey(target, /*nos*/ sortKey2, key2status );
  95.     if (U_FAILURE(key1status) || U_FAILURE(key2status)) {
  96.         errln("SortKey generation Failed.\n");
  97.         return;
  98.     }
  99.     Collator::EComparisonResult keyResult = sortKey1.compareTo(sortKey2);
  100.     reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
  101. }
  102.  
  103. void CollationKanaTest::TestTertiary( char* par )
  104. {
  105.     int32_t i = 0;
  106.     myCollation->setStrength(Collator::TERTIARY);
  107.     for (i = 0; i < 11; i++) {
  108.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  109.     }
  110. }
  111.  
  112. void CollationKanaTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  113. {
  114.     if (exec) logln("TestSuite CollationKanaTest: ");
  115.     switch (index) {
  116.         case 0: name = "TestTertiary";  if (exec)   TestTertiary( par ); break;
  117.         default: name = ""; break;
  118.     }
  119. }
  120.  
  121.  
  122.