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(RustEncodePng_smoke_test,r)17 DEF_TEST(RustEncodePng_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 SkPngRustEncoder::Options options;
33 success = SkPngRustEncoder::Encode(&dst, src, options);
34 REPORTER_ASSERT(r, success);
35 if (!success) {
36 return;
37 }
38
39 SkBitmap roundtrip;
40 success = ToolUtils::DecodeDataToBitmap(dst.detachAsData(), &roundtrip);
41 REPORTER_ASSERT(r, success);
42 if (!success) {
43 return;
44 }
45
46 success = ToolUtils::equal_pixels(bitmap, roundtrip);
47 REPORTER_ASSERT(r, success);
48 }
49