]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Update sellist unittests.
authorRadosław Korzeniewski <radekk@inteos.pl>
Mon, 27 Aug 2018 15:32:44 +0000 (17:32 +0200)
committerRadosław Korzeniewski <radekk@inteos.pl>
Tue, 11 Sep 2018 10:01:06 +0000 (12:01 +0200)
.gitignore
bacula/src/lib/Makefile.in
bacula/src/lib/sellist.c
regress/tests/sellist-unittests [new file with mode: 0755]

index 480e26a2afafd2ea5c164da2a4998cd7cc5f2222..bd2a34256f90bffc0386165ab1f6181aee620778 100644 (file)
@@ -326,3 +326,4 @@ bacula/src/lib/sha1_test
 bacula/src/lib/htable_test
 bacula/src/lib/ini_test
 bacula/src/lib/lockmgr_test
+bacula/src/lib/sellist_test
index 83d91ec4099a6d4c7ad4268c2e746c574077af16..b0aef3b26f0f6ad6c1cc122bd577dcabdd59fef5 100644 (file)
@@ -209,10 +209,10 @@ crc32_test: Makefile crc32.c unittests.o
        $(RMF) crc32.o
        $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) crc32.c
 
-sellist_test: Makefile sellist.c
+sellist_test: Makefile libbac.la sellist.c unittests.o
        $(RMF) sellist.o
        $(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sellist.c
-       $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ sellist.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
+       $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ sellist.o unittests.o $(DLIB) -lbac -lm $(LIBS) $(OPENSSL_LIBS)
        $(RMF) sellist.o
        $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sellist.c
 
index d8f13908b87e81b8da05cf4b4b8e666e8a78a6a8..25365a97e4f97033ee66f4a9050d742c463c1496 100644 (file)
@@ -11,7 +11,7 @@
    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 
+   This notice must be preserved when any source code is
    conveyed and/or propagated.
 
    Bacula(R) is a registered trademark of Kern Sibbald.
@@ -212,63 +212,57 @@ char *sellist::get_expanded_list()
    return expanded;
 }
 
+#ifndef TEST_PROGRAM
+#define TEST_PROGRAM_A
+#endif
+
 #ifdef TEST_PROGRAM
+#include "unittests.h"
 
-/* Test input string */
-const char *sinp[] = {
-   "1,70",
-   "1",
-   "256",
-   "1-5",
-   "1-5,7",
-   "1 10 20 30",
-   "1-5,7,20 21",
-   "all",
-   "12a",    /* error */
-   "12-11",  /* error */
-   "12-13a", /* error */
-   "a123",   /* error */
-   NULL
+struct test {
+   const int nr;
+   const char *sinp;
+   const char *sout;
+   const bool res;
 };
 
-/* Scanned output string -- or ERROR if input is illegal */
-const char *sout[] = {
-   "1,70",
-   "1",
-   "256",
-   "1,2,3,4,5",
-   "1,2,3,4,5,7",
-   "1,10,20,30",
-   "1,2,3,4,5,7,20,21",
-   "0",
-   "ERROR",
-   "ERROR",
-   "ERROR",
-   "ERROR",
-   NULL
+static struct test tests[] = {
+   { 1, "1,70", "1,70", true, },
+   { 2, "1", "1", true, },
+   { 3, "256", "256", true, },
+   { 4, "1-5", "1,2,3,4,5", true, },
+   { 5, "1-5,7", "1,2,3,4,5,7", true, },
+   { 6, "1 10 20 30", "1,10,20,30", true, },
+   { 7, "1-5,7,20 21", "1,2,3,4,5,7,20,21", true, },
+   { 8, "all", "0", true, },
+   { 9, "12a", "", false, },
+   {10, "12-11", "", false, },
+   {11, "12-13a", "", false, },
+   {12, "a123", "", false, },
+   {13, "1  3", "", false, },
+   {0, "dummy", "dummy", false, },
 };
 
-int main(int argc, char **argv, char **env)
+#define ntests ((int)(sizeof(tests)/sizeof(struct test)))
+#define MSGLEN 80
+
+int main()
 {
+   Unittests sellist_test("sellist_test");
    const char *msg;
    sellist sl;
-   int x;
+   char buf[MSGLEN];
+   bool check_rc;
 
-   for (x=0; sinp[x] != NULL; x++) {
-      if (!sl.set_string(sinp[x], true)) {
-         printf("ERR: input: %s ERR=%s", sinp[x], sl.get_errmsg());
-         continue;
-      }
-      msg = sl.get_expanded_list();
-      if (sl.get_errmsg() == NULL && strcmp(msg, sout[x]) == 0) {
-         printf("OK: input: %s output: %s\n", sinp[x], msg);
-      } else {
-         printf("ERR: input: %s gave output: %s ERR=%s\n", sinp[x], msg,
-            sl.get_errmsg());
+   for (int i = 0; i < ntests; i++) {
+      if (tests[i].nr > 0){
+         snprintf(buf, MSGLEN, "Checking test: %d - %s", tests[i].nr, tests[i].sinp);
+         check_rc = sl.set_string(tests[i].sinp, true);
+         msg = sl.get_expanded_list();
+         ok(check_rc == tests[i].res && strcmp(msg, tests[i].sout) == 0, buf);
       }
    }
-   printf("\n");
-   return 0;
 
+   return report();
 }
-#endif /* TEST_PROGRAM */
+#endif   /* TEST_PROGRAM */
diff --git a/regress/tests/sellist-unittests b/regress/tests/sellist-unittests
new file mode 100755 (executable)
index 0000000..f0ae5e6
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/sh
+#
+# Copyright (C) 2000-2015 Kern Sibbald
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
+# Copyright (c) 2018 by Inteos sp. z o.o.
+# All rights reserved. IP transfered to Bacula Systems according to agreement.
+#
+# This is a sellist unit test
+#
+TestName="sellist_test"
+. scripts/functions
+make -C $src/src/lib $TestName
+
+$src/src/lib/$TestName
+exit $?