From e45499816eab8abadbdd5bb6dd79b526a4ed6648 Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Sat, 11 Feb 2023 23:03:39 +0100 Subject: Implement undo This also fixes a bunch of valgrind errors --- test/minibuffer.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test/minibuffer.c') diff --git a/test/minibuffer.c b/test/minibuffer.c index dc29648..0e41c7b 100644 --- a/test/minibuffer.c +++ b/test/minibuffer.c @@ -2,12 +2,17 @@ #include "stdlib.h" #include "test.h" +#include "allocator.h" #include "buffer.h" #include "display.h" #include "minibuffer.h" static struct buffer b = {0}; +static struct frame_allocator *g_alloc = NULL; + +void *alloc_fn(size_t sz) { return frame_allocator_alloc(g_alloc, sz); } + void init() { if (b.name == NULL) { b = buffer_create("minibuffer", false); @@ -16,12 +21,21 @@ void init() { minibuffer_init(&b); } +void destroy() { + if (b.name != NULL) { + buffer_destroy(&b); + } +} + void test_minibuffer_echo() { uint32_t relline, relcol; // TODO: how to clear this? + struct frame_allocator alloc = frame_allocator_create(1024); + g_alloc = &alloc; + struct command_list *list = - command_list_create(10, malloc, 0, 0, "minibuffer"); + command_list_create(10, alloc_fn, 0, 0, "minibuffer"); init(); ASSERT(!minibuffer_displaying(), @@ -38,6 +52,10 @@ void test_minibuffer_echo() { buffer_update(&b, 100, 1, list, 0, &relline, &relcol); ASSERT(!minibuffer_displaying(), "A zero timeout echo should be cleared after first update"); + + frame_allocator_destroy(&alloc); + g_alloc = NULL; + destroy(); } int32_t fake(struct command_ctx ctx, int argc, const char *argv[]) { return 0; } @@ -64,6 +82,7 @@ void test_minibuffer_prompt() { minibuffer_abort_prompt(); ASSERT(!minibuffer_focused(), "Minibuffer must not be focused after prompt has been aborted"); + destroy(); } void run_minibuffer_tests() { -- cgit v1.2.3