home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / frcoll.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  5.8 KB  |  210 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 _FRCOLL
  31. #include "frcoll.h"
  32. #endif
  33.  
  34. CollationFrenchTest::CollationFrenchTest()
  35. : myCollation(0)
  36. {
  37.     UErrorCode status = U_ZERO_ERROR;
  38.     myCollation = Collator::createInstance(Locale::FRANCE, status);
  39. }
  40.  
  41. CollationFrenchTest::~CollationFrenchTest()
  42. {
  43.     delete myCollation;
  44. }
  45.  
  46. const UChar CollationFrenchTest::testSourceCases[][CollationFrenchTest::MAX_TOKEN_LEN] =
  47. {
  48.     {'a', 'b', 'c', 0},
  49.     {'C', 'O', 'T', 'E', 0},
  50.     {'c', 'o', '-', 'o', 'p', 0},
  51.     {'p', 0x00EA, 'c', 'h', 'e', 0},
  52.     {'p', 0x00EA, 'c', 'h', 'e', 'r', 0},
  53.     {'p', 0x00E9, 'c', 'h', 'e', 'r', 0},
  54.     {'p', 0x00E9, 'c', 'h', 'e', 'r', 0},
  55.     {'H', 'e', 'l', 'l', 'o', 0},
  56.     {0x01f1, 0},
  57.     {0xfb00, 0},
  58.     {0x01fa, 0},
  59.     {0x0101, 0}
  60. };
  61.  
  62. const UChar CollationFrenchTest::testTargetCases[][CollationFrenchTest::MAX_TOKEN_LEN] =
  63. {
  64.     {'A', 'B', 'C', 0},
  65.     {'c', 0x00f4, 't', 'e', 0},
  66.     {'C', 'O', 'O', 'P', 0},
  67.     {'p', 0x00E9, 'c', 'h', 0x00E9, 0},
  68.     {'p', 0x00E9, 'c', 'h', 0x00E9, 0},
  69.     {'p', 0x00EA, 'c', 'h', 'e', 0},
  70.     {'p', 0x00EA, 'c', 'h', 'e', 'r', 0},
  71.     {'h', 'e', 'l', 'l', 'O', 0},
  72.     {0x01ee, 0},
  73.     {0x25ca, 0},
  74.     {0x00e0, 0},
  75.     {0x01df, 0}
  76. };
  77.  
  78. const Collator::EComparisonResult CollationFrenchTest::results[] =
  79. {
  80.     Collator::LESS,
  81.     Collator::LESS,
  82.     Collator::GREATER,
  83.     Collator::LESS,
  84.     Collator::GREATER,
  85.     Collator::GREATER,
  86.     Collator::LESS,
  87.     Collator::GREATER,
  88.     Collator::GREATER,
  89.     Collator::GREATER,
  90.     Collator::GREATER,
  91.     Collator::GREATER
  92. };
  93.  
  94. // 0x0300 is grave, 0x0301 is acute
  95. // the order of elements in this array must be different than the order in CollationEnglishTest
  96. const UChar CollationFrenchTest::testAcute[][CollationFrenchTest::MAX_TOKEN_LEN] =
  97. {
  98.     {'e', 'e', 0},
  99.     {'e', 0x0301, 'e', 0},
  100.     {'e', 0x0301, 0x0300, 'e', 0},
  101.     {'e', 0x0300, 'e', 0},
  102.     {'e', 0x0300, 0x0301, 'e', 0},
  103.     {'e', 'e', 0x0301, 0},
  104.     {'e', 0x0301, 'e', 0x0301, 0},
  105.     {'e', 0x0301, 0x0300, 'e', 0x0301, 0},
  106.     {'e', 0x0300, 'e', 0x0301, 0},
  107.     {'e', 0x0300, 0x0301, 'e', 0x0301, 0},
  108.     {'e', 'e', 0x0301, 0x0300, 0},
  109.     {'e', 0x0301, 'e', 0x0301, 0x0300, 0},
  110.     {'e', 0x0301, 0x0300, 'e', 0x0301, 0x0300, 0},
  111.     {'e', 0x0300, 'e', 0x0301, 0x0300, 0},
  112.     {'e', 0x0300, 0x0301, 'e', 0x0301, 0x0300, 0},
  113.     {'e', 'e', 0x0300, 0},
  114.     {'e', 0x0301, 'e', 0x0300, 0},
  115.     {'e', 0x0301, 0x0300, 'e', 0x0300, 0},
  116.     {'e', 0x0300, 'e', 0x0300, 0},
  117.     {'e', 0x0300, 0x0301, 'e', 0x0300, 0},
  118.     {'e', 'e', 0x0300, 0x0301, 0},
  119.     {'e', 0x0301, 'e', 0x0300, 0x0301, 0},
  120.     {'e', 0x0301, 0x0300, 'e', 0x0300, 0x0301, 0},
  121.     {'e', 0x0300, 'e', 0x0300, 0x0301, 0},
  122.     {'e', 0x0300, 0x0301, 'e', 0x0300, 0x0301, 0}
  123. };
  124.  
  125. const UChar CollationFrenchTest::testBugs[][CollationFrenchTest::MAX_TOKEN_LEN] =
  126. {
  127.     {'a', 0},
  128.     {'A', 0},
  129.     {'e', 0},
  130.     {'E', 0},
  131.     {0x00e9, 0},
  132.     {0x00e8, 0},
  133.     {0x00ea, 0},
  134.     {0x00eb, 0},
  135.     {'e', 'a', 0},
  136.     {'x', 0}
  137. };
  138.  
  139. void CollationFrenchTest::doTest( UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
  140. {
  141.     Collator::EComparisonResult compareResult = myCollation->compare(source, target);
  142.     CollationKey sortKey1, sortKey2;
  143.     UErrorCode key1status = U_ZERO_ERROR, key2status = U_ZERO_ERROR; //nos
  144.     myCollation->getCollationKey(source, /*nos*/ sortKey1, key1status );
  145.     myCollation->getCollationKey(target, /*nos*/ sortKey2, key2status );
  146.     if (U_FAILURE(key1status) || U_FAILURE(key2status))
  147.     {
  148.         errln("SortKey generation Failed.\n");
  149.         return;
  150.     }
  151.  
  152.     Collator::EComparisonResult keyResult = sortKey1.compareTo(sortKey2);
  153.     reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
  154. }
  155.  
  156. void CollationFrenchTest::TestTertiary( char* par )
  157. {
  158.     int32_t i = 0;
  159.     myCollation->setStrength(Collator::TERTIARY);
  160.     for (i = 0; i < 12 ; i++)
  161.     {
  162.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  163.     }
  164. }
  165.  
  166. void CollationFrenchTest::TestSecondary( char* par )
  167. {
  168.     //test acute and grave ordering
  169.     int32_t i = 0;
  170.     int32_t j;
  171.     Collator::EComparisonResult expected;
  172.     const int32_t testAcuteSize = sizeof(testAcute) / sizeof(testAcute[0]);
  173.     for (i = 0; i < testAcuteSize; i++)
  174.     {
  175.         for (j = 0; j < testAcuteSize; j++)
  176.         {
  177.             if (i <  j) expected = Collator::LESS;
  178.             if (i == j) expected = Collator::EQUAL;
  179.             if (i >  j) expected = Collator::GREATER;
  180.             doTest(testAcute[i], testAcute[j], expected );
  181.         }
  182.     }
  183. }
  184.  
  185. void CollationFrenchTest::TestExtra( char* par )
  186. {
  187.     int32_t i, j;
  188.     myCollation->setStrength(Collator::TERTIARY);
  189.     for (i = 0; i < 9 ; i++)
  190.     {
  191.         for (j = i + 1; j < 10; j += 1)
  192.         {
  193.             doTest(testBugs[i], testBugs[j], Collator::LESS);
  194.         }
  195.     }
  196. }
  197.  
  198. void CollationFrenchTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  199. {
  200.     if (exec) logln("TestSuite CollationFrenchTest: ");
  201.     switch (index) {
  202.         case 0: name = "TestSecondary"; if (exec)   TestSecondary( par ); break;
  203.         case 1: name = "TestTertiary";  if (exec)   TestTertiary( par ); break;
  204.         case 2: name = "TestExtra";     if (exec)   TestExtra( par ); break;
  205.         default: name = ""; break;
  206.     }
  207. }
  208.  
  209.  
  210.