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

Side by Side Diff: tests/AnnotationTest.cpp

Issue 1278403006: SkPDF: clean up overuse of SK_SUPPORT_PDF (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-11 (Tuesday) 16:25:36 EDT Created 5 years, 4 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 | « gyp/tests.gypi ('k') | tests/CanvasTest.cpp » ('j') | 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 /* 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 "SkDocument.h" 11 #include "SkDocument.h"
12 #include "SkStream.h" 12 #include "SkStream.h"
13 #include "Test.h" 13 #include "Test.h"
14 14
15 #if SK_SUPPORT_PDF
16
17 /** Returns true if data (may contain null characters) contains needle (null 15 /** Returns true if data (may contain null characters) contains needle (null
18 * terminated). */ 16 * terminated). */
19 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 ) {
20 size_t nSize = strlen(needle); 18 size_t nSize = strlen(needle);
21 for (size_t i = 0; i < dataSize - nSize; i++) { 19 for (size_t i = 0; i < dataSize - nSize; i++) {
22 if (strncmp(&data[i], needle, nSize) == 0) { 20 if (strncmp(&data[i], needle, nSize) == 0) {
23 return true; 21 return true;
24 } 22 }
25 } 23 }
26 return false; 24 return false;
27 } 25 }
28 26
29 DEF_TEST(Annotation_NoDraw, reporter) { 27 DEF_TEST(Annotation_NoDraw, reporter) {
30 SkBitmap bm; 28 SkBitmap bm;
31 bm.allocN32Pixels(10, 10); 29 bm.allocN32Pixels(10, 10);
32 bm.eraseColor(SK_ColorTRANSPARENT); 30 bm.eraseColor(SK_ColorTRANSPARENT);
33 31
34 SkCanvas canvas(bm); 32 SkCanvas canvas(bm);
35 SkRect r = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10)); 33 SkRect r = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10));
36 34
37 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); 35 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com"));
38 36
39 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); 37 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
40 SkAnnotateRectWithURL(&canvas, r, data.get()); 38 SkAnnotateRectWithURL(&canvas, r, data.get());
41 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); 39 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
42 } 40 }
43 41
44 DEF_TEST(Annotation_PdfLink, reporter) { 42 DEF_TEST(Annotation_PdfLink, reporter) {
43 REQUIRE_PDF_DOCUMENT(Annotation_PdfLink, reporter);
45 SkDynamicMemoryWStream outStream; 44 SkDynamicMemoryWStream outStream;
46 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); 45 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
47 SkCanvas* canvas = doc->beginPage(612.0f, 792.0f); 46 SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
48 REPORTER_ASSERT(reporter, canvas); 47 REPORTER_ASSERT(reporter, canvas);
49 48
50 SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72), 49 SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72),
51 SkIntToScalar(288), SkIntToScalar(72)); 50 SkIntToScalar(288), SkIntToScalar(72));
52 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); 51 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com"));
53 SkAnnotateRectWithURL(canvas, r, data.get()); 52 SkAnnotateRectWithURL(canvas, r, data.get());
54 53
55 REPORTER_ASSERT(reporter, doc->close()); 54 REPORTER_ASSERT(reporter, doc->close());
56 SkAutoDataUnref out(outStream.copyToData()); 55 SkAutoDataUnref out(outStream.copyToData());
57 const char* rawOutput = (const char*)out->data(); 56 const char* rawOutput = (const char*)out->data();
58 57
59 REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots ") ); 58 REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots ") );
60 } 59 }
61 60
62 DEF_TEST(Annotation_NamedDestination, reporter) { 61 DEF_TEST(Annotation_NamedDestination, reporter) {
62 REQUIRE_PDF_DOCUMENT(Annotation_NamedDestination, reporter);
63 SkDynamicMemoryWStream outStream; 63 SkDynamicMemoryWStream outStream;
64 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); 64 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
65 SkCanvas* canvas = doc->beginPage(612.0f, 792.0f); 65 SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
66 REPORTER_ASSERT(reporter, canvas); 66 REPORTER_ASSERT(reporter, canvas);
67 67
68 SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72)); 68 SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72));
69 SkAutoDataUnref data(SkData::NewWithCString("example")); 69 SkAutoDataUnref data(SkData::NewWithCString("example"));
70 SkAnnotateNamedDestination(canvas, p, data.get()); 70 SkAnnotateNamedDestination(canvas, p, data.get());
71 71
72 REPORTER_ASSERT(reporter, doc->close()); 72 REPORTER_ASSERT(reporter, doc->close());
73 SkAutoDataUnref out(outStream.copyToData()); 73 SkAutoDataUnref out(outStream.copyToData());
74 const char* rawOutput = (const char*)out->data(); 74 const char* rawOutput = (const char*)out->data();
75 75
76 REPORTER_ASSERT(reporter, 76 REPORTER_ASSERT(reporter,
77 ContainsString(rawOutput, out->size(), "/example ")); 77 ContainsString(rawOutput, out->size(), "/example "));
78 } 78 }
79 #endif // SK_SUPPORT_PDF
OLDNEW
« no previous file with comments | « gyp/tests.gypi ('k') | tests/CanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698