aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PDFDocumentTest.cpp
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-09-09 11:41:59 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-09 11:41:59 -0700
commit57f744e3030fec4d1a2b3e9119011904b149a4da (patch)
tree62e2dbe5a2550e0fccfcf085663ada6a8a3d8756 /tests/PDFDocumentTest.cpp
parent8d914908d8ad37a73c39ba8f7ef298bfee457388 (diff)
SkPDF/Tests: imporve test coverage.
Also: make sure that all SkPDF unit tests are named SkPDF_* to make testing changes to SkPDF easier. Other cleanup. Add test: SkPDF_pdfa_document to verify that flag in public API works. SkPDF_JpegIdentification test: test slightly malformed JPEGs to verify that all code paths work. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2322133003 Review-Url: https://codereview.chromium.org/2322133003
Diffstat (limited to 'tests/PDFDocumentTest.cpp')
-rw-r--r--tests/PDFDocumentTest.cpp70
1 files changed, 65 insertions, 5 deletions
diff --git a/tests/PDFDocumentTest.cpp b/tests/PDFDocumentTest.cpp
index b763742b06..c871375117 100644
--- a/tests/PDFDocumentTest.cpp
+++ b/tests/PDFDocumentTest.cpp
@@ -105,7 +105,7 @@ static void test_close(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, stream.bytesWritten() != 0);
}
-DEF_TEST(document_tests, reporter) {
+DEF_TEST(SkPDF_document_tests, reporter) {
REQUIRE_PDF_DOCUMENT(document_tests, reporter);
test_empty(reporter);
test_abort(reporter);
@@ -147,8 +147,8 @@ size_t count_bytes(const SkBitmap& bm, bool useDCT) {
return stream.bytesWritten();
}
-DEF_TEST(document_dct_encoder, r) {
- REQUIRE_PDF_DOCUMENT(document_dct_encoder, r);
+DEF_TEST(SkPDF_document_dct_encoder, r) {
+ REQUIRE_PDF_DOCUMENT(SkPDF_document_dct_encoder, r);
SkBitmap bm;
if (GetResourceAsBitmap("mandrill_64.png", &bm)) {
// Lossy encoding works better on photographs.
@@ -156,8 +156,8 @@ DEF_TEST(document_dct_encoder, r) {
}
}
-DEF_TEST(document_skbug_4734, r) {
- REQUIRE_PDF_DOCUMENT(document_skbug_4734, r);
+DEF_TEST(SkPDF_document_skbug_4734, r) {
+ REQUIRE_PDF_DOCUMENT(SkPDF_document_skbug_4734, r);
SkDynamicMemoryWStream stream;
sk_sp<SkDocument> doc(SkDocument::MakePDF(&stream));
SkCanvas* canvas = doc->beginPage(64, 64);
@@ -167,3 +167,63 @@ DEF_TEST(document_skbug_4734, r) {
const char text[] = "HELLO";
canvas->drawText(text, strlen(text), 0, 0, SkPaint());
}
+
+static bool contains(const uint8_t* result, size_t size, const char expectation[]) {
+ size_t len = strlen(expectation);
+ size_t N = 1 + size - len;
+ for (size_t i = 0; i < N; ++i) {
+ if (0 == memcmp(result + i, expectation, len)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+// verify that the PDFA flag does something.
+DEF_TEST(SkPDF_pdfa_document, r) {
+ REQUIRE_PDF_DOCUMENT(SkPDF_pdfa_document, r);
+
+ SkDocument::PDFMetadata pdfMetadata;
+ pdfMetadata.fTitle = "test document";
+ pdfMetadata.fCreation.fEnabled = true;
+ pdfMetadata.fCreation.fDateTime = {0, 1999, 12, 5, 31, 23, 59, 59};
+
+ SkDynamicMemoryWStream buffer;
+ auto doc = SkDocument::MakePDF(&buffer, SK_ScalarDefaultRasterDPI,
+ pdfMetadata, nullptr, /* pdfa = */ true);
+ doc->beginPage(64, 64)->drawColor(SK_ColorRED);
+ doc->close();
+ sk_sp<SkData> data(buffer.copyToData());
+ buffer.reset();
+ static const char* expectations[] = {
+ "sRGB IEC61966-2.1",
+ "<dc:title><rdf:Alt><rdf:li xml:lang=\"x-default\">test document",
+ "<xmp:CreateDate>1999-12-31T23:59:59+00:00</xmp:CreateDate>",
+ "/Subtype /XML",
+ "/CreationDate (D:19991231235959+00'00')>>",
+ };
+ for (const char* expectation : expectations) {
+ if (!contains(data->bytes(), data->size(), expectation)) {
+ ERRORF(r, "PDFA expectation missing: '%s'.", expectation);
+ }
+ }
+ pdfMetadata.fProducer = "phoney library";
+ doc = SkDocument::MakePDF(&buffer, SK_ScalarDefaultRasterDPI,
+ pdfMetadata, nullptr, /* pdfa = */ true);
+ doc->beginPage(64, 64)->drawColor(SK_ColorRED);
+ doc->close();
+ data.reset(buffer.copyToData());
+ buffer.reset();
+
+ static const char* moreExpectations[] = {
+ "/Producer (phoney library)",
+ "/ProductionLibrary (Skia/PDF m",
+ "<!-- <skia:ProductionLibrary>Skia/PDF m",
+ "<pdf:Producer>phoney library</pdf:Producer>",
+ };
+ for (const char* expectation : moreExpectations) {
+ if (!contains(data->bytes(), data->size(), expectation)) {
+ ERRORF(r, "PDFA expectation missing: '%s'.", expectation);
+ }
+ }
+}