aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-03-07 14:46:53 +0100
committerJay Berkenbilt <ejb@ql.org>2022-03-07 16:07:27 +0100
commit17c0e38c8efa7882f8e6a13c6030edf3e768257c (patch)
tree12e4a483fa885fdf55998d4ead5200da293a4829
parent066efb69aec4aa1a62ecf56902a5f4f3d2c73bd5 (diff)
downloadqpdf-17c0e38c8efa7882f8e6a13c6030edf3e768257c.tar.zst
Force assert to be defined in test code
-rw-r--r--libtests/arg_parser.cc5
-rw-r--r--libtests/buffer.cc7
-rw-r--r--libtests/concatenate.cc7
-rw-r--r--libtests/cxx11.cc7
-rw-r--r--libtests/json.cc5
-rw-r--r--libtests/json_handler.cc5
-rw-r--r--libtests/matrix.cc7
-rw-r--r--libtests/pdf_version.cc7
-rw-r--r--libtests/predictors.cc7
-rw-r--r--libtests/qintc.cc5
-rw-r--r--libtests/qutil.cc7
-rw-r--r--libtests/rc4.cc5
-rw-r--r--libtests/sparse_array.cc7
-rw-r--r--qpdf/pdf_from_scratch.cc1
-rw-r--r--qpdf/qpdf-ctest.c7
-rw-r--r--qpdf/qpdfjob-ctest.c7
-rw-r--r--qpdf/test_driver.cc7
-rw-r--r--qpdf/test_large_file.cc7
18 files changed, 97 insertions, 13 deletions
diff --git a/libtests/arg_parser.cc b/libtests/arg_parser.cc
index 0c7e6787..4b10709e 100644
--- a/libtests/arg_parser.cc
+++ b/libtests/arg_parser.cc
@@ -3,6 +3,11 @@
#include <qpdf/QPDFUsage.hh>
#include <iostream>
#include <cstring>
+
+#ifdef NDEBUG
+// We need assert even in a release build for test code.
+# undef NDEBUG
+#endif
#include <cassert>
class ArgParser
diff --git a/libtests/buffer.cc b/libtests/buffer.cc
index ea36a807..5dfe55f8 100644
--- a/libtests/buffer.cc
+++ b/libtests/buffer.cc
@@ -5,9 +5,14 @@
#include <stdlib.h>
#include <stdexcept>
#include <iostream>
-#include <cassert>
#include <cstring>
+#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)
{
return QUtil::unsigned_char_pointer(s);
diff --git a/libtests/concatenate.cc b/libtests/concatenate.cc
index 16850d03..84fee2bb 100644
--- a/libtests/concatenate.cc
+++ b/libtests/concatenate.cc
@@ -3,7 +3,12 @@
#include <qpdf/Pl_Buffer.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <assert.h>
+
+#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 bc14b5c0..5ad3e6ed 100644
--- a/libtests/cxx11.cc
+++ b/libtests/cxx11.cc
@@ -1,5 +1,4 @@
#include <iostream>
-#include <cassert>
#include <cstring>
#include <cstdlib>
#include <functional>
@@ -10,6 +9,12 @@
#include <memory>
#include <regex>
+#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 c37af0e8..a8c72a3b 100644
--- a/libtests/json.cc
+++ b/libtests/json.cc
@@ -1,6 +1,11 @@
#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 568677a8..6e894e11 100644
--- a/libtests/json_handler.cc
+++ b/libtests/json_handler.cc
@@ -2,6 +2,11 @@
#include <qpdf/QUtil.hh>
#include <qpdf/QPDFUsage.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 ecaa02a0..210c022f 100644
--- a/libtests/matrix.cc
+++ b/libtests/matrix.cc
@@ -1,8 +1,13 @@
#include <qpdf/QPDFMatrix.hh>
#include <qpdf/QUtil.hh>
-#include <assert.h>
#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)
{
std::string u = m.unparse();
diff --git a/libtests/pdf_version.cc b/libtests/pdf_version.cc
index c8a568ed..2471cb0b 100644
--- a/libtests/pdf_version.cc
+++ b/libtests/pdf_version.cc
@@ -1,8 +1,13 @@
#include <qpdf/PDFVersion.hh>
-#include <cassert>
#include <iostream>
+#ifdef NDEBUG
+// We need assert even in a release build for test code.
+# undef NDEBUG
+#endif
+#include <cassert>
+
int main()
{
PDFVersion v1;
diff --git a/libtests/predictors.cc b/libtests/predictors.cc
index d2c4863e..f9fa759e 100644
--- a/libtests/predictors.cc
+++ b/libtests/predictors.cc
@@ -6,10 +6,15 @@
#include <iostream>
#include <errno.h>
-#include <assert.h>
#include <string.h>
#include <stdlib.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,
bool encode, unsigned int columns,
unsigned int bits_per_sample, unsigned int samples_per_pixel)
diff --git a/libtests/qintc.cc b/libtests/qintc.cc
index f9ca9558..85806d1a 100644
--- a/libtests/qintc.cc
+++ b/libtests/qintc.cc
@@ -1,5 +1,10 @@
#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) \
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index b9b7c674..c3a9b163 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -9,7 +9,6 @@
#include <qpdf/Pl_Buffer.hh>
#include <string.h>
#include <limits.h>
-#include <assert.h>
#include <fstream>
#include <locale>
@@ -19,6 +18,12 @@
# 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(char const* str, int_T wanted, bool error,
int_T (*fn)(char const*))
diff --git a/libtests/rc4.cc b/libtests/rc4.cc
index eab3a759..b7aecd4b 100644
--- a/libtests/rc4.cc
+++ b/libtests/rc4.cc
@@ -7,6 +7,11 @@
#include <string.h>
#include <iostream>
#include <stdlib.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 9c3e00b4..5636abd1 100644
--- a/libtests/sparse_array.cc
+++ b/libtests/sparse_array.cc
@@ -1,7 +1,12 @@
#include <qpdf/SparseOHArray.hh>
-#include <assert.h>
#include <iostream>
+#ifdef NDEBUG
+// We need assert even in a release build for test code.
+# undef NDEBUG
+#endif
+#include <cassert>
+
int main()
{
SparseOHArray a;
diff --git a/qpdf/pdf_from_scratch.cc b/qpdf/pdf_from_scratch.cc
index 07170347..0dd5bbf7 100644
--- a/qpdf/pdf_from_scratch.cc
+++ b/qpdf/pdf_from_scratch.cc
@@ -9,7 +9,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <assert.h>
static char const* whoami = 0;
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index dff7c8c4..3a890a69 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -1,12 +1,17 @@
#include <qpdf/qpdf-c.h>
#include <stdio.h>
-#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <qpdf/qpdf-config.h> // for LL_FMT -- special case in build
+#ifdef NDEBUG
+/* We need assert even in a release build for test code. */
+# undef NDEBUG
+#endif
+#include <assert.h>
+
static char* whoami = 0;
static qpdf_data qpdf = 0;
diff --git a/qpdf/qpdfjob-ctest.c b/qpdf/qpdfjob-ctest.c
index 43935333..5ee21f31 100644
--- a/qpdf/qpdfjob-ctest.c
+++ b/qpdf/qpdfjob-ctest.c
@@ -1,9 +1,14 @@
#include <qpdf/qpdfjob-c.h>
#include <stdio.h>
-#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#ifdef NDEBUG
+/* We need assert even in a release build for test code. */
+# undef NDEBUG
+#endif
+#include <assert.h>
+
#ifndef QPDF_NO_WCHAR_T
static void wide_test()
{
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index aee3cd53..fd0733fc 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -28,10 +28,15 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <assert.h>
#include <limits.h>
#include <map>
+#ifdef NDEBUG
+// We need assert even in a release build for test code.
+# undef NDEBUG
+#endif
+#include <cassert>
+
static char const* whoami = 0;
void usage()
diff --git a/qpdf/test_large_file.cc b/qpdf/test_large_file.cc
index 47796ba5..e403dd51 100644
--- a/qpdf/test_large_file.cc
+++ b/qpdf/test_large_file.cc
@@ -13,7 +13,12 @@
#include <iostream>
#include <string.h>
#include <stdlib.h>
-#include <assert.h>
+
+#ifdef NDEBUG
+// We need assert even in a release build for test code.
+# undef NDEBUG
+#endif
+#include <cassert>
// Run "test_large_file write small a.pdf" to get a PDF file that you
// can look at in a reader.