Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: tests/PDFMetadataAttributeTest.cpp

Issue 1689683002: SkDocument: remove use of SkTArray (part 1/3). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: size_t -> int Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/doc/SkDocument_PDF.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SkDocument.h" 7 #include "SkDocument.h"
8 #include "SkStream.h" 8 #include "SkStream.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "Test.h" 10 #include "Test.h"
11 11
12 DEF_TEST(SkPDF_MetadataAttribute, r) { 12 DEF_TEST(SkPDF_MetadataAttribute, r) {
13 REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r); 13 REQUIRE_PDF_DOCUMENT(SkPDF_MetadataAttribute, r);
14 SkDynamicMemoryWStream pdf; 14 SkDynamicMemoryWStream pdf;
15 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf)); 15 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&pdf));
16 SkTArray<SkDocument::Attribute> info; 16 SkTArray<SkDocument::Attribute> info;
17 info.emplace_back(SkString("Title"), SkString("A1")); 17 info.emplace_back(SkString("Title"), SkString("A1"));
18 info.emplace_back(SkString("Author"), SkString("A2")); 18 info.emplace_back(SkString("Author"), SkString("A2"));
19 info.emplace_back(SkString("Subject"), SkString("A3")); 19 info.emplace_back(SkString("Subject"), SkString("A3"));
20 info.emplace_back(SkString("Keywords"), SkString("A4")); 20 info.emplace_back(SkString("Keywords"), SkString("A4"));
21 info.emplace_back(SkString("Creator"), SkString("A5")); 21 info.emplace_back(SkString("Creator"), SkString("A5"));
22 SkTime::DateTime now; 22 SkTime::DateTime now;
23 SkTime::GetDateTime(&now); 23 SkTime::GetDateTime(&now);
24 doc->setMetadata(info, &now, &now); 24 doc->setMetadata(&info[0], info.count(), &now, &now);
25 doc->beginPage(612.0f, 792.0f); 25 doc->beginPage(612.0f, 792.0f);
26 doc->close(); 26 doc->close();
27 SkAutoTUnref<SkData> data(pdf.copyToData()); 27 SkAutoTUnref<SkData> data(pdf.copyToData());
28 static const char* expectations[] = { 28 static const char* expectations[] = {
29 "/Title (A1)", 29 "/Title (A1)",
30 "/Author (A2)", 30 "/Author (A2)",
31 "/Subject (A3)", 31 "/Subject (A3)",
32 "/Keywords (A4)", 32 "/Keywords (A4)",
33 "/Creator (A5)", 33 "/Creator (A5)",
34 "/Producer (Skia/PDF)", 34 "/Producer (Skia/PDF)",
35 "/CreationDate (D:", 35 "/CreationDate (D:",
36 "/ModDate (D:" 36 "/ModDate (D:"
37 }; 37 };
38 for (const char* expectation : expectations) { 38 for (const char* expectation : expectations) {
39 bool found = false; 39 bool found = false;
40 size_t N = 1 + data->size() - strlen(expectation); 40 size_t N = 1 + data->size() - strlen(expectation);
41 for (size_t i = 0; i < N; ++i) { 41 for (size_t i = 0; i < N; ++i) {
42 if (0 == memcmp(data->bytes() + i, 42 if (0 == memcmp(data->bytes() + i,
43 expectation, strlen(expectation))) { 43 expectation, strlen(expectation))) {
44 found = true; 44 found = true;
45 break; 45 break;
46 } 46 }
47 } 47 }
48 if (!found) { 48 if (!found) {
49 ERRORF(r, "expectation missing: '%s'.", expectation); 49 ERRORF(r, "expectation missing: '%s'.", expectation);
50 } 50 }
51 } 51 }
52 } 52 }
OLDNEW
« no previous file with comments | « src/doc/SkDocument_PDF.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698