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