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
diff --git a/tests/AnnotationTest.cpp b/tests/AnnotationTest.cpp
index a40a5f4..4f904bd 100644
--- a/tests/AnnotationTest.cpp
+++ b/tests/AnnotationTest.cpp
@@ -12,8 +12,6 @@
 #include "SkStream.h"
 #include "Test.h"
 
-#if SK_SUPPORT_PDF
-
 /** Returns true if data (may contain null characters) contains needle (null
  *  terminated). */
 static bool ContainsString(const char* data, size_t dataSize, const char* needle) {
@@ -42,6 +40,7 @@
 }
 
 DEF_TEST(Annotation_PdfLink, reporter) {
+    REQUIRE_PDF_DOCUMENT(Annotation_PdfLink, reporter);
     SkDynamicMemoryWStream outStream;
     SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
     SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
@@ -60,6 +59,7 @@
 }
 
 DEF_TEST(Annotation_NamedDestination, reporter) {
+    REQUIRE_PDF_DOCUMENT(Annotation_NamedDestination, reporter);
     SkDynamicMemoryWStream outStream;
     SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
     SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
@@ -76,4 +76,3 @@
     REPORTER_ASSERT(reporter,
         ContainsString(rawOutput, out->size(), "/example "));
 }
-#endif  // SK_SUPPORT_PDF
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index 78253ac..0d5c862 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -570,6 +570,12 @@
     SkAutoTUnref<SkDocument> 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 @@
     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 97%
rename from tests/DeflateWStream.cpp
rename to tests/PDFDeflateWStreamTest.cpp
index 930ecb4..b225746 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 @@
         }
     }
 }
-#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 5bd6ba6..f9fcdff 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 @@
 }
 
 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 8387f52..40efe1a 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 @@
     TestFlate(reporter, &fileStream, 512);
     TestFlate(reporter, &fileStream, 10240);
 }
-#endif  // SK_SUPPORT_PDF
diff --git a/tests/ToUnicodeTest.cpp b/tests/PDFGlyphsToUnicodeTest.cpp
similarity index 98%
rename from tests/ToUnicodeTest.cpp
rename to tests/PDFGlyphsToUnicodeTest.cpp
index 4dcb2df..33fcc80 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 @@
     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 6a54706..8a9b1fa 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 @@
 
     // This test passes if it does not crash.
 }
-#endif  // SK_SUPPORT_PDF
diff --git a/tests/PDFJpegEmbedTest.cpp b/tests/PDFJpegEmbedTest.cpp
index 021161b..cfe6776 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 @@
         }
     }
 }
-#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 8c7fc75..156856c 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<SkDocument> pdfDoc(SkDocument::CreatePDF(out));
     SkCanvas* c = pdfDoc->beginPage(612.0f, 792.0f);
@@ -28,6 +26,7 @@
 
 // http://crbug.com/473572
 DEF_TEST(SkPDF_OpaqueSrcModeToSrcOver, r) {
+    REQUIRE_PDF_DOCUMENT(SkPDF_OpaqueSrcModeToSrcOver, r);
     SkDynamicMemoryWStream srcMode;
     SkDynamicMemoryWStream srcOverMode;
 
@@ -46,4 +45,3 @@
     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 22d8d16..013d586 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 @@
     // 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 ed5de0f..c1e0c52 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -102,4 +102,16 @@
             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<SkDocument> testDoc(SkDocument::CreatePDF(&testStream)); \
+        if (!testDoc) {                                                       \
+            if ((REPORTER) && (REPORTER)->verbose()) {                        \
+                SkDebugf("PDF disabled; %s test skipped.", #TEST_NAME);       \
+            }                                                                 \
+            return;                                                           \
+        }                                                                     \
+    } while (false)
+
 #endif