Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
AnnotationTest.cpp File Reference
#include "include/core/SkAnnotation.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkData.h"
#include "include/core/SkDocument.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypes.h"
#include "include/docs/SkPDFDocument.h"
#include "tests/Test.h"
#include <cstddef>
#include <cstring>

Go to the source code of this file.

Functions

static bool ContainsString (const char *data, size_t dataSize, const char *needle)
 
 DEF_TEST (Annotation_NoDraw, reporter)
 
 DEF_TEST (Annotation_PdfLink, reporter)
 
 DEF_TEST (Annotation_PdfDefineNamedDestination, reporter)
 

Function Documentation

◆ ContainsString()

static bool ContainsString ( const char *  data,
size_t  dataSize,
const char *  needle 
)
static

Returns true if data (may contain null characters) contains needle (null terminated).

Definition at line 28 of file AnnotationTest.cpp.

28 {
29 size_t nSize = strlen(needle);
30 for (size_t i = 0; i < dataSize - nSize; i++) {
31 if (strncmp(&data[i], needle, nSize) == 0) {
32 return true;
33 }
34 }
35 return false;
36}

◆ DEF_TEST() [1/3]

DEF_TEST ( Annotation_NoDraw  ,
reporter   
)

Definition at line 38 of file AnnotationTest.cpp.

38 {
39 SkBitmap bm;
40 bm.allocN32Pixels(10, 10);
42
43 SkCanvas canvas(bm);
45
46 sk_sp<SkData> data(SkData::MakeWithCString("http://www.gooogle.com"));
47
48 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
49 SkAnnotateRectWithURL(&canvas, r, data.get());
50 REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
51}
reporter
SK_API void SkAnnotateRectWithURL(SkCanvas *, const SkRect &, SkData *)
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
#define SkIntToScalar(x)
Definition SkScalar.h:57
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
uint32_t * getAddr32(int x, int y) const
Definition SkBitmap.h:1260
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
static sk_sp< SkData > MakeWithCString(const char cstr[])
Definition SkData.cpp:195
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ DEF_TEST() [2/3]

DEF_TEST ( Annotation_PdfDefineNamedDestination  ,
reporter   
)

Definition at line 72 of file AnnotationTest.cpp.

72 {
73 REQUIRE_PDF_DOCUMENT(Annotation_PdfNamedDestination, reporter);
74 SkDynamicMemoryWStream outStream;
75 auto doc = SkPDF::MakeDocument(&outStream);
76 SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
78
81 SkAnnotateNamedDestination(canvas, p, data.get());
82
83 doc->close();
84 sk_sp<SkData> out = outStream.detachAsData();
85 const char* rawOutput = (const char*)out->data();
86
88 ContainsString(rawOutput, out->size(), "/example "));
89}
static bool ContainsString(const char *data, size_t dataSize, const char *needle)
SK_API void SkAnnotateNamedDestination(SkCanvas *, const SkPoint &, SkData *)
#define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER)
Definition Test.h:485
sk_sp< SkData > detachAsData()
Definition SkStream.cpp:707
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
static constexpr SkPoint Make(float x, float y)

◆ DEF_TEST() [3/3]

DEF_TEST ( Annotation_PdfLink  ,
reporter   
)

Definition at line 53 of file AnnotationTest.cpp.

53 {
54 REQUIRE_PDF_DOCUMENT(Annotation_PdfLink, reporter);
55 SkDynamicMemoryWStream outStream;
56 auto doc = SkPDF::MakeDocument(&outStream);
57 SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
59
62 sk_sp<SkData> data(SkData::MakeWithCString("http://www.gooogle.com"));
63 SkAnnotateRectWithURL(canvas, r, data.get());
64
65 doc->close();
66 sk_sp<SkData> out = outStream.detachAsData();
67 const char* rawOutput = (const char*)out->data();
68
69 REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots "));
70}
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659