summaryrefslogtreecommitdiffstats
path: root/libtests
diff options
context:
space:
mode:
authorJay Berkenbilt <jberkenbilt@users.noreply.github.com>2023-05-20 17:29:09 +0200
committerGitHub <noreply@github.com>2023-05-20 17:29:09 +0200
commitfd17c8e3fe38a56abf50ce0edec1cde48d4f74cb (patch)
treec1efea1b140cac94dbaf496ae6ec5e0a621daa07 /libtests
parenta6d7b79e65941238871c0c3d7d06b9bf246213ba (diff)
parente6577a1323cd813a92ddbc8841e1342c05de071a (diff)
downloadqpdf-fd17c8e3fe38a56abf50ce0edec1cde48d4f74cb.tar.zst
Merge pull request #963 from m-holger/tidy
Code tidy
Diffstat (limited to 'libtests')
-rw-r--r--libtests/aes.cc24
-rw-r--r--libtests/arg_parser.cc3
-rw-r--r--libtests/ascii85.cc2
-rw-r--r--libtests/bits.cc5
-rw-r--r--libtests/buffer.cc2
-rw-r--r--libtests/closed_file_input_source.cc4
-rw-r--r--libtests/cxx11.cc1
-rw-r--r--libtests/dct_compress.cc10
-rw-r--r--libtests/dct_uncompress.cc5
-rw-r--r--libtests/flate.cc6
-rw-r--r--libtests/hex.cc2
-rw-r--r--libtests/input_source.cc4
-rw-r--r--libtests/json_parse.cc13
-rw-r--r--libtests/logger_c.c1
-rw-r--r--libtests/lzw.cc4
-rw-r--r--libtests/md5.cc2
-rw-r--r--libtests/numrange.cc2
-rw-r--r--libtests/pointer_holder.cc5
-rw-r--r--libtests/predictors.cc7
-rw-r--r--libtests/qintc.cc4
-rw-r--r--libtests/qutil.cc12
-rw-r--r--libtests/random.cc3
-rw-r--r--libtests/rc4.cc14
-rw-r--r--libtests/runlength.cc6
-rw-r--r--libtests/sha2.cc3
25 files changed, 63 insertions, 81 deletions
diff --git a/libtests/aes.cc b/libtests/aes.cc
index 3ad491cc..a981fc22 100644
--- a/libtests/aes.cc
+++ b/libtests/aes.cc
@@ -4,9 +4,9 @@
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
static void
usage()
@@ -29,9 +29,9 @@ main(int argc, char* argv[])
{
bool encrypt = true;
bool cbc_mode = true;
- char* hexkey = 0;
- char* infilename = 0;
- char* outfilename = 0;
+ char* hexkey = nullptr;
+ char* infilename = nullptr;
+ char* outfilename = nullptr;
bool zero_iv = false;
bool static_iv = false;
bool disable_padding = false;
@@ -65,7 +65,7 @@ main(int argc, char* argv[])
usage();
}
}
- if (outfilename == 0) {
+ if (outfilename == nullptr) {
usage();
}
@@ -74,21 +74,21 @@ main(int argc, char* argv[])
FILE* infile = QUtil::safe_fopen(infilename, "rb");
FILE* outfile = QUtil::safe_fopen(outfilename, "wb");
- unsigned char* key = new unsigned char[keylen];
+ auto* key = new unsigned char[keylen];
for (unsigned int i = 0; i < strlen(hexkey); i += 2) {
char t[3];
t[0] = hexkey[i];
t[1] = hexkey[i + 1];
t[2] = '\0';
- long val = strtol(t, 0, 16);
+ long val = strtol(t, nullptr, 16);
key[i / 2] = static_cast<unsigned char>(val);
}
- Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile);
- Pl_AES_PDF* aes = new Pl_AES_PDF("aes_128_cbc", out, encrypt, key, keylen);
+ auto* out = new Pl_StdioFile("stdout", outfile);
+ auto* aes = new Pl_AES_PDF("aes_128_cbc", out, encrypt, key, keylen);
delete[] key;
- key = 0;
+ key = nullptr;
if (!cbc_mode) {
aes->disableCBC();
}
diff --git a/libtests/arg_parser.cc b/libtests/arg_parser.cc
index 9e3e8da5..c9474d55 100644
--- a/libtests/arg_parser.cc
+++ b/libtests/arg_parser.cc
@@ -2,7 +2,6 @@
#include <qpdf/QPDFArgParser.hh>
#include <qpdf/QPDFUsage.hh>
-#include <qpdf/QUtil.hh>
#include <cstring>
#include <iostream>
@@ -52,7 +51,7 @@ ArgParser::initOptions()
ap.addBare("potato", b(&ArgParser::handlePotato));
ap.addRequiredParameter("salad", p(&ArgParser::handleSalad), "tossed");
ap.addOptionalParameter("moo", p(&ArgParser::handleMoo));
- char const* choices[] = {"pig", "boar", "sow", 0};
+ char const* choices[] = {"pig", "boar", "sow", nullptr};
ap.addChoices("oink", p(&ArgParser::handleOink), true, choices);
ap.selectHelpOptionTable();
ap.addBare("version", [this]() { output("3.14159"); });
diff --git a/libtests/ascii85.cc b/libtests/ascii85.cc
index 2acc56ba..8d926898 100644
--- a/libtests/ascii85.cc
+++ b/libtests/ascii85.cc
@@ -2,7 +2,7 @@
#include <qpdf/Pl_StdioFile.hh>
#include <iostream>
-#include <stdlib.h>
+#include <cstdlib>
int
main()
diff --git a/libtests/bits.cc b/libtests/bits.cc
index 07870eb7..af715da8 100644
--- a/libtests/bits.cc
+++ b/libtests/bits.cc
@@ -4,8 +4,7 @@
#include <qpdf/QIntC.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdlib>
// See comments in bits_functions.hh
#define BITS_TESTING 1
@@ -142,7 +141,7 @@ test()
unsigned char ch = 0;
bit_offset = 7;
- Pl_Buffer* bp = new Pl_Buffer("buffer");
+ auto* bp = new Pl_Buffer("buffer");
test_write_bits(ch, bit_offset, 30UL, 5, bp);
test_write_bits(ch, bit_offset, 10UL, 4, bp);
diff --git a/libtests/buffer.cc b/libtests/buffer.cc
index f372e7b4..66eaa71c 100644
--- a/libtests/buffer.cc
+++ b/libtests/buffer.cc
@@ -7,7 +7,7 @@
#include <cstring>
#include <iostream>
#include <stdexcept>
-#include <stdlib.h>
+#include <cstdlib>
static unsigned char*
uc(char const* s)
diff --git a/libtests/closed_file_input_source.cc b/libtests/closed_file_input_source.cc
index e4c8ed36..183658a9 100644
--- a/libtests/closed_file_input_source.cc
+++ b/libtests/closed_file_input_source.cc
@@ -2,9 +2,7 @@
#include <qpdf/FileInputSource.hh>
#include <iostream>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
void
check(std::string const& what, bool result)
diff --git a/libtests/cxx11.cc b/libtests/cxx11.cc
index ac18e13e..5f0dcc9a 100644
--- a/libtests/cxx11.cc
+++ b/libtests/cxx11.cc
@@ -1,6 +1,5 @@
#include <qpdf/assert_test.h>
-#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <functional>
diff --git a/libtests/dct_compress.cc b/libtests/dct_compress.cc
index ad8710b1..1f969982 100644
--- a/libtests/dct_compress.cc
+++ b/libtests/dct_compress.cc
@@ -3,9 +3,9 @@
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
static void
usage()
@@ -22,8 +22,8 @@ class Callback: public Pl_DCT::CompressConfig
called(false)
{
}
- virtual ~Callback() = default;
- virtual void apply(jpeg_compress_struct*);
+ ~Callback() override = default;
+ void apply(jpeg_compress_struct*) override;
bool called;
};
diff --git a/libtests/dct_uncompress.cc b/libtests/dct_uncompress.cc
index 1ab22e97..6606e4a5 100644
--- a/libtests/dct_uncompress.cc
+++ b/libtests/dct_uncompress.cc
@@ -3,9 +3,8 @@
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
int
main(int argc, char* argv[])
diff --git a/libtests/flate.cc b/libtests/flate.cc
index 77fb440e..9b64ca67 100644
--- a/libtests/flate.cc
+++ b/libtests/flate.cc
@@ -4,10 +4,8 @@
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QUtil.hh>
-#include <errno.h>
#include <iostream>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
void
run(char const* filename)
@@ -30,7 +28,7 @@ run(char const* filename)
Pipeline* inf2 = new Pl_Flate("inf2", out2, Pl_Flate::a_inflate);
// Count bytes written to o3
- Pl_Count* count3 = new Pl_Count("count3", out3);
+ auto* count3 = new Pl_Count("count3", out3);
// Do both simultaneously
Pipeline* inf3 = new Pl_Flate("inf3", count3, Pl_Flate::a_inflate);
diff --git a/libtests/hex.cc b/libtests/hex.cc
index 9e708204..d239d202 100644
--- a/libtests/hex.cc
+++ b/libtests/hex.cc
@@ -2,7 +2,7 @@
#include <qpdf/Pl_StdioFile.hh>
#include <iostream>
-#include <stdlib.h>
+#include <cstdlib>
int
main()
diff --git a/libtests/input_source.cc b/libtests/input_source.cc
index 83744250..9ab41b5d 100644
--- a/libtests/input_source.cc
+++ b/libtests/input_source.cc
@@ -24,8 +24,8 @@ class Finder: public InputSource::Finder
after(after)
{
}
- virtual ~Finder() = default;
- virtual bool check();
+ ~Finder() override = default;
+ bool check() override;
private:
std::shared_ptr<InputSource> is;
diff --git a/libtests/json_parse.cc b/libtests/json_parse.cc
index 721b17de..31381ebf 100644
--- a/libtests/json_parse.cc
+++ b/libtests/json_parse.cc
@@ -1,6 +1,5 @@
#include <qpdf/FileInputSource.hh>
#include <qpdf/JSON.hh>
-#include <qpdf/QUtil.hh>
#include <cstdlib>
#include <cstring>
#include <iostream>
@@ -12,13 +11,13 @@ namespace
{
public:
virtual ~Reactor() = default;
- virtual void dictionaryStart() override;
- virtual void arrayStart() override;
- virtual void containerEnd(JSON const& value) override;
- virtual void topLevelScalar() override;
- virtual bool
+ void dictionaryStart() override;
+ void arrayStart() override;
+ void containerEnd(JSON const& value) override;
+ void topLevelScalar() override;
+ bool
dictionaryItem(std::string const& key, JSON const& value) override;
- virtual bool arrayItem(JSON const& value) override;
+ bool arrayItem(JSON const& value) override;
private:
void printItem(JSON const&);
diff --git a/libtests/logger_c.c b/libtests/logger_c.c
index 5c4c519a..c3fa0d8c 100644
--- a/libtests/logger_c.c
+++ b/libtests/logger_c.c
@@ -2,7 +2,6 @@
#include <qpdf/qpdflogger-c.h>
-#include <qpdf/Constants.h>
#include <qpdf/qpdfjob-c.h>
#include <stdio.h>
diff --git a/libtests/lzw.cc b/libtests/lzw.cc
index 788d3dfc..412ce4c5 100644
--- a/libtests/lzw.cc
+++ b/libtests/lzw.cc
@@ -3,8 +3,8 @@
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
int
main(int argc, char* argv[])
diff --git a/libtests/md5.cc b/libtests/md5.cc
index 0fe4205e..27aaad51 100644
--- a/libtests/md5.cc
+++ b/libtests/md5.cc
@@ -3,7 +3,7 @@
#include <qpdf/Pl_MD5.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <stdio.h>
+#include <cstdio>
static void
test_string(char const* str)
diff --git a/libtests/numrange.cc b/libtests/numrange.cc
index c0bf5bd7..ded03324 100644
--- a/libtests/numrange.cc
+++ b/libtests/numrange.cc
@@ -4,7 +4,7 @@
static void
test_numrange(char const* range)
{
- if (range == 0) {
+ if (range == nullptr) {
std::cout << "null" << std::endl;
} else {
std::vector<int> result = QUtil::parse_numrange(range, 15);
diff --git a/libtests/pointer_holder.cc b/libtests/pointer_holder.cc
index f03c4257..4b9d43cb 100644
--- a/libtests/pointer_holder.cc
+++ b/libtests/pointer_holder.cc
@@ -7,7 +7,6 @@
#include <iostream>
#include <list>
-#include <stdlib.h>
class Object
{
@@ -73,7 +72,7 @@ test_ph()
ObjectHolder oh0;
{
std::cout << "hello" << std::endl;
- Object* o1 = new Object;
+ auto* o1 = new Object;
ObjectHolder oh1(o1);
std::cout << "oh1 refcount = " << oh1.getRefcount() << std::endl;
ObjectHolder oh2(oh1);
@@ -96,7 +95,7 @@ test_ph()
}
ol1.push_back(oh3);
ol1.push_back(oh3);
- Object* o3 = new Object;
+ auto* o3 = new Object;
oh0 = o3;
PointerHolder<Object const> oh6(new Object());
oh6->hello();
diff --git a/libtests/predictors.cc b/libtests/predictors.cc
index a8f6c5d9..d7825bc6 100644
--- a/libtests/predictors.cc
+++ b/libtests/predictors.cc
@@ -6,10 +6,9 @@
#include <qpdf/QIntC.hh>
#include <qpdf/QUtil.hh>
-#include <errno.h>
#include <iostream>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
void
run(char const* filename,
@@ -22,7 +21,7 @@ run(char const* filename,
FILE* in = QUtil::safe_fopen(filename, "rb");
FILE* o1 = QUtil::safe_fopen("out", "wb");
Pipeline* out = new Pl_StdioFile("out", o1);
- Pipeline* pl = 0;
+ Pipeline* pl = nullptr;
if (strcmp(filter, "png") == 0) {
pl = new Pl_PNGFilter(
"png",
diff --git a/libtests/qintc.cc b/libtests/qintc.cc
index f6c15f00..5b985644 100644
--- a/libtests/qintc.cc
+++ b/libtests/qintc.cc
@@ -1,7 +1,7 @@
#include <qpdf/assert_test.h>
#include <qpdf/QIntC.hh>
-#include <stdint.h>
+#include <cstdint>
#define try_convert(exp_pass, fn, i) \
try_convert_real(#fn "(" #i ")", exp_pass, fn, i)
@@ -74,7 +74,7 @@ main()
uint64_t ul1 = 1099511627776LL; // Too big for 32-bit
uint64_t ul2 = 12345; // Fits into 32-bit
int32_t i2 = 81; // Fits in char and uchar
- signed char c1 = static_cast<signed char>('\xf7'); // Signed value when char
+ auto c1 = static_cast<signed char>('\xf7'); // Signed value when char
char c2 = 'W'; // char; may be signed or unsigned
// Verify i1 and u1 have same bit pattern
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index 66264d19..be5b6b1b 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -3,15 +3,11 @@
#include <qpdf/Pl_Buffer.hh>
#include <qpdf/QPDFSystemError.hh>
#include <qpdf/QUtil.hh>
-#include <fcntl.h>
#include <fstream>
#include <iostream>
-#include <limits.h>
-#include <locale>
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
+#include <climits>
+#include <cstdio>
+#include <cstring>
#ifdef _WIN32
# include <io.h>
@@ -493,7 +489,7 @@ same_file_test()
assert_same_file("qutil.out", "qutil.out", true);
assert_same_file("qutil.out", "other-file", false);
assert_same_file("qutil.out", "", false);
- assert_same_file("qutil.out", 0, false);
+ assert_same_file("qutil.out", nullptr, false);
assert_same_file("", "qutil.out", false);
}
diff --git a/libtests/random.cc b/libtests/random.cc
index ad7d105d..899c264c 100644
--- a/libtests/random.cc
+++ b/libtests/random.cc
@@ -1,7 +1,6 @@
#include <qpdf/InsecureRandomDataProvider.hh>
#include <qpdf/QUtil.hh>
#include <qpdf/SecureRandomDataProvider.hh>
-#include <qpdf/qpdf-config.h>
#include <iostream>
class BogusRandomDataProvider: public RandomDataProvider
@@ -57,7 +56,7 @@ main()
if (!((buf[0] == 0) && (buf[1] == 1) && (buf[2] == 2) && (buf[3] == 3))) {
std::cout << "fail: bogus random didn't provide correct bytes\n";
}
- QUtil::setRandomDataProvider(0);
+ QUtil::setRandomDataProvider(nullptr);
if (QUtil::getRandomDataProvider() != orig_rdp) {
std::cout << "fail: passing null to setRandomDataProvider "
"didn't reset the random data provider\n";
diff --git a/libtests/rc4.cc b/libtests/rc4.cc
index a6a1328e..300c6201 100644
--- a/libtests/rc4.cc
+++ b/libtests/rc4.cc
@@ -6,9 +6,9 @@
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
static void
other_tests()
@@ -41,7 +41,7 @@ main(int argc, char* argv[])
char* outfilename = argv[3];
unsigned int hexkeylen = QIntC::to_uint(strlen(hexkey));
unsigned int keylen = hexkeylen / 2;
- unsigned char* key = new unsigned char[keylen + 1];
+ auto* key = new unsigned char[keylen + 1];
key[keylen] = '\0';
FILE* infile = QUtil::safe_fopen(infilename, "rb");
@@ -51,14 +51,14 @@ main(int argc, char* argv[])
t[1] = hexkey[i + 1];
t[2] = '\0';
- long val = strtol(t, 0, 16);
+ long val = strtol(t, nullptr, 16);
key[i / 2] = static_cast<unsigned char>(val);
}
FILE* outfile = QUtil::safe_fopen(outfilename, "wb");
- Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile);
+ auto* out = new Pl_StdioFile("stdout", outfile);
// Use a small buffer size (64) for testing
- Pl_RC4* rc4 = new Pl_RC4("rc4", out, key, QIntC::to_int(keylen), 64U);
+ auto* rc4 = new Pl_RC4("rc4", out, key, QIntC::to_int(keylen), 64U);
delete[] key;
// 64 < buffer size < 512, buffer_size is not a power of 2 for testing
diff --git a/libtests/runlength.cc b/libtests/runlength.cc
index 456e33a2..260ce5cb 100644
--- a/libtests/runlength.cc
+++ b/libtests/runlength.cc
@@ -3,9 +3,9 @@
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
int
main(int argc, char* argv[])
diff --git a/libtests/sha2.cc b/libtests/sha2.cc
index 65b70c39..4be8956a 100644
--- a/libtests/sha2.cc
+++ b/libtests/sha2.cc
@@ -1,8 +1,7 @@
#include <qpdf/Pl_SHA2.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
-#include <stdlib.h>
-#include <string.h>
+#include <cstring>
static void
test(