OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The test buffer data is 52 bytes, wrap position is set to 20 (this is | 5 // The test buffer data is 52 bytes, wrap position is set to 20 (this is |
6 // arbitrarily chosen). The total buffer size is allocated dynamically based on | 6 // arbitrarily chosen). The total buffer size is allocated dynamically based on |
7 // the actual header size. This gives: | 7 // the actual header size. This gives: |
8 // Header of some size, non-wrapping part 20 bytes, wrapping part 32 bytes. | 8 // Header of some size, non-wrapping part 20 bytes, wrapping part 32 bytes. |
9 // As input data, a 14 byte array is used and repeatedly written. It's chosen | 9 // As input data, a 14 byte array is used and repeatedly written. It's chosen |
10 // not to be an integer factor smaller than the wrapping part. This ensures that | 10 // not to be an integer factor smaller than the wrapping part. This ensures that |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 InitReadBuffer(); | 182 InitReadBuffer(); |
183 | 183 |
184 uint8 output_data[sizeof(kInputData)] = {0}; | 184 uint8 output_data[sizeof(kInputData)] = {0}; |
185 EXPECT_EQ(sizeof(output_data), | 185 EXPECT_EQ(sizeof(output_data), |
186 pcb_read_->Read(output_data, sizeof(output_data))); | 186 pcb_read_->Read(output_data, sizeof(output_data))); |
187 | 187 |
188 EXPECT_EQ(0, memcmp(kInputData, output_data, sizeof(kInputData))); | 188 EXPECT_EQ(0, memcmp(kInputData, output_data, sizeof(kInputData))); |
189 | 189 |
190 EXPECT_EQ(0u, pcb_read_->Read(output_data, sizeof(output_data))); | 190 EXPECT_EQ(0u, pcb_read_->Read(output_data, sizeof(output_data))); |
191 } | 191 } |
| 192 |
| 193 TEST_F(PartialCircularBufferTest, WrapTwiceWithSingleWrite) { |
| 194 const size_t kInputSize = sizeof(kInputData); |
| 195 const size_t kLargeSize = kInputSize * 7; |
| 196 uint8 large_input[kLargeSize] = {0}; |
| 197 for (size_t offset = 0; offset < kLargeSize; offset += kInputSize) |
| 198 memcpy(large_input + offset, kInputData, kInputSize); |
| 199 |
| 200 InitWriteBuffer(false); |
| 201 pcb_write_->Write(large_input, kLargeSize); |
| 202 InitReadBuffer(); |
| 203 |
| 204 uint8 output_data[sizeof(kOutputRefDataWrap)] = {0}; |
| 205 EXPECT_EQ(sizeof(output_data), |
| 206 pcb_read_->Read(output_data, sizeof(output_data))); |
| 207 |
| 208 EXPECT_EQ(0, memcmp(kOutputRefDataWrap, output_data, sizeof(output_data))); |
| 209 |
| 210 EXPECT_EQ(0u, pcb_read_->Read(output_data, sizeof(output_data))); |
| 211 } |
| 212 |
OLD | NEW |