Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: source/test/intltest/usettest.cpp

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/test/intltest/usettest.h ('k') | source/test/intltest/ustrtest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/test/intltest/usettest.cpp
diff --git a/source/test/intltest/usettest.cpp b/source/test/intltest/usettest.cpp
index 3f1713d357ba783cb65e77c365a1bcb20dcc3133..f715c5bffb36734fd386f3f3f07dee5d66c8be20 100644
--- a/source/test/intltest/usettest.cpp
+++ b/source/test/intltest/usettest.cpp
@@ -1,6 +1,6 @@
/*
********************************************************************************
-* Copyright (C) 1999-2014 International Business Machines Corporation and
+* Copyright (C) 1999-2015 International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************************
* Date Name Description
@@ -90,6 +90,7 @@ UnicodeSetTest::runIndexedTest(int32_t index, UBool exec,
CASE(21,TestFreezable);
CASE(22,TestSpan);
CASE(23,TestStringSpan);
+ CASE(24,TestUCAUnsafeBackwards);
default: name = ""; break;
}
}
@@ -1714,6 +1715,12 @@ void UnicodeSetTest::TestSurrogate() {
errln((UnicodeString)"FAIL: " + UnicodeString(DATA[i], -1, US_INV) + ".size() == " +
set.size() + ", expected 4");
}
+
+ {
+ UErrorCode subErr = U_ZERO_ERROR;
+ checkRoundTrip(set);
+ checkSerializeRoundTrip(set, subErr);
+ }
}
}
@@ -1730,8 +1737,12 @@ void UnicodeSetTest::TestExhaustive() {
logln((UnicodeString)"Testing " + i + ", " + x);
_testComplement(i, x, y);
+ UnicodeSet &toTest = bitsToSet(i, aa);
+
// AS LONG AS WE ARE HERE, check roundtrip
- checkRoundTrip(bitsToSet(i, aa));
+ checkRoundTrip(toTest);
+ UErrorCode ec = U_ZERO_ERROR;
+ checkSerializeRoundTrip(toTest, ec);
for (int32_t j = 0; j < limit; ++j) {
_testAdd(i,j, x,y,z);
@@ -1890,39 +1901,80 @@ UnicodeString UnicodeSetTest::getPairs(const UnicodeSet& set) {
* get the same thing back
*/
void UnicodeSetTest::checkRoundTrip(const UnicodeSet& s) {
- UErrorCode ec = U_ZERO_ERROR;
+ {
+ UnicodeSet t(s);
+ checkEqual(s, t, "copy ct");
+ }
- UnicodeSet t(s);
- checkEqual(s, t, "copy ct");
+ {
+ UnicodeSet t(0xabcd, 0xdef0); // dummy contents should be overwritten
+ t = s;
+ checkEqual(s, t, "operator=");
+ }
- t = s;
- checkEqual(s, t, "operator=");
+ {
+ UnicodeSet t;
+ copyWithIterator(t, s, FALSE);
+ checkEqual(s, t, "iterator roundtrip");
+ }
- copyWithIterator(t, s, FALSE);
- checkEqual(s, t, "iterator roundtrip");
+ {
+ UnicodeSet t;
+ copyWithIterator(t, s, TRUE); // try range
+ checkEqual(s, t, "iterator roundtrip");
+ }
- copyWithIterator(t, s, TRUE); // try range
- checkEqual(s, t, "iterator roundtrip");
-
- UnicodeString pat; s.toPattern(pat, FALSE);
- t.applyPattern(pat, ec);
- if (U_FAILURE(ec)) {
- errln("FAIL: applyPattern");
- return;
- } else {
- checkEqual(s, t, "toPattern(false)");
+ {
+ UnicodeSet t;
+ UnicodeString pat;
+ UErrorCode ec = U_ZERO_ERROR;
+ s.toPattern(pat, FALSE);
+ t.applyPattern(pat, ec);
+ if (U_FAILURE(ec)) {
+ errln("FAIL: toPattern(escapeUnprintable=FALSE), applyPattern - %s", u_errorName(ec));
+ return;
+ } else {
+ checkEqual(s, t, "toPattern(false)");
+ }
}
-
- s.toPattern(pat, TRUE);
- t.applyPattern(pat, ec);
- if (U_FAILURE(ec)) {
- errln("FAIL: applyPattern");
- return;
- } else {
- checkEqual(s, t, "toPattern(true)");
+
+ {
+ UnicodeSet t;
+ UnicodeString pat;
+ UErrorCode ec = U_ZERO_ERROR;
+ s.toPattern(pat, TRUE);
+ t.applyPattern(pat, ec);
+ if (U_FAILURE(ec)) {
+ errln("FAIL: toPattern(escapeUnprintable=TRUE), applyPattern - %s", u_errorName(ec));
+ return;
+ } else {
+ checkEqual(s, t, "toPattern(true)");
+ }
}
}
-
+
+void UnicodeSetTest::checkSerializeRoundTrip(const UnicodeSet& t, UErrorCode &status) {
+ if(U_FAILURE(status)) return;
+ int32_t len = t.serialize(serializeBuffer.getAlias(), serializeBuffer.getCapacity(), status);
+ if(status == U_BUFFER_OVERFLOW_ERROR) {
+ status = U_ZERO_ERROR;
+ serializeBuffer.resize(len);
+ len = t.serialize(serializeBuffer.getAlias(), serializeBuffer.getCapacity(), status);
+ // let 2nd error stand
+ }
+ if(U_FAILURE(status)) {
+ errln("checkSerializeRoundTrip: error %s serializing buffer\n", u_errorName(status));
+ return;
+ }
+ UnicodeSet deserialized(serializeBuffer.getAlias(), len, UnicodeSet::kSerialized, status);
+ if(U_FAILURE(status)) {
+ errln("checkSerializeRoundTrip: error %s deserializing buffer: buf %p len %d, original %d\n", u_errorName(status), serializeBuffer.getAlias(), len, t.getRangeCount());
+ return;
+ }
+
+ checkEqual(t, deserialized, "Set was unequal when deserialized");
+}
+
void UnicodeSetTest::copyWithIterator(UnicodeSet& t, const UnicodeSet& s, UBool withRange) {
t.clear();
UnicodeSetIterator it(s);
@@ -1946,6 +1998,8 @@ void UnicodeSetTest::copyWithIterator(UnicodeSet& t, const UnicodeSet& s, UBool
}
UBool UnicodeSetTest::checkEqual(const UnicodeSet& s, const UnicodeSet& t, const char* message) {
+ assertEquals(UnicodeString("RangeCount: ","") + message, s.getRangeCount(), t.getRangeCount());
+ assertEquals(UnicodeString("size: ","") + message, s.size(), t.size());
UnicodeString source; s.toPattern(source, TRUE);
UnicodeString result; t.toPattern(result, TRUE);
if (s != t) {
@@ -3812,3 +3866,59 @@ void UnicodeSetTest::TestStringSpan() {
errln("FAIL: UnicodeSet(%s).spanBack(while longest match) returns the wrong value", pattern);
}
}
+
+/**
+ * Including collationroot.h fails here with
+1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\driverspecs.h(142): error C2008: '$' : unexpected in macro definition
+ * .. so, we skip this test on Windows.
+ *
+ * the cause is that intltest builds with /Za which disables language extensions - which means
+ * windows header files can't be used.
+ */
+#if !UCONFIG_NO_COLLATION && !U_PLATFORM_HAS_WIN32_API
+#include "collationroot.h"
+#include "collationtailoring.h"
+#endif
+
+void UnicodeSetTest::TestUCAUnsafeBackwards() {
+#if U_PLATFORM_HAS_WIN32_API
+ infoln("Skipping TestUCAUnsafeBackwards() - can't include collationroot.h on Windows without language extensions!");
+#elif !UCONFIG_NO_COLLATION
+ UErrorCode errorCode = U_ZERO_ERROR;
+
+ // Get the unsafeBackwardsSet
+ const CollationCacheEntry *rootEntry = CollationRoot::getRootCacheEntry(errorCode);
+ if(U_FAILURE(errorCode)) {
+ dataerrln("FAIL: %s getting root cache entry", u_errorName(errorCode));
+ return;
+ }
+ //const UVersionInfo &version = rootEntry->tailoring->version;
+ const UnicodeSet *unsafeBackwardSet = rootEntry->tailoring->unsafeBackwardSet;
+
+ checkSerializeRoundTrip(*unsafeBackwardSet, errorCode);
+
+ if(!logKnownIssue("11891","UnicodeSet fails to round trip on CollationRoot...unsafeBackwards set")) {
+ // simple test case
+ // TODO(ticket #11891): Simplify this test function to this simple case. Rename it appropriately.
+ // TODO(ticket #11891): Port test to Java. Is this a bug there, too?
+ UnicodeSet surrogates;
+ surrogates.add(0xd83a); // a lead surrogate
+ surrogates.add(0xdc00, 0xdfff); // a range of trail surrogates
+ UnicodeString pat;
+ surrogates.toPattern(pat, FALSE); // bad: [ 0xd83a, 0xdc00, 0x2d, 0xdfff ]
+ // TODO: Probably fix either UnicodeSet::_generatePattern() or _appendToPat()
+ // so that at least one type of surrogate code points are escaped,
+ // or (minimally) so that adjacent lead+trail surrogate code points are escaped.
+ errorCode = U_ZERO_ERROR;
+ UnicodeSet s2;
+ s2.applyPattern(pat, errorCode); // looks like invalid range [ 0x1e800, 0x2d, 0xdfff ]
+ if(U_FAILURE(errorCode)) {
+ errln("FAIL: surrogates to/from pattern - %s", u_errorName(errorCode));
+ } else {
+ checkEqual(surrogates, s2, "surrogates to/from pattern");
+ }
+ // This occurs in the UCA unsafe-backwards set.
+ checkRoundTrip(*unsafeBackwardSet);
+ }
+#endif
+}
« no previous file with comments | « source/test/intltest/usettest.h ('k') | source/test/intltest/ustrtest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698