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 uint32_t* const ptr = originalData.get(); |
mtklein
2015/12/10 16:00:03
It's fairly rare that we make const pointers. Thi
scroggo
2015/12/10 16:26:45
Oh, right; I meant to just use SkAutoTMalloc::oper
| |
154 uint32_t* stop = ptr + (dataSize>>2); | 153 for (size_t i = 0; i < dataSize; i++) { |
155 while (ptr < stop) { | 154 ptr[i] = rand.nextU(); |
156 *ptr++ = rand.nextU(); | |
157 } | 155 } |
158 | 156 |
159 // Write the random data to the writer at different lengths for | 157 // Write the random data to the writer at different lengths for |
160 // different alignments. | 158 // different alignments. |
161 for (size_t len = 0; len < dataSize; len++) { | 159 for (size_t len = 0; len < dataSize; len++) { |
162 writer->writePad(originalData.get(), len); | 160 writer->writePad(originalData.get(), len); |
163 } | 161 } |
164 } | 162 } |
165 | 163 |
166 size_t totalBytes = writer->bytesWritten(); | 164 size_t totalBytes = writer->bytesWritten(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 testOverwriteT(reporter, &writer); | 272 testOverwriteT(reporter, &writer); |
275 } | 273 } |
276 | 274 |
277 DEF_TEST(Writer32_misc, reporter) { | 275 DEF_TEST(Writer32_misc, reporter) { |
278 test_reserve(reporter); | 276 test_reserve(reporter); |
279 test_string_null(reporter); | 277 test_string_null(reporter); |
280 test_ptr(reporter); | 278 test_ptr(reporter); |
281 test_rewind(reporter); | 279 test_rewind(reporter); |
282 } | 280 } |
283 | 281 |
OLD | NEW |