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