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

Side by Side Diff: tests/AnnotationTest.cpp

Issue 968683002: PDF: Switch some unit tests to higher level API. (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 | « src/pdf/SkPDFCatalog.h ('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 "SkPDFCanon.h" 11 #include "SkDocument.h"
12 #include "SkPDFDevice.h" 12 #include "SkStream.h"
13 #include "SkPDFDocument.h"
14 #include "Test.h" 13 #include "Test.h"
15 14
16 /** Returns true if data (may contain null characters) contains needle (null 15 /** Returns true if data (may contain null characters) contains needle (null
17 * terminated). */ 16 * terminated). */
18 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 ) {
19 size_t nSize = strlen(needle); 18 size_t nSize = strlen(needle);
20 for (size_t i = 0; i < dataSize - nSize; i++) { 19 for (size_t i = 0; i < dataSize - nSize; i++) {
21 if (strncmp(&data[i], needle, nSize) == 0) { 20 if (strncmp(&data[i], needle, nSize) == 0) {
22 return true; 21 return true;
23 } 22 }
(...skipping 10 matching lines...) Expand all
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));
41 } 40 }
42 41
43 DEF_TEST(Annotation_PdfLink, reporter) { 42 DEF_TEST(Annotation_PdfLink, reporter) {
44 SkISize size = SkISize::Make(612, 792); 43 SkDynamicMemoryWStream outStream;
45 SkPDFCanon canon; 44 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
46 SkAutoTUnref<SkPDFDevice> device(SkPDFDevice::Create(size, 72.0f, &canon)); 45 SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
47 SkCanvas canvas(device.get()); 46 REPORTER_ASSERT(reporter, canvas);
48 47
49 SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72), 48 SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72),
50 SkIntToScalar(288), SkIntToScalar(72)); 49 SkIntToScalar(288), SkIntToScalar(72));
51 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); 50 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com"));
52 SkAnnotateRectWithURL(&canvas, r, data.get()); 51 SkAnnotateRectWithURL(canvas, r, data.get());
53 52
54 SkPDFDocument doc; 53 REPORTER_ASSERT(reporter, doc->close());
55 doc.appendPage(device.get());
56 SkDynamicMemoryWStream outStream;
57 doc.emitPDF(&outStream);
58 SkAutoDataUnref out(outStream.copyToData()); 54 SkAutoDataUnref out(outStream.copyToData());
59 const char* rawOutput = (const char*)out->data(); 55 const char* rawOutput = (const char*)out->data();
60 56
61 REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots ") ); 57 REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots ") );
62 } 58 }
63 59
64 DEF_TEST(Annotation_NamedDestination, reporter) { 60 DEF_TEST(Annotation_NamedDestination, reporter) {
65 SkISize size = SkISize::Make(612, 792); 61 SkDynamicMemoryWStream outStream;
66 SkPDFCanon canon; 62 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream));
67 SkAutoTUnref<SkPDFDevice> device(SkPDFDevice::Create(size, 72.0f, &canon)); 63 SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
68 SkCanvas canvas(device.get()); 64 REPORTER_ASSERT(reporter, canvas);
69 65
70 SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72)); 66 SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72));
71 SkAutoDataUnref data(SkData::NewWithCString("example")); 67 SkAutoDataUnref data(SkData::NewWithCString("example"));
72 SkAnnotateNamedDestination(&canvas, p, data.get()); 68 SkAnnotateNamedDestination(canvas, p, data.get());
73 69
74 SkPDFDocument doc; 70 REPORTER_ASSERT(reporter, doc->close());
75 doc.appendPage(device.get());
76 SkDynamicMemoryWStream outStream;
77 doc.emitPDF(&outStream);
78 SkAutoDataUnref out(outStream.copyToData()); 71 SkAutoDataUnref out(outStream.copyToData());
79 const char* rawOutput = (const char*)out->data(); 72 const char* rawOutput = (const char*)out->data();
80 73
81 REPORTER_ASSERT(reporter, 74 REPORTER_ASSERT(reporter,
82 ContainsString(rawOutput, out->size(), "/example ")); 75 ContainsString(rawOutput, out->size(), "/example "));
83 } 76 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFCatalog.h ('k') | tests/CanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698