• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "SkData.h"
8 #include "SkPDFDocument.h"
9 #include "SkStream.h"
10 #include "Test.h"
11 
DEF_TEST(SkPDF_Metadata,r)12 DEF_TEST(SkPDF_Metadata, r) {
13     REQUIRE_PDF_DOCUMENT(SkPDF_Metadata, r);
14     SkTime::DateTime now;
15     SkTime::GetDateTime(&now);
16     SkPDF::Metadata metadata;
17     metadata.fTitle = "A1";
18     metadata.fAuthor = "A2";
19     metadata.fSubject = "A3";
20     metadata.fKeywords = "A4";
21     metadata.fCreator = "A5";
22     metadata.fCreation = now;
23     metadata.fModified = now;
24 
25     SkDynamicMemoryWStream pdf;
26     auto doc = SkPDF::MakeDocument(&pdf, metadata);
27     doc->beginPage(612.0f, 792.0f);
28     doc->close();
29     sk_sp<SkData> data = pdf.detachAsData();
30     static const char* expectations[] = {
31         "/Title (A1)",
32         "/Author (A2)",
33         "/Subject (A3)",
34         "/Keywords (A4)",
35         "/Creator (A5)",
36         "/Producer (Skia/PDF ",
37         "/CreationDate (D:",
38         "/ModDate (D:"
39     };
40     const uint8_t* bytes = data->bytes();
41     for (const char* expectation : expectations) {
42         size_t len = strlen(expectation);
43         bool found = false;
44         size_t N = 1 + data->size() - len;
45         for (size_t i = 0; i < N; ++i) {
46             if (0 == memcmp(bytes + i, expectation, len)) {
47                 found = true;
48                 break;
49             }
50         }
51         if (!found) {
52             ERRORF(r, "expectation missing: '%s'.", expectation);
53         }
54     }
55 }
56