diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-07-31 03:43:26 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-07-31 03:43:26 (EDT) |
commit | a31530c334fac67a5c051fd22f6f86dfbaf30e2c (patch) | |
tree | 06cb40a1024bef3d0fb6305ec56d6e6d93d48078 | |
parent | df4d21ee4349e18b4a0edde0fa777020913fd738 (diff) |
tests: Add dirent tests
Based on test code removed in commit
ceb7c5fd1ee2705b09aac143931a925a6f23d7eb.
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/dirent.c | 63 | ||||
-rwxr-xr-x | tests/dirent.sh | 3 | ||||
-rw-r--r-- | tests/local.mk | 12 |
4 files changed, 78 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 1a78c9e..2154dc1 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,6 +1,7 @@ *.log *.trs mode +dirent pkg.opk pkg/data/dev/null pkg/specials diff --git a/tests/dirent.c b/tests/dirent.c new file mode 100644 index 0000000..6446806 --- /dev/null +++ b/tests/dirent.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 Patrick McDermott + * + * This file is part of opkg-opk. + * + * opkg-opk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * opkg-opk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with opkg-opk. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "defs.h" +#include "dirent.h" + +int +main() +{ + struct opkg_opk_dirent foo = { + .name = "foo", + .parent = NULL, + }; + struct opkg_opk_dirent bar = { + .name = "bar", + .parent = &foo, + }; + struct opkg_opk_dirent baz = { + .name = "baz", + .parent = &bar, + }; + char name[8]; + char pref[4]; + + puts("1..2"); + + if (opkg_opk_dirent_name_prefix(&baz, 0, name, sizeof(name), + pref, sizeof(pref)) != OPKG_OPK_OK || + strcmp(pref, "foo") != 0 || + strcmp(name, "bar/baz") != 0) { + fputs("not ", stdout); + } + printf("ok 1 - \"%s\" + \"%s\"\n", pref, name); + + if (opkg_opk_dirent_name_prefix(&baz, 1, name, sizeof(name), + pref, sizeof(pref)) != OPKG_OPK_OK || + strcmp(pref, "foo") != 0 || + strcmp(name, "bar/baz/") != 0) { + fputs("not ", stdout); + } + printf("ok 2 - \"%s\" + \"%s\"\n", pref, name); + + return EXIT_SUCCESS; +} diff --git a/tests/dirent.sh b/tests/dirent.sh new file mode 100755 index 0000000..4d87288 --- /dev/null +++ b/tests/dirent.sh @@ -0,0 +1,3 @@ +# Automake can't seem to figure out how to use <build-aux/tap-driver.sh> to run +# compiled tests, so this ugly hack is needed. +exec "${0%.sh}${EXEEXT}" diff --git a/tests/local.mk b/tests/local.mk index 0045124..eb04ae6 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -1,5 +1,6 @@ check_PROGRAMS = \ - %reldir%/mode + %reldir%/mode \ + %reldir%/dirent tests_mode_SOURCES = \ common/defs.h \ common/mode.c \ @@ -7,9 +8,18 @@ tests_mode_SOURCES = \ %reldir%/mode.c tests_mode_CPPFLAGS = \ -I"$(top_srcdir)/common" +tests_dirent_SOURCES = \ + common/defs.h \ + opkg-opk/dirent.c \ + opkg-opk/dirent.h \ + %reldir%/dirent.c +tests_dirent_CPPFLAGS = \ + -I"$(top_srcdir)/common" \ + -I"$(top_srcdir)/opkg-opk" TESTS = \ %reldir%/version.sh \ %reldir%/mode.sh \ + %reldir%/dirent.sh \ %reldir%/build.sh TEST_EXTENSIONS = .sh SH_LOG_DRIVER = \ |