# HG changeset patch # User Mike Becker # Date 1788429259 -7200 # Node ID cf7b86d79d351795e19cbd6e31548a7f49f871d2 # Parent 16a114c84ff5011dfd7c4cd09a5fcdf7058d8525 add (empty) test suites for all pieces diff -r 16a114c84ff5 -r cf7b86d79d35 test/Makefile --- a/test/Makefile Thu Sep 03 11:53:58 2026 +0200 +++ b/test/Makefile Thu Sep 03 11:54:19 2026 +0200 @@ -31,7 +31,14 @@ SRC = run-tests.c \ test-datatypes.c \ test-rules-helper.c \ - test-real-pgn.c + test-real-pgn.c \ + test-pawn.c \ + test-rook.c \ + test-knight.c \ + test-bishop.c \ + test-queen.c \ + test-king.c \ + OBJ = $(SRC:%.c=$(BUILDDIR)/%.o) @@ -48,10 +55,30 @@ @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< +$(BUILDDIR)/test-bishop.o: test-bishop.c ../src/chess/rules.h ucxtest.h + @echo "Compiling $<" + $(CC) -o $@ $(CFLAGS) -c $< + $(BUILDDIR)/test-datatypes.o: test-datatypes.c ../src/chess/rules.h @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< +$(BUILDDIR)/test-king.o: test-king.c ../src/chess/rules.h ucxtest.h + @echo "Compiling $<" + $(CC) -o $@ $(CFLAGS) -c $< + +$(BUILDDIR)/test-knight.o: test-knight.c ../src/chess/rules.h ucxtest.h + @echo "Compiling $<" + $(CC) -o $@ $(CFLAGS) -c $< + +$(BUILDDIR)/test-pawn.o: test-pawn.c ../src/chess/rules.h ucxtest.h + @echo "Compiling $<" + $(CC) -o $@ $(CFLAGS) -c $< + +$(BUILDDIR)/test-queen.o: test-queen.c ../src/chess/rules.h ucxtest.h + @echo "Compiling $<" + $(CC) -o $@ $(CFLAGS) -c $< + $(BUILDDIR)/test-real-pgn.o: test-real-pgn.c ucxtest.h ../src/chess/pgn.h \ ../src/chess/rules.h data/game001.pgn data/game002.pgn data/game003.pgn \ data/game004.pgn data/game005.pgn data/game006.pgn data/game007.pgn \ @@ -94,6 +121,10 @@ @echo "Compiling $<" $(CC) -o $@ $(CFLAGS) -c $< +$(BUILDDIR)/test-rook.o: test-rook.c ../src/chess/rules.h ucxtest.h + @echo "Compiling $<" + $(CC) -o $@ $(CFLAGS) -c $< + $(BUILDDIR)/test-rules-helper.o: test-rules-helper.c ucxtest.h \ ../src/chess/rules.h @echo "Compiling $<" diff -r 16a114c84ff5 -r cf7b86d79d35 test/run-tests.c --- a/test/run-tests.c Thu Sep 03 11:53:58 2026 +0200 +++ b/test/run-tests.c Thu Sep 03 11:54:19 2026 +0200 @@ -32,10 +32,23 @@ CxTestSuite *test_real_pgn_suite(void); CxTestSuite *test_rules_helper_suite(void); +CxTestSuite *test_pawn_suite(void); +CxTestSuite *test_rook_suite(void); +CxTestSuite *test_knight_suite(void); +CxTestSuite *test_bishop_suite(void); +CxTestSuite *test_queen_suite(void); +CxTestSuite *test_king_suite(void); + int main(void) { CxTestSuite *suites[] = { test_real_pgn_suite(), - test_rules_helper_suite() + test_rules_helper_suite(), + test_pawn_suite(), + test_rook_suite(), + test_knight_suite(), + test_bishop_suite(), + test_queen_suite(), + test_king_suite(), }; size_t suites_count = sizeof(suites)/sizeof(CxTestSuite *); unsigned int failure = 0, success = 0; diff -r 16a114c84ff5 -r cf7b86d79d35 test/test-bishop.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test-bishop.c Thu Sep 03 11:54:19 2026 +0200 @@ -0,0 +1,39 @@ +/* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "chess/rules.h" +#include "ucxtest.h" + + + +CxTestSuite* test_bishop_suite(void) { + CxTestSuite* suite = cx_test_suite_new("Test Bishop Moves"); + + return suite; +} diff -r 16a114c84ff5 -r cf7b86d79d35 test/test-king.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test-king.c Thu Sep 03 11:54:19 2026 +0200 @@ -0,0 +1,39 @@ +/* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "chess/rules.h" +#include "ucxtest.h" + + + +CxTestSuite* test_king_suite(void) { + CxTestSuite* suite = cx_test_suite_new("Test King Moves"); + + return suite; +} diff -r 16a114c84ff5 -r cf7b86d79d35 test/test-knight.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test-knight.c Thu Sep 03 11:54:19 2026 +0200 @@ -0,0 +1,39 @@ +/* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "chess/rules.h" +#include "ucxtest.h" + + + +CxTestSuite* test_knight_suite(void) { + CxTestSuite* suite = cx_test_suite_new("Test Knight Moves"); + + return suite; +} diff -r 16a114c84ff5 -r cf7b86d79d35 test/test-pawn.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test-pawn.c Thu Sep 03 11:54:19 2026 +0200 @@ -0,0 +1,39 @@ +/* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "chess/rules.h" +#include "ucxtest.h" + + + +CxTestSuite* test_pawn_suite(void) { + CxTestSuite* suite = cx_test_suite_new("Test Pawn Moves"); + + return suite; +} diff -r 16a114c84ff5 -r cf7b86d79d35 test/test-queen.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test-queen.c Thu Sep 03 11:54:19 2026 +0200 @@ -0,0 +1,39 @@ +/* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "chess/rules.h" +#include "ucxtest.h" + + + +CxTestSuite* test_queen_suite(void) { + CxTestSuite* suite = cx_test_suite_new("Test Queen Moves"); + + return suite; +} diff -r 16a114c84ff5 -r cf7b86d79d35 test/test-rook.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test-rook.c Thu Sep 03 11:54:19 2026 +0200 @@ -0,0 +1,39 @@ +/* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2026 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "chess/rules.h" +#include "ucxtest.h" + + + +CxTestSuite* test_rook_suite(void) { + CxTestSuite* suite = cx_test_suite_new("Test Rook Moves"); + + return suite; +} diff -r 16a114c84ff5 -r cf7b86d79d35 test/ucxtest.h --- a/test/ucxtest.h Thu Sep 03 11:53:58 2026 +0200 +++ b/test/ucxtest.h Thu Sep 03 11:54:19 2026 +0200 @@ -48,7 +48,7 @@ * * CX_TEST(function_name) { * // memory allocation and other stuff here - * #CX_TEST_DO { + * CX_TEST_DO { * // tests with CX_TEST_ASSERT() and/or * // calls with CX_TEST_CALL_SUBROUTINE() here * } @@ -72,8 +72,6 @@ #include #include -typedef size_t (*cx_write_func)(const void*, size_t, size_t, void*); - #ifndef __FUNCTION__ /** * Alias for the __func__ preprocessor macro. @@ -86,14 +84,16 @@ #if !defined(__clang__) && __GNUC__ > 3 #pragma GCC diagnostic ignored "-Wclobbered" -#pragma GCC diagnostic ignored "-Wunused-function" #endif /** Type for the CxTestSuite. */ typedef struct CxTestSuite CxTestSuite; +/** Output function compatible to cx_write_func */ +typedef size_t (*cx_test_output_func)(const void*, size_t, size_t, void*); + /** Pointer to a test function. */ -typedef void(*CxTest)(CxTestSuite *, void *, cx_write_func); +typedef void(*CxTest)(CxTestSuite *, void *, cx_test_output_func); /** Type for the internal list of test cases. */ typedef struct CxTestSet CxTestSet; @@ -134,7 +134,7 @@ * @param name optional name of the suite * @return a new test suite */ -static CxTestSuite* cx_test_suite_new(const char *name) { +static inline CxTestSuite* cx_test_suite_new(const char *name) { CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite)); if (suite != NULL) { suite->name = name; @@ -151,7 +151,7 @@ * * @param suite the test suite to free */ -static void cx_test_suite_free(CxTestSuite* suite) { +static inline void cx_test_suite_free(CxTestSuite* suite) { if (suite == NULL) return; CxTestSet *l = suite->tests; while (l != NULL) { @@ -170,7 +170,7 @@ * @retval zero success * @retval non-zero failure */ -static int cx_test_register(CxTestSuite* suite, CxTest test) { +static inline int cx_test_register(CxTestSuite* suite, CxTest test) { CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet)); if (t) { t->test = test; @@ -196,7 +196,8 @@ * @param out_target the target buffer or file to write the output to * @param out_writer the write function writing to @p out_target */ -static void cx_test_run(CxTestSuite *suite, void *out_target, cx_write_func out_writer) { +static inline void cx_test_run(CxTestSuite *suite, void *out_target, + cx_test_output_func out_writer) { if (suite->name == NULL) { out_writer("*** Test Suite ***\n", 1, 19, out_target); } else { @@ -224,7 +225,8 @@ * @param suite (@c CxTestSuite*) the test suite to run * @param file (@c FILE*) the target file to write the output to */ -#define cx_test_run_f(suite, file) cx_test_run(suite, (void*)file, (cx_write_func)fwrite) +#define cx_test_run_f(suite, file) cx_test_run(suite, (void*)file, \ + (cx_test_output_func) fwrite) /** * Runs a test suite and writes the test log to stdout. @@ -239,7 +241,8 @@ * * @param name the name of the test function */ -#define CX_TEST(name) void name(CxTestSuite* _suite_,void *_output_, cx_write_func _writefnc_) +#define CX_TEST(name) void name(CxTestSuite* _suite_,void *_output_, \ + cx_test_output_func _writefnc_) /** * Defines the scope of a test. @@ -289,7 +292,8 @@ * written to the test suites output stream. * @param condition (@c bool) the condition to check */ -#define CX_TEST_ASSERT(condition) CX_TEST_ASSERTM(condition, #condition " failed") +#define CX_TEST_ASSERT(condition) \ + CX_TEST_ASSERTM(condition, #condition " failed") /** * Macro for a test subroutine function header. @@ -303,7 +307,8 @@ * @see CX_TEST_CALL_SUBROUTINE() */ #define CX_TEST_SUBROUTINE(name,...) void name(CxTestSuite* _suite_,\ - void *_output_, cx_write_func _writefnc_, jmp_buf _env_, __VA_ARGS__) + void *_output_, cx_test_output_func _writefnc_, \ + jmp_buf _env_, __VA_ARGS__) /** * Macro for calling a test subroutine.