summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2022-02-15 17:14:44 +0100
committerAlbert Astals Cid <aacid@kde.org>2022-02-15 18:25:12 +0100
commit07889cdfd8a261dc5ae6eb72c26a8a3ec2e35930 (patch)
tree3c7b221789cc6ddcec923e967e5d4c818d313f79 /test
parent47256c3c2905ade19f21224cb48ff5bb7de43a03 (diff)
Make PDFDoc constructor take the filename as unique_ptr
Makes it clear that it will own the given GooString
Diffstat (limited to 'test')
-rw-r--r--test/pdf-fullrewrite.cc13
-rw-r--r--test/pdf-inspector.cc7
-rw-r--r--test/perf-test.cc16
3 files changed, 8 insertions, 28 deletions
diff --git a/test/pdf-fullrewrite.cc b/test/pdf-fullrewrite.cc
index 1afc7e16..4c8d9818 100644
--- a/test/pdf-fullrewrite.cc
+++ b/test/pdf-fullrewrite.cc
@@ -39,8 +39,6 @@ int main(int argc, char *argv[])
{
PDFDoc *doc = nullptr;
PDFDoc *docOut = nullptr;
- GooString *inputName = nullptr;
- GooString *outputName = nullptr;
GooString *ownerPW = nullptr;
GooString *userPW = nullptr;
int res = 0;
@@ -55,9 +53,6 @@ int main(int argc, char *argv[])
goto done;
}
- inputName = new GooString(argv[1]);
- outputName = new GooString(argv[2]);
-
if (ownerPassword[0] != '\001') {
ownerPW = new GooString(ownerPassword);
}
@@ -67,7 +62,7 @@ int main(int argc, char *argv[])
// load input document
globalParams = std::make_unique<GlobalParams>();
- doc = new PDFDoc(inputName, ownerPW, userPW);
+ doc = new PDFDoc(std::make_unique<GooString>(argv[1]), ownerPW, userPW);
if (!doc->isOk()) {
fprintf(stderr, "Error loading input document\n");
res = 1;
@@ -75,7 +70,7 @@ int main(int argc, char *argv[])
}
// save it back (in rewrite or incremental update mode)
- if (doc->saveAs(*outputName, forceIncremental ? writeForceIncremental : writeForceRewrite) != 0) {
+ if (doc->saveAs(*doc->getFileName(), forceIncremental ? writeForceIncremental : writeForceRewrite) != 0) {
fprintf(stderr, "Error saving document\n");
res = 1;
goto done;
@@ -83,7 +78,7 @@ int main(int argc, char *argv[])
if (checkOutput) {
// open the generated document to verify it
- docOut = new PDFDoc(outputName, ownerPW, userPW);
+ docOut = new PDFDoc(std::make_unique<GooString>(argv[2]), ownerPW, userPW);
if (!docOut->isOk()) {
fprintf(stderr, "Error loading generated document\n");
res = 1;
@@ -91,8 +86,6 @@ int main(int argc, char *argv[])
fprintf(stderr, "Verification failed\n");
res = 1;
}
- } else {
- delete outputName;
}
done:
diff --git a/test/pdf-inspector.cc b/test/pdf-inspector.cc
index eb6c62e1..f3034cf1 100644
--- a/test/pdf-inspector.cc
+++ b/test/pdf-inspector.cc
@@ -4,7 +4,7 @@
//
// Copyright 2005 Jonathan Blandford <jrb@redhat.com>
// Copyright 2018 Adam Reichold <adam.reichold@t-online.de>
-// Copyright 2019 Albert Astals Cid <aacid@kde.org>
+// Copyright 2019, 2022 Albert Astals Cid <aacid@kde.org>
//
//========================================================================
@@ -222,10 +222,7 @@ void PdfInspector::load(const char *file_name)
// load the new file
if (file_name) {
- GooString *filename_g;
-
- filename_g = new GooString(file_name);
- doc = new PDFDoc(filename_g, nullptr, nullptr);
+ doc = new PDFDoc(std::make_unique<GooString>(file_name), nullptr, nullptr);
}
if (doc && !doc->isOk()) {
diff --git a/test/perf-test.cc b/test/perf-test.cc
index 36e21bb0..1d577eb1 100644
--- a/test/perf-test.cc
+++ b/test/perf-test.cc
@@ -1,6 +1,6 @@
/* Copyright Krzysztof Kowalczyk 2006-2007
Copyright Hib Eris <hib@hiberis.nl> 2008, 2013
- Copyright 2018, 2020 Albert Astals Cid <aacid@kde.org> 2018
+ Copyright 2018, 2020, 2022 Albert Astals Cid <aacid@kde.org> 2018
Copyright 2019 Oliver Sander <oliver.sander@tu-dresden.de>
Copyright 2020 Adam Reichold <adam.reichold@t-online.de>
License: GPLv2 */
@@ -382,12 +382,8 @@ PdfEnginePoppler::~PdfEnginePoppler()
bool PdfEnginePoppler::load(const char *fileName)
{
setFileName(fileName);
- /* note: don't delete fileNameStr since PDFDoc takes ownership and deletes them itself */
- GooString *fileNameStr = new GooString(fileName);
- if (!fileNameStr)
- return false;
- _pdfDoc = new PDFDoc(fileNameStr, nullptr, nullptr, nullptr);
+ _pdfDoc = new PDFDoc(std::make_unique<GooString>(fileName), nullptr, nullptr, nullptr);
if (!_pdfDoc->isOk()) {
return false;
}
@@ -585,7 +581,6 @@ static bool ShowPreview()
static void RenderPdfAsText(const char *fileName)
{
- GooString *fileNameStr = nullptr;
PDFDoc *pdfDoc = nullptr;
GooString *txt = nullptr;
int pageCount;
@@ -604,12 +599,7 @@ static void RenderPdfAsText(const char *fileName)
}
GooTimer msTimer;
- /* note: don't delete fileNameStr since PDFDoc takes ownership and deletes them itself */
- fileNameStr = new GooString(fileName);
- if (!fileNameStr)
- goto Exit;
-
- pdfDoc = new PDFDoc(fileNameStr, nullptr, nullptr, nullptr);
+ pdfDoc = new PDFDoc(std::make_unique<GooString>(fileName), nullptr, nullptr, nullptr);
if (!pdfDoc->isOk()) {
error(errIO, -1, "RenderPdfFile(): failed to open PDF file {0:s}\n", fileName);
goto Exit;