diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/common/test_contracts.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/common/test_contracts.c b/tests/common/test_contracts.c index 654eb1e..d1964ff 100644 --- a/tests/common/test_contracts.c +++ b/tests/common/test_contracts.c @@ -1,3 +1,4 @@ +#define _POSIX_C_SOURCE 200809L #include "common/backend.h" #include "common/input.h" #include "common/timing.h" @@ -5,8 +6,10 @@ #include <assert.h> #include <errno.h> #include <math.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> static void test_timing_clock(void) { @@ -182,6 +185,52 @@ static void test_held_buttons(void) input_queue_clear(&q); } +static void test_drop_paths(void) +{ + char host[256] = ""; + assert(gethostname(host, sizeof(host)) == 0); + char list[1024]; + snprintf(list, sizeof(list), + "# comment\r\n" + "\r\n" + "file:///home/user/a%%20b.txt\r\n" + "https://example.com/x\r\n" + "file://elsewhere.invalid/remote\r\n" + "file://localhost/tmp/%%C3%%A9t%%C3%%A9 \r\n" + "file://%s/srv/x\r\n" + "FILE:/single/slash\n" + "file:///bad%%2\r\n" + "file:///nul%%00byte\r\n" + "file:///q?query#frag\r\n" + "file:relative\r\n" + "file:///last", + host); + static const char *const want[] = { + "/home/user/a b.txt", "/tmp/\xc3\xa9t\xc3\xa9", "/srv/x", "/single/slash", + "/q", "/last", + }; + const char *cursor = list; + char path[64]; + for (size_t i = 0; i < sizeof(want) / sizeof(want[0]); i++) { + size_t len = strlen(want[i]); + /* A short buffer reports the length and leaves both outputs alone. */ + const char *before = cursor; + memcpy(path, "keep", 5); + assert(yasl_drop_next_path(&cursor, path, len) == len); + assert(cursor == before && strcmp(path, "keep") == 0); + assert(yasl_drop_next_path(&cursor, NULL, 0) == len && cursor == before); + assert(yasl_drop_next_path(&cursor, path, sizeof(path)) == len); + assert(strcmp(path, want[i]) == 0); + } + assert(yasl_drop_next_path(&cursor, path, sizeof(path)) == 0 && *cursor == '\0'); + assert(yasl_drop_next_path(&cursor, path, sizeof(path)) == 0); + assert(yasl_drop_next_path(NULL, path, sizeof(path)) == 0); + const char *none = NULL; + assert(yasl_drop_next_path(&none, path, sizeof(path)) == 0); + cursor = list; + assert(yasl_drop_next_path(&cursor, NULL, 8) == 0 && cursor == list); +} + static void test_native(void) { const struct yasl_backend_ops ops = {.display_caps = native_caps, @@ -372,6 +421,7 @@ int main(void) test_surface_state(); test_queue(); test_held_buttons(); + test_drop_paths(); test_validation(); test_native(); test_scale(); |
