| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkRandom.h" | 8 #include "SkRandom.h" |
| 9 #include "SkReader32.h" | 9 #include "SkReader32.h" |
| 10 #include "SkWriter32.h" | 10 #include "SkWriter32.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 size_t alignedSize = SkAlign4(len + 1); | 137 size_t alignedSize = SkAlign4(len + 1); |
| 138 for (size_t j = len; j < alignedSize; j++) { | 138 for (size_t j = len; j < alignedSize; j++) { |
| 139 REPORTER_ASSERT(reporter, 0 == str[j]); | 139 REPORTER_ASSERT(reporter, 0 == str[j]); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 REPORTER_ASSERT(reporter, reader.eof()); | 142 REPORTER_ASSERT(reporter, reader.eof()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 static void testWritePad(skiatest::Reporter* reporter, SkWriter32* writer) { | 145 static void testWritePad(skiatest::Reporter* reporter, SkWriter32* writer) { |
| 146 // Create some random data to write. | 146 // Create some random data to write. |
| 147 const size_t dataSize = 10<<2; | 147 const size_t dataSize = 10; |
| 148 SkASSERT(SkIsAlign4(dataSize)); | |
| 149 | 148 |
| 150 SkAutoMalloc originalData(dataSize); | 149 SkAutoTMalloc<uint32_t> originalData(dataSize); |
| 151 { | 150 { |
| 152 SkRandom rand(0); | 151 SkRandom rand(0); |
| 153 uint32_t* ptr = static_cast<uint32_t*>(originalData.get()); | 152 for (size_t i = 0; i < dataSize; i++) { |
| 154 uint32_t* stop = ptr + (dataSize>>2); | 153 originalData[(int) i] = rand.nextU(); |
| 155 while (ptr < stop) { | |
| 156 *ptr++ = rand.nextU(); | |
| 157 } | 154 } |
| 158 | 155 |
| 159 // Write the random data to the writer at different lengths for | 156 // Write the random data to the writer at different lengths for |
| 160 // different alignments. | 157 // different alignments. |
| 161 for (size_t len = 0; len < dataSize; len++) { | 158 for (size_t len = 0; len < dataSize; len++) { |
| 162 writer->writePad(originalData.get(), len); | 159 writer->writePad(originalData.get(), len); |
| 163 } | 160 } |
| 164 } | 161 } |
| 165 | 162 |
| 166 size_t totalBytes = writer->bytesWritten(); | 163 size_t totalBytes = writer->bytesWritten(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 testOverwriteT(reporter, &writer); | 271 testOverwriteT(reporter, &writer); |
| 275 } | 272 } |
| 276 | 273 |
| 277 DEF_TEST(Writer32_misc, reporter) { | 274 DEF_TEST(Writer32_misc, reporter) { |
| 278 test_reserve(reporter); | 275 test_reserve(reporter); |
| 279 test_string_null(reporter); | 276 test_string_null(reporter); |
| 280 test_ptr(reporter); | 277 test_ptr(reporter); |
| 281 test_rewind(reporter); | 278 test_rewind(reporter); |
| 282 } | 279 } |
| 283 | 280 |
| OLD | NEW |