home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / cregrtst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  63.7 KB  |  1,693 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 CREGRTST.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *     Madhu Katragadda            Ported for C API, added extra functions and tests
  19. *********************************************************************************
  20. */
  21.  
  22. /* C FUNCTIONALITY AND REGRESSION TEST FOR BREAKITERATOR */
  23.  
  24. #include "uloc.h"
  25. #include "ubrk.h"
  26. #include "uchar.h"
  27. #include "utypes.h"
  28. #include "utypes.h"
  29. #include "ustring.h"
  30. #include "cintltst.h"
  31. #include "cregrtst.h"
  32. #include<stdio.h>
  33. #include<string.h>
  34.  
  35.  
  36. /* -------------------------------------------------------------------------------------- */
  37. /**
  38.  * "Vector" structure for holding test tables
  39.  * (this strucure is actually a linked list, but we use the name and API of the
  40.  * java.util.Vector class to keep as much of our test code as possible the same.)
  41.  */
  42. struct Vector1 {
  43.      UChar *text;
  44.     struct Vector1 *link;
  45. };
  46. typedef struct Vector1 Vector;
  47.  
  48. void addElement(Vector *q, const char* string)
  49. {
  50.  
  51.     Vector *p;
  52.         p=(Vector*)malloc(sizeof(Vector));
  53.         p->text=(UChar*)malloc(sizeof(UChar) * (strlen(string)+1));
  54.         u_uastrcpy(p->text, string);
  55.         p->link=NULL;
  56.     while(q->link!=NULL)
  57.         q=q->link;
  58.     q->link=p;
  59.  
  60. }
  61. void addElement2(Vector *q, const UChar* string)
  62. {
  63.  
  64.     Vector *p;
  65.         p=(Vector*)malloc(sizeof(Vector));
  66.         p->text=(UChar*)malloc(sizeof(UChar) * (u_strlen(string)+1));
  67.         u_strcpy(p->text, string);
  68.         p->link=NULL;
  69.     while(q->link!=NULL)
  70.         q=q->link;
  71.     q->link=p;
  72.  
  73. }
  74.  
  75. int32_t Count(Vector *q)
  76. {
  77.     int32_t c=0;
  78.     while(q!=NULL){
  79.         q=q->link;
  80.         c++;
  81.     }
  82.     return c;
  83. }
  84.  
  85. UChar* elementAt(Vector *q, int32_t pos)
  86. {
  87.     int32_t i=0;
  88.     if(q==NULL)
  89.         return NULL;
  90.     for(i=0;i<pos;i++)
  91.         q=q->link;
  92.     return (q->text);
  93. }
  94. /* Just to make it easier to use with UChar array.*/
  95.     
  96. UChar* CharsToUCharArray(const char* chars)
  97. {
  98.     int unicode;
  99.     int i;
  100.     UChar *buffer;
  101.     UChar *alias;
  102.     int len = strlen(chars);
  103.     int count = 0;
  104.  
  105.     /* preflight */
  106.     for (i = 0; i < len;) {
  107.         if ((chars[i] == '\\') && (i+1 < len) && (chars[i+1] == 'u')) {
  108.             ++count;
  109.             i += 6;
  110.         } else {
  111.             ++count;
  112.             i++;
  113.         }
  114.     }
  115.  
  116.     buffer = (UChar*) malloc(sizeof(UChar) * (count + 1));
  117.     alias = buffer;
  118.     
  119.     for (i = 0; i < len;) {
  120.         if ((chars[i] == '\\') && (i+1 < len) && (chars[i+1] == 'u')) {
  121.             
  122.             sscanf(&(chars[i+2]), "%4X", &unicode);
  123.             *alias = (UChar)unicode;
  124.             i += 6;
  125.             ++alias;
  126.         } else {
  127.             *alias = (UChar)chars[i];
  128.             ++alias;
  129.             ++i;
  130.            }
  131.     }
  132.     *alias = 0x0000;
  133.     return buffer;
  134. }
  135. UChar* UCharToUCharArray(const UChar uchar)
  136. {
  137.     UChar *buffer;
  138.     UChar *alias;
  139.     buffer=(UChar*)malloc(sizeof(uchar) * 2);
  140.     alias=buffer;
  141.     *alias=uchar;
  142.     alias++;
  143.     *alias=0x0000;
  144.     return buffer;
  145. }
  146.  
  147.  
  148. UChar* extractBetween(UTextOffset start, UTextOffset end, UChar* text)
  149. {
  150.     UChar* result;
  151.     UChar* temp;
  152.     temp=(UChar*)malloc(sizeof(UChar) * ((u_strlen(text)-start)+1));
  153.     result=(UChar*)malloc(sizeof(UChar) * ((end-start)+1));
  154.     u_strcpy(temp, &text[start]);
  155.     u_strncpy(result, temp, end-start);
  156.  
  157.     return result;
  158. }
  159. /* -------------------------------------------------------------------------------------- */
  160. /**
  161.  * BrealIterator Regression Test is medium top level test class for everything in the C BreakIterator API
  162.  * (ubrk.h and ubrk.c).
  163.  */
  164.  
  165.  
  166.  
  167. const UChar cannedTestArray[] = {
  168.     0x0001, 0x0002, 0x0003, 0x0004, 0x0020, 0x0021, 0x005c, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0028, 0x0029,
  169.     0x002b, 0x002d, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x003c, 0x003d, 0x003e, 0x0041, 0x0042, 0x0043, 0x0044,
  170.     0x0045, 0x005B, 0x005d, 0x005e,    0x005f, 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x007b, 0x007d, 0x007c, 
  171.     0x002c, 0x00a0, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00ab, 0x00ad, 0x00ae, 0x00af, 
  172.     0x00b0, 0x00b2, 0x00b3, 0x00b4, 0x00b9, 0x00bb, 0x00bc, 0x00bd, 0x02b0, 0x02b1, 0x02b2, 0x02b3, 0x02b4, 0x0300, 
  173.     0x0301, 0x0302, 0x0303, 0x0304, 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x0903, 0x093e, 0x093f, 0x0940, 0x0949, 
  174.     0x0f3a, 0x0f3b, 0x2000, 0x2001, 0x2002, 0x200c, 0x200d, 0x200e, 0x200f, 0x2010, 0x2011, 0x2012, 0x2028, 0x2029, 
  175.     0x202a, 0x203e, 0x203f, 0x2040, 0x20dd, 0x20de, 0x20df, 0x20e0, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x0000
  176. };
  177.  
  178.  
  179.  
  180.  
  181. /*--------------------------------------------- */
  182. /* setup methods */
  183. /*--------------------------------------------- */
  184.  
  185. void AllocateTextBoundary()
  186. {
  187.     
  188.    cannedTestChars=(UChar*)malloc(sizeof(UChar) * (u_strlen(cannedTestArray) + 10));
  189.    u_uastrcpy(cannedTestChars,"");
  190.    u_uastrcpy(cannedTestChars,"0x0000");
  191.    u_strcat(cannedTestChars, cannedTestArray);
  192.     
  193. }
  194.  
  195. void FreeTextBoundary()
  196. {
  197.    free(cannedTestChars);
  198. }
  199.  
  200. /*Add Word Data*/
  201. void addTestWordData()
  202. {
  203.     int32_t elems;
  204.     
  205.     
  206.     wordSelectionData=(Vector*)malloc(sizeof(Vector));
  207.     wordSelectionData->text=(UChar*)malloc(sizeof(UChar) * 6);
  208.     u_uastrcpy(wordSelectionData->text, "12,34");
  209.     wordSelectionData->link=NULL;
  210.         
  211.     addElement(wordSelectionData, " ");
  212.     addElement2(wordSelectionData, UCharToUCharArray((UChar)(0x00A2)));   /*cent sign */
  213.     addElement2(wordSelectionData, UCharToUCharArray((UChar)(0x00A3)));   /*pound sign */
  214.     addElement2(wordSelectionData, UCharToUCharArray((UChar)(0x00A4)));   /*currency sign */
  215.     addElement2(wordSelectionData, UCharToUCharArray((UChar)(0x00A5)));   /*yen sign */
  216.     addElement(wordSelectionData, "alpha-beta-gamma");
  217.     addElement(wordSelectionData, ".");
  218.     addElement(wordSelectionData, " ");
  219.     addElement(wordSelectionData, "Badges");
  220.     addElement(wordSelectionData, "?");
  221.     addElement(wordSelectionData, " ");
  222.     addElement(wordSelectionData, "BADGES");
  223.     addElement(wordSelectionData, "!");
  224.     addElement(wordSelectionData, "?");
  225.     addElement(wordSelectionData, "!");
  226.     addElement(wordSelectionData, " ");
  227.     addElement(wordSelectionData, "We");
  228.     addElement(wordSelectionData, " ");
  229.     addElement(wordSelectionData, "don't");
  230.     addElement(wordSelectionData, " ");
  231.     addElement(wordSelectionData, "need");
  232.     addElement(wordSelectionData, " ");
  233.     addElement(wordSelectionData, "no");
  234.     addElement(wordSelectionData, " ");
  235.     addElement(wordSelectionData, "STINKING");
  236.     addElement(wordSelectionData, " ");
  237.     addElement(wordSelectionData, "BADGES");
  238.     addElement(wordSelectionData, "!");
  239.     addElement(wordSelectionData, "!");
  240.     addElement(wordSelectionData, "!");
  241.  
  242.     addElement(wordSelectionData, "012.566,5");
  243.     addElement(wordSelectionData, " ");
  244.     addElement(wordSelectionData, "123.3434,900");
  245.     addElement(wordSelectionData, " ");
  246.     addElement(wordSelectionData, "1000,233,456.000");
  247.     addElement(wordSelectionData, " ");
  248.     addElement(wordSelectionData, "1,23.322%");
  249.     addElement(wordSelectionData, " ");
  250.     addElement(wordSelectionData, "123.1222");
  251.  
  252.     addElement(wordSelectionData, " ");
  253.     addElement(wordSelectionData, "$123,000.20");
  254.  
  255.     addElement(wordSelectionData, " ");
  256.     addElement(wordSelectionData, "179.01%");
  257.  
  258.     addElement(wordSelectionData, "Hello");
  259.     addElement(wordSelectionData, ",");
  260.     addElement(wordSelectionData, " ");
  261.     addElement(wordSelectionData, "how");
  262.     addElement(wordSelectionData, " ");
  263.     addElement(wordSelectionData, "are");
  264.     addElement(wordSelectionData, " ");
  265.     addElement(wordSelectionData, "you");
  266.     addElement(wordSelectionData, " ");
  267.     addElement(wordSelectionData, "X");
  268.     addElement(wordSelectionData, " ");
  269.  
  270.     addElement(wordSelectionData, "Now");
  271.     addElement(wordSelectionData, "\r");
  272.     addElement(wordSelectionData, "is");
  273.     addElement(wordSelectionData, "\n");
  274.     addElement(wordSelectionData, "the");
  275.     addElement(wordSelectionData, "\r\n");
  276.     addElement(wordSelectionData, "time");
  277.     addElement(wordSelectionData, "\n");
  278.     addElement(wordSelectionData, "\r");
  279.     addElement(wordSelectionData, "for");
  280.     addElement(wordSelectionData, "\r");
  281.     addElement(wordSelectionData, "\r");
  282.     addElement(wordSelectionData, "all");
  283.     addElement(wordSelectionData, " ");
  284.  
  285.   /* to test for bug #4097779 */
  286.    addElement2(wordSelectionData, CharsToUCharArray("aa\\u0300a"));
  287.    addElement(wordSelectionData, " ");
  288.  
  289.    /* to test for bug #4098467
  290.      What follows is a string of Korean characters (I found it in the Yellow Pages
  291.      ad for the Korean Presbyterian Church of San Francisco, and I hope I transcribed
  292.      it correctly), first as precomposed syllables, and then as conjoining jamo.
  293.      Both sequences should be semantically identical and break the same way.
  294.      precomposed syllables... */
  295.     addElement2(wordSelectionData, CharsToUCharArray("\\uc0c1\\ud56d"));
  296.     addElement(wordSelectionData, " ");
  297.     addElement2(wordSelectionData, CharsToUCharArray("\\ud55c\\uc778"));
  298.     addElement(wordSelectionData, " ");
  299.     addElement2(wordSelectionData, CharsToUCharArray("\\uc5f0\\ud569"));
  300.     addElement(wordSelectionData, " ");
  301.     addElement2(wordSelectionData, CharsToUCharArray("\\uc7a5\\ub85c\\uad50\\ud68c"));
  302.     addElement(wordSelectionData, " ");
  303.     /* conjoining jamo... */
  304.     addElement2(wordSelectionData, CharsToUCharArray("\\u1109\\u1161\\u11bc\\u1112\\u1161\\u11bc"));
  305.     addElement(wordSelectionData, " ");
  306.     addElement2(wordSelectionData, CharsToUCharArray("\\u1112\\u1161\\u11ab\\u110b\\u1175\\u11ab"));
  307.     addElement(wordSelectionData, " ");
  308.     addElement2(wordSelectionData, CharsToUCharArray("\\u110b\\u1167\\u11ab\\u1112\\u1161\\u11b8"));
  309.     addElement(wordSelectionData, " ");
  310.     addElement2(wordSelectionData, CharsToUCharArray("\\u110c\\u1161\\u11bc\\u1105\\u1169\\u1100\\u116d\\u1112\\u116c"));
  311.     addElement(wordSelectionData, " ");
  312.  
  313.     /* this is a test for bug #4117554: the ideographic iteration mark (U+3005) should
  314.        count as a Kanji character for the purposes of word breaking */
  315.     addElement(wordSelectionData, "abc"); 
  316.     addElement2(wordSelectionData, CharsToUCharArray("\\u4e01\\u4e02\\u3005\\u4e03\\u4e03"));
  317.     addElement(wordSelectionData, "abc");
  318.  
  319.     elems= Count(wordSelectionData);
  320.     log_verbose("In word, the no: of words are: %d\n", elems);
  321.     testWordText = createTestData(wordSelectionData, elems);
  322.     
  323.     
  324. }
  325.  
  326. const UChar kParagraphSeparator = 0x2029;
  327. const UChar kLineSeparator = 0x2028;
  328.  
  329. /**
  330.  * Add Sentence Data
  331.  */
  332. void addTestSentenceData()
  333. {
  334.     int32_t elems;
  335.     UChar temp[100];
  336.  
  337.     sentenceSelectionData=(Vector*)malloc(sizeof(Vector));
  338.     sentenceSelectionData->text=(UChar*)malloc(sizeof(UChar) * (strlen("This is a simple sample sentence. ")+1));
  339.     u_uastrcpy(sentenceSelectionData->text, "This is a simple sample sentence. ");
  340.     sentenceSelectionData->link=NULL;
  341.    
  342.    /* addElement(sentenceSelectionData, "This is a simple sample sentence. "); */
  343.     addElement(sentenceSelectionData, "(This is it.) ");
  344.     addElement(sentenceSelectionData, "This is a simple sample sentence. ");
  345.     addElement(sentenceSelectionData, "\"This isn\'t it.\" ");
  346.     addElement(sentenceSelectionData, "Hi! ");
  347.     addElement(sentenceSelectionData, "This is a simple sample sentence. ");
  348.     addElement(sentenceSelectionData, "It does not have to make any sense as you can see. ");
  349.     addElement(sentenceSelectionData, "Nel mezzo del cammin di nostra vita, mi ritrovai in una selva oscura. ");
  350.     addElement(sentenceSelectionData, "Che la dritta via aveo smarrita. ");
  351.     addElement(sentenceSelectionData, "He said, that I said, that you said!! ");
  352.  
  353.     u_uastrcpy(temp, "Don't rock the boat");
  354.     u_strcat(temp, UCharToUCharArray(kParagraphSeparator));
  355.     addElement2(sentenceSelectionData, temp);
  356.  
  357.     addElement(sentenceSelectionData, "Because I am the daddy, that is why. ");
  358.     addElement(sentenceSelectionData, "Not on my time (el timo.)! ");
  359.  
  360.     u_uastrcpy(temp, "So what!!");
  361.     u_strcat(temp, UCharToUCharArray(kParagraphSeparator));
  362.     addElement2(sentenceSelectionData, temp);
  363.     
  364.     addElement(sentenceSelectionData, "\"But now,\" he said, \"I know!\" ");
  365.     addElement(sentenceSelectionData, "Harris thumbed down several, including \"Away We Go\" (which became the huge success Oklahoma!). ");
  366.     addElement(sentenceSelectionData, "One species, B. anthracis, is highly virulent.\n");
  367.     addElement(sentenceSelectionData, "Wolf said about Sounder:\"Beautifully thought-out and directed.\" ");
  368.     addElement(sentenceSelectionData, "Have you ever said, \"This is where\tI shall live\"? ");
  369.     addElement(sentenceSelectionData, "He answered, \"You may not!\" ");
  370.     addElement(sentenceSelectionData, "Another popular saying is: \"How do you do?\". ");
  371.     addElement(sentenceSelectionData, "Yet another popular saying is: \'I\'m fine thanks.\' ");
  372.     addElement(sentenceSelectionData, "What is the proper use of the abbreviation pp.? ");
  373.     addElement(sentenceSelectionData, "Yes, I am definatelly 12\" tall!!");
  374.  
  375.     /* test for bug #4113835: \n and \r count as spaces, not as paragraph breaks */
  376.     u_uastrcpy(temp, "Now\ris\nthe\r\ntime\n\rfor\r\rall");
  377.     u_strcat(temp, UCharToUCharArray(kParagraphSeparator));
  378.     addElement2(sentenceSelectionData, temp);
  379.  
  380.     /* test for bug #4117554: Treat fullwidth variants of .!? the same as their
  381.        normal counterparts */
  382.     addElement2(sentenceSelectionData, CharsToUCharArray("I know I'm right\\uff0e "));
  383.     addElement2(sentenceSelectionData, CharsToUCharArray("Right\\uff1f "));
  384.     addElement2(sentenceSelectionData, CharsToUCharArray("Right\\uff01 "));
  385.  
  386.     /* test for bug #4117554: Break sentence between a sentence terminator and
  387.        opening punctuation */
  388.     addElement(sentenceSelectionData, "no?");
  389.         u_uastrcpy(temp, "(yes)");
  390.      u_strcat(temp, CharsToUCharArray("\\u2029"));
  391.     addElement2(sentenceSelectionData, temp);
  392.  
  393.     /* test for bug #4158381: Don't break sentence after period if it isn't
  394.        followed by a space */
  395.     addElement(sentenceSelectionData, "Test <code>Flags.Flag</code> class.  ");
  396.      u_uastrcpy(temp, "Another test.");
  397.      u_strcat(temp, CharsToUCharArray("\\u2029"));
  398.     addElement2(sentenceSelectionData, temp);
  399.     
  400.     /* test for bug #4158381: No breaks when there are no terminators around  */
  401.     addElement(sentenceSelectionData, "<P>Provides a set of "lightweight" (all-java<FONT SIZE=\"-2\"><SUP>TM</SUP></FONT> language) components that, to the maximum degree possible, work the same on all platforms.  ");
  402.      u_uastrcpy(temp, "Another test.");
  403.      u_strcat(temp, CharsToUCharArray("\\u2029"));
  404.     addElement2(sentenceSelectionData, temp);
  405.     
  406.     /* test for bug #4143071: Make sure sentences that end with digits work right */
  407.     addElement(sentenceSelectionData, "Today is the 27th of May, 1998.  ");
  408.     addElement(sentenceSelectionData, "Tomorrow with be 28 May 1998.  ");
  409.      u_uastrcpy(temp, "The day after will be the 30th.");
  410.      u_strcat(temp, CharsToUCharArray("\\u2029"));
  411.     addElement2(sentenceSelectionData, temp);
  412.     
  413.     /* test for bug #4152416: Make sure sentences ending with a capital
  414.        letter are treated correctly */
  415.     addElement(sentenceSelectionData, "The type of all primitive <code>boolean</code> values accessed in the target VM.  ");
  416.      u_uastrcpy(temp, "Calls to xxx will return an implementor of this interface.");
  417.      u_strcat(temp, CharsToUCharArray("\\u2029"));
  418.     addElement2(sentenceSelectionData, temp);
  419.  
  420.  
  421.     /* test for bug #4152117: Make sure sentence breaking is handling
  422.        punctuation correctly  */
  423.     addElement(sentenceSelectionData, "Constructs a randomly generated BigInteger, uniformly distributed over the range <tt>0</tt> to <tt>(2<sup>numBits</sup> - 1)</tt>, inclusive.  ");
  424.     addElement(sentenceSelectionData, "The uniformity of the distribution assumes that a fair source of random bits is provided in <tt>rnd</tt>.  ");
  425.      u_uastrcpy(temp, "Note that this constructor always constructs a non-negative BigInteger.");
  426.      u_strcat(temp, CharsToUCharArray("\\u2029"));
  427.     addElement2(sentenceSelectionData, temp);
  428.     
  429.     elems = Count(sentenceSelectionData);
  430.     log_verbose("In sentence: the no: of sentences are %d\n", elems);
  431.     testSentenceText = createTestData(sentenceSelectionData, elems);
  432.     
  433. }
  434.  
  435. /**
  436.  * Add Line Data
  437.  */
  438.  
  439. void addTestLineData()
  440. {
  441.     int32_t elems;
  442.     
  443.     lineSelectionData=(Vector*)malloc(sizeof(Vector));
  444.     lineSelectionData->text=(UChar*)malloc(sizeof(UChar) * 7);
  445.     u_uastrcpy(lineSelectionData->text, "Multi-");
  446.     lineSelectionData->link=NULL;
  447.     
  448.     /* lineSelectionData->addElement("Multi-"); */
  449.     addElement(lineSelectionData, "Level ");
  450.     addElement(lineSelectionData, "example ");
  451.     addElement(lineSelectionData, "of ");
  452.     addElement(lineSelectionData, "a ");
  453.     addElement(lineSelectionData, "semi-");
  454.     addElement(lineSelectionData, "idiotic ");
  455.     addElement(lineSelectionData, "non-");
  456.     addElement(lineSelectionData, "sensical ");
  457.     addElement(lineSelectionData, "(non-");
  458.     addElement(lineSelectionData, "important) ");
  459.     addElement(lineSelectionData, "sentence. ");
  460.  
  461.     addElement(lineSelectionData, "Hi  ");
  462.     addElement(lineSelectionData, "Hello ");
  463.     addElement(lineSelectionData, "How\n");
  464.     addElement(lineSelectionData, "are\r");
  465.     
  466.     
  467.     addElement2(lineSelectionData, CharsToUCharArray("you\\u2028")); /* lineSeperator */
  468.     
  469.     addElement(lineSelectionData, "fine.\t");
  470.     addElement(lineSelectionData, "good.  ");
  471.  
  472.     addElement(lineSelectionData, "Now\r");
  473.     addElement(lineSelectionData, "is\n");
  474.     addElement(lineSelectionData, "the\r\n");
  475.     addElement(lineSelectionData, "time\n");
  476.     addElement(lineSelectionData, "\r");
  477.     addElement(lineSelectionData, "for\r");
  478.     addElement(lineSelectionData, "\r");
  479.     addElement(lineSelectionData, "all ");
  480.  
  481.     /* to test for bug #4068133  */
  482.     addElement2(lineSelectionData, CharsToUCharArray("\\u96f6"));
  483.     addElement2(lineSelectionData, CharsToUCharArray("\\u4e00\\u3002"));
  484.     addElement2(lineSelectionData, CharsToUCharArray("\\u4e8c\\u3001"));
  485.     addElement2(lineSelectionData, CharsToUCharArray("\\u4e09\\u3002\\u3001"));
  486.     addElement2(lineSelectionData, CharsToUCharArray("\\u56db\\u3001\\u3002\\u3001"));
  487.        
  488.     
  489.     addElement2(lineSelectionData, CharsToUCharArray("\\u4e94,"));
  490.     
  491.     addElement2(lineSelectionData, CharsToUCharArray("\\u516d."));
  492.  
  493.     addElement2(lineSelectionData, CharsToUCharArray("\\u4e03.\\u3001,\\u3002"));
  494.     addElement2(lineSelectionData, CharsToUCharArray("\\u516b"));
  495.  
  496.     /* to test for bug #4086052 */
  497.     addElement2(lineSelectionData, CharsToUCharArray("foo\\u00a0bar "));
  498.    
  499.     /* to test for bug #4097920 */
  500.     addElement(lineSelectionData, "dog,");
  501.     addElement(lineSelectionData, "cat,");
  502.     addElement(lineSelectionData, "mouse ");
  503.     addElement(lineSelectionData, "(one)");
  504.     addElement(lineSelectionData, "(two)\n");
  505.  
  506.     /* to test for bug #4035266 */
  507.     addElement(lineSelectionData, "The ");
  508.     addElement(lineSelectionData, "balance ");
  509.     addElement(lineSelectionData, "is ");
  510.     addElement(lineSelectionData, "$-23,456.78, ");
  511.     addElement(lineSelectionData, "not ");
  512.     addElement(lineSelectionData, "-$32,456.78!\n");
  513.  
  514.     /* to test for bug #4098467
  515.        What follows is a string of Korean characters (I found it in the Yellow Pages
  516.        ad for the Korean Presbyterian Church of San Francisco, and I hope I transcribed
  517.        it correctly), first as precomposed syllables, and then as conjoining jamo.
  518.        Both sequences should be semantically identical and break the same way.
  519.        precomposed syllables... */
  520.     addElement2(lineSelectionData, CharsToUCharArray("\\uc0c1\\ud56d "));
  521.     addElement2(lineSelectionData, CharsToUCharArray("\\ud55c\\uc778 "));
  522.     addElement2(lineSelectionData, CharsToUCharArray("\\uc5f0\\ud569 "));
  523.     addElement2(lineSelectionData, CharsToUCharArray("\\uc7a5\\ub85c\\uad50\\ud68c "));
  524.     /* conjoining jamo... */
  525.     addElement2(lineSelectionData, CharsToUCharArray("\\u1109\\u1161\\u11bc\\u1112\\u1161\\u11bc "));
  526.     addElement2(lineSelectionData, CharsToUCharArray("\\u1112\\u1161\\u11ab\\u110b\\u1175\\u11ab "));
  527.     addElement2(lineSelectionData, CharsToUCharArray("\\u110b\\u1167\\u11ab\\u1112\\u1161\\u11b8 "));
  528.     addElement2(lineSelectionData, CharsToUCharArray("\\u110c\\u1161\\u11bc\\u1105\\u1169\\u1100\\u116d\\u1112\\u116c"));
  529.  
  530.     /* to test for bug #4117554: Fullwidth .!? should be treated as postJwrd */
  531.     addElement2(lineSelectionData, CharsToUCharArray("\\u4e01\\uff0e"));
  532.     addElement2(lineSelectionData, CharsToUCharArray("\\u4e02\\uff01"));
  533.     addElement2(lineSelectionData, CharsToUCharArray("\\u4e03\\uff1f"));
  534.  
  535.     elems = Count(lineSelectionData);
  536.     log_verbose("In line: the no: of lines are %d\n", elems);
  537.     testLineText = createTestData(lineSelectionData, elems);
  538.     
  539. }
  540.  
  541. /*
  542.  
  543. const UChar* graveS = "S" + (UniChar)0x0300;
  544. const UChar* acuteBelowI = "i" + UCharToUCharArray(0x0317);
  545. const UChar* acuteE = "e" + UCharToUCharArray(0x0301);
  546. const UChar* circumflexA = "a" + UCharToUCharArray(0x0302);
  547. const UChar* tildeE = "e" + UCharToUCharArray(0x0303);
  548. */
  549.  
  550. /**
  551.  * Add Character Data
  552.  */
  553. void addTestCharacterData()
  554. {
  555.     int32_t elems;
  556.     UChar temp[10];
  557.  
  558.     characterSelectionData=(Vector*)malloc(sizeof(Vector));
  559.     characterSelectionData->text=(UChar*)malloc(sizeof(UChar) * 2);
  560.     u_uastrcpy(characterSelectionData->text, "B");
  561.     characterSelectionData->link=NULL;
  562.  
  563.     u_uastrcpy(temp, "S");
  564.     u_strcat(temp, UCharToUCharArray(0x0317));
  565.     addElement2(characterSelectionData, temp); /* graveS */
  566.   
  567.     u_uastrcpy(temp, "i");
  568.     u_strcat(temp, UCharToUCharArray(0x0301));
  569.     addElement2(characterSelectionData, temp); /* acuteBelowI */
  570.     
  571.     addElement(characterSelectionData, "m");
  572.     addElement(characterSelectionData, "p");
  573.     addElement(characterSelectionData, "l");
  574.  
  575.     u_uastrcpy(temp, "e");
  576.     u_strcat(temp, UCharToUCharArray(0x0301));
  577.     addElement2(characterSelectionData, temp);/* acuteE */
  578.     
  579.     addElement(characterSelectionData, " ");
  580.     addElement(characterSelectionData, "s");
  581.  
  582.     u_uastrcpy(temp, "a");
  583.     u_strcat(temp, UCharToUCharArray(0x0302));
  584.     addElement2(characterSelectionData, temp);/* circumflexA */
  585.     
  586.     addElement(characterSelectionData, "m");
  587.     addElement(characterSelectionData, "p");
  588.     addElement(characterSelectionData, "l");
  589.   
  590.     u_uastrcpy(temp, "e");
  591.     u_strcat(temp, UCharToUCharArray(0x0303));
  592.     addElement2(characterSelectionData, temp); /* tildeE */
  593.     
  594.     addElement(characterSelectionData, ".");
  595.     addElement(characterSelectionData, "w");
  596.     
  597.     u_uastrcpy(temp, "a");
  598.     u_strcat(temp, UCharToUCharArray(0x0302));
  599.     addElement2(characterSelectionData, temp);/* circumflexA */
  600.  
  601.     addElement(characterSelectionData, "w");
  602.     addElement(characterSelectionData, "a");
  603.     addElement(characterSelectionData, "f");
  604.     addElement(characterSelectionData, "q");
  605.     addElement(characterSelectionData, "\n");
  606.     addElement(characterSelectionData, "\r");
  607.     addElement(characterSelectionData, "\r\n");
  608.     addElement(characterSelectionData, "\n");
  609.     addElement(characterSelectionData, "E");
  610.     /* to test for bug #4098467
  611.        What follows is a string of Korean characters (I found it in the Yellow Pages
  612.        ad for the Korean Presbyterian Church of San Francisco, and I hope I transcribed
  613.        it correctly), first as precomposed syllables, and then as conjoining jamo.
  614.        Both sequences should be semantically identical and break the same way.
  615.        precomposed syllables... */
  616.     addElement2(characterSelectionData, CharsToUCharArray("\\uc0c1"));
  617.     addElement2(characterSelectionData, CharsToUCharArray("\\ud56d"));
  618.     addElement(characterSelectionData, " ");
  619.     addElement2(characterSelectionData, CharsToUCharArray("\\ud55c"));
  620.     addElement2(characterSelectionData, CharsToUCharArray("\\uc778"));
  621.     addElement(characterSelectionData, " ");
  622.     addElement2(characterSelectionData, CharsToUCharArray("\\uc5f0"));
  623.     addElement2(characterSelectionData, CharsToUCharArray("\\ud569"));
  624.     addElement(characterSelectionData, " ");
  625.     addElement2(characterSelectionData, CharsToUCharArray("\\uc7a5"));
  626.     addElement2(characterSelectionData, CharsToUCharArray("\\ub85c"));
  627.     addElement2(characterSelectionData, CharsToUCharArray("\\uad50"));
  628.     addElement2(characterSelectionData, CharsToUCharArray("\\ud68c"));
  629.     addElement(characterSelectionData, " ");
  630.     /* conjoining jamo... */
  631.     addElement2(characterSelectionData, CharsToUCharArray("\\u1109\\u1161\\u11bc"));
  632.     addElement2(characterSelectionData, CharsToUCharArray("\\u1112\\u1161\\u11bc"));
  633.     addElement(characterSelectionData, " ");
  634.     addElement2(characterSelectionData, CharsToUCharArray("\\u1112\\u1161\\u11ab"));
  635.     addElement2(characterSelectionData, CharsToUCharArray("\\u110b\\u1175\\u11ab"));
  636.     addElement(characterSelectionData, " ");
  637.     addElement2(characterSelectionData, CharsToUCharArray("\\u110b\\u1167\\u11ab"));
  638.     addElement2(characterSelectionData, CharsToUCharArray("\\u1112\\u1161\\u11b8"));
  639.     addElement(characterSelectionData, " ");
  640.     addElement2(characterSelectionData, CharsToUCharArray("\\u110c\\u1161\\u11bc"));
  641.     addElement2(characterSelectionData, CharsToUCharArray("\\u1105\\u1169"));
  642.     addElement2(characterSelectionData, CharsToUCharArray("\\u1100\\u116d"));
  643.     addElement2(characterSelectionData, CharsToUCharArray("\\u1112\\u116c"));
  644.  
  645.     elems = Count(characterSelectionData);
  646.     log_verbose("In character: the no: of characters are %d", elems);
  647.     testCharacterText = createTestData(characterSelectionData, elems);
  648.     
  649. }
  650.  
  651. UChar* createTestData(Vector *select, int32_t e)
  652. {
  653.   int32_t i, len;
  654.   UChar* result;
  655.   result=(UChar*)malloc(sizeof(UChar) * 2);
  656.   u_uastrcpy(result, "");
  657.   i=0;
  658.   while (i<e) {
  659.       len=u_strlen(result)+1;
  660.       result=(UChar*)realloc(result, sizeof(UChar) * (len + u_strlen(elementAt(select,i))));
  661.       u_strcat(result, elementAt(select,i));
  662.       i++;
  663.   }
  664.  
  665.   return result;
  666. }
  667.  
  668. /*---------------------------------------------
  669.    SentenceBreak tests
  670.   --------------------------------------------- */
  671.  
  672. void TestForwardSentenceSelection()
  673. {
  674.     UErrorCode status = U_ZERO_ERROR;
  675.     UBreakIterator *e;
  676.     addTestSentenceData();
  677.     e = ubrk_open(UBRK_SENTENCE, "en_US", testSentenceText, u_strlen(testSentenceText), &status);
  678.     if(U_FAILURE(status)){
  679.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  680.         return;
  681.     }
  682. /*    sample(e, testSentenceText); */
  683.     log_verbose("Testing forward sentence selection.....\n");
  684.     doForwardSelectionTest(e, testSentenceText, sentenceSelectionData);
  685.     ubrk_close(e);
  686.     free(sentenceSelectionData);
  687. }
  688.  
  689. void TestFirstSentenceSelection()
  690. {
  691.     UErrorCode status = U_ZERO_ERROR;
  692.     UBreakIterator *e;
  693.     addTestSentenceData();
  694.     e = ubrk_open(UBRK_SENTENCE, "en_US", testSentenceText, u_strlen(testSentenceText), &status);
  695.     if(U_FAILURE(status)){
  696.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  697.         return;
  698.     }
  699.     log_verbose("Testing first sentence selection.....\n");
  700.     doFirstSelectionTest(e, testSentenceText, sentenceSelectionData);
  701.     ubrk_close(e);
  702.     free(sentenceSelectionData);
  703. }
  704.  
  705. void TestLastSentenceSelection()
  706. {
  707.     UErrorCode status = U_ZERO_ERROR;
  708.     UBreakIterator *e;
  709.     addTestSentenceData();
  710.     e = ubrk_open(UBRK_SENTENCE, "en_US", testSentenceText, u_strlen(testSentenceText), &status);
  711.     if(U_FAILURE(status)){
  712.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  713.         return;
  714.     }
  715.     log_verbose("Testing last sentence selection.....\n");
  716.     doLastSelectionTest(e, testSentenceText, sentenceSelectionData);
  717.     ubrk_close(e);
  718.     free(sentenceSelectionData);
  719. }
  720.  
  721. void TestBackwardSentenceSelection()
  722. {
  723.     UErrorCode status = U_ZERO_ERROR;
  724.     UBreakIterator *e;
  725.     addTestSentenceData();
  726.     e = ubrk_open(UBRK_SENTENCE, "en_US", testSentenceText, u_strlen(testSentenceText), &status);
  727.     if(U_FAILURE(status)){
  728.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  729.         return;
  730.     }
  731.     log_verbose("Testing backward sentence selection.....\n");
  732.     doBackwardSelectionTest(e, testSentenceText, sentenceSelectionData);
  733.     ubrk_close(e);
  734.     free(sentenceSelectionData);
  735. }
  736.  
  737. void TestForwardSentenceIndexSelection()
  738. {
  739.    UErrorCode status = U_ZERO_ERROR;
  740.     UBreakIterator *e;
  741.     addTestSentenceData();
  742.     e = ubrk_open(UBRK_SENTENCE, "en_US", testSentenceText, u_strlen(testSentenceText), &status);
  743.     if(U_FAILURE(status)){
  744.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  745.         return;
  746.     }
  747.     log_verbose("Testing sentence forward index selection.....\n");
  748.     doForwardIndexSelectionTest(e, testSentenceText, sentenceSelectionData);
  749.     ubrk_close(e);
  750.     free(sentenceSelectionData);
  751. }
  752.  
  753. void TestBackwardSentenceIndexSelection()
  754. {
  755.     UErrorCode status = U_ZERO_ERROR;
  756.     UBreakIterator *e;
  757.     addTestSentenceData();
  758.     e = ubrk_open(UBRK_SENTENCE, "en_US", testSentenceText, u_strlen(testSentenceText), &status);
  759.     if(U_FAILURE(status)){
  760.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  761.         return;
  762.     }
  763.     log_verbose("Testing sentence backward index selection.....\n");
  764.     doBackwardIndexSelectionTest(e, testSentenceText, sentenceSelectionData);
  765.     ubrk_close(e);
  766.     free(sentenceSelectionData);
  767. }
  768.  
  769.  
  770. void TestSentenceInvariants()
  771. {
  772.     int x;
  773.    UChar *s;
  774. AllocateTextBoundary();
  775.    x=u_strlen(cannedTestChars);
  776.    s=(UChar*)malloc(sizeof(UChar) * (x + 15));
  777.    u_strcpy(s, cannedTestChars);
  778.     u_strcat(s, CharsToUCharArray(".,\\u3001\\u3002\\u3041\\u3042\\u3043\\ufeff"));
  779.     log_verbose("Testing sentence Other invariants.....\n");
  780.     doOtherInvariantTest(UBRK_SENTENCE, s);
  781.     free(s);
  782. FreeTextBoundary();
  783. }
  784.  
  785. /*---------------------------------------------
  786.    WordBreak tests
  787.   --------------------------------------------- */
  788.  
  789. void TestForwardWordSelection()
  790. {
  791.     UErrorCode status = U_ZERO_ERROR;
  792.     UBreakIterator *e;
  793.     addTestWordData();
  794.     e = ubrk_open(UBRK_WORD, "en_US", testWordText, u_strlen(testWordText), &status);
  795.     if(U_FAILURE(status)){
  796.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  797.         return;
  798.     }
  799. /*    sample(e, testWordText); */
  800.     log_verbose("Testing forward word selection.....\n");
  801.     doForwardSelectionTest(e, testWordText, wordSelectionData);
  802.     ubrk_close(e);
  803.     free(wordSelectionData);
  804. }
  805.  
  806. void TestFirstWordSelection()
  807. {
  808.     UErrorCode status = U_ZERO_ERROR;
  809.     UBreakIterator *e;
  810.     addTestWordData();
  811.     e = ubrk_open(UBRK_WORD, "en_US", testWordText, u_strlen(testWordText), &status);
  812.     if(U_FAILURE(status)){
  813.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  814.         return;
  815.     }
  816.     log_verbose("Testing first word selection.....\n");
  817.     doFirstSelectionTest(e, testWordText, wordSelectionData);
  818.     ubrk_close(e);
  819.     free(wordSelectionData);
  820. }
  821.  
  822. void TestLastWordSelection()
  823. {
  824.     UErrorCode status = U_ZERO_ERROR;
  825.     UBreakIterator *e;
  826.     addTestWordData();
  827.     e = ubrk_open(UBRK_WORD, "en_US", testWordText, u_strlen(testWordText), &status);
  828.     if(U_FAILURE(status)){
  829.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  830.         return;
  831.     }
  832.     log_verbose("Testing last word selection.....\n");
  833.     doLastSelectionTest(e, testWordText, wordSelectionData);
  834.     ubrk_close(e);
  835.     free(wordSelectionData);
  836. }
  837.  
  838. void TestBackwardWordSelection()
  839. {
  840.     UErrorCode status = U_ZERO_ERROR;
  841.     UBreakIterator *e;
  842.     addTestWordData();
  843.     e = ubrk_open(UBRK_WORD, "en_US", testWordText, u_strlen(testWordText), &status);
  844.     if(U_FAILURE(status)){
  845.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  846.         return;
  847.     }
  848.     log_verbose("Testing backward word selection.....\n");
  849.     doBackwardSelectionTest(e, testWordText, wordSelectionData);
  850.     ubrk_close(e);
  851.     free(wordSelectionData);
  852. }
  853.  
  854. void TestForwardWordIndexSelection()
  855. {
  856.     UErrorCode status = U_ZERO_ERROR;
  857.     UBreakIterator *e;
  858.     addTestWordData();
  859.     e = ubrk_open(UBRK_WORD, "en_US", testWordText, u_strlen(testWordText), &status);
  860.     if(U_FAILURE(status)){
  861.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  862.         return;
  863.     }
  864.     log_verbose("Testing forward word index selection.....\n");
  865.     doForwardIndexSelectionTest(e, testWordText, wordSelectionData);
  866.     ubrk_close(e);
  867.     free(wordSelectionData);
  868. }
  869.  
  870. void TestBackwardWordIndexSelection()
  871. {
  872.     UErrorCode status = U_ZERO_ERROR;
  873.     UBreakIterator *e;
  874.     addTestWordData();
  875.     e = ubrk_open(UBRK_WORD, "en_US", testWordText, u_strlen(testWordText), &status);
  876.     if(U_FAILURE(status)){
  877.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  878.         return;
  879.     }
  880.     log_verbose("Testing backward word index selection.....\n");
  881.     doBackwardIndexSelectionTest(e, testWordText, wordSelectionData);
  882.     ubrk_close(e);
  883.     free(wordSelectionData);
  884. }
  885.  
  886. void TestWordInvariants()
  887. {
  888.    UChar *s;
  889.    int x;
  890. AllocateTextBoundary();
  891.    x=u_strlen(cannedTestChars);
  892.    s=(UChar*)malloc(sizeof(UChar) * (x + 15));
  893.    u_strcpy(s, cannedTestChars);
  894.     u_strcat(s, CharsToUCharArray("\',.\\u3041\\u3042\\u3043\\u309b\\u309c\\u30a1\\u30a2\\u30a3\\u4e00\\u4e01\\u4e02"));
  895.     log_verbose("Testing word break invariant.....\n");
  896.     doBreakInvariantTest(UBRK_WORD, s);
  897.     u_strcpy(s, cannedTestChars);
  898.     u_strcat(s, CharsToUCharArray("\',.\\u3041\\u3042\\u3043\\u309b\\u309c\\u30a1\\u30a2\\u30a3\\u4e00\\u4e01\\u4e02"));
  899.     doOtherInvariantTest(UBRK_WORD, s);
  900.     free(s);
  901. FreeTextBoundary();    
  902. }
  903.  
  904. /*---------------------------------------------
  905.    LineBreak tests
  906.  --------------------------------------------- */
  907.  
  908. void TestForwardLineSelection()
  909. {
  910.     UErrorCode status = U_ZERO_ERROR;
  911.     UBreakIterator *e;
  912.     addTestLineData();
  913.     e = ubrk_open(UBRK_LINE, "en_US", testLineText, u_strlen(testLineText), &status);
  914.     if(U_FAILURE(status)){
  915.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  916.         return;
  917.     }
  918.     log_verbose("Testing forward line selection.....\n");
  919.     doForwardSelectionTest(e, testLineText, lineSelectionData);
  920.     ubrk_close(e);
  921. }
  922.  
  923. void TestFirstLineSelection()
  924. {
  925.     UErrorCode status = U_ZERO_ERROR;
  926.     UBreakIterator *e;
  927.     addTestLineData();
  928.     e = ubrk_open(UBRK_LINE, "en_US", testLineText, u_strlen(testLineText), &status);
  929.     if(U_FAILURE(status)){
  930.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  931.         return;
  932.     }
  933.     log_verbose("Testing first line selection.....\n");
  934.     doFirstSelectionTest(e, testLineText, lineSelectionData);
  935.     ubrk_close(e);
  936.     free(lineSelectionData);
  937. }
  938.  
  939. void TestLastLineSelection()
  940. {
  941.     UErrorCode status = U_ZERO_ERROR;
  942.     UBreakIterator *e;
  943.     addTestLineData();
  944.     e = ubrk_open(UBRK_LINE, "en_US", testLineText, u_strlen(testLineText), &status);
  945.     if(U_FAILURE(status)){
  946.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  947.         return;
  948.     }
  949.     log_verbose("Testing last line selection.....\n");
  950.     doLastSelectionTest(e, testLineText, lineSelectionData);
  951.     ubrk_close(e);
  952.     free(lineSelectionData);
  953. }
  954.  
  955. void TestBackwardLineSelection()
  956. {
  957.     UErrorCode status = U_ZERO_ERROR;
  958.     UBreakIterator *e;
  959.     addTestLineData();
  960.     e = ubrk_open(UBRK_LINE, "en_US", testLineText, u_strlen(testLineText), &status);
  961.     if(U_FAILURE(status)){
  962.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  963.         return;
  964.     }
  965.     log_verbose("Testing backward line selection.....\n");
  966.     doBackwardSelectionTest(e, testLineText, lineSelectionData);
  967.     ubrk_close(e);
  968.     free(lineSelectionData);
  969. }
  970.  
  971. void TestForwardLineIndexSelection()
  972. {
  973.     UErrorCode status = U_ZERO_ERROR;
  974.     UBreakIterator *e;
  975.     addTestLineData();
  976.     e = ubrk_open(UBRK_LINE, "en_US", testLineText, u_strlen(testLineText), &status);
  977.     if(U_FAILURE(status)){
  978.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  979.         return;
  980.     }
  981.     log_verbose("Testing forward line index selection.....\n");
  982.     doForwardIndexSelectionTest(e, testLineText, lineSelectionData);
  983.     ubrk_close(e);
  984.     free(lineSelectionData);
  985. }
  986.  
  987. void TestBackwardLineIndexSelection()
  988. {
  989.     UErrorCode status = U_ZERO_ERROR;
  990.     UBreakIterator *e;
  991.     addTestLineData();
  992.     e = ubrk_open(UBRK_LINE, "en_US", testLineText, u_strlen(testLineText), &status);
  993.     if(U_FAILURE(status)){
  994.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  995.         return;
  996.     }
  997.     log_verbose("Testing backward line index selection.....\n");
  998.     doBackwardIndexSelectionTest(e, testLineText, lineSelectionData);
  999.     ubrk_close(e);
  1000.     free(lineSelectionData);
  1001. }
  1002. void TestLineInvariants()
  1003. {
  1004.     int errorCount,l;
  1005.     UTextOffset i, j, k;
  1006.     UChar c;
  1007.     UBreakIterator *e;
  1008.     UErrorCode status = U_ZERO_ERROR;
  1009.    UChar noBreak[10], dashes[10];
  1010.    bool_t saw2;
  1011.    UChar work[5];
  1012.    UChar *s;
  1013. AllocateTextBoundary();   
  1014.    s=(UChar*)malloc(sizeof(UChar) * (u_strlen(cannedTestChars) + 20));
  1015.    u_strcpy(s, cannedTestChars);
  1016.    u_strcat(s, CharsToUCharArray(".,;:\\u3001\\u3002\\u3041\\u3042\\u3043\\u3044\\u3045\\u30a3\\u4e00\\u4e01\\u4e02"));
  1017.     log_verbose("Testing line break Invariant.....\n");
  1018.    doBreakInvariantTest(UBRK_LINE, s);
  1019.    log_verbose("Testing line other Invariant....\n");
  1020.    doOtherInvariantTest(UBRK_LINE, s);
  1021.  
  1022.     
  1023.  
  1024.     /* in addition to the other invariants, a line-break iterator should make sure that:
  1025.        it doesn't break around the non-breaking characters */
  1026.     errorCount=0;
  1027.     status=U_ZERO_ERROR;
  1028.     u_strcpy(noBreak, CharsToUCharArray("\\u00a0\\u2007\\u2011\\ufeff"));
  1029.     u_uastrcpy(work, "aaa");
  1030.     for (i = 0; i < u_strlen(s); i++) {
  1031.          c = s[i];
  1032.         if (c == '\r' || c == '\n' || c == 0x2029 || c == 0x2028 || c == 0x0003)
  1033.             continue;
  1034.         work[0] = c;
  1035.         for (j = 0; j < u_strlen(noBreak); j++) {
  1036.             work[1] = noBreak[j];
  1037.             for (k = 0; k < u_strlen(s); k++) {
  1038.                 work[2] = s[k];
  1039.                 
  1040.                 e = ubrk_open(UBRK_LINE, "en_US", work, u_strlen(work), &status);
  1041.                 if(U_FAILURE(status)){
  1042.                 log_err("FAIL: Error in opening the word break Iterator in testLineInvaiants:\n %s\n", myErrorName(status));
  1043.                 return;
  1044.                 }
  1045.                 for (l = ubrk_first(e); l != UBRK_DONE; l = ubrk_next(e))
  1046.                     if (l == 1 || l == 2) {
  1047.                         log_err("Got break between U+%s  and U+%s\n", austrdup(UCharToUCharArray(work[l - 1])),
  1048.                                                           austrdup(UCharToUCharArray(work[l])) );
  1049.                         
  1050.                         errorCount++;
  1051.                         if (errorCount >= 75)
  1052.                             return;
  1053.                     }
  1054.             }
  1055.         }
  1056.     }
  1057.     ubrk_close(e);
  1058.     /* it does break after hyphens (unless they're followed by a digit, a non-spacing mark,
  1059.        a currency symbol, a non-breaking space, or a line or paragraph separator) */
  1060.     u_strcpy(dashes, CharsToUCharArray("-\\u00ad\\u2010\\u2012\\u2013\\u2014"));
  1061.     for (i = 0; i < u_strlen(s); i++) {
  1062.         work[0] = s[i];
  1063.         for (j = 0; j < u_strlen(dashes); j++) {
  1064.             work[1] = dashes[j];
  1065.             for (k = 0; k < u_strlen(s); k++) {
  1066.                  c = s[k];
  1067.                 if (u_charType(c) == U_DECIMAL_DIGIT_NUMBER ||
  1068.                     u_charType(c) == U_OTHER_NUMBER ||
  1069.                     u_charType(c) == U_NON_SPACING_MARK ||
  1070.                     u_charType(c) == U_ENCLOSING_MARK ||
  1071.                     u_charType(c) == U_CURRENCY_SYMBOL ||
  1072.                     c == '\n' || c == '\r' || c == 0x2028 || c == 0x2029 ||
  1073.                     c == 0x0003 || c == 0x00a0 || c == 0x2007 || c == 0x2011 ||
  1074.                     c == 0xfeff)
  1075.                     continue;
  1076.                 work[2] = c;
  1077.                 e = ubrk_open(UBRK_LINE, "en_US", work, u_strlen(work), &status);
  1078.                 if(U_FAILURE(status)){
  1079.                 log_err("FAIL: Error in opening the word break Iterator in testLineInvaiants:\n %s \n", myErrorName(status));
  1080.                 return;
  1081.                 }
  1082.                 saw2 = FALSE;
  1083.                 for (l = ubrk_first(e); l != UBRK_DONE; l = ubrk_next(e))
  1084.                     if (l == 2)
  1085.                         saw2 = TRUE;
  1086.                 if (!saw2) {
  1087.                     log_err("Didn't get break between U+%s  and U+%s\n", austrdup(UCharToUCharArray(work[1])),
  1088.                         austrdup(UCharToUCharArray(work[2])) );
  1089.                     errorCount++;
  1090.                     if (errorCount >= 75)
  1091.                         return;
  1092.                 }
  1093.             }
  1094.         }
  1095.     }
  1096.    ubrk_close(e);
  1097.    free(s);
  1098. FreeTextBoundary();
  1099. }
  1100. /*---------------------------------------------
  1101.    CharacterBreak tests
  1102.   --------------------------------------------- */
  1103.  
  1104. void TestForwardCharacterSelection()
  1105. {
  1106.     UErrorCode status = U_ZERO_ERROR;
  1107.     UBreakIterator *e;
  1108.     addTestCharacterData();
  1109.     e = ubrk_open(UBRK_CHARACTER, "en_US", testCharacterText, u_strlen(testCharacterText), &status);
  1110.     if(U_FAILURE(status)){
  1111.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  1112.         return;
  1113.     }
  1114.     log_verbose("Testing forward character selection.....\n");
  1115.     doForwardSelectionTest(e, testCharacterText, characterSelectionData);
  1116.     ubrk_close(e);
  1117.     free(characterSelectionData);
  1118. }
  1119.  
  1120. void TestFirstCharacterSelection()
  1121. {
  1122.     UErrorCode status = U_ZERO_ERROR;
  1123.     UBreakIterator *e;
  1124.     addTestCharacterData();
  1125.     e = ubrk_open(UBRK_CHARACTER, "en_US", testCharacterText, u_strlen(testCharacterText), &status);
  1126.     if(U_FAILURE(status)){
  1127.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  1128.         return;
  1129.     }
  1130.     log_verbose("Testing first character selection.....\n");
  1131.     doFirstSelectionTest(e, testCharacterText, characterSelectionData);
  1132.     ubrk_close(e);
  1133.     free(characterSelectionData);
  1134. }
  1135.  
  1136. void TestLastCharacterSelection()
  1137. {
  1138.     UErrorCode status = U_ZERO_ERROR;
  1139.     UBreakIterator *e;
  1140.     addTestCharacterData();
  1141.     e = ubrk_open(UBRK_CHARACTER, "en_US", testCharacterText, u_strlen(testCharacterText), &status);
  1142.     if(U_FAILURE(status)){
  1143.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  1144.         return;
  1145.     }
  1146.     log_verbose("Testing last character selection.....\n");
  1147.     doLastSelectionTest(e, testCharacterText, characterSelectionData);
  1148.     ubrk_close(e);
  1149.     free(characterSelectionData);
  1150. }
  1151.  
  1152. void TestBackwardCharacterSelection()
  1153. {
  1154.     UErrorCode status = U_ZERO_ERROR;
  1155.     UBreakIterator *e;
  1156.     addTestCharacterData();
  1157.     e = ubrk_open(UBRK_CHARACTER, "en_US", testCharacterText, u_strlen(testCharacterText), &status);
  1158.     if(U_FAILURE(status)){
  1159.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  1160.         return;
  1161.     }
  1162.     log_verbose("Testing backward character selection.....\n");
  1163.     doBackwardSelectionTest(e, testCharacterText, characterSelectionData);
  1164.     ubrk_close(e);
  1165.     free(characterSelectionData);
  1166. }
  1167.  
  1168. void TestForwardCharacterIndexSelection()
  1169. {
  1170.     UErrorCode status = U_ZERO_ERROR;
  1171.     UBreakIterator *e;
  1172.     addTestCharacterData();
  1173.     e = ubrk_open(UBRK_CHARACTER, "en_US", testCharacterText, u_strlen(testCharacterText), &status);
  1174.     if(U_FAILURE(status)){
  1175.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  1176.         return;
  1177.     }
  1178.     log_verbose("Testing forward index character selection.....\n");
  1179.     doForwardIndexSelectionTest(e, testCharacterText, characterSelectionData);
  1180.     ubrk_close(e);
  1181.     free(characterSelectionData);
  1182. }
  1183.  
  1184. void TestBackwardCharacterIndexSelection()
  1185. {
  1186.     UErrorCode status = U_ZERO_ERROR;
  1187.     UBreakIterator *e;
  1188.     addTestCharacterData();
  1189.     e = ubrk_open(UBRK_CHARACTER, "en_US", testCharacterText, u_strlen(testCharacterText), &status);
  1190.     if(U_FAILURE(status)){
  1191.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  1192.         return;
  1193.     }
  1194.     log_verbose("Testing backward character index selection.....\n");
  1195.     doBackwardSelectionTest(e, testCharacterText, characterSelectionData);
  1196.     ubrk_close(e);
  1197.     free(characterSelectionData);
  1198. }
  1199.  
  1200. void TestCharacterInvariants()
  1201. {
  1202.    UChar *s;
  1203. AllocateTextBoundary();
  1204.    s=(UChar*)malloc(sizeof(UChar) * (u_strlen(cannedTestChars) + 15));
  1205.    u_strcpy(s, cannedTestChars);    
  1206.    u_strcat(s, CharsToUCharArray("\\u1100\\u1101\\u1102\\u1160\\u1161\\u1162\\u11a8\\u11a9\\u11aa"));
  1207.    log_verbose("Testing character break invariant.....\n");
  1208.    doBreakInvariantTest(UBRK_CHARACTER, s);
  1209.    u_strcpy(s, cannedTestChars);        
  1210.    u_strcat(s, CharsToUCharArray("\\u1100\\u1101\\u1102\\u1160\\u1161\\u1162\\u11a8\\u11a9\\u11aa"));
  1211.    log_verbose("Testing character other invariant.....\n");
  1212.    doOtherInvariantTest(UBRK_CHARACTER, s);
  1213.    free(s);
  1214. FreeTextBoundary();   
  1215. }
  1216. /*---------------------------------------------
  1217.    other tests
  1218.   --------------------------------------------- */
  1219.  
  1220.  
  1221. void TestPreceding()
  1222. {
  1223.     UTextOffset p1, p2, p3, p4, f, p;
  1224.     UBreakIterator *e;
  1225.     UChar words3[15];
  1226.     UErrorCode status = U_ZERO_ERROR;
  1227.     u_uastrcpy(words3, "aaa bbb ccc");
  1228.     log_verbose("Testting preceding...\n");
  1229.     e  = ubrk_open(UBRK_WORD, "en_US", words3, u_strlen(words3), &status);
  1230.     if(U_FAILURE(status)){
  1231.         log_err("FAIL: Error in ubrk_open() for word breakiterator: %s\n", myErrorName(status));
  1232.     }
  1233.     
  1234.     ubrk_first(e);
  1235.     p1 = ubrk_next(e);
  1236.     p2 = ubrk_next(e);
  1237.     p3 = ubrk_next(e);
  1238.     p4 = ubrk_next(e);
  1239.     f = ubrk_following(e, p2+1);
  1240.     p = ubrk_preceding(e, p2+1);
  1241.     
  1242.     if (f!=p3) log_err("Error in TestPreceding: %d!=%d\n", (int32_t)f, (int32_t)p3);
  1243.     if (p!=p2) log_err("Error in TestPreceding: %d!=%d\n", (int32_t)p, (int32_t)p2);
  1244.    
  1245.     ubrk_close(e);
  1246. }
  1247.  
  1248. /**
  1249.  * @bug 4068137
  1250.  */
  1251. void TestEndBehaviour()
  1252. {
  1253.     int32_t end, previous;
  1254.     UErrorCode status = U_ZERO_ERROR;
  1255.     UBreakIterator* wb;
  1256.     UChar testString[5];
  1257.     u_uastrcpy(testString, "boo");
  1258.     log_verbose("Testing end behaviour\n");
  1259.     wb = ubrk_open(UBRK_WORD, "en_US", testString, u_strlen(testString), &status);
  1260.     if(U_FAILURE(status)){
  1261.         log_err("FAIL: Error in opening the word break Iterator: %s\n", myErrorName(status));
  1262.         return;
  1263.     } 
  1264.     
  1265.    
  1266.     end=ubrk_last(wb);
  1267.     previous=ubrk_previous(wb);
  1268.     log_verbose("end= %d and previous=%d   %d\n", end, previous, ubrk_previous(wb));
  1269.     
  1270.     
  1271.     ubrk_close(wb);
  1272. }
  1273.  
  1274.  
  1275. /*---------------------------------------------
  1276.    Test implementation routines
  1277.   --------------------------------------------- */
  1278.  
  1279. void doForwardSelectionTest(UBreakIterator* iterator, UChar* testText, Vector* result)
  1280. {
  1281.     UChar *expectedResult, *selectionResult;
  1282.     int32_t lastOffset, offset;
  1283.     int32_t forwardSelectionCounter = 0;
  1284.     int32_t forwardSelectionOffset = 0;
  1285.     
  1286.     log_verbose("doForwardSelectionTest text of length: %d\n", u_strlen(testText));
  1287.  
  1288.        
  1289.     lastOffset = ubrk_first(iterator);
  1290.     offset       = ubrk_next(iterator);
  1291.     while(offset!=UBRK_DONE && forwardSelectionCounter < Count(result)) {
  1292.         
  1293.         if (offset != ubrk_current(iterator)){
  1294.             log_err("current() failed: it returned %d and offset was %d\n", ubrk_current(iterator), offset);
  1295.         }
  1296.     expectedResult =elementAt(result, forwardSelectionCounter);
  1297.     forwardSelectionOffset += u_strlen(expectedResult);
  1298.         
  1299.         selectionResult=extractBetween(lastOffset, offset, testText);
  1300.         if (offset != forwardSelectionOffset) {
  1301.             log_err("\n*** Selection #%d\n expected : %s - length %d\n\rselected : %s - length %d\n", 
  1302.                 forwardSelectionCounter, austrdup(expectedResult), u_strlen(expectedResult), 
  1303.                                          austrdup(selectionResult), u_strlen(selectionResult) );
  1304.         }
  1305.         log_verbose("#%d [\"%d\",\"%d\"] : %s\n", forwardSelectionCounter, lastOffset, offset, 
  1306.                                                             austrdup(selectionResult));
  1307.  
  1308.         forwardSelectionCounter++;
  1309.         lastOffset = offset;
  1310.         offset = ubrk_next(iterator);
  1311.     }
  1312.     if (forwardSelectionCounter < Count(result) - 1){
  1313.         log_err("\n*** Selection #%d not found at offset %d !!!\n", forwardSelectionCounter, offset);
  1314.     }
  1315.     else if (forwardSelectionCounter >= Count(result) && offset != UBRK_DONE){
  1316.         log_err("\n*** Selection #%d should not exist at offset %d !!!\n", forwardSelectionCounter, offset);
  1317.     }
  1318. }
  1319. void doBackwardSelectionTest(UBreakIterator* iterator, UChar* testText, Vector* result)
  1320. {
  1321.     UChar* expectedResult;
  1322.     UChar* selectionResult;
  1323.     int32_t backwardSelectionCounter, neededOffset, lastOffset, offset;
  1324.     backwardSelectionCounter = (Count(result) - 1);
  1325.     neededOffset = u_strlen(testText);
  1326.     lastOffset = ubrk_last(iterator);
  1327.     offset = ubrk_previous(iterator);
  1328.     
  1329.     log_verbose("doBackwardSelectionTest text of length: %d\n", u_strlen(testText));
  1330.     while(offset != UBRK_DONE)
  1331.     {
  1332.         expectedResult = elementAt(result, backwardSelectionCounter);
  1333.         neededOffset -= u_strlen(expectedResult);
  1334.         selectionResult=extractBetween(offset, lastOffset, testText);
  1335.         if(offset != neededOffset) {
  1336.             log_err("\n*** Selection #%d\nExpected : %d > %s < \n\rSelected : %d > %s < \n", 
  1337.                 backwardSelectionCounter, neededOffset, austrdup(expectedResult), 
  1338.                                             offset, austrdup(selectionResult) );
  1339.         }
  1340.  
  1341.         log_verbose("#%d : %s\n", backwardSelectionCounter, selectionResult);
  1342.         backwardSelectionCounter--;
  1343.         lastOffset = offset;
  1344.         offset = ubrk_previous(iterator);
  1345.     }
  1346.     if (backwardSelectionCounter >= 0 && offset != UBRK_DONE){
  1347.         log_err("*** Selection #%d not found!!!\n", backwardSelectionCounter);
  1348.     }
  1349. }
  1350.  
  1351. void doFirstSelectionTest(UBreakIterator* iterator, UChar* testText, Vector* result)
  1352. {
  1353.     int32_t selectionStart, selectionEnd;
  1354.     UChar* expectedFirstSelection;
  1355.     UChar* tempFirst;
  1356.     bool_t success = TRUE;
  1357.     
  1358.     log_verbose("doFirstSelectionTest.......\n"); 
  1359.     
  1360.     selectionStart = ubrk_first(iterator);
  1361.     selectionEnd   = ubrk_next(iterator);
  1362.     if(selectionEnd != UBRK_DONE) {
  1363.         
  1364.         tempFirst=extractBetween(selectionStart, selectionEnd, testText);
  1365.         expectedFirstSelection = elementAt(result,0);
  1366.  
  1367.         if(u_strcmp(tempFirst,expectedFirstSelection)!=0) {
  1368.             log_err("\n### Error in doFirstSelectionTest. First selection not equal to what expected\n");
  1369.             log_err("Expected: %s - length %d\n\rSelected: %s - length %d\n", 
  1370.                 austrdup(expectedFirstSelection), u_strlen(expectedFirstSelection),
  1371.                 austrdup(tempFirst), u_strlen(tempFirst));
  1372.             success = FALSE;
  1373.         }
  1374.     }
  1375.     else if (selectionStart != 0 || u_strlen(testText)!= 0) {
  1376.         log_err("\n### Error in doFirstSelectionTest. Could not get first selection.\n\r start= %d end= %d\n",
  1377.                                             selectionStart, selectionEnd);
  1378.         success = FALSE;
  1379.     }
  1380.  
  1381.     if(success) {
  1382.         log_verbose("doFirstSelectionTest\n\nExpexcted first selection: %s\nCalculated first selection: %s is correct\n",
  1383.             austrdup(expectedFirstSelection), austrdup(tempFirst) );
  1384.         
  1385.     }
  1386. }
  1387.  
  1388. void doLastSelectionTest(UBreakIterator* iterator, UChar* testText, Vector* result)
  1389. {
  1390.     int32_t selectionEnd, selectionStart;
  1391.     UChar *expectedLastSelection;
  1392.     UChar *tempLast;
  1393.     bool_t success = TRUE;
  1394.   
  1395.     log_verbose("doLastSelectionTest.......\n"); 
  1396.  
  1397.     selectionEnd = ubrk_last(iterator);
  1398.     selectionStart = ubrk_previous(iterator);
  1399.  
  1400.     
  1401.     if(selectionStart != UBRK_DONE) {
  1402.         tempLast=extractBetween(selectionStart, selectionEnd, testText);
  1403.         expectedLastSelection = elementAt(result,Count(result)-1);
  1404.         if(u_strcmp(tempLast,expectedLastSelection)!=0) {
  1405.             log_err("\n\n### Error in doLastSelectionTest. Last selection not equal to what expected.\n");
  1406.             log_err("Expected: %s - length %d\n\r Selected: %s - length %d\n", 
  1407.                     austrdup(expectedLastSelection), u_strlen(expectedLastSelection), 
  1408.                     austrdup(tempLast), u_strlen(tempLast) );
  1409.             success = FALSE;
  1410.               
  1411.         }
  1412.     }
  1413.     else if (selectionEnd != 0 || u_strlen(testText)!= 0) {
  1414.         log_err("\n### Error in doLastSelectionTest. Could not get last selection. [%d,%d]\n", selectionStart, 
  1415.                                                                     selectionEnd);
  1416.         success = FALSE;
  1417.     }
  1418.     if(success) {
  1419.         log_verbose("doLastSelectionTest\n\nExpected Last selection: %s \n", austrdup(expectedLastSelection));
  1420.         log_verbose("Calculated last Selection: %s is correct\n",  austrdup(tempLast) );
  1421.     }
  1422.     
  1423. }
  1424.  
  1425. /**
  1426.  * @bug 4052418 4068139
  1427.  */
  1428. void doForwardIndexSelectionTest(UBreakIterator* iterator, UChar* testText, Vector* result)
  1429. {
  1430.     int32_t arrayCount, textLength;
  1431.     int32_t selBegin, selEnd, current, entry, pos;
  1432.     UTextOffset offset;
  1433.     
  1434.     log_verbose("doForwardIndexSelectionTest text of length: %d\n", u_strlen(testText));
  1435.     arrayCount = Count(result);
  1436.     textLength = u_strlen(testText);
  1437.    
  1438.     for(offset = 0; offset < textLength; offset++) {
  1439.         selBegin = ubrk_preceding(iterator, offset);
  1440.         selEnd = ubrk_following(iterator, offset);
  1441.         
  1442.         entry = 0;
  1443.         pos = 0;
  1444.         if (selBegin != UBRK_DONE) {
  1445.             while (pos < selBegin && entry < arrayCount) {
  1446.                 pos += u_strlen(elementAt(result, entry));
  1447.                 ++entry;
  1448.             }
  1449.             if (pos != selBegin) {
  1450.                 log_err("With offset = %d, got back spurious %d from preceding\n", offset, selBegin);
  1451.                 continue;
  1452.             }
  1453.             else {
  1454.                 pos += u_strlen(elementAt(result, entry));
  1455.                 ++entry;
  1456.             }
  1457.         }
  1458.         current=ubrk_current(iterator);
  1459.         if(pos==current){
  1460.              if (pos != selEnd) {
  1461.             log_err("With offset = %d, got back erroneous %d from follwoing\n", offset, selEnd);
  1462.             continue;
  1463.             }
  1464.         }
  1465.     }
  1466. }
  1467.  
  1468. /**
  1469.  * @bug 4052418 4068139
  1470.  */
  1471. void doBackwardIndexSelectionTest(UBreakIterator* iterator, UChar* testText, Vector* result)
  1472. {
  1473.     int32_t arrayCount, textLength;
  1474.     int32_t selBegin, selEnd, current, entry, pos;
  1475.     UTextOffset offset;
  1476.     
  1477.     log_verbose("doBackwardIndexSelectionTest text of length: %d\n", u_strlen(testText));
  1478.     arrayCount = Count(result);
  1479.     textLength = u_strlen(testText);
  1480.  
  1481.     for(offset = textLength-1; offset >= 0; offset--) {
  1482.          selBegin = ubrk_preceding(iterator, offset);
  1483.          selEnd = ubrk_following(iterator, offset);
  1484.         
  1485.         entry = 0;
  1486.         pos = 0;
  1487.         if (selBegin != UBRK_DONE) {
  1488.             while (pos < selBegin && entry < arrayCount) {
  1489.                pos += u_strlen(elementAt(result, entry));
  1490.                 ++entry;
  1491.             }
  1492.             if (pos != selBegin) {
  1493.                 log_err("With offset = %d, got back spurious %d from preceding\n", offset, selBegin);
  1494.                 continue;
  1495.             }
  1496.             else {
  1497.                 pos += u_strlen(elementAt(result, entry));
  1498.                 ++entry;
  1499.             }
  1500.         }
  1501.         current=ubrk_current(iterator);
  1502.         if(pos==current){
  1503.             if (pos != selEnd) {
  1504.                 log_err("With offset = %d, got back erroneous %d from following\n", offset, selEnd);
  1505.                 continue;
  1506.             }
  1507.         }
  1508.     }
  1509. }
  1510.  
  1511.  
  1512.  
  1513. void doBreakInvariantTest(UBreakIteratorType type, UChar* testChars)
  1514. {
  1515.     int l,k;
  1516.     UBreakIterator *tb;
  1517.     UTextOffset i, j;
  1518.     UErrorCode status = U_ZERO_ERROR;
  1519.     UChar work[3]; 
  1520.     UChar breaks[10];
  1521.     UChar c;
  1522.     bool_t seen2;
  1523.     int errorCount = 0;
  1524.     status=U_ZERO_ERROR;
  1525.    
  1526.     u_uastrcpy(work, "aaa");
  1527.     
  1528.     log_verbose("doBreakInvariantTest text of length: %d\n", u_strlen(testChars));
  1529.     /* a break should always occur after CR (unless followed by LF), LF, PS, and LS */
  1530.       
  1531.     u_strcpy(breaks, CharsToUCharArray("\r\n\\u2029\\u2028"));
  1532.     
  1533.  
  1534.     for (i = 0; i < u_strlen(breaks); i++) {
  1535.         work[1] = breaks[i];
  1536.         for (j = 0; j < u_strlen(testChars); j++) {
  1537.             work[0] = testChars[j];
  1538.             for (k = 0; k < u_strlen(testChars); k++) {
  1539.                 c = testChars[k];
  1540.  
  1541.                 /* if a cr is followed by lf, ps, ls or etx, don't do the check (that's
  1542.                    not supposed to work) */
  1543.                 if (work[1] == '\r' && (c == '\n' || c == 0x2029
  1544.                         || c == 0x2028 || c == 0x0003))
  1545.                     continue;
  1546.  
  1547.                 work[2] = testChars[k];
  1548.                 tb=ubrk_open(type, "en_US", work, u_strlen(work), &status);
  1549.                 if(U_FAILURE(status)){
  1550.                     log_err("ERROR in opening the breakIterator in doVariant Function: %s\n", myErrorName(status));
  1551.                 }
  1552.                 seen2 = FALSE;
  1553.                 for (l = ubrk_first(tb); l != UBRK_DONE; l = ubrk_next(tb)) {
  1554.                     if (l == 2)
  1555.                         seen2 = TRUE;
  1556.                 }
  1557.                 if (!seen2) {
  1558.                     log_err("No break between U+%s and U+%s\n", austrdup(UCharToUCharArray(work[1])), 
  1559.                         austrdup(UCharToUCharArray(work[2])) );
  1560.                     errorCount++;
  1561.                     if (errorCount >= 75)
  1562.                         return;
  1563.                 }
  1564.             }
  1565.         }
  1566.     }
  1567.     ubrk_close(tb);
  1568. }
  1569.  
  1570. void doOtherInvariantTest(UBreakIteratorType type , UChar* testChars)
  1571. {
  1572.     int32_t k;
  1573.     UBreakIterator *tb;
  1574.     UTextOffset i, j;
  1575.     UErrorCode status = U_ZERO_ERROR;
  1576.     UChar work[5]; 
  1577.     UChar c;
  1578.     int32_t errorCount = 0;
  1579.     status=U_ZERO_ERROR;
  1580.    
  1581.     u_uastrcpy(work, "a\r\na");
  1582.     
  1583.     log_verbose("doOtherInvariantTest text of length: %d\n", u_strlen(testChars));
  1584.     
  1585.     /* a break should never occur between CR and LF */
  1586.     for (i = 0; i < u_strlen(testChars); i++) {
  1587.         work[0] = testChars[i];
  1588.         for (j = 0; j < u_strlen(testChars); j++) {
  1589.             work[3] = testChars[j];
  1590.             tb=ubrk_open(type, "en_US", work, u_strlen(work), &status);
  1591.                 if(U_FAILURE(status)){
  1592.                     log_err("ERROR in opening the breakIterator in doVariant Function: %s\n", myErrorName(status));
  1593.                     }
  1594.             for ( k = ubrk_first(tb); k != UBRK_DONE; k = ubrk_next(tb))
  1595.                 if (k == 2) {
  1596.                     log_err("Break between CR and LF in string U+%s, U+d U+a U+%s\n", 
  1597.                         austrdup(UCharToUCharArray(work[0])), austrdup(UCharToUCharArray(work[3])) );
  1598.                     errorCount++;
  1599.                     if (errorCount >= 75)
  1600.                         return;
  1601.                 }
  1602.         }
  1603.     }
  1604.     ubrk_close(tb);
  1605.     /* a break should never occur before a non-spacing mark, unless the preceding
  1606.        character is CR, LF, PS, or LS */
  1607.     u_uastrcpy(work,"aaaa");
  1608.     for (i = 0; i < u_strlen(testChars); i++) {
  1609.         c = testChars[i];
  1610.         if (c == '\n' || c == '\r' || c == 0x2029 || c == 0x2028 || c == 0x0003)
  1611.             continue;
  1612.         work[1] = c;
  1613.         for (j = 0; j < u_strlen(testChars); j++) {
  1614.             c = testChars[j];
  1615.             if ((u_charType(c) != U_NON_SPACING_MARK) && 
  1616.                 (u_charType(c) != U_ENCLOSING_MARK))
  1617.                 continue;
  1618.             work[2] = c;
  1619.             tb=ubrk_open(type, "en_US", work, u_strlen(work), &status);
  1620.                 if(U_FAILURE(status)){
  1621.                     log_err("ERROR in opening the breakIterator in doOtherVariant Function %s\n", myErrorName(status));
  1622.                     }
  1623.             for (k = ubrk_first(tb); k != UBRK_DONE; k = ubrk_next(tb))
  1624.                 if (k == 2) {
  1625.                     log_err("Break between U+%s and U+%s\n", austrdup(UCharToUCharArray(work[1])), 
  1626.                                             austrdup(UCharToUCharArray(work[2])) );
  1627.                     errorCount++;
  1628.                     if (errorCount >= 75)
  1629.                         return;
  1630.                 }
  1631.         }
  1632.     }
  1633. }
  1634.  
  1635. void sample(UBreakIterator* tb, UChar* text)
  1636. {
  1637.  
  1638.     int32_t start, end;
  1639.     UChar*   substring;
  1640.     log_verbose("-------------------------\n");
  1641.     log_verbose("%s  of length %d\n", austrdup(text), u_strlen(text));
  1642.     
  1643.     start = ubrk_first(tb);
  1644.     for (end = ubrk_next(tb); end != UBRK_DONE; end = ubrk_next(tb)) {
  1645.         substring=extractBetween(start, end, text);
  1646.         log_err("[%d,%d] \"%s\" \n", start, end, austrdup(substring) );
  1647.         start = end;
  1648.     }
  1649.     
  1650. }
  1651.  
  1652.  
  1653. void addBrkIterRegrTest(TestNode** root)
  1654. {
  1655.         
  1656.     addTest(root, &TestForwardWordSelection,        "tstxtbd/cregrtst/TestForwardWordSelection"    );
  1657.     addTest(root, &TestBackwardWordSelection,       "tstxtbd/cregrtst/TestBackwardWordSelection"   );
  1658.     addTest(root, &TestFirstWordSelection,            "tstxtbd/cregrtst/TestFirstWordSelection"    );
  1659.     addTest(root, &TestLastWordSelection,            "tstxtbd/cregrtst/TestLastWordSelection"    );
  1660.     addTest(root, &TestForwardWordIndexSelection,    "tstxtbd/cregrtst/TestForwardWordIndexSelection");
  1661.     addTest(root, &TestBackwardWordIndexSelection,    "tstxtbd/cregrtst/TestBackwardWordIndexSelection");
  1662.     addTest(root, &TestForwardSentenceSelection,    "tstxtbd/cregrtst/TestForwardSentenceSelection");
  1663.     addTest(root, &TestBackwardSentenceSelection,    "tstxtbd/cregrtst/TestBackwardSentenceSelection");
  1664.     addTest(root, &TestFirstSentenceSelection,        "tstxtbd/cregrtst/TestFirstSentenceSelection");
  1665.     addTest(root, &TestLastSentenceSelection,        "tstxtbd/cregrtst/TestLastSentenceSelection");
  1666.     addTest(root, &TestForwardSentenceIndexSelection,  "tstxtbd/cregrtst/TestForwardSentenceIndexSelection");
  1667.     addTest(root, &TestBackwardSentenceIndexSelection, "tstxtbd/cregrtst/TestBackwardSentenceIndexSelection");
  1668.  
  1669.     addTest(root, &TestForwardLineSelection,        "tstxtbd/cregrtst/TestForwardLineSelection");
  1670.     addTest(root, &TestBackwardLineSelection,        "tstxtbd/cregrtst/TestBackwardLineSelection");
  1671.     addTest(root, &TestFirstLineSelection,            "tstxtbd/cregrtst/TestFirstLineSelection");
  1672.     addTest(root, &TestLastLineSelection,            "tstxtbd/cregrtst/TestLastLineSelection");
  1673.     addTest(root, &TestForwardLineIndexSelection,    "tstxtbd/cregrtst/TestForwardLineIndexSelection");
  1674.     addTest(root, &TestBackwardLineIndexSelection,  "tstxtbd/cregrtst/TestBackwardLineIndexSelection");
  1675.  
  1676.     addTest(root, &TestForwardCharacterSelection,    "tstxtbd/cregrtst/TestForwardCharacterSelection");
  1677.     addTest(root, &TestBackwardCharacterSelection,  "tstxtbd/cregrtst/TestBackwardCharacterSelection");
  1678.     addTest(root, &TestFirstCharacterSelection,        "tstxtbd/cregrtst/TestFirstCharacterSelection");
  1679.     addTest(root, &TestLastCharacterSelection,        "tstxtbd/cregrtst/TestLastCharacterSelection");
  1680.     addTest(root, &TestForwardCharacterIndexSelection,  "tstxtbd/cregrtst/TestForwardCharacterIndexSelection");
  1681.     addTest(root, &TestBackwardCharacterIndexSelection, "tstxtbd/cregrtst/TestBackwardCharacterIndexSelection");
  1682.  
  1683.     addTest(root, &TestPreceding,    "tstxtbd/cregrtst/TestPreceding");
  1684.     addTest(root, &TestEndBehaviour, "tstxtbd/cregrtst/TestEndBehaviour");
  1685.  
  1686.     addTest(root, &TestWordInvariants,      "tstxtbd/cregrtst/TestWordInvariants");
  1687.     addTest(root, &TestSentenceInvariants,  "tstxtbd/cregrtst/TestSentenceInvariants");
  1688.     addTest(root, &TestCharacterInvariants, "tstxtbd/cregrtst/TestCharacterInvariants");
  1689.     addTest(root, &TestLineInvariants,      "tstxtbd/cregrtst/TestLineInvariants");
  1690.  
  1691.    
  1692. }
  1693.