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

Side by Side Diff: tests/PDFDocumentTest.cpp

Issue 2322133003: SkPDF/Tests: imporve test coverage. (Closed)
Patch Set: toms nit Created 4 years, 3 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 | « tests/PDFDeflateWStreamTest.cpp ('k') | tests/PDFGlyphsToUnicodeTest.cpp » ('j') | 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 2013 Google Inc. 2 * Copyright 2013 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 "Test.h" 7 #include "Test.h"
8 8
9 #include "Resources.h" 9 #include "Resources.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 SkCanvas* canvas = doc->beginPage(100, 100); 99 SkCanvas* canvas = doc->beginPage(100, 100);
100 canvas->drawColor(SK_ColorRED); 100 canvas->drawColor(SK_ColorRED);
101 doc->endPage(); 101 doc->endPage();
102 102
103 doc->close(); 103 doc->close();
104 104
105 REPORTER_ASSERT(reporter, stream.bytesWritten() != 0); 105 REPORTER_ASSERT(reporter, stream.bytesWritten() != 0);
106 } 106 }
107 107
108 DEF_TEST(document_tests, reporter) { 108 DEF_TEST(SkPDF_document_tests, reporter) {
109 REQUIRE_PDF_DOCUMENT(document_tests, reporter); 109 REQUIRE_PDF_DOCUMENT(document_tests, reporter);
110 test_empty(reporter); 110 test_empty(reporter);
111 test_abort(reporter); 111 test_abort(reporter);
112 test_abortWithFile(reporter); 112 test_abortWithFile(reporter);
113 test_file(reporter); 113 test_file(reporter);
114 test_close(reporter); 114 test_close(reporter);
115 } 115 }
116 116
117 namespace { 117 namespace {
118 class JPEGSerializer final : public SkPixelSerializer { 118 class JPEGSerializer final : public SkPixelSerializer {
(...skipping 21 matching lines...) Expand all
140 } else { 140 } else {
141 doc = SkDocument::MakePDF(&stream); 141 doc = SkDocument::MakePDF(&stream);
142 } 142 }
143 SkCanvas* canvas = doc->beginPage(64, 64); 143 SkCanvas* canvas = doc->beginPage(64, 64);
144 canvas->drawBitmap(bm, 0, 0); 144 canvas->drawBitmap(bm, 0, 0);
145 doc->endPage(); 145 doc->endPage();
146 doc->close(); 146 doc->close();
147 return stream.bytesWritten(); 147 return stream.bytesWritten();
148 } 148 }
149 149
150 DEF_TEST(document_dct_encoder, r) { 150 DEF_TEST(SkPDF_document_dct_encoder, r) {
151 REQUIRE_PDF_DOCUMENT(document_dct_encoder, r); 151 REQUIRE_PDF_DOCUMENT(SkPDF_document_dct_encoder, r);
152 SkBitmap bm; 152 SkBitmap bm;
153 if (GetResourceAsBitmap("mandrill_64.png", &bm)) { 153 if (GetResourceAsBitmap("mandrill_64.png", &bm)) {
154 // Lossy encoding works better on photographs. 154 // Lossy encoding works better on photographs.
155 REPORTER_ASSERT(r, count_bytes(bm, true) < count_bytes(bm, false)); 155 REPORTER_ASSERT(r, count_bytes(bm, true) < count_bytes(bm, false));
156 } 156 }
157 } 157 }
158 158
159 DEF_TEST(document_skbug_4734, r) { 159 DEF_TEST(SkPDF_document_skbug_4734, r) {
160 REQUIRE_PDF_DOCUMENT(document_skbug_4734, r); 160 REQUIRE_PDF_DOCUMENT(SkPDF_document_skbug_4734, r);
161 SkDynamicMemoryWStream stream; 161 SkDynamicMemoryWStream stream;
162 sk_sp<SkDocument> doc(SkDocument::MakePDF(&stream)); 162 sk_sp<SkDocument> doc(SkDocument::MakePDF(&stream));
163 SkCanvas* canvas = doc->beginPage(64, 64); 163 SkCanvas* canvas = doc->beginPage(64, 64);
164 canvas->scale(10000.0f, 10000.0f); 164 canvas->scale(10000.0f, 10000.0f);
165 canvas->translate(20.0f, 10.0f); 165 canvas->translate(20.0f, 10.0f);
166 canvas->rotate(30.0f); 166 canvas->rotate(30.0f);
167 const char text[] = "HELLO"; 167 const char text[] = "HELLO";
168 canvas->drawText(text, strlen(text), 0, 0, SkPaint()); 168 canvas->drawText(text, strlen(text), 0, 0, SkPaint());
169 } 169 }
170
171 static bool contains(const uint8_t* result, size_t size, const char expectation[ ]) {
172 size_t len = strlen(expectation);
173 size_t N = 1 + size - len;
174 for (size_t i = 0; i < N; ++i) {
175 if (0 == memcmp(result + i, expectation, len)) {
176 return true;
177 }
178 }
179 return false;
180 }
181
182 // verify that the PDFA flag does something.
183 DEF_TEST(SkPDF_pdfa_document, r) {
184 REQUIRE_PDF_DOCUMENT(SkPDF_pdfa_document, r);
185
186 SkDocument::PDFMetadata pdfMetadata;
187 pdfMetadata.fTitle = "test document";
188 pdfMetadata.fCreation.fEnabled = true;
189 pdfMetadata.fCreation.fDateTime = {0, 1999, 12, 5, 31, 23, 59, 59};
190
191 SkDynamicMemoryWStream buffer;
192 auto doc = SkDocument::MakePDF(&buffer, SK_ScalarDefaultRasterDPI,
193 pdfMetadata, nullptr, /* pdfa = */ true);
194 doc->beginPage(64, 64)->drawColor(SK_ColorRED);
195 doc->close();
196 sk_sp<SkData> data(buffer.copyToData());
197 buffer.reset();
198 static const char* expectations[] = {
199 "sRGB IEC61966-2.1",
200 "<dc:title><rdf:Alt><rdf:li xml:lang=\"x-default\">test document",
201 "<xmp:CreateDate>1999-12-31T23:59:59+00:00</xmp:CreateDate>",
202 "/Subtype /XML",
203 "/CreationDate (D:19991231235959+00'00')>>",
204 };
205 for (const char* expectation : expectations) {
206 if (!contains(data->bytes(), data->size(), expectation)) {
207 ERRORF(r, "PDFA expectation missing: '%s'.", expectation);
208 }
209 }
210 pdfMetadata.fProducer = "phoney library";
211 doc = SkDocument::MakePDF(&buffer, SK_ScalarDefaultRasterDPI,
212 pdfMetadata, nullptr, /* pdfa = */ true);
213 doc->beginPage(64, 64)->drawColor(SK_ColorRED);
214 doc->close();
215 data.reset(buffer.copyToData());
216 buffer.reset();
217
218 static const char* moreExpectations[] = {
219 "/Producer (phoney library)",
220 "/ProductionLibrary (Skia/PDF m",
221 "<!-- <skia:ProductionLibrary>Skia/PDF m",
222 "<pdf:Producer>phoney library</pdf:Producer>",
223 };
224 for (const char* expectation : moreExpectations) {
225 if (!contains(data->bytes(), data->size(), expectation)) {
226 ERRORF(r, "PDFA expectation missing: '%s'.", expectation);
227 }
228 }
229 }
OLDNEW
« no previous file with comments | « tests/PDFDeflateWStreamTest.cpp ('k') | tests/PDFGlyphsToUnicodeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698