home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / capitst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  21.5 KB  |  524 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1996                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1999                    *
  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. * File CAPITEST.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *     Madhu Katragadda             Ported for C API
  19. *********************************************************************************
  20. *//* C API TEST For COLLATOR */
  21. #include "utypes.h"
  22. #include "ucol.h"
  23. #include "uloc.h"
  24. #include "cintltst.h"
  25. #include "capitst.h"
  26. #include "ustring.h"
  27. #include <memory.h>
  28. #include <string.h>
  29.  
  30. void addCollAPITest(TestNode** root)
  31. {
  32.     addTest(root, &TestProperty,        "tscoll/capitst/TestProperty");
  33.     addTest(root, &TestRuleBasedColl,        "tscoll/capitst/TestRuleBasedColl");
  34.     addTest(root, &TestCompare,        "tscoll/capitst/TestCompare");
  35.     addTest(root, &TestSortKey,        "tscoll/capitst/TestSortKey");
  36.     addTest(root, &TestHashCode,        "tscoll/capitst/TestHashCode");
  37.     addTest(root, &TestElemIter,        "tscoll/capitst/TestElemIter");
  38.     addTest(root, &TestGetAll,        "tscoll/capitst/TestGetAll");
  39.     
  40. }
  41.  
  42. static void doAssert(int condition, const char *message)
  43. {
  44.     if (condition==0) {
  45.         log_err("ERROR :  %c\n", message);
  46.     }
  47. }
  48.  
  49. /* Collator Properties
  50.  ucol_open, ucol_strcoll,  getStrength/setStrength
  51.  getDecomposition/setDecomposition, getDisplayName*/
  52. void TestProperty()
  53. {    
  54.     UCollator *col;
  55.     UChar *disName;
  56.     int32_t len;
  57.     UChar *source, *target;
  58.     int32_t tempLength;
  59.     UErrorCode status = U_ZERO_ERROR;
  60.     
  61.     log_verbose("The property tests begin : \n");
  62.     log_verbose("Test ucol_strcoll : \n");
  63.     col = ucol_open(NULL, &status);
  64.     if (U_FAILURE(status)) {
  65.         log_err("Default Collator creation failed.: %s\n", myErrorName(status));
  66.         return;
  67.     }
  68.  
  69.     source=(UChar*)malloc(sizeof(UChar) * 12);
  70.     target=(UChar*)malloc(sizeof(UChar) * 12);
  71.     
  72.     u_uastrcpy(source, "ab");
  73.     u_uastrcpy(target, "abc");
  74.  
  75.     
  76.     doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_LESS), "ab < abc comparison failed");
  77.     u_uastrcpy(source, "ab");
  78.     u_uastrcpy(target, "AB");
  79.  
  80.     doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_LESS), "ab < AB comparison failed");
  81.     u_uastrcpy(source, "black-bird");
  82.     u_uastrcpy(target, "blackbird");
  83.     doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_GREATER), 
  84.         "black-bird > blackbird comparison failed");
  85.     u_uastrcpy(source, "black bird");
  86.     u_uastrcpy(target, "black-bird");
  87.     doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_LESS), 
  88.         "black bird < black-bird comparison failed");
  89.     u_uastrcpy(source, "Hello");
  90.     u_uastrcpy(target, "hello");
  91.  
  92.     doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_GREATER), 
  93.         "Hello > hello comparison failed");
  94.     free(source);
  95.     free(target);
  96.     log_verbose("Test ucol_strcoll ends.\n");
  97.  
  98.     log_verbose("testing ucol_getStrength() method ...\n");
  99.     doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object has the wrong strength");
  100.     doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference");
  101.         
  102.     log_verbose("testing ucol_setStrength() method ...\n");
  103.     ucol_setStrength(col, UCOL_SECONDARY);
  104.     doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object's strength is secondary difference");
  105.     doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference");
  106.     doAssert( (ucol_getStrength(col) == UCOL_SECONDARY), "collation object has the wrong strength");
  107.  
  108.     log_verbose("testing ucol_setDecomposition() method ...\n");
  109.     ucol_setNormalization(col, UCOL_NO_NORMALIZATION);
  110.     doAssert( (ucol_getNormalization(col) != UCOL_DECOMP_CAN_COMP_COMPAT), "collation object's normalization mode is Canonical decomposition followed by canonical composition");
  111.     doAssert( (ucol_getNormalization(col) != UCOL_DECOMP_CAN), "collation object's normalization mode is canonical decomposition");
  112.     doAssert( (ucol_getNormalization(col) == UCOL_NO_NORMALIZATION), "collation object has the wrong normalization mode");
  113.  
  114.     
  115.     log_verbose("Get display name for the default collation in German : \n");
  116.  
  117.     len=ucol_getDisplayName("en_US", "de_DE", NULL, 0,  &status);
  118.     if(status==U_BUFFER_OVERFLOW_ERROR){
  119.         status=U_ZERO_ERROR;
  120.         disName=(UChar*)malloc(sizeof(UChar) * (len+1));
  121.         ucol_getDisplayName("en_US", "de_DE", disName, len+1,  &status);
  122.     }
  123.     if(U_FAILURE(status)){
  124.         log_err("ERROR: in getDisplayName: %s\n", myErrorName(status));
  125.         return;
  126.     }
  127.     log_verbose("the display name for default collation in german: %s\n", austrdup(disName) );
  128.     log_verbose("Default collation getDisplayName ended.\n");
  129.     free(disName);
  130.  
  131.     log_verbose("ucol_getRules() testing ...\n");
  132.     ucol_getRules(col, &tempLength);
  133.     doAssert( tempLength != 0, "getRules() result incorrect" );
  134.     log_verbose("getRules tests end.\n");
  135.  
  136.     ucol_close(col);
  137.  
  138.     log_verbose("open an collator for french locale");
  139.     col = ucol_open("fr_FR", &status);
  140.     if (U_FAILURE(status)) {
  141.        log_err("ERROR: Creating French collation failed.: %s\n", myErrorName(status));
  142.         return;
  143.     }
  144.     ucol_setStrength(col, UCOL_PRIMARY);
  145.     log_verbose("testing ucol_getStrength() method again ...\n");
  146.     doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object has the wrong strength");
  147.     doAssert( (ucol_getStrength(col) == UCOL_PRIMARY), "collation object's strength is not primary difference");
  148.         
  149.     log_verbose("testing French ucol_setStrength() method ...\n");
  150.     ucol_setStrength(col, UCOL_TERTIARY);
  151.     doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object's strength is not tertiary difference");
  152.     doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference");
  153.     doAssert( (ucol_getStrength(col) != UCOL_SECONDARY), "collation object's strength is secondary difference");
  154.     ucol_close(col);
  155.     
  156.     log_verbose("Get display name for the french collation in english : \n");
  157.     len=ucol_getDisplayName("fr_FR", "en_US", NULL, 0,  &status);
  158.     if(status==U_BUFFER_OVERFLOW_ERROR){
  159.         status=U_ZERO_ERROR;
  160.         disName=(UChar*)malloc(sizeof(UChar) * (len+1));
  161.         ucol_getDisplayName("fr_FR", "en_US", disName, len+1,  &status);
  162.     }
  163.     if(U_FAILURE(status)){
  164.         log_err("ERROR: in getDisplayName: %s\n", myErrorName(status));
  165.         return;
  166.     }
  167.     log_verbose("the display name for french collation in german: %s\n", austrdup(disName) );
  168.     log_verbose("Default collation getDisplayName ended.\n");
  169.     free(disName);
  170.  
  171.        
  172.     
  173.  
  174. }
  175. /* Test RuleBasedCollator and getRules*/
  176. void TestRuleBasedColl()
  177. {
  178.     UCollator *col1, *col2, *col3, *col4;
  179.     UChar ruleset1[60];
  180.     UChar ruleset2[50];
  181.     const UChar *rule1, *rule2, *rule3, *rule4;
  182.     int32_t tempLength;
  183.     UErrorCode status = U_ZERO_ERROR;
  184.     
  185.     u_uastrcpy(ruleset1, "< a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E");
  186.     u_uastrcpy(ruleset2, "< a, A < b, B < c, C < d, D, e, E");
  187.     
  188.     col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT_NORMALIZATION, UCOL_DEFAULT_STRENGTH, &status);
  189.     if (U_FAILURE(status)) {
  190.         log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
  191.         return;
  192.     }
  193.     else
  194.         log_verbose("PASS: RuleBased Collator creation passed\n");
  195.     
  196.     status = U_ZERO_ERROR;
  197.     col2 = ucol_openRules(ruleset2, u_strlen(ruleset2),  UCOL_DEFAULT_NORMALIZATION, UCOL_DEFAULT_STRENGTH, &status);
  198.     if (U_FAILURE(status)) {
  199.         log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
  200.         return;
  201.     }
  202.     else
  203.         log_verbose("PASS: RuleBased Collator creation passed\n");
  204.     
  205.     
  206.     status = U_ZERO_ERROR;
  207.     col3= ucol_open(NULL, &status);
  208.     if (U_FAILURE(status)) {
  209.         log_err("Default Collator creation failed.: %s\n", myErrorName(status));
  210.         return;
  211.     }
  212.     else
  213.         log_verbose("PASS: Default Collator creation passed\n");
  214.     
  215.     rule1 = ucol_getRules(col1, &tempLength);
  216.     rule2 = ucol_getRules(col2, &tempLength);
  217.     rule3 = ucol_getRules(col3, &tempLength);
  218.  
  219.     doAssert((u_strcmp(rule1, rule2) != 0), "Default collator getRules failed");
  220.     doAssert((u_strcmp(rule2, rule3) != 0), "Default collator getRules failed");
  221.     doAssert((u_strcmp(rule1, rule3) != 0), "Default collator getRules failed");
  222.     
  223.     col4=ucol_openRules(rule2, u_strlen(rule2), UCOL_DEFAULT_NORMALIZATION, UCOL_DEFAULT_STRENGTH, &status);
  224.     if (U_FAILURE(status)) {
  225.         log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
  226.         return;
  227.     }
  228.     rule4= ucol_getRules(col4, &tempLength);
  229.     doAssert((u_strcmp(rule2, rule4) == 0), "Default collator getRules failed");
  230.  
  231.     ucol_close(col1);
  232.     ucol_close(col2);
  233.     ucol_close(col3);
  234.     ucol_close(col4);
  235.         
  236. }
  237.  
  238. void TestCompare()
  239. {
  240.     UErrorCode status = U_ZERO_ERROR;
  241.     UCollator *col;
  242.     UChar* test1;
  243.     UChar* test2;
  244.     
  245.     log_verbose("The compare tests begin : \n");
  246.     status=U_ZERO_ERROR;
  247.     col = ucol_open("en_US", &status);
  248.     if(U_FAILURE(status)) {
  249.         log_err("ucal_open() collation creation failed.: %s\n", myErrorName(status));
  250.         return;
  251.     }
  252.     test1=(UChar*)malloc(sizeof(UChar) * 6);
  253.     test2=(UChar*)malloc(sizeof(UChar) * 6);
  254.     u_uastrcpy(test1, "Abcda");
  255.     u_uastrcpy(test2, "abcda");
  256.     
  257.     log_verbose("Use tertiary comparison level testing ....\n");
  258.                 
  259.     doAssert( (!ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" != \"abcda\" ");
  260.     doAssert( (ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\" ");
  261.     doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\""); 
  262.  
  263.     ucol_setStrength(col, UCOL_SECONDARY);
  264.     log_verbose("Use secondary comparison level testing ....\n");
  265.                 
  266.     doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\"");
  267.     doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
  268.     doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\"");  
  269.  
  270.     ucol_setStrength(col, UCOL_PRIMARY);
  271.     log_verbose("Use primary comparison level testing ....\n");
  272.     
  273.     doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
  274.     doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
  275.     doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");  
  276.  
  277.       
  278.     log_verbose("The compare tests end.\n");
  279.     ucol_close(col);
  280.     free(test1);
  281.     free(test2);
  282.    
  283. }
  284. /*
  285. ----------------------------------------------------------------------------
  286.  ctor -- Tests the getSortKey
  287. */
  288. void TestSortKey()
  289. {   
  290.     uint8_t *sortk1, *sortk2, *sortk3;
  291.     int32_t sortklen;
  292.     UCollator *col;
  293.     UChar *test1, *test2, *test3;
  294.     UErrorCode status = U_ZERO_ERROR;
  295.     log_verbose("testing SortKey begins...\n");
  296.     col = ucol_open(NULL, &status);
  297.     if (U_FAILURE(status)) {
  298.         log_err("ERROR: Default collation creation failed.: %s\n", myErrorName(status));
  299.         return;
  300.     }
  301.  
  302.     test1=(UChar*)malloc(sizeof(UChar) * 6);
  303.     test2=(UChar*)malloc(sizeof(UChar) * 6);
  304.     test3=(UChar*)malloc(sizeof(UChar) * 6);
  305.     u_uastrcpy(test1, "Abcda");
  306.     u_uastrcpy(test2, "abcda");
  307.     u_uastrcpy(test3, "abcda");
  308.  
  309.     log_verbose("Use tertiary comparison level testing ....\n");
  310.     sortklen=ucol_getSortKey(col, test1, u_strlen(test1),  NULL, 0);
  311.     sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  312.     ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1);
  313.     sortklen=ucol_getSortKey(col, test2, u_strlen(test2),  NULL, 0);
  314.     sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  315.     ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1);
  316.     sortklen=ucol_getSortKey(col, test2, u_strlen(test3),  NULL, 0);
  317.     sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  318.     ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortklen+1);
  319.  
  320.     doAssert( (memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" > \"abcda\"");
  321.     doAssert( (memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" < \"Abcda\"");
  322.     doAssert( (memcmp(sortk2, sortk3, sortklen) == 0), "Result should be \"abcda\" ==  \"abcda\"");
  323.     free(sortk1);
  324.     free(sortk2);
  325.     free(sortk3);
  326.  
  327.     log_verbose("Use secondary comparision level testing ...\n");
  328.     ucol_setStrength(col, UCOL_SECONDARY);
  329.     sortklen=ucol_getSortKey(col, test1, u_strlen(test1),  NULL, 0);
  330.     sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  331.     ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1);
  332.     sortklen=ucol_getSortKey(col, test2, u_strlen(test2),  NULL, 0);
  333.     sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
  334.     ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1);
  335.     
  336.     doAssert( !(memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" == \"abcda\"");
  337.     doAssert( !(memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" == \"Abcda\"");
  338.     doAssert( (memcmp(sortk1, sortk2, sortklen) == 0), "Result should be \"abcda\" ==  \"abcda\"");
  339.     
  340.     
  341.     log_verbose("testing sortkey ends...\n");
  342.     ucol_close(col);
  343.     free(test1);
  344.     free(test2);
  345.     free(test3);
  346.     free(sortk1);
  347.     free(sortk2);
  348.      
  349. }
  350. void TestHashCode()
  351. {
  352.     uint8_t *sortk1, *sortk2, *sortk3;
  353.     int32_t sortk1len, sortk2len, sortk3len;
  354.     UCollator *col;
  355.     UChar *test1, *test2, *test3;
  356.     UErrorCode status = U_ZERO_ERROR;
  357.     log_verbose("testing getHashCode begins...\n");
  358.     col = ucol_open("en_US", &status);
  359.     if (U_FAILURE(status)) {
  360.         log_err("ERROR: Default collation creation failed.: %s\n", myErrorName(status));
  361.         return;
  362.     }
  363.     test1=(UChar*)malloc(sizeof(UChar) * 6);
  364.     test2=(UChar*)malloc(sizeof(UChar) * 6);
  365.     test3=(UChar*)malloc(sizeof(UChar) * 6);
  366.     u_uastrcpy(test1, "Abcda");
  367.     u_uastrcpy(test2, "abcda");
  368.     u_uastrcpy(test3, "abcda");
  369.  
  370.     log_verbose("Use tertiary comparison level testing ....\n");
  371.     sortk1len=ucol_getSortKey(col, test1, u_strlen(test1),  NULL, 0);
  372.     sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortk1len+1));
  373.     ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortk1len+1);
  374.     sortk2len=ucol_getSortKey(col, test2, u_strlen(test2),  NULL, 0);
  375.     sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortk2len+1));
  376.     ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortk2len+1);
  377.     sortk3len=ucol_getSortKey(col, test2, u_strlen(test3),  NULL, 0);
  378.     sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortk3len+1));
  379.     ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortk3len+1);
  380.         
  381.     
  382.     log_verbose("ucol_hashCode() testing ...\n");
  383.     
  384.     doAssert( ucol_keyHashCode(sortk1, sortk1len) != ucol_keyHashCode(sortk2, sortk2len), "Hash test1 result incorrect" );               
  385.     doAssert( !(ucol_keyHashCode(sortk1, sortk1len) == ucol_keyHashCode(sortk2, sortk2len)), "Hash test2 result incorrect" );
  386.     doAssert( ucol_keyHashCode(sortk2, sortk2len) == ucol_keyHashCode(sortk3, sortk3len), "Hash result not equal" );
  387.     
  388.     log_verbose("hashCode tests end.\n");
  389.     ucol_close(col);
  390.     free(sortk1);
  391.     free(sortk2);
  392.     free(sortk3);
  393.  
  394. }
  395. /*
  396.  *----------------------------------------------------------------------------
  397.  * Tests the UCollatorElements API.
  398.  * 
  399.  */ 
  400. void TestElemIter()
  401. {
  402.     UTextOffset offset;
  403.     int32_t order1, order2, order3;
  404.     UChar *testString1, *testString2;
  405.     UCollator *col;
  406.     UCollationElements *iterator1, *iterator2, *iterator3;
  407.     UErrorCode status = U_ZERO_ERROR;
  408.     log_verbose("testing UCollatorElements begins...\n");
  409.     col = ucol_open(NULL, &status);
  410.     ucol_setNormalization(col, UCOL_NO_NORMALIZATION);
  411.     if (U_FAILURE(status)) {
  412.         log_err("ERROR: Default collation creation failed.: %s\n", myErrorName(status));
  413.         return;
  414.     }
  415.  
  416.     testString1=(UChar*)malloc(sizeof(UChar) * 150);
  417.     testString2=(UChar*)malloc(sizeof(UChar) * 150);
  418.     u_uastrcpy(testString1, "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?");
  419.     u_uastrcpy(testString2, "Xf ile What subset of all possible test cases has the lowest probability of detecting the least errors?");
  420.     
  421.     log_verbose("Constructors and comparison testing....\n");
  422.     
  423.     iterator1 = ucol_openElements(col, testString1, u_strlen(testString1), &status);
  424.     if(U_FAILURE(status)) {
  425.         log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status));
  426.         ucol_close(col);
  427.         return;
  428.     }
  429.     else{ log_verbose("PASS: Default collationElement iterator1 creation passed\n");}
  430.  
  431.     iterator2 = ucol_openElements(col, testString1, u_strlen(testString1), &status);
  432.     if(U_FAILURE(status)) {
  433.         log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status));
  434.         ucol_close(col);
  435.         return;
  436.     }
  437.     else{ log_verbose("PASS: Default collationElement iterator2 creation passed\n");}
  438.  
  439.     iterator3 = ucol_openElements(col, testString2, u_strlen(testString2), &status);
  440.     if(U_FAILURE(status)) {
  441.         log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status));
  442.         ucol_close(col);
  443.         return;
  444.     }
  445.     else{ log_verbose("PASS: Default collationElement iterator3 creation passed\n");}
  446.  
  447.     offset=ucol_getOffset(iterator1);
  448.     ucol_setOffset(iterator1, 6, &status);
  449.     if (U_FAILURE(status)) {
  450.         log_err("Error in setOffset for UCollatorElements iterator.: %s\n", myErrorName(status));
  451.         return;
  452.     }
  453.     if(ucol_getOffset(iterator1)==6)
  454.         log_verbose("setOffset and getOffset working fine\n");
  455.     else{
  456.         log_err("error in set and get Offset got %d instead of 6\n", ucol_getOffset(iterator1));
  457.     }
  458.  
  459.     ucol_setOffset(iterator1, 0, &status);
  460.     order1 = ucol_next(iterator1, &status);
  461.     if (U_FAILURE(status)) {
  462.         log_err("Somehow ran out of memory stepping through the iterator1.: %s\n", myErrorName(status));
  463.         return;
  464.     }
  465.     order2=ucol_getOffset(iterator2);
  466.     doAssert((order1 != order2), "The first iterator advance failed");
  467.     order2 = ucol_next(iterator2, &status);
  468.     if (U_FAILURE(status)) {
  469.         log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
  470.         return;
  471.     }
  472.     order3 = ucol_next(iterator3, &status);
  473.     if (U_FAILURE(status)) {
  474.         log_err("Somehow ran out of memory stepping through the iterator3.: %s\n", myErrorName(status));
  475.         return;
  476.     }
  477.     
  478.     doAssert((order1 == order2), "The second iterator advance failed should be the same as first one");
  479.     
  480.     doAssert( ((order1 & UCOL_PRIMARYMASK) == (order3 & UCOL_PRIMARYMASK)), "The primary orders should be identical");
  481.     doAssert( ((order1 & UCOL_SECONDARYMASK) == (order3 & UCOL_SECONDARYMASK)), "The secondary orders should be identical");
  482.     doAssert( ((order1 & UCOL_TERTIARYMASK) == (order3 & UCOL_TERTIARYMASK)), "The tertiary orders should be identical");
  483.     
  484.     order1=ucol_next(iterator1, &status);
  485.     order3=ucol_next(iterator3, &status);
  486.     doAssert( ((order1 & UCOL_PRIMARYMASK) == (order3 & UCOL_PRIMARYMASK)), "The primary orders should be identical");
  487.     doAssert( ((order1 & UCOL_TERTIARYMASK) != (order3 & UCOL_TERTIARYMASK)), "The tertiary orders should be different");
  488.     
  489.     order1=ucol_next(iterator1, &status);
  490.     order3=ucol_next(iterator3, &status);
  491.     doAssert( ((order1 & UCOL_SECONDARYMASK) != (order3 & UCOL_SECONDARYMASK)), "The secondary orders should be different");
  492.     doAssert( (order1 != UCOL_NULLORDER), "Unexpected end of iterator reached");
  493.  
  494.     ucol_reset(iterator1);
  495.     ucol_reset(iterator2);
  496.     ucol_reset(iterator3);
  497.  
  498.     free(testString1);
  499.     free(testString2);
  500.     ucol_closeElements(iterator1);
  501.     ucol_closeElements(iterator2);
  502.     ucol_closeElements(iterator3);
  503.     ucol_close(col);
  504.     
  505.     log_verbose("testing CollationElementIterator ends...\n");
  506. }
  507.  
  508. void TestGetAll()
  509. {
  510.     int32_t i, count;
  511.     count=ucol_countAvailable();
  512.     /* use something sensible w/o hardcoding the count */
  513.     if(count < 0){
  514.         log_err("Error in countAvailable(), it returned %d\n", count);
  515.     }
  516.     else{
  517.         log_verbose("Pass: countAvailable() successful, it returned %d\n", count);
  518.     }
  519.     for(i=0;i<count;i++)
  520.         log_verbose("%s\n", ucol_getAvailable(i));
  521.  
  522.  
  523. }
  524.