| 115 | void header_test() |
| 116 | { |
| 117 | // This test is in response to https://svn.boost.org/trac/boost/ticket/5908 |
| 118 | // which describes a problem parsing gzip headers with extra fields as |
| 119 | // defined in RFC 1952 (http://www.ietf.org/rfc/rfc1952.txt). |
| 120 | // The extra field data used here is characteristic of the tabix file |
| 121 | // format (http://samtools.sourceforge.net/tabix.shtml). |
| 122 | const char header_bytes[] = { |
| 123 | gzip::magic::id1, |
| 124 | gzip::magic::id2, |
| 125 | gzip::method::deflate, // Compression Method: deflate |
| 126 | gzip::flags::extra | gzip::flags::name | gzip::flags::comment, // flags |
| 127 | 0x22, 0x9c, 0xf3, 0x4e, // 4 byte modification time (little endian) |
| 128 | gzip::extra_flags::best_compression, // XFL |
| 129 | gzip::os_unix, // OS |
| 130 | 6, 0, // 2 byte length of extra field (little endian, 6 bytes) |
| 131 | 'B', 'C', 2, 0, 0, 0, // 6 bytes worth of extra field data |
| 132 | 'a', 'b', 'c', 0, // original filename, null terminated |
| 133 | 'n', 'o', ' ', 'c', 'o', 'm', 'm', 'e', 'n', 't', 0, // comment |
| 134 | }; |
| 135 | size_t sz = sizeof(header_bytes)/sizeof(header_bytes[0]); |
| 136 | |
| 137 | boost::iostreams::detail::gzip_header hdr; |
| 138 | for (size_t i = 0; i < sz; ++i) { |
| 139 | hdr.process(header_bytes[i]); |
| 140 | |
| 141 | // Require that we are done at the last byte, not before. |
| 142 | if (i == sz-1) |
| 143 | BOOST_REQUIRE(hdr.done()); |
| 144 | else |
| 145 | BOOST_REQUIRE(!hdr.done()); |
| 146 | } |
| 147 | |
| 148 | BOOST_CHECK_EQUAL("abc", hdr.file_name()); |
| 149 | BOOST_CHECK_EQUAL("no comment", hdr.comment()); |
| 150 | BOOST_CHECK_EQUAL(0x4ef39c22, hdr.mtime()); |
| 151 | BOOST_CHECK_EQUAL(gzip::os_unix, hdr.os()); |
| 152 | } |
| 153 | |