From: Radosław Korzeniewski Date: Mon, 27 Aug 2018 15:13:37 +0000 (+0200) Subject: Update unittests fir ConfigFile/ini.c. X-Git-Tag: Release-9.4.0~73 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8daeebfcfd91977772e1597590d731aa99ccb17d;p=thirdparty%2Fbacula.git Update unittests fir ConfigFile/ini.c. --- diff --git a/.gitignore b/.gitignore index 97fe60892b..0deaae06d9 100644 --- a/.gitignore +++ b/.gitignore @@ -324,3 +324,4 @@ bacula/src/lib/sellist_test bacula/src/lib/fnmatch_test bacula/src/lib/sha1_test bacula/src/lib/htable_test +bacula/src/lib/ini_test diff --git a/bacula/src/lib/Makefile.in b/bacula/src/lib/Makefile.in index eb0d1da5e6..c62f335100 100644 --- a/bacula/src/lib/Makefile.in +++ b/bacula/src/lib/Makefile.in @@ -251,10 +251,10 @@ bsnprintf_test: Makefile bsnprintf.c unittests.o $(RMF) bsnprintf.o $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bsnprintf.c -ini: Makefile ini.o +ini_test: Makefile libbac.la ini.c unittests.o $(RMF) ini.o $(CXX) -DTEST_PROGRAM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) ini.c - $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ ini.o -lbaccfg -lbac $(DLIB) -lm $(LIBS) $(OPENSSL_LIBS) + $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L. -o $@ ini.o unittests.o -lbaccfg -lbac $(DLIB) -lm $(LIBS) $(OPENSSL_LIBS) $(RMF) ini.o $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) ini.c diff --git a/bacula/src/lib/ini.c b/bacula/src/lib/ini.c index ee30151f46..f3c188f9d6 100644 --- a/bacula/src/lib/ini.c +++ b/bacula/src/lib/ini.c @@ -675,49 +675,18 @@ bool ini_store_date(LEX *lc, ConfigFile *inifile, ini_items *item) return true; } +#ifndef TEST_PROGRAM +#define TEST_PROGRAM_A +#endif + /* ---------------------------------------------------------------- */ #ifdef TEST_PROGRAM -/* make ini +#include "unittests.h" +/* make ini_test * export LD_LIBRARY_PATH=.libs/ - * ./.libs/ini + * ./.libs/ini_test */ -#include - -int err=0; -int nb=0; -void _ok(const char *file, int l, const char *op, int value, const char *label) -{ - nb++; - if (!value) { - err++; - printf("ERR %.45s %s:%i on %s\n", label, file, l, op); - } else { - printf("OK %.45s\n", label); - } -} - -#define ok(x, label) _ok(__FILE__, __LINE__, #x, (x), label) - -void _nok(const char *file, int l, const char *op, int value, const char *label) -{ - nb++; - if (value) { - err++; - printf("ERR %.45s %s:%i on !%s\n", label, file, l, op); - } else { - printf("OK %.45s\n", label); - } -} - -#define nok(x, label) _nok(__FILE__, __LINE__, #x, (x), label) - -int report() -{ - printf("Result %i/%i OK\n", nb - err, nb); - return err>0; -} - struct ini_items membuf_items[] = { /* name handler comment req */ {"client", ini_store_name, "Client name", 0}, @@ -726,7 +695,6 @@ struct ini_items membuf_items[] = { {NULL, NULL, NULL, 0} }; - struct ini_items test_items[] = { /* name handler comment req */ {"datastore", ini_store_name, "Target Datastore", 0}, @@ -749,13 +717,13 @@ bool save_resource(RES_HEAD **rhead, int type, RES_ITEM *items, int pass){return bool save_resource(CONFIG*, int, RES_ITEM*, int) {return false;} void dump_resource(int type, RES *ares, void sendit(void *sock, const char *fmt, ...), void *sock){} void free_resource(RES *rres, int type){} -union URES { -}; +union URES {}; RES_TABLE resources[] = {}; URES res_all; int main() { + Unittests ini_test("ini_test"); FILE *fp; int pos, size; ConfigFile *ini = new ConfigFile(); @@ -763,7 +731,7 @@ int main() char buffer[2000]; //debug_level=500; - printf("Begin Memory buffer Test\n"); + Pmsg0(0, "Begin Memory buffer Test\n"); ok(ini->register_items(membuf_items, sizeof(struct ini_items)), "Check sizeof ini_items"); if ((fp = bfopen("test.cfg", "w")) == NULL) { @@ -790,10 +758,11 @@ int main() ok(ini->parse_buf(buffer), "Test memory read with all members"); ini->clear_items(); + ini->free_items(); fclose(fp); //debug_level = 0; - printf("\n\nBegin Original Full Tests\n"); + Pmsg0(0, "Begin Original Full Tests\n"); nok(ini->register_items(test_items, 5), "Check bad sizeof ini_items"); ok(ini->register_items(test_items, sizeof(struct ini_items)), "Check sizeof ini_items"); @@ -915,11 +884,14 @@ int main() ini->clear_items(); ini->free_items(); - report(); - + delete(ini); free_pool_memory(buf); - exit (0); -} + /* clean after tests */ + unlink("test.cfg"); + unlink("test2.cfg"); + unlink("test3.cfg"); + unlink("test4.cfg"); - -#endif + return report(); +} +#endif /* TEST_PROGRAM */ diff --git a/regress/tests/ini-unittests b/regress/tests/ini-unittests new file mode 100755 index 0000000000..0a6055b5d8 --- /dev/null +++ b/regress/tests/ini-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 an ConfigFile/ini unit test +# +TestName="ini_test" +. scripts/functions +make -C $src/src/lib $TestName + +$src/src/lib/$TestName +exit $?