]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/lib/unittests.h
authorEric Bollengier <eric@baculasystems.com>
Thu, 23 Apr 2020 14:33:50 +0000 (16:33 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:17 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Mar 26 10:17:48 2020 +0100

    Modify ok() and nok() to return a boolean in the unittest lib

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Feb 27 20:46:39 2020 +0100

    Display local variables when a unittest is on error

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Wed Feb 26 09:50:29 2020 +0100

    Use Bacula Systems copyright for bcollector/bsock files

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Sep 6 15:54:35 2018 +0200

    Add a function to control the unittest output

bacula/src/lib/unittests.h

index 62f593056304414ef0de4cc7ef2a4f2bbf83e5c5..7c1ff479705e482989b0ec25f75dfce7b3ce4521 100644 (file)
@@ -28,6 +28,9 @@
 // Test success if value x is zero
 #define nok(x, label) _nok(__FILE__, __LINE__, #x, (x), label)
 
+#define is(x, y, label) _is(__FILE__, __LINE__, #x, (x), (y), label)
+#define isnt(x, y, label) _isnt(__FILE__, __LINE__, #x, (x), (y), label)
+
 /* TODO: log() ported from BEE it should be updated. */
 #ifdef RTEST_LOG_THREADID
 #define log(format, ...)  do { \
  } while (0)
 #endif
 
-void _ok(const char *file, int l, const char *op, int value, const char *label);
-void _nok(const char *file, int l, const char *op, int value, const char *label);
+enum {
+   TEST_VERBOSE = 1,
+   TEST_QUIET   = 2,
+   TEST_END     = 4,
+   TEST_PRINT_LOCAL = 8
+};
+void configure_test(uint64_t options);
+bool _ok(const char *file, int l, const char *op, int value, const char *label);
+bool _nok(const char *file, int l, const char *op, int value, const char *label);
+bool _is(const char *file, int l, const char *op, const char *str, const char *str2, const char *label);
+bool _isnt(const char *file, int l, const char *op, const char *str, const char *str2, const char *label);
+bool _is(const char *file, int l, const char *op, int64_t nb, int64_t nb2, const char *label);
+bool _isnt(const char *file, int l, const char *op, int64_t nb, int64_t nb2, const char *label);
 int report();
 void terminate(int sig);
 void prolog(const char *name, bool lmgr=false, bool motd=true);
@@ -52,11 +66,9 @@ void epilog();
 class Unittests
 {
 public:
-   Unittests(const char *name, bool lmgr=false, bool motd=true)
-   {
-      prolog(name, lmgr, motd);
-   };
+   Unittests(const char *name, bool lmgr=false, bool motd=true);
    ~Unittests() { epilog(); };
+   void configure(uint64_t v) { configure_test(v); };
 };
 
-#endif /* _UNITTESTS_H_ */
\ No newline at end of file
+#endif /* _UNITTESTS_H_ */