diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/allocator.c | 31 | ||||
| -rw-r--r-- | test/main.c | 7 | ||||
| -rw-r--r-- | test/minibuffer.c | 72 | ||||
| -rw-r--r-- | test/test.h | 7 |
4 files changed, 116 insertions, 1 deletions
diff --git a/test/allocator.c b/test/allocator.c new file mode 100644 index 0000000..ca1a7a0 --- /dev/null +++ b/test/allocator.c @@ -0,0 +1,31 @@ +#include "assert.h" +#include "test.h" + +#include "allocator.h" + +void test_frame_allocator() { + struct frame_allocator fa = frame_allocator_create(128); + + ASSERT(fa.capacity == 128, + "Expected frame allocator to be created with specified capacity"); + + void *bytes = frame_allocator_alloc(&fa, 128); + ASSERT( + bytes != NULL, + "Expected to be able to allocate <capacity> bytes from frame allocator"); + + void *bytes_again = frame_allocator_alloc(&fa, 128); + ASSERT(bytes_again == NULL, + "Expected to not be able to allocate <capacity> bytes " + "from frame allocator a second time"); + + frame_allocator_clear(&fa); + void *bytes_after_clear = frame_allocator_alloc(&fa, 128); + ASSERT(bytes_after_clear != NULL, + "Expected to be able to allocate <capacity> bytes from frame " + "allocator again after clearing it"); + + frame_allocator_destroy(&fa); +} + +void run_allocator_tests() { run_test(test_frame_allocator); } diff --git a/test/main.c b/test/main.c index 68241f9..7663f8f 100644 --- a/test/main.c +++ b/test/main.c @@ -4,7 +4,6 @@ #include <stdlib.h> #include <time.h> -#include "bits/time.h" #include "test.h" void handle_abort() { exit(1); } @@ -31,6 +30,12 @@ int main() { printf("\nš \x1b[1;36mRunning keyboard tests...\x1b[0m\n"); run_keyboard_tests(); + printf("\nš¾ \x1b[1;36mRunning allocator tests...\x1b[0m\n"); + run_allocator_tests(); + + printf("\nš \x1b[1;36mRunning minibuffer tests...\x1b[0m\n"); + run_minibuffer_tests(); + struct timespec elapsed; clock_gettime(CLOCK_MONOTONIC, &elapsed); uint64_t elapsed_nanos = diff --git a/test/minibuffer.c b/test/minibuffer.c new file mode 100644 index 0000000..dc29648 --- /dev/null +++ b/test/minibuffer.c @@ -0,0 +1,72 @@ +#include "assert.h" +#include "stdlib.h" +#include "test.h" + +#include "buffer.h" +#include "display.h" +#include "minibuffer.h" + +static struct buffer b = {0}; + +void init() { + if (b.name == NULL) { + b = buffer_create("minibuffer", false); + } + + minibuffer_init(&b); +} + +void test_minibuffer_echo() { + uint32_t relline, relcol; + + // TODO: how to clear this? + struct command_list *list = + command_list_create(10, malloc, 0, 0, "minibuffer"); + + init(); + ASSERT(!minibuffer_displaying(), + "Minibuffer should have nothing to display before echoing"); + + minibuffer_echo("Test %s", "test"); + ASSERT(minibuffer_displaying(), "Minibuffer should now have text to display"); + + minibuffer_clear(); + ASSERT(!minibuffer_displaying(), + "Minibuffer should have nothing to display after clearing"); + + minibuffer_echo_timeout(0, "You will not see me"); + buffer_update(&b, 100, 1, list, 0, &relline, &relcol); + ASSERT(!minibuffer_displaying(), + "A zero timeout echo should be cleared after first update"); +} + +int32_t fake(struct command_ctx ctx, int argc, const char *argv[]) { return 0; } + +void test_minibuffer_prompt() { + init(); + ASSERT(!minibuffer_focused(), + "Minibuffer should not be focused without reason"); + + struct command cmd = { + .fn = fake, + .name = "fake", + .userdata = NULL, + }; + struct command_ctx ctx = {.commands = NULL, + .active_window = NULL, + .buffers = NULL, + .userdata = NULL, + .self = &cmd}; + minibuffer_prompt(ctx, "prompt %s: ", "yes"); + + ASSERT(minibuffer_focused(), "Minibuffer should get focused when prompting"); + + minibuffer_abort_prompt(); + ASSERT(!minibuffer_focused(), + "Minibuffer must not be focused after prompt has been aborted"); +} + +void run_minibuffer_tests() { + run_test(test_minibuffer_echo); + run_test(test_minibuffer_prompt); +} diff --git a/test/test.h b/test/test.h index 2d9d8af..f777916 100644 --- a/test/test.h +++ b/test/test.h @@ -1,3 +1,6 @@ +#ifndef _TEST_H_ +#define _TEST_H_ + #include <stdio.h> #define run_test(fn) \ @@ -11,3 +14,7 @@ void run_utf8_tests(); void run_text_tests(); void run_command_tests(); void run_keyboard_tests(); +void run_allocator_tests(); +void run_minibuffer_tests(); + +#endif |
