OLD | NEW |
(Empty) | |
| 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_MetadataAttribute, r) { |
| 13 REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r); |
| 14 SkDynamicMemoryWStream pdf; |
| 15 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf)); |
| 16 SkTArray<SkDocument::Attribute> info; |
| 17 info.emplace_back(SkString("Title"), SkString("A1")); |
| 18 info.emplace_back(SkString("Author"), SkString("A2")); |
| 19 info.emplace_back(SkString("Subject"), SkString("A3")); |
| 20 info.emplace_back(SkString("Keywords"), SkString("A4")); |
| 21 info.emplace_back(SkString("Creator"), SkString("A5")); |
| 22 SkTime::DateTime now; |
| 23 SkTime::GetDateTime(&now); |
| 24 doc->setMetadata(info, &now, &now); |
| 25 doc->beginPage(612.0f, 792.0f); |
| 26 doc->close(); |
| 27 SkAutoTUnref<SkData> data(pdf.copyToData()); |
| 28 static const char* expectations[] = { |
| 29 "/Title (A1)", |
| 30 "/Author (A2)", |
| 31 "/Subject (A3)", |
| 32 "/Keywords (A4)", |
| 33 "/Creator (A5)", |
| 34 "/Producer (Skia/PDF)", |
| 35 "/CreationDate (D:", |
| 36 "/ModDate (D:" |
| 37 }; |
| 38 for (const char* expectation : expectations) { |
| 39 bool found = false; |
| 40 size_t N = 1 + data->size() - strlen(expectation); |
| 41 for (size_t i = 0; i < N; ++i) { |
| 42 if (0 == memcmp(data->bytes() + i, |
| 43 expectation, strlen(expectation))) { |
| 44 found = true; |
| 45 break; |
| 46 } |
| 47 } |
| 48 if (!found) { |
| 49 ERRORF(r, "expectation missing: '%s'.", expectation); |
| 50 } |
| 51 } |
| 52 } |
OLD | NEW |