summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-06-27 18:31:41 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-06-27 19:29:59 (EDT)
commit680815fe2a26d8c48b6abf3b42b0c0aa5ec64fc7 (patch)
tree1965d2fd1fec323828289f39d70ac1c9ed8bd812
parent1e16609b8eac585fc0679ca4466b2c1f56ecebae (diff)
tests: Test helpers/mode
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/local.mk9
-rw-r--r--tests/mode.c50
-rwxr-xr-xtests/mode.sh3
4 files changed, 63 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 966477b..fd17e2a 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,3 +1,4 @@
*.log
*.trs
+mode
pkg.opk
diff --git a/tests/local.mk b/tests/local.mk
index 84833d1..e61da9c 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -1,11 +1,20 @@
+check_PROGRAMS = \
+ %reldir%/mode
+tests_mode_SOURCES = \
+ helpers/defs.h \
+ helpers/mode.c \
+ helpers/mode.h \
+ %reldir%/mode.c
TESTS = \
%reldir%/version.sh \
+ %reldir%/mode.sh \
%reldir%/build.sh
TEST_EXTENSIONS = .sh
SH_LOG_DRIVER = \
AM_TAP_AWK='$(AWK)' \
TOP_SRCDIR="$(abs_top_srcdir)" \
TOP_BUILDDIR="$(abs_top_builddir)" \
+ EXEEXT="$(EXEEXT)" \
$(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
EXTRA_DIST += \
$(TESTS) \
diff --git a/tests/mode.c b/tests/mode.c
new file mode 100644
index 0000000..3944263
--- /dev/null
+++ b/tests/mode.c
@@ -0,0 +1,50 @@
+/*
+ * 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 <sys/stat.h>
+#include "../helpers/defs.h"
+#include "../helpers/mode.h"
+
+static unsigned int _test_num = 0U;
+
+static void
+_test(mode_t cur_mode, const char *mode_str, int exp_ret, mode_t exp_mode)
+{
+ mode_t got_mode;
+
+ if (opkg_opk_helper_mode_parse(cur_mode, mode_str, &got_mode)
+ != exp_ret
+ || got_mode != exp_mode) {
+ fputs("not ", stdout);
+ }
+ printf("ok %u - cur_mode=0%06o mode_str=\"%s\"\n",
+ ++_test_num, cur_mode, mode_str);
+ printf("\texp=0%06o got=0%06o\n", exp_mode, got_mode);
+}
+
+int
+main()
+{
+ puts("1..1");
+ _test(0000644, "a+x", OPKG_OPK_OK, 0000755);
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/mode.sh b/tests/mode.sh
new file mode 100755
index 0000000..4d87288
--- /dev/null
+++ b/tests/mode.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}"