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" |
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 "SkPDFDevice.h" | 16 #include "SkPDFDevice.h" |
17 #include "SkPDFStream.h" | 17 #include "SkPDFStream.h" |
18 #include "SkPDFTypes.h" | 18 #include "SkPDFTypes.h" |
19 #include "SkReadBuffer.h" | 19 #include "SkReadBuffer.h" |
20 #include "SkScalar.h" | 20 #include "SkScalar.h" |
21 #include "SkStream.h" | 21 #include "SkStream.h" |
22 #include "SkTypes.h" | 22 #include "SkTypes.h" |
23 #include "Test.h" | 23 #include "Test.h" |
24 | 24 |
25 #define DUMMY_TEXT "DCT compessed stream." | 25 #define DUMMY_TEXT "DCT compessed stream." |
26 | 26 |
27 static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, | 27 namespace { |
28 const void* buffer, size_t len) { | 28 struct Catalog { |
29 SkAutoDataUnref data(stream.copyToData()); | 29 SkPDFSubstituteMap substitutes; |
30 if (offset + len > data->size()) { | 30 SkPDFObjNumMap numbers; |
31 return false; | 31 }; |
32 } // namespace | |
33 | |
34 template <typename T> | |
35 static SkString emit_to_string(T& obj, Catalog* catPtr = NULL) { | |
36 Catalog catalog; | |
37 SkDynamicMemoryWStream buffer; | |
38 if (!catPtr) { | |
39 catPtr = &catalog; | |
32 } | 40 } |
33 return memcmp(data->bytes() + offset, buffer, len) == 0; | 41 obj.emitObject(&buffer, catPtr->numbers, catPtr->substitutes); |
42 SkAutoTDelete<SkStreamAsset> asset(buffer.detachAsStream()); | |
43 SkString tmp(asset->getLength()); | |
44 asset->read(tmp.writable_str(), asset->getLength()); | |
45 return tmp; | |
34 } | 46 } |
35 | 47 |
36 static void emit_object(SkPDFObject* object, | 48 static bool eq(const SkString& str, const char* strPtr) { |
37 SkWStream* stream, | 49 size_t len = strlen(strPtr); |
38 const SkPDFObjNumMap& objNumMap, | 50 return len == str.size() && 0 == memcmp(str.c_str(), strPtr, len); |
39 const SkPDFSubstituteMap& substitutes, | |
40 bool indirect) { | |
41 SkPDFObject* realObject = substitutes.getSubstitute(object); | |
42 if (indirect) { | |
43 stream->writeDecAsText(objNumMap.getObjectNumber(realObject)); | |
44 stream->writeText(" 0 obj\n"); // Generation number is always 0. | |
45 realObject->emitObject(stream, objNumMap, substitutes); | |
46 stream->writeText("\nendobj\n"); | |
47 } else { | |
48 realObject->emitObject(stream, objNumMap, substitutes); | |
49 } | |
50 } | 51 } |
51 | 52 |
52 static size_t get_output_size(SkPDFObject* object, | 53 static bool eq(const SkString& str, const char* strPtr, size_t len) { |
53 const SkPDFObjNumMap& objNumMap, | 54 return len == str.size() && 0 == memcmp(str.c_str(), strPtr, len); |
54 const SkPDFSubstituteMap& substitutes, | |
55 bool indirect) { | |
56 SkDynamicMemoryWStream buffer; | |
57 emit_object(object, &buffer, objNumMap, substitutes, indirect); | |
58 return buffer.getOffset(); | |
59 } | 55 } |
60 | 56 |
61 static void CheckObjectOutput(skiatest::Reporter* reporter, SkPDFObject* obj, | 57 #define ASSERT_EMIT_EQ(REPORTER, OBJECT, STRING) \ |
62 const char* expectedData, size_t expectedSize, | 58 do { \ |
63 bool indirect) { | 59 SkString result = emit_to_string(OBJECT); \ |
64 SkPDFSubstituteMap substituteMap; | 60 if (!eq(result, STRING)) { \ |
65 SkPDFObjNumMap catalog; | 61 REPORT_FAILURE( \ |
66 size_t directSize = get_output_size(obj, catalog, substituteMap, false); | 62 REPORTER, \ |
67 REPORTER_ASSERT(reporter, directSize == expectedSize); | 63 "", \ |
64 SkStringPrintf("'%s' != '%s'", STRING, result.c_str())); \ | |
65 } \ | |
66 } while (false) | |
68 | 67 |
69 SkDynamicMemoryWStream buffer; | 68 #define ASSERT_EMIT_EQL(REPORTER, OBJECT, STRING, LEN) \ |
70 emit_object(obj, &buffer, catalog, substituteMap, false); | 69 do { \ |
71 REPORTER_ASSERT(reporter, directSize == buffer.getOffset()); | 70 SkString result = emit_to_string(OBJECT); \ |
72 if (!stream_equals(buffer, 0, expectedData, directSize)) { | 71 if (!eq(result, STRING, LEN)) { \ |
73 SkAutoTDelete<SkStreamAsset> asset(buffer.detachAsStream()); | 72 REPORT_FAILURE( \ |
74 SkString s(asset->getLength()); | 73 REPORTER, \ |
75 asset->read(s.writable_str(), s.size()); | 74 "", \ |
76 ERRORF(reporter, "!stream_equals() '%s' '%s'", expectedData, s.c_str()); | 75 SkStringPrintf("'%s' != '%s'", STRING, result.c_str())); \ |
77 } | 76 } \ |
78 | 77 } while (false) |
79 if (indirect) { | |
80 // Indirect output. | |
81 static char header[] = "1 0 obj\n"; | |
82 static size_t headerLen = strlen(header); | |
83 static char footer[] = "\nendobj\n"; | |
84 static size_t footerLen = strlen(footer); | |
85 | |
86 catalog.addObject(obj); | |
87 | |
88 size_t indirectSize = | |
89 get_output_size(obj, catalog, substituteMap, true); | |
90 REPORTER_ASSERT(reporter, | |
91 indirectSize == directSize + headerLen + footerLen); | |
92 | |
93 buffer.reset(); | |
94 emit_object(obj, &buffer, catalog, substituteMap, true); | |
95 REPORTER_ASSERT(reporter, indirectSize == buffer.getOffset()); | |
96 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, header, headerLen)); | |
97 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen, expectedData, | |
98 directSize)); | |
99 REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen + directSize, | |
100 footer, footerLen)); | |
101 } | |
102 } | |
103 | |
104 static void SimpleCheckObjectOutput(skiatest::Reporter* reporter, | |
105 SkPDFObject* obj, | |
106 const char* expectedResult) { | |
107 CheckObjectOutput(reporter, obj, expectedResult, | |
108 strlen(expectedResult), true); | |
109 } | |
110 | 78 |
111 static void TestPDFStream(skiatest::Reporter* reporter) { | 79 static void TestPDFStream(skiatest::Reporter* reporter) { |
112 char streamBytes[] = "Test\nFoo\tBar"; | 80 char streamBytes[] = "Test\nFoo\tBar"; |
113 SkAutoTDelete<SkMemoryStream> streamData(new SkMemoryStream( | 81 SkAutoTDelete<SkMemoryStream> streamData(new SkMemoryStream( |
114 streamBytes, strlen(streamBytes), true)); | 82 streamBytes, strlen(streamBytes), true)); |
115 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get())); | 83 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get())); |
116 SimpleCheckObjectOutput( | 84 ASSERT_EMIT_EQ(reporter, |
117 reporter, stream.get(), | 85 *stream, |
118 "<</Length 12>> stream\nTest\nFoo\tBar\nendstream"); | 86 "<</Length 12>> stream\nTest\nFoo\tBar\nendstream"); |
119 stream->insert("Attribute", new SkPDFInt(42))->unref(); | 87 stream->insertInt("Attribute", 42); |
120 SimpleCheckObjectOutput(reporter, stream.get(), | 88 ASSERT_EMIT_EQ(reporter, |
121 "<</Length 12\n/Attribute 42>> stream\n" | 89 *stream, |
122 "Test\nFoo\tBar\nendstream"); | 90 "<</Length 12\n/Attribute 42>> stream\n" |
91 "Test\nFoo\tBar\nendstream"); | |
123 | 92 |
124 { | 93 { |
125 char streamBytes2[] = "This is a longer string, so that compression " | 94 char streamBytes2[] = "This is a longer string, so that compression " |
126 "can do something with it. With shorter strings, " | 95 "can do something with it. With shorter strings, " |
127 "the short circuit logic cuts in and we end up " | 96 "the short circuit logic cuts in and we end up " |
128 "with an uncompressed string."; | 97 "with an uncompressed string."; |
129 SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2, | 98 SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2, |
130 strlen(streamBytes2))); | 99 strlen(streamBytes2))); |
131 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get())); | 100 SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get())); |
132 | 101 |
133 SkDynamicMemoryWStream compressedByteStream; | 102 SkDynamicMemoryWStream compressedByteStream; |
134 SkFlate::Deflate(streamData2.get(), &compressedByteStream); | 103 SkFlate::Deflate(streamData2.get(), &compressedByteStream); |
135 SkAutoDataUnref compressedData(compressedByteStream.copyToData()); | 104 SkAutoDataUnref compressedData(compressedByteStream.copyToData()); |
136 | 105 |
137 SkDynamicMemoryWStream expected; | 106 SkDynamicMemoryWStream expected; |
138 expected.writeText("<</Filter /FlateDecode\n/Length 116>> stream\n"); | 107 expected.writeText("<</Filter /FlateDecode\n/Length 116>> stream\n"); |
139 expected.write(compressedData->data(), compressedData->size()); | 108 expected.write(compressedData->data(), compressedData->size()); |
140 expected.writeText("\nendstream"); | 109 expected.writeText("\nendstream"); |
141 SkAutoDataUnref expectedResultData2(expected.copyToData()); | 110 SkAutoDataUnref expectedResultData2(expected.copyToData()); |
142 CheckObjectOutput(reporter, stream.get(), | 111 ASSERT_EMIT_EQL(reporter, |
143 (const char*) expectedResultData2->data(), | 112 *stream, |
144 expectedResultData2->size(), true); | 113 (const char*)expectedResultData2->data(), |
114 expectedResultData2->size()); | |
145 } | 115 } |
146 } | 116 } |
147 | 117 |
148 static void TestCatalog(skiatest::Reporter* reporter) { | 118 static void TestCatalog(skiatest::Reporter* reporter) { |
149 SkPDFSubstituteMap substituteMap; | 119 SkPDFSubstituteMap substituteMap; |
150 SkPDFObjNumMap catalog; | 120 SkPDFObjNumMap catalog; |
151 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); | 121 SkAutoTUnref<SkPDFArray> a1(new SkPDFArray); |
152 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); | 122 SkAutoTUnref<SkPDFArray> a2(new SkPDFArray); |
153 SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3)); | 123 SkAutoTUnref<SkPDFArray> a3(new SkPDFArray); |
154 int1.get()->ref(); | |
155 SkAutoTUnref<SkPDFInt> int1Again(int1.get()); | |
156 | 124 |
157 catalog.addObject(int1.get()); | 125 catalog.addObject(a1.get()); |
158 catalog.addObject(int2.get()); | 126 catalog.addObject(a2.get()); |
159 catalog.addObject(int3.get()); | 127 catalog.addObject(a3.get()); |
160 | 128 |
161 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); | 129 REPORTER_ASSERT(reporter, catalog.getObjectNumber(a1.get()) == 1); |
162 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); | 130 REPORTER_ASSERT(reporter, catalog.getObjectNumber(a2.get()) == 2); |
163 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int3.get()) == 3); | 131 REPORTER_ASSERT(reporter, catalog.getObjectNumber(a3.get()) == 3); |
164 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1Again.get()) == 1); | 132 REPORTER_ASSERT(reporter, catalog.getObjectNumber(a1.get()) == 1); |
tomhudson
2015/04/27 18:41:37
With the loss of int1Again, it looks like this isn
hal.canary
2015/04/28 03:52:57
int1Again.get() == int1.get(), so all it tested wa
| |
165 } | 133 } |
166 | 134 |
167 static void TestObjectRef(skiatest::Reporter* reporter) { | 135 static void TestObjectRef(skiatest::Reporter* reporter) { |
tomhudson
2015/04/27 18:41:37
Nit: it's hard to see how this test is testing Obj
hal.canary
2015/04/28 03:52:57
// If appendObjRef misbehaves, then the result wou
| |
168 SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); | 136 SkAutoTUnref<SkPDFArray> a1(new SkPDFArray); |
169 SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); | 137 SkAutoTUnref<SkPDFArray> a2(new SkPDFArray); |
170 SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get())); | 138 a2->appendObjRef(SkRef(a1.get())); |
171 | 139 |
172 SkPDFSubstituteMap substituteMap; | 140 Catalog catalog; |
173 SkPDFObjNumMap catalog; | 141 catalog.numbers.addObject(a1.get()); |
174 catalog.addObject(int1.get()); | 142 REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber(a1.get()) == 1); |
175 catalog.addObject(int2.get()); | |
176 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int1.get()) == 1); | |
177 REPORTER_ASSERT(reporter, catalog.getObjectNumber(int2.get()) == 2); | |
178 | 143 |
179 char expectedResult[] = "2 0 R"; | 144 SkString result = emit_to_string(*a2, &catalog); |
180 SkDynamicMemoryWStream buffer; | 145 REPORTER_ASSERT(reporter, eq(result, "[1 0 R]")); |
181 int2ref->emitObject(&buffer, catalog, substituteMap); | |
182 REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); | |
183 REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, | |
184 buffer.getOffset())); | |
185 } | 146 } |
186 | 147 |
187 static void TestSubstitute(skiatest::Reporter* reporter) { | 148 static void TestSubstitute(skiatest::Reporter* reporter) { |
188 SkAutoTUnref<SkPDFDict> proxy(new SkPDFDict()); | 149 SkAutoTUnref<SkPDFDict> proxy(new SkPDFDict()); |
189 SkAutoTUnref<SkPDFDict> stub(new SkPDFDict()); | 150 SkAutoTUnref<SkPDFDict> stub(new SkPDFDict()); |
190 | 151 |
191 proxy->insert("Value", new SkPDFInt(33))->unref(); | 152 proxy->insertInt("Value", 33); |
192 stub->insert("Value", new SkPDFInt(44))->unref(); | 153 stub->insertInt("Value", 44); |
193 | 154 |
194 SkPDFSubstituteMap substituteMap; | 155 SkPDFSubstituteMap substituteMap; |
195 substituteMap.setSubstitute(proxy.get(), stub.get()); | 156 substituteMap.setSubstitute(proxy.get(), stub.get()); |
196 SkPDFObjNumMap catalog; | 157 SkPDFObjNumMap catalog; |
197 catalog.addObject(proxy.get()); | 158 catalog.addObject(proxy.get()); |
198 | 159 |
199 REPORTER_ASSERT(reporter, stub.get() == substituteMap.getSubstitute(proxy)); | 160 REPORTER_ASSERT(reporter, stub.get() == substituteMap.getSubstitute(proxy)); |
200 REPORTER_ASSERT(reporter, proxy.get() != substituteMap.getSubstitute(stub)); | 161 REPORTER_ASSERT(reporter, proxy.get() != substituteMap.getSubstitute(stub)); |
201 } | 162 } |
202 | 163 |
203 // This test used to assert without the fix submitted for | 164 // This test used to assert without the fix submitted for |
204 // http://code.google.com/p/skia/issues/detail?id=1083. | 165 // http://code.google.com/p/skia/issues/detail?id=1083. |
205 // SKP files might have invalid glyph ids. This test ensures they are ignored, | 166 // SKP files might have invalid glyph ids. This test ensures they are ignored, |
206 // and there is no assert on input data in Debug mode. | 167 // and there is no assert on input data in Debug mode. |
207 static void test_issue1083() { | 168 static void test_issue1083() { |
208 SkDynamicMemoryWStream outStream; | 169 SkDynamicMemoryWStream outStream; |
209 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); | 170 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); |
210 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f); | 171 SkCanvas* canvas = doc->beginPage(100.0f, 100.0f); |
211 SkPaint paint; | 172 SkPaint paint; |
212 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 173 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
213 | 174 |
214 uint16_t glyphID = 65000; | 175 uint16_t glyphID = 65000; |
215 canvas->drawText(&glyphID, 2, 0, 0, paint); | 176 canvas->drawText(&glyphID, 2, 0, 0, paint); |
216 | 177 |
217 doc->close(); | 178 doc->close(); |
218 } | 179 } |
219 | 180 |
220 DEF_TEST(PDFPrimitives, reporter) { | 181 DEF_TEST(PDFPrimitives, reporter) { |
221 SkAutoTUnref<SkPDFInt> int42(new SkPDFInt(42)); | 182 SkPDFUnion int42 = SkPDFUnion::Int(42); |
222 SimpleCheckObjectOutput(reporter, int42.get(), "42"); | 183 ASSERT_EMIT_EQ(reporter, int42, "42"); |
223 | 184 |
224 SkAutoTUnref<SkPDFScalar> realHalf(new SkPDFScalar(SK_ScalarHalf)); | 185 SkPDFUnion realHalf = SkPDFUnion::Scalar(SK_ScalarHalf); |
225 SimpleCheckObjectOutput(reporter, realHalf.get(), "0.5"); | 186 ASSERT_EMIT_EQ(reporter, realHalf, "0.5"); |
226 | 187 |
227 SkAutoTUnref<SkPDFScalar> bigScalar(new SkPDFScalar(110999.75f)); | 188 SkPDFUnion bigScalar = SkPDFUnion::Scalar(110999.75f); |
228 #if !defined(SK_ALLOW_LARGE_PDF_SCALARS) | 189 #if !defined(SK_ALLOW_LARGE_PDF_SCALARS) |
229 SimpleCheckObjectOutput(reporter, bigScalar.get(), "111000"); | 190 ASSERT_EMIT_EQ(reporter, bigScalar, "111000"); |
230 #else | 191 #else |
231 SimpleCheckObjectOutput(reporter, bigScalar.get(), "110999.75"); | 192 ASSERT_EMIT_EQ(reporter, bigScalar, "110999.75"); |
232 | 193 |
233 SkAutoTUnref<SkPDFScalar> biggerScalar(new SkPDFScalar(50000000.1)); | 194 SkPDFUnion biggerScalar = SkPDFUnion::Scalar(50000000.1); |
234 SimpleCheckObjectOutput(reporter, biggerScalar.get(), "50000000"); | 195 ASSERT_EMIT_EQ(reporter, biggerScalar, "50000000"); |
235 | 196 |
236 SkAutoTUnref<SkPDFScalar> smallestScalar(new SkPDFScalar(1.0/65536)); | 197 SkPDFUnion smallestScalar = SkPDFUnion::Scalar(1.0 / 65536); |
237 SimpleCheckObjectOutput(reporter, smallestScalar.get(), "0.00001526"); | 198 ASSERT_EMIT_EQ(reporter, smallestScalar, "0.00001526"); |
238 #endif | 199 #endif |
239 | 200 |
240 SkAutoTUnref<SkPDFString> stringSimple( | 201 SkPDFUnion stringSimple = SkPDFUnion::String("test ) string ( foo"); |
241 new SkPDFString("test ) string ( foo")); | 202 ASSERT_EMIT_EQ(reporter, stringSimple, "(test \\) string \\( foo)"); |
242 SimpleCheckObjectOutput(reporter, stringSimple.get(), | |
243 "(test \\) string \\( foo)"); | |
244 SkAutoTUnref<SkPDFString> stringComplex( | |
245 new SkPDFString("\ttest ) string ( foo")); | |
246 SimpleCheckObjectOutput(reporter, stringComplex.get(), | |
247 "<0974657374202920737472696E67202820666F6F>"); | |
248 | 203 |
249 SkAutoTUnref<SkPDFName> name(new SkPDFName("Test name\twith#tab")); | 204 SkString stringComplexInput("\ttest ) string ( foo"); |
250 const char expectedResult[] = "/Test#20name#09with#23tab"; | 205 SkPDFUnion stringComplex = SkPDFUnion::String(stringComplexInput); |
251 CheckObjectOutput(reporter, name.get(), expectedResult, | 206 ASSERT_EMIT_EQ(reporter, |
252 strlen(expectedResult), false); | 207 stringComplex, |
208 "<0974657374202920737472696E67202820666F6F>"); | |
253 | 209 |
254 SkAutoTUnref<SkPDFName> escapedName(new SkPDFName("A#/%()<>[]{}B")); | 210 SkString nameInput("Test name\twith#tab"); |
255 const char escapedNameExpected[] = "/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB"; | 211 SkPDFUnion name = SkPDFUnion::Name(nameInput); |
256 CheckObjectOutput(reporter, escapedName.get(), escapedNameExpected, | 212 ASSERT_EMIT_EQ(reporter, name, "/Test#20name#09with#23tab"); |
257 strlen(escapedNameExpected), false); | 213 |
214 SkString nameInput2("A#/%()<>[]{}B"); | |
215 SkPDFUnion name2 = SkPDFUnion::Name(nameInput2); | |
216 ASSERT_EMIT_EQ(reporter, name2, "/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB"); | |
258 | 217 |
259 // Test that we correctly handle characters with the high-bit set. | 218 // Test that we correctly handle characters with the high-bit set. |
260 const unsigned char highBitCString[] = {0xDE, 0xAD, 'b', 'e', 0xEF, 0}; | 219 SkString highBitString( |
261 SkAutoTUnref<SkPDFName> highBitName( | 220 "\xDE\xAD" |
262 new SkPDFName((const char*)highBitCString)); | 221 "be\xEF"); |
263 const char highBitExpectedResult[] = "/#DE#ADbe#EF"; | 222 SkPDFUnion highBitName = SkPDFUnion::Name(highBitString); |
264 CheckObjectOutput(reporter, highBitName.get(), highBitExpectedResult, | 223 ASSERT_EMIT_EQ(reporter, highBitName, "/#DE#ADbe#EF"); |
265 strlen(highBitExpectedResult), false); | |
266 | 224 |
267 SkAutoTUnref<SkPDFArray> array(new SkPDFArray); | 225 SkAutoTUnref<SkPDFArray> array(new SkPDFArray); |
268 SimpleCheckObjectOutput(reporter, array.get(), "[]"); | 226 ASSERT_EMIT_EQ(reporter, *array, "[]"); |
269 array->append(int42.get()); | 227 array->appendInt(42); |
270 SimpleCheckObjectOutput(reporter, array.get(), "[42]"); | 228 ASSERT_EMIT_EQ(reporter, *array, "[42]"); |
271 array->append(realHalf.get()); | 229 array->appendScalar(SK_ScalarHalf); |
272 SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5]"); | 230 ASSERT_EMIT_EQ(reporter, *array, "[42 0.5]"); |
273 SkAutoTUnref<SkPDFInt> int0(new SkPDFInt(0)); | 231 array->appendInt(0); |
274 array->append(int0.get()); | 232 ASSERT_EMIT_EQ(reporter, *array, "[42 0.5 0]"); |
275 SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5 0]"); | |
276 | 233 |
277 SkAutoTUnref<SkPDFDict> dict(new SkPDFDict); | 234 SkAutoTUnref<SkPDFDict> dict(new SkPDFDict); |
278 SimpleCheckObjectOutput(reporter, dict.get(), "<<>>"); | 235 ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); |
279 dict->insert("n1", int42.get()); | 236 dict->insertInt("n1", 42); |
280 SimpleCheckObjectOutput(reporter, dict.get(), "<</n1 42>>"); | 237 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42>>"); |
281 SkString n3("n3"); | 238 SkString n3("n3"); |
282 dict->insert("n2", realHalf.get()); | 239 dict->insertScalar("n2", SK_ScalarHalf); |
283 dict->insertObject(n3, array.detach()); | 240 dict->insertObject(n3, array.detach()); |
284 SimpleCheckObjectOutput(reporter, dict.get(), | 241 ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42\n/n2 0.5\n/n3 [42 0.5 0]>>"); |
285 "<</n1 42\n/n2 0.5\n/n3 [42 0.5 0]>>"); | |
286 | 242 |
287 TestPDFStream(reporter); | 243 TestPDFStream(reporter); |
288 | 244 |
289 TestCatalog(reporter); | 245 TestCatalog(reporter); |
290 | 246 |
291 TestObjectRef(reporter); | 247 TestObjectRef(reporter); |
292 | 248 |
293 TestSubstitute(reporter); | 249 TestSubstitute(reporter); |
294 | 250 |
295 test_issue1083(); | 251 test_issue1083(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 // Filter just created; should be unvisited. | 299 // Filter just created; should be unvisited. |
344 REPORTER_ASSERT(reporter, !filter->visited()); | 300 REPORTER_ASSERT(reporter, !filter->visited()); |
345 SkPaint paint; | 301 SkPaint paint; |
346 paint.setImageFilter(filter.get()); | 302 paint.setImageFilter(filter.get()); |
347 canvas->drawRect(SkRect::MakeWH(100, 100), paint); | 303 canvas->drawRect(SkRect::MakeWH(100, 100), paint); |
348 doc->close(); | 304 doc->close(); |
349 | 305 |
350 // Filter was used in rendering; should be visited. | 306 // Filter was used in rendering; should be visited. |
351 REPORTER_ASSERT(reporter, filter->visited()); | 307 REPORTER_ASSERT(reporter, filter->visited()); |
352 } | 308 } |
OLD | NEW |