summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/dirent.c63
-rwxr-xr-xtests/dirent.sh3
-rw-r--r--tests/local.mk12
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 = \