mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-09-22 22:48:08 +03:00
QNT: Add odd-size image test
This commit is contained in:
+3
-2
@@ -193,9 +193,10 @@ else() # non-emscripten, non-android
|
||||
src_tests.c
|
||||
gameresource_test.c
|
||||
hankaku_test.c
|
||||
qnt_test.c
|
||||
)
|
||||
target_compile_options(src_tests PRIVATE -Wno-pointer-sign -Wall)
|
||||
target_link_libraries(src_tests PRIVATE src_lib)
|
||||
target_link_libraries(src_tests PRIVATE src_lib sdl2)
|
||||
add_test(NAME src_tests COMMAND src_tests)
|
||||
configure_file(testdata/test.gr ${CMAKE_CURRENT_BINARY_DIR}/testdata/test.gr COPYONLY)
|
||||
file(COPY testdata DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2026 <KichikuouChrome@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "cg.h"
|
||||
#include "qnt.h"
|
||||
#include "unittest.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void odd_size_test(void) {
|
||||
FILE *fp = fopen("testdata/odd-size.qnt", "rb");
|
||||
ASSERT_TRUE(fp);
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
long size = ftell(fp);
|
||||
rewind(fp);
|
||||
uint8_t *data = malloc(size);
|
||||
ASSERT_EQUAL(fread(data, 1, size, fp), size);
|
||||
fclose(fp);
|
||||
|
||||
cgdata *cg = qnt_extract(data);
|
||||
ASSERT_EQUAL(cg->width, 3);
|
||||
ASSERT_EQUAL(cg->height, 3);
|
||||
ASSERT_TRUE(cg->alpha);
|
||||
|
||||
const uint8_t expected[] = {
|
||||
0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90,
|
||||
0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0x11, 0x22, 0x33,
|
||||
0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc,
|
||||
};
|
||||
ASSERT_TRUE(!memcmp(cg->pic, expected, sizeof(expected)));
|
||||
|
||||
const uint8_t expected_alpha[] = {
|
||||
0xff, 0x80, 0x40,
|
||||
0xff, 0x20, 0xc0,
|
||||
0x7f, 0xfe, 0x10,
|
||||
};
|
||||
ASSERT_TRUE(!memcmp(cg->alpha, expected_alpha, sizeof(expected_alpha)));
|
||||
|
||||
free(cg->pic);
|
||||
free(cg->alpha);
|
||||
free(cg);
|
||||
free(data);
|
||||
}
|
||||
|
||||
void qnt_test(void) {
|
||||
odd_size_test();
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
void gameresource_test(void);
|
||||
void hankaku_test(void);
|
||||
void qnt_test(void);
|
||||
|
||||
void sys_error(char *format, ...) {
|
||||
va_list args;
|
||||
@@ -31,8 +32,16 @@ void sys_error(char *format, ...) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void sys_message(int level, char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
int main() {
|
||||
gameresource_test();
|
||||
hankaku_test();
|
||||
qnt_test();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vendored
BIN
Binary file not shown.
Reference in New Issue
Block a user