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

Side by Side Diff: tests/PDFPrimitivesTest.cpp

Issue 1033543002: SKPDF: refactor pdfcatalog and pdfdocument (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-03-25 (Wednesday) 14:17:42 EDT Created 5 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/SkPDFTypes.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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedData, 70 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedData,
71 directSize)); 71 directSize));
72 72
73 if (indirect) { 73 if (indirect) {
74 // Indirect output. 74 // Indirect output.
75 static char header[] = "1 0 obj\n"; 75 static char header[] = "1 0 obj\n";
76 static size_t headerLen = strlen(header); 76 static size_t headerLen = strlen(header);
77 static char footer[] = "\nendobj\n"; 77 static char footer[] = "\nendobj\n";
78 static size_t footerLen = strlen(footer); 78 static size_t footerLen = strlen(footer);
79 79
80 catalog.addObject(obj, false); 80 catalog.addObject(obj);
81 81
82 size_t indirectSize = get_output_size(obj, &catalog, true); 82 size_t indirectSize = get_output_size(obj, &catalog, true);
83 REPORTER_ASSERT(reporter, 83 REPORTER_ASSERT(reporter,
84 indirectSize == directSize + headerLen + footerLen); 84 indirectSize == directSize + headerLen + footerLen);
85 85
86 buffer.reset(); 86 buffer.reset();
87 emit_object(obj, &buffer, &catalog, true); 87 emit_object(obj, &buffer, &catalog, true);
88 REPORTER_ASSERT(reporter, indirectSize == buffer.getOffset()); 88 REPORTER_ASSERT(reporter, indirectSize == buffer.getOffset());
89 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, header, headerLen)); 89 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, header, headerLen));
90 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen, expectedData, 90 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen, expectedData,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 143
144 static void TestCatalog(skiatest::Reporter* reporter) { 144 static void TestCatalog(skiatest::Reporter* reporter) {
145 SkPDFCatalog catalog; 145 SkPDFCatalog catalog;
146 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); 146 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
147 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); 147 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2));
148 SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3)); 148 SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3));
149 int1.get()->ref(); 149 int1.get()->ref();
150 SkAutoTUnref<SkPDFInt> int1Again(int1.get()); 150 SkAutoTUnref<SkPDFInt> int1Again(int1.get());
151 151
152 catalog.addObject(int1.get(), false); 152 catalog.addObject(int1.get());
153 catalog.addObject(int2.get(), false); 153 catalog.addObject(int2.get());
154 catalog.addObject(int3.get(), false); 154 catalog.addObject(int3.get());
155 155
156 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); 156 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1);
157 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); 157 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2);
158 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int3.get()) == 3); 158 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int3.get()) == 3);
159 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1Again.get()) == 1); 159 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1Again.get()) == 1);
160 } 160 }
161 161
162 static void TestObjectRef(skiatest::Reporter* reporter) { 162 static void TestObjectRef(skiatest::Reporter* reporter) {
163 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); 163 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
164 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); 164 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2));
165 SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get())); 165 SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get()));
166 166
167 SkPDFCatalog catalog; 167 SkPDFCatalog catalog;
168 catalog.addObject(int1.get(), false); 168 catalog.addObject(int1.get());
169 catalog.addObject(int2.get(), false); 169 catalog.addObject(int2.get());
170 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); 170 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1);
171 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); 171 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2);
172 172
173 char expectedResult[] = "2 0 R"; 173 char expectedResult[] = "2 0 R";
174 SkDynamicMemoryWStream buffer; 174 SkDynamicMemoryWStream buffer;
175 int2ref->emitObject(&buffer, &catalog); 175 int2ref->emitObject(&buffer, &catalog);
176 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); 176 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult));
177 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, 177 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
178 buffer.getOffset())); 178 buffer.getOffset()));
179 } 179 }
180 180
181 static void TestSubstitute(skiatest::Reporter* reporter) { 181 static void TestSubstitute(skiatest::Reporter* reporter) {
182 SkAutoTUnref<SkPDFDict> proxy(new SkPDFDict()); 182 SkAutoTUnref<SkPDFDict> proxy(new SkPDFDict());
183 SkAutoTUnref<SkPDFDict> stub(new SkPDFDict()); 183 SkAutoTUnref<SkPDFDict> stub(new SkPDFDict());
184 184
185 proxy->insert("Value", new SkPDFInt(33))->unref(); 185 proxy->insert("Value", new SkPDFInt(33))->unref();
186 stub->insert("Value", new SkPDFInt(44))->unref(); 186 stub->insert("Value", new SkPDFInt(44))->unref();
187 187
188 SkPDFCatalog catalog; 188 SkPDFCatalog catalog;
189 catalog.addObject(proxy.get(), false); 189 catalog.addObject(proxy.get());
190 catalog.setSubstitute(proxy.get(), stub.get()); 190 catalog.setSubstitute(proxy.get(), stub.get());
191 191
192 REPORTER_ASSERT(reporter, stub.get() == catalog.getSubstituteObject(proxy)); 192 REPORTER_ASSERT(reporter, stub.get() == catalog.getSubstituteObject(proxy));
193 REPORTER_ASSERT(reporter, proxy.get() != catalog.getSubstituteObject(stub)); 193 REPORTER_ASSERT(reporter, proxy.get() != catalog.getSubstituteObject(stub));
194 } 194 }
195 195
196 // This test used to assert without the fix submitted for 196 // This test used to assert without the fix submitted for
197 // http://code.google.com/p/skia/issues/detail?id=1083. 197 // http://code.google.com/p/skia/issues/detail?id=1083.
198 // SKP files might have invalid glyph ids. This test ensures they are ignored, 198 // SKP files might have invalid glyph ids. This test ensures they are ignored,
199 // and there is no assert on input data in Debug mode. 199 // and there is no assert on input data in Debug mode.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Filter just created; should be unvisited. 341 // Filter just created; should be unvisited.
342 REPORTER_ASSERT(reporter, !filter->visited()); 342 REPORTER_ASSERT(reporter, !filter->visited());
343 SkPaint paint; 343 SkPaint paint;
344 paint.setImageFilter(filter.get()); 344 paint.setImageFilter(filter.get());
345 canvas->drawRect(SkRect::MakeWH(100, 100), paint); 345 canvas->drawRect(SkRect::MakeWH(100, 100), paint);
346 doc->close(); 346 doc->close();
347 347
348 // Filter was used in rendering; should be visited. 348 // Filter was used in rendering; should be visited.
349 REPORTER_ASSERT(reporter, filter->visited()); 349 REPORTER_ASSERT(reporter, filter->visited());
350 } 350 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFTypes.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698