Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Side by Side Diff: tests/DataRefTest.cpp

Issue 1882853004: Revert of Fixes for SkRWBuffer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkRWBuffer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkData.h" 8 #include "SkData.h"
9 #include "SkDataTable.h" 9 #include "SkDataTable.h"
10 #include "SkOSFile.h" 10 #include "SkOSFile.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 const char gABC[] = "abcdefghijklmnopqrstuvwxyz"; 239 const char gABC[] = "abcdefghijklmnopqrstuvwxyz";
240 240
241 static void check_abcs(skiatest::Reporter* reporter, const char buffer[], size_t size) { 241 static void check_abcs(skiatest::Reporter* reporter, const char buffer[], size_t size) {
242 REPORTER_ASSERT(reporter, size % 26 == 0); 242 REPORTER_ASSERT(reporter, size % 26 == 0);
243 for (size_t offset = 0; offset < size; offset += 26) { 243 for (size_t offset = 0; offset < size; offset += 26) {
244 REPORTER_ASSERT(reporter, !memcmp(&buffer[offset], gABC, 26)); 244 REPORTER_ASSERT(reporter, !memcmp(&buffer[offset], gABC, 26));
245 } 245 }
246 } 246 }
247 247
248 // stream should contain an integral number of copies of gABC. 248 // stream should contains an integral number of copies of gABC.
249 static void check_alphabet_stream(skiatest::Reporter* reporter, SkStream* stream ) { 249 static void check_alphabet_stream(skiatest::Reporter* reporter, SkStream* stream ) {
250 REPORTER_ASSERT(reporter, stream->hasLength()); 250 REPORTER_ASSERT(reporter, stream->hasLength());
251 size_t size = stream->getLength(); 251 size_t size = stream->getLength();
252 REPORTER_ASSERT(reporter, size % 26 == 0); 252 REPORTER_ASSERT(reporter, size % 26 == 0);
253 253
254 SkAutoTMalloc<char> storage(size); 254 SkAutoTMalloc<char> storage(size);
255 char* array = storage.get(); 255 char* array = storage.get();
256 size_t bytesRead = stream->read(array, size); 256 size_t bytesRead = stream->read(array, size);
257 REPORTER_ASSERT(reporter, bytesRead == size); 257 REPORTER_ASSERT(reporter, bytesRead == size);
258 check_abcs(reporter, array, size); 258 check_abcs(reporter, array, size);
(...skipping 18 matching lines...) Expand all
277 size_t offset = 0; 277 size_t offset = 0;
278 do { 278 do {
279 SkASSERT(offset + iter.size() <= size); 279 SkASSERT(offset + iter.size() <= size);
280 memcpy(storage.get() + offset, iter.data(), iter.size()); 280 memcpy(storage.get() + offset, iter.data(), iter.size());
281 offset += iter.size(); 281 offset += iter.size();
282 } while (iter.next()); 282 } while (iter.next());
283 REPORTER_ASSERT(reporter, offset == size); 283 REPORTER_ASSERT(reporter, offset == size);
284 check_abcs(reporter, storage.get(), size); 284 check_abcs(reporter, storage.get(), size);
285 } 285 }
286 286
287 #include "SkTaskGroup.h"
288
289 DEF_TEST(RWBuffer, reporter) { 287 DEF_TEST(RWBuffer, reporter) {
290 // Knowing that the default capacity is 4096, choose N large enough so we fo rce it to use 288 // Knowing that the default capacity is 4096, choose N large enough so we fo rce it to use
291 // multiple buffers internally. 289 // multiple buffers internally.
292 const int N = 1000; 290 const int N = 1000;
293 SkROBuffer* readers[N]; 291 SkROBuffer* readers[N];
294 SkStream* streams[N]; 292 SkStream* streams[N];
295 293
296 { 294 {
297 SkTaskGroup tasks;
298 SkRWBuffer buffer; 295 SkRWBuffer buffer;
299 for (int i = 0; i < N; ++i) { 296 for (int i = 0; i < N; ++i) {
300 buffer.append(gABC, 26); 297 buffer.append(gABC, 26);
301 readers[i] = buffer.newRBufferSnapshot(); 298 readers[i] = buffer.newRBufferSnapshot();
302 streams[i] = buffer.newStreamSnapshot(); 299 streams[i] = buffer.newStreamSnapshot();
303 REPORTER_ASSERT(reporter, readers[i]->size() == buffer.size());
304 REPORTER_ASSERT(reporter, streams[i]->getLength() == buffer.size());
305
306 tasks.add([reporter, i, &readers, &streams] {
307 REPORTER_ASSERT(reporter, (i + 1) * 26U == readers[i]->size());
308 REPORTER_ASSERT(reporter, streams[i]->getLength() == readers[i]- >size());
309 check_alphabet_buffer(reporter, readers[i]);
310 check_alphabet_stream(reporter, streams[i]);
311 REPORTER_ASSERT(reporter, streams[i]->rewind());
312 });
313 } 300 }
314 REPORTER_ASSERT(reporter, N*26 == buffer.size()); 301 REPORTER_ASSERT(reporter, N*26 == buffer.size());
315 tasks.wait();
316 } 302 }
317 303
318 // Test again, to verify that the snapshots work even after the SkRWBuffer i s gone.
319 for (int i = 0; i < N; ++i) { 304 for (int i = 0; i < N; ++i) {
320 REPORTER_ASSERT(reporter, (i + 1) * 26U == readers[i]->size()); 305 REPORTER_ASSERT(reporter, (i + 1) * 26U == readers[i]->size());
321 REPORTER_ASSERT(reporter, streams[i]->getLength() == readers[i]->size()) ;
322 check_alphabet_buffer(reporter, readers[i]); 306 check_alphabet_buffer(reporter, readers[i]);
323 check_alphabet_stream(reporter, streams[i]); 307 check_alphabet_stream(reporter, streams[i]);
324 readers[i]->unref(); 308 readers[i]->unref();
325 delete streams[i]; 309 delete streams[i];
326 } 310 }
327 } 311 }
328 312
329 // Tests that it is safe to call SkROBuffer::Iter::size() when exhausted. 313 // Tests that it is safe to call SkROBuffer::Iter::size() when exhausted.
330 DEF_TEST(RWBuffer_size, r) { 314 DEF_TEST(RWBuffer_size, r) {
331 SkRWBuffer buffer; 315 SkRWBuffer buffer;
332 buffer.append(gABC, 26); 316 buffer.append(gABC, 26);
333 317
334 SkAutoTUnref<SkROBuffer> roBuffer(buffer.newRBufferSnapshot()); 318 SkAutoTUnref<SkROBuffer> roBuffer(buffer.newRBufferSnapshot());
335 SkROBuffer::Iter iter(roBuffer); 319 SkROBuffer::Iter iter(roBuffer);
336 REPORTER_ASSERT(r, iter.data()); 320 REPORTER_ASSERT(r, iter.data());
337 REPORTER_ASSERT(r, iter.size() == 26); 321 REPORTER_ASSERT(r, iter.size() == 26);
338 322
339 // There is only one block in this buffer. 323 // There is only one block in this buffer.
340 REPORTER_ASSERT(r, !iter.next()); 324 REPORTER_ASSERT(r, !iter.next());
341 REPORTER_ASSERT(r, 0 == iter.size()); 325 REPORTER_ASSERT(r, 0 == iter.size());
342 } 326 }
343 327
344 // Tests that operations (including the destructor) are safe on an SkRWBuffer 328 // Tests that it is safe to destruct an SkRWBuffer without appending
345 // without any data appended. 329 // anything to it.
346 DEF_TEST(RWBuffer_noAppend, r) { 330 DEF_TEST(RWBuffer_noAppend, r) {
347 SkRWBuffer buffer; 331 SkRWBuffer buffer;
348 REPORTER_ASSERT(r, 0 == buffer.size()); 332 REPORTER_ASSERT(r, 0 == buffer.size());
349
350 sk_sp<SkROBuffer> roBuffer = sk_sp<SkROBuffer>(buffer.newRBufferSnapshot());
351 REPORTER_ASSERT(r, roBuffer);
352 if (roBuffer) {
353 REPORTER_ASSERT(r, roBuffer->size() == 0);
354 SkROBuffer::Iter iter(roBuffer.get());
355 REPORTER_ASSERT(r, iter.size() == 0);
356 REPORTER_ASSERT(r, !iter.data());
357 REPORTER_ASSERT(r, !iter.next());
358 }
359
360 SkAutoTDelete<SkStream> stream(buffer.newStreamSnapshot());
361 REPORTER_ASSERT(r, stream);
362 if (stream) {
363 REPORTER_ASSERT(r, stream->hasLength());
364 REPORTER_ASSERT(r, stream->getLength() == 0);
365 REPORTER_ASSERT(r, stream->skip(10) == 0);
366 }
367 } 333 }
OLDNEW
« no previous file with comments | « src/core/SkRWBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698