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