OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Resources.h" | 8 #include "Resources.h" |
9 #include "SkBitmapSource.h" | 9 #include "SkBitmapSource.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // Make sure this succeeds when it should | 191 // Make sure this succeeds when it should |
192 SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); | 192 SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); |
193 const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2.
skip(0)); | 193 const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2.
skip(0)); |
194 T* obj2 = NULL; | 194 T* obj2 = NULL; |
195 SerializationUtils<T>::Read(buffer2, &obj2); | 195 SerializationUtils<T>::Read(buffer2, &obj2); |
196 const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.s
kip(0)); | 196 const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.s
kip(0)); |
197 if (shouldSucceed) { | 197 if (shouldSucceed) { |
198 // This should have succeeded, since there are enough bytes to read this | 198 // This should have succeeded, since there are enough bytes to read this |
199 REPORTER_ASSERT(reporter, buffer2.isValid()); | 199 REPORTER_ASSERT(reporter, buffer2.isValid()); |
200 REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) ==
bytesWritten); | 200 REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) ==
bytesWritten); |
201 REPORTER_ASSERT(reporter, NULL != obj2); | 201 REPORTER_ASSERT(reporter, obj2); |
202 } else { | 202 } else { |
203 // If the deserialization was supposed to fail, make sure it did | 203 // If the deserialization was supposed to fail, make sure it did |
204 REPORTER_ASSERT(reporter, !buffer.isValid()); | 204 REPORTER_ASSERT(reporter, !buffer.isValid()); |
205 REPORTER_ASSERT(reporter, NULL == obj2); | 205 REPORTER_ASSERT(reporter, NULL == obj2); |
206 } | 206 } |
207 | 207 |
208 return obj2; // Return object to perform further validity tests on it | 208 return obj2; // Return object to perform further validity tests on it |
209 } | 209 } |
210 | 210 |
211 template<typename T> | 211 template<typename T> |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); | 483 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); |
484 pict->flatten(writer); | 484 pict->flatten(writer); |
485 size_t size = writer.bytesWritten(); | 485 size_t size = writer.bytesWritten(); |
486 SkAutoTMalloc<unsigned char> data(size); | 486 SkAutoTMalloc<unsigned char> data(size); |
487 writer.writeToMemory(static_cast<void*>(data.get())); | 487 writer.writeToMemory(static_cast<void*>(data.get())); |
488 | 488 |
489 // Deserialize picture | 489 // Deserialize picture |
490 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); | 490 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); |
491 SkAutoTUnref<SkPicture> readPict( | 491 SkAutoTUnref<SkPicture> readPict( |
492 SkPicture::CreateFromBuffer(reader)); | 492 SkPicture::CreateFromBuffer(reader)); |
493 REPORTER_ASSERT(reporter, NULL != readPict.get()); | 493 REPORTER_ASSERT(reporter, readPict.get()); |
494 } | 494 } |
495 | 495 |
496 TestPictureTypefaceSerialization(reporter); | 496 TestPictureTypefaceSerialization(reporter); |
497 } | 497 } |
OLD | NEW |