blob: 6a5aca76f73b5301cbcd8d2ff037f25b7b407e7e [file] [log] [blame]
halcanaryf12a1672015-09-23 12:45:49 -07001/*
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
12DEF_TEST(SkPDF_MetadataAttribute, r) {
13 REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r);
14 SkDynamicMemoryWStream pdf;
15 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf));
halcanary2c9c4692016-03-20 07:07:11 -070016 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]);
halcanaryf12a1672015-09-23 12:45:49 -070025 SkTime::DateTime now;
26 SkTime::GetDateTime(&now);
halcanary2c9c4692016-03-20 07:07:11 -070027 doc->setMetadata(&info[0], infoCount, &now, &now);
halcanaryf12a1672015-09-23 12:45:49 -070028 doc->beginPage(612.0f, 792.0f);
29 doc->close();
30 SkAutoTUnref<SkData> data(pdf.copyToData());
31 static const char* expectations[] = {
32 "/Title (A1)",
33 "/Author (A2)",
34 "/Subject (A3)",
35 "/Keywords (A4)",
36 "/Creator (A5)",
halcanaryffe54002016-03-29 09:09:29 -070037 "/Producer (Skia/PDF ",
halcanaryf12a1672015-09-23 12:45:49 -070038 "/CreationDate (D:",
39 "/ModDate (D:"
40 };
41 for (const char* expectation : expectations) {
42 bool found = false;
43 size_t N = 1 + data->size() - strlen(expectation);
44 for (size_t i = 0; i < N; ++i) {
45 if (0 == memcmp(data->bytes() + i,
46 expectation, strlen(expectation))) {
47 found = true;
48 break;
49 }
50 }
51 if (!found) {
52 ERRORF(r, "expectation missing: '%s'.", expectation);
53 }
54 }
55}