xref: /trunk/test/testuno/source/api/i18n/XBreakIteratorTest.java (revision ffd38472365e95f6a578737bc9a5eb0fac624a86)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package api.i18n;
25 
26 import java.io.ByteArrayOutputStream;
27 import java.io.File;
28 import java.io.FileInputStream;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.Vector;
32 
33 import com.sun.star.beans.PropertyState;
34 import com.sun.star.beans.PropertyValue;
35 import com.sun.star.i18n.Boundary;
36 import com.sun.star.i18n.LineBreakHyphenationOptions;
37 import com.sun.star.i18n.LineBreakResults;
38 import com.sun.star.i18n.LineBreakUserOptions;
39 import com.sun.star.i18n.ScriptType;
40 import com.sun.star.i18n.WordType;
41 import com.sun.star.i18n.XBreakIterator;
42 import com.sun.star.lang.Locale;
43 import com.sun.star.lang.XComponent;
44 import com.sun.star.text.XTextDocument;
45 import com.sun.star.text.XTextRange;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XComponentContext;
48 import org.junit.After;
49 import org.junit.AfterClass;
50 import org.junit.Before;
51 import org.junit.BeforeClass;
52 import org.junit.Assert;
53 import org.junit.Test;
54 import org.openoffice.test.common.Testspace;
55 import org.openoffice.test.uno.UnoApp;
56 
57 /**
58 * Testing <code>com.sun.star.i18n.XBreakIterator</code>
59 * interface methods :
60 * <ul>
61 *  <li><code> nextCharacters()</code></li>
62 *  <li><code> previousCharacters()</code></li>
63 *  <li><code> nextWord()</code></li>
64 *  <li><code> previousWord()</code></li>
65 *  <li><code> getWordBoundary()</code></li>
66 *  <li><code> getWordType()</code></li>
67 *  <li><code> isBeginWord()</code></li>
68 *  <li><code> isEndWord()</code></li>
69 *  <li><code> beginOfSentence()</code></li>
70 *  <li><code> endOfSentence()</code></li>
71 *  <li><code> getLineBreak()</code></li>
72 *  <li><code> beginOfScript()</code></li>
73 *  <li><code> endOfScript()</code></li>
74 *  <li><code> nextScript()</code></li>
75 *  <li><code> previousScript()</code></li>
76 *  <li><code> getScriptType()</code></li>
77 *  <li><code> beginOfCharBlock()</code></li>
78 *  <li><code> endOfCharBlock()</code></li>
79 *  <li><code> nextCharBlock()</code></li>
80 *  <li><code> previousCharBlock()</code></li>
81 * </ul> <p>
82 * This test needs the following object relations :
83 * <ul>
84 *  <li> <code>'Locale'</code>
85 *   (of type <code>com.sun.star.lang.Locale</code>):
86 *   this locale is used as locale argument for tested methods.
87 *  </li>
88 *  <li> <code>'UnicodeString'</code>
89 *   (of type <code>String</code>): Unicode string which is passed
90 *   to methods except 'CharacterBlock' methods.
91 *  </li>
92 * <ul> <p>
93 * @see com.sun.star.i18n.XBreakIterator
94 */
95 public class XBreakIteratorTest {
96     private static final UnoApp app = new UnoApp();
97     private static final String iteratorPath = "api/i18n/Iterator.sxw";
98     private static String UnicodeString;
99 
100     private XComponentContext xContext = null;
101     public XBreakIterator oObj = null;
102 
103     Locale locale = null;
104 
105     short wordType = WordType.ANYWORD_IGNOREWHITESPACES;
106 
107     // setup and close connections
108     @BeforeClass
109     public static void setUpConnection() throws Exception
110     {
111         app.start();
112         UnicodeString = readFileContents(iteratorPath);
113     }
114 
115     @AfterClass
116     public static void tearDownConnection() throws InterruptedException, com.sun.star.uno.Exception
117     {
118         app.close();
119     }
120 
121     /**
122      * Retrieves object relations.
123      * @throws StatusException If one of relations not found.
124      */
125     @Before
126     public void before() throws Exception {
127         xContext = app.getComponentContext();
128         oObj = UnoRuntime.queryInterface(
129             XBreakIterator.class,
130             xContext.getServiceManager().createInstanceWithContext("com.sun.star.i18n.BreakIterator", xContext)
131         );
132 
133         locale = new Locale("en", "US", "");
134     }
135 
136     private static String readFileContents(String path) throws Exception {
137         String sample = Testspace.prepareData(path);
138         PropertyValue[] properties = new PropertyValue[1];
139         properties[0] = new PropertyValue("Hidden", -1, true, PropertyState.DIRECT_VALUE);
140         XComponent docComponent = app.loadDocument(sample, properties);
141         XTextDocument textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, docComponent);
142         XTextRange xTextRange = (XTextRange)textDocument.getText();
143         return xTextRange.getString();
144     }
145 
146     /**
147      * Compares returned next character positions with expected values. <p>
148      *
149      * Has <b>OK</b> status if position after travel and traveled length
150      * has expected values.
151      */
152     @Test
153     public void _nextCharacters() {
154         short nCharacterIteratorMode =
155             com.sun.star.i18n.CharacterIteratorMode.SKIPCHARACTER;
156 
157         int strLength = UnicodeString.length();
158 
159         //Start from position : Travel ... chars :
160         // Actual position after : How many chars traveled
161         int[][] nextCharacters = {
162             { 1, 5000, strLength , strLength - 1 },
163             { 10, 6, 16, 6}};
164 
165         boolean bRes = true;
166 
167         for(int i = 0; i < nextCharacters.length; i++) {
168             int[] lDone = new int[1];
169             long lRes = oObj.nextCharacters(UnicodeString, nextCharacters[i][0],
170                 locale, nCharacterIteratorMode, nextCharacters[i][1], lDone);
171             System.out.println("Expected result is: lRes = " + nextCharacters[i][2] +
172                         "; lDone = " + nextCharacters[i][3] );
173             System.out.println("Actual result is: lRes = " + lRes +
174                         "; lDone = " + lDone[0] );
175 
176             bRes = bRes && lRes == nextCharacters[i][2];
177             bRes = bRes && lDone[0] == nextCharacters[i][3];
178         }
179 
180         Assert.assertTrue("nextCharacters()", bRes);
181     }
182 
183     /**
184      * Compares returned previous character positions with expected values. <p>
185      *
186      * Has <b>OK</b> status if position after travel and traveled length
187      * has expected values.
188      */
189     @Test
190     public void _previousCharacters() {
191         short nCharacterIteratorMode =
192             com.sun.star.i18n.CharacterIteratorMode.SKIPCHARACTER;
193 
194 
195         //Start from position : Travel ... chars : Actual position after :
196         //How many chars traveled
197         int[][] previousCharacters = {
198             {5, 5000, 0, 5},
199             {10, 6, 4, 6}};
200 
201         boolean bRes = true;
202         for(int i = 0; i < previousCharacters.length; i++) {
203             int[] lDone = new int[1];
204             int lRes = oObj.previousCharacters(UnicodeString,
205                 previousCharacters[i][0],
206                 locale, nCharacterIteratorMode,
207                 previousCharacters[i][1], lDone);
208             System.out.println("Expected result is: lRes = " + previousCharacters[i][2]
209                 + "; lDone = " + previousCharacters[i][3] );
210             System.out.println("Actual result is: lRes = " + lRes
211                 + "; lDone = " + lDone[0]);
212 
213             bRes = bRes && lRes == previousCharacters[i][2];
214             bRes = bRes && lDone[0] == previousCharacters[i][3];
215         }
216 
217         Assert.assertTrue("previousCharacters()", bRes);
218     }
219 
220     /**
221     * Saves bounds of all returned words for the future tests. <p>
222     * Has <b>OK</b> status.
223     */
224     @Test
225     public void _nextWord() {
226         ArrayList<Boundary> vBounds = nextWord();
227         Assert.assertTrue("nextWord()", vBounds != null && vBounds.size() > 0);
228     }
229 
230     private ArrayList<Boundary> nextWord() {
231         int i = 0;
232         ArrayList<Boundary> vBounds = new ArrayList<>();
233         while( i < UnicodeString.length() - 1 ) {
234             Boundary bounds = oObj.nextWord
235                 (UnicodeString, i, locale, wordType);
236             if (bounds.endPos - bounds.startPos > 3) {
237                 vBounds.add( bounds );
238                 System.out.println("Word " + vBounds.size() + "("
239                     + bounds.startPos + "," + bounds.endPos + "): '" +
240                     UnicodeString.substring(bounds.startPos,
241                                             bounds.endPos) + "'");
242             }
243             i = bounds.endPos - 1;
244         }
245         System.out.println("In text there are " + vBounds.size()
246             + " words, if count from left to right");
247         return vBounds;
248     }
249 
250     /**
251     * Compares number of word bounds with number of word bounds saved
252     * by the method _nextWord().<p>
253     * Has <b>OK</b> status if number of word bounds are equal.
254     */
255     @Test
256     public void _previousWord() {
257         ArrayList<Boundary> vBounds = nextWord();
258 
259         int i = UnicodeString.length() - 1;
260         ArrayList<Boundary> vPrevBounds = new ArrayList<>();
261         while( i > 0  ) {
262             Boundary bounds =
263                 oObj.previousWord(UnicodeString, i, locale, wordType);
264             if (bounds.endPos - bounds.startPos > 3) {
265                 vPrevBounds.add( bounds );
266                 System.out.println("Word " + vPrevBounds.size() + "("
267                     + bounds.startPos + "," + bounds.endPos + "): '"
268                     + UnicodeString.substring(bounds.startPos, bounds.endPos)
269                     + "'");
270             }
271             i = bounds.startPos;
272         }
273         System.out.println("In text there are " + vPrevBounds.size()
274             + " words, if count from right to left");
275         Assert.assertTrue("previousWord()", vPrevBounds.size() == vBounds.size() );
276     }
277 
278     /**
279      * For every word in array obtained by <code>nextWord</code> method test
280      * computes bounds of the word, passing its internal character position.<p>
281      *
282      * Has <b>OK</b> status if bounds calculated by <code>getWordBoundary()</code>
283      * method are the same as bounds obtained by <code>nextWord</code> method.
284      */
285     @Test
286     public void _getWordBoundary() {
287         ArrayList<Boundary> vBounds = nextWord();
288 
289         boolean bRes = true;
290 
291         for(int i = 0; i < vBounds.size(); i++) {
292             // calculate middle of the word
293             Boundary iBounds = (Boundary)vBounds.get(i);
294             int iPos = (iBounds.endPos - iBounds.startPos) / 2
295                         + iBounds.startPos;
296             Boundary bounds = oObj.getWordBoundary(UnicodeString, iPos,
297                 locale, wordType, true);
298             System.out.println("Expected result is: startPos = " + iBounds.startPos +
299                                  "; endPos = " + iBounds.endPos);
300             System.out.println("Actual result is: startPos = " + bounds.startPos
301                 + "; endPos = " + bounds.endPos + " Word is: '"
302                 + UnicodeString.substring(bounds.startPos, bounds.endPos) + "'");
303 
304             bRes = bRes && iBounds.startPos == bounds.startPos;
305             bRes = bRes && iBounds.endPos == bounds.endPos;
306         }
307 
308         Assert.assertTrue("getWordBoundary()", bRes);
309     }
310 
311     /**
312      * For every word in array obtained by <code>nextWord</code> method test
313      * get its type, passing its internal character position.<p>
314      *
315      * Has <b>OK</b> status if every word has type <code>WordType.ANY_WORD</code>
316      */
317     @Test
318     public void _getWordType() {
319         ArrayList<Boundary> vBounds = nextWord();
320 
321         boolean bRes = true;
322 
323         for(int i = 0; i < vBounds.size(); i++) {
324             // calculate middle of the word
325             Boundary iBounds = (Boundary)vBounds.get(i);
326             int iPos = (iBounds.endPos - iBounds.startPos) / 2
327                         + iBounds.startPos;
328 
329             short type = oObj.getWordType(UnicodeString, iPos, locale);
330 
331             bRes = bRes && type == WordType.ANY_WORD;
332         }
333 
334         Assert.assertTrue("getWordType()", bRes);
335     }
336 
337     /**
338      * For every word in array obtained by <code>nextWord</code> method test
339      * tries to determine if the character at a position starts a word.
340      * First word starting position is passed, then internal character
341      * position is passed. <p>
342      * Has <b>OK</b> status if in the first case <code>true</code>
343      * returned and in the second - <code>false</code> for every word.
344      */
345     @Test
346     public void _isBeginWord() {
347         ArrayList<Boundary> vBounds = nextWord();
348 
349         boolean bRes = true;
350 
351         for(int i = 0; i < vBounds.size(); i++) {
352             Boundary iBounds = (Boundary)vBounds.get(i);
353             boolean isBegin = oObj.isBeginWord(UnicodeString, iBounds.startPos,
354                                                locale, wordType);
355             bRes = bRes && isBegin;
356             boolean isNotBegin = !oObj.isBeginWord(UnicodeString,
357                     iBounds.startPos + 1, locale, wordType);
358             bRes = bRes && isNotBegin;
359 
360             System.out.println("At position + " + iBounds.startPos
361                 + " isBeginWord? " + isBegin);
362             System.out.println("At position + " + (iBounds.startPos + 1)
363                 + " isBeginWord? " + !isNotBegin);
364         }
365 
366         Assert.assertTrue("isBeginWord()", bRes);
367     }
368 
369     /**
370      * For every word in array obtained by <code>nextWord</code> method test
371      * tries to determine if the character at a position ends a word.
372      * First word ending position is passed, then internal character
373      * position is passed. <p>
374      *
375      * Has <b>OK</b> status if in the first case <code>true</code>
376      * returned and in the second - <code>false</code> for every word.
377      */
378     @Test
379     public void _isEndWord() {
380         ArrayList<Boundary> vBounds = nextWord();
381 
382         boolean bRes = true;
383 
384         for(int i = 0; i < vBounds.size(); i++) {
385             Boundary iBounds = (Boundary)vBounds.get(i);
386             boolean isEnd = oObj.isEndWord(UnicodeString, iBounds.endPos,
387                 locale, wordType);
388             bRes = bRes && isEnd;
389             boolean isNotEnd = !oObj.isEndWord(UnicodeString,
390                 iBounds.endPos - 1, locale, wordType);
391             bRes = bRes && isNotEnd;
392 
393             System.out.println("At position + " + iBounds.endPos
394                 + " isEndWord? " + isEnd);
395             System.out.println("At position + " + (iBounds.endPos - 1)
396                 + " isEndWord? " + !isNotEnd);
397         }
398 
399         Assert.assertTrue("isEndWord()", bRes);
400     }
401 
402     Vector vSentenceStart = new Vector();
403     /**
404      * Tries to find all sentences starting positions passing every character
405      * as position parameter and stores them. Then tries to pass invalid
406      * position parameters.
407      *
408      * Has <b>OK</b> status if -1 is returned for wrong position arguments.
409      */
410     @Test
411     public void _beginOfSentence() {
412         int iPos = 0;
413         while( iPos < UnicodeString.length() ) {
414             Integer start = new Integer( oObj.beginOfSentence(UnicodeString,
415                 iPos, locale) );
416             if (start.intValue() >= 0 && !vSentenceStart.contains(start) ) {
417                 vSentenceStart.add( start );
418                 System.out.println("Sentence " + vSentenceStart.size()
419                     + " : start from position " + start);
420             }
421             iPos++;
422         }
423 
424         //test for invalid nStartPosition
425         boolean bRes = oObj.beginOfSentence(UnicodeString, -10, locale) == -1;
426         bRes &= oObj.beginOfSentence(UnicodeString,
427             UnicodeString.length() + 1, locale) == -1;
428 
429         if (!bRes) {
430             System.out.println("When invalid position, returned value isn't equal to -1");
431         }
432 
433         Assert.assertTrue("beginOfSentence()", bRes);
434     }
435 
436     /**
437      * For every sentence starting position found in
438      * <code>beginOfSentence()</code> test tries to compute end
439      * position of a sentence and checks that the end position is
440      * greater than starting.
441      * Then wrong position arguments are passed.
442      *
443      * Has <b>OK</b> status if the end position of every sentence
444      * greater than starting and -1 returned for invalid arguments.
445      */
446     @Test
447     public void _endOfSentence() {
448         boolean bRes = true;
449         for(int i = 0; i < vSentenceStart.size(); i++) {
450             int start = ((Integer)vSentenceStart.get(i)).intValue();
451             int end = oObj.endOfSentence(UnicodeString, start, locale);
452             bRes &= end > start;
453             System.out.println("Sentence " + i + " range is [" + start + ", "
454                 + end + "]");
455         }
456 
457         //test for invalid nStartPosition
458         boolean bInvRes = oObj.endOfSentence(UnicodeString, -10, locale) == -1;
459         bInvRes &= oObj.endOfSentence(UnicodeString,
460             UnicodeString.length() + 1, locale) == -1;
461 
462         if (!bInvRes) {
463             System.out.println("When invalid position, returned value isn't equal to -1");
464         }
465 
466         Assert.assertTrue("endOfSentence()", bRes && bInvRes);
467     }
468 
469     /**
470     * Tries to break a string in position other than 0 iterating characters
471     * from the string beginning (Hyphenation is not used for a while). <p>
472     *
473     * Has <b>OK</b> status if non-zero break position was found and it is
474     * less or equal than position we trying to break.
475     */
476     @Test
477     public void _getLineBreak() {
478         boolean bRes = true;
479         LineBreakResults lineBreakResults;
480         LineBreakHyphenationOptions lineBreakHyphenationOptions =
481             new LineBreakHyphenationOptions();
482         LineBreakUserOptions lineBreakUserOptions = new LineBreakUserOptions();
483 
484         lineBreakUserOptions.applyForbiddenRules = false;
485         lineBreakUserOptions.allowHyphenateEnglish = false;
486 
487         int breakPos = 0;
488         int pos = 0;
489 
490         while(breakPos == 0 && pos < UnicodeString.length() ) {
491             lineBreakResults = oObj.getLineBreak(UnicodeString, pos,
492                 locale, 0, lineBreakHyphenationOptions, lineBreakUserOptions);
493             breakPos = lineBreakResults.breakIndex;
494             pos++;
495         }
496 
497         // finally the position of break must be found in the middle and
498         // it must be before the break position specified
499         bRes = breakPos <= pos && breakPos > 0;
500 
501         if (!bRes) {
502             System.out.println("The last position was: " + pos
503                 + ", and the break position was: " + breakPos);
504         }
505 
506         Assert.assertTrue("getLineBreak()", bRes);
507     }
508 
509     // Asian type script
510     private static String katakana = new String(new char[] {0x30A1, 0x30A2}) ;
511     // Weak type script
512     private static String arrows = new String(new char[] {0x2190, 0x2191}) ;
513     // Complex type script
514     private static String arabic = new String(new char[] {0x0641, 0x0642}) ;
515 
516     /**
517     * Tries to find the beginning of the nearest script specified
518     * relatively to position passed. <p>
519     * Has <b>OK</b> status if the starting position of script is returned.
520     */
521     @Test
522     public void _beginOfScript() {
523         String multiScript = "ab" + katakana  ;
524 
525         int pos = oObj.beginOfScript(multiScript, 3, ScriptType.ASIAN) ;
526 
527         System.out.println("Position = " + pos) ;
528 
529         Assert.assertTrue("beginOfScript()", pos == 2) ;
530     }
531 
532     /**
533     * Tries to find the end of the nearest script specified
534     * relatively to position passed. <p>
535     * Has <b>OK</b> status if the end position of script is returned.
536     */
537     @Test
538     public void _endOfScript() {
539         String multiScript = "ab" + katakana + "cd" ;
540 
541         int pos = oObj.endOfScript(multiScript, 2, ScriptType.ASIAN) ;
542 
543         System.out.println("Position = " + pos) ;
544 
545         Assert.assertTrue("endOfScript()", pos == 4) ;
546     }
547 
548     /**
549     * Tries to find the next script starting position specified
550     * relatively to position passed. <p>
551     * Has <b>OK</b> status if the appropriate position is returned.
552     */
553     @Test
554     public void _nextScript() {
555         String multiScript = "ab" + katakana + "cd"  ;
556 
557         int pos = oObj.nextScript(multiScript, 0, ScriptType.LATIN) ;
558 
559         System.out.println("Position = " + pos) ;
560 
561         Assert.assertTrue("nextScript()", pos == 4) ;
562     }
563 
564     /**
565     * Tries to find the previous script starting position specified
566     * relatively to position passed. <p>
567     * Has <b>OK</b> status if the appropriate position is returned.
568     */
569     @Test
570     public void _previousScript() {
571         String multiScript = "ab" + katakana + "cd"  ;
572 
573         int pos = oObj.previousScript(multiScript, 5, ScriptType.ASIAN) ;
574 
575         System.out.println("Position = " + pos) ;
576 
577         Assert.assertTrue("previousScript()", pos == 2) ;
578     }
579 
580     /**
581     * Tries to determine script type (of all four types). <p>
582     * Has <b>OK</b> status if <code>LATIN</code> type returned
583     * for ASCII character, <code>ASIAN</code> for Katakana Unicode
584     * codepoints, <code>COMPLEX</code> for Arabic Unicode
585     * codepoints and <code>WEAK</code> for codepoints from Arrows
586     * Unicode block.
587     */
588     @Test
589     public void _getScriptType() {
590         boolean res = true ;
591 
592         res &= oObj.getScriptType("abcd", 0) == ScriptType.LATIN ;
593         res &= oObj.getScriptType(katakana, 0) == ScriptType.ASIAN;
594         res &= oObj.getScriptType(arabic, 0) == ScriptType.COMPLEX ;
595         res &= oObj.getScriptType(arrows, 0) == ScriptType.WEAK ;
596 
597         Assert.assertTrue("getScriptType()", res) ;
598     }
599 
600     protected short getCharBlockType(int pos) {
601         short i = 1;
602         short cType = 0;
603         while (i < 31) {
604             if (oObj.beginOfCharBlock(UnicodeString, pos, locale, i) != -1) {
605                 cType = i;
606                 i = 100;
607             }
608             i++;
609         }
610 
611         return cType;
612     }
613 
614     Vector vCharBlockBounds = new Vector();
615     Vector vCharBlockTypes = new Vector();
616 
617     /**
618      * Creates array of all char blocks with their boundaries and
619      * types using <code>beginOfCharBlock()</code> and
620      * <code>endOfCharBlock()</code> methods. <p>
621      *
622      * Has <b>OK</b> status if the end of each boundary is the same
623      * as start of the next one and if the start of the first block
624      * has position 0 and the end of the last block is at the end
625      * of the whole string.
626      */
627     @Test
628     public void _beginOfCharBlock() {
629         Assert.assertTrue("beginOfCharBlock()", beginOfCharBlock());
630     }
631 
632     private boolean beginOfCharBlock() {
633         boolean bCharBlockRes = true;
634         int iPos = 0;
635 
636         while( iPos < UnicodeString.length() && iPos > -1) {
637             short charType = getCharBlockType(iPos);
638             int startPos = oObj.beginOfCharBlock(UnicodeString, iPos,
639                 locale, charType);
640             int endPos = oObj.endOfCharBlock(UnicodeString, iPos,
641                 locale, charType);
642             iPos = endPos;
643             vCharBlockBounds.add(new Boundary(startPos, endPos));
644             System.out.println("" + vCharBlockBounds.size() + "). Bounds: ["
645                 + startPos + "," + endPos + "]; Type = " + charType);
646             vCharBlockTypes.add(new Short(charType));
647         }
648 
649         for(int i = 0; i < vCharBlockBounds.size() - 1; i++) {
650             int endPos = ((Boundary)vCharBlockBounds.get(i)).endPos;
651             int startPos = ((Boundary)vCharBlockBounds.get(i + 1)).startPos;
652             bCharBlockRes &= endPos == startPos;
653         }
654 
655         System.out.println("Testing for no intersections : " + bCharBlockRes);
656         int startPos = ((Boundary)vCharBlockBounds.get(0)).startPos;
657         bCharBlockRes &= startPos == 0;
658         int endPos = ((Boundary)vCharBlockBounds.get
659             (vCharBlockBounds.size() - 1)).endPos;
660         bCharBlockRes &= endPos == UnicodeString.length();
661         System.out.println("Regions should starts with 0 and ends with "
662             + UnicodeString.length());
663 
664         return bCharBlockRes;
665     }
666 
667     /**
668      * Testing of this method is performed in <code>beginOfCharBlock()</code>
669      * method test. <p>
670      *
671      * Has the status same as <code>beginOfCharBlock()</code> method status.
672      */
673     public void _endOfCharBlock() {
674         Assert.assertTrue("endOfCharBlock()", beginOfCharBlock());
675     }
676 
677     /**
678      * For every character block obtained in <code>beginOfCharBlock()</code>
679      * method test (except the first) tries to find its starting position
680      * by mean of <code>nextCharBlock()</code> method passing as position
681      * argument the position before the start of a block. <p>
682      *
683      * Has <b>OK</b> status if the start of every block was found and it's
684      * equal to this block boundary start.
685      */
686     public void _nextCharBlock() {
687         beginOfCharBlock();
688 
689         boolean bRes = true;
690         for(int i = 0; i < vCharBlockBounds.size(); i++) {
691             Boundary bounds = (Boundary)vCharBlockBounds.get(i);
692             Short type = (Short)vCharBlockTypes.get(i);
693             if (bounds.startPos - 1 < 0) continue;
694             int iPos = oObj.nextCharBlock(UnicodeString, bounds.startPos - 1,
695                 locale, type.shortValue());
696             if (iPos != bounds.startPos) {
697                 bRes = false;
698                 System.out.println("nextCharBlock(UnicodeString, "
699                     + (bounds.startPos - 1) + ", locale, " + type
700                     + ") should return " + bounds.startPos);
701                 System.out.println("... and actual value is " + iPos);
702             }
703         }
704 
705         Assert.assertTrue("nextCharBlock()", bRes);
706     }
707 
708     /**
709      * For every character block obtained in <code>beginOfCharBlock()</code>
710      * method test (except the first) tries to find its starting position
711      * by mean of <code>previousCharBlock()</code> method passing as position
712      * argument the position after the end of a block. <p>
713      *
714      * Has <b>OK</b> status if the start of every block was found and it's
715      * equal to this block boundary start.
716      */
717     public void _previousCharBlock() {
718         beginOfCharBlock();
719 
720         boolean bRes = true;
721         for(int i = 0; i < vCharBlockBounds.size(); i++) {
722             Boundary bounds = (Boundary)vCharBlockBounds.get(i);
723             Short type = (Short)vCharBlockTypes.get(i);
724             int iPos = oObj.previousCharBlock(UnicodeString,
725                 bounds.endPos + 1, locale, type.shortValue());
726             if (iPos != bounds.startPos) {
727                 bRes = false;
728                 System.out.println("previousCharBlock(UnicodeString, "
729                     + (bounds.endPos + 1) + ", locale, " + type
730                     + ") should return " + bounds.startPos);
731                 System.out.println("... and actual value is " + iPos);
732             }
733         }
734 
735         Assert.assertTrue("previousCharBlock()", bRes);
736     }
737 
738 }
739