• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 
4 /********************************************************************
5  * COPYRIGHT:
6  * Copyright (c) 1997-2015, International Business Machines Corporation and
7  * others. All Rights Reserved.
8  ********************************************************************
9 **********************************************************************
10 *   Date        Name        Description
11 *   10/20/99    alan        Creation.
12 *   03/22/2000  Madhu       Added additional tests
13 **********************************************************************
14 */
15 
16 #ifndef _TESTUNISET
17 #define _TESTUNISET
18 
19 #include "unicode/unistr.h"
20 #include "unicode/uniset.h"
21 #include "unicode/ucnv_err.h"
22 #include "unicode/usetiter.h"
23 #include "intltest.h"
24 #include "cmemory.h"
25 
26 class UnicodeSetWithStrings;
27 
28 /**
29  * UnicodeSet test
30  */
31 class UnicodeSetTest: public IntlTest {
32 public:
33     UnicodeSetTest();
34     ~UnicodeSetTest();
35 
36 private:
37     void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par=NULL) override;
38 
39     void Testj2268();
40 
41     /**
42      * Test that toPattern() round trips with syntax characters and
43      * whitespace.
44      */
45     void TestToPattern();
46 
47     void TestPatterns(void);
48     void TestCategories(void);
49     void TestAddRemove(void);
50     void TestCloneEqualHash(void);
51 
52     /**
53      * Make sure minimal representation is maintained.
54      */
55     void TestMinimalRep(void);
56 
57     void TestAPI(void);
58 
59     void TestIteration(void);
60 
61     void TestStrings(void);
62 
63     void TestScriptSet(void);
64 
65     /**
66      * Test the [:Latin:] syntax.
67      */
68     void TestPropertySet(void);
69 
70     void TestClone(void);
71 
72     void TestIndexOf(void);
73 
74     void TestExhaustive(void);
75 
76     void TestCloseOver(void);
77 
78     void TestEscapePattern(void);
79 
80     void TestInvalidCodePoint(void);
81 
82     void TestSymbolTable(void);
83 
84     void TestSurrogate();
85 
86     void TestPosixClasses();
87 
88     void TestFreezable();
89 
90     void TestSpan();
91 
92     void TestStringSpan();
93 
94     void TestPatternWithSurrogates();
95     void TestIntOverflow();
96     void TestUnusedCcc();
97     void TestDeepPattern();
98     void TestEmptyString();
99 
100     void assertNext(UnicodeSetIterator &iter, const UnicodeString &expected);
101     void TestSkipToStrings();
102     void TestPatternCodePointComplement();
103 
104 private:
105 
106     UBool toPatternAux(UChar32 start, UChar32 end);
107 
108     UBool checkPat(const UnicodeString& source,
109                    const UnicodeSet& testSet);
110 
111     UBool checkPat(const UnicodeString& source, const UnicodeSet& testSet, const UnicodeString& pat);
112 
113     void _testComplement(int32_t a, UnicodeSet&, UnicodeSet&);
114 
115     void _testAdd(int32_t a, int32_t b, UnicodeSet&, UnicodeSet&, UnicodeSet&);
116 
117     void _testRetain(int32_t a, int32_t b, UnicodeSet&, UnicodeSet&, UnicodeSet&);
118 
119     void _testRemove(int32_t a, int32_t b, UnicodeSet&, UnicodeSet&, UnicodeSet&);
120 
121     void _testXor(int32_t a, int32_t b, UnicodeSet&, UnicodeSet&, UnicodeSet&);
122 
123     /**
124      * Check that ranges are monotonically increasing and non-
125      * overlapping.
126      */
127     void checkCanonicalRep(const UnicodeSet& set, const UnicodeString& msg);
128 
129     /**
130      * Convert a bitmask to a UnicodeSet.
131      */
132     static UnicodeSet& bitsToSet(int32_t a, UnicodeSet&);
133 
134     /**
135      * Convert a UnicodeSet to a bitmask.  Only the characters
136      * U+0000 to U+0020 are represented in the bitmask.
137      */
138     static int32_t setToBits(const UnicodeSet& x);
139 
140     /**
141      * Return the representation of an inversion list based UnicodeSet
142      * as a pairs list.  Ranges are listed in ascending Unicode order.
143      * For example, the set [a-zA-M3] is represented as "33AMaz".
144      */
145     static UnicodeString getPairs(const UnicodeSet& set);
146 
147     /**
148      * Basic consistency check for a few items.
149      * That the iterator works, and that we can create a pattern and
150      * get the same thing back
151      */
152     void checkRoundTrip(const UnicodeSet& s);
153 
154     void checkSerializeRoundTrip(const UnicodeSet& s, UErrorCode &ec);
155 
156     void copyWithIterator(UnicodeSet& t, const UnicodeSet& s, UBool withRange);
157 
158     UBool checkEqual(const UnicodeSet& s, const UnicodeSet& t, const char* message);
159 
160     void expectContainment(const UnicodeString& pat,
161                            const UnicodeString& charsIn,
162                            const UnicodeString& charsOut);
163     void expectContainment(const UnicodeSet& set,
164                            const UnicodeString& charsIn,
165                            const UnicodeString& charsOut);
166     void expectContainment(const UnicodeSet& set,
167                            const UnicodeString& setName,
168                            const UnicodeString& charsIn,
169                            const UnicodeString& charsOut);
170     void expectPattern(UnicodeSet& set,
171                        const UnicodeString& pattern,
172                        const UnicodeString& expectedPairs);
173     void expectPairs(const UnicodeSet& set,
174                      const UnicodeString& expectedPairs);
175     void expectToPattern(const UnicodeSet& set,
176                          const UnicodeString& expPat,
177                          const char** expStrings);
178     void expectRange(const UnicodeString& label,
179                      const UnicodeSet& set,
180                      UChar32 start, UChar32 end);
181     void doAssert(UBool, const char*);
182 
183     void testSpan(const UnicodeSetWithStrings *sets[4], const void *s, int32_t length, UBool isUTF16,
184                   uint32_t whichSpans,
185                   int32_t expectLimits[], int32_t &expectCount,
186                   const char *testName, int32_t index);
187     void testSpan(const UnicodeSetWithStrings *sets[4], const void *s, int32_t length, UBool isUTF16,
188                   uint32_t whichSpans,
189                   const char *testName, int32_t index);
190     void testSpanBothUTFs(const UnicodeSetWithStrings *sets[4],
191                           const UChar *s16, int32_t length16,
192                           uint32_t whichSpans,
193                           const char *testName, int32_t index);
194     void testSpanContents(const UnicodeSetWithStrings *sets[4], uint32_t whichSpans, const char *testName);
195     void testSpanUTF16String(const UnicodeSetWithStrings *sets[4], uint32_t whichSpans, const char *testName);
196     void testSpanUTF8String(const UnicodeSetWithStrings *sets[4], uint32_t whichSpans, const char *testName);
197 
198     UConverter *openUTF8Converter();
199 
200     UConverter *utf8Cnv;
201 
202     MaybeStackArray<uint16_t, 16> serializeBuffer;
203 
204 public:
205     static UnicodeString escape(const UnicodeString& s);
206 };
207 
208 #endif
209