home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / escoll.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  3.5 KB  |  126 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.  
  14. #ifndef _COLL
  15. #include "coll.h"
  16. #endif
  17.  
  18. #ifndef _TBLCOLL
  19. #include "tblcoll.h"
  20. #endif
  21.  
  22. #ifndef _UNISTR
  23. #include "unistr.h"
  24. #endif
  25.  
  26. #ifndef _SORTKEY
  27. #include "sortkey.h"
  28. #endif
  29.  
  30. #ifndef _ESCOLL
  31. #include "escoll.h"
  32. #endif
  33.  
  34. CollationSpanishTest::CollationSpanishTest()
  35. : myCollation(0)
  36. {
  37.     UErrorCode status = U_ZERO_ERROR;
  38.     myCollation = Collator::createInstance(Locale("es", "ES", ""),status);
  39. }
  40.  
  41. CollationSpanishTest::~CollationSpanishTest()
  42. {
  43.     delete myCollation;
  44. }
  45.  
  46. const UChar CollationSpanishTest::testSourceCases[][CollationSpanishTest::MAX_TOKEN_LEN] = {
  47.     {'a', 'l', 'i', 'a', 's', 0},
  48.     {'E', 'l', 'l', 'i', 'o', 't', 0},
  49.     {'H', 'e', 'l', 'l', 'o', 0},
  50.     {'a', 'c', 'H', 'c', 0},
  51.     {'a', 'c', 'c', 0},
  52.     {'a', 'l', 'i', 'a', 's', 0},
  53.     {'a', 'c', 'H', 'c', 0},
  54.     {'a', 'c', 'c', 0},
  55.     {'H', 'e', 'l', 'l', 'o', 0},
  56. };
  57.  
  58. const UChar CollationSpanishTest::testTargetCases[][CollationSpanishTest::MAX_TOKEN_LEN] = {
  59.     {'a', 'l', 'l', 'i', 'a', 's', 0},
  60.     {'E', 'm', 'i', 'o', 't', 0},
  61.     {'h', 'e', 'l', 'l', 'O', 0},
  62.     {'a', 'C', 'H', 'c', 0},
  63.     {'a', 'C', 'H', 'c', 0},
  64.     {'a', 'l', 'l', 'i', 'a', 's', 0},
  65.     {'a', 'C', 'H', 'c', 0},
  66.     {'a', 'C', 'H', 'c', 0},
  67.     {'h', 'e', 'l', 'l', 'O', 0},
  68. };
  69.  
  70. const Collator::EComparisonResult CollationSpanishTest::results[] = {
  71.     Collator::LESS,
  72.     Collator::LESS,
  73.     Collator::GREATER,
  74.     Collator::LESS,
  75.     Collator::LESS,
  76.     // test primary > 5
  77.     Collator::LESS,
  78.     Collator::EQUAL,
  79.     Collator::LESS,
  80.     Collator::EQUAL
  81. };
  82.  
  83. void CollationSpanishTest::doTest( UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
  84. {
  85.     Collator::EComparisonResult compareResult = myCollation->compare(source, target);
  86.     CollationKey sortKey1, sortKey2;
  87.     UErrorCode key1status = U_ZERO_ERROR, key2status = U_ZERO_ERROR; //nos
  88.     myCollation->getCollationKey(source, /*nos*/ sortKey1, key1status );
  89.     myCollation->getCollationKey(target, /*nos*/ sortKey2, key2status );
  90.     if (U_FAILURE(key1status) || U_FAILURE(key2status)) {
  91.         errln("SortKey generation Failed.\n");
  92.         return;
  93.     }
  94.     Collator::EComparisonResult keyResult = sortKey1.compareTo(sortKey2);
  95.     reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
  96. }
  97.  
  98. void CollationSpanishTest::TestTertiary( char* par )
  99. {
  100.     int32_t i = 0;
  101.     myCollation->setStrength(Collator::TERTIARY);
  102.     for (i = 0; i < 5 ; i++) {
  103.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  104.     }
  105. }
  106. void CollationSpanishTest::TestPrimary( char* par )
  107. {
  108.     int32_t i;
  109.     myCollation->setStrength(Collator::PRIMARY);
  110.     for (i = 5; i < 9; i++) {
  111.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  112.     }
  113. }
  114.  
  115. void CollationSpanishTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  116. {
  117.     if (exec) logln("TestSuite CollationSpanishTest: ");
  118.     switch (index) {
  119.         case 0: name = "TestPrimary";   if (exec)   TestPrimary( par ); break;
  120.         case 1: name = "TestTertiary";  if (exec)   TestTertiary( par ); break;
  121.         default: name = ""; break;
  122.     }
  123. }
  124.  
  125.  
  126.