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

Side by Side Diff: tests/PDFPrimitivesTest.cpp

Issue 2322133003: SkPDF/Tests: imporve test coverage. (Closed)
Patch Set: toms nit Created 4 years, 3 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 | « tests/PDFJpegEmbedTest.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 2010 The Android Open Source Project 2 * Copyright 2010 The Android Open Source Project
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 "Resources.h" 8 #include "Resources.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 sk_sp<SkPDFArray> referencedArray(new SkPDFArray); 327 sk_sp<SkPDFArray> referencedArray(new SkPDFArray);
328 SkPDFObjNumMap catalog; 328 SkPDFObjNumMap catalog;
329 catalog.addObject(referencedArray.get()); 329 catalog.addObject(referencedArray.get());
330 REPORTER_ASSERT(reporter, catalog.getObjectNumber( 330 REPORTER_ASSERT(reporter, catalog.getObjectNumber(
331 referencedArray.get()) == 1); 331 referencedArray.get()) == 1);
332 dict->insertObjRef("n1", std::move(referencedArray)); 332 dict->insertObjRef("n1", std::move(referencedArray));
333 SkString result = emit_to_string(*dict, &catalog); 333 SkString result = emit_to_string(*dict, &catalog);
334 assert_eq(reporter, result, "<</Type /DType\n/n1 1 0 R>>"); 334 assert_eq(reporter, result, "<</Type /DType\n/n1 1 0 R>>");
335 } 335 }
336 336
337 DEF_TEST(PDFPrimitives, reporter) { 337 DEF_TEST(SkPDF_Primitives, reporter) {
338 TestPDFUnion(reporter); 338 TestPDFUnion(reporter);
339 TestPDFArray(reporter); 339 TestPDFArray(reporter);
340 TestPDFDict(reporter); 340 TestPDFDict(reporter);
341 TestPDFStream(reporter); 341 TestPDFStream(reporter);
342 TestObjectNumberMap(reporter); 342 TestObjectNumberMap(reporter);
343 TestObjectRef(reporter); 343 TestObjectRef(reporter);
344 test_issue1083(); 344 test_issue1083();
345 } 345 }
346 346
347 namespace { 347 namespace {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 void DummyImageFilter::toString(SkString* str) const { 382 void DummyImageFilter::toString(SkString* str) const {
383 str->appendf("DummyImageFilter: ("); 383 str->appendf("DummyImageFilter: (");
384 str->append(")"); 384 str->append(")");
385 } 385 }
386 #endif 386 #endif
387 387
388 }; 388 };
389 389
390 // Check that PDF rendering of image filters successfully falls back to 390 // Check that PDF rendering of image filters successfully falls back to
391 // CPU rasterization. 391 // CPU rasterization.
392 DEF_TEST(PDFImageFilter, reporter) { 392 DEF_TEST(SkPDF_ImageFilter, reporter) {
393 REQUIRE_PDF_DOCUMENT(SkPDF_ImageFilter, reporter);
393 SkDynamicMemoryWStream stream; 394 SkDynamicMemoryWStream stream;
394 sk_sp<SkDocument> doc(SkDocument::MakePDF(&stream)); 395 sk_sp<SkDocument> doc(SkDocument::MakePDF(&stream));
395 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f); 396 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
396 397
397 sk_sp<DummyImageFilter> filter(DummyImageFilter::Make()); 398 sk_sp<DummyImageFilter> filter(DummyImageFilter::Make());
398 399
399 // Filter just created; should be unvisited. 400 // Filter just created; should be unvisited.
400 REPORTER_ASSERT(reporter, !filter->visited()); 401 REPORTER_ASSERT(reporter, !filter->visited());
401 SkPaint paint; 402 SkPaint paint;
402 paint.setImageFilter(filter.get()); 403 paint.setImageFilter(filter.get());
403 canvas->drawRect(SkRect::MakeWH(100, 100), paint); 404 canvas->drawRect(SkRect::MakeWH(100, 100), paint);
404 doc->close(); 405 doc->close();
405 406
406 // Filter was used in rendering; should be visited. 407 // Filter was used in rendering; should be visited.
407 REPORTER_ASSERT(reporter, filter->visited()); 408 REPORTER_ASSERT(reporter, filter->visited());
408 } 409 }
409 410
410 // Check that PDF rendering of image filters successfully falls back to 411 // Check that PDF rendering of image filters successfully falls back to
411 // CPU rasterization. 412 // CPU rasterization.
412 DEF_TEST(PDFFontCanEmbedTypeface, reporter) { 413 DEF_TEST(SkPDF_FontCanEmbedTypeface, reporter) {
413 SkPDFCanon canon; 414 SkPDFCanon canon;
414 415
415 const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf"; 416 const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf";
416 sk_sp<SkTypeface> noEmbedTypeface(MakeResourceAsTypeface(resource)); 417 sk_sp<SkTypeface> noEmbedTypeface(MakeResourceAsTypeface(resource));
417 if (noEmbedTypeface) { 418 if (noEmbedTypeface) {
418 REPORTER_ASSERT(reporter, 419 REPORTER_ASSERT(reporter,
419 !SkPDFFont::CanEmbedTypeface(noEmbedTypeface.get(), &can on)); 420 !SkPDFFont::CanEmbedTypeface(noEmbedTypeface.get(), &can on));
420 } 421 }
421 sk_sp<SkTypeface> portableTypeface( 422 sk_sp<SkTypeface> portableTypeface(
422 sk_tool_utils::create_portable_typeface(NULL, SkFontStyle())); 423 sk_tool_utils::create_portable_typeface(NULL, SkFontStyle()));
(...skipping 23 matching lines...) Expand all
446 ERRORF(reporter, "unscannable result: %s", floatString); 447 ERRORF(reporter, "unscannable result: %s", floatString);
447 return; 448 return;
448 } 449 }
449 if (std::isfinite(inputFloat) && roundTripFloat != inputFloat) { 450 if (std::isfinite(inputFloat) && roundTripFloat != inputFloat) {
450 ERRORF(reporter, "roundTripFloat (%.9g) != inputFloat (%.9g)", 451 ERRORF(reporter, "roundTripFloat (%.9g) != inputFloat (%.9g)",
451 roundTripFloat, inputFloat); 452 roundTripFloat, inputFloat);
452 } 453 }
453 } 454 }
454 455
455 // Test SkPDFUtils::AppendScalar for accuracy. 456 // Test SkPDFUtils::AppendScalar for accuracy.
456 DEF_TEST(PDFPrimitives_Scalar, reporter) { 457 DEF_TEST(SkPDF_Primitives_Scalar, reporter) {
457 SkRandom random(0x5EED); 458 SkRandom random(0x5EED);
458 int iterationCount = 512; 459 int iterationCount = 512;
459 while (iterationCount-- > 0) { 460 while (iterationCount-- > 0) {
460 union { uint32_t u; float f; }; 461 union { uint32_t u; float f; };
461 u = random.nextU(); 462 u = random.nextU();
462 static_assert(sizeof(float) == sizeof(uint32_t), ""); 463 static_assert(sizeof(float) == sizeof(uint32_t), "");
463 check_pdf_scalar_serialization(reporter, f); 464 check_pdf_scalar_serialization(reporter, f);
464 } 465 }
465 float alwaysCheck[] = { 466 float alwaysCheck[] = {
466 0.0f, -0.0f, 1.0f, -1.0f, SK_ScalarPI, 0.1f, FLT_MIN, FLT_MAX, 467 0.0f, -0.0f, 1.0f, -1.0f, SK_ScalarPI, 0.1f, FLT_MIN, FLT_MAX,
467 -FLT_MIN, -FLT_MAX, FLT_MIN / 16.0f, -FLT_MIN / 16.0f, 468 -FLT_MIN, -FLT_MAX, FLT_MIN / 16.0f, -FLT_MIN / 16.0f,
468 SK_FloatNaN, SK_FloatInfinity, SK_FloatNegativeInfinity, 469 SK_FloatNaN, SK_FloatInfinity, SK_FloatNegativeInfinity,
469 -FLT_MIN / 8388608.0 470 -FLT_MIN / 8388608.0
470 }; 471 };
471 for (float inputFloat: alwaysCheck) { 472 for (float inputFloat: alwaysCheck) {
472 check_pdf_scalar_serialization(reporter, inputFloat); 473 check_pdf_scalar_serialization(reporter, inputFloat);
473 } 474 }
474 } 475 }
475 476
476 // Test SkPDFUtils:: for accuracy. 477 // Test SkPDFUtils:: for accuracy.
477 DEF_TEST(PDFPrimitives_Color, reporter) { 478 DEF_TEST(SkPDF_Primitives_Color, reporter) {
478 char buffer[5]; 479 char buffer[5];
479 for (int i = 0; i < 256; ++i) { 480 for (int i = 0; i < 256; ++i) {
480 size_t len = SkPDFUtils::ColorToDecimal(i, buffer); 481 size_t len = SkPDFUtils::ColorToDecimal(i, buffer);
481 REPORTER_ASSERT(reporter, len == strlen(buffer)); 482 REPORTER_ASSERT(reporter, len == strlen(buffer));
482 float f; 483 float f;
483 REPORTER_ASSERT(reporter, 1 == sscanf(buffer, "%f", &f)); 484 REPORTER_ASSERT(reporter, 1 == sscanf(buffer, "%f", &f));
484 int roundTrip = (int)(0.5 + f * 255); 485 int roundTrip = (int)(0.5 + f * 255);
485 REPORTER_ASSERT(reporter, roundTrip == i); 486 REPORTER_ASSERT(reporter, roundTrip == i);
486 } 487 }
487 } 488 }
OLDNEW
« no previous file with comments | « tests/PDFJpegEmbedTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698