Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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();
39 sk_sp<SkData> data = pdf.detachAsData();
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
void GetDateTime(SkPDF::DateTime *)
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
-comparison