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