]>
Commit | Line | Data |
---|---|---|
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 "intltest.h" | |
23 | #include "cmemory.h" | |
24 | ||
25 | class UnicodeSetWithStrings; | |
26 | ||
27 | /** | |
28 | * UnicodeSet test | |
29 | */ | |
30 | class UnicodeSetTest: public IntlTest { | |
31 | public: | |
32 | UnicodeSetTest(); | |
33 | ~UnicodeSetTest(); | |
34 | ||
35 | private: | |
36 | void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par=NULL); | |
37 | ||
38 | void Testj2268(); | |
39 | ||
40 | /** | |
41 | * Test that toPattern() round trips with syntax characters and | |
42 | * whitespace. | |
43 | */ | |
44 | void TestToPattern(); | |
45 | ||
46 | void TestPatterns(void); | |
47 | void TestCategories(void); | |
48 | void TestAddRemove(void); | |
49 | void TestCloneEqualHash(void); | |
50 | ||
51 | /** | |
52 | * Make sure minimal representation is maintained. | |
53 | */ | |
54 | void TestMinimalRep(void); | |
55 | ||
56 | void TestAPI(void); | |
57 | ||
58 | void TestIteration(void); | |
59 | ||
60 | void TestStrings(void); | |
61 | ||
62 | void TestScriptSet(void); | |
63 | ||
64 | /** | |
65 | * Test the [:Latin:] syntax. | |
66 | */ | |
67 | void TestPropertySet(void); | |
68 | ||
69 | void TestClone(void); | |
70 | ||
71 | void TestIndexOf(void); | |
72 | ||
73 | void TestExhaustive(void); | |
74 | ||
75 | void TestCloseOver(void); | |
76 | ||
77 | void TestEscapePattern(void); | |
78 | ||
79 | void TestInvalidCodePoint(void); | |
80 | ||
81 | void TestSymbolTable(void); | |
82 | ||
83 | void TestSurrogate(); | |
84 | ||
85 | void TestPosixClasses(); | |
86 | ||
87 | void TestFreezable(); | |
88 | ||
89 | void TestSpan(); | |
90 | ||
91 | void TestStringSpan(); | |
92 | ||
93 | void TestUCAUnsafeBackwards(); | |
94 | ||
95 | private: | |
96 | ||
97 | UBool toPatternAux(UChar32 start, UChar32 end); | |
98 | ||
99 | UBool checkPat(const UnicodeString& source, | |
100 | const UnicodeSet& testSet); | |
101 | ||
102 | UBool checkPat(const UnicodeString& source, const UnicodeSet& testSet, const UnicodeString& pat); | |
103 | ||
104 | void _testComplement(int32_t a, UnicodeSet&, UnicodeSet&); | |
105 | ||
106 | void _testAdd(int32_t a, int32_t b, UnicodeSet&, UnicodeSet&, UnicodeSet&); | |
107 | ||
108 | void _testRetain(int32_t a, int32_t b, UnicodeSet&, UnicodeSet&, UnicodeSet&); | |
109 | ||
110 | void _testRemove(int32_t a, int32_t b, UnicodeSet&, UnicodeSet&, UnicodeSet&); | |
111 | ||
112 | void _testXor(int32_t a, int32_t b, UnicodeSet&, UnicodeSet&, UnicodeSet&); | |
113 | ||
114 | /** | |
115 | * Check that ranges are monotonically increasing and non- | |
116 | * overlapping. | |
117 | */ | |
118 | void checkCanonicalRep(const UnicodeSet& set, const UnicodeString& msg); | |
119 | ||
120 | /** | |
121 | * Convert a bitmask to a UnicodeSet. | |
122 | */ | |
123 | static UnicodeSet& bitsToSet(int32_t a, UnicodeSet&); | |
124 | ||
125 | /** | |
126 | * Convert a UnicodeSet to a bitmask. Only the characters | |
127 | * U+0000 to U+0020 are represented in the bitmask. | |
128 | */ | |
129 | static int32_t setToBits(const UnicodeSet& x); | |
130 | ||
131 | /** | |
132 | * Return the representation of an inversion list based UnicodeSet | |
133 | * as a pairs list. Ranges are listed in ascending Unicode order. | |
134 | * For example, the set [a-zA-M3] is represented as "33AMaz". | |
135 | */ | |
136 | static UnicodeString getPairs(const UnicodeSet& set); | |
137 | ||
138 | /** | |
139 | * Basic consistency check for a few items. | |
140 | * That the iterator works, and that we can create a pattern and | |
141 | * get the same thing back | |
142 | */ | |
143 | void checkRoundTrip(const UnicodeSet& s); | |
144 | ||
145 | void checkSerializeRoundTrip(const UnicodeSet& s, UErrorCode &ec); | |
146 | ||
147 | void copyWithIterator(UnicodeSet& t, const UnicodeSet& s, UBool withRange); | |
148 | ||
149 | UBool checkEqual(const UnicodeSet& s, const UnicodeSet& t, const char* message); | |
150 | ||
151 | void expectContainment(const UnicodeString& pat, | |
152 | const UnicodeString& charsIn, | |
153 | const UnicodeString& charsOut); | |
154 | void expectContainment(const UnicodeSet& set, | |
155 | const UnicodeString& charsIn, | |
156 | const UnicodeString& charsOut); | |
157 | void expectContainment(const UnicodeSet& set, | |
158 | const UnicodeString& setName, | |
159 | const UnicodeString& charsIn, | |
160 | const UnicodeString& charsOut); | |
161 | void expectPattern(UnicodeSet& set, | |
162 | const UnicodeString& pattern, | |
163 | const UnicodeString& expectedPairs); | |
164 | void expectPairs(const UnicodeSet& set, | |
165 | const UnicodeString& expectedPairs); | |
166 | void expectToPattern(const UnicodeSet& set, | |
167 | const UnicodeString& expPat, | |
168 | const char** expStrings); | |
169 | void expectRange(const UnicodeString& label, | |
170 | const UnicodeSet& set, | |
171 | UChar32 start, UChar32 end); | |
172 | void doAssert(UBool, const char*); | |
173 | ||
174 | void testSpan(const UnicodeSetWithStrings *sets[4], const void *s, int32_t length, UBool isUTF16, | |
175 | uint32_t whichSpans, | |
176 | int32_t expectLimits[], int32_t &expectCount, | |
177 | const char *testName, int32_t index); | |
178 | void testSpan(const UnicodeSetWithStrings *sets[4], const void *s, int32_t length, UBool isUTF16, | |
179 | uint32_t whichSpans, | |
180 | const char *testName, int32_t index); | |
181 | void testSpanBothUTFs(const UnicodeSetWithStrings *sets[4], | |
182 | const UChar *s16, int32_t length16, | |
183 | uint32_t whichSpans, | |
184 | const char *testName, int32_t index); | |
185 | void testSpanContents(const UnicodeSetWithStrings *sets[4], uint32_t whichSpans, const char *testName); | |
186 | void testSpanUTF16String(const UnicodeSetWithStrings *sets[4], uint32_t whichSpans, const char *testName); | |
187 | void testSpanUTF8String(const UnicodeSetWithStrings *sets[4], uint32_t whichSpans, const char *testName); | |
188 | ||
189 | UConverter *openUTF8Converter(); | |
190 | ||
191 | UConverter *utf8Cnv; | |
192 | ||
193 | MaybeStackArray<uint16_t, 16> serializeBuffer; | |
194 | ||
195 | public: | |
196 | static UnicodeString escape(const UnicodeString& s); | |
197 | }; | |
198 | ||
199 | #endif |