Flutter Engine
The Flutter Engine
PDFMetadataAttributeTest.cpp
Go to the documentation of this file.
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 */
8
9#ifdef SK_SUPPORT_PDF
10#include "include/core/SkData.h"
16#include "src/pdf/SkPDFUtils.h"
17#include "tests/Test.h"
18
19#include <cstdint>
20#include <cstring>
21
22DEF_TEST(SkPDF_Metadata, r) {
23 REQUIRE_PDF_DOCUMENT(SkPDF_Metadata, r);
26 SkPDF::Metadata metadata;
27 metadata.fTitle = "A1";
28 metadata.fAuthor = "A2";
29 metadata.fSubject = "A3";
30 metadata.fKeywords = "A4";
31 metadata.fCreator = "A5";
32 metadata.fCreation = now;
33 metadata.fModified = now;
34
36 auto doc = SkPDF::MakeDocument(&pdf, metadata);
37 doc->beginPage(612.0f, 792.0f);
38 doc->close();
40 static const char* expectations[] = {
41 "/Title (A1)",
42 "/Author (A2)",
43 "/Subject (A3)",
44 "/Keywords (A4)",
45 "/Creator (A5)",
46 "/Producer (Skia/PDF ",
47 "/CreationDate (D:",
48 "/ModDate (D:"
49 };
50 const uint8_t* bytes = data->bytes();
51 for (const char* expectation : expectations) {
52 size_t len = strlen(expectation);
53 bool found = false;
54 size_t N = 1 + data->size() - len;
55 for (size_t i = 0; i < N; ++i) {
56 if (0 == memcmp(bytes + i, expectation, len)) {
57 found = true;
58 break;
59 }
60 }
61 if (!found) {
62 ERRORF(r, "expectation missing: '%s'.", expectation);
63 }
64 }
65}
66#endif
#define DEF_TEST(name, reporter)
Definition: Test.h:312
#define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER)
Definition: Test.h:485
#define ERRORF(r,...)
Definition: Test.h:293
#define N
Definition: beziers.cpp:19
sk_sp< SkData > detachAsData()
Definition: SkStream.cpp:707
void GetDateTime(SkPDF::DateTime *)
Definition: SkPDFUtils.cpp:431
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
SkString fSubject
Definition: SkPDFDocument.h:96
SkString fAuthor
Definition: SkPDFDocument.h:92
SkString fKeywords
DateTime fCreation
DateTime fModified
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63