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

Side by Side 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, 2 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 unified diff | Download patch
« no previous file with comments | « src/doc/SkDocument_PDF.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SkDocument.h"
8 #include "SkStream.h"
9 #include "SkData.h"
10 #include "Test.h"
11
12 DEF_TEST(SkPDF_MetadataAttribute, r) {
13 REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r);
14 SkDynamicMemoryWStream pdf;
15 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf));
16 SkTArray<SkDocument::Attribute> info;
17 info.emplace_back(SkString("Title"), SkString("A1"));
18 info.emplace_back(SkString("Author"), SkString("A2"));
19 info.emplace_back(SkString("Subject"), SkString("A3"));
20 info.emplace_back(SkString("Keywords"), SkString("A4"));
21 info.emplace_back(SkString("Creator"), SkString("A5"));
22 SkTime::DateTime now;
23 SkTime::GetDateTime(&now);
24 doc->setMetadata(info, &now, &now);
25 doc->beginPage(612.0f, 792.0f);
26 doc->close();
27 SkAutoTUnref<SkData> data(pdf.copyToData());
28 static const char* expectations[] = {
29 "/Title (A1)",
30 "/Author (A2)",
31 "/Subject (A3)",
32 "/Keywords (A4)",
33 "/Creator (A5)",
34 "/Producer (Skia/PDF)",
35 "/CreationDate (D:",
36 "/ModDate (D:"
37 };
38 for (const char* expectation : expectations) {
39 bool found = false;
40 size_t N = 1 + data->size() - strlen(expectation);
41 for (size_t i = 0; i < N; ++i) {
42 if (0 == memcmp(data->bytes() + i,
43 expectation, strlen(expectation))) {
44 found = true;
45 break;
46 }
47 }
48 if (!found) {
49 ERRORF(r, "expectation missing: '%s'.", expectation);
50 }
51 }
52 }
OLDNEW
« 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