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