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 "net/http/http_chunked_decoder.h" | 5 #include "net/http/http_chunked_decoder.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/test/gtest_util.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
| 14 using net::test::IsError; |
| 15 using net::test::IsOk; |
| 16 |
12 namespace net { | 17 namespace net { |
13 | 18 |
14 namespace { | 19 namespace { |
15 | 20 |
16 typedef testing::Test HttpChunkedDecoderTest; | 21 typedef testing::Test HttpChunkedDecoderTest; |
17 | 22 |
18 void RunTest(const char* const inputs[], | 23 void RunTest(const char* const inputs[], |
19 size_t num_inputs, | 24 size_t num_inputs, |
20 const char* expected_output, | 25 const char* expected_output, |
21 bool expected_eof, | 26 bool expected_eof, |
(...skipping 20 matching lines...) Expand all Loading... |
42 void RunTestUntilFailure(const char* const inputs[], | 47 void RunTestUntilFailure(const char* const inputs[], |
43 size_t num_inputs, | 48 size_t num_inputs, |
44 size_t fail_index) { | 49 size_t fail_index) { |
45 HttpChunkedDecoder decoder; | 50 HttpChunkedDecoder decoder; |
46 EXPECT_FALSE(decoder.reached_eof()); | 51 EXPECT_FALSE(decoder.reached_eof()); |
47 | 52 |
48 for (size_t i = 0; i < num_inputs; ++i) { | 53 for (size_t i = 0; i < num_inputs; ++i) { |
49 std::string input = inputs[i]; | 54 std::string input = inputs[i]; |
50 int n = decoder.FilterBuf(&input[0], static_cast<int>(input.size())); | 55 int n = decoder.FilterBuf(&input[0], static_cast<int>(input.size())); |
51 if (n < 0) { | 56 if (n < 0) { |
52 EXPECT_EQ(ERR_INVALID_CHUNKED_ENCODING, n); | 57 EXPECT_THAT(n, IsError(ERR_INVALID_CHUNKED_ENCODING)); |
53 EXPECT_EQ(fail_index, i); | 58 EXPECT_EQ(fail_index, i); |
54 return; | 59 return; |
55 } | 60 } |
56 } | 61 } |
57 FAIL(); // We should have failed on the |fail_index| iteration of the loop. | 62 FAIL(); // We should have failed on the |fail_index| iteration of the loop. |
58 } | 63 } |
59 | 64 |
60 TEST(HttpChunkedDecoderTest, Basic) { | 65 TEST(HttpChunkedDecoderTest, Basic) { |
61 const char* const inputs[] = { | 66 const char* const inputs[] = { |
62 "B\r\nhello hello\r\n0\r\n\r\n" | 67 "B\r\nhello hello\r\n0\r\n\r\n" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 const char* const inputs[] = { | 353 const char* const inputs[] = { |
349 "5;", | 354 "5;", |
350 big_chunk.get() | 355 big_chunk.get() |
351 }; | 356 }; |
352 RunTestUntilFailure(inputs, arraysize(inputs), 1); | 357 RunTestUntilFailure(inputs, arraysize(inputs), 1); |
353 } | 358 } |
354 | 359 |
355 } // namespace | 360 } // namespace |
356 | 361 |
357 } // namespace net | 362 } // namespace net |
OLD | NEW |