aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/test_large_file.cc
diff options
context:
space:
mode:
Diffstat (limited to 'qpdf/test_large_file.cc')
-rw-r--r--qpdf/test_large_file.cc145
1 files changed, 64 insertions, 81 deletions
diff --git a/qpdf/test_large_file.cc b/qpdf/test_large_file.cc
index 8f7f8755..0a81dcc7 100644
--- a/qpdf/test_large_file.cc
+++ b/qpdf/test_large_file.cc
@@ -4,15 +4,15 @@
// internally by the library as long as they don't do their own file
// I/O.
+#include <qpdf/QIntC.hh>
#include <qpdf/QPDF.hh>
+#include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/QPDFPageDocumentHelper.hh>
#include <qpdf/QPDFWriter.hh>
-#include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/QUtil.hh>
-#include <qpdf/QIntC.hh>
#include <iostream>
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#ifdef NDEBUG
// We need assert even in a release build for test code.
@@ -53,9 +53,11 @@ size_t width = 0;
size_t height = 0;
static unsigned char* buf = 0;
-static inline unsigned char get_pixel_color(size_t n, size_t row)
+static inline unsigned char
+get_pixel_color(size_t n, size_t row)
{
- return ((n & (1LLU << (nstripes - 1LLU - row)))
+ return (
+ (n & (1LLU << (nstripes - 1LLU - row)))
? static_cast<unsigned char>('\xc0')
: static_cast<unsigned char>('\x40'));
}
@@ -89,12 +91,10 @@ ImageChecker::~ImageChecker()
void
ImageChecker::write(unsigned char* data, size_t len)
{
- for (size_t i = 0; i < len; ++i)
- {
+ for (size_t i = 0; i < len; ++i) {
size_t y = (this->offset + i) / width / stripesize;
unsigned char color = get_pixel_color(n, y);
- if (data[i] != color)
- {
+ if (data[i] != color) {
okay = false;
}
}
@@ -104,8 +104,7 @@ ImageChecker::write(unsigned char* data, size_t len)
void
ImageChecker::finish()
{
- if (! okay)
- {
+ if (!okay) {
std::cout << "errors found checking image data for page " << n
<< std::endl;
}
@@ -116,8 +115,8 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider
public:
ImageProvider(size_t n);
virtual ~ImageProvider();
- virtual void provideStreamData(int objid, int generation,
- Pipeline* pipeline);
+ virtual void
+ provideStreamData(int objid, int generation, Pipeline* pipeline);
private:
size_t n;
@@ -133,16 +132,13 @@ ImageProvider::~ImageProvider()
}
void
-ImageProvider::provideStreamData(int objid, int generation,
- Pipeline* pipeline)
+ImageProvider::provideStreamData(int objid, int generation, Pipeline* pipeline)
{
- if (buf == 0)
- {
+ if (buf == 0) {
buf = new unsigned char[width * stripesize];
}
std::cout << "page " << n << " of " << npages << std::endl;
- for (size_t y = 0; y < nstripes; ++y)
- {
+ for (size_t y = 0; y < nstripes; ++y) {
unsigned char color = get_pixel_color(n, y);
memset(buf, color, width * stripesize);
pipeline->write(buf, width * stripesize);
@@ -150,52 +146,59 @@ ImageProvider::provideStreamData(int objid, int generation,
pipeline->finish();
}
-void usage()
+void
+usage()
{
std::cerr << "Usage: " << whoami << " {read|write} {large|small} outfile"
<< std::endl;
exit(2);
}
-static void set_parameters(bool large)
+static void
+set_parameters(bool large)
{
stripesize = large ? stripesize_large : stripesize_small;
height = nstripes * stripesize;
width = height;
}
-std::string generate_page_contents(size_t pageno)
+std::string
+generate_page_contents(size_t pageno)
{
- std::string contents =
- "BT /F1 24 Tf 72 720 Td (page " + QUtil::uint_to_string(pageno) +
+ std::string contents = "BT /F1 24 Tf 72 720 Td (page " +
+ QUtil::uint_to_string(pageno) +
") Tj ET\n"
"q 468 0 0 468 72 72 cm /Im1 Do Q\n";
return contents;
}
-static QPDFObjectHandle create_page_contents(QPDF& pdf, size_t pageno)
+static QPDFObjectHandle
+create_page_contents(QPDF& pdf, size_t pageno)
{
return QPDFObjectHandle::newStream(&pdf, generate_page_contents(pageno));
}
-QPDFObjectHandle newName(std::string const& name)
+QPDFObjectHandle
+newName(std::string const& name)
{
return QPDFObjectHandle::newName(name);
}
-QPDFObjectHandle newInteger(size_t val)
+QPDFObjectHandle
+newInteger(size_t val)
{
return QPDFObjectHandle::newInteger(QIntC::to_longlong(val));
}
-static void create_pdf(char const* filename)
+static void
+create_pdf(char const* filename)
{
QPDF pdf;
pdf.emptyPDF();
- QPDFObjectHandle font = pdf.makeIndirectObject(
- QPDFObjectHandle::newDictionary());
+ QPDFObjectHandle font =
+ pdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
font.replaceKey("/Type", newName("/Font"));
font.replaceKey("/Subtype", newName("/Type1"));
font.replaceKey("/Name", newName("/F1"));
@@ -218,8 +221,7 @@ static void create_pdf(char const* filename)
mediabox.appendItem(newInteger(792));
QPDFPageDocumentHelper dh(pdf);
- for (size_t pageno = 1; pageno <= npages; ++pageno)
- {
+ for (size_t pageno = 1; pageno <= npages; ++pageno) {
QPDFObjectHandle image = QPDFObjectHandle::newStream(&pdf);
QPDFObjectHandle image_dict = image.getDict();
image_dict.replaceKey("/Type", newName("/XObject"));
@@ -230,9 +232,8 @@ static void create_pdf(char const* filename)
image_dict.replaceKey("/Height", newInteger(height));
ImageProvider* p = new ImageProvider(pageno);
PointerHolder<QPDFObjectHandle::StreamDataProvider> provider(p);
- image.replaceStreamData(provider,
- QPDFObjectHandle::newNull(),
- QPDFObjectHandle::newNull());
+ image.replaceStreamData(
+ provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
QPDFObjectHandle xobject = QPDFObjectHandle::newDictionary();
xobject.replaceKey("/Im1", image);
@@ -244,8 +245,8 @@ static void create_pdf(char const* filename)
QPDFObjectHandle contents = create_page_contents(pdf, pageno);
- QPDFObjectHandle page = pdf.makeIndirectObject(
- QPDFObjectHandle::newDictionary());
+ QPDFObjectHandle page =
+ pdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
page.replaceKey("/Type", newName("/Page"));
page.replaceKey("/MediaBox", mediabox);
page.replaceKey("/Contents", contents);
@@ -255,30 +256,28 @@ static void create_pdf(char const* filename)
}
QPDFWriter w(pdf, filename);
- w.setStaticID(true); // for testing only
+ w.setStaticID(true); // for testing only
w.setStreamDataMode(qpdf_s_preserve);
w.setObjectStreamMode(qpdf_o_disable);
w.write();
}
-static void check_page_contents(size_t pageno, QPDFObjectHandle page)
+static void
+check_page_contents(size_t pageno, QPDFObjectHandle page)
{
- PointerHolder<Buffer> buf =
- page.getKey("/Contents").getStreamData();
+ PointerHolder<Buffer> buf = page.getKey("/Contents").getStreamData();
std::string actual_contents =
- std::string(reinterpret_cast<char *>(buf->getBuffer()),
- buf->getSize());
+ std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize());
std::string expected_contents = generate_page_contents(pageno);
- if (expected_contents != actual_contents)
- {
+ if (expected_contents != actual_contents) {
std::cout << "page contents wrong for page " << pageno << std::endl
<< "ACTUAL: " << actual_contents
- << "EXPECTED: " << expected_contents
- << "----\n";
+ << "EXPECTED: " << expected_contents << "----\n";
}
}
-static void check_image(size_t pageno, QPDFObjectHandle page)
+static void
+check_image(size_t pageno, QPDFObjectHandle page)
{
QPDFObjectHandle image =
page.getKey("/Resources").getKey("/XObject").getKey("/Im1");
@@ -286,14 +285,14 @@ static void check_image(size_t pageno, QPDFObjectHandle page)
image.pipeStreamData(&ic, 0, qpdf_dl_specialized);
}
-static void check_pdf(char const* filename)
+static void
+check_pdf(char const* filename)
{
QPDF pdf;
pdf.processFile(filename);
std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
assert(pages.size() == QIntC::to_size(npages));
- for (size_t i = 0; i < npages; ++i)
- {
+ for (size_t i = 0; i < npages; ++i) {
size_t pageno = i + 1;
std::cout << "page " << pageno << " of " << npages << std::endl;
check_page_contents(pageno, pages.at(i));
@@ -301,13 +300,13 @@ static void check_pdf(char const* filename)
}
}
-int main(int argc, char* argv[])
+int
+main(int argc, char* argv[])
{
whoami = QUtil::getWhoami(argv[0]);
QUtil::setLineBuf(stdout);
- if (argc != 4)
- {
+ if (argc != 4) {
usage();
}
char const* operation = argv[1];
@@ -317,52 +316,36 @@ int main(int argc, char* argv[])
bool op_write = false;
bool size_large = false;
- if (strcmp(operation, "write") == 0)
- {
+ if (strcmp(operation, "write") == 0) {
op_write = true;
- }
- else if (strcmp(operation, "read") == 0)
- {
+ } else if (strcmp(operation, "read") == 0) {
op_write = false;
- }
- else
- {
+ } else {
usage();
}
- if (strcmp(size, "large") == 0)
- {
+ if (strcmp(size, "large") == 0) {
size_large = true;
- }
- else if (strcmp(size, "small") == 0)
- {
+ } else if (strcmp(size, "small") == 0) {
size_large = false;
- }
- else
- {
+ } else {
usage();
}
set_parameters(size_large);
- try
- {
- if (op_write)
- {
+ try {
+ if (op_write) {
create_pdf(filename);
- }
- else
- {
+ } else {
check_pdf(filename);
}
- }
- catch (std::exception& e)
- {
+ } catch (std::exception& e) {
std::cerr << e.what() << std::endl;
exit(2);
}
- delete [] buf;
+ delete[] buf;
return 0;
}