OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************** | 2 ******************************************************************************** |
3 * Copyright (C) 1999-2014 International Business Machines Corporation and | 3 * Copyright (C) 1999-2015 International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ******************************************************************************** | 5 ******************************************************************************** |
6 * Date Name Description | 6 * Date Name Description |
7 * 10/20/99 alan Creation. | 7 * 10/20/99 alan Creation. |
8 * 03/22/2000 Madhu Added additional tests | 8 * 03/22/2000 Madhu Added additional tests |
9 ******************************************************************************** | 9 ******************************************************************************** |
10 */ | 10 */ |
11 | 11 |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 | 13 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 CASE(14,TestCloseOver); | 83 CASE(14,TestCloseOver); |
84 CASE(15,TestEscapePattern); | 84 CASE(15,TestEscapePattern); |
85 CASE(16,TestInvalidCodePoint); | 85 CASE(16,TestInvalidCodePoint); |
86 CASE(17,TestSymbolTable); | 86 CASE(17,TestSymbolTable); |
87 CASE(18,TestSurrogate); | 87 CASE(18,TestSurrogate); |
88 CASE(19,TestPosixClasses); | 88 CASE(19,TestPosixClasses); |
89 CASE(20,TestIteration); | 89 CASE(20,TestIteration); |
90 CASE(21,TestFreezable); | 90 CASE(21,TestFreezable); |
91 CASE(22,TestSpan); | 91 CASE(22,TestSpan); |
92 CASE(23,TestStringSpan); | 92 CASE(23,TestStringSpan); |
| 93 CASE(24,TestUCAUnsafeBackwards); |
93 default: name = ""; break; | 94 default: name = ""; break; |
94 } | 95 } |
95 } | 96 } |
96 | 97 |
97 static const char NOT[] = "%%%%"; | 98 static const char NOT[] = "%%%%"; |
98 | 99 |
99 /** | 100 /** |
100 * UVector was improperly copying contents | 101 * UVector was improperly copying contents |
101 * This code will crash this is still true | 102 * This code will crash this is still true |
102 */ | 103 */ |
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 errln("FAIL: UnicodeSet constructor"); | 1708 errln("FAIL: UnicodeSet constructor"); |
1708 continue; | 1709 continue; |
1709 } | 1710 } |
1710 expectContainment(set, | 1711 expectContainment(set, |
1711 CharsToUnicodeString("abc\\U00010000"), | 1712 CharsToUnicodeString("abc\\U00010000"), |
1712 CharsToUnicodeString("\\uD800;\\uDC00")); // split apa
rt surrogate-pair | 1713 CharsToUnicodeString("\\uD800;\\uDC00")); // split apa
rt surrogate-pair |
1713 if (set.size() != 4) { | 1714 if (set.size() != 4) { |
1714 errln((UnicodeString)"FAIL: " + UnicodeString(DATA[i], -1, US_INV) +
".size() == " + | 1715 errln((UnicodeString)"FAIL: " + UnicodeString(DATA[i], -1, US_INV) +
".size() == " + |
1715 set.size() + ", expected 4"); | 1716 set.size() + ", expected 4"); |
1716 } | 1717 } |
| 1718 |
| 1719 { |
| 1720 UErrorCode subErr = U_ZERO_ERROR; |
| 1721 checkRoundTrip(set); |
| 1722 checkSerializeRoundTrip(set, subErr); |
| 1723 } |
1717 } | 1724 } |
1718 } | 1725 } |
1719 | 1726 |
1720 void UnicodeSetTest::TestExhaustive() { | 1727 void UnicodeSetTest::TestExhaustive() { |
1721 // exhaustive tests. Simulate UnicodeSets with integers. | 1728 // exhaustive tests. Simulate UnicodeSets with integers. |
1722 // That gives us very solid tests (except for large memory tests). | 1729 // That gives us very solid tests (except for large memory tests). |
1723 | 1730 |
1724 int32_t limit = 128; | 1731 int32_t limit = 128; |
1725 | 1732 |
1726 UnicodeSet x, y, z, aa; | 1733 UnicodeSet x, y, z, aa; |
1727 | 1734 |
1728 for (int32_t i = 0; i < limit; ++i) { | 1735 for (int32_t i = 0; i < limit; ++i) { |
1729 bitsToSet(i, x); | 1736 bitsToSet(i, x); |
1730 logln((UnicodeString)"Testing " + i + ", " + x); | 1737 logln((UnicodeString)"Testing " + i + ", " + x); |
1731 _testComplement(i, x, y); | 1738 _testComplement(i, x, y); |
1732 | 1739 |
| 1740 UnicodeSet &toTest = bitsToSet(i, aa); |
| 1741 |
1733 // AS LONG AS WE ARE HERE, check roundtrip | 1742 // AS LONG AS WE ARE HERE, check roundtrip |
1734 checkRoundTrip(bitsToSet(i, aa)); | 1743 checkRoundTrip(toTest); |
| 1744 UErrorCode ec = U_ZERO_ERROR; |
| 1745 checkSerializeRoundTrip(toTest, ec); |
1735 | 1746 |
1736 for (int32_t j = 0; j < limit; ++j) { | 1747 for (int32_t j = 0; j < limit; ++j) { |
1737 _testAdd(i,j, x,y,z); | 1748 _testAdd(i,j, x,y,z); |
1738 _testXor(i,j, x,y,z); | 1749 _testXor(i,j, x,y,z); |
1739 _testRetain(i,j, x,y,z); | 1750 _testRetain(i,j, x,y,z); |
1740 _testRemove(i,j, x,y,z); | 1751 _testRemove(i,j, x,y,z); |
1741 } | 1752 } |
1742 } | 1753 } |
1743 } | 1754 } |
1744 | 1755 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 } | 1894 } |
1884 return pairs; | 1895 return pairs; |
1885 } | 1896 } |
1886 | 1897 |
1887 /** | 1898 /** |
1888 * Basic consistency check for a few items. | 1899 * Basic consistency check for a few items. |
1889 * That the iterator works, and that we can create a pattern and | 1900 * That the iterator works, and that we can create a pattern and |
1890 * get the same thing back | 1901 * get the same thing back |
1891 */ | 1902 */ |
1892 void UnicodeSetTest::checkRoundTrip(const UnicodeSet& s) { | 1903 void UnicodeSetTest::checkRoundTrip(const UnicodeSet& s) { |
1893 UErrorCode ec = U_ZERO_ERROR; | 1904 { |
| 1905 UnicodeSet t(s); |
| 1906 checkEqual(s, t, "copy ct"); |
| 1907 } |
1894 | 1908 |
1895 UnicodeSet t(s); | 1909 { |
1896 checkEqual(s, t, "copy ct"); | 1910 UnicodeSet t(0xabcd, 0xdef0); // dummy contents should be overwritten |
| 1911 t = s; |
| 1912 checkEqual(s, t, "operator="); |
| 1913 } |
1897 | 1914 |
1898 t = s; | 1915 { |
1899 checkEqual(s, t, "operator="); | 1916 UnicodeSet t; |
| 1917 copyWithIterator(t, s, FALSE); |
| 1918 checkEqual(s, t, "iterator roundtrip"); |
| 1919 } |
1900 | 1920 |
1901 copyWithIterator(t, s, FALSE); | 1921 { |
1902 checkEqual(s, t, "iterator roundtrip"); | 1922 UnicodeSet t; |
| 1923 copyWithIterator(t, s, TRUE); // try range |
| 1924 checkEqual(s, t, "iterator roundtrip"); |
| 1925 } |
1903 | 1926 |
1904 copyWithIterator(t, s, TRUE); // try range | 1927 { |
1905 checkEqual(s, t, "iterator roundtrip"); | 1928 UnicodeSet t; |
1906 | 1929 UnicodeString pat; |
1907 UnicodeString pat; s.toPattern(pat, FALSE); | 1930 UErrorCode ec = U_ZERO_ERROR; |
1908 t.applyPattern(pat, ec); | 1931 s.toPattern(pat, FALSE); |
1909 if (U_FAILURE(ec)) { | 1932 t.applyPattern(pat, ec); |
1910 errln("FAIL: applyPattern"); | 1933 if (U_FAILURE(ec)) { |
1911 return; | 1934 errln("FAIL: toPattern(escapeUnprintable=FALSE), applyPattern - %s",
u_errorName(ec)); |
1912 } else { | 1935 return; |
1913 checkEqual(s, t, "toPattern(false)"); | 1936 } else { |
| 1937 checkEqual(s, t, "toPattern(false)"); |
| 1938 } |
1914 } | 1939 } |
1915 | 1940 |
1916 s.toPattern(pat, TRUE); | 1941 { |
1917 t.applyPattern(pat, ec); | 1942 UnicodeSet t; |
1918 if (U_FAILURE(ec)) { | 1943 UnicodeString pat; |
1919 errln("FAIL: applyPattern"); | 1944 UErrorCode ec = U_ZERO_ERROR; |
1920 return; | 1945 s.toPattern(pat, TRUE); |
1921 } else { | 1946 t.applyPattern(pat, ec); |
1922 checkEqual(s, t, "toPattern(true)"); | 1947 if (U_FAILURE(ec)) { |
| 1948 errln("FAIL: toPattern(escapeUnprintable=TRUE), applyPattern - %s",
u_errorName(ec)); |
| 1949 return; |
| 1950 } else { |
| 1951 checkEqual(s, t, "toPattern(true)"); |
| 1952 } |
1923 } | 1953 } |
1924 } | 1954 } |
1925 | 1955 |
| 1956 void UnicodeSetTest::checkSerializeRoundTrip(const UnicodeSet& t, UErrorCode &st
atus) { |
| 1957 if(U_FAILURE(status)) return; |
| 1958 int32_t len = t.serialize(serializeBuffer.getAlias(), serializeBuffer.getCapac
ity(), status); |
| 1959 if(status == U_BUFFER_OVERFLOW_ERROR) { |
| 1960 status = U_ZERO_ERROR; |
| 1961 serializeBuffer.resize(len); |
| 1962 len = t.serialize(serializeBuffer.getAlias(), serializeBuffer.getCapacity(),
status); |
| 1963 // let 2nd error stand |
| 1964 } |
| 1965 if(U_FAILURE(status)) { |
| 1966 errln("checkSerializeRoundTrip: error %s serializing buffer\n", u_errorName(
status)); |
| 1967 return; |
| 1968 } |
| 1969 UnicodeSet deserialized(serializeBuffer.getAlias(), len, UnicodeSet::kSerializ
ed, status); |
| 1970 if(U_FAILURE(status)) { |
| 1971 errln("checkSerializeRoundTrip: error %s deserializing buffer: buf %p len %d
, original %d\n", u_errorName(status), serializeBuffer.getAlias(), len, t.getRan
geCount()); |
| 1972 return; |
| 1973 } |
| 1974 |
| 1975 checkEqual(t, deserialized, "Set was unequal when deserialized"); |
| 1976 } |
| 1977 |
1926 void UnicodeSetTest::copyWithIterator(UnicodeSet& t, const UnicodeSet& s, UBool
withRange) { | 1978 void UnicodeSetTest::copyWithIterator(UnicodeSet& t, const UnicodeSet& s, UBool
withRange) { |
1927 t.clear(); | 1979 t.clear(); |
1928 UnicodeSetIterator it(s); | 1980 UnicodeSetIterator it(s); |
1929 if (withRange) { | 1981 if (withRange) { |
1930 while (it.nextRange()) { | 1982 while (it.nextRange()) { |
1931 if (it.isString()) { | 1983 if (it.isString()) { |
1932 t.add(it.getString()); | 1984 t.add(it.getString()); |
1933 } else { | 1985 } else { |
1934 t.add(it.getCodepoint(), it.getCodepointEnd()); | 1986 t.add(it.getCodepoint(), it.getCodepointEnd()); |
1935 } | 1987 } |
1936 } | 1988 } |
1937 } else { | 1989 } else { |
1938 while (it.next()) { | 1990 while (it.next()) { |
1939 if (it.isString()) { | 1991 if (it.isString()) { |
1940 t.add(it.getString()); | 1992 t.add(it.getString()); |
1941 } else { | 1993 } else { |
1942 t.add(it.getCodepoint()); | 1994 t.add(it.getCodepoint()); |
1943 } | 1995 } |
1944 } | 1996 } |
1945 } | 1997 } |
1946 } | 1998 } |
1947 | 1999 |
1948 UBool UnicodeSetTest::checkEqual(const UnicodeSet& s, const UnicodeSet& t, const
char* message) { | 2000 UBool UnicodeSetTest::checkEqual(const UnicodeSet& s, const UnicodeSet& t, const
char* message) { |
| 2001 assertEquals(UnicodeString("RangeCount: ","") + message, s.getRangeCount(), t.
getRangeCount()); |
| 2002 assertEquals(UnicodeString("size: ","") + message, s.size(), t.size()); |
1949 UnicodeString source; s.toPattern(source, TRUE); | 2003 UnicodeString source; s.toPattern(source, TRUE); |
1950 UnicodeString result; t.toPattern(result, TRUE); | 2004 UnicodeString result; t.toPattern(result, TRUE); |
1951 if (s != t) { | 2005 if (s != t) { |
1952 errln((UnicodeString)"FAIL: " + message | 2006 errln((UnicodeString)"FAIL: " + message |
1953 + "; source = " + source | 2007 + "; source = " + source |
1954 + "; result = " + result | 2008 + "; result = " + result |
1955 ); | 2009 ); |
1956 return FALSE; | 2010 return FALSE; |
1957 } else { | 2011 } else { |
1958 logln((UnicodeString)"Ok: " + message | 2012 logln((UnicodeString)"Ok: " + message |
(...skipping 1846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3805 string16=UNICODE_STRING_SIMPLE("abbcdabcdabd"); | 3859 string16=UNICODE_STRING_SIMPLE("abbcdabcdabd"); |
3806 s16=string16.getBuffer(); | 3860 s16=string16.getBuffer(); |
3807 length16=string16.length(); | 3861 length16=string16.length(); |
3808 if( set.spanBack(s16, 12, USET_SPAN_CONTAINED)!=0 || | 3862 if( set.spanBack(s16, 12, USET_SPAN_CONTAINED)!=0 || |
3809 set.spanBack(s16, 12, USET_SPAN_SIMPLE)!=6 || | 3863 set.spanBack(s16, 12, USET_SPAN_SIMPLE)!=6 || |
3810 set.spanBack(s16, 5, USET_SPAN_SIMPLE)!=0 | 3864 set.spanBack(s16, 5, USET_SPAN_SIMPLE)!=0 |
3811 ) { | 3865 ) { |
3812 errln("FAIL: UnicodeSet(%s).spanBack(while longest match) returns the wr
ong value", pattern); | 3866 errln("FAIL: UnicodeSet(%s).spanBack(while longest match) returns the wr
ong value", pattern); |
3813 } | 3867 } |
3814 } | 3868 } |
| 3869 |
| 3870 /** |
| 3871 * Including collationroot.h fails here with |
| 3872 1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\driverspecs.h(142)
: error C2008: '$' : unexpected in macro definition |
| 3873 * .. so, we skip this test on Windows. |
| 3874 * |
| 3875 * the cause is that intltest builds with /Za which disables language extension
s - which means |
| 3876 * windows header files can't be used. |
| 3877 */ |
| 3878 #if !UCONFIG_NO_COLLATION && !U_PLATFORM_HAS_WIN32_API |
| 3879 #include "collationroot.h" |
| 3880 #include "collationtailoring.h" |
| 3881 #endif |
| 3882 |
| 3883 void UnicodeSetTest::TestUCAUnsafeBackwards() { |
| 3884 #if U_PLATFORM_HAS_WIN32_API |
| 3885 infoln("Skipping TestUCAUnsafeBackwards() - can't include collationroot.h on
Windows without language extensions!"); |
| 3886 #elif !UCONFIG_NO_COLLATION |
| 3887 UErrorCode errorCode = U_ZERO_ERROR; |
| 3888 |
| 3889 // Get the unsafeBackwardsSet |
| 3890 const CollationCacheEntry *rootEntry = CollationRoot::getRootCacheEntry(erro
rCode); |
| 3891 if(U_FAILURE(errorCode)) { |
| 3892 dataerrln("FAIL: %s getting root cache entry", u_errorName(errorCode)); |
| 3893 return; |
| 3894 } |
| 3895 //const UVersionInfo &version = rootEntry->tailoring->version; |
| 3896 const UnicodeSet *unsafeBackwardSet = rootEntry->tailoring->unsafeBackwardSe
t; |
| 3897 |
| 3898 checkSerializeRoundTrip(*unsafeBackwardSet, errorCode); |
| 3899 |
| 3900 if(!logKnownIssue("11891","UnicodeSet fails to round trip on CollationRoot..
.unsafeBackwards set")) { |
| 3901 // simple test case |
| 3902 // TODO(ticket #11891): Simplify this test function to this simple case.
Rename it appropriately. |
| 3903 // TODO(ticket #11891): Port test to Java. Is this a bug there, too? |
| 3904 UnicodeSet surrogates; |
| 3905 surrogates.add(0xd83a); // a lead surrogate |
| 3906 surrogates.add(0xdc00, 0xdfff); // a range of trail surrogates |
| 3907 UnicodeString pat; |
| 3908 surrogates.toPattern(pat, FALSE); // bad: [ 0xd83a, 0xdc00, 0x2d, 0xdff
f ] |
| 3909 // TODO: Probably fix either UnicodeSet::_generatePattern() or _appendTo
Pat() |
| 3910 // so that at least one type of surrogate code points are escaped, |
| 3911 // or (minimally) so that adjacent lead+trail surrogate code points are
escaped. |
| 3912 errorCode = U_ZERO_ERROR; |
| 3913 UnicodeSet s2; |
| 3914 s2.applyPattern(pat, errorCode); // looks like invalid range [ 0x1e800,
0x2d, 0xdfff ] |
| 3915 if(U_FAILURE(errorCode)) { |
| 3916 errln("FAIL: surrogates to/from pattern - %s", u_errorName(errorCode
)); |
| 3917 } else { |
| 3918 checkEqual(surrogates, s2, "surrogates to/from pattern"); |
| 3919 } |
| 3920 // This occurs in the UCA unsafe-backwards set. |
| 3921 checkRoundTrip(*unsafeBackwardSet); |
| 3922 } |
| 3923 #endif |
| 3924 } |
OLD | NEW |