Mercurial > molko
changeset 422:b0579ae033ed
core: use err.h in (action|drawable)-stack
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 15 Oct 2022 13:48:40 +0200 |
parents | 3edda1ce314c |
children | 63ebfa352ae1 |
files | extern/libdt/dt.h src/libmlk-core/core/action-stack.c src/libmlk-core/core/drawable-stack.c tests/test-action.c tests/test-character.c tests/test-drawable.c tests/test-map.c tests/test-save.c tests/test-tileset.c tests/test-vfs-zip.c |
diffstat | 10 files changed, 39 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/extern/libdt/dt.h Thu Oct 13 20:56:42 2022 +0200 +++ b/extern/libdt/dt.h Sat Oct 15 13:48:40 2022 +0200 @@ -21,6 +21,7 @@ #include <inttypes.h> #include <math.h> +#include <stddef.h> #include <stdint.h> #include <stdio.h> #include <string.h> @@ -115,12 +116,30 @@ dt_nchecks - nchecks, dt_nfailures - nfailures); \ } while (0) +#define DT_RUN_EX(f, init, fini, ...) \ +do { \ + const size_t nchecks = dt_nchecks; \ + const size_t nfailures = dt_nfailures; \ + \ + ++ dt_ntests; \ + \ + printf("== test " #f " ==\n"); \ + init(__VA_ARGS__); \ + f(__VA_ARGS__); \ + fini(__VA_ARGS__); \ + \ + printf("\n%zu checks, %zu failures\n\n", \ + dt_nchecks - nchecks, dt_nfailures - nfailures); \ +} while (0) + #define DT_SUMMARY() \ do { \ printf("summary: %zu tests, %zu checks, %zu failures\n", \ dt_ntests, dt_nchecks, dt_nfailures); \ } while (0) +#define DT_EXIT() (dt_nfailures != 0) + /* Aliases for basic types. */ #define DT_EQ_CHAR(x, y) DT_EQ(x, y, char, "%c") #define DT_EQ_SHORT(x, y) DT_EQ(x, y, short, "%hd") @@ -133,6 +152,8 @@ #define DT_EQ_ULLONG(x, y) DT_EQ(x, y, unsigned long long, "%llu") #define DT_EQ_INTMAX(x, y) DT_EQ(x, y, intmax_t, "%jd") #define DT_EQ_UINTMAX(x, y) DT_EQ(x, y, uintmax_t, "%ju") +#define DT_EQ_SIZE(x, y) DT_EQ(x, y, size_t, "%zu") +#define DT_EQ_PTRDIFF(x, y) DT_EQ(x, y, ptrdiff_t, "%td") /* Aliases for fixed size integers. */ #define DT_EQ_INT8(x, y) DT_EQ(x, y, int8_t, PRId8)
--- a/src/libmlk-core/core/action-stack.c Thu Oct 13 20:56:42 2022 +0200 +++ b/src/libmlk-core/core/action-stack.c Sat Oct 15 13:48:40 2022 +0200 @@ -19,8 +19,9 @@ #include <assert.h> #include <string.h> +#include "action-stack.h" #include "action.h" -#include "action-stack.h" +#include "err.h" #define ACTION_FOREACH(st, iter) \ for (size_t i = 0; i < (st)->actionsz && ((iter) = (st)->actions[i], 1); ++i) @@ -50,7 +51,7 @@ } } - return -1; + return ERR_NO_MEM; } void @@ -120,7 +121,7 @@ action_stack_finish(struct action_stack *st) { assert(st); - + struct action *act; ACTION_FOREACH(st, act) {
--- a/src/libmlk-core/core/drawable-stack.c Thu Oct 13 20:56:42 2022 +0200 +++ b/src/libmlk-core/core/drawable-stack.c Sat Oct 15 13:48:40 2022 +0200 @@ -21,6 +21,7 @@ #include "drawable.h" #include "drawable-stack.h" +#include "err.h" #define DRAWABLE_FOREACH(st, iter) \ for (size_t i = 0; i < (st)->objectsz && ((iter) = (st)->objects[i], 1); ++i) @@ -50,7 +51,7 @@ } } - return -1; + return ERR_NO_MEM; } int
--- a/tests/test-action.c Thu Oct 13 20:56:42 2022 +0200 +++ b/tests/test-action.c Sat Oct 15 13:48:40 2022 +0200 @@ -16,8 +16,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <core/action-stack.h> #include <core/action.h> -#include <core/action-stack.h> +#include <core/err.h> #include <core/event.h> #include <dt.h> @@ -191,7 +192,7 @@ DT_EQ_INT(action_stack_add(&st, &act), 0); /* This one should not fit in. */ - DT_EQ_INT(action_stack_add(&st, &act), -1); + DT_EQ_INT(action_stack_add(&st, &act), ERR_NO_MEM); } static void
--- a/tests/test-character.c Thu Oct 13 20:56:42 2022 +0200 +++ b/tests/test-character.c Sat Oct 15 13:48:40 2022 +0200 @@ -63,7 +63,7 @@ } int -main(int argc, char **argv) +main(void) { remove("test.db");
--- a/tests/test-drawable.c Thu Oct 13 20:56:42 2022 +0200 +++ b/tests/test-drawable.c Sat Oct 15 13:48:40 2022 +0200 @@ -16,8 +16,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <core/drawable-stack.h> #include <core/drawable.h> -#include <core/drawable-stack.h> +#include <core/err.h> #include <core/event.h> #include <dt.h> @@ -159,7 +160,7 @@ DT_EQ_INT(drawable_stack_add(&st, &dw), 0); /* This one should not fit in. */ - DT_EQ_INT(drawable_stack_add(&st, &dw), -1); + DT_EQ_INT(drawable_stack_add(&st, &dw), ERR_NO_MEM); } static void
--- a/tests/test-map.c Thu Oct 13 20:56:42 2022 +0200 +++ b/tests/test-map.c Sat Oct 15 13:48:40 2022 +0200 @@ -126,7 +126,7 @@ } int -main(int argc, char **argv) +main(void) { /* * This test opens graphical images and therefore need to initialize a
--- a/tests/test-save.c Thu Oct 13 20:56:42 2022 +0200 +++ b/tests/test-save.c Sat Oct 15 13:48:40 2022 +0200 @@ -137,7 +137,7 @@ int main(void) { - DT_RUN(test_basics_read); - DT_RUN(test_basics_write); + DT_RUN_EX(test_basics_read, cleanup, cleanup); + DT_RUN_EX(test_basics_write, cleanup, cleanup); DT_SUMMARY(); }