| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| 11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
| 12 #include "SkReader32.h" | 12 #include "SkReader32.h" |
| 13 #include "SkWriter32.h" | 13 #include "SkWriter32.h" |
| 14 #include "Test.h" | 14 #include "Test.h" |
| 15 | 15 |
| 16 static void check_contents(skiatest::Reporter* reporter, const SkWriter32& write
r, | 16 static void check_contents(skiatest::Reporter* reporter, const SkWriter32& write
r, |
| 17 const void* expected, size_t size) { | 17 const void* expected, size_t size) { |
| 18 SkAutoSMalloc<256> storage(size); | 18 SkAutoSMalloc<256> storage(size); |
| 19 REPORTER_ASSERT(reporter, writer.bytesWritten() == size); | 19 REPORTER_ASSERT(reporter, writer.bytesWritten() == size); |
| 20 writer.flatten(storage.get()); | 20 writer.flatten(storage.get()); |
| 21 REPORTER_ASSERT(reporter, !memcmp(storage.get(), expected, size)); | 21 REPORTER_ASSERT(reporter, !memcmp(storage.get(), expected, size)); |
| 22 } | 22 } |
| 23 | 23 |
| 24 |
| 25 static void test_reserve(skiatest::Reporter* reporter) { |
| 26 // There used to be a bug where we'd assert your first reservation had to |
| 27 // fit in external storage if you used it. This would crash in debug mode. |
| 28 uint8_t storage[4]; |
| 29 SkWriter32 writer(0, storage, sizeof(storage)); |
| 30 writer.reserve(40); |
| 31 } |
| 32 |
| 24 static void test_string_null(skiatest::Reporter* reporter) { | 33 static void test_string_null(skiatest::Reporter* reporter) { |
| 25 uint8_t storage[8]; | 34 uint8_t storage[8]; |
| 26 SkWriter32 writer(0, storage, sizeof(storage)); | 35 SkWriter32 writer(0, storage, sizeof(storage)); |
| 27 | 36 |
| 28 // Can we write NULL? | 37 // Can we write NULL? |
| 29 writer.writeString(NULL); | 38 writer.writeString(NULL); |
| 30 const int32_t expected[] = { 0x0, 0x0 }; | 39 const int32_t expected[] = { 0x0, 0x0 }; |
| 31 check_contents(reporter, writer, expected, sizeof(expected)); | 40 check_contents(reporter, writer, expected, sizeof(expected)); |
| 32 } | 41 } |
| 33 | 42 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 { | 240 { |
| 232 SkSWriter32<1024 * sizeof(intptr_t)> writer(100); | 241 SkSWriter32<1024 * sizeof(intptr_t)> writer(100); |
| 233 test1(reporter, &writer); | 242 test1(reporter, &writer); |
| 234 writer.reset(); // should just rewind our storage | 243 writer.reset(); // should just rewind our storage |
| 235 test2(reporter, &writer); | 244 test2(reporter, &writer); |
| 236 | 245 |
| 237 writer.reset(); | 246 writer.reset(); |
| 238 testWritePad(reporter, &writer); | 247 testWritePad(reporter, &writer); |
| 239 } | 248 } |
| 240 | 249 |
| 250 test_reserve(reporter); |
| 241 test_string_null(reporter); | 251 test_string_null(reporter); |
| 242 test_ptr(reporter); | 252 test_ptr(reporter); |
| 243 test_rewind(reporter); | 253 test_rewind(reporter); |
| 244 } | 254 } |
| 245 | 255 |
| 246 #include "TestClassDef.h" | 256 #include "TestClassDef.h" |
| 247 DEFINE_TESTCLASS("Writer32", Writer32Class, Tests) | 257 DEFINE_TESTCLASS("Writer32", Writer32Class, Tests) |
| OLD | NEW |