2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-16 17:45:09 +00:00
qpdf/libtests/concatenate.cc
Jay Berkenbilt 12f1eb15ca Programmatically apply new formatting to code
Run this:

for i in  **/*.cc **/*.c **/*.h **/*.hh; do
  clang-format < $i >| $i.new && mv $i.new $i
done
2022-04-04 08:10:40 -04:00

45 lines
1.2 KiB
C++

#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)
{
p->write(QUtil::unsigned_char_pointer(str), str.length());
p->finish();
}
int
main(int argc, char* argv[])
{
Pl_Buffer b1("compressed");
Pl_Flate deflate("compress", &b1, Pl_Flate::a_deflate);
Pl_Concatenate concat("concat", &deflate);
pipeStringAndFinish(&concat, "-one-");
pipeStringAndFinish(&concat, "-two-");
concat.manualFinish();
auto b1_buf = b1.getBufferSharedPointer();
Pl_Buffer b2("uncompressed");
Pl_Flate inflate("uncompress", &b2, Pl_Flate::a_inflate);
inflate.write(b1_buf->getBuffer(), b1_buf->getSize());
inflate.finish();
auto b2_buf = b2.getBufferSharedPointer();
std::string result(
reinterpret_cast<char*>(b2_buf->getBuffer()), b2_buf->getSize());
if (result == "-one--two-") {
std::cout << "concatenate test passed" << std::endl;
} else {
std::cout << "concatenate test failed: " << result << std::endl;
}
return 0;
}