diff --git a/libtests/build.mk b/libtests/build.mk index f7e53929..6464502b 100644 --- a/libtests/build.mk +++ b/libtests/build.mk @@ -3,6 +3,7 @@ BINS_libtests = \ ascii85 \ bits \ buffer \ + concatenate \ flate \ hex \ lzw \ diff --git a/libtests/concatenate.cc b/libtests/concatenate.cc new file mode 100644 index 00000000..cf4332cb --- /dev/null +++ b/libtests/concatenate.cc @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +static void pipeStringAndFinish(Pipeline* p, std::string const& str) +{ + p->write((unsigned char*)str.c_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(); + + PointerHolder b1_buf = b1.getBuffer(); + Pl_Buffer b2("uncompressed"); + Pl_Flate inflate("uncompress", &b2, Pl_Flate::a_inflate); + inflate.write(b1_buf->getBuffer(), b1_buf->getSize()); + inflate.finish(); + PointerHolder b2_buf = b2.getBuffer(); + std::string result((char const*)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; +}