| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/http2/hpack/huffman/http2_hpack_huffman_decoder.h" | 5 #include "net/http2/hpack/huffman/http2_hpack_huffman_decoder.h" |
| 6 | 6 |
| 7 // Tests of HpackHuffmanDecoder and HuffmanBitBuffer. | 7 // Tests of HpackHuffmanDecoder and HuffmanBitBuffer. |
| 8 | 8 |
| 9 #include <iostream> | 9 #include <iostream> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/bind.h" | |
| 13 #include "base/bind_helpers.h" | |
| 14 #include "base/macros.h" | 12 #include "base/macros.h" |
| 15 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 16 #include "net/http2/decoder/decode_buffer.h" | 14 #include "net/http2/decoder/decode_buffer.h" |
| 17 #include "net/http2/decoder/decode_status.h" | 15 #include "net/http2/decoder/decode_status.h" |
| 18 #include "net/http2/tools/failure.h" | 16 #include "net/http2/tools/failure.h" |
| 19 #include "net/http2/tools/random_decoder_test.h" | 17 #include "net/http2/tools/random_decoder_test.h" |
| 20 #include "net/spdy/spdy_test_utils.h" | 18 #include "net/spdy/spdy_test_utils.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 20 |
| 23 using ::testing::AssertionResult; | 21 using ::testing::AssertionResult; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 case DecoderChoice::IF_TREE: | 193 case DecoderChoice::IF_TREE: |
| 196 return decoder_.DecodeWithIfTreeAndStruct(sp, &output_buffer_); | 194 return decoder_.DecodeWithIfTreeAndStruct(sp, &output_buffer_); |
| 197 case DecoderChoice::SHORT_CODE: | 195 case DecoderChoice::SHORT_CODE: |
| 198 return decoder_.DecodeShortCodesFirst(sp, &output_buffer_); | 196 return decoder_.DecodeShortCodesFirst(sp, &output_buffer_); |
| 199 } | 197 } |
| 200 | 198 |
| 201 NOTREACHED(); | 199 NOTREACHED(); |
| 202 return false; | 200 return false; |
| 203 } | 201 } |
| 204 | 202 |
| 205 AssertionResult ValidatorForHuffmanDecodeAndValidateSeveralWays( | |
| 206 StringPiece expected_plain) { | |
| 207 VERIFY_EQ(output_buffer_.size(), expected_plain.size()); | |
| 208 VERIFY_EQ(output_buffer_, expected_plain); | |
| 209 return AssertionSuccess(); | |
| 210 } | |
| 211 | |
| 212 AssertionResult HuffmanDecodeAndValidateSeveralWays( | 203 AssertionResult HuffmanDecodeAndValidateSeveralWays( |
| 213 StringPiece encoded, | 204 StringPiece encoded, |
| 214 StringPiece expected_plain) { | 205 StringPiece expected_plain) { |
| 215 input_bytes_expected_ = encoded.size(); | 206 input_bytes_expected_ = encoded.size(); |
| 207 NoArgValidator validator = [expected_plain, this]() -> AssertionResult { |
| 208 VERIFY_EQ(output_buffer_.size(), expected_plain.size()); |
| 209 VERIFY_EQ(output_buffer_, expected_plain); |
| 210 return AssertionSuccess(); |
| 211 }; |
| 216 DecodeBuffer db(encoded); | 212 DecodeBuffer db(encoded); |
| 217 bool return_non_zero_on_first = false; | 213 bool return_non_zero_on_first = false; |
| 218 return DecodeAndValidateSeveralWays( | 214 return DecodeAndValidateSeveralWays(&db, return_non_zero_on_first, |
| 219 &db, return_non_zero_on_first, | 215 ValidateDoneAndEmpty(validator)); |
| 220 ValidateDoneAndEmpty( | |
| 221 base::Bind(&HpackHuffmanDecoderTest:: | |
| 222 ValidatorForHuffmanDecodeAndValidateSeveralWays, | |
| 223 base::Unretained(this), expected_plain))); | |
| 224 } | 216 } |
| 225 | 217 |
| 226 HpackHuffmanDecoder decoder_; | 218 HpackHuffmanDecoder decoder_; |
| 227 string output_buffer_; | 219 string output_buffer_; |
| 228 size_t input_bytes_seen_; | 220 size_t input_bytes_seen_; |
| 229 size_t input_bytes_expected_; | 221 size_t input_bytes_expected_; |
| 230 }; | 222 }; |
| 231 INSTANTIATE_TEST_CASE_P(AllDecoders, | 223 INSTANTIATE_TEST_CASE_P(AllDecoders, |
| 232 HpackHuffmanDecoderTest, | 224 HpackHuffmanDecoderTest, |
| 233 ::testing::Values(DecoderChoice::IF_TREE, | 225 ::testing::Values(DecoderChoice::IF_TREE, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 decoder.Reset(); | 275 decoder.Reset(); |
| 284 EXPECT_TRUE(decoder.Decode(huffman_encoded, &buffer)) << decoder; | 276 EXPECT_TRUE(decoder.Decode(huffman_encoded, &buffer)) << decoder; |
| 285 EXPECT_TRUE(decoder.InputProperlyTerminated()) << decoder; | 277 EXPECT_TRUE(decoder.InputProperlyTerminated()) << decoder; |
| 286 EXPECT_EQ(buffer, plain_string); | 278 EXPECT_EQ(buffer, plain_string); |
| 287 } | 279 } |
| 288 } | 280 } |
| 289 | 281 |
| 290 } // namespace | 282 } // namespace |
| 291 } // namespace test | 283 } // namespace test |
| 292 } // namespace net | 284 } // namespace net |
| OLD | NEW |