| OLD | NEW |
| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedData, | 88 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedData, |
| 89 directSize)); | 89 directSize)); |
| 90 | 90 |
| 91 if (indirect) { | 91 if (indirect) { |
| 92 // Indirect output. | 92 // Indirect output. |
| 93 static char header[] = "1 0 obj\n"; | 93 static char header[] = "1 0 obj\n"; |
| 94 static size_t headerLen = strlen(header); | 94 static size_t headerLen = strlen(header); |
| 95 static char footer[] = "\nendobj\n"; | 95 static char footer[] = "\nendobj\n"; |
| 96 static size_t footerLen = strlen(footer); | 96 static size_t footerLen = strlen(footer); |
| 97 | 97 |
| 98 catalog.addObject(obj, false); | 98 catalog.addObject(obj); |
| 99 | 99 |
| 100 size_t indirectSize = get_output_size(obj, &catalog, true); | 100 size_t indirectSize = get_output_size(obj, &catalog, true); |
| 101 REPORTER_ASSERT(reporter, | 101 REPORTER_ASSERT(reporter, |
| 102 indirectSize == directSize + headerLen + footerLen); | 102 indirectSize == directSize + headerLen + footerLen); |
| 103 | 103 |
| 104 buffer.reset(); | 104 buffer.reset(); |
| 105 emit_object(obj, &buffer, &catalog, true); | 105 emit_object(obj, &buffer, &catalog, true); |
| 106 REPORTER_ASSERT(reporter, indirectSize == buffer.getOffset()); | 106 REPORTER_ASSERT(reporter, indirectSize == buffer.getOffset()); |
| 107 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, header, headerLen)); | 107 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, header, headerLen)); |
| 108 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen, expectedData, | 108 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen, expectedData, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 160 } |
| 161 | 161 |
| 162 static void TestCatalog(skiatest::Reporter* reporter) { | 162 static void TestCatalog(skiatest::Reporter* reporter) { |
| 163 SkPDFCatalog catalog; | 163 SkPDFCatalog catalog; |
| 164 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); | 164 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); |
| 165 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); | 165 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); |
| 166 SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3)); | 166 SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3)); |
| 167 int1.get()->ref(); | 167 int1.get()->ref(); |
| 168 SkAutoTUnref<SkPDFInt> int1Again(int1.get()); | 168 SkAutoTUnref<SkPDFInt> int1Again(int1.get()); |
| 169 | 169 |
| 170 catalog.addObject(int1.get(), false); | 170 catalog.addObject(int1.get()); |
| 171 catalog.addObject(int2.get(), false); | 171 catalog.addObject(int2.get()); |
| 172 catalog.addObject(int3.get(), false); | 172 catalog.addObject(int3.get()); |
| 173 | 173 |
| 174 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); | 174 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); |
| 175 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); | 175 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); |
| 176 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int3.get()) == 3); | 176 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int3.get()) == 3); |
| 177 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1Again.get()) == 1); | 177 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1Again.get()) == 1); |
| 178 } | 178 } |
| 179 | 179 |
| 180 static void TestObjectRef(skiatest::Reporter* reporter) { | 180 static void TestObjectRef(skiatest::Reporter* reporter) { |
| 181 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); | 181 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); |
| 182 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); | 182 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); |
| 183 SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get())); | 183 SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get())); |
| 184 | 184 |
| 185 SkPDFCatalog catalog; | 185 SkPDFCatalog catalog; |
| 186 catalog.addObject(int1.get(), false); | 186 catalog.addObject(int1.get()); |
| 187 catalog.addObject(int2.get(), false); | 187 catalog.addObject(int2.get()); |
| 188 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); | 188 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); |
| 189 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); | 189 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); |
| 190 | 190 |
| 191 char expectedResult[] = "2 0 R"; | 191 char expectedResult[] = "2 0 R"; |
| 192 SkDynamicMemoryWStream buffer; | 192 SkDynamicMemoryWStream buffer; |
| 193 int2ref->emitObject(&buffer, &catalog); | 193 int2ref->emitObject(&buffer, &catalog); |
| 194 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); | 194 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); |
| 195 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, | 195 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, |
| 196 buffer.getOffset())); | 196 buffer.getOffset())); |
| 197 } | 197 } |
| 198 | 198 |
| 199 static void TestSubstitute(skiatest::Reporter* reporter) { | 199 static void TestSubstitute(skiatest::Reporter* reporter) { |
| 200 SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict()); | 200 SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict()); |
| 201 SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict()); | 201 SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict()); |
| 202 | 202 |
| 203 proxy->insert("Value", new SkPDFInt(33))->unref(); | 203 proxy->insert("Value", new SkPDFInt(33))->unref(); |
| 204 stub->insert("Value", new SkPDFInt(44))->unref(); | 204 stub->insert("Value", new SkPDFInt(44))->unref(); |
| 205 | 205 |
| 206 SkPDFCatalog catalog; | 206 SkPDFCatalog catalog; |
| 207 catalog.addObject(proxy.get(), false); | 207 catalog.addObject(proxy.get()); |
| 208 catalog.setSubstitute(proxy.get(), stub.get()); | 208 catalog.setSubstitute(proxy.get(), stub.get()); |
| 209 | 209 |
| 210 REPORTER_ASSERT(reporter, stub.get() == catalog.getSubstituteObject(proxy)); | 210 REPORTER_ASSERT(reporter, stub.get() == catalog.getSubstituteObject(proxy)); |
| 211 REPORTER_ASSERT(reporter, proxy.get() != catalog.getSubstituteObject(stub)); | 211 REPORTER_ASSERT(reporter, proxy.get() != catalog.getSubstituteObject(stub)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // This test used to assert without the fix submitted for | 214 // This test used to assert without the fix submitted for |
| 215 // http://code.google.com/p/skia/issues/detail?id=1083. | 215 // http://code.google.com/p/skia/issues/detail?id=1083. |
| 216 // SKP files might have invalid glyph ids. This test ensures they are ignored, | 216 // SKP files might have invalid glyph ids. This test ensures they are ignored, |
| 217 // and there is no assert on input data in Debug mode. | 217 // and there is no assert on input data in Debug mode. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // Filter just created; should be unvisited. | 359 // Filter just created; should be unvisited. |
| 360 REPORTER_ASSERT(reporter, !filter->visited()); | 360 REPORTER_ASSERT(reporter, !filter->visited()); |
| 361 SkPaint paint; | 361 SkPaint paint; |
| 362 paint.setImageFilter(filter.get()); | 362 paint.setImageFilter(filter.get()); |
| 363 canvas->drawRect(SkRect::MakeWH(100, 100), paint); | 363 canvas->drawRect(SkRect::MakeWH(100, 100), paint); |
| 364 doc->close(); | 364 doc->close(); |
| 365 | 365 |
| 366 // Filter was used in rendering; should be visited. | 366 // Filter was used in rendering; should be visited. |
| 367 REPORTER_ASSERT(reporter, filter->visited()); | 367 REPORTER_ASSERT(reporter, filter->visited()); |
| 368 } | 368 } |
| OLD | NEW |