QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame^] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/platform/api/quic_mem_slice_storage.h" |
| 6 | #include "net/third_party/quiche/src/quic/core/quic_simple_buffer_allocator.h" |
| 7 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 8 | |
| 9 | namespace quic { |
| 10 | namespace test { |
| 11 | namespace { |
| 12 | |
| 13 | class QuicMemSliceStorageImplTest : public QuicTest { |
| 14 | public: |
| 15 | QuicMemSliceStorageImplTest() = default; |
| 16 | }; |
| 17 | |
| 18 | TEST_F(QuicMemSliceStorageImplTest, EmptyIov) { |
| 19 | QuicMemSliceStorage storage(nullptr, 0, nullptr, 1024); |
| 20 | EXPECT_TRUE(storage.ToSpan().empty()); |
| 21 | } |
| 22 | |
| 23 | TEST_F(QuicMemSliceStorageImplTest, SingleIov) { |
| 24 | SimpleBufferAllocator allocator; |
| 25 | QuicString body(3, 'c'); |
| 26 | struct iovec iov = {const_cast<char*>(body.data()), body.length()}; |
| 27 | QuicMemSliceStorage storage(&iov, 1, &allocator, 1024); |
| 28 | auto span = storage.ToSpan(); |
| 29 | EXPECT_EQ("ccc", span.GetData(0)); |
| 30 | EXPECT_NE(static_cast<const void*>(span.GetData(0).data()), body.data()); |
| 31 | } |
| 32 | |
| 33 | TEST_F(QuicMemSliceStorageImplTest, MultipleIovInSingleSlice) { |
| 34 | SimpleBufferAllocator allocator; |
| 35 | QuicString body1(3, 'a'); |
| 36 | QuicString body2(4, 'b'); |
| 37 | struct iovec iov[] = {{const_cast<char*>(body1.data()), body1.length()}, |
| 38 | {const_cast<char*>(body2.data()), body2.length()}}; |
| 39 | |
| 40 | QuicMemSliceStorage storage(iov, 2, &allocator, 1024); |
| 41 | auto span = storage.ToSpan(); |
| 42 | EXPECT_EQ("aaabbbb", span.GetData(0)); |
| 43 | } |
| 44 | |
| 45 | TEST_F(QuicMemSliceStorageImplTest, MultipleIovInMultipleSlice) { |
| 46 | SimpleBufferAllocator allocator; |
| 47 | QuicString body1(4, 'a'); |
| 48 | QuicString body2(4, 'b'); |
| 49 | struct iovec iov[] = {{const_cast<char*>(body1.data()), body1.length()}, |
| 50 | {const_cast<char*>(body2.data()), body2.length()}}; |
| 51 | |
| 52 | QuicMemSliceStorage storage(iov, 2, &allocator, 4); |
| 53 | auto span = storage.ToSpan(); |
| 54 | EXPECT_EQ("aaaa", span.GetData(0)); |
| 55 | EXPECT_EQ("bbbb", span.GetData(1)); |
| 56 | } |
| 57 | |
| 58 | } // namespace |
| 59 | } // namespace test |
| 60 | } // namespace quic |