aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/concatenate.cc
blob: cf4332cb9d090f8b3bd28b2bb2ee3f18f9b0be1c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <qpdf/Pl_Concatenate.hh>
#include <qpdf/Pl_Flate.hh>
#include <qpdf/Pl_Buffer.hh>
#include <iostream>
#include <assert.h>

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<Buffer> 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<Buffer> 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;
}