Returns -1 if test passes, or returns the failed sequence number
| 160 | |
| 161 | // Returns -1 if test passes, or returns the failed sequence number |
| 162 | int |
| 163 | test_decoding(const string &filename) |
| 164 | { |
| 165 | HpackIndexingTable indexing_table(INITIAL_TABLE_SIZE); |
| 166 | string line, name, value; |
| 167 | uint8_t unpacked[8192]; |
| 168 | size_t unpacked_len; |
| 169 | int result = -1; |
| 170 | HTTPHdr original, decoded; |
| 171 | MIMEField *field; |
| 172 | |
| 173 | decoded.create(HTTP_TYPE_REQUEST); |
| 174 | original.create(HTTP_TYPE_REQUEST); |
| 175 | |
| 176 | int seqnum = -1; |
| 177 | ifstream ifs(filename); |
| 178 | while (ifs && getline(ifs, line) && result == -1) { |
| 179 | switch (line.find_first_of('"')) { |
| 180 | case 6: |
| 181 | switch (line[6 + 1]) { |
| 182 | case 's': |
| 183 | // This line should be the start of new case |
| 184 | // Check the last case |
| 185 | if (compare_header_fields(&decoded, &original) != 0) { |
| 186 | result = seqnum; |
| 187 | break; |
| 188 | } |
| 189 | // Prepare for next sequence |
| 190 | ++seqnum; |
| 191 | decoded.fields_clear(); |
| 192 | original.fields_clear(); |
| 193 | break; |
| 194 | case 'w': |
| 195 | parse_line(line, 6, name, value); |
| 196 | unpacked_len = unpack(value, unpacked); |
| 197 | hpack_decode_header_block(indexing_table, &decoded, unpacked, unpacked_len, MAX_REQUEST_HEADER_SIZE, MAX_TABLE_SIZE); |
| 198 | break; |
| 199 | } |
| 200 | break; |
| 201 | case 10: |
| 202 | // This line should be a header field |
| 203 | parse_line(line, 10, name, value); |
| 204 | field = original.field_create(name.c_str(), name.length()); |
| 205 | field->value_set(original.m_heap, original.m_mime, value.c_str(), value.length()); |
| 206 | original.field_attach(field); |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | decoded.destroy(); |
| 211 | original.destroy(); |
| 212 | return result; |
| 213 | } |
| 214 | |
| 215 | int |
| 216 | test_encoding(const string &filename_in, const string &filename_out) |
no test coverage detected