From 8be96ccaf19bb16c73629d4017e6670a910e4849 Mon Sep 17 00:00:00 2001 From: li fengdy Date: Mon, 28 Oct 2024 11:17:02 +0800 Subject: [PATCH 01/13] fix the comment error --- include/tgfx/core/ImageInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tgfx/core/ImageInfo.h b/include/tgfx/core/ImageInfo.h index e6be895e..a0e29816 100644 --- a/include/tgfx/core/ImageInfo.h +++ b/include/tgfx/core/ImageInfo.h @@ -108,7 +108,7 @@ class ImageInfo { } /** - * Returns the byte size of the pixels, computed from the rowBytes and width. + * Returns the byte size of the pixels, computed from the rowBytes and height. */ size_t byteSize() const { return _rowBytes * static_cast(_height); From 8d000eec5949995826eb6bed7f2b91214cf63eba Mon Sep 17 00:00:00 2001 From: li fengdy Date: Mon, 28 Oct 2024 11:18:56 +0800 Subject: [PATCH 02/13] fix the comment error --- include/tgfx/core/ImageInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tgfx/core/ImageInfo.h b/include/tgfx/core/ImageInfo.h index a0e29816..e6be895e 100644 --- a/include/tgfx/core/ImageInfo.h +++ b/include/tgfx/core/ImageInfo.h @@ -108,7 +108,7 @@ class ImageInfo { } /** - * Returns the byte size of the pixels, computed from the rowBytes and height. + * Returns the byte size of the pixels, computed from the rowBytes and width. */ size_t byteSize() const { return _rowBytes * static_cast(_height); From c40926b0d3d416bd30a05c7a2ccccf48636c78eb Mon Sep 17 00:00:00 2001 From: illidanstormrange <1753894329@qq.com> Date: Mon, 28 Oct 2024 14:05:49 +0800 Subject: [PATCH 03/13] fix the comment error --- include/tgfx/core/ImageInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tgfx/core/ImageInfo.h b/include/tgfx/core/ImageInfo.h index e6be895e..a0e29816 100644 --- a/include/tgfx/core/ImageInfo.h +++ b/include/tgfx/core/ImageInfo.h @@ -108,7 +108,7 @@ class ImageInfo { } /** - * Returns the byte size of the pixels, computed from the rowBytes and width. + * Returns the byte size of the pixels, computed from the rowBytes and height. */ size_t byteSize() const { return _rowBytes * static_cast(_height); From 0df774ed6eb8ae7cf54766b095807da3ccd5bc97 Mon Sep 17 00:00:00 2001 From: illidanstormrange <1753894329@qq.com> Date: Mon, 28 Oct 2024 14:37:12 +0800 Subject: [PATCH 04/13] Add some path and canvas unit test --- test/src/CanvasTest.cpp | 45 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/test/src/CanvasTest.cpp b/test/src/CanvasTest.cpp index 101d8645..27a98e7a 100644 --- a/test/src/CanvasTest.cpp +++ b/test/src/CanvasTest.cpp @@ -276,7 +276,7 @@ TGFX_TEST(CanvasTest, textShape) { auto newline = [&]() { x = 0; height += lineHeight; - path.moveTo(0, height); + path.moveTo(Point{0, height}); }; newline(); for (size_t i = 0; i < count; ++i) { @@ -296,7 +296,7 @@ TGFX_TEST(CanvasTest, textShape) { run->ids.emplace_back(glyphID); run->positions.push_back(Point{x, height}); x += run->font.getAdvance(glyphID); - path.lineTo(x, height); + path.lineTo(Point{x, height}); if (width < x) { width = x; } @@ -495,7 +495,7 @@ TGFX_TEST(CanvasTest, path) { ASSERT_TRUE(device != nullptr); auto context = device->lockContext(); ASSERT_TRUE(context != nullptr); - auto surface = Surface::Make(context, 500, 500); + auto surface = Surface::Make(context, 700, 500); auto canvas = surface->getCanvas(); Path path; path.addRect(Rect::MakeXYWH(10, 10, 100, 100)); @@ -549,10 +549,49 @@ TGFX_TEST(CanvasTest, path) { canvas->drawLine(200, 50, 400, 50, paint); paint.setLineCap(LineCap::Round); canvas->drawLine(200, 320, 400, 320, paint); + path.reset(); + path.quadTo(Point{100, 150}, Point{150, 150}); + paint.setColor(Color::White()); + matrix.reset(); + matrix.postTranslate(500, 10); + canvas->setMatrix(matrix); + canvas->drawPath(path, paint); EXPECT_TRUE(Baseline::Compare(surface, "CanvasTest/path")); device->unlock(); } +TGFX_TEST(CanvasTest, shape) { + auto device = DevicePool::Make(); + ASSERT_TRUE(device != nullptr); + auto context = device->lockContext(); + ASSERT_TRUE(context != nullptr); + auto width = 400; + auto height = 500; + auto surface = Surface::Make(context, width, height); + auto canvas = surface->getCanvas(); + canvas->clearRect(Rect::MakeWH(surface->width(), surface->height()), Color::White()); + auto image = MakeImage("resources/apitest/imageReplacement.png"); + ASSERT_TRUE(image != nullptr); + Paint paint; + paint.setStyle(PaintStyle::Stroke); + paint.setStroke(Stroke(0)); + EXPECT_TRUE(paint.nothingToDraw()); + paint.setStrokeWidth(2); + paint.setColor(Color{1.f, 0.f, 0.f, 1.f}); + auto point = Point::Make(width / 2, height / 2); + auto radius = image->width() / 2; + auto rect = Rect::MakeWH(radius * 2, radius * 2); + canvas->drawCircle(point, radius + 30, paint); + canvas->setMatrix(Matrix::MakeTrans(point.x - radius, point.y - radius)); + canvas->drawRoundRect(rect, 10, 10, paint); + + canvas->setMatrix(Matrix::MakeTrans(point.x - radius, point.y - radius)); + canvas->rotate(45, radius, radius); + canvas->drawImage(image, SamplingOptions(FilterMode::Linear)); + EXPECT_TRUE(Baseline::Compare(surface, "CanvasTest/shape")); + device->unlock(); +} + TGFX_TEST(CanvasTest, image) { auto device = DevicePool::Make(); ASSERT_TRUE(device != nullptr); From 334f2ac01af5806e2af703f370b9085d928f3ee9 Mon Sep 17 00:00:00 2001 From: illidanstormrange Date: Tue, 29 Oct 2024 17:45:33 +0800 Subject: [PATCH 05/13] Add some unit tests related to NativeCodec and DataView. --- test/baseline/version.json | 4 +++ test/src/ReadPixelsTest.cpp | 57 ++++++++++++++++++++++++++++++++++++ test/src/utils/TestUtils.cpp | 4 +++ test/src/utils/TestUtils.h | 2 ++ 4 files changed, 67 insertions(+) diff --git a/test/baseline/version.json b/test/baseline/version.json index a89d5de0..ff8d62fb 100644 --- a/test/baseline/version.json +++ b/test/baseline/version.json @@ -78,6 +78,10 @@ "JpegCodec_Encode_Gray8": "d010fb8", "JpegCodec_Encode_RGB565": "d010fb8", "JpegCodec_Encode_RGBA": "d010fb8", + "NativeCodec_Decode_Alpha8": "840f02f", + "NativeCodec_Decode_RGBA": "840f02f", + "NativeCodec_Encode_Alpha8": "840f02f", + "NativeCodec_Encode_RGBA": "840f02f", "PixelMap_BGRA_to_BGRA": "d010fb8", "PixelMap_BGRA_to_RGBA": "d010fb8", "PixelMap_BGRA_to_rgb_A": "d010fb8", diff --git a/test/src/ReadPixelsTest.cpp b/test/src/ReadPixelsTest.cpp index 3ae1573f..04de003a 100644 --- a/test/src/ReadPixelsTest.cpp +++ b/test/src/ReadPixelsTest.cpp @@ -16,6 +16,8 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// +#include +#include #include #include "gpu/opengl/GLUtil.h" #include "tgfx/core/Buffer.h" @@ -436,4 +438,59 @@ TGFX_TEST(ReadPixelsTest, JpegCodec) { CHECK_PIXELS(RGB565Info, pixels, "JpegCodec_Encode_RGB565"); } +TGFX_TEST(ReadPixelsTest, NativeCodec) { + auto rgbaCodec = MakeNativeCodec("resources/apitest/test_timestretch.png"); + ASSERT_TRUE(rgbaCodec != nullptr); + ASSERT_EQ(rgbaCodec->width(), 1280); + ASSERT_EQ(rgbaCodec->height(), 720); + ASSERT_EQ(rgbaCodec->orientation(), Orientation::TopLeft); + auto RGBAInfo = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::RGBA_8888, + AlphaType::Premultiplied); + Buffer buffer(RGBAInfo.byteSize()); + auto pixels = buffer.data(); + ASSERT_TRUE(pixels); + ASSERT_TRUE(rgbaCodec->readPixels(RGBAInfo, pixels)); + CHECK_PIXELS(RGBAInfo, pixels, "NativeCodec_Decode_RGBA"); + auto bytes = ImageCodec::Encode(Pixmap(RGBAInfo, pixels), EncodedFormat::PNG, 100); + auto codec = ImageCodec::MakeNativeCodec(bytes); + ASSERT_TRUE(codec != nullptr); + ASSERT_EQ(codec->width(), 1280); + ASSERT_EQ(codec->height(), 720); + ASSERT_EQ(codec->orientation(), Orientation::TopLeft); + buffer.clear(); + ASSERT_TRUE(codec->readPixels(RGBAInfo, pixels)); + CHECK_PIXELS(RGBAInfo, pixels, "NativeCodec_Encode_RGBA"); + + auto A8Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::ALPHA_8, + AlphaType::Premultiplied); + buffer.clear(); + ASSERT_TRUE(rgbaCodec->readPixels(A8Info, pixels)); + CHECK_PIXELS(A8Info, pixels, "NativeCodec_Decode_Alpha8"); + bytes = ImageCodec::Encode(Pixmap(A8Info, pixels), EncodedFormat::PNG, 100); + codec = ImageCodec::MakeNativeCodec(bytes); + ASSERT_TRUE(codec != nullptr); + buffer.clear(); + ASSERT_TRUE(codec->readPixels(A8Info, pixels)); + CHECK_PIXELS(A8Info, pixels, "NativeCodec_Encode_Alpha8"); +} + +TGFX_TEST(ImageReaderTest, dataCheck) { + auto stream = Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); + ASSERT_TRUE(stream != nullptr && stream->size() >= 14); + Buffer buffer(14); + ASSERT_TRUE(stream->read(buffer.data(), 14) == 14); + auto data = DataView(buffer.bytes(), buffer.size()); + auto secondByte = data.getUint8(1); + auto thirdByte = data.getUint8(2); + auto fouthByte = data.getUint8(3); + ASSERT_TRUE(secondByte == 'P' && thirdByte == 'N' && fouthByte == 'G'); + buffer.clear(); + data.setUint8(1, 'J'); + data.setUint8(2, 'P'); + data.setUint8(3, 'G'); + secondByte = data.getUint8(1); + thirdByte = data.getUint8(2); + fouthByte = data.getUint8(3); + ASSERT_TRUE(secondByte == 'J' && thirdByte == 'P' && fouthByte == 'G'); +} } // namespace tgfx diff --git a/test/src/utils/TestUtils.cpp b/test/src/utils/TestUtils.cpp index 06aff54b..0a243f45 100644 --- a/test/src/utils/TestUtils.cpp +++ b/test/src/utils/TestUtils.cpp @@ -50,6 +50,10 @@ std::shared_ptr MakeImageCodec(const std::string& path) { return ImageCodec::MakeFrom(ProjectPath::Absolute(path)); } +std::shared_ptr MakeNativeCodec(const std::string& path) { + return ImageCodec::MakeNativeCodec(ProjectPath::Absolute(path)); +} + std::shared_ptr MakeImage(const std::string& path) { return Image::MakeFromFile(ProjectPath::Absolute(path)); } diff --git a/test/src/utils/TestUtils.h b/test/src/utils/TestUtils.h index d672bd92..2abe5a7a 100644 --- a/test/src/utils/TestUtils.h +++ b/test/src/utils/TestUtils.h @@ -35,6 +35,8 @@ bool CreateGLTexture(Context* context, int width, int height, GLTextureInfo* tex std::shared_ptr MakeImageCodec(const std::string& path); +std::shared_ptr MakeNativeCodec(const std::string& path); + std::shared_ptr MakeImage(const std::string& path); std::shared_ptr MakeTypeface(const std::string& path); From 97d940f9b4da29e904e73c60e7bf6c2e72d6c78c Mon Sep 17 00:00:00 2001 From: illidanstormrange Date: Tue, 29 Oct 2024 17:56:46 +0800 Subject: [PATCH 06/13] Fix code format check error --- test/src/ReadPixelsTest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/src/ReadPixelsTest.cpp b/test/src/ReadPixelsTest.cpp index 04de003a..43d3fb20 100644 --- a/test/src/ReadPixelsTest.cpp +++ b/test/src/ReadPixelsTest.cpp @@ -474,8 +474,9 @@ TGFX_TEST(ReadPixelsTest, NativeCodec) { CHECK_PIXELS(A8Info, pixels, "NativeCodec_Encode_Alpha8"); } -TGFX_TEST(ImageReaderTest, dataCheck) { - auto stream = Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); +TGFX_TEST(ImageReaderTest, DataCheck) { + auto stream = + Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); ASSERT_TRUE(stream != nullptr && stream->size() >= 14); Buffer buffer(14); ASSERT_TRUE(stream->read(buffer.data(), 14) == 14); From c1936129b8f1f4cfb8a9d721df0cc5ae912a13dd Mon Sep 17 00:00:00 2001 From: illidanstormrange Date: Tue, 29 Oct 2024 18:43:15 +0800 Subject: [PATCH 07/13] Fix code format check error --- test/src/ReadPixelsTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/ReadPixelsTest.cpp b/test/src/ReadPixelsTest.cpp index 43d3fb20..46da5a2d 100644 --- a/test/src/ReadPixelsTest.cpp +++ b/test/src/ReadPixelsTest.cpp @@ -476,7 +476,7 @@ TGFX_TEST(ReadPixelsTest, NativeCodec) { TGFX_TEST(ImageReaderTest, DataCheck) { auto stream = - Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); + Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); ASSERT_TRUE(stream != nullptr && stream->size() >= 14); Buffer buffer(14); ASSERT_TRUE(stream->read(buffer.data(), 14) == 14); From 4a6d08017e429c5f368541b4cc1bbf4dfa179658 Mon Sep 17 00:00:00 2001 From: illidanstormrange Date: Wed, 30 Oct 2024 15:11:31 +0800 Subject: [PATCH 08/13] Add DataView unit Test, delete extra unit test in ReadPixelsTest --- test/src/DataViewTest.cpp | 83 +++++++++++++++++++++++++++++++++++++ test/src/ReadPixelsTest.cpp | 23 ---------- 2 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 test/src/DataViewTest.cpp diff --git a/test/src/DataViewTest.cpp b/test/src/DataViewTest.cpp new file mode 100644 index 00000000..c4cfccae --- /dev/null +++ b/test/src/DataViewTest.cpp @@ -0,0 +1,83 @@ +///////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tencent is pleased to support the open source community by making tgfx available. +// +// Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// unless required by applicable law or agreed to in writing, software distributed under the +// license is distributed on an "as is" basis, without warranties or conditions of any kind, +// either express or implied. see the license for the specific language governing permissions +// and limitations under the license. +// +///////////////////////////////////////////////////////////////////////////////////////////////// +#include +#include +#include +#include "tgfx/core/Buffer.h" +#include "utils/TestUtils.h" + +namespace tgfx{ +TGFX_TEST(DataViewTest, PNGDataCheck) { + auto stream = + Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); + ASSERT_TRUE(stream != nullptr && stream->size() >= 14); + Buffer buffer(14); + ASSERT_TRUE(stream->read(buffer.data(), 14) == 14); + auto data = DataView(buffer.bytes(), buffer.size()); + auto secondByte = data.getUint8(1); + auto thirdByte = data.getUint8(2); + auto fourthByte = data.getUint8(3); + ASSERT_TRUE(secondByte == 'P' && thirdByte == 'N' && fourthByte == 'G'); + buffer.clear(); +} + +TGFX_TEST(DataViewTest, ReadString) { + Buffer buffer(100); + std::string text = "Hello TGFX 123"; + auto dataView = DataView(buffer.bytes(), buffer.size()); + const char* textStart = text.data(); + const char* textStop = textStart + text.size(); + while (textStart < textStop) { + auto offset = text.size() - static_cast(textStop - textStart); + auto unichar = UTF::NextUTF8(&textStart, textStop); + dataView.setInt32(offset, unichar); + } + ASSERT_EQ(std::string((char*)buffer.bytes()), text); +} + +TGFX_TEST(DataViewTest, ReadWriteData) { + Buffer buffer(100); + auto dataView = DataView(buffer.bytes(), buffer.size()); + dataView.setInt8(0, 'T'); + dataView.setUint8(1, 0xFF); + dataView.setInt16(2, 'G'); + dataView.setUint16(4, 0xFFFF); + dataView.setInt32(6, 'F'); + dataView.setUint32(10, 0xFFFFFFFF); + dataView.setInt64(14, 'X'); + dataView.setUint64(22, 0xFFFFFFFFFFFFFFFF); + dataView.setFloat(30, 1.123f); + dataView.setDouble(34, 1.0E+39); + ASSERT_TRUE(dataView.getInt8(0) == 'T'); + ASSERT_TRUE(dataView.getUint8(1) == 0xFF); + ASSERT_TRUE(dataView.getInt16(2) == 'G'); + ASSERT_TRUE(dataView.getUint16(4) == 0xFFFF); + ASSERT_TRUE(dataView.getInt32(6) == 'F'); + ASSERT_TRUE(dataView.getUint32(10) == 0xFFFFFFFF); + ASSERT_TRUE(dataView.getInt64(14) == 'X'); + ASSERT_TRUE(dataView.getUint64(22) == 0xFFFFFFFFFFFFFFFF); + ASSERT_TRUE(dataView.getFloat(30) == 1.123f); + ASSERT_TRUE(dataView.getDouble(34) == 1.0E+39); + buffer.clear(); + dataView.setByteOrder(ByteOrder::BigEndian); + dataView.setUint16(0, 0x1234); + ASSERT_TRUE(dataView.getUint16(0) == 0x1234); + dataView.setByteOrder(ByteOrder::LittleEndian); + ASSERT_TRUE(dataView.getUint16(0) == 0x3412); +} +} \ No newline at end of file diff --git a/test/src/ReadPixelsTest.cpp b/test/src/ReadPixelsTest.cpp index 46da5a2d..c320d592 100644 --- a/test/src/ReadPixelsTest.cpp +++ b/test/src/ReadPixelsTest.cpp @@ -16,8 +16,6 @@ // ///////////////////////////////////////////////////////////////////////////////////////////////// -#include -#include #include #include "gpu/opengl/GLUtil.h" #include "tgfx/core/Buffer.h" @@ -473,25 +471,4 @@ TGFX_TEST(ReadPixelsTest, NativeCodec) { ASSERT_TRUE(codec->readPixels(A8Info, pixels)); CHECK_PIXELS(A8Info, pixels, "NativeCodec_Encode_Alpha8"); } - -TGFX_TEST(ImageReaderTest, DataCheck) { - auto stream = - Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); - ASSERT_TRUE(stream != nullptr && stream->size() >= 14); - Buffer buffer(14); - ASSERT_TRUE(stream->read(buffer.data(), 14) == 14); - auto data = DataView(buffer.bytes(), buffer.size()); - auto secondByte = data.getUint8(1); - auto thirdByte = data.getUint8(2); - auto fouthByte = data.getUint8(3); - ASSERT_TRUE(secondByte == 'P' && thirdByte == 'N' && fouthByte == 'G'); - buffer.clear(); - data.setUint8(1, 'J'); - data.setUint8(2, 'P'); - data.setUint8(3, 'G'); - secondByte = data.getUint8(1); - thirdByte = data.getUint8(2); - fouthByte = data.getUint8(3); - ASSERT_TRUE(secondByte == 'J' && thirdByte == 'P' && fouthByte == 'G'); -} } // namespace tgfx From 374bd4bec3a3928bf92589d7a4ad0c250d063ea1 Mon Sep 17 00:00:00 2001 From: illidanstormrange Date: Wed, 30 Oct 2024 16:17:58 +0800 Subject: [PATCH 09/13] Fix code format error --- test/src/DataViewTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/DataViewTest.cpp b/test/src/DataViewTest.cpp index c4cfccae..fae908a1 100644 --- a/test/src/DataViewTest.cpp +++ b/test/src/DataViewTest.cpp @@ -21,7 +21,7 @@ #include "tgfx/core/Buffer.h" #include "utils/TestUtils.h" -namespace tgfx{ +namespace tgfx { TGFX_TEST(DataViewTest, PNGDataCheck) { auto stream = Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); @@ -80,4 +80,4 @@ TGFX_TEST(DataViewTest, ReadWriteData) { dataView.setByteOrder(ByteOrder::LittleEndian); ASSERT_TRUE(dataView.getUint16(0) == 0x3412); } -} \ No newline at end of file +} // namespace tgfx From 42af755559951d2cf5829314368bcb6726f27202 Mon Sep 17 00:00:00 2001 From: illidanstormrange Date: Wed, 30 Oct 2024 19:28:31 +0800 Subject: [PATCH 10/13] Change some Assert to Expect, initialize all buffer data to 0 --- test/src/DataViewTest.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/src/DataViewTest.cpp b/test/src/DataViewTest.cpp index fae908a1..aac381ba 100644 --- a/test/src/DataViewTest.cpp +++ b/test/src/DataViewTest.cpp @@ -25,9 +25,10 @@ namespace tgfx { TGFX_TEST(DataViewTest, PNGDataCheck) { auto stream = Stream::MakeFromFile(ProjectPath::Absolute("resources/apitest/test_timestretch.png")); - ASSERT_TRUE(stream != nullptr && stream->size() >= 14); + ASSERT_TRUE(stream != nullptr); + EXPECT_TRUE(stream->size() >= 14); Buffer buffer(14); - ASSERT_TRUE(stream->read(buffer.data(), 14) == 14); + EXPECT_TRUE(stream->read(buffer.data(), 14) == 14); auto data = DataView(buffer.bytes(), buffer.size()); auto secondByte = data.getUint8(1); auto thirdByte = data.getUint8(2); @@ -38,6 +39,7 @@ TGFX_TEST(DataViewTest, PNGDataCheck) { TGFX_TEST(DataViewTest, ReadString) { Buffer buffer(100); + memset(buffer.bytes(), 0, buffer.size()); std::string text = "Hello TGFX 123"; auto dataView = DataView(buffer.bytes(), buffer.size()); const char* textStart = text.data(); From bf86e1517e37a0659b0acff6a2c81ffb9c90cb0f Mon Sep 17 00:00:00 2001 From: illidanstormrange Date: Wed, 30 Oct 2024 19:52:54 +0800 Subject: [PATCH 11/13] Change Assert to Expect, Prevent program abort when a test fails --- test/src/DataViewTest.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/src/DataViewTest.cpp b/test/src/DataViewTest.cpp index aac381ba..5928760e 100644 --- a/test/src/DataViewTest.cpp +++ b/test/src/DataViewTest.cpp @@ -33,7 +33,7 @@ TGFX_TEST(DataViewTest, PNGDataCheck) { auto secondByte = data.getUint8(1); auto thirdByte = data.getUint8(2); auto fourthByte = data.getUint8(3); - ASSERT_TRUE(secondByte == 'P' && thirdByte == 'N' && fourthByte == 'G'); + EXPECT_TRUE(secondByte == 'P' && thirdByte == 'N' && fourthByte == 'G'); buffer.clear(); } @@ -49,7 +49,7 @@ TGFX_TEST(DataViewTest, ReadString) { auto unichar = UTF::NextUTF8(&textStart, textStop); dataView.setInt32(offset, unichar); } - ASSERT_EQ(std::string((char*)buffer.bytes()), text); + EXPECT_EQ(std::string((char*)buffer.bytes(), text.size()), text); } TGFX_TEST(DataViewTest, ReadWriteData) { @@ -65,21 +65,21 @@ TGFX_TEST(DataViewTest, ReadWriteData) { dataView.setUint64(22, 0xFFFFFFFFFFFFFFFF); dataView.setFloat(30, 1.123f); dataView.setDouble(34, 1.0E+39); - ASSERT_TRUE(dataView.getInt8(0) == 'T'); - ASSERT_TRUE(dataView.getUint8(1) == 0xFF); - ASSERT_TRUE(dataView.getInt16(2) == 'G'); - ASSERT_TRUE(dataView.getUint16(4) == 0xFFFF); - ASSERT_TRUE(dataView.getInt32(6) == 'F'); - ASSERT_TRUE(dataView.getUint32(10) == 0xFFFFFFFF); - ASSERT_TRUE(dataView.getInt64(14) == 'X'); - ASSERT_TRUE(dataView.getUint64(22) == 0xFFFFFFFFFFFFFFFF); - ASSERT_TRUE(dataView.getFloat(30) == 1.123f); - ASSERT_TRUE(dataView.getDouble(34) == 1.0E+39); + EXPECT_TRUE(dataView.getInt8(0) == 'T'); + EXPECT_TRUE(dataView.getUint8(1) == 0xFF); + EXPECT_TRUE(dataView.getInt16(2) == 'G'); + EXPECT_TRUE(dataView.getUint16(4) == 0xFFFF); + EXPECT_TRUE(dataView.getInt32(6) == 'F'); + EXPECT_TRUE(dataView.getUint32(10) == 0xFFFFFFFF); + EXPECT_TRUE(dataView.getInt64(14) == 'X'); + EXPECT_TRUE(dataView.getUint64(22) == 0xFFFFFFFFFFFFFFFF); + EXPECT_TRUE(dataView.getFloat(30) == 1.123f); + EXPECT_TRUE(dataView.getDouble(34) == 1.0E+39); buffer.clear(); dataView.setByteOrder(ByteOrder::BigEndian); dataView.setUint16(0, 0x1234); - ASSERT_TRUE(dataView.getUint16(0) == 0x1234); + EXPECT_TRUE(dataView.getUint16(0) == 0x1234); dataView.setByteOrder(ByteOrder::LittleEndian); - ASSERT_TRUE(dataView.getUint16(0) == 0x3412); + EXPECT_TRUE(dataView.getUint16(0) == 0x3412); } } // namespace tgfx From 3a74c2ece10ea5fd16e467839f7a5fca2fd01ddf Mon Sep 17 00:00:00 2001 From: illidanstormrange Date: Thu, 31 Oct 2024 10:23:16 +0800 Subject: [PATCH 12/13] Change Assert to Expect, Prevent program abort when a test fails --- test/src/CanvasTest.cpp | 4 +- test/src/MaskTest.cpp | 2 +- test/src/ReadPixelsTest.cpp | 140 ++++++++++++++++++------------------ 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/test/src/CanvasTest.cpp b/test/src/CanvasTest.cpp index 1e7d2f01..d2f5d035 100644 --- a/test/src/CanvasTest.cpp +++ b/test/src/CanvasTest.cpp @@ -422,7 +422,7 @@ TGFX_TEST(CanvasTest, mipmap) { Pixmap pixmap(bitmap); auto result = codec->readPixels(pixmap.info(), pixmap.writablePixels()); pixmap.reset(); - ASSERT_TRUE(result); + EXPECT_TRUE(result); auto imageBuffer = bitmap.makeBuffer(); auto image = Image::MakeFrom(imageBuffer); ASSERT_TRUE(image != nullptr); @@ -471,7 +471,7 @@ TGFX_TEST(CanvasTest, hardwareMipmap) { Pixmap pixmap(bitmap); auto result = codec->readPixels(pixmap.info(), pixmap.writablePixels()); pixmap.reset(); - ASSERT_TRUE(result); + EXPECT_TRUE(result); auto image = Image::MakeFrom(bitmap); auto imageMipmapped = image->makeMipmapped(true); ASSERT_TRUE(imageMipmapped != nullptr); diff --git a/test/src/MaskTest.cpp b/test/src/MaskTest.cpp index 4e6a4b2c..074fa402 100644 --- a/test/src/MaskTest.cpp +++ b/test/src/MaskTest.cpp @@ -54,7 +54,7 @@ TGFX_TEST(MaskTest, Rasterize) { Pixmap pixmap(bitmap); pixmap.clear(); auto result = surface->readPixels(pixmap.info(), pixmap.writablePixels()); - ASSERT_TRUE(result); + EXPECT_TRUE(result); EXPECT_TRUE(Baseline::Compare(pixmap, "MaskTest/rasterize_path_texture")); auto typeface = diff --git a/test/src/ReadPixelsTest.cpp b/test/src/ReadPixelsTest.cpp index c320d592..b14e27ee 100644 --- a/test/src/ReadPixelsTest.cpp +++ b/test/src/ReadPixelsTest.cpp @@ -55,41 +55,41 @@ TGFX_TEST(ReadPixelsTest, PixelMap) { pixelsB.clear(); auto RGB565Info = RGBAInfo.makeColorType(ColorType::RGB_565); result = RGBAMap.readPixels(RGB565Info, pixelsB.data()); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGB565Info, pixelsB.data(), "PixelMap_RGBA_to_RGB565"); pixelsB.clear(); auto Gray8Info = RGBAInfo.makeColorType(ColorType::Gray_8); result = RGBAMap.readPixels(Gray8Info, pixelsB.data()); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(Gray8Info, pixelsB.data(), "PixelMap_RGBA_to_Gray8"); pixelsB.clear(); auto RGBAF16Info = RGBAInfo.makeColorType(ColorType::RGBA_F16); result = RGBAMap.readPixels(RGBAF16Info, pixelsB.data()); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBAF16Info, pixelsB.data(), "PixelMap_RGBA_to_RGBA_F16"); pixelsB.clear(); auto RGBA1010102Info = RGBAInfo.makeColorType(ColorType::RGBA_1010102); result = RGBAMap.readPixels(RGBA1010102Info, pixelsB.data()); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBA1010102Info, pixelsB.data(), "PixelMap_RGBA_to_RGBA_1010102"); pixelsB.clear(); result = RGBAMap.readPixels(RGBAInfo, pixelsB.data(), 100, 100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixelsB.data(), "PixelMap_RGBA_to_RGBA_100_100"); auto RGBARectInfo = ImageInfo::Make(500, 500, ColorType::RGBA_8888, AlphaType::Premultiplied); pixelsB.clear(); result = RGBAMap.readPixels(RGBARectInfo, pixelsB.data(), -100, -100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBARectInfo, pixelsB.data(), "PixelMap_RGBA_to_RGBA_-100_-100"); pixelsB.clear(); result = RGBAMap.readPixels(RGBARectInfo, pixelsB.data(), 100, -100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBARectInfo, pixelsB.data(), "PixelMap_RGBA_to_RGBA_100_-100"); auto rgb_AInfo = RGBAInfo.makeAlphaType(AlphaType::Premultiplied); @@ -163,7 +163,7 @@ TGFX_TEST(ReadPixelsTest, Surface) { auto pixels = bitmap.lockPixels(); auto result = codec->readPixels(bitmap.info(), pixels); bitmap.unlockPixels(); - ASSERT_TRUE(result); + EXPECT_TRUE(result); auto device = DevicePool::Make(); ASSERT_TRUE(device != nullptr); @@ -182,28 +182,28 @@ TGFX_TEST(ReadPixelsTest, Surface) { auto RGBAInfo = ImageInfo::Make(width, height, ColorType::RGBA_8888, AlphaType::Premultiplied); result = surface->readPixels(RGBAInfo, pixels); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixels, "Surface_rgb_A_to_rgb_A"); auto BGRAInfo = ImageInfo::Make(width, height, ColorType::BGRA_8888, AlphaType::Premultiplied); result = surface->readPixels(BGRAInfo, pixels); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(BGRAInfo, pixels, "Surface_rgb_A_to_bgr_A"); memset(pixels, 0, RGBAInfo.byteSize()); result = surface->readPixels(RGBAInfo, pixels, 100, 100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixels, "Surface_rgb_A_to_rgb_A_100_100"); auto RGBARectInfo = ImageInfo::Make(500, 500, ColorType::RGBA_8888, AlphaType::Premultiplied); memset(pixels, 0, RGBARectInfo.byteSize()); result = surface->readPixels(RGBARectInfo, pixels, -100, -100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBARectInfo, pixels, "Surface_rgb_A_to_rgb_A_-100_-100"); memset(pixels, 0, RGBARectInfo.byteSize()); result = surface->readPixels(RGBARectInfo, pixels, 100, -100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBARectInfo, pixels, "Surface_rgb_A_to_rgb_A_100_-100"); surface = Surface::Make(context, width, height, true); @@ -213,22 +213,22 @@ TGFX_TEST(ReadPixelsTest, Surface) { auto A8Info = ImageInfo::Make(width, height, ColorType::ALPHA_8, AlphaType::Premultiplied); result = surface->readPixels(A8Info, pixels); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(A8Info, pixels, "Surface_alpha_to_alpha"); result = surface->readPixels(RGBAInfo, pixels); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixels, "Surface_alpha_to_rgba"); auto AlphaRectInfo = ImageInfo::Make(500, 500, ColorType::ALPHA_8, AlphaType::Premultiplied); memset(pixels, 0, AlphaRectInfo.byteSize()); result = surface->readPixels(AlphaRectInfo, pixels, 100, -100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(AlphaRectInfo, pixels, "Surface_alpha_to_alpha_100_-100"); GLTextureInfo textureInfo = {}; result = CreateGLTexture(context, width, height, &textureInfo); - ASSERT_TRUE(result); + EXPECT_TRUE(result); surface = Surface::MakeFrom(context, {textureInfo, width, height}, ImageOrigin::BottomLeft); ASSERT_TRUE(surface != nullptr); canvas = surface->getCanvas(); @@ -236,22 +236,22 @@ TGFX_TEST(ReadPixelsTest, Surface) { canvas->drawImage(image); result = surface->readPixels(RGBAInfo, pixels); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixels, "Surface_BL_rgb_A_to_rgb_A"); memset(pixels, 0, RGBAInfo.byteSize()); result = surface->readPixels(RGBAInfo, pixels, 100, 100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBAInfo, pixels, "Surface_BL_rgb_A_to_rgb_A_100_100"); memset(pixels, 0, RGBARectInfo.byteSize()); result = surface->readPixels(RGBARectInfo, pixels, -100, -100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBARectInfo, pixels, "Surface_BL_rgb_A_to_rgb_A_-100_-100"); memset(pixels, 0, RGBARectInfo.byteSize()); result = surface->readPixels(RGBARectInfo, pixels, 100, -100); - ASSERT_TRUE(result); + EXPECT_TRUE(result); CHECK_PIXELS(RGBARectInfo, pixels, "Surface_BL_rgb_A_to_rgb_A_100_-100"); auto gl = GLFunctions::Get(context); gl->deleteTextures(1, &textureInfo.id); @@ -262,192 +262,192 @@ TGFX_TEST(ReadPixelsTest, Surface) { TGFX_TEST(ReadPixelsTest, PngCodec) { auto rgbaCodec = MakeImageCodec("resources/apitest/test_timestretch.png"); ASSERT_TRUE(rgbaCodec != nullptr); - ASSERT_EQ(rgbaCodec->width(), 1280); - ASSERT_EQ(rgbaCodec->height(), 720); - ASSERT_EQ(rgbaCodec->orientation(), Orientation::TopLeft); + EXPECT_EQ(rgbaCodec->width(), 1280); + EXPECT_EQ(rgbaCodec->height(), 720); + EXPECT_EQ(rgbaCodec->orientation(), Orientation::TopLeft); auto rowBytes = static_cast(rgbaCodec->width()) * 4; Buffer buffer(rowBytes * static_cast(rgbaCodec->height())); auto pixels = buffer.data(); ASSERT_TRUE(pixels); auto RGBAInfo = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::RGBA_8888, AlphaType::Premultiplied); - ASSERT_TRUE(rgbaCodec->readPixels(RGBAInfo, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(RGBAInfo, pixels)); CHECK_PIXELS(RGBAInfo, pixels, "PngCodec_Decode_RGBA"); auto bytes = ImageCodec::Encode(Pixmap(RGBAInfo, pixels), EncodedFormat::PNG, 100); auto codec = ImageCodec::MakeFrom(bytes); ASSERT_TRUE(codec != nullptr); - ASSERT_EQ(codec->width(), 1280); - ASSERT_EQ(codec->height(), 720); - ASSERT_EQ(codec->orientation(), Orientation::TopLeft); + EXPECT_EQ(codec->width(), 1280); + EXPECT_EQ(codec->height(), 720); + EXPECT_EQ(codec->orientation(), Orientation::TopLeft); buffer.clear(); - ASSERT_TRUE(codec->readPixels(RGBAInfo, pixels)); + EXPECT_TRUE(codec->readPixels(RGBAInfo, pixels)); CHECK_PIXELS(RGBAInfo, pixels, "PngCodec_Encode_RGBA"); auto A8Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::ALPHA_8, AlphaType::Premultiplied); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(A8Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(A8Info, pixels)); CHECK_PIXELS(A8Info, pixels, "PngCodec_Decode_Alpha8"); bytes = ImageCodec::Encode(Pixmap(A8Info, pixels), EncodedFormat::PNG, 100); codec = ImageCodec::MakeFrom(bytes); ASSERT_TRUE(codec != nullptr); buffer.clear(); - ASSERT_TRUE(codec->readPixels(A8Info, pixels)); + EXPECT_TRUE(codec->readPixels(A8Info, pixels)); CHECK_PIXELS(A8Info, pixels, "PngCodec_Encode_Alpha8"); auto Gray8Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::Gray_8, AlphaType::Opaque); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(Gray8Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(Gray8Info, pixels)); CHECK_PIXELS(Gray8Info, pixels, "PngCodec_Decode_Gray8"); bytes = ImageCodec::Encode(Pixmap(Gray8Info, pixels), EncodedFormat::PNG, 100); codec = ImageCodec::MakeFrom(bytes); ASSERT_TRUE(codec != nullptr); buffer.clear(); - ASSERT_TRUE(codec->readPixels(Gray8Info, pixels)); + EXPECT_TRUE(codec->readPixels(Gray8Info, pixels)); CHECK_PIXELS(Gray8Info, pixels, "PngCodec_Encode_Gray8"); auto RGB565Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::RGB_565, AlphaType::Opaque); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(RGB565Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(RGB565Info, pixels)); CHECK_PIXELS(RGB565Info, pixels, "PngCodec_Decode_RGB565"); bytes = ImageCodec::Encode(Pixmap(RGB565Info, pixels), EncodedFormat::PNG, 100); codec = ImageCodec::MakeFrom(bytes); ASSERT_TRUE(codec != nullptr); buffer.clear(); - ASSERT_TRUE(codec->readPixels(RGB565Info, pixels)); + EXPECT_TRUE(codec->readPixels(RGB565Info, pixels)); CHECK_PIXELS(RGB565Info, pixels, "PngCodec_Encode_RGB565"); } TGFX_TEST(ReadPixelsTest, WebpCodec) { auto rgbaCodec = MakeImageCodec("resources/apitest/imageReplacement.webp"); ASSERT_TRUE(rgbaCodec != nullptr); - ASSERT_EQ(rgbaCodec->width(), 110); - ASSERT_EQ(rgbaCodec->height(), 110); - ASSERT_EQ(rgbaCodec->orientation(), Orientation::TopLeft); + EXPECT_EQ(rgbaCodec->width(), 110); + EXPECT_EQ(rgbaCodec->height(), 110); + EXPECT_EQ(rgbaCodec->orientation(), Orientation::TopLeft); auto RGBAInfo = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::RGBA_8888, AlphaType::Premultiplied); Buffer buffer(RGBAInfo.byteSize()); auto pixels = buffer.data(); ASSERT_TRUE(pixels); - ASSERT_TRUE(rgbaCodec->readPixels(RGBAInfo, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(RGBAInfo, pixels)); CHECK_PIXELS(RGBAInfo, pixels, "WebpCodec_Decode_RGBA"); Pixmap pixmap(RGBAInfo, pixels); auto bytes = ImageCodec::Encode(pixmap, EncodedFormat::WEBP, 100); auto codec = ImageCodec::MakeFrom(bytes); ASSERT_TRUE(codec != nullptr); - ASSERT_EQ(codec->width(), 110); - ASSERT_EQ(codec->height(), 110); - ASSERT_EQ(codec->orientation(), Orientation::TopLeft); + EXPECT_EQ(codec->width(), 110); + EXPECT_EQ(codec->height(), 110); + EXPECT_EQ(codec->orientation(), Orientation::TopLeft); buffer.clear(); - ASSERT_TRUE(codec->readPixels(RGBAInfo, pixels)); + EXPECT_TRUE(codec->readPixels(RGBAInfo, pixels)); CHECK_PIXELS(RGBAInfo, pixels, "WebpCodec_Encode_RGBA"); auto A8Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::ALPHA_8, AlphaType::Premultiplied); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(A8Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(A8Info, pixels)); CHECK_PIXELS(A8Info, pixels, "WebpCodec_Decode_Alpha8"); bytes = ImageCodec::Encode(Pixmap(A8Info, pixels), EncodedFormat::WEBP, 100); codec = ImageCodec::MakeFrom(bytes); buffer.clear(); - ASSERT_TRUE(codec->readPixels(A8Info, pixels)); + EXPECT_TRUE(codec->readPixels(A8Info, pixels)); CHECK_PIXELS(A8Info, pixels, "WebpCodec_Encode_Alpha8"); auto Gray8Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::Gray_8, AlphaType::Opaque); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(Gray8Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(Gray8Info, pixels)); CHECK_PIXELS(Gray8Info, pixels, "WebpCodec_Decode_Gray8"); bytes = ImageCodec::Encode(Pixmap(Gray8Info, pixels), EncodedFormat::WEBP, 100); codec = ImageCodec::MakeFrom(bytes); buffer.clear(); - ASSERT_TRUE(codec->readPixels(Gray8Info, pixels)); + EXPECT_TRUE(codec->readPixels(Gray8Info, pixels)); CHECK_PIXELS(Gray8Info, pixels, "WebpCodec_Encode_Gray8"); auto RGB565Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::RGB_565, AlphaType::Opaque); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(RGB565Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(RGB565Info, pixels)); CHECK_PIXELS(RGB565Info, pixels, "WebpCodec_Decode_RGB565"); bytes = ImageCodec::Encode(Pixmap(RGB565Info, pixels), EncodedFormat::WEBP, 100); codec = ImageCodec::MakeFrom(bytes); buffer.clear(); - ASSERT_TRUE(codec->readPixels(RGB565Info, pixels)); + EXPECT_TRUE(codec->readPixels(RGB565Info, pixels)); CHECK_PIXELS(RGB565Info, pixels, "WebpCodec_Encode_RGB565"); } TGFX_TEST(ReadPixelsTest, JpegCodec) { auto rgbaCodec = MakeImageCodec("resources/apitest/rotation.jpg"); ASSERT_TRUE(rgbaCodec != nullptr); - ASSERT_EQ(rgbaCodec->width(), 4032); - ASSERT_EQ(rgbaCodec->height(), 3024); - ASSERT_EQ(rgbaCodec->orientation(), Orientation::RightTop); + EXPECT_EQ(rgbaCodec->width(), 4032); + EXPECT_EQ(rgbaCodec->height(), 3024); + EXPECT_EQ(rgbaCodec->orientation(), Orientation::RightTop); auto RGBAInfo = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::RGBA_8888, AlphaType::Premultiplied); Buffer buffer(RGBAInfo.byteSize()); auto pixels = buffer.data(); ASSERT_TRUE(pixels); - ASSERT_TRUE(rgbaCodec->readPixels(RGBAInfo, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(RGBAInfo, pixels)); CHECK_PIXELS(RGBAInfo, pixels, "JpegCodec_Decode_RGBA"); auto bytes = ImageCodec::Encode(Pixmap(RGBAInfo, pixels), EncodedFormat::JPEG, 20); auto codec = ImageCodec::MakeFrom(bytes); ASSERT_TRUE(codec != nullptr); - ASSERT_EQ(codec->width(), 4032); - ASSERT_EQ(codec->height(), 3024); - ASSERT_EQ(codec->orientation(), Orientation::TopLeft); + EXPECT_EQ(codec->width(), 4032); + EXPECT_EQ(codec->height(), 3024); + EXPECT_EQ(codec->orientation(), Orientation::TopLeft); buffer.clear(); - ASSERT_TRUE(codec->readPixels(RGBAInfo, pixels)); + EXPECT_TRUE(codec->readPixels(RGBAInfo, pixels)); CHECK_PIXELS(RGBAInfo, pixels, "JpegCodec_Encode_RGBA"); auto A8Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::ALPHA_8, AlphaType::Premultiplied); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(A8Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(A8Info, pixels)); CHECK_PIXELS(A8Info, pixels, "JpegCodec_Decode_Alpha8"); bytes = ImageCodec::Encode(Pixmap(A8Info, pixels), EncodedFormat::JPEG, 100); codec = ImageCodec::MakeFrom(bytes); buffer.clear(); - ASSERT_TRUE(codec->readPixels(A8Info, pixels)); + EXPECT_TRUE(codec->readPixels(A8Info, pixels)); CHECK_PIXELS(A8Info, pixels, "JpegCodec_Encode_Alpha8"); auto Gray8Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::Gray_8, AlphaType::Opaque); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(Gray8Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(Gray8Info, pixels)); CHECK_PIXELS(Gray8Info, pixels, "JpegCodec_Decode_Gray8"); bytes = ImageCodec::Encode(Pixmap(Gray8Info, pixels), EncodedFormat::JPEG, 70); codec = ImageCodec::MakeFrom(bytes); buffer.clear(); - ASSERT_TRUE(codec->readPixels(Gray8Info, pixels)); + EXPECT_TRUE(codec->readPixels(Gray8Info, pixels)); CHECK_PIXELS(Gray8Info, pixels, "JpegCodec_Encode_Gray8"); auto RGB565Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::RGB_565, AlphaType::Opaque); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(RGB565Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(RGB565Info, pixels)); CHECK_PIXELS(RGB565Info, pixels, "JpegCodec_Decode_RGB565"); bytes = ImageCodec::Encode(Pixmap(RGB565Info, pixels), EncodedFormat::JPEG, 80); codec = ImageCodec::MakeFrom(bytes); buffer.clear(); - ASSERT_TRUE(codec->readPixels(RGB565Info, pixels)); + EXPECT_TRUE(codec->readPixels(RGB565Info, pixels)); CHECK_PIXELS(RGB565Info, pixels, "JpegCodec_Encode_RGB565"); } TGFX_TEST(ReadPixelsTest, NativeCodec) { auto rgbaCodec = MakeNativeCodec("resources/apitest/test_timestretch.png"); ASSERT_TRUE(rgbaCodec != nullptr); - ASSERT_EQ(rgbaCodec->width(), 1280); - ASSERT_EQ(rgbaCodec->height(), 720); - ASSERT_EQ(rgbaCodec->orientation(), Orientation::TopLeft); + EXPECT_EQ(rgbaCodec->width(), 1280); + EXPECT_EQ(rgbaCodec->height(), 720); + EXPECT_EQ(rgbaCodec->orientation(), Orientation::TopLeft); auto RGBAInfo = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::RGBA_8888, AlphaType::Premultiplied); Buffer buffer(RGBAInfo.byteSize()); auto pixels = buffer.data(); ASSERT_TRUE(pixels); - ASSERT_TRUE(rgbaCodec->readPixels(RGBAInfo, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(RGBAInfo, pixels)); CHECK_PIXELS(RGBAInfo, pixels, "NativeCodec_Decode_RGBA"); auto bytes = ImageCodec::Encode(Pixmap(RGBAInfo, pixels), EncodedFormat::PNG, 100); auto codec = ImageCodec::MakeNativeCodec(bytes); @@ -456,19 +456,19 @@ TGFX_TEST(ReadPixelsTest, NativeCodec) { ASSERT_EQ(codec->height(), 720); ASSERT_EQ(codec->orientation(), Orientation::TopLeft); buffer.clear(); - ASSERT_TRUE(codec->readPixels(RGBAInfo, pixels)); + EXPECT_TRUE(codec->readPixels(RGBAInfo, pixels)); CHECK_PIXELS(RGBAInfo, pixels, "NativeCodec_Encode_RGBA"); auto A8Info = ImageInfo::Make(rgbaCodec->width(), rgbaCodec->height(), ColorType::ALPHA_8, AlphaType::Premultiplied); buffer.clear(); - ASSERT_TRUE(rgbaCodec->readPixels(A8Info, pixels)); + EXPECT_TRUE(rgbaCodec->readPixels(A8Info, pixels)); CHECK_PIXELS(A8Info, pixels, "NativeCodec_Decode_Alpha8"); bytes = ImageCodec::Encode(Pixmap(A8Info, pixels), EncodedFormat::PNG, 100); codec = ImageCodec::MakeNativeCodec(bytes); ASSERT_TRUE(codec != nullptr); buffer.clear(); - ASSERT_TRUE(codec->readPixels(A8Info, pixels)); + EXPECT_TRUE(codec->readPixels(A8Info, pixels)); CHECK_PIXELS(A8Info, pixels, "NativeCodec_Encode_Alpha8"); } } // namespace tgfx From 836a4ae7d8179828585b126a6d4cbb9cbe99aa23 Mon Sep 17 00:00:00 2001 From: illidanstormrange Date: Thu, 31 Oct 2024 10:27:13 +0800 Subject: [PATCH 13/13] Buffer use clear() to initialize --- test/src/DataViewTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/DataViewTest.cpp b/test/src/DataViewTest.cpp index 5928760e..d8c5620e 100644 --- a/test/src/DataViewTest.cpp +++ b/test/src/DataViewTest.cpp @@ -39,7 +39,7 @@ TGFX_TEST(DataViewTest, PNGDataCheck) { TGFX_TEST(DataViewTest, ReadString) { Buffer buffer(100); - memset(buffer.bytes(), 0, buffer.size()); + buffer.clear(); std::string text = "Hello TGFX 123"; auto dataView = DataView(buffer.bytes(), buffer.size()); const char* textStart = text.data();