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