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

Side by Side Diff: tests/PDFPrimitivesTest.cpp

Issue 936403002: PDF: why do we have flags no one uses (or can use)? (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 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 | « tests/AnnotationTest.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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 static size_t get_output_size(SkPDFObject* object, 68 static size_t get_output_size(SkPDFObject* object,
69 SkPDFCatalog* catalog, 69 SkPDFCatalog* catalog,
70 bool indirect) { 70 bool indirect) {
71 SkDynamicMemoryWStream buffer; 71 SkDynamicMemoryWStream buffer;
72 emit_object(object, &buffer, catalog, indirect); 72 emit_object(object, &buffer, catalog, indirect);
73 return buffer.getOffset(); 73 return buffer.getOffset();
74 } 74 }
75 75
76 static void CheckObjectOutput(skiatest::Reporter* reporter, SkPDFObject* obj, 76 static void CheckObjectOutput(skiatest::Reporter* reporter, SkPDFObject* obj,
77 const char* expectedData, size_t expectedSize, 77 const char* expectedData, size_t expectedSize,
78 bool indirect, bool compression) { 78 bool indirect) {
79 SkPDFDocument::Flags docFlags = (SkPDFDocument::Flags) 0; 79 SkPDFCatalog catalog;
80 if (!compression) {
81 docFlags = SkTBitOr(docFlags, SkPDFDocument::kFavorSpeedOverSize_Flags);
82 }
83 SkPDFCatalog catalog(docFlags);
84 size_t directSize = get_output_size(obj, &catalog, false); 80 size_t directSize = get_output_size(obj, &catalog, false);
85 REPORTER_ASSERT(reporter, directSize == expectedSize); 81 REPORTER_ASSERT(reporter, directSize == expectedSize);
86 82
87 SkDynamicMemoryWStream buffer; 83 SkDynamicMemoryWStream buffer;
88 emit_object(obj, &buffer, &catalog, false); 84 emit_object(obj, &buffer, &catalog, false);
89 REPORTER_ASSERT(reporter, directSize == buffer.getOffset()); 85 REPORTER_ASSERT(reporter, directSize == buffer.getOffset());
90 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedData, 86 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedData,
91 directSize)); 87 directSize));
92 88
93 if (indirect) { 89 if (indirect) {
(...skipping 17 matching lines...) Expand all
111 directSize)); 107 directSize));
112 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen + directSize, 108 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen + directSize,
113 footer, footerLen)); 109 footer, footerLen));
114 } 110 }
115 } 111 }
116 112
117 static void SimpleCheckObjectOutput(skiatest::Reporter* reporter, 113 static void SimpleCheckObjectOutput(skiatest::Reporter* reporter,
118 SkPDFObject* obj, 114 SkPDFObject* obj,
119 const char* expectedResult) { 115 const char* expectedResult) {
120 CheckObjectOutput(reporter, obj, expectedResult, 116 CheckObjectOutput(reporter, obj, expectedResult,
121 strlen(expectedResult), true, false); 117 strlen(expectedResult), true);
122 } 118 }
123 119
124 static void TestPDFStream(skiatest::Reporter* reporter) { 120 static void TestPDFStream(skiatest::Reporter* reporter) {
125 char streamBytes[] = "Test\nFoo\tBar"; 121 char streamBytes[] = "Test\nFoo\tBar";
126 SkAutoTDelete<SkMemoryStream> streamData(new SkMemoryStream( 122 SkAutoTDelete<SkMemoryStream> streamData(new SkMemoryStream(
127 streamBytes, strlen(streamBytes), true)); 123 streamBytes, strlen(streamBytes), true));
128 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get())); 124 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get()));
129 SimpleCheckObjectOutput( 125 SimpleCheckObjectOutput(
130 reporter, stream.get(), 126 reporter, stream.get(),
131 "<</Length 12\n>> stream\nTest\nFoo\tBar\nendstream"); 127 "<</Length 12\n>> stream\nTest\nFoo\tBar\nendstream");
132 stream->insert("Attribute", new SkPDFInt(42))->unref(); 128 stream->insert("Attribute", new SkPDFInt(42))->unref();
133 SimpleCheckObjectOutput(reporter, stream.get(), 129 SimpleCheckObjectOutput(reporter, stream.get(),
134 "<</Length 12\n/Attribute 42\n>> stream\n" 130 "<</Length 12\n/Attribute 42\n>> stream\n"
135 "Test\nFoo\tBar\nendstream"); 131 "Test\nFoo\tBar\nendstream");
136 132
137 #ifndef SK_NO_FLATE 133 #ifndef SK_NO_FLATE
138 { 134 {
139 char streamBytes2[] = "This is a longer string, so that compression " 135 char streamBytes2[] = "This is a longer string, so that compression "
140 "can do something with it. With shorter strings, " 136 "can do something with it. With shorter strings, "
141 "the short circuit logic cuts in and we end up " 137 "the short circuit logic cuts in and we end up "
142 "with an uncompressed string."; 138 "with an uncompressed string.";
143 SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2, 139 SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2,
144 strlen(streamBytes2))); 140 strlen(streamBytes2)));
145 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get())); 141 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get()));
146 142
147 SkDynamicMemoryWStream compressedByteStream; 143 SkDynamicMemoryWStream compressedByteStream;
148 SkFlate::Deflate(streamData2.get(), &compressedByteStream); 144 SkFlate::Deflate(streamData2.get(), &compressedByteStream);
149 SkAutoDataUnref compressedData(compressedByteStream.copyToData()); 145 SkAutoDataUnref compressedData(compressedByteStream.copyToData());
150 146
151 // Check first without compression. 147 SkDynamicMemoryWStream expected;
152 SkDynamicMemoryWStream expectedResult1; 148 expected.writeText("<</Filter /FlateDecode\n/Length 116\n"
153 expectedResult1.writeText("<</Length 167\n>> stream\n");
154 expectedResult1.writeText(streamBytes2);
155 expectedResult1.writeText("\nendstream");
156 SkAutoDataUnref expectedResultData1(expectedResult1.copyToData());
157 CheckObjectOutput(reporter, stream.get(),
158 (const char*) expectedResultData1->data(),
159 expectedResultData1->size(), true, false);
160
161 // Then again with compression.
162 SkDynamicMemoryWStream expectedResult2;
163 expectedResult2.writeText("<</Filter /FlateDecode\n/Length 116\n"
164 ">> stream\n"); 149 ">> stream\n");
165 expectedResult2.write(compressedData->data(), compressedData->size()); 150 expected.write(compressedData->data(), compressedData->size());
166 expectedResult2.writeText("\nendstream"); 151 expected.writeText("\nendstream");
167 SkAutoDataUnref expectedResultData2(expectedResult2.copyToData()); 152 SkAutoDataUnref expectedResultData2(expected.copyToData());
168 CheckObjectOutput(reporter, stream.get(), 153 CheckObjectOutput(reporter, stream.get(),
169 (const char*) expectedResultData2->data(), 154 (const char*) expectedResultData2->data(),
170 expectedResultData2->size(), true, true); 155 expectedResultData2->size(), true);
171 } 156 }
172 #endif // SK_NO_FLATE 157 #endif // SK_NO_FLATE
173 } 158 }
174 159
175 static void TestCatalog(skiatest::Reporter* reporter) { 160 static void TestCatalog(skiatest::Reporter* reporter) {
176 SkPDFCatalog catalog((SkPDFDocument::Flags)0); 161 SkPDFCatalog catalog;
177 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); 162 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
178 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); 163 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2));
179 SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3)); 164 SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3));
180 int1.get()->ref(); 165 int1.get()->ref();
181 SkAutoTUnref<SkPDFInt> int1Again(int1.get()); 166 SkAutoTUnref<SkPDFInt> int1Again(int1.get());
182 167
183 catalog.addObject(int1.get(), false); 168 catalog.addObject(int1.get(), false);
184 catalog.addObject(int2.get(), false); 169 catalog.addObject(int2.get(), false);
185 catalog.addObject(int3.get(), false); 170 catalog.addObject(int3.get(), false);
186 171
187 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); 172 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1);
188 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); 173 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2);
189 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int3.get()) == 3); 174 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int3.get()) == 3);
190 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1Again.get()) == 1); 175 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1Again.get()) == 1);
191 } 176 }
192 177
193 static void TestObjectRef(skiatest::Reporter* reporter) { 178 static void TestObjectRef(skiatest::Reporter* reporter) {
194 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); 179 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
195 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); 180 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2));
196 SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get())); 181 SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get()));
197 182
198 SkPDFCatalog catalog((SkPDFDocument::Flags)0); 183 SkPDFCatalog catalog;
199 catalog.addObject(int1.get(), false); 184 catalog.addObject(int1.get(), false);
200 catalog.addObject(int2.get(), false); 185 catalog.addObject(int2.get(), false);
201 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); 186 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1);
202 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); 187 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2);
203 188
204 char expectedResult[] = "2 0 R"; 189 char expectedResult[] = "2 0 R";
205 SkDynamicMemoryWStream buffer; 190 SkDynamicMemoryWStream buffer;
206 int2ref->emitObject(&buffer, &catalog); 191 int2ref->emitObject(&buffer, &catalog);
207 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); 192 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult));
208 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, 193 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
209 buffer.getOffset())); 194 buffer.getOffset()));
210 } 195 }
211 196
212 static void TestSubstitute(skiatest::Reporter* reporter) { 197 static void TestSubstitute(skiatest::Reporter* reporter) {
213 SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict()); 198 SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict());
214 SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict()); 199 SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict());
215 200
216 proxy->insert("Value", new SkPDFInt(33))->unref(); 201 proxy->insert("Value", new SkPDFInt(33))->unref();
217 stub->insert("Value", new SkPDFInt(44))->unref(); 202 stub->insert("Value", new SkPDFInt(44))->unref();
218 203
219 SkPDFCatalog catalog((SkPDFDocument::Flags)0); 204 SkPDFCatalog catalog;
220 catalog.addObject(proxy.get(), false); 205 catalog.addObject(proxy.get(), false);
221 catalog.setSubstitute(proxy.get(), stub.get()); 206 catalog.setSubstitute(proxy.get(), stub.get());
222 207
223 REPORTER_ASSERT(reporter, stub.get() == catalog.getSubstituteObject(proxy)); 208 REPORTER_ASSERT(reporter, stub.get() == catalog.getSubstituteObject(proxy));
224 REPORTER_ASSERT(reporter, proxy.get() != catalog.getSubstituteObject(stub)); 209 REPORTER_ASSERT(reporter, proxy.get() != catalog.getSubstituteObject(stub));
225 } 210 }
226 211
227 // This test used to assert without the fix submitted for 212 // This test used to assert without the fix submitted for
228 // http://code.google.com/p/skia/issues/detail?id=1083. 213 // http://code.google.com/p/skia/issues/detail?id=1083.
229 // SKP files might have invalid glyph ids. This test ensures they are ignored, 214 // SKP files might have invalid glyph ids. This test ensures they are ignored,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 SimpleCheckObjectOutput(reporter, stringSimple.get(), 256 SimpleCheckObjectOutput(reporter, stringSimple.get(),
272 "(test \\) string \\( foo)"); 257 "(test \\) string \\( foo)");
273 SkAutoTUnref<SkPDFString> stringComplex( 258 SkAutoTUnref<SkPDFString> stringComplex(
274 new SkPDFString("\ttest ) string ( foo")); 259 new SkPDFString("\ttest ) string ( foo"));
275 SimpleCheckObjectOutput(reporter, stringComplex.get(), 260 SimpleCheckObjectOutput(reporter, stringComplex.get(),
276 "<0974657374202920737472696E67202820666F6F>"); 261 "<0974657374202920737472696E67202820666F6F>");
277 262
278 SkAutoTUnref<SkPDFName> name(new SkPDFName("Test name\twith#tab")); 263 SkAutoTUnref<SkPDFName> name(new SkPDFName("Test name\twith#tab"));
279 const char expectedResult[] = "/Test#20name#09with#23tab"; 264 const char expectedResult[] = "/Test#20name#09with#23tab";
280 CheckObjectOutput(reporter, name.get(), expectedResult, 265 CheckObjectOutput(reporter, name.get(), expectedResult,
281 strlen(expectedResult), false, false); 266 strlen(expectedResult), false);
282 267
283 SkAutoTUnref<SkPDFName> escapedName(new SkPDFName("A#/%()<>[]{}B")); 268 SkAutoTUnref<SkPDFName> escapedName(new SkPDFName("A#/%()<>[]{}B"));
284 const char escapedNameExpected[] = "/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB"; 269 const char escapedNameExpected[] = "/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB";
285 CheckObjectOutput(reporter, escapedName.get(), escapedNameExpected, 270 CheckObjectOutput(reporter, escapedName.get(), escapedNameExpected,
286 strlen(escapedNameExpected), false, false); 271 strlen(escapedNameExpected), false);
287 272
288 // Test that we correctly handle characters with the high-bit set. 273 // Test that we correctly handle characters with the high-bit set.
289 const unsigned char highBitCString[] = {0xDE, 0xAD, 'b', 'e', 0xEF, 0}; 274 const unsigned char highBitCString[] = {0xDE, 0xAD, 'b', 'e', 0xEF, 0};
290 SkAutoTUnref<SkPDFName> highBitName( 275 SkAutoTUnref<SkPDFName> highBitName(
291 new SkPDFName((const char*)highBitCString)); 276 new SkPDFName((const char*)highBitCString));
292 const char highBitExpectedResult[] = "/#DE#ADbe#EF"; 277 const char highBitExpectedResult[] = "/#DE#ADbe#EF";
293 CheckObjectOutput(reporter, highBitName.get(), highBitExpectedResult, 278 CheckObjectOutput(reporter, highBitName.get(), highBitExpectedResult,
294 strlen(highBitExpectedResult), false, false); 279 strlen(highBitExpectedResult), false);
295 280
296 SkAutoTUnref<SkPDFArray> array(new SkPDFArray); 281 SkAutoTUnref<SkPDFArray> array(new SkPDFArray);
297 SimpleCheckObjectOutput(reporter, array.get(), "[]"); 282 SimpleCheckObjectOutput(reporter, array.get(), "[]");
298 array->append(int42.get()); 283 array->append(int42.get());
299 SimpleCheckObjectOutput(reporter, array.get(), "[42]"); 284 SimpleCheckObjectOutput(reporter, array.get(), "[42]");
300 array->append(realHalf.get()); 285 array->append(realHalf.get());
301 SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5]"); 286 SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5]");
302 SkAutoTUnref<SkPDFInt> int0(new SkPDFInt(0)); 287 SkAutoTUnref<SkPDFInt> int0(new SkPDFInt(0));
303 array->append(int0.get()); 288 array->append(int0.get());
304 SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5 0]"); 289 SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5 0]");
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 360
376 // Filter just created; should be unvisited. 361 // Filter just created; should be unvisited.
377 REPORTER_ASSERT(reporter, !filter->visited()); 362 REPORTER_ASSERT(reporter, !filter->visited());
378 SkPaint paint; 363 SkPaint paint;
379 paint.setImageFilter(filter.get()); 364 paint.setImageFilter(filter.get());
380 canvas.drawRect(SkRect::MakeWH(100, 100), paint); 365 canvas.drawRect(SkRect::MakeWH(100, 100), paint);
381 366
382 // Filter was used in rendering; should be visited. 367 // Filter was used in rendering; should be visited.
383 REPORTER_ASSERT(reporter, filter->visited()); 368 REPORTER_ASSERT(reporter, filter->visited());
384 } 369 }
OLDNEW
« no previous file with comments | « tests/AnnotationTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698