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

Side by Side Diff: tests/PDFPrimitivesTest.cpp

Issue 1033833002: SkPDF: unit test cleanup (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « no previous file | 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"
11 #include "SkDocument.h" 11 #include "SkDocument.h"
12 #include "SkFlate.h" 12 #include "SkFlate.h"
13 #include "SkImageEncoder.h" 13 #include "SkImageEncoder.h"
14 #include "SkMatrix.h" 14 #include "SkMatrix.h"
15 #include "SkPDFCanon.h" 15 #include "SkPDFCanon.h"
16 #include "SkPDFCatalog.h" 16 #include "SkPDFCatalog.h"
17 #include "SkPDFDevice.h" 17 #include "SkPDFDevice.h"
18 #include "SkPDFStream.h" 18 #include "SkPDFStream.h"
19 #include "SkPDFTypes.h" 19 #include "SkPDFTypes.h"
20 #include "SkReadBuffer.h" 20 #include "SkReadBuffer.h"
21 #include "SkScalar.h" 21 #include "SkScalar.h"
22 #include "SkStream.h" 22 #include "SkStream.h"
23 #include "SkTypes.h" 23 #include "SkTypes.h"
24 #include "Test.h" 24 #include "Test.h"
25 25
26 class SkPDFTestDict : public SkPDFDict {
27 public:
28 virtual void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects,
29 SkTSet<SkPDFObject*>* newResourceObjects) {
30 for (int i = 0; i < fResources.count(); i++) {
31 newResourceObjects->add(fResources[i]);
32 fResources[i]->ref();
33 }
34 }
35
36 void addResource(SkPDFObject* object) {
37 fResources.append(1, &object);
38 }
39
40 private:
41 SkTDArray<SkPDFObject*> fResources;
42 };
43
44 #define DUMMY_TEXT "DCT compessed stream." 26 #define DUMMY_TEXT "DCT compessed stream."
45 27
46 static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, 28 static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset,
47 const void* buffer, size_t len) { 29 const void* buffer, size_t len) {
48 SkAutoDataUnref data(stream.copyToData()); 30 SkAutoDataUnref data(stream.copyToData());
49 if (offset + len > data->size()) { 31 if (offset + len > data->size()) {
50 return false; 32 return false;
51 } 33 }
52 return memcmp(data->bytes() + offset, buffer, len) == 0; 34 return memcmp(data->bytes() + offset, buffer, len) == 0;
53 } 35 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 172
191 char expectedResult[] = "2 0 R"; 173 char expectedResult[] = "2 0 R";
192 SkDynamicMemoryWStream buffer; 174 SkDynamicMemoryWStream buffer;
193 int2ref->emitObject(&buffer, &catalog); 175 int2ref->emitObject(&buffer, &catalog);
194 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); 176 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult));
195 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, 177 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
196 buffer.getOffset())); 178 buffer.getOffset()));
197 } 179 }
198 180
199 static void TestSubstitute(skiatest::Reporter* reporter) { 181 static void TestSubstitute(skiatest::Reporter* reporter) {
200 SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict()); 182 SkAutoTUnref<SkPDFDict> proxy(new SkPDFDict());
201 SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict()); 183 SkAutoTUnref<SkPDFDict> stub(new SkPDFDict());
202 184
203 proxy->insert("Value", new SkPDFInt(33))->unref(); 185 proxy->insert("Value", new SkPDFInt(33))->unref();
204 stub->insert("Value", new SkPDFInt(44))->unref(); 186 stub->insert("Value", new SkPDFInt(44))->unref();
205 187
206 SkPDFCatalog catalog; 188 SkPDFCatalog catalog;
207 catalog.addObject(proxy.get(), false); 189 catalog.addObject(proxy.get(), false);
208 catalog.setSubstitute(proxy.get(), stub.get()); 190 catalog.setSubstitute(proxy.get(), stub.get());
209 191
210 REPORTER_ASSERT(reporter, stub.get() == catalog.getSubstituteObject(proxy)); 192 REPORTER_ASSERT(reporter, stub.get() == catalog.getSubstituteObject(proxy));
211 REPORTER_ASSERT(reporter, proxy.get() != catalog.getSubstituteObject(stub)); 193 REPORTER_ASSERT(reporter, proxy.get() != catalog.getSubstituteObject(stub));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 // Filter just created; should be unvisited. 341 // Filter just created; should be unvisited.
360 REPORTER_ASSERT(reporter, !filter->visited()); 342 REPORTER_ASSERT(reporter, !filter->visited());
361 SkPaint paint; 343 SkPaint paint;
362 paint.setImageFilter(filter.get()); 344 paint.setImageFilter(filter.get());
363 canvas->drawRect(SkRect::MakeWH(100, 100), paint); 345 canvas->drawRect(SkRect::MakeWH(100, 100), paint);
364 doc->close(); 346 doc->close();
365 347
366 // Filter was used in rendering; should be visited. 348 // Filter was used in rendering; should be visited.
367 REPORTER_ASSERT(reporter, filter->visited()); 349 REPORTER_ASSERT(reporter, filter->visited());
368 } 350 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698