Skip to content

Commit

Permalink
Add test for .ico & .cur loader
Browse files Browse the repository at this point in the history
  • Loading branch information
a740g committed Jul 21, 2024
1 parent 5ae0893 commit 34a6bdc
Show file tree
Hide file tree
Showing 54 changed files with 185 additions and 6 deletions.
8 changes: 4 additions & 4 deletions internal/c/parts/video/image/sg_curico/sg_curico.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CurIcoImage {

Header(Stream &stream) { ReadFromStream(stream); }

bool IsValid() { return reserved == 0 && (type == Type::Icon || type == Type::Cursor) && count > 0; }
auto IsValid() { return reserved == 0 && (type == Type::Icon || type == Type::Cursor) && count > 0; }

static auto GetStructSize() noexcept { return 6; } // sizeof(Header)

Expand Down Expand Up @@ -285,7 +285,7 @@ class CurIcoImage {
/// @param fileName The name of the icon file
/// @param payloadData A pointer to the PNG payload
/// @param payloadSize The size of the PNG payload in bytes
static bool WriteToFile(const char *fileName, const uint8_t *payloadData, uint32_t payloadSize) {
static auto WriteToFile(const char *fileName, const uint8_t *payloadData, uint32_t payloadSize) {
if (fileName && fileName[0] && payloadData && payloadSize) {
auto file = fopen(fileName, "wb");

Expand Down Expand Up @@ -601,9 +601,9 @@ class CurIcoImage {

auto src = input.GetData();
auto dst = *out_data;
auto pixels = width * height;
size_t pixels = width * height;

for (auto i = 0; i < pixels; i++) {
for (size_t i = 0; i < pixels; i++) {
auto r = *src;
++src;
auto g = *src;
Expand Down
79 changes: 79 additions & 0 deletions tests/compile_tests/image/curico_test.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
DEFLNG A-Z
OPTION _EXPLICIT
$CONSOLE:ONLY
CHDIR _STARTDIR$

CONST ICON_DIR = "./icons/"
CONST TEST_FILE_FORMAT = "bmp"
CONST TOLERANCE_LIMIT = 0

RESTORE file_list

DIM fileName AS STRING: READ fileName

DO
DoImageFile ICON_DIR + fileName
READ fileName
LOOP WHILE LEN(fileName)

SYSTEM

file_list:
DATA 1bpp.ico
DATA 24bpp.ico
DATA 4bpp.cur
DATA 4bpp.ico
DATA 8bpp.ico
DATA 8bpp.cur
DATA bard.ico
DATA broom.ico
DATA cat.ico
DATA computer.ico
DATA dumb1.ico
DATA dumb2.ico
DATA pencil.ico
DATA please_wait.ico
DATA question.ico
DATA really_huge_duck.ico
DATA sample3.ico
DATA sample4.ico
DATA soft_drink.ico
DATA taco.ico
DATA terra_globe.ico
DATA thumbs_up.ico
DATA volme_dialog.ico
DATA word-icon.ico
DATA x.ico
DATA ""

SUB PrintImageDetails (handle AS LONG, testFileName AS STRING)
DIM fullTestFileName AS STRING: fullTestFileName = testFileName + "." + TEST_FILE_FORMAT

PRINT "Testing against "; fullTestFileName; " ("; _WIDTH(handle); "x"; _HEIGHT(handle); ")."
'_SAVEIMAGE fullTestFileName, handle
AssertImage2 handle, fullTestFileName, TOLERANCE_LIMIT

PRINT
END SUB


SUB DoImageFile (testFileName AS STRING)
DIM fileName AS STRING: fileName = testFileName

PRINT "Loading image from storage "; fileName; " ... ";

DIM h AS LONG: h = _LOADIMAGE(fileName, 32)

IF h < -1 THEN
PRINT "done."

PrintImageDetails h, testFileName

_FREEIMAGE h
ELSE
PRINT "failed!"
END IF
END SUB

'$INCLUDE:'../utilities/imageassert.bm'
'$INCLUDE:'../utilities/base64.bm'
100 changes: 100 additions & 0 deletions tests/compile_tests/image/curico_test.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Loading image from storage ./icons/1bpp.ico ... done.
Testing against ./icons/1bpp.ico.bmp ( 128 x 128 ).
Success, images are identical!

Loading image from storage ./icons/24bpp.ico ... done.
Testing against ./icons/24bpp.ico.bmp ( 128 x 128 ).
Success, images are identical!

Loading image from storage ./icons/4bpp.cur ... done.
Testing against ./icons/4bpp.cur.bmp ( 16 x 16 ).
Success, images are identical!

Loading image from storage ./icons/4bpp.ico ... done.
Testing against ./icons/4bpp.ico.bmp ( 128 x 128 ).
Success, images are identical!

Loading image from storage ./icons/8bpp.ico ... done.
Testing against ./icons/8bpp.ico.bmp ( 128 x 128 ).
Success, images are identical!

Loading image from storage ./icons/8bpp.cur ... done.
Testing against ./icons/8bpp.cur.bmp ( 32 x 32 ).
Success, images are identical!

Loading image from storage ./icons/bard.ico ... done.
Testing against ./icons/bard.ico.bmp ( 1360 x 1083 ).
Success, images are identical!

Loading image from storage ./icons/broom.ico ... done.
Testing against ./icons/broom.ico.bmp ( 600 x 600 ).
Success, images are identical!

Loading image from storage ./icons/cat.ico ... done.
Testing against ./icons/cat.ico.bmp ( 150 x 150 ).
Success, images are identical!

Loading image from storage ./icons/computer.ico ... done.
Testing against ./icons/computer.ico.bmp ( 474 x 474 ).
Success, images are identical!

Loading image from storage ./icons/dumb1.ico ... done.
Testing against ./icons/dumb1.ico.bmp ( 540 x 500 ).
Success, images are identical!

Loading image from storage ./icons/dumb2.ico ... done.
Testing against ./icons/dumb2.ico.bmp ( 540 x 500 ).
Success, images are identical!

Loading image from storage ./icons/pencil.ico ... done.
Testing against ./icons/pencil.ico.bmp ( 256 x 256 ).
Success, images are identical!

Loading image from storage ./icons/please_wait.ico ... done.
Testing against ./icons/please_wait.ico.bmp ( 404 x 325 ).
Success, images are identical!

Loading image from storage ./icons/question.ico ... done.
Testing against ./icons/question.ico.bmp ( 512 x 512 ).
Success, images are identical!

Loading image from storage ./icons/really_huge_duck.ico ... done.
Testing against ./icons/really_huge_duck.ico.bmp ( 4293 x 4293 ).
Success, images are identical!

Loading image from storage ./icons/sample3.ico ... done.
Testing against ./icons/sample3.ico.bmp ( 256 x 171 ).
Success, images are identical!

Loading image from storage ./icons/sample4.ico ... done.
Testing against ./icons/sample4.ico.bmp ( 256 x 192 ).
Success, images are identical!

Loading image from storage ./icons/soft_drink.ico ... done.
Testing against ./icons/soft_drink.ico.bmp ( 256 x 256 ).
Success, images are identical!

Loading image from storage ./icons/taco.ico ... done.
Testing against ./icons/taco.ico.bmp ( 966 x 764 ).
Success, images are identical!

Loading image from storage ./icons/terra_globe.ico ... done.
Testing against ./icons/terra_globe.ico.bmp ( 772 x 769 ).
Success, images are identical!

Loading image from storage ./icons/thumbs_up.ico ... done.
Testing against ./icons/thumbs_up.ico.bmp ( 463 x 294 ).
Success, images are identical!

Loading image from storage ./icons/volme_dialog.ico ... done.
Testing against ./icons/volme_dialog.ico.bmp ( 32 x 32 ).
Success, images are identical!

Loading image from storage ./icons/word-icon.ico ... done.
Testing against ./icons/word-icon.ico.bmp ( 512 x 512 ).
Success, images are identical!

Loading image from storage ./icons/x.ico ... done.
Testing against ./icons/x.ico.bmp ( 256 x 256 ).
Success, images are identical!

Binary file added tests/compile_tests/image/icons/1bpp.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/1bpp.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/24bpp.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/24bpp.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/4bpp.cur
Binary file not shown.
Binary file added tests/compile_tests/image/icons/4bpp.cur.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/4bpp.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/4bpp.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/8bpp.cur
Binary file not shown.
Binary file added tests/compile_tests/image/icons/8bpp.cur.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/8bpp.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/8bpp.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/bard.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/bard.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/broom.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/broom.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/cat.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/cat.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/computer.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/computer.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/dumb1.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/dumb1.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/dumb2.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/dumb2.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/pencil.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/pencil.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/please_wait.ico
Binary file not shown.
Binary file not shown.
Binary file added tests/compile_tests/image/icons/question.ico
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/compile_tests/image/icons/sample3.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/sample3.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/sample4.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/sample4.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/soft_drink.ico
Binary file not shown.
Binary file not shown.
Binary file added tests/compile_tests/image/icons/taco.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/taco.ico.bmp
Binary file not shown.
Binary file added tests/compile_tests/image/icons/terra_globe.ico
Binary file not shown.
Binary file not shown.
Binary file added tests/compile_tests/image/icons/thumbs_up.ico
Binary file not shown.
Binary file not shown.
Binary file added tests/compile_tests/image/icons/volme_dialog.ico
Binary file not shown.
Binary file not shown.
Binary file added tests/compile_tests/image/icons/word-icon.ico
Binary file not shown.
Binary file not shown.
Binary file added tests/compile_tests/image/icons/x.ico
Binary file not shown.
Binary file added tests/compile_tests/image/icons/x.ico.bmp
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/compile_tests/utilities/imageassert.bm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ END SUB


FUNCTION GetColorDelta~& (color1 AS _UNSIGNED LONG, color2 AS _UNSIGNED LONG)
GetColorDelta = ABS(_RED32(color1) - _RED32(color2)) + ABS(_GREEN32(color1) - _GREEN32(color2)) + ABS(_BLUE32(color1) - _BLUE32(color2)) + ABS(_ALPHA32(color1) - _ALPHA32(color2))
GetColorDelta = ABS(_RED32(color1) - _RED32(color2)) + ABS(_GREEN32(color1) - _GREEN32(color2)) + ABS(_BLUE32(color1) - _BLUE32(color2))
END FUNCTION


Expand Down Expand Up @@ -178,7 +178,7 @@ SUB AssertImage2 (originalActualImage AS LONG, expectedFileName AS STRING, toler
actualPixel = _MEMGET(actual, actual.OFFSET + pixelOffset, _UNSIGNED LONG)
expectedPixel = _MEMGET(expected, expected.OFFSET + pixelOffset, _UNSIGNED LONG)

IF actualPixel <> expectedPixel _ANDALSO GetColorDelta(actualPixel, expectedPixel) > toleranceLimit THEN
IF actualPixel <> expectedPixel _ANDALSO _ALPHA32(actualPixel) <> 0 _ANDALSO _ALPHA32(expectedPixel) <> 0 _ANDALSO GetColorDelta(actualPixel, expectedPixel) > toleranceLimit THEN
PRINT "Failure! Image pixels at ("; x&; ","; y&; ") differ, actual: 0x"; HEX$(actualPixel); ", expected: 0x"; HEX$(expectedPixel)
GOTO freeImages
END IF
Expand Down

0 comments on commit 34a6bdc

Please sign in to comment.