From 7e49d534d71d3e7b053fe6f23dfe018ddbceb45b Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Tue, 11 Jul 2017 15:07:08 -0400 Subject: 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 Commit-Queue: Mike Reed --- tests/TextBlobTest.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'tests/TextBlobTest.cpp') 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 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 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 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 blob0 = builder.make(); - sk_sp img0 = render(blob0.get()); SkTDArray array; sk_sp data = blob0->serialize([&array](SkTypeface* tf) { @@ -455,16 +451,19 @@ DEF_TEST(TextBlob_serialize, reporter) { REPORTER_ASSERT(reporter, false); return sk_sp(nullptr); }); - sk_sp img1 = render(blob1.get()); - REPORTER_ASSERT(reporter, img0->width() == img1->width()); - REPORTER_ASSERT(reporter, img0->height() == img1->height()); - - sk_sp enc0(img0->encode()); - sk_sp 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 img0 = render(blob0.get()); + sk_sp img1 = render(blob1.get()); + if (img0 && img1) { + REPORTER_ASSERT(reporter, img0->width() == img1->width()); + REPORTER_ASSERT(reporter, img0->height() == img1->height()); + + sk_sp enc0(img0->encode()); + sk_sp 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()); + } } } -- cgit v1.2.3