From b08c297a37c2b061de783b1954bb908796fe91b0 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 26 Mar 2023 11:33:06 -0700 Subject: test: Add simple test cases for functions in src/RdBitF.c Signed-off-by: Alan Coopersmith --- test/Makefile.am | 8 ++- test/ReadBitmapData.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/bitmaps/plaid | 11 ++++ test/bitmaps/star | 8 +++ test/bitmaps/xlogo64 | 46 +++++++++++++++++ 5 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 test/ReadBitmapData.c create mode 100644 test/bitmaps/plaid create mode 100644 test/bitmaps/star create mode 100644 test/bitmaps/xlogo64 diff --git a/test/Makefile.am b/test/Makefile.am index 6a1dbbf..5af50d1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -30,7 +30,7 @@ AM_CFLAGS = $(CWARNFLAGS) $(XMU_CFLAGS) $(GLIB_CFLAGS) XMU_TEST_LIBS = ${top_builddir}/src/libXmu.la $(XMU_LIBS) $(GLIB_LIBS) XMUU_TEST_LIBS = ${top_builddir}/src/libXmuu.la $(XMUU_LIBS) $(GLIB_LIBS) -check_PROGRAMS = EditResStream +check_PROGRAMS = EditResStream ReadBitmapData TESTS = $(check_PROGRAMS) TESTS_ENVIRONMENT = $(MALLOC_DEBUG_ENV) @@ -44,8 +44,14 @@ LOG_COMPILER = $(srcdir)/tap-test EditResStream_SOURCES = EditResStream.c EditResStream_LDADD = $(XMU_TEST_LIBS) +ReadBitmapData_SOURCES = ReadBitmapData.c +ReadBitmapData_LDADD = $(XMU_TEST_LIBS) + endif HAVE_GLIB endif ENABLE_UNIT_TESTS EXTRA_DIST = \ + bitmaps/plaid \ + bitmaps/star \ + bitmaps/xlogo64 \ tap-test diff --git a/test/ReadBitmapData.c b/test/ReadBitmapData.c new file mode 100644 index 0000000..b9cdcd1 --- /dev/null +++ b/test/ReadBitmapData.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* Test code for XmuReadBitmapData functions in src/RdBitF.c */ +#include "config.h" +#include +#include +#include + +struct BitmapData { + unsigned int width; + unsigned int height; + unsigned char * datap; + int xhot; + int yhot; +}; + +#include "bitmaps/plaid" + +static const struct BitmapData plaid_expected = { + plaid_width, plaid_height, (unsigned char *) plaid_bits, + plaid_x_hot, plaid_y_hot +}; + +#include "bitmaps/star" + +static const struct BitmapData star_expected = { + star_width, star_height, (unsigned char *) star_bits, + star_x_hot, star_y_hot +}; + +#include "bitmaps/xlogo64" +#define xlogo64_x_hot -1 +#define xlogo64_y_hot -1 + +static const struct BitmapData xlogo64_expected = { + xlogo64_width, xlogo64_height, xlogo64_bits, + xlogo64_x_hot, xlogo64_y_hot +}; + +struct TestData { + const char *filename; + const struct BitmapData *data; +}; + +static struct TestData testdata[] = { + { "plaid", &plaid_expected }, + { "star", &star_expected }, + { "xlogo64", &xlogo64_expected }, +}; + +#define testcount (sizeof(testdata) / sizeof(testdata[0])) + +static void +CompareBitmapData(const struct BitmapData *readin, + const struct BitmapData *expected) +{ + size_t bytes_per_line; + size_t total_bytes; + + g_assert_cmpuint(readin->width, ==, expected->width); + g_assert_cmpuint(readin->height, ==, expected->height); + g_assert_cmpint(readin->xhot, ==, expected->xhot); + g_assert_cmpint(readin->yhot, ==, expected->yhot); + + bytes_per_line = (readin->width + 7) / 8; + total_bytes = bytes_per_line * readin->height; + g_assert_cmpmem(readin->datap, total_bytes, expected->datap, total_bytes); +} + + +static void +test_ReadBitmapData(void) +{ + for (unsigned int i = 0; i < testcount; i++) { + const gchar *filename; + FILE *fp; + int status; + struct BitmapData readin; + + filename = g_test_get_filename(G_TEST_DIST, "bitmaps", + testdata[i].filename, NULL); + + g_test_message("Testing XmuReadBitmapDataFromFile(\"%s\")", filename); + + status = XmuReadBitmapDataFromFile(filename, + &readin.width, &readin.height, + &readin.datap, + &readin.xhot, &readin.yhot); + g_assert_cmpint(status, ==, Success); + CompareBitmapData(&readin, testdata[i].data); + + + g_test_message("Testing XmuReadBitmapData on \"%s\"", filename); + fp = fopen(filename, "r"); + g_assert_nonnull(fp); + + status = XmuReadBitmapData(fp, + &readin.width, &readin.height, + &readin.datap, + &readin.xhot, &readin.yhot); + g_assert_cmpint(status, ==, Success); + CompareBitmapData(&readin, testdata[i].data); + fclose(fp); + } +} + +int +main(int argc, char** argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_bug_base(PACKAGE_BUGREPORT); + + g_test_add_func("/RdBitF/ReadBitmapData", + test_ReadBitmapData); + + return g_test_run(); +} diff --git a/test/bitmaps/plaid b/test/bitmaps/plaid new file mode 100644 index 0000000..578e464 --- /dev/null +++ b/test/bitmaps/plaid @@ -0,0 +1,11 @@ +#define plaid_width 22 +#define plaid_height 22 +#define plaid_x_hot -1 +#define plaid_y_hot -1 +static char plaid_bits[] = { + 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, + 0x75, 0xfd, 0x3f, 0xff, 0x57, 0x15, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, + 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0x20, 0xa8, 0x2b, + 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, + 0xff, 0xff, 0x3f, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, + 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b}; diff --git a/test/bitmaps/star b/test/bitmaps/star new file mode 100644 index 0000000..c98f1a4 --- /dev/null +++ b/test/bitmaps/star @@ -0,0 +1,8 @@ +#define star_width 16 +#define star_height 16 +#define star_x_hot 7 +#define star_y_hot 7 +static char star_bits[] = { + 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x88, 0x08, 0x90, 0x04, 0xa0, 0x02, + 0x40, 0x01, 0x3e, 0x3e, 0x40, 0x01, 0xa0, 0x02, 0x90, 0x04, 0x88, 0x08, + 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/test/bitmaps/xlogo64 b/test/bitmaps/xlogo64 new file mode 100644 index 0000000..ad3b0db --- /dev/null +++ b/test/bitmaps/xlogo64 @@ -0,0 +1,46 @@ +#define xlogo64_width 64 +#define xlogo64_height 64 +static unsigned char xlogo64_bits[] = { + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfe, 0xff, 0x01, 0x00, + 0x00, 0x00, 0x00, 0xf8, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x7c, + 0xf8, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x3e, 0xf8, 0xff, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x1f, 0xf0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x0f, + 0xe0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x80, 0x0f, 0xc0, 0xff, 0x3f, 0x00, + 0x00, 0x00, 0xc0, 0x07, 0xc0, 0xff, 0x3f, 0x00, 0x00, 0x00, 0xe0, 0x03, + 0x80, 0xff, 0x7f, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0xff, 0xff, 0x00, + 0x00, 0x00, 0xf8, 0x00, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x00, 0xf8, 0x00, + 0x00, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x7c, 0x00, 0x00, 0xfc, 0xff, 0x03, + 0x00, 0x00, 0x3e, 0x00, 0x00, 0xf8, 0xff, 0x07, 0x00, 0x00, 0x1f, 0x00, + 0x00, 0xf0, 0xff, 0x0f, 0x00, 0x80, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0x0f, + 0x00, 0xc0, 0x07, 0x00, 0x00, 0xe0, 0xff, 0x1f, 0x00, 0xc0, 0x07, 0x00, + 0x00, 0xc0, 0xff, 0x3f, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x80, 0xff, 0x7f, + 0x00, 0xf0, 0x01, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0xf8, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, + 0x01, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x3e, 0x00, 0x00, + 0x00, 0x00, 0xfc, 0xff, 0x03, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, + 0x87, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xcf, 0x07, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xff, 0xcf, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xe7, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xf3, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x80, 0xff, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x7e, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, + 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9f, 0xff, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x80, 0xcf, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe7, + 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe7, 0xff, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xc3, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc1, + 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x80, 0xff, 0x7f, 0x00, 0x00, + 0x00, 0x00, 0x7c, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, + 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0xfe, 0xff, 0x01, 0x00, + 0x00, 0x00, 0x1f, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x80, 0x0f, 0x00, + 0xf8, 0xff, 0x07, 0x00, 0x00, 0xc0, 0x07, 0x00, 0xf0, 0xff, 0x0f, 0x00, + 0x00, 0xe0, 0x03, 0x00, 0xf0, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0x03, 0x00, + 0xe0, 0xff, 0x1f, 0x00, 0x00, 0xf0, 0x01, 0x00, 0xc0, 0xff, 0x3f, 0x00, + 0x00, 0xf8, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x7c, 0x00, 0x00, + 0x80, 0xff, 0x7f, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, + 0x00, 0x3e, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x1f, 0x00, 0x00, + 0x00, 0xfc, 0xff, 0x03, 0x80, 0x0f, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, + 0xc0, 0x07, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x07, 0xe0, 0x03, 0x00, 0x00, + 0x00, 0xf0, 0xff, 0x0f, 0xe0, 0x03, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x1f, + 0xf0, 0x01, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x1f, 0xf8, 0x00, 0x00, 0x00, + 0x00, 0xc0, 0xff, 0x3f, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, + 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff}; -- cgit v1.2.1