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

Unified Diff: tests/SerializationTest.cpp

Issue 37803002: Adding size parameter to read array functions (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Cleanup Created 7 years, 2 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
« src/effects/SkEmbossMaskFilter.cpp ('K') | « src/images/SkImageRef.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
new file mode 100644
index 0000000000000000000000000000000000000000..dbcca727aac5c417b856cbeec9df0275f91a08b0
--- /dev/null
+++ b/tests/SerializationTest.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkOrderedWriteBuffer.h"
+#include "SkValidatingReadBuffer.h"
+#include "Test.h"
+
+static void Tests(skiatest::Reporter* reporter) {
+ static const uint32_t arraySize = 512;
+ unsigned char data[arraySize] = {0};
+ SkOrderedWriteBuffer writer(1024);
+ writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag);
+ writer.writeByteArray(data, arraySize);
+ uint32_t bytesWritten = writer.bytesWritten();
+ // This should write the length (in 4 bytes) and the array
+ REPORTER_ASSERT(reporter, (4 + arraySize) == bytesWritten);
+
+ unsigned char dataWritten[1024];
+ writer.writeToMemory(dataWritten);
+
+ // Make sure this fails when it should
+ SkValidatingReadBuffer buffer(dataWritten, bytesWritten);
+ unsigned char dataRead[arraySize];
+ bool success = buffer.readByteArray(dataRead, 256);
+ // This should have failed, since 256 < sizeInBytes
+ REPORTER_ASSERT(reporter, !success);
+
+ // Make sure this succeeds when it should
+ SkValidatingReadBuffer buffer2(dataWritten, bytesWritten);
+ success = buffer2.readByteArray(dataRead, arraySize);
+ // This should have succeeded, since there are enough bytes to read this
+ REPORTER_ASSERT(reporter, success);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("Serialization", SerializationClass, Tests)
Stephen White 2013/10/30 20:33:20 IWBN to have tests for all of the readFoo() functi
sugoi1 2013/10/31 14:16:24 Done.
« src/effects/SkEmbossMaskFilter.cpp ('K') | « src/images/SkImageRef.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698