blob: 964d0e741dcfb7e23d1422b871ec2c39b89666b3 [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 */
halcanaryf12a1672015-09-23 12:45:49 -07007#include "SkData.h"
Hal Canary23564b92018-09-07 14:33:14 -04008#include "SkPDFDocument.h"
9#include "SkStream.h"
halcanaryf12a1672015-09-23 12:45:49 -070010#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);
Hal Canary23564b92018-09-07 14:33:14 -040016 SkPDF::Metadata metadata;
halcanary4b656662016-04-27 07:45:18 -070017 metadata.fTitle = "A1";
18 metadata.fAuthor = "A2";
19 metadata.fSubject = "A3";
20 metadata.fKeywords = "A4";
21 metadata.fCreator = "A5";
Hal Canary23564b92018-09-07 14:33:14 -040022 metadata.fCreation = now;
23 metadata.fModified = now;
halcanary4b656662016-04-27 07:45:18 -070024
25 SkDynamicMemoryWStream pdf;
Hal Canary3026d4b2019-01-07 10:00:48 -050026 auto doc = SkPDF::MakeDocument(&pdf, metadata);
halcanaryf12a1672015-09-23 12:45:49 -070027 doc->beginPage(612.0f, 792.0f);
28 doc->close();
reed42943c82016-09-12 12:01:44 -070029 sk_sp<SkData> data = pdf.detachAsData();
halcanaryf12a1672015-09-23 12:45:49 -070030 static const char* expectations[] = {
31 "/Title (A1)",
32 "/Author (A2)",
33 "/Subject (A3)",
34 "/Keywords (A4)",
35 "/Creator (A5)",
halcanaryffe54002016-03-29 09:09:29 -070036 "/Producer (Skia/PDF ",
halcanaryf12a1672015-09-23 12:45:49 -070037 "/CreationDate (D:",
38 "/ModDate (D:"
39 };
halcanary4b656662016-04-27 07:45:18 -070040 const uint8_t* bytes = data->bytes();
halcanaryf12a1672015-09-23 12:45:49 -070041 for (const char* expectation : expectations) {
halcanary4b656662016-04-27 07:45:18 -070042 size_t len = strlen(expectation);
halcanaryf12a1672015-09-23 12:45:49 -070043 bool found = false;
halcanary4b656662016-04-27 07:45:18 -070044 size_t N = 1 + data->size() - len;
halcanaryf12a1672015-09-23 12:45:49 -070045 for (size_t i = 0; i < N; ++i) {
halcanary4b656662016-04-27 07:45:18 -070046 if (0 == memcmp(bytes + i, expectation, len)) {
halcanaryf12a1672015-09-23 12:45:49 -070047 found = true;
48 break;
49 }
50 }
51 if (!found) {
52 ERRORF(r, "expectation missing: '%s'.", expectation);
53 }
54 }
55}