diff options
author | halcanary <halcanary@google.com> | 2015-03-01 06:55:20 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-01 06:55:20 -0800 |
commit | 3d32d50364d1b63777fbf05c3593a35601bde9e2 (patch) | |
tree | c1624a6fba189f14c9813727e463dccb84cd22c5 | |
parent | 9f2f3493f6185bb7d0c24c8ab451d5d012234edc (diff) |
PDF: Switch some unit tests to higher level API.
Also, clean up some headers.
Review URL: https://codereview.chromium.org/968683002
-rw-r--r-- | src/pdf/SkPDFBitmap.cpp | 1 | ||||
-rw-r--r-- | src/pdf/SkPDFCatalog.h | 2 | ||||
-rw-r--r-- | tests/AnnotationTest.cpp | 35 | ||||
-rw-r--r-- | tests/CanvasTest.cpp | 22 | ||||
-rw-r--r-- | tests/PDFPrimitivesTest.cpp | 28 |
5 files changed, 35 insertions, 53 deletions
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp index 5774360a7c..668f7dede0 100644 --- a/src/pdf/SkPDFBitmap.cpp +++ b/src/pdf/SkPDFBitmap.cpp @@ -10,7 +10,6 @@ #include "SkPDFBitmap.h" #include "SkPDFCanon.h" #include "SkPDFCatalog.h" -#include "SkPDFDocument.h" #include "SkStream.h" #include "SkUnPreMultiply.h" diff --git a/src/pdf/SkPDFCatalog.h b/src/pdf/SkPDFCatalog.h index 9175f6255f..1bdac936d4 100644 --- a/src/pdf/SkPDFCatalog.h +++ b/src/pdf/SkPDFCatalog.h @@ -12,9 +12,7 @@ #include <sys/types.h> -#include "SkPDFDocument.h" #include "SkPDFTypes.h" -#include "SkRefCnt.h" #include "SkTDArray.h" /** \class SkPDFCatalog diff --git a/tests/AnnotationTest.cpp b/tests/AnnotationTest.cpp index fc762b1493..7a1ca97a55 100644 --- a/tests/AnnotationTest.cpp +++ b/tests/AnnotationTest.cpp @@ -8,9 +8,8 @@ #include "SkAnnotation.h" #include "SkCanvas.h" #include "SkData.h" -#include "SkPDFCanon.h" -#include "SkPDFDevice.h" -#include "SkPDFDocument.h" +#include "SkDocument.h" +#include "SkStream.h" #include "Test.h" /** Returns true if data (may contain null characters) contains needle (null @@ -41,20 +40,17 @@ DEF_TEST(Annotation_NoDraw, reporter) { } DEF_TEST(Annotation_PdfLink, reporter) { - SkISize size = SkISize::Make(612, 792); - SkPDFCanon canon; - SkAutoTUnref<SkPDFDevice> device(SkPDFDevice::Create(size, 72.0f, &canon)); - SkCanvas canvas(device.get()); + SkDynamicMemoryWStream outStream; + SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); + SkCanvas* canvas = doc->beginPage(612.0f, 792.0f); + REPORTER_ASSERT(reporter, canvas); SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72), SkIntToScalar(288), SkIntToScalar(72)); SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); - SkAnnotateRectWithURL(&canvas, r, data.get()); + SkAnnotateRectWithURL(canvas, r, data.get()); - SkPDFDocument doc; - doc.appendPage(device.get()); - SkDynamicMemoryWStream outStream; - doc.emitPDF(&outStream); + REPORTER_ASSERT(reporter, doc->close()); SkAutoDataUnref out(outStream.copyToData()); const char* rawOutput = (const char*)out->data(); @@ -62,19 +58,16 @@ DEF_TEST(Annotation_PdfLink, reporter) { } DEF_TEST(Annotation_NamedDestination, reporter) { - SkISize size = SkISize::Make(612, 792); - SkPDFCanon canon; - SkAutoTUnref<SkPDFDevice> device(SkPDFDevice::Create(size, 72.0f, &canon)); - SkCanvas canvas(device.get()); + SkDynamicMemoryWStream outStream; + SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); + SkCanvas* canvas = doc->beginPage(612.0f, 792.0f); + REPORTER_ASSERT(reporter, canvas); SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72)); SkAutoDataUnref data(SkData::NewWithCString("example")); - SkAnnotateNamedDestination(&canvas, p, data.get()); + SkAnnotateNamedDestination(canvas, p, data.get()); - SkPDFDocument doc; - doc.appendPage(device.get()); - SkDynamicMemoryWStream outStream; - doc.emitPDF(&outStream); + REPORTER_ASSERT(reporter, doc->close()); SkAutoDataUnref out(outStream.copyToData()); const char* rawOutput = (const char*)out->data(); diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index c405fcd52c..98cfbc158d 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -47,11 +47,9 @@ #include "SkCanvas.h" #include "SkDeferredCanvas.h" #include "SkDevice.h" +#include "SkDocument.h" #include "SkMatrix.h" #include "SkNWayCanvas.h" -#include "SkPDFCanon.h" -#include "SkPDFDevice.h" -#include "SkPDFDocument.h" #include "SkPaint.h" #include "SkPath.h" #include "SkPicture.h" @@ -558,17 +556,15 @@ static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData static void TestPdfDevice(skiatest::Reporter* reporter, const TestData& d, CanvasTestStep* testStep) { - SkISize pageSize = SkISize::Make(d.fWidth, d.fHeight); - SkPDFCanon canon; - SkAutoTUnref<SkPDFDevice> pdfDevice( - SkPDFDevice::Create(pageSize, 72.0f, &canon)); - SkCanvas canvas(pdfDevice.get()); + SkDynamicMemoryWStream outStream; + SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); + SkCanvas* canvas = doc->beginPage(SkIntToScalar(d.fWidth), + SkIntToScalar(d.fHeight)); + REPORTER_ASSERT(reporter, canvas); testStep->setAssertMessageFormat(kPdfAssertMessageFormat); - testStep->draw(&canvas, d, reporter); - SkPDFDocument doc; - doc.appendPage(pdfDevice.get()); - SkDynamicMemoryWStream stream; - doc.emitPDF(&stream); + testStep->draw(canvas, d, reporter); + + REPORTER_ASSERT(reporter, doc->close()); } // The following class groups static functions that need to access diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 97ad25e09a..7861ef0fe1 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -8,6 +8,7 @@ #include "SkBitmap.h" #include "SkCanvas.h" #include "SkData.h" +#include "SkDocument.h" #include "SkFlate.h" #include "SkImageEncoder.h" #include "SkMatrix.h" @@ -215,21 +216,16 @@ static void TestSubstitute(skiatest::Reporter* reporter) { // SKP files might have invalid glyph ids. This test ensures they are ignored, // and there is no assert on input data in Debug mode. static void test_issue1083() { - SkISize pageSize = SkISize::Make(100, 100); - SkPDFCanon canon; - SkAutoTUnref<SkPDFDevice> dev(SkPDFDevice::Create(pageSize, 72.0f, &canon)); - SkCanvas c(dev); + SkDynamicMemoryWStream outStream; + SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); + SkCanvas* canvas = doc->beginPage(100.0f, 100.0f); SkPaint paint; paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); uint16_t glyphID = 65000; - c.drawText(&glyphID, 2, 0, 0, paint); + canvas->drawText(&glyphID, 2, 0, 0, paint); - SkPDFDocument doc; - doc.appendPage(dev); - - SkDynamicMemoryWStream stream; - doc.emitPDF(&stream); + doc->close(); } DEF_TEST(PDFPrimitives, reporter) { @@ -354,18 +350,18 @@ void DummyImageFilter::toString(SkString* str) const { // Check that PDF rendering of image filters successfully falls back to // CPU rasterization. DEF_TEST(PDFImageFilter, reporter) { - SkISize pageSize = SkISize::Make(100, 100); - SkPDFCanon canon; - SkAutoTUnref<SkPDFDevice> pdfDevice( - SkPDFDevice::Create(pageSize, 72.0f, &canon)); - SkCanvas canvas(pdfDevice.get()); + SkDynamicMemoryWStream stream; + SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream)); + SkCanvas* canvas = doc->beginPage(100.0f, 100.0f); + SkAutoTUnref<DummyImageFilter> filter(new DummyImageFilter()); // Filter just created; should be unvisited. REPORTER_ASSERT(reporter, !filter->visited()); SkPaint paint; paint.setImageFilter(filter.get()); - canvas.drawRect(SkRect::MakeWH(100, 100), paint); + canvas->drawRect(SkRect::MakeWH(100, 100), paint); + doc->close(); // Filter was used in rendering; should be visited. REPORTER_ASSERT(reporter, filter->visited()); |