xref: /aosp_15_r20/external/skia/tests/SkPngRustEncoderTest.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2024 Google LLC.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "experimental/rust_png/encoder/SkPngRustEncoder.h"
9 
10 #include "include/core/SkBitmap.h"
11 #include "include/core/SkPixmap.h"
12 #include "include/core/SkStream.h"
13 #include "tests/Test.h"
14 #include "tools/DecodeUtils.h"
15 #include "tools/ToolUtils.h"
16 
DEF_TEST(Encode_png_Rust_smoke_test,r)17 DEF_TEST(Encode_png_Rust_smoke_test, r) {
18     SkBitmap bitmap;
19     bool success = ToolUtils::GetResourceAsBitmap("images/mandrill_128.png", &bitmap);
20     if (!success) {
21         return;
22     }
23 
24     SkPixmap src;
25     success = bitmap.peekPixels(&src);
26     REPORTER_ASSERT(r, success);
27     if (!success) {
28         return;
29     }
30 
31     SkDynamicMemoryWStream dst;
32     success = SkPngRustEncoder::Encode(&dst, src);
33     REPORTER_ASSERT(r, success);
34     if (!success) {
35         return;
36     }
37 
38     SkBitmap roundtrip;
39     success = ToolUtils::DecodeDataToBitmap(dst.detachAsData(), &roundtrip);
40     REPORTER_ASSERT(r, success);
41     if (!success) {
42         return;
43     }
44 
45     success = ToolUtils::equal_pixels(bitmap, roundtrip);
46     REPORTER_ASSERT(r, success);
47 }
48