home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / dacoll.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  8.6 KB  |  249 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 _DACOLL
  31. #include "dacoll.h"
  32. #endif
  33.  
  34. CollationDanishTest::CollationDanishTest()
  35. : myCollation(0)
  36. {
  37.     UErrorCode status = U_ZERO_ERROR;
  38.     myCollation = Collator::createInstance(Locale("da", "DK", ""),status);
  39. }
  40.  
  41. CollationDanishTest::~CollationDanishTest()
  42. {
  43.     delete myCollation;
  44. }
  45.  
  46. const UChar CollationDanishTest::testSourceCases[][CollationDanishTest::MAX_TOKEN_LEN] = {
  47.     {'L', 'u', 'c', 0},
  48.     {'l', 'u', 'c', 'k', 0},
  49.     {'L', 0x00FC, 'b', 'e', 'c', 'k', 0},
  50.     {'L', 0x00E4, 'v', 'i', 0},
  51.     {'L', 0x00F6, 'w', 'w', 0},
  52.     {'L', 'v', 'i', 0},
  53.     {'L', 0x00E4, 'v', 'i', 0},
  54.     {'L', 0x00FC, 'b', 'e', 'c', 'k', 0}
  55. };
  56.  
  57. const UChar CollationDanishTest::testTargetCases[][CollationDanishTest::MAX_TOKEN_LEN] = {
  58.     {'l', 'u', 'c', 'k', 0},
  59.     {'L', 0x00FC, 'b', 'e', 'c', 'k', 0},
  60.     {'l', 'y', 'b', 'e', 'c', 'k', 0},
  61.     {'L', 0x00F6, 'w', 'e', 0},
  62.     {'m', 'a', 's', 't', 0},
  63.     {'L', 'w', 'i', 0},
  64.     {'L', 0x00F6, 'w', 'i', 0},
  65.     {'L', 'y', 'b', 'e', 'c', 'k', 0}
  66. };
  67.  
  68. const Collator::EComparisonResult CollationDanishTest::results[] = {
  69.     Collator::LESS,
  70.     Collator::LESS,
  71.     Collator::GREATER,
  72.     Collator::LESS,
  73.     Collator::LESS,
  74.     // test primary > 5
  75.     Collator::EQUAL,
  76.     Collator::LESS,
  77.     Collator::EQUAL
  78. };
  79.  
  80. const UChar CollationDanishTest::testBugs[][CollationDanishTest::MAX_TOKEN_LEN] = {
  81.     {'A', '/', 'S', 0},
  82.     {'A', 'N', 'D', 'R', 'E', 0},
  83.     {'A', 'N', 'D', 'R', 0x00C9, 0},
  84.     {'A', 'N', 'D', 'R', 'E', 'A', 'S', 0},
  85.     {'A', 'S', 0},
  86.     {'C', 'A', 0},
  87.     {0x00C7, 'A', 0},
  88.     {'C', 'B', 0},
  89.     {0x00C7, 'C', 0},
  90.     {'D', '.', 'S', '.', 'B', '.', 0},
  91.     {'D', 'A', 0},                                                                           // 10
  92.     {'D', 'B', 0},
  93.     {'D', 'S', 'B', 0},
  94.     {'D', 'S', 'C', 0},
  95.     {'E', 'K', 'S', 'T', 'R', 'A', '_', 'A', 'R', 'B', 'E', 'J', 'D', 'E', 0},
  96.     {'E', 'K', 'S', 'T', 'R', 'A', 'B', 'U', 'D', 0},
  97.     {'H', 0x00D8, 'S', 'T', 0},  // could the 0x00D8 be 0x2205?
  98.     {'H', 'A', 'A', 'G', 0},                                                                 // 20
  99.     {'H', 0x00C5, 'N', 'D', 'B', 'O', 'G', 0},
  100.     {'H', 'A', 'A', 'N', 'D', 'V', 0x00C6, 'R', 'K', 'S', 'B', 'A', 'N', 'K', 'E', 'N', 0},
  101.     {'k', 'a', 'r', 'l', 0},
  102.     {'K', 'a', 'r', 'l', 0},
  103.     {'N', 'I', 'E', 'L', 'S', 'E', 'N', 0},
  104.     {'N', 'I', 'E', 'L', 'S', ' ', 'J', 0x00D8, 'R', 'G', 'E', 'N', 0},
  105.     {'N', 'I', 'E', 'L', 'S', '-', 'J', 0x00D8, 'R', 'G', 'E', 'N', 0},
  106.     {'R', 0x00C9, 'E', ',', ' ', 'A', 0},
  107.     {'R', 'E', 'E', ',', ' ', 'B', 0},
  108.     {'R', 0x00C9, 'E', ',', ' ', 'L', 0},                                                    // 30
  109.     {'R', 'E', 'E', ',', ' ', 'V', 0},
  110.     {'S', 'C', 'H', 'Y', 'T', 'T', ',', ' ', 'B', 0},
  111.     {'S', 'C', 'H', 'Y', 'T', 'T', ',', ' ', 'H', 0},
  112.     {'S', 'C', 'H', 0x00DC, 'T', 'T', ',', ' ', 'H', 0},
  113.     {'S', 'C', 'H', 'Y', 'T', 'T', ',', ' ', 'L', 0},
  114.     {'S', 'C', 'H', 0x00DC, 'T', 'T', ',', ' ', 'M', 0},
  115.     {'S', 'S', 0},
  116.     {0x00DF, 0},
  117.     {'S', 'S', 'A', 0},
  118.     {'S', 'T', 'O', 'R', 'E', 'K', 0x00C6, 'R', 0},
  119.     {'S', 'T', 'O', 'R', 'E', ' ', 'V', 'I', 'L', 'D', 'M', 'O', 'S', 'E', 0},               // 40
  120.     {'S', 'T', 'O', 'R', 'M', 'L', 'Y', 0},
  121.     {'S', 'T', 'O', 'R', 'M', ' ', 'P', 'E', 'T', 'E', 'R', 'S', 'E', 'N', 0},
  122.     {'T', 'H', 'O', 'R', 'V', 'A', 'L', 'D', 0},
  123.     {'T', 'H', 'O', 'R', 'V', 'A', 'R', 'D', 'U', 'R', 0},
  124.     {0x00FE, 'O', 'R', 'V', 'A', 'R', 0x0110, 'U', 'R', 0},
  125.     {'T', 'H', 'Y', 'G', 'E', 'S', 'E', 'N', 0},
  126.     {'V', 'E', 'S', 'T', 'E', 'R', 'G', 0x00C5, 'R', 'D', ',', ' ', 'A', 0},
  127.     {'V', 'E', 'S', 'T', 'E', 'R', 'G', 'A', 'A', 'R', 'D', ',', ' ', 'A', 0},
  128.     {'V', 'E', 'S', 'T', 'E', 'R', 'G', 0x00C5, 'R', 'D', ',', ' ', 'B', 0},                 // 50
  129.     {0x00C6, 'B', 'L', 'E', 0},
  130.     {0x00C4, 'B', 'L', 'E', 0},
  131.     {0x00D8, 'B', 'E', 'R', 'G', 0},
  132.     {0x00D6, 'B', 'E', 'R', 'G', 0},
  133.     {0x0110, 'A', 0},
  134.     {0x0110, 'C', 0}                                                                         // 54
  135. };
  136.  
  137. const UChar CollationDanishTest::testNTList[][CollationDanishTest::MAX_TOKEN_LEN] = {
  138.     {'a', 'n', 'd', 'e', 'r', 'e', 0},
  139.     {'c', 'h', 'a', 'q', 'u', 'e', 0},
  140.     {'c', 'h', 'e', 'm', 'i', 'n', 0},
  141.     {'c', 'o', 't', 'e', 0},
  142.     {'c', 'o', 't', 0x00e9, 0},
  143.     {'c', 0x00f4, 't', 'e', 0},
  144.     {'c', 0x00f4, 't', 0x00e9, 0},
  145.     {0x010d, 'u', 0x010d, 0x0113, 't', 0},
  146.     {'C', 'z', 'e', 'c', 'h', 0},
  147.     {'h', 'i', 0x0161, 'a', 0},
  148.     {'i', 'r', 'd', 'i', 's', 'c', 'h', 0},
  149.     {'l', 'i', 'e', 0},
  150.     {'l', 'i', 'r', 'e', 0},
  151.     {'l', 'l', 'a', 'm', 'a', 0},
  152.     {'l', 0x00f5, 'u', 'g', 0},
  153.     {'l', 0x00f2, 'z', 'a', 0},
  154.     {'l', 'u', 0x010d, 0},                                
  155.     {'l', 'u', 'c', 'k', 0},
  156.     {'L', 0x00fc, 'b', 'e', 'c', 'k', 0},
  157.     {'l', 'y', 'e', 0},                               /* 20 */
  158.     {'l', 0x00e4, 'v', 'i', 0},
  159.     {'L', 0x00f6, 'w', 'e', 'n', 0},
  160.     {'m', 0x00e0, 0x0161, 't', 'a', 0},
  161.     {'m', 0x00ee, 'r', 0},
  162.     {'m', 'y', 'n', 'd', 'i', 'g', 0},
  163.     {'M', 0x00e4, 'n', 'n', 'e', 'r', 0},
  164.     {'m', 0x00f6, 'c', 'h', 't', 'e', 'n', 0},
  165.     {'p', 'i', 0x00f1, 'a', 0},
  166.     {'p', 'i', 'n', 't', 0},
  167.     {'p', 'y', 'l', 'o', 'n', 0},
  168.     {0x0161, 0x00e0, 'r', 'a', 'n', 0},
  169.     {'s', 'a', 'v', 'o', 'i', 'r', 0},
  170.     {0x0160, 'e', 'r', 'b', 0x016b, 'r', 'a', 0},
  171.     {'S', 'i', 'e', 't', 'l', 'a', 0},
  172.     {0x015b, 'l', 'u', 'b', 0},
  173.     {'s', 'u', 'b', 't', 'l', 'e', 0},
  174.     {'s', 'y', 'm', 'b', 'o', 'l', 0},
  175.     {'s', 0x00e4, 'm', 't', 'l', 'i', 'c', 'h', 0},
  176.     {'w', 'a', 'f', 'f', 'l', 'e', 0},
  177.     {'v', 'e', 'r', 'k', 'e', 'h', 'r', 't', 0},
  178.     {'w', 'o', 'o', 'd', 0},
  179.     {'v', 'o', 'x', 0},                                 /* 40 */
  180.     {'v', 0x00e4, 'g', 'a', 0},
  181.     {'y', 'e', 'n', 0},
  182.     {'y', 'u', 'a', 'n', 0},
  183.     {'y', 'u', 'c', 'c', 'a', 0},
  184.     {0x017e, 'a', 'l', 0},
  185.     {0x017e, 'e', 'n', 'a', 0},
  186.     {0x017d, 'e', 'n', 0x0113, 'v', 'a', 0},
  187.     {'z', 'o', 'o', 0},
  188.     {'Z', 'v', 'i', 'e', 'd', 'r', 'i', 'j', 'a', 0},
  189.     {'Z', 0x00fc, 'r', 'i', 'c', 'h', 0},
  190.     {'z', 'y', 's', 'k', 0},             
  191.     {0x00e4, 'n', 'd', 'e', 'r', 'e', 0}                  /* 53 */
  192. };
  193. void CollationDanishTest::doTest( UnicodeString source, UnicodeString target, Collator::EComparisonResult result)
  194. {
  195.     Collator::EComparisonResult compareResult = myCollation->compare(source, target);
  196.     CollationKey sortKey1, sortKey2;
  197.     UErrorCode key1status = U_ZERO_ERROR, key2status = U_ZERO_ERROR; //nos
  198.     myCollation->getCollationKey(source, /*nos*/ sortKey1, key1status );
  199.     myCollation->getCollationKey(target, /*nos*/ sortKey2, key2status );
  200.     if (U_FAILURE(key1status) || U_FAILURE(key2status)) {
  201.         errln("SortKey generation Failed.\n");
  202.         return;
  203.     }
  204.     Collator::EComparisonResult keyResult = sortKey1.compareTo(sortKey2);
  205.     reportCResult( source, target, sortKey1, sortKey2, compareResult, keyResult, result );
  206. }
  207.  
  208. void CollationDanishTest::TestTertiary( char* par )
  209. {
  210.     int32_t i = 0;
  211.     myCollation->setStrength(Collator::TERTIARY);
  212.     for (i = 0; i < 5 ; i++) {
  213.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  214.     }
  215.     int32_t j = 0;
  216.     logln("Test internet data list : ");
  217.     for (i = 0; i < 53; i++) {
  218.         for (j = i+1; j < 54; j++) {
  219.             doTest(testBugs[i], testBugs[j], Collator::LESS);
  220.         }
  221.     }
  222.     logln("Test NT data list : ");
  223.     for (i = 0; i < 52; i++) {
  224.         for (j = i+1; j < 53; j++) {
  225.             doTest(testNTList[i], testNTList[j], Collator::LESS);
  226.         }
  227.     }
  228. }
  229. void CollationDanishTest::TestPrimary( char* par )
  230. {
  231.     int32_t i;
  232.     myCollation->setStrength(Collator::PRIMARY);
  233.     for (i = 5; i < 8; i++) {
  234.         doTest(testSourceCases[i], testTargetCases[i], results[i]);
  235.     }
  236. }
  237.  
  238. void CollationDanishTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  239. {
  240.     if (exec) logln("TestSuite CollationDanishTest: ");
  241.     switch (index) {
  242.         case 0: name = "TestPrimary";   if (exec)   TestPrimary( par ); break;
  243.         case 1: name = "TestTertiary";  if (exec)   TestTertiary( par ); break;
  244.         default: name = ""; break;
  245.     }
  246. }
  247.  
  248.  
  249.