OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <limits.h> | 5 #include <limits.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 CHECK(input_block_length > 0); | 94 CHECK(input_block_length > 0); |
95 Filter::FilterStatus status(Filter::FILTER_NEED_MORE_DATA); | 95 Filter::FilterStatus status(Filter::FILTER_NEED_MORE_DATA); |
96 size_t source_index = 0; | 96 size_t source_index = 0; |
97 scoped_array<char> output_buffer(new char[output_buffer_length]); | 97 scoped_array<char> output_buffer(new char[output_buffer_length]); |
98 size_t input_amount = std::min(input_block_length, | 98 size_t input_amount = std::min(input_block_length, |
99 static_cast<size_t>(filter->stream_buffer_size())); | 99 static_cast<size_t>(filter->stream_buffer_size())); |
100 | 100 |
101 do { | 101 do { |
102 int copy_amount = std::min(input_amount, source.size() - source_index); | 102 int copy_amount = std::min(input_amount, source.size() - source_index); |
103 if (copy_amount > 0 && status == Filter::FILTER_NEED_MORE_DATA) { | 103 if (copy_amount > 0 && status == Filter::FILTER_NEED_MORE_DATA) { |
104 memcpy(filter->stream_buffer(), source.data() + source_index, | 104 memcpy(filter->stream_buffer()->data(), source.data() + source_index, |
105 copy_amount); | 105 copy_amount); |
106 filter->FlushStreamBuffer(copy_amount); | 106 filter->FlushStreamBuffer(copy_amount); |
107 source_index += copy_amount; | 107 source_index += copy_amount; |
108 } | 108 } |
109 int buffer_length = output_buffer_length; | 109 int buffer_length = output_buffer_length; |
110 status = filter->ReadData(output_buffer.get(), &buffer_length); | 110 status = filter->ReadData(output_buffer.get(), &buffer_length); |
111 output->append(output_buffer.get(), buffer_length); | 111 output->append(output_buffer.get(), buffer_length); |
112 if (status == Filter::FILTER_ERROR) | 112 if (status == Filter::FILTER_ERROR) |
113 return false; | 113 return false; |
114 if (copy_amount == 0 && buffer_length == 0) | 114 if (copy_amount == 0 && buffer_length == 0) |
(...skipping 30 matching lines...) Expand all Loading... |
145 Filter::FilterStatus status = filter->ReadData(output_buffer, | 145 Filter::FilterStatus status = filter->ReadData(output_buffer, |
146 &output_bytes_or_buffer_size); | 146 &output_bytes_or_buffer_size); |
147 | 147 |
148 EXPECT_EQ(0, output_bytes_or_buffer_size); | 148 EXPECT_EQ(0, output_bytes_or_buffer_size); |
149 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); | 149 EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status); |
150 | 150 |
151 // Supply bogus data (which doesnt't yet specify a full dictionary hash). | 151 // Supply bogus data (which doesnt't yet specify a full dictionary hash). |
152 // Dictionary hash is 8 characters followed by a null. | 152 // Dictionary hash is 8 characters followed by a null. |
153 std::string dictionary_hash_prefix("123"); | 153 std::string dictionary_hash_prefix("123"); |
154 | 154 |
155 char* input_buffer = filter->stream_buffer(); | 155 char* input_buffer = filter->stream_buffer()->data(); |
156 int input_buffer_size = filter->stream_buffer_size(); | 156 int input_buffer_size = filter->stream_buffer_size(); |
157 EXPECT_EQ(kInputBufferSize, input_buffer_size); | 157 EXPECT_EQ(kInputBufferSize, input_buffer_size); |
158 | 158 |
159 EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()), | 159 EXPECT_LT(static_cast<int>(dictionary_hash_prefix.size()), |
160 input_buffer_size); | 160 input_buffer_size); |
161 memcpy(input_buffer, dictionary_hash_prefix.data(), | 161 memcpy(input_buffer, dictionary_hash_prefix.data(), |
162 dictionary_hash_prefix.size()); | 162 dictionary_hash_prefix.size()); |
163 filter->FlushStreamBuffer(dictionary_hash_prefix.size()); | 163 filter->FlushStreamBuffer(dictionary_hash_prefix.size()); |
164 | 164 |
165 // With less than a dictionary specifier, try to read output. | 165 // With less than a dictionary specifier, try to read output. |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 TEST_F(SdchFilterTest, DictionaryTooLarge) { | 897 TEST_F(SdchFilterTest, DictionaryTooLarge) { |
898 std::string dictionary_domain(".google.com"); | 898 std::string dictionary_domain(".google.com"); |
899 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 899 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
900 | 900 |
901 dictionary_text.append( | 901 dictionary_text.append( |
902 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' '); | 902 SdchManager::kMaxDictionarySize + 1 - dictionary_text.size(), ' '); |
903 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, | 903 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, |
904 GURL("http://" + dictionary_domain))); | 904 GURL("http://" + dictionary_domain))); |
905 } | 905 } |
906 | 906 |
OLD | NEW |