Adding error checks to SkRBuffer

BUG=
R=robertphillips@google.com, bsalomon@google.com, reed@google.com

Author: sugoi@chromium.org

Review URL: https://codereview.chromium.org/61913002

git-svn-id: http://skia.googlecode.com/svn/trunk@12202 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index f047ec1..f49abe9 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -109,18 +109,18 @@
 
     // 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);