| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/test_data_stream.h" | 5 #include "net/base/test_data_stream.h" | 
| 6 | 6 | 
| 7 namespace net { | 7 namespace net { | 
| 8 | 8 | 
| 9 TestDataStream::TestDataStream() { | 9 TestDataStream::TestDataStream() { | 
| 10   Reset(); | 10   Reset(); | 
| 11 } | 11 } | 
| 12 | 12 | 
| 13 // Fill |buffer| with |length| bytes of data from the stream. | 13 // Fill |buffer| with |length| bytes of data from the stream. | 
| 14 void TestDataStream::GetBytes(char* buffer, int length) { | 14 void TestDataStream::GetBytes(char* buffer, int length) { | 
| 15   while (length) { | 15   while (length) { | 
| 16     AdvanceIndex(); | 16     AdvanceIndex(); | 
| 17     int bytes_to_copy = std::min(length, bytes_remaining_); | 17     int bytes_to_copy = std::min(length, bytes_remaining_); | 
| 18     memcpy(buffer, buffer_ptr_, bytes_to_copy); | 18     memcpy(buffer, buffer_ptr_, bytes_to_copy); | 
| 19     buffer += bytes_to_copy; | 19     buffer += bytes_to_copy; | 
| 20     Consume(bytes_to_copy); | 20     Consume(bytes_to_copy); | 
| 21     length -= bytes_to_copy; | 21     length -= bytes_to_copy; | 
| 22   } | 22   } | 
| 23 } | 23 } | 
| 24 | 24 | 
| 25 bool TestDataStream::VerifyBytes(const char *buffer, int length) { | 25 bool TestDataStream::VerifyBytes(const char* buffer, int length) { | 
| 26   while (length) { | 26   while (length) { | 
| 27     AdvanceIndex(); | 27     AdvanceIndex(); | 
| 28     int bytes_to_compare = std::min(length, bytes_remaining_); | 28     int bytes_to_compare = std::min(length, bytes_remaining_); | 
| 29     if (memcmp(buffer, buffer_ptr_, bytes_to_compare)) | 29     if (memcmp(buffer, buffer_ptr_, bytes_to_compare)) | 
| 30       return false; | 30       return false; | 
| 31     Consume(bytes_to_compare); | 31     Consume(bytes_to_compare); | 
| 32     length -= bytes_to_compare; | 32     length -= bytes_to_compare; | 
| 33     buffer += bytes_to_compare; | 33     buffer += bytes_to_compare; | 
| 34   } | 34   } | 
| 35   return true; | 35   return true; | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 58 // Consume data from the spill buffer. | 58 // Consume data from the spill buffer. | 
| 59 void TestDataStream::Consume(int bytes) { | 59 void TestDataStream::Consume(int bytes) { | 
| 60   bytes_remaining_ -= bytes; | 60   bytes_remaining_ -= bytes; | 
| 61   if (bytes_remaining_) | 61   if (bytes_remaining_) | 
| 62     buffer_ptr_ += bytes; | 62     buffer_ptr_ += bytes; | 
| 63   else | 63   else | 
| 64     buffer_ptr_ = buffer_; | 64     buffer_ptr_ = buffer_; | 
| 65 } | 65 } | 
| 66 | 66 | 
| 67 }  // namespace net | 67 }  // namespace net | 
| 68 |  | 
| OLD | NEW | 
|---|