]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
regress: Add test for debug-tags functions
authorEric Bollengier <eric@baculasystems.com>
Wed, 4 Aug 2021 14:01:55 +0000 (16:01 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:03 +0000 (09:03 +0100)
bacula/src/tools/Makefile.in
bacula/src/tools/debug-tags.c [new file with mode: 0644]
regress/tests/debug-tags-test [new file with mode: 0755]

index 30b396abe5b3758f9178cc5e4c61527378ba1275..0326bca00f94965f300943cb8b3a9d54f2473ffd 100644 (file)
@@ -67,6 +67,10 @@ all: Makefile $(TOOLS) gigaslam grow
 test-cpp: test-cpp.o ../lib/unittests.o
        $(LIBTOOL_LINK) $(CXX) $(LDFLAGS)  -L../lib -o $@ test-cpp.o ../lib/unittests.o -lbac $(DLIB) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS)
 
+debug-tags_test: debug-tags.o ../lib/unittests.o
+       $(LIBTOOL_LINK) $(CXX) $(LDFLAGS)  -L../lib -o $@ debug-tags.o ../lib/unittests.o -lbac $(DLIB) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS)
+       $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/
+
 fs-io-error: fs-io-error.c
        $(CXX) -Wall fs-io-error.c -D_FILE_OFFSET_BITS=64 -lfuse  -o fs-io-error
 
diff --git a/bacula/src/tools/debug-tags.c b/bacula/src/tools/debug-tags.c
new file mode 100644 (file)
index 0000000..158b564
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2022 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
+*/
+
+/* Written by Eric Bollengier */
+
+#include "bacula.h"
+#include "lib/unittests.h"
+
+
+void test_list(int64_t tags, int nb, const char *format)
+{
+      alist tlist(10, not_owned_by_alist);
+      debug_get_tags_list(&tlist, tags);
+      is(tlist.size(), nb, "Parse simple tags back");
+
+      POOL_MEM tmp;
+      debug_get_tags(tmp.handle(), tags);
+      is(tmp.c_str(), format, "Check tags format");
+}
+
+int main(int argc, char **argv)
+{
+   int64_t tags=0;
+   Unittests alist_test("debug-tags");
+   log("Test debug tags feature");
+
+   ok(debug_parse_tags("network,snapshot", &tags), "Parse simple tags");
+   is(tags, DT_NETWORK|DT_SNAPSHOT, "Check simple parsing");
+   test_list(tags, 2, "network,snapshot");
+
+   ok(debug_parse_tags("network,!snapshot", &tags), "Parse tag deletion");
+   is(tags, DT_NETWORK, "Check tag deletion");
+   test_list(tags, 1, "network");
+   return report();
+}
diff --git a/regress/tests/debug-tags-test b/regress/tests/debug-tags-test
new file mode 100755 (executable)
index 0000000..f603ecc
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+#
+# Copyright (C) 2000-2015 Kern Sibbald
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
+# This is an alist unit test
+#
+TestName="debug-tags_test"
+. scripts/functions
+make -C $src/src/tools $TestName
+
+$bin/$TestName
+exit $?