| 213 | } |
| 214 | |
| 215 | int |
| 216 | test_encoding(const string &filename_in, const string &filename_out) |
| 217 | { |
| 218 | HpackIndexingTable indexing_table_for_encoding(INITIAL_TABLE_SIZE), indexing_table_for_decoding(INITIAL_TABLE_SIZE); |
| 219 | string line, name, value; |
| 220 | uint8_t encoded[8192]; |
| 221 | const uint64_t encoded_len = sizeof(encoded); |
| 222 | string packed; |
| 223 | int64_t written; |
| 224 | int result = -1; |
| 225 | HTTPHdr original, decoded; |
| 226 | MIMEField *field; |
| 227 | |
| 228 | decoded.create(HTTP_TYPE_REQUEST); |
| 229 | original.create(HTTP_TYPE_REQUEST); |
| 230 | |
| 231 | ofstream ofs(filename_out); |
| 232 | ofs << "{" << endl; |
| 233 | ofs << " \"cases\": [" << endl; |
| 234 | |
| 235 | int seqnum = -1; |
| 236 | ifstream ifs(filename_in); |
| 237 | while (ifs && getline(ifs, line) && result == -1) { |
| 238 | switch (line.find_first_of('"')) { |
| 239 | case 6: |
| 240 | switch (line[6 + 1]) { |
| 241 | case 's': |
| 242 | // This line should be the start of new case |
| 243 | // Check the last sequence |
| 244 | if (seqnum != -1) { |
| 245 | ofs << " }" << endl; // end of last header |
| 246 | ofs << " ]," << endl; // end of headers |
| 247 | written = hpack_encode_header_block(indexing_table_for_encoding, encoded, encoded_len, &original); |
| 248 | if (written == -1) { |
| 249 | result = seqnum; |
| 250 | break; |
| 251 | } |
| 252 | hpack_decode_header_block(indexing_table_for_decoding, &decoded, encoded, written, MAX_REQUEST_HEADER_SIZE, |
| 253 | MAX_TABLE_SIZE); |
| 254 | if (compare_header_fields(&decoded, &original) != 0) { |
| 255 | result = seqnum; |
| 256 | break; |
| 257 | } |
| 258 | pack(encoded, written, packed); |
| 259 | ofs << R"( "wire": ")" << packed << "\"" << endl; |
| 260 | ofs << " }," << endl; |
| 261 | } |
| 262 | // Prepare for next sequence |
| 263 | ++seqnum; |
| 264 | decoded.fields_clear(); |
| 265 | original.fields_clear(); |
| 266 | name = ""; |
| 267 | value = ""; |
| 268 | ofs << " {" << endl; |
| 269 | ofs << " \"seqnum\": " << seqnum << "," << endl; |
| 270 | ofs << " \"headers\": [" << endl; |
| 271 | break; |
| 272 | case 'w': |
no test coverage detected