| 43 | namespace { |
| 44 | |
| 45 | std::tuple<int, int, bool> feed_bytes(http_parser& parser, string_view str) |
| 46 | { |
| 47 | std::tuple<int, int, bool> ret(0, 0, false); |
| 48 | std::tuple<int, int, bool> prev(0, 0, false); |
| 49 | for (int chunks = 1; chunks < 70; ++chunks) |
| 50 | { |
| 51 | ret = std::make_tuple(0, 0, false); |
| 52 | parser.reset(); |
| 53 | string_view recv_buf; |
| 54 | for (;;) |
| 55 | { |
| 56 | int const chunk_size = std::min(chunks, int(str.size() - recv_buf.size())); |
| 57 | if (chunk_size == 0) break; |
| 58 | recv_buf = str.substr(0, recv_buf.size() + std::size_t(chunk_size)); |
| 59 | int payload, protocol; |
| 60 | bool error = false; |
| 61 | std::tie(payload, protocol) = parser.incoming(recv_buf, error); |
| 62 | std::get<0>(ret) += payload; |
| 63 | std::get<1>(ret) += protocol; |
| 64 | |
| 65 | #ifdef _MSC_VER |
| 66 | #pragma warning(push, 1) |
| 67 | // this ia a buggy diagnostic on msvc |
| 68 | // warning C4834: discarding return value of function with 'nodiscard' attribute |
| 69 | #pragma warning( disable : 4834 ) |
| 70 | #endif |
| 71 | std::get<2>(ret) |= error; |
| 72 | |
| 73 | #ifdef _MSC_VER |
| 74 | #pragma warning(pop) |
| 75 | #endif |
| 76 | TORRENT_ASSERT(payload + protocol == chunk_size || std::get<2>(ret)); |
| 77 | } |
| 78 | TEST_CHECK(prev == std::make_tuple(0, 0, false) || ret == prev || std::get<2>(ret)); |
| 79 | if (!std::get<2>(ret)) |
| 80 | { |
| 81 | TEST_EQUAL(std::get<0>(ret) + std::get<1>(ret), int(str.size())); |
| 82 | } |
| 83 | |
| 84 | prev = ret; |
| 85 | } |
| 86 | return ret; |
| 87 | } |
| 88 | |
| 89 | } // anonymous namespace |
| 90 |
no test coverage detected