Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(671)

Side by Side Diff: net/spdy/fuzzing/hpack_fuzz_util_test.cc

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/fuzzing/hpack_fuzz_util.cc ('k') | net/spdy/header_coalescer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/spdy/fuzzing/hpack_fuzz_util.h" 5 #include "net/spdy/fuzzing/hpack_fuzz_util.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "net/spdy/spdy_test_utils.h" 13 #include "net/spdy/spdy_test_utils.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace net { 17 namespace net {
18 namespace test { 18 namespace test {
19 19
20 using std::map; 20 using std::map;
21 using std::string;
22 using test::a2b_hex; 21 using test::a2b_hex;
23 22
24 TEST(HpackFuzzUtilTest, GeneratorContextInitialization) { 23 TEST(HpackFuzzUtilTest, GeneratorContextInitialization) {
25 HpackFuzzUtil::GeneratorContext context; 24 HpackFuzzUtil::GeneratorContext context;
26 HpackFuzzUtil::InitializeGeneratorContext(&context); 25 HpackFuzzUtil::InitializeGeneratorContext(&context);
27 26
28 // Context was seeded with initial name & value fixtures. 27 // Context was seeded with initial name & value fixtures.
29 EXPECT_LT(0u, context.names.size()); 28 EXPECT_LT(0u, context.names.size());
30 EXPECT_LT(0u, context.values.size()); 29 EXPECT_LT(0u, context.values.size());
31 } 30 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block)); 77 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
79 EXPECT_EQ("e", block); 78 EXPECT_EQ("e", block);
80 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block)); 79 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
81 EXPECT_EQ("", block); 80 EXPECT_EQ("", block);
82 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block)); 81 EXPECT_TRUE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
83 EXPECT_EQ("fin", block); 82 EXPECT_EQ("fin", block);
84 EXPECT_FALSE(HpackFuzzUtil::NextHeaderBlock(&input, &block)); 83 EXPECT_FALSE(HpackFuzzUtil::NextHeaderBlock(&input, &block));
85 } 84 }
86 85
87 TEST(HpackFuzzUtilTest, SerializedHeaderBlockPrefixes) { 86 TEST(HpackFuzzUtilTest, SerializedHeaderBlockPrefixes) {
88 EXPECT_EQ(string("\x00\x00\x00\x00", 4), HpackFuzzUtil::HeaderBlockPrefix(0)); 87 EXPECT_EQ(SpdyString("\x00\x00\x00\x00", 4),
89 EXPECT_EQ(string("\x00\x00\x00\x05", 4), HpackFuzzUtil::HeaderBlockPrefix(5)); 88 HpackFuzzUtil::HeaderBlockPrefix(0));
89 EXPECT_EQ(SpdyString("\x00\x00\x00\x05", 4),
90 HpackFuzzUtil::HeaderBlockPrefix(5));
90 EXPECT_EQ("\x4f\xb3\x0a\x91", HpackFuzzUtil::HeaderBlockPrefix(1337133713)); 91 EXPECT_EQ("\x4f\xb3\x0a\x91", HpackFuzzUtil::HeaderBlockPrefix(1337133713));
91 } 92 }
92 93
93 TEST(HpackFuzzUtilTest, PassValidInputThroughAllStages) { 94 TEST(HpackFuzzUtilTest, PassValidInputThroughAllStages) {
94 // Example lifted from HpackDecoderTest.SectionD4RequestHuffmanExamples. 95 // Example lifted from HpackDecoderTest.SectionD4RequestHuffmanExamples.
95 string input = a2b_hex("828684418cf1e3c2e5f23a6ba0ab90f4" 96 SpdyString input = a2b_hex("828684418cf1e3c2e5f23a6ba0ab90f4ff");
96 "ff");
97 97
98 HpackFuzzUtil::FuzzerContext context; 98 HpackFuzzUtil::FuzzerContext context;
99 HpackFuzzUtil::InitializeFuzzerContext(&context); 99 HpackFuzzUtil::InitializeFuzzerContext(&context);
100 100
101 EXPECT_TRUE( 101 EXPECT_TRUE(
102 HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(&context, input)); 102 HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(&context, input));
103 103
104 SpdyHeaderBlock expect; 104 SpdyHeaderBlock expect;
105 expect[":method"] = "GET"; 105 expect[":method"] = "GET";
106 expect[":scheme"] = "http"; 106 expect[":scheme"] = "http";
(...skipping 21 matching lines...) Expand all
128 SpdyStringPiece block; 128 SpdyStringPiece block;
129 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) { 129 while (HpackFuzzUtil::NextHeaderBlock(&input, &block)) {
130 // As these are valid examples, all fuzz stages should succeed. 130 // As these are valid examples, all fuzz stages should succeed.
131 EXPECT_TRUE(HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages( 131 EXPECT_TRUE(HpackFuzzUtil::RunHeaderBlockThroughFuzzerStages(
132 &context, block)); 132 &context, block));
133 } 133 }
134 } 134 }
135 135
136 TEST(HpackFuzzUtilTest, FlipBitsMutatesBuffer) { 136 TEST(HpackFuzzUtilTest, FlipBitsMutatesBuffer) {
137 char buffer[] = "testbuffer1234567890"; 137 char buffer[] = "testbuffer1234567890";
138 string unmodified(buffer, arraysize(buffer) - 1); 138 SpdyString unmodified(buffer, arraysize(buffer) - 1);
139 139
140 EXPECT_EQ(unmodified, buffer); 140 EXPECT_EQ(unmodified, buffer);
141 HpackFuzzUtil::FlipBits(reinterpret_cast<uint8_t*>(buffer), 141 HpackFuzzUtil::FlipBits(reinterpret_cast<uint8_t*>(buffer),
142 arraysize(buffer) - 1, 1); 142 arraysize(buffer) - 1, 1);
143 EXPECT_NE(unmodified, buffer); 143 EXPECT_NE(unmodified, buffer);
144 } 144 }
145 145
146 } // namespace test 146 } // namespace test
147 } // namespace net 147 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/fuzzing/hpack_fuzz_util.cc ('k') | net/spdy/header_coalescer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698