1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 * Copyright (c) 2002-2016, International Business Machines
6 * Corporation and others.  All Rights Reserved.
7 **********************************************************************
8 */
9 
10 #include <stdbool.h>
11 #include <stdlib.h>
12 #include <string.h>
13 
14 #include "unicode/uset.h"
15 #include "unicode/ustring.h"
16 #include "cintltst.h"
17 #include "cmemory.h"
18 
19 #define TEST(x) addTest(root, &x, "uset/" # x)
20 
21 static void TestAPI(void);
22 static void Testj2269(void);
23 static void TestSerialized(void);
24 static void TestNonInvariantPattern(void);
25 static void TestBadPattern(void);
26 static void TestFreezable(void);
27 static void TestSpan(void);
28 
29 void addUSetTest(TestNode** root);
30 
31 static void expect(const USet* set,
32                    const char* inList,
33                    const char* outList,
34                    UErrorCode* ec);
35 static void expectContainment(const USet* set,
36                               const char* list,
37                               UBool isIn);
38 static char oneUCharToChar(UChar32 c);
39 static void expectItems(const USet* set,
40                         const char* items);
41 
42 void
addUSetTest(TestNode ** root)43 addUSetTest(TestNode** root) {
44     TEST(TestAPI);
45     TEST(Testj2269);
46     TEST(TestSerialized);
47     TEST(TestNonInvariantPattern);
48     TEST(TestBadPattern);
49     TEST(TestFreezable);
50     TEST(TestSpan);
51 }
52 
53 /*------------------------------------------------------------------
54  * Tests
55  *------------------------------------------------------------------*/
56 
Testj2269()57 static void Testj2269() {
58   UErrorCode status = U_ZERO_ERROR;
59   UChar a[4] = { 0x61, 0x62, 0x63, 0 };
60   USet *s = uset_open(1, 0);
61   uset_addString(s, a, 3);
62   a[0] = 0x63; a[1] = 0x63;
63   expect(s, "{abc}", "{ccc}", &status);
64   uset_close(s);
65 }
66 
67 static const UChar PAT[] = {91,97,45,99,123,97,98,125,93,0}; /* "[a-c{ab}]" */
68 static const int32_t PAT_LEN = UPRV_LENGTHOF(PAT) - 1;
69 
70 static const UChar PAT_lb[] = {0x6C, 0x62, 0}; /* "lb" */
71 static const int32_t PAT_lb_LEN = UPRV_LENGTHOF(PAT_lb) - 1;
72 
73 static const UChar VAL_SP[] = {0x53, 0x50, 0}; /* "SP" */
74 static const int32_t VAL_SP_LEN = UPRV_LENGTHOF(VAL_SP) - 1;
75 
76 static const UChar STR_bc[] = {98,99,0}; /* "bc" */
77 static const int32_t STR_bc_LEN = UPRV_LENGTHOF(STR_bc) - 1;
78 
79 static const UChar STR_ab[] = {97,98,0}; /* "ab" */
80 static const int32_t STR_ab_LEN = UPRV_LENGTHOF(STR_ab) - 1;
81 
82 /**
83  * Basic API test for uset.x
84  */
TestAPI()85 static void TestAPI() {
86     USet* set;
87     USet* set2;
88     UErrorCode ec;
89 
90     /* [] */
91     set = uset_openEmpty();
92     expect(set, "", "abc{ab}", NULL);
93     uset_close(set);
94 
95     set = uset_open(1, 0);
96     expect(set, "", "abc{ab}", NULL);
97     uset_close(set);
98 
99     set = uset_open(1, 1);
100     uset_clear(set);
101     expect(set, "", "abc{ab}", NULL);
102     uset_close(set);
103 
104     /* [ABC] */
105     set = uset_open(0x0041, 0x0043);
106     expect(set, "ABC", "DEF{ab}", NULL);
107     if(uset_hasStrings(set)) {
108         log_err("uset_hasStrings([ABC]) = true");
109     }
110     uset_close(set);
111 
112     /* [a-c{ab}] */
113     ec = U_ZERO_ERROR;
114     set = uset_openPattern(PAT, PAT_LEN, &ec);
115     if(U_FAILURE(ec)) {
116         log_err("uset_openPattern([a-c{ab}]) failed - %s\n", u_errorName(ec));
117         return;
118     }
119     if(!uset_resemblesPattern(PAT, PAT_LEN, 0)) {
120         log_err("uset_resemblesPattern of PAT failed\n");
121     }
122     if(!uset_hasStrings(set)) {
123         log_err("uset_hasStrings([a-c{ab}]) = false");
124     }
125     expect(set, "abc{ab}", "def{bc}", &ec);
126 
127     /* [a-d{ab}] */
128     uset_add(set, 0x64);
129     expect(set, "abcd{ab}", "ef{bc}", NULL);
130 
131     /* [acd{ab}{bc}] */
132     uset_remove(set, 0x62);
133     uset_addString(set, STR_bc, STR_bc_LEN);
134     expect(set, "acd{ab}{bc}", "bef{cd}", NULL);
135 
136     /* [acd{bc}] */
137     uset_removeString(set, STR_ab, STR_ab_LEN);
138     expect(set, "acd{bc}", "bfg{ab}", NULL);
139 
140     /* [[^acd]{bc}] */
141     uset_complement(set);
142     expect(set, "bef{bc}", "acd{ac}", NULL);
143 
144     /* [a-e{bc}] */
145     uset_complement(set);
146     uset_addRange(set, 0x0062, 0x0065);
147     expect(set, "abcde{bc}", "fg{ab}", NULL);
148 
149     /* [de{bc}] */
150     uset_removeRange(set, 0x0050, 0x0063);
151     expect(set, "de{bc}", "bcfg{ab}", NULL);
152 
153     /* [g-l] */
154     uset_set(set, 0x0067, 0x006C);
155     expect(set, "ghijkl", "de{bc}", NULL);
156 
157     if (uset_indexOf(set, 0x0067) != 0) {
158         log_err("uset_indexOf failed finding correct index of 'g'\n");
159     }
160 
161     if (uset_charAt(set, 0) != 0x0067) {
162         log_err("uset_charAt failed finding correct char 'g' at index 0\n");
163     }
164 
165     /* How to test this one...? */
166     uset_compact(set);
167 
168     /* [g-i] */
169     uset_retain(set, 0x0067, 0x0069);
170     expect(set, "ghi", "dejkl{bc}", NULL);
171 
172     /* UCHAR_ASCII_HEX_DIGIT */
173     uset_applyIntPropertyValue(set, UCHAR_ASCII_HEX_DIGIT, 1, &ec);
174     if(U_FAILURE(ec)) {
175         log_err("uset_applyIntPropertyValue([UCHAR_ASCII_HEX_DIGIT]) failed - %s\n", u_errorName(ec));
176         return;
177     }
178     expect(set, "0123456789ABCDEFabcdef", "GHIjkl{bc}", NULL);
179     if (uset_size(set) != 22 || uset_getRangeCount(set) != 3 || uset_getItemCount(set) != 3) {
180         log_err("line %d: uset_size()/uset_getRangeCount()/uset_getItemCount() wrong", __LINE__);
181     }
182 
183     /* [ab] */
184     uset_clear(set);
185     uset_addAllCodePoints(set, STR_ab, STR_ab_LEN);
186     expect(set, "ab", "def{ab}", NULL);
187     if (uset_containsAllCodePoints(set, STR_bc, STR_bc_LEN)){
188         log_err("set should not contain all characters of \"bc\" \n");
189     }
190 
191     /* [] */
192     set2 = uset_open(1, 1);
193     uset_clear(set2);
194 
195     /* space */
196     uset_applyPropertyAlias(set2, PAT_lb, PAT_lb_LEN, VAL_SP, VAL_SP_LEN, &ec);
197     expect(set2, " ", "abcdefghi{bc}", NULL);
198 
199     /* [a-c] */
200     uset_set(set2, 0x0061, 0x0063);
201     /* [g-i] */
202     uset_set(set, 0x0067, 0x0069);
203 
204     /* [a-c g-i] */
205     if (uset_containsSome(set, set2)) {
206         log_err("set should not contain some of set2 yet\n");
207     }
208     uset_complementAll(set, set2);
209     if (!uset_containsSome(set, set2)) {
210         log_err("set should contain some of set2\n");
211     }
212     expect(set, "abcghi", "def{bc}", NULL);
213 
214     /* [g-i] */
215     uset_removeAll(set, set2);
216     expect(set, "ghi", "abcdef{bc}", NULL);
217 
218     /* [a-c g-i] */
219     uset_addAll(set2, set);
220     expect(set2, "abcghi", "def{bc}", NULL);
221 
222     /* [g-i] */
223     uset_retainAll(set2, set);
224     expect(set2, "ghi", "abcdef{bc}", NULL);
225 
226     // ICU 69 added some missing functions for parity with C++ and Java.
227     uset_applyPattern(set, u"[abcdef{ch}{sch}]", -1, 0, &ec);
228     if(U_FAILURE(ec)) {
229         log_err("uset_openPattern([abcdef{ch}{sch}]) failed - %s\n", u_errorName(ec));
230         return;
231     }
232     expect(set, "abcdef{ch}{sch}", "", NULL);
233 
234     uset_removeAllCodePoints(set, u"ce", 2);
235     expect(set, "abdf{ch}{sch}", "ce", NULL);
236 
237     uset_complementRange(set, u'b', u'f');
238     expect(set, "ace{ch}{sch}", "bdf", NULL);
239 
240     uset_complementString(set, u"ch", -1);
241     expect(set, "ace{sch}", "bdf{ch}", NULL);
242 
243     uset_complementString(set, u"xy", -1);
244     expect(set, "ace{sch}{xy}", "bdf{ch}", NULL);
245 
246     uset_complementAllCodePoints(set, u"abef", 4);
247     expect(set, "bcf{sch}{xy}", "ade{ch}", NULL);
248 
249     uset_retainAllCodePoints(set, u"abef", -1);
250     expect(set, "bf", "acde{ch}{sch}{xy}", NULL);
251 
252     uset_applyPattern(set, u"[abcdef{ch}{sch}]", -1, 0, &ec);
253     if(U_FAILURE(ec)) {
254         log_err("uset_openPattern([abcdef{ch}{sch}]) failed - %s\n", u_errorName(ec));
255         return;
256     }
257     expect(set, "abcdef{ch}{sch}", "", NULL);
258     if (uset_size(set) != 8 || uset_getRangeCount(set) != 1 || uset_getItemCount(set) != 3) {
259         log_err("line %d: uset_size()/uset_getRangeCount()/uset_getItemCount() wrong", __LINE__);
260     }
261 
262     uset_retainString(set, u"sch", 3);
263     expect(set, "{sch}", "abcdef{ch}", NULL);
264 
265     uset_retainString(set, u"ch", 3);
266     expect(set, "", "abcdef{ch}{sch}", NULL);
267 
268     uset_close(set);
269     uset_close(set2);
270 }
271 
272 /*------------------------------------------------------------------
273  * Support
274  *------------------------------------------------------------------*/
275 
276 /**
277  * Verifies that the given set contains the characters and strings in
278  * inList, and does not contain those in outList.  Also verifies that
279  * 'set' is not NULL and that 'ec' succeeds.
280  * @param set the set to test, or NULL (on error)
281  * @param inList list of set contents, in iteration order.  Format is
282  * list of individual strings, in iteration order, followed by sorted
283  * list of strings, delimited by {}.  This means we do not test
284  * characters '{' or '}' and we do not test strings containing those
285  * characters either.
286  * @param outList list of things not in the set.  Same format as
287  * inList.
288  * @param ec an error code, checked for success.  May be NULL in which
289  * case it is ignored.
290  */
expect(const USet * set,const char * inList,const char * outList,UErrorCode * ec)291 static void expect(const USet* set,
292                    const char* inList,
293                    const char* outList,
294                    UErrorCode* ec) {
295     if (ec!=NULL && U_FAILURE(*ec)) {
296         log_err("FAIL: %s\n", u_errorName(*ec));
297         return;
298     }
299     if (set == NULL) {
300         log_err("FAIL: USet is NULL\n");
301         return;
302     }
303     expectContainment(set, inList, TRUE);
304     expectContainment(set, outList, FALSE);
305     expectItems(set, inList);
306 }
307 
expectContainment(const USet * set,const char * list,UBool isIn)308 static void expectContainment(const USet* set,
309                               const char* list,
310                               UBool isIn) {
311     const char* p = list;
312     UChar ustr[4096];
313     char *pat;
314     UErrorCode ec;
315     int32_t rangeStart = -1, rangeEnd = -1, length;
316 
317     ec = U_ZERO_ERROR;
318     length = uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
319     if(U_FAILURE(ec)) {
320         log_err("FAIL: uset_toPattern() fails in expectContainment() - %s\n", u_errorName(ec));
321         return;
322     }
323     pat=aescstrdup(ustr, length);
324 
325     while (*p) {
326         if (*p=='{') {
327             const char* stringStart = ++p;
328             int32_t stringLength = 0;
329             char strCopy[64];
330 
331             while (*p++ != '}') {
332             }
333             stringLength = (int32_t)(p - stringStart - 1);
334             strncpy(strCopy, stringStart, stringLength);
335             strCopy[stringLength] = 0;
336 
337             u_charsToUChars(stringStart, ustr, stringLength);
338 
339             if (uset_containsString(set, ustr, stringLength) == isIn) {
340                 log_verbose("Ok: %s %s \"%s\"\n", pat,
341                             (isIn ? "contains" : "does not contain"),
342                             strCopy);
343             } else {
344                 log_data_err("FAIL: %s %s \"%s\" (Are you missing data?)\n", pat,
345                         (isIn ? "does not contain" : "contains"),
346                         strCopy);
347             }
348         }
349 
350         else {
351             UChar32 c;
352 
353             u_charsToUChars(p, ustr, 1);
354             c = ustr[0];
355 
356             if (uset_contains(set, c) == isIn) {
357                 log_verbose("Ok: %s %s '%c'\n", pat,
358                             (isIn ? "contains" : "does not contain"),
359                             *p);
360             } else {
361                 log_data_err("FAIL: %s %s '%c' (Are you missing data?)\n", pat,
362                         (isIn ? "does not contain" : "contains"),
363                         *p);
364             }
365 
366             /* Test the range API too by looking for ranges */
367             if (c == rangeEnd+1) {
368                 rangeEnd = c;
369             } else {
370                 if (rangeStart >= 0) {
371                     if (uset_containsRange(set, rangeStart, rangeEnd) == isIn) {
372                         log_verbose("Ok: %s %s U+%04X-U+%04X\n", pat,
373                                     (isIn ? "contains" : "does not contain"),
374                                     rangeStart, rangeEnd);
375                     } else {
376                         log_data_err("FAIL: %s %s U+%04X-U+%04X (Are you missing data?)\n", pat,
377                                 (isIn ? "does not contain" : "contains"),
378                                 rangeStart, rangeEnd);
379                     }
380                 }
381                 rangeStart = rangeEnd = c;
382             }
383 
384             ++p;
385         }
386     }
387 
388     if (rangeStart >= 0) {
389         if (uset_containsRange(set, rangeStart, rangeEnd) == isIn) {
390             log_verbose("Ok: %s %s U+%04X-U+%04X\n", pat,
391                         (isIn ? "contains" : "does not contain"),
392                         rangeStart, rangeEnd);
393         } else {
394             log_data_err("FAIL: %s %s U+%04X-U+%04X (Are you missing data?)\n", pat,
395                     (isIn ? "does not contain" : "contains"),
396                     rangeStart, rangeEnd);
397         }
398     }
399 }
400 
401 /* This only works for invariant BMP chars */
oneUCharToChar(UChar32 c)402 static char oneUCharToChar(UChar32 c) {
403     UChar ubuf[1];
404     char buf[1];
405     ubuf[0] = (UChar) c;
406     u_UCharsToChars(ubuf, buf, 1);
407     return buf[0];
408 }
409 
expectItems(const USet * set,const char * items)410 static void expectItems(const USet* set,
411                         const char* items) {
412     const char* p = items;
413     UChar ustr[4096], itemStr[4096];
414     char buf[4096];
415     char *pat;
416     UErrorCode ec;
417     int32_t expectedSize = 0;
418     int32_t rangeCount = uset_getRangeCount(set);
419     int32_t itemCount = uset_getItemCount(set);
420     int32_t itemIndex = 0;
421     UChar32 start = 1, end = 0;
422     int32_t itemLen = 0, length;
423     bool isString = false;
424 
425     ec = U_ZERO_ERROR;
426     length = uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
427     if (U_FAILURE(ec)) {
428         log_err("FAIL: uset_toPattern => %s\n", u_errorName(ec));
429         return;
430     }
431     pat=aescstrdup(ustr, length);
432 
433     if (uset_isEmpty(set) != (strlen(items)==0)) {
434         log_data_err("FAIL: %s should return %s from isEmpty (Are you missing data?)\n",
435                 pat,
436                 strlen(items)==0 ? "TRUE" : "FALSE");
437     }
438 
439     /* Don't test patterns starting with "[^" or "[\\u0000". */
440     if ((u_strlen(ustr) > 2 && ustr[1] == u'^') || uset_contains(set, 0)) {
441         return;
442     }
443 
444     while (*p) {
445 
446         ++expectedSize;
447 
448         if (start > end || start == -1) {
449             /* Fetch our next item */
450             if (itemIndex >= itemCount) {
451                 log_data_err("FAIL: ran out of items iterating %s (Are you missing data?)\n", pat);
452                 return;
453             }
454 
455             // Pass in NULL pointers where we expect them to be ok.
456             if (itemIndex < rangeCount) {
457                 itemLen = uset_getItem(set, itemIndex, &start, &end, NULL, 0, &ec);
458             } else {
459                 itemLen = uset_getItem(set, itemIndex, NULL, NULL,
460                                        itemStr, UPRV_LENGTHOF(itemStr), &ec);
461                 isString = true;
462             }
463             if (U_FAILURE(ec) || itemLen < 0) {
464                 log_err("FAIL: uset_getItem => %s\n", u_errorName(ec));
465                 return;
466             }
467 
468             if (!isString) {
469                 log_verbose("Ok: %s item %d is %c-%c\n", pat,
470                             itemIndex, oneUCharToChar(start),
471                             oneUCharToChar(end));
472                 if (itemLen != 0) {
473                     log_err("FAIL: uset_getItem(%d) => length %d\n", itemIndex, itemLen);
474                 }
475             } else {
476                 itemStr[itemLen] = 0;
477                 u_UCharsToChars(itemStr, buf, itemLen+1);
478                 log_verbose("Ok: %s item %d is \"%s\"\n", pat, itemIndex, buf);
479             }
480 
481             ++itemIndex;
482         }
483 
484         if (*p=='{') {
485             const char* stringStart = ++p;
486             int32_t stringLength = 0;
487             char strCopy[64];
488 
489             while (*p++ != '}') {
490             }
491             stringLength = (int32_t)(p - stringStart - 1);
492             strncpy(strCopy, stringStart, stringLength);
493             strCopy[stringLength] = 0;
494 
495             u_charsToUChars(stringStart, ustr, stringLength);
496             ustr[stringLength] = 0;
497 
498             if (!isString) {
499                 log_err("FAIL: for %s expect \"%s\" next, but got a char\n",
500                         pat, strCopy);
501                 return;
502             }
503 
504             if (u_strcmp(ustr, itemStr) != 0) {
505                 log_err("FAIL: for %s expect \"%s\" next\n",
506                         pat, strCopy);
507                 return;
508             }
509         }
510 
511         else {
512             UChar32 c;
513 
514             u_charsToUChars(p, ustr, 1);
515             c = ustr[0];
516 
517             if (isString) {
518                 log_err("FAIL: for %s expect '%c' next, but got a string\n",
519                         pat, *p);
520                 return;
521             }
522 
523             if (c != start) {
524                 log_err("FAIL: for %s expect '%c' next\n",
525                         pat, *p);
526                 return;
527             }
528 
529             ++start;
530             ++p;
531         }
532     }
533 
534     if (uset_size(set) == expectedSize) {
535         log_verbose("Ok: %s size is %d\n", pat, expectedSize);
536     } else {
537         log_err("FAIL: %s size is %d, expected %d\n",
538                 pat, uset_size(set), expectedSize);
539     }
540 }
541 
542 static void
TestSerialized()543 TestSerialized() {
544     uint16_t buffer[1000];
545     USerializedSet sset;
546     USet *set;
547     UErrorCode errorCode;
548     UChar32 c;
549     int32_t length;
550 
551     /* use a pattern that generates both BMP and supplementary code points */
552     U_STRING_DECL(pattern, "[:Cf:]", 6);
553     U_STRING_INIT(pattern, "[:Cf:]", 6);
554 
555     errorCode=U_ZERO_ERROR;
556     set=uset_openPattern(pattern, -1, &errorCode);
557     if(U_FAILURE(errorCode)) {
558         log_data_err("uset_openPattern([:Cf:]) failed - %s (Are you missing data?)\n", u_errorName(errorCode));
559         return;
560     }
561 
562     length=uset_serialize(set, buffer, UPRV_LENGTHOF(buffer), &errorCode);
563     if(U_FAILURE(errorCode)) {
564         log_err("unable to uset_serialize([:Cf:]) - %s\n", u_errorName(errorCode));
565         uset_close(set);
566         return;
567     }
568 
569     uset_getSerializedSet(&sset, buffer, length);
570     for(c=0; c<=0x10ffff; ++c) {
571         if(uset_contains(set, c)!=uset_serializedContains(&sset, c)) {
572             log_err("uset_contains(U+%04x)!=uset_serializedContains(U+%04x)\n", c);
573             break;
574         }
575     }
576 
577     uset_close(set);
578 }
579 
580 /**
581  * Make sure that when non-invariant chars are passed to uset_openPattern
582  * they do not cause an ugly failure mode (e.g. assertion failure).
583  * JB#3795.
584  */
585 static void
TestNonInvariantPattern()586 TestNonInvariantPattern() {
587     UErrorCode ec = U_ZERO_ERROR;
588     /* The critical part of this test is that the following pattern
589        must contain a non-invariant character. */
590     static const char *pattern = "[:ccc!=0:]";
591     UChar buf[256];
592     int32_t len = u_unescape(pattern, buf, 256);
593     /* This test 'fails' by having an assertion failure within the
594        following call.  It passes by running to completion with no
595        assertion failure. */
596     USet *set = uset_openPattern(buf, len, &ec);
597     uset_close(set);
598 }
599 
TestBadPattern(void)600 static void TestBadPattern(void) {
601     UErrorCode status = U_ZERO_ERROR;
602     USet *pat;
603     U_STRING_DECL(pattern, "[", 1);
604     U_STRING_INIT(pattern, "[", 1);
605     pat = uset_openPatternOptions(pattern, u_strlen(pattern), 0, &status);
606     if (pat != NULL || U_SUCCESS(status)) {
607         log_err("uset_openPatternOptions did not fail as expected %s\n", u_errorName(status));
608     }
609 }
610 
openIDSet()611 static USet *openIDSet() {
612     UErrorCode errorCode = U_ZERO_ERROR;
613     U_STRING_DECL(pattern, "[:ID_Continue:]", 15);
614     U_STRING_INIT(pattern, "[:ID_Continue:]", 15);
615     return uset_openPattern(pattern, 15, &errorCode);
616 }
617 
TestFreezable()618 static void TestFreezable() {
619     USet *idSet;
620     USet *frozen;
621     USet *thawed;
622 
623     idSet=openIDSet();
624 
625     if (idSet == NULL) {
626         log_data_err("openIDSet() returned NULL. (Are you missing data?)\n");
627         uset_close(idSet);
628         return;
629     }
630 
631     frozen=uset_clone(idSet);
632 
633     if (frozen == NULL) {
634         log_err("uset_Clone() returned NULL\n");
635         return;
636     }
637 
638     if(!uset_equals(frozen, idSet)) {
639         log_err("uset_clone() did not make an equal copy\n");
640     }
641 
642     uset_freeze(frozen);
643     uset_addRange(frozen, 0xd802, 0xd805);
644 
645     if(uset_isFrozen(idSet) || !uset_isFrozen(frozen) || !uset_equals(frozen, idSet)) {
646         log_err("uset_freeze() or uset_isFrozen() does not work\n");
647     }
648 
649     thawed=uset_cloneAsThawed(frozen);
650 
651     if (thawed == NULL) {
652         log_err("uset_cloneAsThawed(frozen) returned NULL");
653         uset_close(frozen);
654         uset_close(idSet);
655         return;
656     }
657 
658     uset_addRange(thawed, 0xd802, 0xd805);
659 
660     if(uset_isFrozen(thawed) || uset_equals(thawed, idSet) || !uset_containsRange(thawed, 0xd802, 0xd805)) {
661         log_err("uset_cloneAsThawed() does not work\n");
662     }
663 
664     uset_close(idSet);
665     uset_close(frozen);
666     uset_close(thawed);
667 }
668 
TestSpan()669 static void TestSpan() {
670     static const UChar s16[2]={ 0xe01, 0x3000 };
671     static const char* s8="\xE0\xB8\x81\xE3\x80\x80";
672 
673     USet *idSet=openIDSet();
674 
675     if (idSet == NULL) {
676         log_data_err("openIDSet() returned NULL (Are you missing data?)\n");
677         return;
678     }
679 
680     if(
681         1!=uset_span(idSet, s16, 2, USET_SPAN_CONTAINED) ||
682         0!=uset_span(idSet, s16, 2, USET_SPAN_NOT_CONTAINED) ||
683         2!=uset_spanBack(idSet, s16, 2, USET_SPAN_CONTAINED) ||
684         1!=uset_spanBack(idSet, s16, 2, USET_SPAN_NOT_CONTAINED)
685     ) {
686         log_err("uset_span() or uset_spanBack() does not work\n");
687     }
688 
689     if(
690         3!=uset_spanUTF8(idSet, s8, 6, USET_SPAN_CONTAINED) ||
691         0!=uset_spanUTF8(idSet, s8, 6, USET_SPAN_NOT_CONTAINED) ||
692         6!=uset_spanBackUTF8(idSet, s8, 6, USET_SPAN_CONTAINED) ||
693         3!=uset_spanBackUTF8(idSet, s8, 6, USET_SPAN_NOT_CONTAINED)
694     ) {
695         log_err("uset_spanUTF8() or uset_spanBackUTF8() does not work\n");
696     }
697 
698     uset_freeze(idSet);
699 
700     if(
701         1!=uset_span(idSet, s16, 2, USET_SPAN_CONTAINED) ||
702         0!=uset_span(idSet, s16, 2, USET_SPAN_NOT_CONTAINED) ||
703         2!=uset_spanBack(idSet, s16, 2, USET_SPAN_CONTAINED) ||
704         1!=uset_spanBack(idSet, s16, 2, USET_SPAN_NOT_CONTAINED)
705     ) {
706         log_err("uset_span(frozen) or uset_spanBack(frozen) does not work\n");
707     }
708 
709     if(
710         3!=uset_spanUTF8(idSet, s8, 6, USET_SPAN_CONTAINED) ||
711         0!=uset_spanUTF8(idSet, s8, 6, USET_SPAN_NOT_CONTAINED) ||
712         6!=uset_spanBackUTF8(idSet, s8, 6, USET_SPAN_CONTAINED) ||
713         3!=uset_spanBackUTF8(idSet, s8, 6, USET_SPAN_NOT_CONTAINED)
714     ) {
715         log_err("uset_spanUTF8(frozen) or uset_spanBackUTF8(frozen) does not work\n");
716     }
717 
718     uset_close(idSet);
719 }
720 
721 /*eof*/
722