OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkFlattenable.h" | 8 #include "SkFlattenable.h" |
9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 static sk_sp<SkFlattenable> custom_create_proc(SkReadBuffer& buffer) { | 45 static sk_sp<SkFlattenable> custom_create_proc(SkReadBuffer& buffer) { |
46 uint32_t a = buffer.readUInt(); | 46 uint32_t a = buffer.readUInt(); |
47 uint32_t b = buffer.readUInt(); | 47 uint32_t b = buffer.readUInt(); |
48 uint32_t c = buffer.readUInt(); | 48 uint32_t c = buffer.readUInt(); |
49 uint32_t d = buffer.readUInt(); | 49 uint32_t d = buffer.readUInt(); |
50 return sk_sp<SkFlattenable>(new IntFlattenable(a + 1, b + 1, c + 1, d + 1)); | 50 return sk_sp<SkFlattenable>(new IntFlattenable(a + 1, b + 1, c + 1, d + 1)); |
51 } | 51 } |
52 | 52 |
53 DEF_TEST(UnflattenWithCustomFactory, r) { | 53 DEF_TEST(UnflattenWithCustomFactory, r) { |
54 // Create and flatten the test flattenable | 54 // Create and flatten the test flattenable |
55 SkWriteBuffer writeBuffer; | 55 SkBinaryWriteBuffer writeBuffer; |
56 SkAutoTUnref<SkFlattenable> flattenable1(new IntFlattenable(1, 2, 3, 4)); | 56 SkAutoTUnref<SkFlattenable> flattenable1(new IntFlattenable(1, 2, 3, 4)); |
57 writeBuffer.writeFlattenable(flattenable1); | 57 writeBuffer.writeFlattenable(flattenable1); |
58 SkAutoTUnref<SkFlattenable> flattenable2(new IntFlattenable(2, 3, 4, 5)); | 58 SkAutoTUnref<SkFlattenable> flattenable2(new IntFlattenable(2, 3, 4, 5)); |
59 writeBuffer.writeFlattenable(flattenable2); | 59 writeBuffer.writeFlattenable(flattenable2); |
60 SkAutoTUnref<SkFlattenable> flattenable3(new IntFlattenable(3, 4, 5, 6)); | 60 SkAutoTUnref<SkFlattenable> flattenable3(new IntFlattenable(3, 4, 5, 6)); |
61 writeBuffer.writeFlattenable(flattenable3); | 61 writeBuffer.writeFlattenable(flattenable3); |
62 | 62 |
63 // Copy the contents of the write buffer into a read buffer | 63 // Copy the contents of the write buffer into a read buffer |
64 sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten()); | 64 sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten()); |
65 writeBuffer.writeToMemory(data->writable_data()); | 65 writeBuffer.writeToMemory(data->writable_data()); |
(...skipping 20 matching lines...) Expand all Loading... |
86 REPORTER_ASSERT(r, 6 == out2->d()); | 86 REPORTER_ASSERT(r, 6 == out2->d()); |
87 | 87 |
88 SkAutoTUnref<IntFlattenable> out3((IntFlattenable*) readBuffer.readFlattenab
le( | 88 SkAutoTUnref<IntFlattenable> out3((IntFlattenable*) readBuffer.readFlattenab
le( |
89 SkFlattenable::kSkUnused_Type)); | 89 SkFlattenable::kSkUnused_Type)); |
90 REPORTER_ASSERT(r, out3); | 90 REPORTER_ASSERT(r, out3); |
91 REPORTER_ASSERT(r, 4 == out3->a()); | 91 REPORTER_ASSERT(r, 4 == out3->a()); |
92 REPORTER_ASSERT(r, 5 == out3->b()); | 92 REPORTER_ASSERT(r, 5 == out3->b()); |
93 REPORTER_ASSERT(r, 6 == out3->c()); | 93 REPORTER_ASSERT(r, 6 == out3->c()); |
94 REPORTER_ASSERT(r, 7 == out3->d()); | 94 REPORTER_ASSERT(r, 7 == out3->d()); |
95 } | 95 } |
OLD | NEW |