| OLD | NEW | 
|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 #include "net/spdy/core/array_output_buffer.h" | 5 #include "net/spdy/core/array_output_buffer.h" | 
| 6 | 6 | 
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" | 
| 8 | 8 | 
| 9 namespace net { | 9 namespace net { | 
| 10 namespace test { | 10 namespace test { | 
| 11 | 11 | 
| 12 // This test verifies that ArrayOutputBuffer is initialized properly. | 12 // This test verifies that ArrayOutputBuffer is initialized properly. | 
| 13 TEST(ArrayOutputBufferTest, InitializedFromArray) { | 13 TEST(ArrayOutputBufferTest, InitializedFromArray) { | 
| 14   char array[100]; | 14   char array[100]; | 
| 15   ArrayOutputBuffer buffer(array, sizeof(array)); | 15   ArrayOutputBuffer buffer(array, sizeof(array)); | 
| 16   EXPECT_EQ(sizeof(array), buffer.BytesFree()); | 16   EXPECT_EQ(sizeof(array), buffer.BytesFree()); | 
| 17   EXPECT_EQ((uint64_t)0, buffer.Size()); | 17   EXPECT_EQ(0u, buffer.Size()); | 
| 18   EXPECT_EQ(array, buffer.Begin()); | 18   EXPECT_EQ(array, buffer.Begin()); | 
| 19 } | 19 } | 
| 20 | 20 | 
| 21 // This test verifies that Reset() causes an ArrayOutputBuffer's capacity and | 21 // This test verifies that Reset() causes an ArrayOutputBuffer's capacity and | 
| 22 // size to be reset to the initial state. | 22 // size to be reset to the initial state. | 
| 23 TEST(ArrayOutputBufferTest, WriteAndReset) { | 23 TEST(ArrayOutputBufferTest, WriteAndReset) { | 
| 24   char array[100]; | 24   char array[100]; | 
| 25   ArrayOutputBuffer buffer(array, sizeof(array)); | 25   ArrayOutputBuffer buffer(array, sizeof(array)); | 
| 26 | 26 | 
| 27   // Let's write some bytes. | 27   // Let's write some bytes. | 
| 28   char* dst; | 28   char* dst; | 
| 29   int size; | 29   int size; | 
| 30   buffer.Next(&dst, &size); | 30   buffer.Next(&dst, &size); | 
| 31   ASSERT_GT(size, 1); | 31   ASSERT_GT(size, 1); | 
| 32   ASSERT_NE(nullptr, dst); | 32   ASSERT_NE(nullptr, dst); | 
| 33   const int64_t written = size / 2; | 33   const int64_t written = size / 2; | 
| 34   memset(dst, 'x', written); | 34   memset(dst, 'x', written); | 
| 35   buffer.AdvanceWritePtr(written); | 35   buffer.AdvanceWritePtr(written); | 
| 36 | 36 | 
| 37   // The buffer should be partially used. | 37   // The buffer should be partially used. | 
| 38   EXPECT_EQ((uint64_t)size - written, buffer.BytesFree()); | 38   EXPECT_EQ(static_cast<uint64_t>(size) - written, buffer.BytesFree()); | 
| 39   EXPECT_EQ((uint64_t)written, buffer.Size()); | 39   EXPECT_EQ(static_cast<uint64_t>(written), buffer.Size()); | 
| 40 | 40 | 
| 41   buffer.Reset(); | 41   buffer.Reset(); | 
| 42 | 42 | 
| 43   // After a reset, the buffer should regain its full capacity. | 43   // After a reset, the buffer should regain its full capacity. | 
| 44   EXPECT_EQ(sizeof(array), buffer.BytesFree()); | 44   EXPECT_EQ(sizeof(array), buffer.BytesFree()); | 
| 45   EXPECT_EQ((uint64_t)0, buffer.Size()); | 45   EXPECT_EQ(0u, buffer.Size()); | 
| 46 } | 46 } | 
| 47 | 47 | 
| 48 }  // namespace test | 48 }  // namespace test | 
| 49 }  // namespace net | 49 }  // namespace net | 
| OLD | NEW | 
|---|