mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Refactor testlib's funcname handling.
This commit is contained in:
1 parent
8d6694a752
commit
88e2d4cf59
3 files changed
+32
-31
No files matched your search
+22
-22
@@ -18,45 +18,46 @@ Each edition should print "PASS", amongst other information, and exit(0).
|
||||
const char* test_filename = "gif/basic.c";
|
||||
|
||||
void test_constructor_not_called() {
|
||||
test_funcname = __func__;
|
||||
puffs_gif_lzw_decoder dec;
|
||||
puffs_base_buf1 dst = {0};
|
||||
puffs_base_buf1 src = {0};
|
||||
puffs_gif_status status =
|
||||
puffs_gif_lzw_decoder_decode(&dec, &dst, &src, false);
|
||||
if (status != puffs_gif_error_constructor_not_called) {
|
||||
FAIL("test_constructor_not_called: status: got %d, want %d", status,
|
||||
FAIL("status: got %d, want %d", status,
|
||||
puffs_gif_error_constructor_not_called);
|
||||
}
|
||||
}
|
||||
|
||||
void test_bad_argument() {
|
||||
test_funcname = __func__;
|
||||
puffs_gif_lzw_decoder dec;
|
||||
puffs_gif_lzw_decoder_constructor(&dec, PUFFS_VERSION, 0);
|
||||
puffs_gif_status status =
|
||||
puffs_gif_lzw_decoder_decode(&dec, NULL, NULL, false);
|
||||
if (status != puffs_gif_error_bad_argument) {
|
||||
FAIL("test_bad_argument: status: got %d, want %d", status,
|
||||
puffs_gif_error_bad_argument);
|
||||
FAIL("status: got %d, want %d", status, puffs_gif_error_bad_argument);
|
||||
}
|
||||
}
|
||||
|
||||
void test_bad_receiver() {
|
||||
test_funcname = __func__;
|
||||
puffs_base_buf1 dst = {0};
|
||||
puffs_base_buf1 src = {0};
|
||||
puffs_gif_status status =
|
||||
puffs_gif_lzw_decoder_decode(NULL, &dst, &src, false);
|
||||
if (status != puffs_gif_error_bad_receiver) {
|
||||
FAIL("test_bad_receiver: status: got %d, want %d", status,
|
||||
puffs_gif_error_bad_receiver);
|
||||
FAIL("status: got %d, want %d", status, puffs_gif_error_bad_receiver);
|
||||
}
|
||||
}
|
||||
|
||||
void test_puffs_version_bad() {
|
||||
test_funcname = __func__;
|
||||
puffs_gif_lzw_decoder dec;
|
||||
puffs_gif_lzw_decoder_constructor(&dec, 0, 0); // 0 is not PUFFS_VERSION.
|
||||
if (dec.status != puffs_gif_error_bad_version) {
|
||||
FAIL("test_puffs_version_bad: status: got %d, want %d", dec.status,
|
||||
puffs_gif_error_bad_version);
|
||||
FAIL("status: got %d, want %d", dec.status, puffs_gif_error_bad_version);
|
||||
goto cleanup0;
|
||||
}
|
||||
cleanup0:
|
||||
@@ -64,16 +65,15 @@ cleanup0:
|
||||
}
|
||||
|
||||
void test_puffs_version_good() {
|
||||
test_funcname = __func__;
|
||||
puffs_gif_lzw_decoder dec;
|
||||
puffs_gif_lzw_decoder_constructor(&dec, PUFFS_VERSION, 0);
|
||||
if (dec.magic != PUFFS_MAGIC) {
|
||||
FAIL("test_puffs_version_good: magic: got %u, want %u", dec.magic,
|
||||
PUFFS_MAGIC);
|
||||
FAIL("magic: got %u, want %u", dec.magic, PUFFS_MAGIC);
|
||||
goto cleanup0;
|
||||
}
|
||||
if (dec.f_literal_width != 8) {
|
||||
FAIL("test_puffs_version_good: f_literal_width: got %u, want %u",
|
||||
dec.f_literal_width, 8);
|
||||
FAIL("f_literal_width: got %u, want %u", dec.f_literal_width, 8);
|
||||
goto cleanup0;
|
||||
}
|
||||
cleanup0:
|
||||
@@ -81,56 +81,56 @@ cleanup0:
|
||||
}
|
||||
|
||||
void test_status_is_error() {
|
||||
test_funcname = __func__;
|
||||
if (puffs_gif_status_is_error(puffs_gif_status_ok)) {
|
||||
FAIL("test_status_is_error: is_error(ok) returned true");
|
||||
FAIL("is_error(ok) returned true");
|
||||
return;
|
||||
}
|
||||
if (!puffs_gif_status_is_error(puffs_gif_error_bad_version)) {
|
||||
FAIL("test_status_is_error: is_error(bad_version) returned false");
|
||||
FAIL("is_error(bad_version) returned false");
|
||||
return;
|
||||
}
|
||||
if (puffs_gif_status_is_error(puffs_gif_status_short_write)) {
|
||||
FAIL("test_status_is_error: is_error(short_write) returned true");
|
||||
FAIL("is_error(short_write) returned true");
|
||||
return;
|
||||
}
|
||||
if (!puffs_gif_status_is_error(puffs_gif_error_lzw_code_is_out_of_range)) {
|
||||
FAIL(
|
||||
"test_status_is_error: is_error(lzw_code_is_out_of_range) returned "
|
||||
"false");
|
||||
FAIL("is_error(lzw_code_is_out_of_range) returned false");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void test_status_strings() {
|
||||
test_funcname = __func__;
|
||||
const char* s0 = puffs_gif_status_string(puffs_gif_status_ok);
|
||||
const char* t0 = "gif: ok";
|
||||
if (strcmp(s0, t0)) {
|
||||
FAIL("test_status_strings: got \"%s\", want \"%s\"", s0, t0);
|
||||
FAIL("got \"%s\", want \"%s\"", s0, t0);
|
||||
return;
|
||||
}
|
||||
const char* s1 = puffs_gif_status_string(puffs_gif_error_bad_version);
|
||||
const char* t1 = "gif: bad version";
|
||||
if (strcmp(s1, t1)) {
|
||||
FAIL("test_status_strings: got \"%s\", want \"%s\"", s1, t1);
|
||||
FAIL("got \"%s\", want \"%s\"", s1, t1);
|
||||
return;
|
||||
}
|
||||
const char* s2 = puffs_gif_status_string(puffs_gif_status_short_write);
|
||||
const char* t2 = "gif: short write";
|
||||
if (strcmp(s2, t2)) {
|
||||
FAIL("test_status_strings: got \"%s\", want \"%s\"", s2, t2);
|
||||
FAIL("got \"%s\", want \"%s\"", s2, t2);
|
||||
return;
|
||||
}
|
||||
const char* s3 =
|
||||
puffs_gif_status_string(puffs_gif_error_lzw_code_is_out_of_range);
|
||||
const char* t3 = "gif: LZW code is out of range";
|
||||
if (strcmp(s3, t3)) {
|
||||
FAIL("test_status_strings: got \"%s\", want \"%s\"", s3, t3);
|
||||
FAIL("got \"%s\", want \"%s\"", s3, t3);
|
||||
return;
|
||||
}
|
||||
const char* s4 = puffs_gif_status_string(-254);
|
||||
const char* t4 = "gif: unknown status";
|
||||
if (strcmp(s4, t4)) {
|
||||
FAIL("test_status_strings: got \"%s\", want \"%s\"", s4, t4);
|
||||
FAIL("got \"%s\", want \"%s\"", s4, t4);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-8
@@ -23,6 +23,7 @@ uint8_t global_dst_buffer[BUFFER_SIZE];
|
||||
uint8_t global_src_buffer[BUFFER_SIZE];
|
||||
|
||||
void test_lzw_decode() {
|
||||
test_funcname = __func__;
|
||||
puffs_base_buf1 dst = {.ptr = global_dst_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
if (!read_file(&src, "../../testdata/bricks-nodither.giflzw")) {
|
||||
@@ -30,13 +31,12 @@ void test_lzw_decode() {
|
||||
}
|
||||
// That .giflzw file should be 13382 bytes long.
|
||||
if (src.wi != 13382) {
|
||||
FAIL("test_lzw_decode: src size: got %d, want %d", (int)(src.wi), 13382);
|
||||
FAIL("src size: got %d, want %d", (int)(src.wi), 13382);
|
||||
goto cleanup0;
|
||||
}
|
||||
// The first byte in that file, the LZW literal width, should be 0x08.
|
||||
if (src.ptr[0] != 0x08) {
|
||||
FAIL("test_lzw_decode: LZW literal width: got %d, want %d",
|
||||
(int)(src.ptr[0]), 0x08);
|
||||
FAIL("LZW literal width: got %d, want %d", (int)(src.ptr[0]), 0x08);
|
||||
goto cleanup0;
|
||||
}
|
||||
src.ri++;
|
||||
@@ -47,8 +47,7 @@ void test_lzw_decode() {
|
||||
puffs_gif_status status =
|
||||
puffs_gif_lzw_decoder_decode(&dec, &dst, &src, false);
|
||||
if (status != puffs_gif_status_ok) {
|
||||
FAIL("test_lzw_decode: status: got %d, want %d", status,
|
||||
puffs_gif_status_ok);
|
||||
FAIL("status: got %d, want %d", status, puffs_gif_status_ok);
|
||||
goto cleanup1;
|
||||
}
|
||||
|
||||
@@ -56,13 +55,13 @@ void test_lzw_decode() {
|
||||
//
|
||||
// TODO: s/3982/19200/ as 19200 = 160 * 120.
|
||||
if (dst.wi != 3982) {
|
||||
FAIL("test_lzw_decode: dst size: got %d, want %d", (int)(dst.wi), 3982);
|
||||
FAIL("dst size: got %d, want %d", (int)(dst.wi), 3982);
|
||||
goto cleanup1;
|
||||
}
|
||||
// The first decoded byte should be 0xDC.
|
||||
if (dst.ptr[0] != 0xDC) {
|
||||
FAIL("test_lzw_decode: first decoded byte: got 0x%02x, want 0x%02x",
|
||||
(int)(dst.ptr[0]), 0xDC);
|
||||
FAIL("first decoded byte: got 0x%02x, want 0x%02x", (int)(dst.ptr[0]),
|
||||
0xDC);
|
||||
goto cleanup1;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ typedef void (*test)();
|
||||
test tests[];
|
||||
|
||||
const char* test_filename;
|
||||
const char* test_funcname = "";
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// The order matters here. Clang also defines "__GNUC__".
|
||||
@@ -32,7 +33,8 @@ int main(int argc, char** argv) {
|
||||
for (test* t = tests; *t; t++) {
|
||||
(*t)();
|
||||
if (fail_msg[0]) {
|
||||
printf("%-16s%-8sFAIL %s\n", test_filename, cc, fail_msg);
|
||||
printf("%-16s%-8sFAIL %s: %s\n", test_filename, cc, test_funcname,
|
||||
fail_msg);
|
||||
return 1;
|
||||
}
|
||||
tests_run++;
|
||||
|
||||
Reference in new issue
Block a user