aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/TextBlobTest.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-07-11 15:07:08 -0400
committerGravatar Mike Reed <reed@google.com>2017-07-11 19:45:04 +0000
commit7e49d534d71d3e7b053fe6f23dfe018ddbceb45b (patch)
treef7381846701467385866446cf35191af3a3c1787 /tests/TextBlobTest.cpp
parenta6cb441fc0fb37c883d79b87cb5d8bd66e5cb2ed (diff)
check for null surface in test
If the bounds of the blob are empty, we will request a zero-sized surface which will fail. Just check for that. Only expect this if the typeface is empty (e.g. faked out for testing) Bug: skia: Change-Id: Idcac0e9d4e2a5fe68926a33250015609b5c7e365 Reviewed-on: https://skia-review.googlesource.com/22360 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tests/TextBlobTest.cpp')
-rw-r--r--tests/TextBlobTest.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp
index cec7028056..60ad653dcc 100644
--- a/tests/TextBlobTest.cpp
+++ b/tests/TextBlobTest.cpp
@@ -409,6 +409,9 @@ static void add_run(SkTextBlobBuilder* builder, const char text[], SkScalar x, S
static sk_sp<SkImage> render(const SkTextBlob* blob) {
auto surf = SkSurface::MakeRasterN32Premul(SkScalarRoundToInt(blob->bounds().width()),
SkScalarRoundToInt(blob->bounds().height()));
+ if (!surf) {
+ return nullptr; // bounds are empty?
+ }
surf->getCanvas()->clear(SK_ColorWHITE);
surf->getCanvas()->drawTextBlob(blob, -blob->bounds().left(), -blob->bounds().top(), SkPaint());
return surf->makeImageSnapshot();
@@ -421,12 +424,6 @@ static sk_sp<SkImage> render(const SkTextBlob* blob) {
* Then draw the new instance and assert it draws the same as the original.
*/
DEF_TEST(TextBlob_serialize, reporter) {
- // test requires at least the default font
- if (!SkTypeface::MakeDefault()) {
- SkDebugf("TextBlob_serialize: missing default typeface\n");
- return;
- }
-
SkTextBlobBuilder builder;
sk_sp<SkTypeface> tf0;
@@ -435,7 +432,6 @@ DEF_TEST(TextBlob_serialize, reporter) {
add_run(&builder, "Hello", 10, 20, tf0);
add_run(&builder, "World", 10, 40, tf1);
sk_sp<SkTextBlob> blob0 = builder.make();
- sk_sp<SkImage> img0 = render(blob0.get());
SkTDArray<SkTypeface*> array;
sk_sp<SkData> data = blob0->serialize([&array](SkTypeface* tf) {
@@ -455,16 +451,19 @@ DEF_TEST(TextBlob_serialize, reporter) {
REPORTER_ASSERT(reporter, false);
return sk_sp<SkTypeface>(nullptr);
});
- sk_sp<SkImage> img1 = render(blob1.get());
- REPORTER_ASSERT(reporter, img0->width() == img1->width());
- REPORTER_ASSERT(reporter, img0->height() == img1->height());
-
- sk_sp<SkData> enc0(img0->encode());
- sk_sp<SkData> enc1(img1->encode());
- REPORTER_ASSERT(reporter, enc0->equals(enc1.get()));
- if (false) { // in case you want to actually see the images...
- SkFILEWStream("textblob_serialize_img0.png").write(enc0->data(), enc0->size());
- SkFILEWStream("textblob_serialize_img1.png").write(enc1->data(), enc1->size());
+ sk_sp<SkImage> img0 = render(blob0.get());
+ sk_sp<SkImage> img1 = render(blob1.get());
+ if (img0 && img1) {
+ REPORTER_ASSERT(reporter, img0->width() == img1->width());
+ REPORTER_ASSERT(reporter, img0->height() == img1->height());
+
+ sk_sp<SkData> enc0(img0->encode());
+ sk_sp<SkData> enc1(img1->encode());
+ REPORTER_ASSERT(reporter, enc0->equals(enc1.get()));
+ if (false) { // in case you want to actually see the images...
+ SkFILEWStream("textblob_serialize_img0.png").write(enc0->data(), enc0->size());
+ SkFILEWStream("textblob_serialize_img1.png").write(enc1->data(), enc1->size());
+ }
}
}