From 2ccdb636e8618db77be8e05cdacd82c249c6898c Mon Sep 17 00:00:00 2001 From: halcanary Date: Tue, 11 Aug 2015 13:35:12 -0700 Subject: [PATCH] SkPDF: clean up overuse of SK_SUPPORT_PDF When possible use run-time checks (via SkDocument::CreatePDF) When PDF is disabled, do not compile tests/PDF*.cpp Review URL: https://codereview.chromium.org/1278403006 --- gyp/tests.gypi | 1 + tests/AnnotationTest.cpp | 5 ++--- tests/CanvasTest.cpp | 9 ++++++--- ...{DeflateWStream.cpp => PDFDeflateWStreamTest.cpp} | 3 --- tests/{DocumentTest.cpp => PDFDocumentTest.cpp} | 3 +-- tests/{FlateTest.cpp => PDFFlateTest.cpp} | 3 --- ...{ToUnicodeTest.cpp => PDFGlyphsToUnicodeTest.cpp} | 3 --- tests/PDFInvalidBitmapTest.cpp | 3 --- tests/PDFJpegEmbedTest.cpp | 3 --- ...srcover.cpp => PDFOpaqueSrcModeToSrcOverTest.cpp} | 4 +--- tests/PDFPrimitivesTest.cpp | 3 --- tests/Test.h | 12 ++++++++++++ 12 files changed, 23 insertions(+), 29 deletions(-) rename tests/{DeflateWStream.cpp => PDFDeflateWStreamTest.cpp} (98%) rename tests/{DocumentTest.cpp => PDFDocumentTest.cpp} (98%) rename tests/{FlateTest.cpp => PDFFlateTest.cpp} (98%) rename tests/{ToUnicodeTest.cpp => PDFGlyphsToUnicodeTest.cpp} (99%) rename tests/{skpdf_opaquesrcmodetosrcover.cpp => PDFOpaqueSrcModeToSrcOverTest.cpp} (96%) diff --git a/gyp/tests.gypi b/gyp/tests.gypi index a6ad5d2cc6..c054e9f93d 100644 --- a/gyp/tests.gypi +++ b/gyp/tests.gypi @@ -40,6 +40,7 @@ [ 'not skia_pdf', { 'dependencies!': [ 'pdf.gyp:pdf' ], 'dependencies': [ 'pdf.gyp:nopdf' ], + 'sources!': [ ' doc(SkDocument::CreatePDF(&outStream)); SkCanvas* canvas = doc->beginPage(612.0f, 792.0f); @@ -60,6 +59,7 @@ DEF_TEST(Annotation_PdfLink, reporter) { } DEF_TEST(Annotation_NamedDestination, reporter) { + REQUIRE_PDF_DOCUMENT(Annotation_NamedDestination, reporter); SkDynamicMemoryWStream outStream; SkAutoTUnref doc(SkDocument::CreatePDF(&outStream)); SkCanvas* canvas = doc->beginPage(612.0f, 792.0f); @@ -76,4 +76,3 @@ DEF_TEST(Annotation_NamedDestination, reporter) { REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/example ")); } -#endif // SK_SUPPORT_PDF diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index 78253ac900..0d5c862360 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -570,6 +570,12 @@ static void TestPdfDevice(skiatest::Reporter* reporter, SkAutoTUnref doc(SkDocument::CreatePDF(&outStream)); #if SK_SUPPORT_PDF REPORTER_ASSERT(reporter, doc); +#else + REPORTER_ASSERT(reporter, !doc); +#endif // SK_SUPPORT_PDF + if (!doc) { + return; + } SkCanvas* canvas = doc->beginPage(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight)); REPORTER_ASSERT(reporter, canvas); @@ -577,9 +583,6 @@ static void TestPdfDevice(skiatest::Reporter* reporter, testStep->draw(canvas, d, reporter); REPORTER_ASSERT(reporter, doc->close()); -#else - REPORTER_ASSERT(reporter, !doc); -#endif // SK_SUPPORT_PDF } // The following class groups static functions that need to access diff --git a/tests/DeflateWStream.cpp b/tests/PDFDeflateWStreamTest.cpp similarity index 98% rename from tests/DeflateWStream.cpp rename to tests/PDFDeflateWStreamTest.cpp index 930ecb4144..b22574671b 100644 --- a/tests/DeflateWStream.cpp +++ b/tests/PDFDeflateWStreamTest.cpp @@ -9,8 +9,6 @@ #include "SkRandom.h" #include "Test.h" -#if SK_SUPPORT_PDF - DEF_TEST(SkDeflateWStream, r) { SkRandom random(123456); for (int i = 0; i < 50; ++i) { @@ -72,4 +70,3 @@ DEF_TEST(SkDeflateWStream, r) { } } } -#endif // SK_SUPPORT_PDF diff --git a/tests/DocumentTest.cpp b/tests/PDFDocumentTest.cpp similarity index 98% rename from tests/DocumentTest.cpp rename to tests/PDFDocumentTest.cpp index 5bd6ba6a03..f9fcdff6a2 100644 --- a/tests/DocumentTest.cpp +++ b/tests/PDFDocumentTest.cpp @@ -10,7 +10,6 @@ #include "SkDocument.h" #include "SkOSFile.h" #include "SkStream.h" -#if SK_SUPPORT_PDF static void test_empty(skiatest::Reporter* reporter) { SkDynamicMemoryWStream stream; @@ -104,10 +103,10 @@ static void test_close(skiatest::Reporter* reporter) { } DEF_TEST(document_tests, reporter) { + REQUIRE_PDF_DOCUMENT(document_tests, reporter); test_empty(reporter); test_abort(reporter); test_abortWithFile(reporter); test_file(reporter); test_close(reporter); } -#endif // SK_SUPPORT_PDF diff --git a/tests/FlateTest.cpp b/tests/PDFFlateTest.cpp similarity index 98% rename from tests/FlateTest.cpp rename to tests/PDFFlateTest.cpp index 8387f527d1..40efe1a5d8 100644 --- a/tests/FlateTest.cpp +++ b/tests/PDFFlateTest.cpp @@ -10,8 +10,6 @@ #include "SkStream.h" #include "Test.h" -#if SK_SUPPORT_PDF - // A memory stream that reports zero size with the standard call, like // an unseekable file stream would. class SkZeroSizeMemStream : public SkMemoryStream { @@ -114,4 +112,3 @@ DEF_TEST(Flate, reporter) { TestFlate(reporter, &fileStream, 512); TestFlate(reporter, &fileStream, 10240); } -#endif // SK_SUPPORT_PDF diff --git a/tests/ToUnicodeTest.cpp b/tests/PDFGlyphsToUnicodeTest.cpp similarity index 99% rename from tests/ToUnicodeTest.cpp rename to tests/PDFGlyphsToUnicodeTest.cpp index 4dcb2df0b2..33fcc80ef7 100644 --- a/tests/ToUnicodeTest.cpp +++ b/tests/PDFGlyphsToUnicodeTest.cpp @@ -11,8 +11,6 @@ #include "SkStream.h" #include "Test.h" -#if SK_SUPPORT_PDF - static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, const char* buffer, size_t len) { SkAutoDataUnref data(stream.copyToData()); @@ -180,4 +178,3 @@ endbfrange\n"; REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2, buffer2.getOffset())); } -#endif // SK_SUPPORT_PDF diff --git a/tests/PDFInvalidBitmapTest.cpp b/tests/PDFInvalidBitmapTest.cpp index 6a547066d5..8a9b1fa132 100644 --- a/tests/PDFInvalidBitmapTest.cpp +++ b/tests/PDFInvalidBitmapTest.cpp @@ -15,8 +15,6 @@ #include "Test.h" -#if SK_SUPPORT_PDF - namespace { // SkPixelRef which fails to lock, as a lazy pixel ref might if its pixels @@ -60,4 +58,3 @@ DEF_TEST(PDFInvalidBitmap, reporter) { // This test passes if it does not crash. } -#endif // SK_SUPPORT_PDF diff --git a/tests/PDFJpegEmbedTest.cpp b/tests/PDFJpegEmbedTest.cpp index 021161bf9f..cfe6776bf5 100644 --- a/tests/PDFJpegEmbedTest.cpp +++ b/tests/PDFJpegEmbedTest.cpp @@ -14,8 +14,6 @@ #include "Resources.h" #include "Test.h" -#if SK_SUPPORT_PDF - // Returned bitmap is lazy. Only lazy bitmaps hold onto the original data. static SkBitmap bitmap_from_data(SkData* data) { SkASSERT(data); @@ -127,4 +125,3 @@ DEF_TEST(JpegIdentification, r) { } } } -#endif // SK_SUPPORT_PDF diff --git a/tests/skpdf_opaquesrcmodetosrcover.cpp b/tests/PDFOpaqueSrcModeToSrcOverTest.cpp similarity index 96% rename from tests/skpdf_opaquesrcmodetosrcover.cpp rename to tests/PDFOpaqueSrcModeToSrcOverTest.cpp index 8c7fc75162..156856c0da 100644 --- a/tests/skpdf_opaquesrcmodetosrcover.cpp +++ b/tests/PDFOpaqueSrcModeToSrcOverTest.cpp @@ -9,8 +9,6 @@ #include "SkStream.h" #include "Test.h" -#if SK_SUPPORT_PDF - static void run_test(SkWStream* out, SkXfermode::Mode mode, U8CPU alpha) { SkAutoTUnref pdfDoc(SkDocument::CreatePDF(out)); SkCanvas* c = pdfDoc->beginPage(612.0f, 792.0f); @@ -28,6 +26,7 @@ static void run_test(SkWStream* out, SkXfermode::Mode mode, U8CPU alpha) { // http://crbug.com/473572 DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r) { + REQUIRE_PDF_DOCUMENT(SkPDF_OpaqueSrcModeToSrcOver, r); SkDynamicMemoryWStream srcMode; SkDynamicMemoryWStream srcOverMode; @@ -46,4 +45,3 @@ DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r) { REPORTER_ASSERT(r, srcMode.getOffset() > srcOverMode.getOffset()); // The two PDFs should not be equal because they have a non-opaque alpha. } -#endif // SK_SUPPORT_PDF diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 22d8d16328..013d58657b 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -22,8 +22,6 @@ #include "SkTypes.h" #include "Test.h" -#if SK_SUPPORT_PDF - #define DUMMY_TEXT "DCT compessed stream." namespace { @@ -415,4 +413,3 @@ DEF_TEST(PDFImageFilter, reporter) { // Filter was used in rendering; should be visited. REPORTER_ASSERT(reporter, filter->visited()); } -#endif // SK_SUPPORT_PDF diff --git a/tests/Test.h b/tests/Test.h index ed5de0f860..c1e0c528fb 100644 --- a/tests/Test.h +++ b/tests/Test.h @@ -102,4 +102,16 @@ typedef SkTRegistry TestRegistry; skiatest::Test(#name, true, test_##name)); \ void test_##name(skiatest::Reporter* reporter, GrContextFactory* factory) +#define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER) \ + do { \ + SkDynamicMemoryWStream testStream; \ + SkAutoTUnref testDoc(SkDocument::CreatePDF(&testStream)); \ + if (!testDoc) { \ + if ((REPORTER) && (REPORTER)->verbose()) { \ + SkDebugf("PDF disabled; %s test skipped.", #TEST_NAME); \ + } \ + return; \ + } \ + } while (false) + #endif -- 2.34.1