2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/Pl_Buffer.hh>
|
|
|
|
#include <qpdf/Pl_Count.hh>
|
|
|
|
#include <qpdf/Pl_Discard.hh>
|
2013-02-24 02:46:21 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
2008-05-04 16:02:53 +00:00
|
|
|
#include <stdlib.h>
|
2010-10-01 11:19:36 +00:00
|
|
|
#include <stdexcept>
|
2011-08-11 15:56:37 +00:00
|
|
|
#include <iostream>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2013-02-24 02:46:21 +00:00
|
|
|
static unsigned char* uc(char const* s)
|
|
|
|
{
|
|
|
|
return QUtil::unsigned_char_pointer(s);
|
|
|
|
}
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Pl_Discard discard;
|
|
|
|
Pl_Count count("count", &discard);
|
|
|
|
Pl_Buffer bp1("bp1", &count);
|
2013-02-24 02:46:21 +00:00
|
|
|
bp1.write(uc("12345"), 5);
|
|
|
|
bp1.write(uc("67890"), 5);
|
2008-04-29 12:55:25 +00:00
|
|
|
bp1.finish();
|
|
|
|
std::cout << "count: " << count.getCount() << std::endl;
|
2013-02-24 02:46:21 +00:00
|
|
|
bp1.write(uc("abcde"), 5);
|
|
|
|
bp1.write(uc("fghij"), 6);
|
2008-04-29 12:55:25 +00:00
|
|
|
bp1.finish();
|
|
|
|
std::cout << "count: " << count.getCount() << std::endl;
|
|
|
|
Buffer* b = bp1.getBuffer();
|
|
|
|
std::cout << "size: " << b->getSize() << std::endl;
|
|
|
|
std::cout << "data: " << b->getBuffer() << std::endl;
|
|
|
|
delete b;
|
2013-02-24 02:46:21 +00:00
|
|
|
bp1.write(uc("qwert"), 5);
|
|
|
|
bp1.write(uc("yuiop"), 6);
|
2008-04-29 12:55:25 +00:00
|
|
|
bp1.finish();
|
|
|
|
std::cout << "count: " << count.getCount() << std::endl;
|
|
|
|
b = bp1.getBuffer();
|
|
|
|
std::cout << "size: " << b->getSize() << std::endl;
|
|
|
|
std::cout << "data: " << b->getBuffer() << std::endl;
|
|
|
|
delete b;
|
|
|
|
|
|
|
|
Pl_Buffer bp2("bp2");
|
2013-02-24 02:46:21 +00:00
|
|
|
bp2.write(uc("moo"), 3);
|
|
|
|
bp2.write(uc("quack"), 6);
|
2008-04-29 12:55:25 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
delete bp2.getBuffer();
|
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
|
|
|
std::cout << e.what() << std::endl;
|
|
|
|
}
|
|
|
|
bp2.finish();
|
|
|
|
b = bp2.getBuffer();
|
|
|
|
std::cout << "size: " << b->getSize() << std::endl;
|
|
|
|
std::cout << "data: " << b->getBuffer() << std::endl;
|
|
|
|
delete b;
|
2010-10-01 11:19:36 +00:00
|
|
|
|
|
|
|
unsigned char lbuf[10];
|
|
|
|
Buffer b1(lbuf, 10);
|
|
|
|
if (! ((b1.getBuffer() == lbuf) &&
|
|
|
|
(b1.getSize() == 10)))
|
|
|
|
{
|
|
|
|
throw std::logic_error("hand-created buffer is not as expected");
|
|
|
|
}
|
2018-03-06 16:24:30 +00:00
|
|
|
|
|
|
|
Pl_Buffer bp3("bp3");
|
|
|
|
b = bp3.getBuffer();
|
|
|
|
std::cout << "size: " << b->getSize() << std::endl;
|
2018-05-05 21:43:44 +00:00
|
|
|
delete b;
|
2008-04-29 12:55:25 +00:00
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
|
|
|
std::cout << "unexpected exception: " << e.what() << std::endl;
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "done" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|