aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-08-11 13:35:12 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-11 13:35:12 -0700
commit2ccdb636e8618db77be8e05cdacd82c249c6898c (patch)
tree2cf6f3fc1e2dc9cdc15645415a415cf7481244cd
parentfcaaadee711a93d601ccc9f0b47d744e22c35205 (diff)
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
-rw-r--r--gyp/tests.gypi1
-rw-r--r--tests/AnnotationTest.cpp5
-rw-r--r--tests/CanvasTest.cpp9
-rw-r--r--tests/PDFDeflateWStreamTest.cpp (renamed from tests/DeflateWStream.cpp)3
-rw-r--r--tests/PDFDocumentTest.cpp (renamed from tests/DocumentTest.cpp)3
-rw-r--r--tests/PDFFlateTest.cpp (renamed from tests/FlateTest.cpp)3
-rw-r--r--tests/PDFGlyphsToUnicodeTest.cpp (renamed from tests/ToUnicodeTest.cpp)3
-rw-r--r--tests/PDFInvalidBitmapTest.cpp3
-rw-r--r--tests/PDFJpegEmbedTest.cpp3
-rw-r--r--tests/PDFOpaqueSrcModeToSrcOverTest.cpp (renamed from tests/skpdf_opaquesrcmodetosrcover.cpp)4
-rw-r--r--tests/PDFPrimitivesTest.cpp3
-rw-r--r--tests/Test.h12
12 files changed, 23 insertions, 29 deletions
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!': [ '<!@(python find.py ../tests "PDF*.c*")', ],
}],
],
'sources': [
diff --git a/tests/AnnotationTest.cpp b/tests/AnnotationTest.cpp
index a40a5f427b..4f904bdc42 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_NoDraw, reporter) {
}
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_PdfLink, reporter) {
}
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 @@ 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<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 @@ 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
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
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
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
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
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<SkDocument> 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<Test> 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<SkDocument> testDoc(SkDocument::CreatePDF(&testStream)); \
+ if (!testDoc) { \
+ if ((REPORTER) && (REPORTER)->verbose()) { \
+ SkDebugf("PDF disabled; %s test skipped.", #TEST_NAME); \
+ } \
+ return; \
+ } \
+ } while (false)
+
#endif