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

Unified Diff: tests/SerializationTest.cpp

Issue 61913002: Adding error checks to SkRBuffer (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Added doc Created 7 years, 1 month 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 | « src/ports/SkFontConfigInterface_direct.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/SerializationTest.cpp
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index f047ec128470f3393a3ecabac652340eb16a98c2..f49abe9106b0569be5eb883b2c3f1e73c5242095 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -109,18 +109,18 @@ static void TestObjectSerialization(T* testObj, skiatest::Reporter* reporter) {
// Make sure this fails when it should (test with smaller size, but still multiple of 4)
SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4);
- const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer.skip(0));
- SerializationUtils<T>::Read(buffer, testObj);
- const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer.skip(0));
- // This should have failed, since the buffer is too small to read a matrix from it
- REPORTER_ASSERT(reporter, peekBefore == peekAfter);
+ T obj;
+ SerializationUtils<T>::Read(buffer, &obj);
+ REPORTER_ASSERT(reporter, !buffer.validate(true));
// Make sure this succeeds when it should
SkValidatingReadBuffer buffer2(dataWritten, bytesWritten);
- peekBefore = static_cast<const unsigned char*>(buffer2.skip(0));
- SerializationUtils<T>::Read(buffer2, testObj);
- peekAfter = static_cast<const unsigned char*>(buffer2.skip(0));
+ const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2.skip(0));
+ T obj2;
+ SerializationUtils<T>::Read(buffer2, &obj2);
+ const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.skip(0));
// This should have succeeded, since there are enough bytes to read this
+ REPORTER_ASSERT(reporter, buffer2.validate(true));
REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == bytesWritten);
TestAlignment(testObj, reporter);
« no previous file with comments | « src/ports/SkFontConfigInterface_direct.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698