aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-03 14:21:01 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-04 00:31:22 +0200
commit62bf296a9c0f5be492f0677ed111b3fa217f4c11 (patch)
treef49564b3d70a12ee4e16e84c4e4e33a2adce1133 /libtests
parent92b692466f7a4dbf4e51e6a77713c029a3e18ab1 (diff)
downloadqpdf-62bf296a9c0f5be492f0677ed111b3fa217f4c11.tar.zst
Make assert handling less error-prone
Prevent my future self or other contributors from using assert in tests and then having that assert not do anything because of the NDEBUG macro.
Diffstat (limited to 'libtests')
-rw-r--r--libtests/arg_parser.cc8
-rw-r--r--libtests/base64.cc3
-rw-r--r--libtests/buffer.cc8
-rw-r--r--libtests/concatenate.cc8
-rw-r--r--libtests/cxx11.cc8
-rw-r--r--libtests/json.cc8
-rw-r--r--libtests/json_handler.cc8
-rw-r--r--libtests/matrix.cc8
-rw-r--r--libtests/pdf_version.cc8
-rw-r--r--libtests/predictors.cc8
-rw-r--r--libtests/qintc.cc8
-rw-r--r--libtests/qutil.cc8
-rw-r--r--libtests/rc4.cc8
-rw-r--r--libtests/sparse_array.cc8
14 files changed, 28 insertions, 79 deletions
diff --git a/libtests/arg_parser.cc b/libtests/arg_parser.cc
index 8b4d556a..1480a717 100644
--- a/libtests/arg_parser.cc
+++ b/libtests/arg_parser.cc
@@ -1,15 +1,11 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/QPDFArgParser.hh>
#include <qpdf/QPDFUsage.hh>
#include <qpdf/QUtil.hh>
#include <cstring>
#include <iostream>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
class ArgParser
{
public:
diff --git a/libtests/base64.cc b/libtests/base64.cc
index 66f2d828..0ce6f9a3 100644
--- a/libtests/base64.cc
+++ b/libtests/base64.cc
@@ -1,8 +1,9 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/Pl_Base64.hh>
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QUtil.hh>
-#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
diff --git a/libtests/buffer.cc b/libtests/buffer.cc
index a24c0f99..a65efb1c 100644
--- a/libtests/buffer.cc
+++ b/libtests/buffer.cc
@@ -1,3 +1,5 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/Pl_Buffer.hh>
#include <qpdf/Pl_Count.hh>
#include <qpdf/Pl_Discard.hh>
@@ -7,12 +9,6 @@
#include <stdexcept>
#include <stdlib.h>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
static unsigned char*
uc(char const* s)
{
diff --git a/libtests/concatenate.cc b/libtests/concatenate.cc
index 10902adf..9bc0fd04 100644
--- a/libtests/concatenate.cc
+++ b/libtests/concatenate.cc
@@ -1,15 +1,11 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/Pl_Buffer.hh>
#include <qpdf/Pl_Concatenate.hh>
#include <qpdf/Pl_Flate.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
static void
pipeStringAndFinish(Pipeline* p, std::string const& str)
{
diff --git a/libtests/cxx11.cc b/libtests/cxx11.cc
index 4c2c2cb6..250e7e2b 100644
--- a/libtests/cxx11.cc
+++ b/libtests/cxx11.cc
@@ -1,3 +1,5 @@
+#include <qpdf/assert_test.h>
+
#include <cstdint>
#include <cstdlib>
#include <cstring>
@@ -9,12 +11,6 @@
#include <type_traits>
#include <vector>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
// Functional programming
// Function that returns a callable in the form of a lambda
diff --git a/libtests/json.cc b/libtests/json.cc
index 43f2b3c6..3844222f 100644
--- a/libtests/json.cc
+++ b/libtests/json.cc
@@ -1,13 +1,9 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/JSON.hh>
#include <qpdf/QPDFObjectHandle.hh>
#include <iostream>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
static void
check(JSON const& j, std::string const& exp)
{
diff --git a/libtests/json_handler.cc b/libtests/json_handler.cc
index 567cde86..4e610b08 100644
--- a/libtests/json_handler.cc
+++ b/libtests/json_handler.cc
@@ -1,14 +1,10 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/JSONHandler.hh>
#include <qpdf/QPDFUsage.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
static void
print_null(std::string const& path)
{
diff --git a/libtests/matrix.cc b/libtests/matrix.cc
index 7dc73390..f69d270c 100644
--- a/libtests/matrix.cc
+++ b/libtests/matrix.cc
@@ -1,13 +1,9 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/QPDFMatrix.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
static void
check(QPDFMatrix const& m, std::string const& exp)
{
diff --git a/libtests/pdf_version.cc b/libtests/pdf_version.cc
index e9bfb00b..5db444b3 100644
--- a/libtests/pdf_version.cc
+++ b/libtests/pdf_version.cc
@@ -1,13 +1,9 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/PDFVersion.hh>
#include <iostream>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
int
main()
{
diff --git a/libtests/predictors.cc b/libtests/predictors.cc
index c024cbd6..a8f6c5d9 100644
--- a/libtests/predictors.cc
+++ b/libtests/predictors.cc
@@ -1,3 +1,5 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/Pl_PNGFilter.hh>
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/Pl_TIFFPredictor.hh>
@@ -9,12 +11,6 @@
#include <stdlib.h>
#include <string.h>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
void
run(char const* filename,
char const* filter,
diff --git a/libtests/qintc.cc b/libtests/qintc.cc
index d3e19f5b..d5738a4b 100644
--- a/libtests/qintc.cc
+++ b/libtests/qintc.cc
@@ -1,12 +1,8 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/QIntC.hh>
#include <stdint.h>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
#define try_convert(exp_pass, fn, i) \
try_convert_real(#fn "(" #i ")", exp_pass, fn, i)
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index 017f371b..f79f9a3f 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -1,3 +1,5 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/Pl_Buffer.hh>
#include <qpdf/QPDFSystemError.hh>
#include <qpdf/QUtil.hh>
@@ -17,12 +19,6 @@
# include <unistd.h>
#endif
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
template <class int_T>
void
test_to_number(
diff --git a/libtests/rc4.cc b/libtests/rc4.cc
index 7245ef86..1b1a8744 100644
--- a/libtests/rc4.cc
+++ b/libtests/rc4.cc
@@ -1,3 +1,5 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/Pl_RC4.hh>
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QIntC.hh>
@@ -8,12 +10,6 @@
#include <stdlib.h>
#include <string.h>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
static void
other_tests()
{
diff --git a/libtests/sparse_array.cc b/libtests/sparse_array.cc
index 8d37bc2f..62410399 100644
--- a/libtests/sparse_array.cc
+++ b/libtests/sparse_array.cc
@@ -1,12 +1,8 @@
+#include <qpdf/assert_test.h>
+
#include <qpdf/SparseOHArray.hh>
#include <iostream>
-#ifdef NDEBUG
-// We need assert even in a release build for test code.
-# undef NDEBUG
-#endif
-#include <cassert>
-
int
main()
{