• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*************************************************************************
4  * Copyright (c) 1999-2016, International Business Machines
5  * Corporation and others. All Rights Reserved.
6  *************************************************************************
7  *   Date        Name        Description
8  *   12/15/99    Madhu        Creation.
9  *   01/12/2000  Madhu        Updated for changed API and added new tests
10  ************************************************************************/
11 
12 
13 #ifndef RBBITEST_H
14 #define RBBITEST_H
15 
16 #include "unicode/utypes.h"
17 
18 #if !UCONFIG_NO_BREAK_ITERATION
19 
20 #include "intltest.h"
21 #include "unicode/brkiter.h"
22 #include "unicode/rbbi.h"
23 
24 class  Enumeration;
25 class  BITestData;
26 struct TestParams;
27 class  RBBIMonkeyKind;
28 
29 U_NAMESPACE_BEGIN
30 class  UVector32;
31 U_NAMESPACE_END
32 
33 /**
34  * Test the RuleBasedBreakIterator class giving different rules
35  */
36 class RBBITest: public IntlTest {
37 public:
38 
39     RBBITest();
40     virtual ~RBBITest();
41 
42     void runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL );
43 
44     /**
45      * Tests rule status return values
46      **/
47     void TestStatusReturn();
48 
49     void TestEmptyString();
50     void TestGetAvailableLocales();
51     void TestGetDisplayName();
52     void TestEndBehaviour();
53     void TestBug4153072();
54     void TestJapaneseLineBreak();
55     void TestThaiLineBreak();
56     void TestMixedThaiLineBreak();
57     void TestMaiyamok();
58     void TestMonkey();
59 
60     void TestExtended();
61     UChar *ReadAndConvertFile(const char *fileName, int &ulen, const char *encoding, UErrorCode &status);
62     void executeTest(TestParams *, UErrorCode &status);
63 
64     void TestWordBreaks();
65     void TestWordBoundary();
66     void TestLineBreaks();
67     void TestSentBreaks();
68     void TestBug3818();
69     void TestJapaneseWordBreak();
70     void TestTrieDict();
71     void TestUnicodeFiles();
72     void TestBug5775();
73     void TestTailoredBreaks();
74     void TestDictRules();
75     void TestBug5532();
76     void TestBug9983();
77     void TestBug7547();
78     void TestBug12797();
79     void TestBug12918();
80 
81     void TestDebug();
82     void TestProperties();
83 
84 /***********************/
85 private:
86     /**
87      * internal methods to prepare test data
88      **/
89 
90     /**
91      * Perform tests of BreakIterator forward and backward functionality
92      * on different kinds of iterators (word, sentence, line and character).
93      * It tests the methods first(), next(), current(), preceding(), following()
94      * previous() and isBoundary().
95      * It makes use of internal functions to achieve this.
96      **/
97     void generalIteratorTest(RuleBasedBreakIterator& bi, BITestData  &td);
98     /**
99      * Internal method to perform iteration and test the first() and next() functions
100      **/
101     void testFirstAndNext(RuleBasedBreakIterator& bi, BITestData &td);
102     /**
103      * Internal method to perform iteration and test the last() and previous() functions
104      **/
105     void testLastAndPrevious(RuleBasedBreakIterator& bi, BITestData &td);
106     /**
107      * Internal method to perform iteration and test the following() function
108      **/
109     void testFollowing(RuleBasedBreakIterator& bi, BITestData &td);
110     /**
111      * Internal method to perform iteration and test the preceding() function
112      **/
113     void testPreceding(RuleBasedBreakIterator& bi, BITestData &td);
114     /**
115      * Internal method to perform iteration and test the isBoundary() function
116      **/
117     void testIsBoundary(RuleBasedBreakIterator& bi, BITestData &td);
118     /**
119      * Internal method to perform tests of BreakIterator multiple selection functionality
120      * on different kinds of iterators (word, sentence, line and character)
121      **/
122     void doMultipleSelectionTest(RuleBasedBreakIterator& iterator, BITestData &td);
123 
124     void RunMonkey(BreakIterator *bi, RBBIMonkeyKind &mk, const char *name, uint32_t  seed,
125         int32_t loopCount, UBool useUText);
126 
127     // Run one of the Unicode Consortium boundary test data files.
128     void runUnicodeTestData(const char *fileName, RuleBasedBreakIterator *bi);
129 
130     // Run a single test case from one of the Unicode Consortium test files.
131     void checkUnicodeTestCase(const char *testFileName, int lineNumber,
132                          const UnicodeString &testString,
133                          UVector32 *breakPositions,
134                          RuleBasedBreakIterator *bi);
135 
136     // Run the actual tests for TestTailoredBreaks()
137     void TBTest(BreakIterator* brkitr, int type, const char *locale, const char* escapedText,
138                 const int32_t *expectOffsets, int32_t expectOffsetsCount);
139 
140     /** Filter for test cases from the Unicode test data files.
141      *  Some need to be skipped because ICU is unable to fully implement the
142      *  Unicode boundary specifications.
143      *  @param testCase the test data string.
144      *  @param fileName the Unicode test data file name.
145      *  @return FALSE if the test case should be run, TRUE if it should be skipped.
146      */
147     UBool testCaseIsKnownIssue(const UnicodeString &testCase, const char *fileName);
148 
149     // Test parameters, from the test framework and test invocation.
150     const char* fTestParams;
151 };
152 
153 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
154 
155 #endif
156