Imported Upstream version 58.1
[platform/upstream/icu.git] / source / test / intltest / rbbitst.h
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
80     void TestDebug();
81     void TestProperties();
82
83 /***********************/
84 private:
85     /**
86      * internal methods to prepare test data
87      **/
88
89     /**
90      * Perform tests of BreakIterator forward and backward functionality
91      * on different kinds of iterators (word, sentence, line and character).
92      * It tests the methods first(), next(), current(), preceding(), following()
93      * previous() and isBoundary().
94      * It makes use of internal functions to achieve this.
95      **/
96     void generalIteratorTest(RuleBasedBreakIterator& bi, BITestData  &td);
97     /**
98      * Internal method to perform iteration and test the first() and next() functions
99      **/
100     void testFirstAndNext(RuleBasedBreakIterator& bi, BITestData &td);
101     /**
102      * Internal method to perform iteration and test the last() and previous() functions
103      **/
104     void testLastAndPrevious(RuleBasedBreakIterator& bi, BITestData &td);
105     /**
106      * Internal method to perform iteration and test the following() function
107      **/
108     void testFollowing(RuleBasedBreakIterator& bi, BITestData &td);
109     /**
110      * Internal method to perform iteration and test the preceding() function
111      **/
112     void testPreceding(RuleBasedBreakIterator& bi, BITestData &td);
113     /**
114      * Internal method to perform iteration and test the isBoundary() function
115      **/
116     void testIsBoundary(RuleBasedBreakIterator& bi, BITestData &td);
117     /**
118      * Internal method to perform tests of BreakIterator multiple selection functionality
119      * on different kinds of iterators (word, sentence, line and character)
120      **/
121     void doMultipleSelectionTest(RuleBasedBreakIterator& iterator, BITestData &td);
122
123     void RunMonkey(BreakIterator *bi, RBBIMonkeyKind &mk, const char *name, uint32_t  seed,
124         int32_t loopCount, UBool useUText);
125
126     // Run one of the Unicode Consortium boundary test data files.
127     void runUnicodeTestData(const char *fileName, RuleBasedBreakIterator *bi);
128
129     // Run a single test case from one of the Unicode Consortium test files.
130     void checkUnicodeTestCase(const char *testFileName, int lineNumber,
131                          const UnicodeString &testString,
132                          UVector32 *breakPositions,
133                          RuleBasedBreakIterator *bi);
134
135     // Run the actual tests for TestTailoredBreaks()
136     void TBTest(BreakIterator* brkitr, int type, const char *locale, const char* escapedText,
137                 const int32_t *expectOffsets, int32_t expectOffsetsCount);
138
139     /** Filter for test cases from the Unicode test data files.
140      *  Some need to be skipped because ICU is unable to fully implement the
141      *  Unicode boundary specifications.
142      *  @param testCase the test data string.
143      *  @param fileName the Unicode test data file name.
144      *  @return FALSE if the test case should be run, TRUE if it should be skipped.
145      */
146     UBool testCaseIsKnownIssue(const UnicodeString &testCase, const char *fileName);
147
148     // Test parameters, from the test framework and test invocation.
149     const char* fTestParams;
150 };
151
152 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
153
154 #endif