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

Unified Diff: tests/AnnotationTest.cpp

Issue 12533009: PDF: add support for named destinations. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: attempt_to_fix_warnings_in_internal_links.cpp Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkGlobalInitialization_default.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/AnnotationTest.cpp
===================================================================
--- tests/AnnotationTest.cpp (revision 8005)
+++ tests/AnnotationTest.cpp (working copy)
@@ -12,6 +12,18 @@
#include "SkPDFDevice.h"
#include "SkPDFDocument.h"
+/** Returns true if data (may contain null characters) contains needle (null
+ * terminated). */
+static bool ContainsString(const char* data, size_t dataSize, const char* needle) {
+ size_t nSize = strlen(needle);
+ for (size_t i = 0; i < dataSize - nSize; i++) {
+ if (strncmp(&data[i], needle, nSize) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
static void test_nodraw(skiatest::Reporter* reporter) {
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
@@ -55,27 +67,38 @@
SkAutoDataUnref out(outStream.copyToData());
const char* rawOutput = (const char*)out->data();
- bool found = false;
- for (size_t i = 0; i < out->size() - 8; i++) {
- if (rawOutput[i + 0] == '/' &&
- rawOutput[i + 1] == 'A' &&
- rawOutput[i + 2] == 'n' &&
- rawOutput[i + 3] == 'n' &&
- rawOutput[i + 4] == 'o' &&
- rawOutput[i + 5] == 't' &&
- rawOutput[i + 6] == 's' &&
- rawOutput[i + 7] == ' ') {
- found = true;
- break;
- }
- }
- REPORTER_ASSERT(reporter, found == tests[testNum].expectAnnotations);
+ REPORTER_ASSERT(reporter,
+ ContainsString(rawOutput, out->size(), "/Annots ")
+ == tests[testNum].expectAnnotations);
}
}
+static void test_named_destination_annotations(skiatest::Reporter* reporter) {
+ SkISize size = SkISize::Make(612, 792);
+ SkMatrix initialTransform;
+ initialTransform.reset();
+ SkPDFDevice device(size, size, initialTransform);
+ SkCanvas canvas(&device);
+
+ SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72));
+ SkAutoDataUnref data(SkData::NewWithCString("example"));
+ SkAnnotateNamedDestination(&canvas, p, data.get());
+
+ SkPDFDocument doc;
+ doc.appendPage(&device);
+ SkDynamicMemoryWStream outStream;
+ doc.emitPDF(&outStream);
+ SkAutoDataUnref out(outStream.copyToData());
+ const char* rawOutput = (const char*)out->data();
+
+ REPORTER_ASSERT(reporter,
+ ContainsString(rawOutput, out->size(), "/example "));
+}
+
static void TestAnnotation(skiatest::Reporter* reporter) {
test_nodraw(reporter);
test_pdf_link_annotations(reporter);
+ test_named_destination_annotations(reporter);
}
#include "TestClassDef.h"
« no previous file with comments | « src/ports/SkGlobalInitialization_default.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698