blob: bdfd7d6190177bf1df3893ced767084f62dd71e1 [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
halcanary4b656662016-04-27 07:45:18 -070012DEF_TEST(SkPDF_Metadata, r) {
13 REQUIRE_PDF_DOCUMENT(SkPDF_Metadata, r);
halcanaryf12a1672015-09-23 12:45:49 -070014 SkTime::DateTime now;
15 SkTime::GetDateTime(&now);
halcanary4b656662016-04-27 07:45:18 -070016 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;
Mike Reeda4daf192017-12-14 13:25:04 -050028 sk_sp<SkDocument> doc = SkDocument::MakePDF(&pdf, metadata);
halcanaryf12a1672015-09-23 12:45:49 -070029 doc->beginPage(612.0f, 792.0f);
30 doc->close();
reed42943c82016-09-12 12:01:44 -070031 sk_sp<SkData> data = pdf.detachAsData();
halcanaryf12a1672015-09-23 12:45:49 -070032 static const char* expectations[] = {
33 "/Title (A1)",
34 "/Author (A2)",
35 "/Subject (A3)",
36 "/Keywords (A4)",
37 "/Creator (A5)",
halcanaryffe54002016-03-29 09:09:29 -070038 "/Producer (Skia/PDF ",
halcanaryf12a1672015-09-23 12:45:49 -070039 "/CreationDate (D:",
40 "/ModDate (D:"
41 };
halcanary4b656662016-04-27 07:45:18 -070042 const uint8_t* bytes = data->bytes();
halcanaryf12a1672015-09-23 12:45:49 -070043 for (const char* expectation : expectations) {
halcanary4b656662016-04-27 07:45:18 -070044 size_t len = strlen(expectation);
halcanaryf12a1672015-09-23 12:45:49 -070045 bool found = false;
halcanary4b656662016-04-27 07:45:18 -070046 size_t N = 1 + data->size() - len;
halcanaryf12a1672015-09-23 12:45:49 -070047 for (size_t i = 0; i < N; ++i) {
halcanary4b656662016-04-27 07:45:18 -070048 if (0 == memcmp(bytes + i, expectation, len)) {
halcanaryf12a1672015-09-23 12:45:49 -070049 found = true;
50 break;
51 }
52 }
53 if (!found) {
54 ERRORF(r, "expectation missing: '%s'.", expectation);
55 }
56 }
57}