tests: Add otcore unit tests
authorColin Walters <walters@verbum.org>
Tue, 22 Aug 2023 17:04:12 +0000 (13:04 -0400)
committerColin Walters <walters@verbum.org>
Tue, 22 Aug 2023 17:04:46 +0000 (13:04 -0400)
This just stubs out the basic infrastructure, to be expanded upon.

Makefile-tests.am
tests/test-otcore.c [new file with mode: 0644]

index 5544a6bf05c88e67c1133acb7aa04bfefa77c9cd..a8683808750e75a1863ea2040ece1ff9279f14a1 100644 (file)
@@ -262,7 +262,7 @@ else
 EXTRA_DIST += $(js_installed_tests)
 endif
 
-_installed_or_uninstalled_test_programs = tests/test-varint tests/test-ot-unix-utils tests/test-bsdiff tests/test-mutable-tree \
+_installed_or_uninstalled_test_programs = tests/test-varint tests/test-ot-unix-utils tests/test-bsdiff tests/test-otcore tests/test-mutable-tree \
        tests/test-keyfile-utils tests/test-ot-opt-utils tests/test-ot-tool-util \
        tests/test-checksum tests/test-lzma tests/test-rollsum \
        tests/test-basic-c tests/test-sysroot-c tests/test-pull-c tests/test-repo tests/test-include-ostree-h tests/test-kargs \
@@ -365,6 +365,9 @@ tests_test_varint_LDADD = $(TESTS_LDADD)
 tests_test_bsdiff_CFLAGS = $(TESTS_CFLAGS)
 tests_test_bsdiff_LDADD = libbsdiff.la $(TESTS_LDADD)
 
+tests_test_otcore_CFLAGS = $(AM_CFLAGS) $(OT_INTERNAL_GIO_UNIX_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libotcore -I$(srcdir)/libglnx
+tests_test_otcore_LDADD = $(OT_INTERNAL_GIO_UNIX_LIBS) libotcore.la libglnx.la
+
 tests_test_checksum_SOURCES = \
        src/libostree/ostree-core.c \
        src/libostree/ostree-varint.c \
diff --git a/tests/test-otcore.c b/tests/test-otcore.c
new file mode 100644 (file)
index 0000000..cac4209
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.0+
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "otcore.h"
+
+static void
+test_ed25519 (void)
+{
+  g_autoptr (GBytes) empty = g_bytes_new_static ("", 0);
+  bool valid = false;
+  g_autoptr (GError) error = NULL;
+  if (otcore_validate_ed25519_signature (empty, empty, empty, &valid, &error))
+    g_assert_not_reached ();
+  g_assert (error != NULL);
+  g_clear_error (&error);
+}
+
+int
+main (int argc, char **argv)
+{
+  g_test_init (&argc, &argv, NULL);
+  otcore_ed25519_init ();
+  g_test_add_func ("/ed25519", test_ed25519);
+  return g_test_run ();
+}