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

Side by Side Diff: tests/AnnotationTest.cpp

Issue 100113004: Use DEFINE_TESTCLASS_SHORT macro in tests. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/AtomicTest.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 "Test.h" 8 #include "Test.h"
9 #include "TestClassDef.h"
9 #include "SkAnnotation.h" 10 #include "SkAnnotation.h"
10 #include "SkData.h" 11 #include "SkData.h"
11 #include "SkCanvas.h" 12 #include "SkCanvas.h"
12 #include "SkPDFDevice.h" 13 #include "SkPDFDevice.h"
13 #include "SkPDFDocument.h" 14 #include "SkPDFDocument.h"
14 15
15 /** Returns true if data (may contain null characters) contains needle (null 16 /** Returns true if data (may contain null characters) contains needle (null
16 * terminated). */ 17 * terminated). */
17 static bool ContainsString(const char* data, size_t dataSize, const char* needle ) { 18 static bool ContainsString(const char* data, size_t dataSize, const char* needle ) {
18 size_t nSize = strlen(needle); 19 size_t nSize = strlen(needle);
19 for (size_t i = 0; i < dataSize - nSize; i++) { 20 for (size_t i = 0; i < dataSize - nSize; i++) {
20 if (strncmp(&data[i], needle, nSize) == 0) { 21 if (strncmp(&data[i], needle, nSize) == 0) {
21 return true; 22 return true;
22 } 23 }
23 } 24 }
24 return false; 25 return false;
25 } 26 }
26 27
27 static void test_nodraw(skiatest::Reporter* reporter) { 28 DEF_TEST(Annotation_NoDraw, reporter) {
28 SkBitmap bm; 29 SkBitmap bm;
29 bm.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); 30 bm.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
30 bm.allocPixels(); 31 bm.allocPixels();
31 bm.eraseColor(SK_ColorTRANSPARENT); 32 bm.eraseColor(SK_ColorTRANSPARENT);
32 33
33 SkCanvas canvas(bm); 34 SkCanvas canvas(bm);
34 SkRect r = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10)); 35 SkRect r = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10));
35 36
36 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); 37 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com"));
37 38
38 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); 39 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
39 SkAnnotateRectWithURL(&canvas, r, data.get()); 40 SkAnnotateRectWithURL(&canvas, r, data.get());
40 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0)); 41 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
41 } 42 }
42 43
43 struct testCase { 44 struct testCase {
44 SkPDFDocument::Flags flags; 45 SkPDFDocument::Flags flags;
45 bool expectAnnotations; 46 bool expectAnnotations;
46 }; 47 };
47 48
48 static void test_pdf_link_annotations(skiatest::Reporter* reporter) { 49 DEF_TEST(Annotation_PdfLink, reporter) {
49 SkISize size = SkISize::Make(612, 792); 50 SkISize size = SkISize::Make(612, 792);
50 SkMatrix initialTransform; 51 SkMatrix initialTransform;
51 initialTransform.reset(); 52 initialTransform.reset();
52 SkPDFDevice device(size, size, initialTransform); 53 SkPDFDevice device(size, size, initialTransform);
53 SkCanvas canvas(&device); 54 SkCanvas canvas(&device);
54 55
55 SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72), 56 SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72),
56 SkIntToScalar(288), SkIntToScalar(72)); 57 SkIntToScalar(288), SkIntToScalar(72));
57 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com")); 58 SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com"));
58 SkAnnotateRectWithURL(&canvas, r, data.get()); 59 SkAnnotateRectWithURL(&canvas, r, data.get());
59 60
60 testCase tests[] = {{(SkPDFDocument::Flags)0, true}, 61 testCase tests[] = {{(SkPDFDocument::Flags)0, true},
61 {SkPDFDocument::kNoLinks_Flags, false}}; 62 {SkPDFDocument::kNoLinks_Flags, false}};
62 for (size_t testNum = 0; testNum < SK_ARRAY_COUNT(tests); testNum++) { 63 for (size_t testNum = 0; testNum < SK_ARRAY_COUNT(tests); testNum++) {
63 SkPDFDocument doc(tests[testNum].flags); 64 SkPDFDocument doc(tests[testNum].flags);
64 doc.appendPage(&device); 65 doc.appendPage(&device);
65 SkDynamicMemoryWStream outStream; 66 SkDynamicMemoryWStream outStream;
66 doc.emitPDF(&outStream); 67 doc.emitPDF(&outStream);
67 SkAutoDataUnref out(outStream.copyToData()); 68 SkAutoDataUnref out(outStream.copyToData());
68 const char* rawOutput = (const char*)out->data(); 69 const char* rawOutput = (const char*)out->data();
69 70
70 REPORTER_ASSERT(reporter, 71 REPORTER_ASSERT(reporter,
71 ContainsString(rawOutput, out->size(), "/Annots ") 72 ContainsString(rawOutput, out->size(), "/Annots ")
72 == tests[testNum].expectAnnotations); 73 == tests[testNum].expectAnnotations);
73 } 74 }
74 } 75 }
75 76
76 static void test_named_destination_annotations(skiatest::Reporter* reporter) { 77 DEF_TEST(Annotation_NamedDestination, reporter) {
77 SkISize size = SkISize::Make(612, 792); 78 SkISize size = SkISize::Make(612, 792);
78 SkMatrix initialTransform; 79 SkMatrix initialTransform;
79 initialTransform.reset(); 80 initialTransform.reset();
80 SkPDFDevice device(size, size, initialTransform); 81 SkPDFDevice device(size, size, initialTransform);
81 SkCanvas canvas(&device); 82 SkCanvas canvas(&device);
82 83
83 SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72)); 84 SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72));
84 SkAutoDataUnref data(SkData::NewWithCString("example")); 85 SkAutoDataUnref data(SkData::NewWithCString("example"));
85 SkAnnotateNamedDestination(&canvas, p, data.get()); 86 SkAnnotateNamedDestination(&canvas, p, data.get());
86 87
87 SkPDFDocument doc; 88 SkPDFDocument doc;
88 doc.appendPage(&device); 89 doc.appendPage(&device);
89 SkDynamicMemoryWStream outStream; 90 SkDynamicMemoryWStream outStream;
90 doc.emitPDF(&outStream); 91 doc.emitPDF(&outStream);
91 SkAutoDataUnref out(outStream.copyToData()); 92 SkAutoDataUnref out(outStream.copyToData());
92 const char* rawOutput = (const char*)out->data(); 93 const char* rawOutput = (const char*)out->data();
93 94
94 REPORTER_ASSERT(reporter, 95 REPORTER_ASSERT(reporter,
95 ContainsString(rawOutput, out->size(), "/example ")); 96 ContainsString(rawOutput, out->size(), "/example "));
96 } 97 }
97
98 static void TestAnnotation(skiatest::Reporter* reporter) {
99 test_nodraw(reporter);
100 test_pdf_link_annotations(reporter);
101 test_named_destination_annotations(reporter);
102 }
103
104 #include "TestClassDef.h"
105 DEFINE_TESTCLASS("Annotation", AnnotationClass, TestAnnotation)
OLDNEW
« no previous file with comments | « no previous file | tests/AtomicTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698