Ticket #5898: testpbzip2.cc

File testpbzip2.cc, 1.6 KB (added by Andrew.Bromage@…, 11 years ago)

Failing test case

Line 
1#include <iostream>
2#include <sstream>
3#include <boost/iostreams/filtering_stream.hpp>
4#include <boost/iostreams/filter/bzip2.hpp>
5#include <boost/iostreams/copy.hpp>
6
7using namespace std;
8using namespace boost::iostreams;
9
10std::string
11decompressString(const uint8_t* pBegin, size_t pLen, size_t pBufSize = 4096)
12{
13 string input(pBegin, pBegin + pLen);
14 stringstream istring(input, ios_base::in | ios_base::binary);
15 filtering_istream in;
16 in.push(bzip2_decompressor(false, pBufSize));
17 in.push(istring);
18
19 stringstream out(ios_base::out | ios_base::binary);
20 copy(in, out);
21
22 return out.str();
23}
24
25
26static uint8_t
27pbzipFile[] = {
28 0x42, 0x5a, 0x68, 0x39, 0x31, 0x41, 0x59, 0x26,
29 0x53, 0x59, 0x63, 0xe3, 0xec, 0xa2, 0x00, 0x06,
30 0xe4, 0xc1, 0x00, 0xc0, 0x00, 0x02, 0x00, 0x00,
31 0x08, 0x20, 0x00, 0x30, 0xcc, 0x09, 0xaa, 0x69,
32 0x94, 0xa1, 0x36, 0xa9, 0x28, 0x4f, 0x17, 0x72,
33 0x45, 0x38, 0x50, 0x90, 0x63, 0xe3, 0xec, 0xa2,
34 0x42, 0x5a, 0x68, 0x39, 0x31, 0x41, 0x59, 0x26,
35 0x53, 0x59, 0x01, 0xe8, 0xd0, 0x60, 0x00, 0x00,
36 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0x80, 0x00,
37 0x08, 0x20, 0x00, 0x20, 0xaa, 0x6d, 0x41, 0x98,
38 0xba, 0x83, 0xc5, 0xdc, 0x91, 0x4e, 0x14, 0x24,
39 0x00, 0x7a, 0x34, 0x18, 0x00
40};
41
42int
43main()
44{
45 try {
46 string output;
47 output = decompressString(pbzipFile, sizeof(pbzipFile));
48 cout << "Output size 1 = " << output.size() << "\n";
49 output = decompressString(pbzipFile, sizeof(pbzipFile), 50);
50 cout << "Output size 2 = " << output.size() << "\n";
51 }
52 catch (std::exception err)
53 {
54 cout << "Caught exception " << err.what() << "\n";
55 }
56}
57