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

Side by Side Diff: tests/PDFMetadataAttributeTest.cpp

Issue 1916093002: SkDocument/PDF: new API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-04-26 (Tuesday) 15:55:33 EDT Created 4 years, 7 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 | « tests/PDFJpegEmbedTest.cpp ('k') | tests/PDFOpaqueSrcModeToSrcOverTest.cpp » ('j') | 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_Metadata, r) {
13 REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r); 13 REQUIRE_PDF_DOCUMENT(SkPDF_Metadata, r);
14 SkDynamicMemoryWStream pdf;
15 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf));
16 typedef SkDocument::Attribute Attr;
17 Attr info[] = {
18 Attr(SkString("Title"), SkString("A1")),
19 Attr(SkString("Author"), SkString("A2")),
20 Attr(SkString("Subject"), SkString("A3")),
21 Attr(SkString("Keywords"), SkString("A4")),
22 Attr(SkString("Creator"), SkString("A5")),
23 };
24 int infoCount = sizeof(info) / sizeof(info[0]);
25 SkTime::DateTime now; 14 SkTime::DateTime now;
26 SkTime::GetDateTime(&now); 15 SkTime::GetDateTime(&now);
27 doc->setMetadata(&info[0], infoCount, &now, &now); 16 SkDocument::PDFMetadata metadata;
17 metadata.fTitle = "A1";
18 metadata.fAuthor = "A2";
19 metadata.fSubject = "A3";
20 metadata.fKeywords = "A4";
21 metadata.fCreator = "A5";
22 metadata.fCreation.fEnabled = true;
23 metadata.fCreation.fDateTime = now;
24 metadata.fModified.fEnabled = true;
25 metadata.fModified.fDateTime = now;
26
27 SkDynamicMemoryWStream pdf;
28 sk_sp<SkDocument> doc = SkDocument::MakePDF(&pdf, SK_ScalarDefaultRasterDPI,
29 metadata, nullptr, false);
28 doc->beginPage(612.0f, 792.0f); 30 doc->beginPage(612.0f, 792.0f);
29 doc->close(); 31 doc->close();
30 SkAutoTUnref<SkData> data(pdf.copyToData()); 32 SkAutoTUnref<SkData> data(pdf.copyToData());
31 static const char* expectations[] = { 33 static const char* expectations[] = {
32 "/Title (A1)", 34 "/Title (A1)",
33 "/Author (A2)", 35 "/Author (A2)",
34 "/Subject (A3)", 36 "/Subject (A3)",
35 "/Keywords (A4)", 37 "/Keywords (A4)",
36 "/Creator (A5)", 38 "/Creator (A5)",
37 "/Producer (Skia/PDF ", 39 "/Producer (Skia/PDF ",
38 "/CreationDate (D:", 40 "/CreationDate (D:",
39 "/ModDate (D:" 41 "/ModDate (D:"
40 }; 42 };
43 const uint8_t* bytes = data->bytes();
41 for (const char* expectation : expectations) { 44 for (const char* expectation : expectations) {
45 size_t len = strlen(expectation);
42 bool found = false; 46 bool found = false;
43 size_t N = 1 + data->size() - strlen(expectation); 47 size_t N = 1 + data->size() - len;
44 for (size_t i = 0; i < N; ++i) { 48 for (size_t i = 0; i < N; ++i) {
45 if (0 == memcmp(data->bytes() + i, 49 if (0 == memcmp(bytes + i, expectation, len)) {
46 expectation, strlen(expectation))) {
47 found = true; 50 found = true;
48 break; 51 break;
49 } 52 }
50 } 53 }
51 if (!found) { 54 if (!found) {
52 ERRORF(r, "expectation missing: '%s'.", expectation); 55 ERRORF(r, "expectation missing: '%s'.", expectation);
53 } 56 }
54 } 57 }
55 } 58 }
OLDNEW
« no previous file with comments | « tests/PDFJpegEmbedTest.cpp ('k') | tests/PDFOpaqueSrcModeToSrcOverTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698