| 119 | } |
| 120 | |
| 121 | void AssertChunkingBlockSize(Chunker& chunker, std::shared_ptr<Buffer> buf, |
| 122 | int64_t block_size, int expected_count) { |
| 123 | std::shared_ptr<Buffer> partial = Buffer::FromString({}); |
| 124 | int64_t pos = 0; |
| 125 | int total_count = 0; |
| 126 | while (pos < buf->size()) { |
| 127 | int count; |
| 128 | auto block = SliceBuffer(buf, pos, std::min(block_size, buf->size() - pos)); |
| 129 | pos += block->size(); |
| 130 | std::shared_ptr<Buffer> completion, whole, next_partial; |
| 131 | |
| 132 | if (pos == buf->size()) { |
| 133 | // Last block |
| 134 | ASSERT_OK(chunker.ProcessFinal(partial, block, &completion, &whole)); |
| 135 | } else { |
| 136 | std::shared_ptr<Buffer> starts_with_whole; |
| 137 | ASSERT_OK( |
| 138 | chunker.ProcessWithPartial(partial, block, &completion, &starts_with_whole)); |
| 139 | ASSERT_OK(chunker.Process(starts_with_whole, &whole, &next_partial)); |
| 140 | } |
| 141 | // partial + completion should be a valid JSON block |
| 142 | ASSERT_OK_AND_ASSIGN(partial, ConcatenateBuffers({partial, completion})); |
| 143 | AssertOnlyWholeObjects(chunker, partial, &count); |
| 144 | total_count += count; |
| 145 | // whole should be a valid JSON block |
| 146 | AssertOnlyWholeObjects(chunker, whole, &count); |
| 147 | total_count += count; |
| 148 | partial = next_partial; |
| 149 | } |
| 150 | ASSERT_EQ(pos, buf->size()); |
| 151 | ASSERT_EQ(total_count, expected_count); |
| 152 | } |
| 153 | |
| 154 | void AssertStraddledChunking(Chunker& chunker, const std::shared_ptr<Buffer>& buf) { |
| 155 | auto first_half = SliceBuffer(buf, 0, buf->size() / 2); |
no test coverage detected