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

Side by Side Diff: tests/PDFPrimitivesTest.cpp

Issue 1775043002: SkPDF: Add sk_sp setters; .release() becomes std::move() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix -Wpessimizing-move Created 4 years, 9 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/pdf/SkPDFUtils.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 2010 The Android Open Source Project 2 * Copyright 2010 The Android Open Source Project
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 7
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 SkString result = emit_to_string(OBJECT); \ 76 SkString result = emit_to_string(OBJECT); \
77 ASSERT_EQ(REPORTER, result, STRING); \ 77 ASSERT_EQ(REPORTER, result, STRING); \
78 } while (false) 78 } while (false)
79 79
80 80
81 81
82 static void TestPDFStream(skiatest::Reporter* reporter) { 82 static void TestPDFStream(skiatest::Reporter* reporter) {
83 char streamBytes[] = "Test\nFoo\tBar"; 83 char streamBytes[] = "Test\nFoo\tBar";
84 SkAutoTDelete<SkMemoryStream> streamData(new SkMemoryStream( 84 SkAutoTDelete<SkMemoryStream> streamData(new SkMemoryStream(
85 streamBytes, strlen(streamBytes), true)); 85 streamBytes, strlen(streamBytes), true));
86 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get())); 86 sk_sp<SkPDFStream> stream(new SkPDFStream(streamData.get()));
87 ASSERT_EMIT_EQ(reporter, 87 ASSERT_EMIT_EQ(reporter,
88 *stream, 88 *stream,
89 "<</Length 12>> stream\nTest\nFoo\tBar\nendstream"); 89 "<</Length 12>> stream\nTest\nFoo\tBar\nendstream");
90 stream->insertInt("Attribute", 42); 90 stream->insertInt("Attribute", 42);
91 ASSERT_EMIT_EQ(reporter, 91 ASSERT_EMIT_EQ(reporter,
92 *stream, 92 *stream,
93 "<</Length 12\n/Attribute 42>> stream\n" 93 "<</Length 12\n/Attribute 42>> stream\n"
94 "Test\nFoo\tBar\nendstream"); 94 "Test\nFoo\tBar\nendstream");
95 95
96 { 96 {
97 char streamBytes2[] = "This is a longer string, so that compression " 97 char streamBytes2[] = "This is a longer string, so that compression "
98 "can do something with it. With shorter strings, " 98 "can do something with it. With shorter strings, "
99 "the short circuit logic cuts in and we end up " 99 "the short circuit logic cuts in and we end up "
100 "with an uncompressed string."; 100 "with an uncompressed string.";
101 SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2, 101 SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2,
102 strlen(streamBytes2))); 102 strlen(streamBytes2)));
103 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get())); 103 sk_sp<SkPDFStream> stream(new SkPDFStream(streamData2.get()));
104 104
105 SkDynamicMemoryWStream compressedByteStream; 105 SkDynamicMemoryWStream compressedByteStream;
106 SkDeflateWStream deflateWStream(&compressedByteStream); 106 SkDeflateWStream deflateWStream(&compressedByteStream);
107 deflateWStream.write(streamBytes2, strlen(streamBytes2)); 107 deflateWStream.write(streamBytes2, strlen(streamBytes2));
108 deflateWStream.finalize(); 108 deflateWStream.finalize();
109 109
110 SkDynamicMemoryWStream expected; 110 SkDynamicMemoryWStream expected;
111 expected.writeText("<</Filter /FlateDecode\n/Length 116>> stream\n"); 111 expected.writeText("<</Filter /FlateDecode\n/Length 116>> stream\n");
112 compressedByteStream.writeToStream(&expected); 112 compressedByteStream.writeToStream(&expected);
113 compressedByteStream.reset(); 113 compressedByteStream.reset();
114 expected.writeText("\nendstream"); 114 expected.writeText("\nendstream");
115 SkAutoDataUnref expectedResultData2(expected.copyToData()); 115 SkAutoDataUnref expectedResultData2(expected.copyToData());
116 SkString result = emit_to_string(*stream); 116 SkString result = emit_to_string(*stream);
117 ASSERT_EQL(reporter, 117 ASSERT_EQL(reporter,
118 result, 118 result,
119 (const char*)expectedResultData2->data(), 119 (const char*)expectedResultData2->data(),
120 expectedResultData2->size()); 120 expectedResultData2->size());
121 } 121 }
122 } 122 }
123 123
124 static void TestObjectNumberMap(skiatest::Reporter* reporter) { 124 static void TestObjectNumberMap(skiatest::Reporter* reporter) {
125 SkPDFObjNumMap objNumMap; 125 SkPDFObjNumMap objNumMap;
126 SkAutoTUnref<SkPDFArray> a1(new SkPDFArray); 126 sk_sp<SkPDFArray> a1(new SkPDFArray);
127 SkAutoTUnref<SkPDFArray> a2(new SkPDFArray); 127 sk_sp<SkPDFArray> a2(new SkPDFArray);
128 SkAutoTUnref<SkPDFArray> a3(new SkPDFArray); 128 sk_sp<SkPDFArray> a3(new SkPDFArray);
129 129
130 objNumMap.addObject(a1.get()); 130 objNumMap.addObject(a1.get());
131 objNumMap.addObject(a2.get()); 131 objNumMap.addObject(a2.get());
132 objNumMap.addObject(a3.get()); 132 objNumMap.addObject(a3.get());
133 133
134 // The objects should be numbered in the order they are added, 134 // The objects should be numbered in the order they are added,
135 // starting with 1. 135 // starting with 1.
136 REPORTER_ASSERT(reporter, objNumMap.getObjectNumber(a1.get()) == 1); 136 REPORTER_ASSERT(reporter, objNumMap.getObjectNumber(a1.get()) == 1);
137 REPORTER_ASSERT(reporter, objNumMap.getObjectNumber(a2.get()) == 2); 137 REPORTER_ASSERT(reporter, objNumMap.getObjectNumber(a2.get()) == 2);
138 REPORTER_ASSERT(reporter, objNumMap.getObjectNumber(a3.get()) == 3); 138 REPORTER_ASSERT(reporter, objNumMap.getObjectNumber(a3.get()) == 3);
139 // Assert that repeated calls to get the object number return 139 // Assert that repeated calls to get the object number return
140 // consistent result. 140 // consistent result.
141 REPORTER_ASSERT(reporter, objNumMap.getObjectNumber(a1.get()) == 1); 141 REPORTER_ASSERT(reporter, objNumMap.getObjectNumber(a1.get()) == 1);
142 } 142 }
143 143
144 static void TestObjectRef(skiatest::Reporter* reporter) { 144 static void TestObjectRef(skiatest::Reporter* reporter) {
145 SkAutoTUnref<SkPDFArray> a1(new SkPDFArray); 145 sk_sp<SkPDFArray> a1(new SkPDFArray);
146 SkAutoTUnref<SkPDFArray> a2(new SkPDFArray); 146 sk_sp<SkPDFArray> a2(new SkPDFArray);
147 a2->appendObjRef(SkRef(a1.get())); 147 a2->appendObjRef(a1);
148 148
149 Catalog catalog; 149 Catalog catalog;
150 catalog.numbers.addObject(a1.get()); 150 catalog.numbers.addObject(a1.get());
151 REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber(a1.get()) == 1); 151 REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber(a1.get()) == 1);
152 152
153 SkString result = emit_to_string(*a2, &catalog); 153 SkString result = emit_to_string(*a2, &catalog);
154 // If appendObjRef misbehaves, then the result would 154 // If appendObjRef misbehaves, then the result would
155 // be [[]], not [1 0 R]. 155 // be [[]], not [1 0 R].
156 ASSERT_EQ(reporter, result, "[1 0 R]"); 156 ASSERT_EQ(reporter, result, "[1 0 R]");
157 } 157 }
158 158
159 static void TestSubstitute(skiatest::Reporter* reporter) { 159 static void TestSubstitute(skiatest::Reporter* reporter) {
160 SkAutoTUnref<SkPDFDict> proxy(new SkPDFDict()); 160 sk_sp<SkPDFDict> proxy(new SkPDFDict());
161 SkAutoTUnref<SkPDFDict> stub(new SkPDFDict()); 161 sk_sp<SkPDFDict> stub(new SkPDFDict());
162 162
163 proxy->insertInt("Value", 33); 163 proxy->insertInt("Value", 33);
164 stub->insertInt("Value", 44); 164 stub->insertInt("Value", 44);
165 165
166 SkPDFSubstituteMap substituteMap; 166 SkPDFSubstituteMap substituteMap;
167 substituteMap.setSubstitute(proxy.get(), stub.get()); 167 substituteMap.setSubstitute(proxy.get(), stub.get());
168 SkPDFObjNumMap catalog; 168 SkPDFObjNumMap catalog;
169 catalog.addObject(proxy.get()); 169 catalog.addObject(proxy.get());
170 170
171 REPORTER_ASSERT(reporter, stub.get() == substituteMap.getSubstitute(proxy)); 171 REPORTER_ASSERT(reporter, stub.get() == substituteMap.getSubstitute(proxy.ge t()));
172 REPORTER_ASSERT(reporter, proxy.get() != substituteMap.getSubstitute(stub)); 172 REPORTER_ASSERT(reporter, proxy.get() != substituteMap.getSubstitute(stub.ge t()));
173 } 173 }
174 174
175 // This test used to assert without the fix submitted for 175 // This test used to assert without the fix submitted for
176 // http://code.google.com/p/skia/issues/detail?id=1083. 176 // http://code.google.com/p/skia/issues/detail?id=1083.
177 // SKP files might have invalid glyph ids. This test ensures they are ignored, 177 // SKP files might have invalid glyph ids. This test ensures they are ignored,
178 // and there is no assert on input data in Debug mode. 178 // and there is no assert on input data in Debug mode.
179 static void test_issue1083() { 179 static void test_issue1083() {
180 SkDynamicMemoryWStream outStream; 180 SkDynamicMemoryWStream outStream;
181 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); 181 sk_sp<SkDocument> doc(SkDocument::CreatePDF(&outStream));
182 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f); 182 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
183 SkPaint paint; 183 SkPaint paint;
184 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 184 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
185 185
186 uint16_t glyphID = 65000; 186 uint16_t glyphID = 65000;
187 canvas->drawText(&glyphID, 2, 0, 0, paint); 187 canvas->drawText(&glyphID, 2, 0, 0, paint);
188 188
189 doc->close(); 189 doc->close();
190 } 190 }
191 191
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 SkPDFUnion name3 = SkPDFUnion::Name("SimpleNameWithOnlyPrintableASCII"); 231 SkPDFUnion name3 = SkPDFUnion::Name("SimpleNameWithOnlyPrintableASCII");
232 ASSERT_EMIT_EQ(reporter, name3, "/SimpleNameWithOnlyPrintableASCII"); 232 ASSERT_EMIT_EQ(reporter, name3, "/SimpleNameWithOnlyPrintableASCII");
233 233
234 // Test that we correctly handle characters with the high-bit set. 234 // Test that we correctly handle characters with the high-bit set.
235 SkString highBitString("\xDE\xAD" "be\xEF"); 235 SkString highBitString("\xDE\xAD" "be\xEF");
236 SkPDFUnion highBitName = SkPDFUnion::Name(highBitString); 236 SkPDFUnion highBitName = SkPDFUnion::Name(highBitString);
237 ASSERT_EMIT_EQ(reporter, highBitName, "/#DE#ADbe#EF"); 237 ASSERT_EMIT_EQ(reporter, highBitName, "/#DE#ADbe#EF");
238 } 238 }
239 239
240 static void TestPDFArray(skiatest::Reporter* reporter) { 240 static void TestPDFArray(skiatest::Reporter* reporter) {
241 SkAutoTUnref<SkPDFArray> array(new SkPDFArray); 241 sk_sp<SkPDFArray> array(new SkPDFArray);
242 ASSERT_EMIT_EQ(reporter, *array, "[]"); 242 ASSERT_EMIT_EQ(reporter, *array, "[]");
243 243
244 array->appendInt(42); 244 array->appendInt(42);
245 ASSERT_EMIT_EQ(reporter, *array, "[42]"); 245 ASSERT_EMIT_EQ(reporter, *array, "[42]");
246 246
247 array->appendScalar(SK_ScalarHalf); 247 array->appendScalar(SK_ScalarHalf);
248 ASSERT_EMIT_EQ(reporter, *array, "[42 .5]"); 248 ASSERT_EMIT_EQ(reporter, *array, "[42 .5]");
249 249
250 array->appendInt(0); 250 array->appendInt(0);
251 ASSERT_EMIT_EQ(reporter, *array, "[42 .5 0]"); 251 ASSERT_EMIT_EQ(reporter, *array, "[42 .5 0]");
252 252
253 array->appendBool(true); 253 array->appendBool(true);
254 ASSERT_EMIT_EQ(reporter, *array, "[42 .5 0 true]"); 254 ASSERT_EMIT_EQ(reporter, *array, "[42 .5 0 true]");
255 255
256 array->appendName("ThisName"); 256 array->appendName("ThisName");
257 ASSERT_EMIT_EQ(reporter, *array, "[42 .5 0 true /ThisName]"); 257 ASSERT_EMIT_EQ(reporter, *array, "[42 .5 0 true /ThisName]");
258 258
259 array->appendName(SkString("AnotherName")); 259 array->appendName(SkString("AnotherName"));
260 ASSERT_EMIT_EQ(reporter, *array, "[42 .5 0 true /ThisName /AnotherName]"); 260 ASSERT_EMIT_EQ(reporter, *array, "[42 .5 0 true /ThisName /AnotherName]");
261 261
262 array->appendString("This String"); 262 array->appendString("This String");
263 ASSERT_EMIT_EQ(reporter, *array, 263 ASSERT_EMIT_EQ(reporter, *array,
264 "[42 .5 0 true /ThisName /AnotherName (This String)]"); 264 "[42 .5 0 true /ThisName /AnotherName (This String)]");
265 265
266 array->appendString(SkString("Another String")); 266 array->appendString(SkString("Another String"));
267 ASSERT_EMIT_EQ(reporter, *array, 267 ASSERT_EMIT_EQ(reporter, *array,
268 "[42 .5 0 true /ThisName /AnotherName (This String) " 268 "[42 .5 0 true /ThisName /AnotherName (This String) "
269 "(Another String)]"); 269 "(Another String)]");
270 270
271 SkAutoTUnref<SkPDFArray> innerArray(new SkPDFArray); 271 sk_sp<SkPDFArray> innerArray(new SkPDFArray);
272 innerArray->appendInt(-1); 272 innerArray->appendInt(-1);
273 array->appendObject(innerArray.detach()); 273 array->appendObject(std::move(innerArray));
274 ASSERT_EMIT_EQ(reporter, *array, 274 ASSERT_EMIT_EQ(reporter, *array,
275 "[42 .5 0 true /ThisName /AnotherName (This String) " 275 "[42 .5 0 true /ThisName /AnotherName (This String) "
276 "(Another String) [-1]]"); 276 "(Another String) [-1]]");
277 277
278 SkAutoTUnref<SkPDFArray> referencedArray(new SkPDFArray); 278 sk_sp<SkPDFArray> referencedArray(new SkPDFArray);
279 Catalog catalog; 279 Catalog catalog;
280 catalog.numbers.addObject(referencedArray.get()); 280 catalog.numbers.addObject(referencedArray.get());
281 REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber( 281 REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber(
282 referencedArray.get()) == 1); 282 referencedArray.get()) == 1);
283 array->appendObjRef(referencedArray.detach()); 283 array->appendObjRef(std::move(referencedArray));
284 284
285 SkString result = emit_to_string(*array, &catalog); 285 SkString result = emit_to_string(*array, &catalog);
286 ASSERT_EQ(reporter, result, 286 ASSERT_EQ(reporter, result,
287 "[42 .5 0 true /ThisName /AnotherName (This String) " 287 "[42 .5 0 true /ThisName /AnotherName (This String) "
288 "(Another String) [-1] 1 0 R]"); 288 "(Another String) [-1] 1 0 R]");
289 } 289 }
290 290
291 static void TestPDFDict(skiatest::Reporter* reporter) { 291 static void TestPDFDict(skiatest::Reporter* reporter) {
292 SkAutoTUnref<SkPDFDict> dict(new SkPDFDict); 292 sk_sp<SkPDFDict> dict(new SkPDFDict);
293 ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); 293 ASSERT_EMIT_EQ(reporter, *dict, "<<>>");
294 294
295 dict->insertInt("n1", SkToSizeT(42)); 295 dict->insertInt("n1", SkToSizeT(42));
296 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42>>"); 296 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42>>");
297 297
298 dict.reset(new SkPDFDict); 298 dict.reset(new SkPDFDict);
299 ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); 299 ASSERT_EMIT_EQ(reporter, *dict, "<<>>");
300 300
301 dict->insertInt("n1", 42); 301 dict->insertInt("n1", 42);
302 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42>>"); 302 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42>>");
303 303
304 dict->insertScalar("n2", SK_ScalarHalf); 304 dict->insertScalar("n2", SK_ScalarHalf);
305 305
306 SkString n3("n3"); 306 SkString n3("n3");
307 SkAutoTUnref<SkPDFArray> innerArray(new SkPDFArray); 307 sk_sp<SkPDFArray> innerArray(new SkPDFArray);
308 innerArray->appendInt(-100); 308 innerArray->appendInt(-100);
309 dict->insertObject(n3, innerArray.detach()); 309 dict->insertObject(n3, std::move(innerArray));
310 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42\n/n2 .5\n/n3 [-100]>>"); 310 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42\n/n2 .5\n/n3 [-100]>>");
311 311
312 dict.reset(new SkPDFDict); 312 dict.reset(new SkPDFDict);
313 ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); 313 ASSERT_EMIT_EQ(reporter, *dict, "<<>>");
314 314
315 dict->insertInt("n1", 24); 315 dict->insertInt("n1", 24);
316 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24>>"); 316 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24>>");
317 317
318 dict->insertInt("n2", SkToSizeT(99)); 318 dict->insertInt("n2", SkToSizeT(99));
319 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99>>"); 319 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99>>");
(...skipping 12 matching lines...) Expand all
332 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n" 332 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n"
333 "/n5 /AnotherName\n/n6 (A String)>>"); 333 "/n5 /AnotherName\n/n6 (A String)>>");
334 334
335 dict->insertString("n7", SkString("Another String")); 335 dict->insertString("n7", SkString("Another String"));
336 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n" 336 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n"
337 "/n5 /AnotherName\n/n6 (A String)\n/n7 (Another String)>>"); 337 "/n5 /AnotherName\n/n6 (A String)\n/n7 (Another String)>>");
338 338
339 dict.reset(new SkPDFDict("DType")); 339 dict.reset(new SkPDFDict("DType"));
340 ASSERT_EMIT_EQ(reporter, *dict, "<</Type /DType>>"); 340 ASSERT_EMIT_EQ(reporter, *dict, "<</Type /DType>>");
341 341
342 SkAutoTUnref<SkPDFArray> referencedArray(new SkPDFArray); 342 sk_sp<SkPDFArray> referencedArray(new SkPDFArray);
343 Catalog catalog; 343 Catalog catalog;
344 catalog.numbers.addObject(referencedArray.get()); 344 catalog.numbers.addObject(referencedArray.get());
345 REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber( 345 REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber(
346 referencedArray.get()) == 1); 346 referencedArray.get()) == 1);
347 dict->insertObjRef("n1", referencedArray.detach()); 347 dict->insertObjRef("n1", std::move(referencedArray));
348 SkString result = emit_to_string(*dict, &catalog); 348 SkString result = emit_to_string(*dict, &catalog);
349 ASSERT_EQ(reporter, result, "<</Type /DType\n/n1 1 0 R>>"); 349 ASSERT_EQ(reporter, result, "<</Type /DType\n/n1 1 0 R>>");
350 } 350 }
351 351
352 DEF_TEST(PDFPrimitives, reporter) { 352 DEF_TEST(PDFPrimitives, reporter) {
353 TestPDFUnion(reporter); 353 TestPDFUnion(reporter);
354 TestPDFArray(reporter); 354 TestPDFArray(reporter);
355 TestPDFDict(reporter); 355 TestPDFDict(reporter);
356 TestPDFStream(reporter); 356 TestPDFStream(reporter);
357 TestObjectNumberMap(reporter); 357 TestObjectNumberMap(reporter);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 str->append(")"); 393 str->append(")");
394 } 394 }
395 #endif 395 #endif
396 396
397 }; 397 };
398 398
399 // Check that PDF rendering of image filters successfully falls back to 399 // Check that PDF rendering of image filters successfully falls back to
400 // CPU rasterization. 400 // CPU rasterization.
401 DEF_TEST(PDFImageFilter, reporter) { 401 DEF_TEST(PDFImageFilter, reporter) {
402 SkDynamicMemoryWStream stream; 402 SkDynamicMemoryWStream stream;
403 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream)); 403 sk_sp<SkDocument> doc(SkDocument::CreatePDF(&stream));
404 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f); 404 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f);
405 405
406 SkAutoTUnref<DummyImageFilter> filter(new DummyImageFilter()); 406 sk_sp<DummyImageFilter> filter(new DummyImageFilter());
407 407
408 // Filter just created; should be unvisited. 408 // Filter just created; should be unvisited.
409 REPORTER_ASSERT(reporter, !filter->visited()); 409 REPORTER_ASSERT(reporter, !filter->visited());
410 SkPaint paint; 410 SkPaint paint;
411 paint.setImageFilter(filter.get()); 411 paint.setImageFilter(filter.get());
412 canvas->drawRect(SkRect::MakeWH(100, 100), paint); 412 canvas->drawRect(SkRect::MakeWH(100, 100), paint);
413 doc->close(); 413 doc->close();
414 414
415 // Filter was used in rendering; should be visited. 415 // Filter was used in rendering; should be visited.
416 REPORTER_ASSERT(reporter, filter->visited()); 416 REPORTER_ASSERT(reporter, filter->visited());
417 } 417 }
418 418
419 // Check that PDF rendering of image filters successfully falls back to 419 // Check that PDF rendering of image filters successfully falls back to
420 // CPU rasterization. 420 // CPU rasterization.
421 DEF_TEST(PDFFontCanEmbedTypeface, reporter) { 421 DEF_TEST(PDFFontCanEmbedTypeface, reporter) {
422 SkPDFCanon canon; 422 SkPDFCanon canon;
423 423
424 const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf"; 424 const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf";
425 SkAutoTUnref<SkTypeface> noEmbedTypeface(GetResourceAsTypeface(resource)); 425 sk_sp<SkTypeface> noEmbedTypeface(GetResourceAsTypeface(resource));
426 if (noEmbedTypeface) { 426 if (noEmbedTypeface) {
427 REPORTER_ASSERT(reporter, 427 REPORTER_ASSERT(reporter,
428 !SkPDFFont::CanEmbedTypeface(noEmbedTypeface, &canon)); 428 !SkPDFFont::CanEmbedTypeface(noEmbedTypeface.get(), &can on));
429 } 429 }
430 SkAutoTUnref<SkTypeface> portableTypeface( 430 sk_sp<SkTypeface> portableTypeface(
431 sk_tool_utils::create_portable_typeface(NULL, SkTypeface::kNormal)); 431 sk_tool_utils::create_portable_typeface(NULL, SkTypeface::kNormal));
432 REPORTER_ASSERT(reporter, 432 REPORTER_ASSERT(reporter,
433 SkPDFFont::CanEmbedTypeface(portableTypeface, &canon)); 433 SkPDFFont::CanEmbedTypeface(portableTypeface.get(), &canon)) ;
434 } 434 }
435 435
436 436
437 // test to see that all finite scalars round trip via scanf(). 437 // test to see that all finite scalars round trip via scanf().
438 static void check_pdf_scalar_serialization( 438 static void check_pdf_scalar_serialization(
439 skiatest::Reporter* reporter, float inputFloat) { 439 skiatest::Reporter* reporter, float inputFloat) {
440 char floatString[SkPDFUtils::kMaximumFloatDecimalLength]; 440 char floatString[SkPDFUtils::kMaximumFloatDecimalLength];
441 size_t len = SkPDFUtils::FloatToDecimal(inputFloat, floatString); 441 size_t len = SkPDFUtils::FloatToDecimal(inputFloat, floatString);
442 if (len >= sizeof(floatString)) { 442 if (len >= sizeof(floatString)) {
443 ERRORF(reporter, "string too long: %u", (unsigned)len); 443 ERRORF(reporter, "string too long: %u", (unsigned)len);
(...skipping 30 matching lines...) Expand all
474 float alwaysCheck[] = { 474 float alwaysCheck[] = {
475 0.0f, -0.0f, 1.0f, -1.0f, SK_ScalarPI, 0.1f, FLT_MIN, FLT_MAX, 475 0.0f, -0.0f, 1.0f, -1.0f, SK_ScalarPI, 0.1f, FLT_MIN, FLT_MAX,
476 -FLT_MIN, -FLT_MAX, FLT_MIN / 16.0f, -FLT_MIN / 16.0f, 476 -FLT_MIN, -FLT_MAX, FLT_MIN / 16.0f, -FLT_MIN / 16.0f,
477 SK_FloatNaN, SK_FloatInfinity, SK_FloatNegativeInfinity, 477 SK_FloatNaN, SK_FloatInfinity, SK_FloatNegativeInfinity,
478 -FLT_MIN / 8388608.0 478 -FLT_MIN / 8388608.0
479 }; 479 };
480 for (float inputFloat: alwaysCheck) { 480 for (float inputFloat: alwaysCheck) {
481 check_pdf_scalar_serialization(reporter, inputFloat); 481 check_pdf_scalar_serialization(reporter, inputFloat);
482 } 482 }
483 } 483 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFUtils.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698