home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / trcoll.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  3.6 KB  |  131 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 _TRCOLL
  30. #include "trcoll.h"
  31. #endif
  32.  
  33. CollationTurkishTest::CollationTurkishTest()
  34. : myCollation(0)
  35. {
  36.     UErrorCode status = U_ZERO_ERROR;
  37.     myCollation = Collator::createInstance(Locale("tr", "", ""),status);
  38. }
  39.  
  40. CollationTurkishTest::~CollationTurkishTest()
  41. {
  42.     delete myCollation;
  43. }
  44.  
  45. const UChar CollationTurkishTest::testSourceCases[][CollationTurkishTest::MAX_TOKEN_LEN] = {
  46.     {'s', 0x0327, 0},
  47.     {'v', 0x00E4, 't', 0},
  48.     {'o', 'l', 'd', 0},
  49.     {0x00FC, 'o', 'i', 'd', 0},
  50.     {'h', 0x011E, 'a', 'l', 't', 0},
  51.     {'s', 't', 'r', 'e', 's', 0x015E, 0},
  52.     {'v', 'o', 0x0131, 'd', 0},
  53.     {'i', 'd', 'e', 'a', 0},
  54.     {0x00FC, 'o', 'i', 'd', 0},
  55.     {'v', 'o', 0x0131, 'd', 0},
  56.     {'i', 'd', 'e', 'a', 0}
  57. };
  58.  
  59. const UChar CollationTurkishTest::testTargetCases[][CollationTurkishTest::MAX_TOKEN_LEN] = {
  60.     {'u', 0x0308, 0},
  61.     {'v', 'b', 't', 0},
  62.     {0x00D6, 'a', 'y', 0},
  63.     {'v', 'o', 'i', 'd', 0},
  64.     {'h', 'a', 'l', 't', 0},
  65.     {0x015E, 't', 'r', 'e', 0x015E, 's', 0},
  66.     {'v', 'o', 'i', 'd', 0},
  67.     {'I', 'd', 'e', 'a', 0},
  68.     {'v', 'o', 'i', 'd', 0},
  69.     {'v', 'o', 'i', 'd', 0},
  70.     {'I', 'd', 'e', 'a', 0}
  71. };
  72.  
  73. const Collator::EComparisonResult CollationTurkishTest::results[] = {
  74.     Collator::LESS,
  75.     Collator::LESS,
  76.     Collator::LESS,
  77.     Collator::LESS,
  78.     Collator::GREATER,
  79.     Collator::LESS,
  80.     Collator::LESS,
  81.     Collator::GREATER,
  82.     // test priamry > 8
  83.     Collator::LESS,
  84.     Collator::EQUAL,
  85.     Collator::EQUAL
  86. };
  87.  
  88. void CollationTurkishTest::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 CollationTurkishTest::TestTertiary( char* par )
  104. {
  105.     int32_t i = 0;
  106.     myCollation->setStrength(Collator::TERTIARY);
  107.     for (i = 0; i < 8 ; i++) {
  108.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  109.     }
  110. }
  111. void CollationTurkishTest::TestPrimary( char* par )
  112. {
  113.     int32_t i;
  114.     myCollation->setStrength(Collator::PRIMARY);
  115.     for (i = 8; i < 11; i++) {
  116.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  117.     }
  118. }
  119.  
  120. void CollationTurkishTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  121. {
  122.     if (exec) logln("TestSuite CollationTurkishTest: ");
  123.     switch (index) {
  124.         case 0: name = "TestPrimary";   if (exec)   TestPrimary( par ); break;
  125.         case 1: name = "TestTertiary";  if (exec)   TestTertiary( par ); break;
  126.         default: name = ""; break;
  127.     }
  128. }
  129.  
  130.  
  131.