2015-09-23 19:45:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/docs/SkPDFDocument.h"
|
|
|
|
#include "tests/Test.h"
|
2015-09-23 19:45:49 +00:00
|
|
|
|
2016-04-27 14:45:18 +00:00
|
|
|
DEF_TEST(SkPDF_Metadata, r) {
|
|
|
|
REQUIRE_PDF_DOCUMENT(SkPDF_Metadata, r);
|
2015-09-23 19:45:49 +00:00
|
|
|
SkTime::DateTime now;
|
|
|
|
SkTime::GetDateTime(&now);
|
2018-09-07 18:33:14 +00:00
|
|
|
SkPDF::Metadata metadata;
|
2016-04-27 14:45:18 +00:00
|
|
|
metadata.fTitle = "A1";
|
|
|
|
metadata.fAuthor = "A2";
|
|
|
|
metadata.fSubject = "A3";
|
|
|
|
metadata.fKeywords = "A4";
|
|
|
|
metadata.fCreator = "A5";
|
2018-09-07 18:33:14 +00:00
|
|
|
metadata.fCreation = now;
|
|
|
|
metadata.fModified = now;
|
2016-04-27 14:45:18 +00:00
|
|
|
|
|
|
|
SkDynamicMemoryWStream pdf;
|
2019-01-07 15:00:48 +00:00
|
|
|
auto doc = SkPDF::MakeDocument(&pdf, metadata);
|
2015-09-23 19:45:49 +00:00
|
|
|
doc->beginPage(612.0f, 792.0f);
|
|
|
|
doc->close();
|
2016-09-12 19:01:44 +00:00
|
|
|
sk_sp<SkData> data = pdf.detachAsData();
|
2015-09-23 19:45:49 +00:00
|
|
|
static const char* expectations[] = {
|
|
|
|
"/Title (A1)",
|
|
|
|
"/Author (A2)",
|
|
|
|
"/Subject (A3)",
|
|
|
|
"/Keywords (A4)",
|
|
|
|
"/Creator (A5)",
|
2016-03-29 16:09:29 +00:00
|
|
|
"/Producer (Skia/PDF ",
|
2015-09-23 19:45:49 +00:00
|
|
|
"/CreationDate (D:",
|
|
|
|
"/ModDate (D:"
|
|
|
|
};
|
2016-04-27 14:45:18 +00:00
|
|
|
const uint8_t* bytes = data->bytes();
|
2015-09-23 19:45:49 +00:00
|
|
|
for (const char* expectation : expectations) {
|
2016-04-27 14:45:18 +00:00
|
|
|
size_t len = strlen(expectation);
|
2015-09-23 19:45:49 +00:00
|
|
|
bool found = false;
|
2016-04-27 14:45:18 +00:00
|
|
|
size_t N = 1 + data->size() - len;
|
2015-09-23 19:45:49 +00:00
|
|
|
for (size_t i = 0; i < N; ++i) {
|
2016-04-27 14:45:18 +00:00
|
|
|
if (0 == memcmp(bytes + i, expectation, len)) {
|
2015-09-23 19:45:49 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
ERRORF(r, "expectation missing: '%s'.", expectation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|