OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2013 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "SkOrderedWriteBuffer.h" | |
9 #include "SkValidatingReadBuffer.h" | |
10 #include "Test.h" | |
11 | |
12 static void Tests(skiatest::Reporter* reporter) { | |
13 static const uint32_t arraySize = 512; | |
14 unsigned char data[arraySize] = {0}; | |
15 SkOrderedWriteBuffer writer(1024); | |
16 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); | |
17 writer.writeByteArray(data, arraySize); | |
18 uint32_t bytesWritten = writer.bytesWritten(); | |
19 // This should write the length (in 4 bytes) and the array | |
20 REPORTER_ASSERT(reporter, (4 + arraySize) == bytesWritten); | |
21 | |
22 unsigned char dataWritten[1024]; | |
23 writer.writeToMemory(dataWritten); | |
24 | |
25 // Make sure this fails when it should | |
26 SkValidatingReadBuffer buffer(dataWritten, bytesWritten); | |
27 unsigned char dataRead[arraySize]; | |
28 bool success = buffer.readByteArray(dataRead, 256); | |
29 // This should have failed, since 256 < sizeInBytes | |
30 REPORTER_ASSERT(reporter, !success); | |
31 | |
32 // Make sure this succeeds when it should | |
33 SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); | |
34 success = buffer2.readByteArray(dataRead, arraySize); | |
35 // This should have succeeded, since there are enough bytes to read this | |
36 REPORTER_ASSERT(reporter, success); | |
37 } | |
38 | |
39 #include "TestClassDef.h" | |
40 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.
| |
OLD | NEW |