home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / ficoll.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  3.2 KB  |  113 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 _FICOLL
  30. #include "ficoll.h"
  31. #endif
  32.  
  33. CollationFinnishTest::CollationFinnishTest()
  34. : myCollation(0)
  35. {
  36.     UErrorCode status = U_ZERO_ERROR;
  37.     myCollation = Collator::createInstance(Locale("fi", "FI", ""),status);
  38. }
  39.  
  40. CollationFinnishTest::~CollationFinnishTest()
  41. {
  42.     delete myCollation;
  43. }
  44.  
  45. const UChar CollationFinnishTest::testSourceCases[][CollationFinnishTest::MAX_TOKEN_LEN] = {
  46.     {'w', 'a', 't', 0},
  47.     {'v', 'a', 't', 0},
  48.     {'a', 0x00FC, 'b', 'e', 'c', 'k', 0},
  49.     {'L', 0x00E5, 'v', 'i', 0},
  50.     {'w', 'a', 't', 0}
  51. };
  52.  
  53. const UChar CollationFinnishTest::testTargetCases[][CollationFinnishTest::MAX_TOKEN_LEN] = {
  54.     {'v', 'a', 't', 0},
  55.     {'w', 'a', 'y', 0},
  56.     {'a', 'x', 'b', 'e', 'c', 'k', 0},
  57.     {'L', 0x00E4, 'w', 'e', 0},
  58.     {'v', 'a', 't', 0}
  59. };
  60.  
  61. const Collator::EComparisonResult CollationFinnishTest::results[] = {
  62.     Collator::GREATER,
  63.     Collator::LESS,
  64.     Collator::GREATER,
  65.     Collator::LESS,
  66.     // test primary > 4
  67.     Collator::EQUAL,
  68. };
  69.  
  70. void CollationFinnishTest::doTest( UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
  71. {
  72.     Collator::EComparisonResult compareResult = myCollation->compare(source, target);
  73.     CollationKey sortKey1, sortKey2;
  74.     UErrorCode key1status = U_ZERO_ERROR, key2status = U_ZERO_ERROR; //nos
  75.     myCollation->getCollationKey(source, /*nos*/ sortKey1, key1status );
  76.     myCollation->getCollationKey(target, /*nos*/ sortKey2, key2status );
  77.     if (U_FAILURE(key1status) || U_FAILURE(key2status)) {
  78.         errln("SortKey generation Failed.\n");
  79.         return;
  80.     }
  81.     Collator::EComparisonResult keyResult = sortKey1.compareTo(sortKey2);
  82.     reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
  83. }
  84.  
  85. void CollationFinnishTest::TestTertiary( char* par )
  86. {
  87.     int32_t i = 0;
  88.     myCollation->setStrength(Collator::TERTIARY);
  89.     for (i = 0; i < 4 ; i++) {
  90.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  91.     }
  92. }
  93. void CollationFinnishTest::TestPrimary( char* par )
  94. {
  95.     int32_t i;
  96.     myCollation->setStrength(Collator::PRIMARY);
  97.     for (i = 4; i < 5; i++) {
  98.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  99.     }
  100. }
  101.  
  102. void CollationFinnishTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  103. {
  104.     if (exec) logln("TestSuite CollationFinnishTest: ");
  105.     switch (index) {
  106.         case 0: name = "TestPrimary";   if (exec)   TestPrimary( par ); break;
  107.         case 1: name = "TestTertiary";  if (exec)   TestTertiary( par ); break;
  108.         default: name = ""; break;
  109.     }
  110. }
  111.  
  112.  
  113.