blob: 01351faec31c600cb527b596032a805182a0d47a [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;
28 sk_sp<SkDocument> doc = SkDocument::MakePDF(&pdf, SK_ScalarDefaultRasterDPI,
29 metadata, nullptr, false);
halcanaryf12a1672015-09-23 12:45:49 -070030 doc->beginPage(612.0f, 792.0f);
31 doc->close();
reed42943c82016-09-12 12:01:44 -070032 sk_sp<SkData> data = pdf.detachAsData();
halcanaryf12a1672015-09-23 12:45:49 -070033 static const char* expectations[] = {
34 "/Title (A1)",
35 "/Author (A2)",
36 "/Subject (A3)",
37 "/Keywords (A4)",
38 "/Creator (A5)",
halcanaryffe54002016-03-29 09:09:29 -070039 "/Producer (Skia/PDF ",
halcanaryf12a1672015-09-23 12:45:49 -070040 "/CreationDate (D:",
41 "/ModDate (D:"
42 };
halcanary4b656662016-04-27 07:45:18 -070043 const uint8_t* bytes = data->bytes();
halcanaryf12a1672015-09-23 12:45:49 -070044 for (const char* expectation : expectations) {
halcanary4b656662016-04-27 07:45:18 -070045 size_t len = strlen(expectation);
halcanaryf12a1672015-09-23 12:45:49 -070046 bool found = false;
halcanary4b656662016-04-27 07:45:18 -070047 size_t N = 1 + data->size() - len;
halcanaryf12a1672015-09-23 12:45:49 -070048 for (size_t i = 0; i < N; ++i) {
halcanary4b656662016-04-27 07:45:18 -070049 if (0 == memcmp(bytes + i, expectation, len)) {
halcanaryf12a1672015-09-23 12:45:49 -070050 found = true;
51 break;
52 }
53 }
54 if (!found) {
55 ERRORF(r, "expectation missing: '%s'.", expectation);
56 }
57 }
58}