Index: tests/SerializationTest.cpp |
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp |
index d2c692526f62bf3a673aba38568f2a19a7b6f95a..61c311cb06757d1fac11e299e5a4b2ece515dcf7 100644 |
--- a/tests/SerializationTest.cpp |
+++ b/tests/SerializationTest.cpp |
@@ -10,6 +10,123 @@ |
#include "Test.h" |
static void Tests(skiatest::Reporter* reporter) { |
+ // Test matrix serialization |
reed1
2013/11/04 14:26:54
Looks like a lot of similar code. Can any of this
sugoi1
2013/11/04 15:26:14
Done.
|
+ { |
+ SkMatrix matrix = SkMatrix::I(); |
+ SkOrderedWriteBuffer writer(1024); |
+ writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); |
+ writer.writeMatrix(matrix); |
+ uint32_t bytesWritten = writer.bytesWritten(); |
+ // This should write the length (in 4 bytes) and the array |
+ REPORTER_ASSERT(reporter, (9 * sizeof(SkScalar)) == bytesWritten); |
+ |
+ unsigned char dataWritten[1024]; |
+ writer.writeToMemory(dataWritten); |
+ |
+ // Make sure this fails when it should |
+ SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 1); |
+ const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer.skip(0)); |
+ buffer.readMatrix(&matrix); |
+ 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); |
+ |
+ // Make sure this succeeds when it should |
+ SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); |
+ peekBefore = static_cast<const unsigned char*>(buffer2.skip(0)); |
+ buffer2.readMatrix(&matrix); |
+ peekAfter = static_cast<const unsigned char*>(buffer2.skip(0)); |
+ // This should have succeeded, since there are enough bytes to read this |
+ REPORTER_ASSERT(reporter, (peekAfter - peekBefore) == bytesWritten); |
+ |
+ // Test memory read/write functions directly |
+ size_t bytesWrittenToMemory = matrix.writeToMemory(dataWritten); |
+ REPORTER_ASSERT(reporter, SkAlign4(bytesWrittenToMemory) == bytesWrittenToMemory); |
+ size_t bytesReadFromMemory = matrix.readFromMemory(dataWritten, bytesWrittenToMemory); |
+ REPORTER_ASSERT(reporter, SkAlign4(bytesReadFromMemory) == bytesReadFromMemory); |
+ } |
+ |
+ // Test path serialization |
+ { |
+ SkPath path; |
+ SkOrderedWriteBuffer writer(1024); |
+ writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); |
+ writer.writePath(path); |
+ uint32_t bytesWritten = writer.bytesWritten(); |
+ |
+ unsigned char dataWritten[1024]; |
+ writer.writeToMemory(dataWritten); |
+ |
+ // Make sure this fails when it should |
+ SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 1); |
+ const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer.skip(0)); |
+ buffer.readPath(&path); |
+ 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); |
+ |
+ // Make sure this succeeds when it should |
+ SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); |
+ peekBefore = static_cast<const unsigned char*>(buffer2.skip(0)); |
+ buffer2.readPath(&path); |
+ peekAfter = static_cast<const unsigned char*>(buffer2.skip(0)); |
+ // This should have succeeded, since there are enough bytes to read this |
+ REPORTER_ASSERT(reporter, (peekAfter - peekBefore) == bytesWritten); |
+ |
+ // Test memory read/write functions directly |
+ size_t bytesWrittenToMemory = path.writeToMemory(dataWritten); |
+ REPORTER_ASSERT(reporter, SkAlign4(bytesWrittenToMemory) == bytesWrittenToMemory); |
+ size_t bytesReadFromMemory = path.readFromMemory(dataWritten, bytesWrittenToMemory); |
+ REPORTER_ASSERT(reporter, SkAlign4(bytesReadFromMemory) == bytesReadFromMemory); |
+ } |
+ |
+ // Test region serialization |
+ { |
+ SkRegion region; |
+ SkOrderedWriteBuffer writer(1024); |
+ writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); |
+ writer.writeRegion(region); |
+ uint32_t bytesWritten = writer.bytesWritten(); |
+ |
+ unsigned char dataWritten[1024]; |
+ writer.writeToMemory(dataWritten); |
+ |
+ // Make sure this fails when it should |
+ SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 1); |
+ const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer.skip(0)); |
+ buffer.readRegion(®ion); |
+ 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); |
+ |
+ // Make sure this succeeds when it should |
+ SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); |
+ peekBefore = static_cast<const unsigned char*>(buffer2.skip(0)); |
+ buffer2.readRegion(®ion); |
+ peekAfter = static_cast<const unsigned char*>(buffer2.skip(0)); |
+ // This should have succeeded, since there are enough bytes to read this |
+ REPORTER_ASSERT(reporter, (peekAfter - peekBefore) == bytesWritten); |
+ |
+ // Test memory read/write functions directly |
+ size_t bytesWrittenToMemory = region.writeToMemory(dataWritten); |
+ REPORTER_ASSERT(reporter, SkAlign4(bytesWrittenToMemory) == bytesWrittenToMemory); |
+ size_t bytesReadFromMemory = region.readFromMemory(dataWritten, bytesWrittenToMemory); |
+ REPORTER_ASSERT(reporter, SkAlign4(bytesReadFromMemory) == bytesReadFromMemory); |
+ } |
+ |
+ // Test rrect serialization |
+ { |
+ SkRRect rrect; |
+ unsigned char dataWritten[1024]; |
+ |
+ // Test memory read/write functions directly |
+ size_t bytesWrittenToMemory = rrect.writeToMemory(dataWritten); |
+ REPORTER_ASSERT(reporter, SkAlign4(bytesWrittenToMemory) == bytesWrittenToMemory); |
+ size_t bytesReadFromMemory = rrect.readFromMemory(dataWritten, bytesWrittenToMemory); |
+ REPORTER_ASSERT(reporter, SkAlign4(bytesReadFromMemory) == bytesReadFromMemory); |
+ } |
+ |
+ // Test readByteArray |
{ |
static const uint32_t arraySize = 512; |
unsigned char data[arraySize] = {0}; |
@@ -37,6 +154,7 @@ static void Tests(skiatest::Reporter* reporter) { |
REPORTER_ASSERT(reporter, success); |
} |
+ // Test readColorArray |
{ |
static const uint32_t arraySize = 64; |
SkColor data[arraySize]; |
@@ -64,6 +182,7 @@ static void Tests(skiatest::Reporter* reporter) { |
REPORTER_ASSERT(reporter, success); |
} |
+ // Test readIntArray |
{ |
static const uint32_t arraySize = 64; |
int32_t data[arraySize]; |
@@ -91,6 +210,7 @@ static void Tests(skiatest::Reporter* reporter) { |
REPORTER_ASSERT(reporter, success); |
} |
+ // Test readPointArray |
{ |
static const uint32_t arraySize = 64; |
SkPoint data[arraySize]; |
@@ -118,6 +238,7 @@ static void Tests(skiatest::Reporter* reporter) { |
REPORTER_ASSERT(reporter, success); |
} |
+ // Test readScalarArray |
{ |
static const uint32_t arraySize = 64; |
SkScalar data[arraySize]; |