]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Update unittests fir ConfigFile/ini.c.
authorRadosław Korzeniewski <radekk@inteos.pl>
Mon, 27 Aug 2018 15:13:37 +0000 (17:13 +0200)
committerRadosław Korzeniewski <radekk@inteos.pl>
Mon, 27 Aug 2018 15:13:37 +0000 (17:13 +0200)
.gitignore
bacula/src/lib/Makefile.in
bacula/src/lib/ini.c
regress/tests/ini-unittests [new file with mode: 0755]

index 97fe60892b35987ca458df4c7aac1d6b90b9d1e5..0deaae06d96f726bd08a16ccb45a68851a6069ec 100644 (file)
@@ -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
index eb0d1da5e6f555c830c06f6ef01e36d77ac9ae82..c62f335100d4fe99a7cfafad89d79bead8821b4c 100644 (file)
@@ -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
 
index ee30151f46897c7e9cb3b424221d6b3b8f02d7d6..f3c188f9d6fa127ecb9186f0fe907d80adf58e46 100644 (file)
@@ -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 <stdio.h>
-
-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 (executable)
index 0000000..0a6055b
--- /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 an ConfigFile/ini unit test
+#
+TestName="ini_test"
+. scripts/functions
+make -C $src/src/lib $TestName
+
+$src/src/lib/$TestName
+exit $?