OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkAnnotation.h" | 8 #include "SkAnnotation.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
11 #include "SkPDFDevice.h" | 11 #include "SkPDFDevice.h" |
12 #include "SkPDFDocument.h" | 12 #include "SkPDFDocument.h" |
13 #include "Test.h" | 13 #include "Test.h" |
14 | 14 |
15 /** Returns true if data (may contain null characters) contains needle (null | 15 /** Returns true if data (may contain null characters) contains needle (null |
16 * terminated). */ | 16 * terminated). */ |
17 static bool ContainsString(const char* data, size_t dataSize, const char* needle
) { | 17 static bool ContainsString(const char* data, size_t dataSize, const char* needle
) { |
18 size_t nSize = strlen(needle); | 18 size_t nSize = strlen(needle); |
19 for (size_t i = 0; i < dataSize - nSize; i++) { | 19 for (size_t i = 0; i < dataSize - nSize; i++) { |
20 if (strncmp(&data[i], needle, nSize) == 0) { | 20 if (strncmp(&data[i], needle, nSize) == 0) { |
21 return true; | 21 return true; |
22 } | 22 } |
23 } | 23 } |
24 return false; | 24 return false; |
25 } | 25 } |
26 | 26 |
27 DEF_TEST(Annotation_NoDraw, reporter) { | 27 DEF_TEST(Annotation_NoDraw, reporter) { |
28 SkBitmap bm; | 28 SkBitmap bm; |
29 bm.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); | 29 bm.allocN32Pixels(10, 10); |
30 bm.allocPixels(); | |
31 bm.eraseColor(SK_ColorTRANSPARENT); | 30 bm.eraseColor(SK_ColorTRANSPARENT); |
32 | 31 |
33 SkCanvas canvas(bm); | 32 SkCanvas canvas(bm); |
34 SkRect r = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10)); | 33 SkRect r = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10)); |
35 | 34 |
36 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); | 35 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); |
37 | 36 |
38 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); | 37 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); |
39 SkAnnotateRectWithURL(&canvas, r, data.get()); | 38 SkAnnotateRectWithURL(&canvas, r, data.get()); |
40 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); | 39 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 SkPDFDocument doc; | 86 SkPDFDocument doc; |
88 doc.appendPage(&device); | 87 doc.appendPage(&device); |
89 SkDynamicMemoryWStream outStream; | 88 SkDynamicMemoryWStream outStream; |
90 doc.emitPDF(&outStream); | 89 doc.emitPDF(&outStream); |
91 SkAutoDataUnref out(outStream.copyToData()); | 90 SkAutoDataUnref out(outStream.copyToData()); |
92 const char* rawOutput = (const char*)out->data(); | 91 const char* rawOutput = (const char*)out->data(); |
93 | 92 |
94 REPORTER_ASSERT(reporter, | 93 REPORTER_ASSERT(reporter, |
95 ContainsString(rawOutput, out->size(), "/example ")); | 94 ContainsString(rawOutput, out->size(), "/example ")); |
96 } | 95 } |
OLD | NEW |