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

Side by Side Diff: util/net/http_body_test.cc

Issue 992503002: Locate test data more robustly (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: 2015 Created 5 years, 9 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 | « build/run_tests.py ('k') | util/net/http_multipart_builder_test.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 Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/net/http_body.h" 15 #include "util/net/http_body.h"
16 16
17 #include "gtest/gtest.h" 17 #include "gtest/gtest.h"
18 #include "util/net/http_body_test_util.h" 18 #include "util/net/http_body_test_util.h"
19 #include "util/test/paths.h"
19 20
20 namespace crashpad { 21 namespace crashpad {
21 namespace test { 22 namespace test {
22 namespace { 23 namespace {
23 24
24 void ExpectBufferSet(const uint8_t* actual, 25 void ExpectBufferSet(const uint8_t* actual,
25 uint8_t expected_byte, 26 uint8_t expected_byte,
26 size_t num_expected_bytes) { 27 size_t num_expected_bytes) {
27 for (size_t i = 0; i < num_expected_bytes; ++i) { 28 for (size_t i = 0; i < num_expected_bytes; ++i) {
28 EXPECT_EQ(expected_byte, actual[i]) << i; 29 EXPECT_EQ(expected_byte, actual[i]) << i;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 EXPECT_EQ(1, stream.GetBytesBuffer(buf, sizeof(buf))); 87 EXPECT_EQ(1, stream.GetBytesBuffer(buf, sizeof(buf)));
87 EXPECT_EQ('c', buf[0]); 88 EXPECT_EQ('c', buf[0]);
88 EXPECT_EQ('b', buf[1]); // Unmodified from last read. 89 EXPECT_EQ('b', buf[1]); // Unmodified from last read.
89 EXPECT_EQ(0, stream.GetBytesBuffer(buf, sizeof(buf))); 90 EXPECT_EQ(0, stream.GetBytesBuffer(buf, sizeof(buf)));
90 EXPECT_EQ('c', buf[0]); 91 EXPECT_EQ('c', buf[0]);
91 EXPECT_EQ('b', buf[1]); 92 EXPECT_EQ('b', buf[1]);
92 } 93 }
93 } 94 }
94 95
95 TEST(FileHTTPBodyStream, ReadASCIIFile) { 96 TEST(FileHTTPBodyStream, ReadASCIIFile) {
96 // TODO(rsesek): Use a more robust mechanism to locate testdata 97 base::FilePath path = Paths::TestDataRoot().Append(
97 // <https://code.google.com/p/crashpad/issues/detail?id=4>.
98 base::FilePath path = base::FilePath(
99 FILE_PATH_LITERAL("util/net/testdata/ascii_http_body.txt")); 98 FILE_PATH_LITERAL("util/net/testdata/ascii_http_body.txt"));
100 FileHTTPBodyStream stream(path); 99 FileHTTPBodyStream stream(path);
101 std::string contents = ReadStreamToString(&stream, 32); 100 std::string contents = ReadStreamToString(&stream, 32);
102 EXPECT_EQ("This is a test.\n", contents); 101 EXPECT_EQ("This is a test.\n", contents);
103 102
104 // Make sure that the file is not read again after it has been read to 103 // Make sure that the file is not read again after it has been read to
105 // completion. 104 // completion.
106 uint8_t buf[8]; 105 uint8_t buf[8];
107 memset(buf, '!', sizeof(buf)); 106 memset(buf, '!', sizeof(buf));
108 EXPECT_EQ(0, stream.GetBytesBuffer(buf, sizeof(buf))); 107 EXPECT_EQ(0, stream.GetBytesBuffer(buf, sizeof(buf)));
109 ExpectBufferSet(buf, '!', sizeof(buf)); 108 ExpectBufferSet(buf, '!', sizeof(buf));
110 EXPECT_EQ(0, stream.GetBytesBuffer(buf, sizeof(buf))); 109 EXPECT_EQ(0, stream.GetBytesBuffer(buf, sizeof(buf)));
111 ExpectBufferSet(buf, '!', sizeof(buf)); 110 ExpectBufferSet(buf, '!', sizeof(buf));
112 } 111 }
113 112
114 TEST(FileHTTPBodyStream, ReadBinaryFile) { 113 TEST(FileHTTPBodyStream, ReadBinaryFile) {
115 // HEX contents of file: |FEEDFACE A11A15|. 114 // HEX contents of file: |FEEDFACE A11A15|.
116 // TODO(rsesek): Use a more robust mechanism to locate testdata 115 base::FilePath path = Paths::TestDataRoot().Append(
117 // <https://code.google.com/p/crashpad/issues/detail?id=4>.
118 base::FilePath path = base::FilePath(
119 FILE_PATH_LITERAL("util/net/testdata/binary_http_body.dat")); 116 FILE_PATH_LITERAL("util/net/testdata/binary_http_body.dat"));
120 // This buffer size was chosen so that reading the file takes multiple reads. 117 // This buffer size was chosen so that reading the file takes multiple reads.
121 uint8_t buf[4]; 118 uint8_t buf[4];
122 119
123 FileHTTPBodyStream stream(path); 120 FileHTTPBodyStream stream(path);
124 121
125 memset(buf, '!', sizeof(buf)); 122 memset(buf, '!', sizeof(buf));
126 EXPECT_EQ(4, stream.GetBytesBuffer(buf, sizeof(buf))); 123 EXPECT_EQ(4, stream.GetBytesBuffer(buf, sizeof(buf)));
127 EXPECT_EQ(0xfe, buf[0]); 124 EXPECT_EQ(0xfe, buf[0]);
128 EXPECT_EQ(0xed, buf[1]); 125 EXPECT_EQ(0xed, buf[1]);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 189
193 ExpectBufferSet(reinterpret_cast<uint8_t*>(&buf[all_strings_length]), '!', 3); 190 ExpectBufferSet(reinterpret_cast<uint8_t*>(&buf[all_strings_length]), '!', 3);
194 } 191 }
195 192
196 TEST_P(CompositeHTTPBodyStreamBufferSize, StringsAndFile) { 193 TEST_P(CompositeHTTPBodyStreamBufferSize, StringsAndFile) {
197 std::string string1("Hello! "); 194 std::string string1("Hello! ");
198 std::string string2(" Goodbye :)"); 195 std::string string2(" Goodbye :)");
199 196
200 std::vector<HTTPBodyStream*> parts; 197 std::vector<HTTPBodyStream*> parts;
201 parts.push_back(new StringHTTPBodyStream(string1)); 198 parts.push_back(new StringHTTPBodyStream(string1));
202 parts.push_back(new FileHTTPBodyStream(base::FilePath( 199 base::FilePath path = Paths::TestDataRoot().Append(
203 FILE_PATH_LITERAL("util/net/testdata/ascii_http_body.txt")))); 200 FILE_PATH_LITERAL("util/net/testdata/ascii_http_body.txt"));
201 parts.push_back(new FileHTTPBodyStream(path));
204 parts.push_back(new StringHTTPBodyStream(string2)); 202 parts.push_back(new StringHTTPBodyStream(string2));
205 203
206 CompositeHTTPBodyStream stream(parts); 204 CompositeHTTPBodyStream stream(parts);
207 205
208 std::string expected_string = string1 + "This is a test.\n" + string2; 206 std::string expected_string = string1 + "This is a test.\n" + string2;
209 std::string actual_string = ReadStreamToString(&stream, GetParam()); 207 std::string actual_string = ReadStreamToString(&stream, GetParam());
210 EXPECT_EQ(expected_string, actual_string); 208 EXPECT_EQ(expected_string, actual_string);
211 } 209 }
212 210
213 INSTANTIATE_TEST_CASE_P(VariableBufferSize, 211 INSTANTIATE_TEST_CASE_P(VariableBufferSize,
214 CompositeHTTPBodyStreamBufferSize, 212 CompositeHTTPBodyStreamBufferSize,
215 testing::Values(1, 2, 9, 16, 31, 128, 1024)); 213 testing::Values(1, 2, 9, 16, 31, 128, 1024));
216 214
217 } // namespace 215 } // namespace
218 } // namespace test 216 } // namespace test
219 } // namespace crashpad 217 } // namespace crashpad
OLDNEW
« no previous file with comments | « build/run_tests.py ('k') | util/net/http_multipart_builder_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698