Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: tests/PDFMetadataAttributeTest.cpp

Issue 1359943003: SkPDF: add basic metadata support (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: style change Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/doc/SkDocument_PDF.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PDFMetadataAttributeTest.cpp
diff --git a/tests/PDFMetadataAttributeTest.cpp b/tests/PDFMetadataAttributeTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e58146ba2b6967ac3626750786083e9e1166252b
--- /dev/null
+++ b/tests/PDFMetadataAttributeTest.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkDocument.h"
+#include "SkStream.h"
+#include "SkData.h"
+#include "Test.h"
+
+DEF_TEST(SkPDF_MetadataAttribute, r) {
+ REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r);
+ SkDynamicMemoryWStream pdf;
+ SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf));
+ SkTArray<SkDocument::Attribute> info;
+ info.emplace_back(SkString("Title"), SkString("A1"));
+ info.emplace_back(SkString("Author"), SkString("A2"));
+ info.emplace_back(SkString("Subject"), SkString("A3"));
+ info.emplace_back(SkString("Keywords"), SkString("A4"));
+ info.emplace_back(SkString("Creator"), SkString("A5"));
+ SkTime::DateTime now;
+ SkTime::GetDateTime(&now);
+ doc->setMetadata(info, &now, &now);
+ doc->beginPage(612.0f, 792.0f);
+ doc->close();
+ SkAutoTUnref<SkData> data(pdf.copyToData());
+ static const char* expectations[] = {
+ "/Title (A1)",
+ "/Author (A2)",
+ "/Subject (A3)",
+ "/Keywords (A4)",
+ "/Creator (A5)",
+ "/Producer (Skia/PDF)",
+ "/CreationDate (D:",
+ "/ModDate (D:"
+ };
+ for (const char* expectation : expectations) {
+ bool found = false;
+ size_t N = 1 + data->size() - strlen(expectation);
+ for (size_t i = 0; i < N; ++i) {
+ if (0 == memcmp(data->bytes() + i,
+ expectation, strlen(expectation))) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ ERRORF(r, "expectation missing: '%s'.", expectation);
+ }
+ }
+}
« no previous file with comments | « src/doc/SkDocument_PDF.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698