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/tools/random_decoder_test.h" | 5 #include "net/http2/tools/random_decoder_test.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 { | 95 { |
96 // Fast decode (no stopping unless decoder does so). | 96 // Fast decode (no stopping unless decoder does so). |
97 DecodeBuffer input(original->cursor(), original_remaining); | 97 DecodeBuffer input(original->cursor(), original_remaining); |
98 VLOG(2) << "DecodeSegmentsAndValidate with SelectRemaining"; | 98 VLOG(2) << "DecodeSegmentsAndValidate with SelectRemaining"; |
99 VERIFY_SUCCESS( | 99 VERIFY_SUCCESS( |
100 DecodeSegmentsAndValidate(&input, SelectRemaining(), validator)) | 100 DecodeSegmentsAndValidate(&input, SelectRemaining(), validator)) |
101 << "\nFailed with SelectRemaining; input.Offset=" << input.Offset() | 101 << "\nFailed with SelectRemaining; input.Offset=" << input.Offset() |
102 << "; input.Remaining=" << input.Remaining(); | 102 << "; input.Remaining=" << input.Remaining(); |
103 first_consumed = input.Offset(); | 103 first_consumed = input.Offset(); |
104 } | 104 } |
105 if (original_remaining <= 30) { | 105 if (original_remaining <= 30) { |
James Synge
2017/01/05 21:39:06
Given the replacement of the test-only flag with t
Bence
2017/01/06 01:42:40
That sound like a good idea. I'll do that once al
| |
106 // Decode again, one byte at a time. | 106 // Decode again, one byte at a time. |
107 DecodeBuffer input(original->cursor(), original_remaining); | 107 DecodeBuffer input(original->cursor(), original_remaining); |
108 VLOG(2) << "DecodeSegmentsAndValidate with SelectOne"; | 108 VLOG(2) << "DecodeSegmentsAndValidate with SelectOne"; |
109 VERIFY_SUCCESS(DecodeSegmentsAndValidate(&input, SelectOne(), validator)) | 109 VERIFY_SUCCESS(DecodeSegmentsAndValidate(&input, SelectOne(), validator)) |
110 << "\nFailed with SelectOne; input.Offset=" << input.Offset() | 110 << "\nFailed with SelectOne; input.Offset=" << input.Offset() |
111 << "; input.Remaining=" << input.Remaining(); | 111 << "; input.Remaining=" << input.Remaining(); |
112 VERIFY_EQ(first_consumed, input.Offset()) << "\nFailed with SelectOne"; | 112 VERIFY_EQ(first_consumed, input.Offset()) << "\nFailed with SelectOne"; |
113 } | 113 } |
114 if (original_remaining <= 20) { | 114 if (original_remaining <= 20) { |
115 // Decode again, one or zero bytes at a time. | 115 // Decode again, one or zero bytes at a time. |
116 DecodeBuffer input(original->cursor(), original_remaining); | 116 DecodeBuffer input(original->cursor(), original_remaining); |
117 VLOG(2) << "DecodeSegmentsAndValidate with SelectZeroAndOne"; | 117 VLOG(2) << "DecodeSegmentsAndValidate with SelectZeroAndOne"; |
118 VERIFY_SUCCESS(DecodeSegmentsAndValidate( | 118 VERIFY_SUCCESS(DecodeSegmentsAndValidate( |
119 &input, SelectZeroAndOne(return_non_zero_on_first), validator)) | 119 &input, SelectZeroAndOne(return_non_zero_on_first), validator)) |
120 << "\nFailed with SelectZeroAndOne"; | 120 << "\nFailed with SelectZeroAndOne"; |
121 VERIFY_EQ(first_consumed, input.Offset()) | 121 VERIFY_EQ(first_consumed, input.Offset()) |
122 << "\nFailed with SelectZeroAndOne; input.Offset=" << input.Offset() | 122 << "\nFailed with SelectZeroAndOne; input.Offset=" << input.Offset() |
123 << "; input.Remaining=" << input.Remaining(); | 123 << "; input.Remaining=" << input.Remaining(); |
124 } | 124 } |
125 { | 125 { |
126 // Decode again, with randomly selected segment sizes. | 126 // Decode again, with randomly selected segment sizes. |
127 DecodeBuffer input(original->cursor(), original_remaining); | 127 DecodeBuffer input(original->cursor(), original_remaining); |
128 VLOG(2) << "DecodeSegmentsAndValidate with SelectRandom"; | 128 VLOG(2) << "DecodeSegmentsAndValidate with SelectRandom"; |
129 VERIFY_SUCCESS(DecodeSegmentsAndValidate( | 129 VERIFY_SUCCESS(DecodeSegmentsAndValidate( |
130 &input, RandomDecoderTest::SelectRandom(return_non_zero_on_first), | 130 &input, SelectRandom(return_non_zero_on_first), validator)) |
131 validator)) | |
132 << "\nFailed with SelectRandom; input.Offset=" << input.Offset() | 131 << "\nFailed with SelectRandom; input.Offset=" << input.Offset() |
133 << "; input.Remaining=" << input.Remaining(); | 132 << "; input.Remaining=" << input.Remaining(); |
134 VERIFY_EQ(first_consumed, input.Offset()) << "\nFailed with SelectRandom"; | 133 VERIFY_EQ(first_consumed, input.Offset()) << "\nFailed with SelectRandom"; |
135 } | 134 } |
136 VERIFY_EQ(original_remaining, original->Remaining()); | 135 VERIFY_EQ(original_remaining, original->Remaining()); |
137 original->AdvanceCursor(first_consumed); | 136 original->AdvanceCursor(first_consumed); |
138 VLOG(1) << "DecodeAndValidateSeveralWays - SUCCESS"; | 137 VLOG(1) << "DecodeAndValidateSeveralWays - SUCCESS"; |
139 return ::testing::AssertionSuccess(); | 138 return ::testing::AssertionSuccess(); |
140 } | 139 } |
141 | 140 |
(...skipping 28 matching lines...) Expand all Loading... | |
170 return r % (remaining + 1); // size in range [0, remaining]. | 169 return r % (remaining + 1); // size in range [0, remaining]. |
171 }; | 170 }; |
172 } | 171 } |
173 | 172 |
174 uint32_t RandomDecoderTest::RandStreamId() { | 173 uint32_t RandomDecoderTest::RandStreamId() { |
175 return random_.Rand32() & StreamIdMask(); | 174 return random_.Rand32() & StreamIdMask(); |
176 } | 175 } |
177 | 176 |
178 } // namespace test | 177 } // namespace test |
179 } // namespace net | 178 } // namespace net |
OLD | NEW |