From: Radosław Korzeniewski Date: Mon, 27 Aug 2018 15:32:44 +0000 (+0200) Subject: Update sellist unittests. X-Git-Tag: Release-9.4.0~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=317fa57a899eaec7d9ef283c3ffcb9e4d596c6b9;p=thirdparty%2Fbacula.git Update sellist unittests. --- diff --git a/.gitignore b/.gitignore index 480e26a2af..bd2a34256f 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/bacula/src/lib/Makefile.in b/bacula/src/lib/Makefile.in index 83d91ec409..b0aef3b26f 100644 --- a/bacula/src/lib/Makefile.in +++ b/bacula/src/lib/Makefile.in @@ -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 diff --git a/bacula/src/lib/sellist.c b/bacula/src/lib/sellist.c index d8f13908b8..25365a97e4 100644 --- a/bacula/src/lib/sellist.c +++ b/bacula/src/lib/sellist.c @@ -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 index 0000000000..f0ae5e6a9c --- /dev/null +++ b/regress/tests/sellist-unittests @@ -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 $?