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

Side by Side Diff: tests/PDFMetadataAttributeTest.cpp

Issue 1780463008: SkPDF: metadata first (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « site/user/sample/pdf.md ('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
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SkDocument.h" 7 #include "SkDocument.h"
8 #include "SkStream.h" 8 #include "SkStream.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "Test.h" 10 #include "Test.h"
11 11
12 DEF_TEST(SkPDF_MetadataAttribute, r) { 12 DEF_TEST(SkPDF_MetadataAttribute, r) {
13 REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r); 13 REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r);
14 SkDynamicMemoryWStream pdf; 14 SkDynamicMemoryWStream pdf;
15 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf)); 15 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf));
16 SkTArray<SkDocument::Attribute> info; 16 typedef SkDocument::Attribute Attr;
17 info.emplace_back(SkString("Title"), SkString("A1")); 17 Attr info[] = {
18 info.emplace_back(SkString("Author"), SkString("A2")); 18 Attr(SkString("Title"), SkString("A1")),
19 info.emplace_back(SkString("Subject"), SkString("A3")); 19 Attr(SkString("Author"), SkString("A2")),
20 info.emplace_back(SkString("Keywords"), SkString("A4")); 20 Attr(SkString("Subject"), SkString("A3")),
21 info.emplace_back(SkString("Creator"), SkString("A5")); 21 Attr(SkString("Keywords"), SkString("A4")),
22 Attr(SkString("Creator"), SkString("A5")),
23 };
24 int infoCount = sizeof(info) / sizeof(info[0]);
22 SkTime::DateTime now; 25 SkTime::DateTime now;
23 SkTime::GetDateTime(&now); 26 SkTime::GetDateTime(&now);
24 doc->setMetadata(&info[0], info.count(), &now, &now); 27 doc->setMetadata(&info[0], infoCount, &now, &now);
25 doc->beginPage(612.0f, 792.0f); 28 doc->beginPage(612.0f, 792.0f);
26 doc->close(); 29 doc->close();
27 SkAutoTUnref<SkData> data(pdf.copyToData()); 30 SkAutoTUnref<SkData> data(pdf.copyToData());
28 static const char* expectations[] = { 31 static const char* expectations[] = {
29 "/Title (A1)", 32 "/Title (A1)",
30 "/Author (A2)", 33 "/Author (A2)",
31 "/Subject (A3)", 34 "/Subject (A3)",
32 "/Keywords (A4)", 35 "/Keywords (A4)",
33 "/Creator (A5)", 36 "/Creator (A5)",
34 "/Producer (Skia/PDF)", 37 "/Producer (Skia/PDF)",
35 "/CreationDate (D:", 38 "/CreationDate (D:",
36 "/ModDate (D:" 39 "/ModDate (D:"
37 }; 40 };
38 for (const char* expectation : expectations) { 41 for (const char* expectation : expectations) {
39 bool found = false; 42 bool found = false;
40 size_t N = 1 + data->size() - strlen(expectation); 43 size_t N = 1 + data->size() - strlen(expectation);
41 for (size_t i = 0; i < N; ++i) { 44 for (size_t i = 0; i < N; ++i) {
42 if (0 == memcmp(data->bytes() + i, 45 if (0 == memcmp(data->bytes() + i,
43 expectation, strlen(expectation))) { 46 expectation, strlen(expectation))) {
44 found = true; 47 found = true;
45 break; 48 break;
46 } 49 }
47 } 50 }
48 if (!found) { 51 if (!found) {
49 ERRORF(r, "expectation missing: '%s'.", expectation); 52 ERRORF(r, "expectation missing: '%s'.", expectation);
50 } 53 }
51 } 54 }
52 } 55 }
OLDNEW
« no previous file with comments | « site/user/sample/pdf.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698