OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 class HttpBaseTest : public testing::Test, public IHttpNotify { | 47 class HttpBaseTest : public testing::Test, public IHttpNotify { |
48 public: | 48 public: |
49 enum EventType { E_HEADER_COMPLETE, E_COMPLETE, E_CLOSED }; | 49 enum EventType { E_HEADER_COMPLETE, E_COMPLETE, E_CLOSED }; |
50 struct Event { | 50 struct Event { |
51 EventType event; | 51 EventType event; |
52 bool chunked; | 52 bool chunked; |
53 size_t data_size; | 53 size_t data_size; |
54 HttpMode mode; | 54 HttpMode mode; |
55 HttpError err; | 55 HttpError err; |
56 }; | 56 }; |
57 HttpBaseTest() : mem(NULL), obtain_stream(false), http_stream(NULL) { } | 57 HttpBaseTest() : mem(nullptr), obtain_stream(false), http_stream(nullptr) {} |
58 | 58 |
59 virtual void SetUp() { } | 59 virtual void SetUp() { } |
60 virtual void TearDown() { | 60 virtual void TearDown() { |
61 delete http_stream; | 61 delete http_stream; |
62 // Avoid an ASSERT, in case a test doesn't clean up properly | 62 // Avoid an ASSERT, in case a test doesn't clean up properly |
63 base.abort(HE_NONE); | 63 base.abort(HE_NONE); |
64 } | 64 } |
65 | 65 |
66 virtual HttpError onHttpHeaderComplete(bool chunked, size_t& data_size) { | 66 virtual HttpError onHttpHeaderComplete(bool chunked, size_t& data_size) { |
67 LOG_F(LS_VERBOSE) << "chunked: " << chunked << " size: " << data_size; | 67 LOG_F(LS_VERBOSE) << "chunked: " << chunked << " size: " << data_size; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 mem->GetSize(&length); | 182 mem->GetSize(&length); |
183 EXPECT_EQ(expected_length, length); | 183 EXPECT_EQ(expected_length, length); |
184 EXPECT_TRUE(0 == memcmp(expected_data, mem->GetBuffer(), length)); | 184 EXPECT_TRUE(0 == memcmp(expected_data, mem->GetBuffer(), length)); |
185 LOG_F(LS_VERBOSE) << "Exit"; | 185 LOG_F(LS_VERBOSE) << "Exit"; |
186 } | 186 } |
187 | 187 |
188 void HttpBaseTest::ObtainDocumentStream() { | 188 void HttpBaseTest::ObtainDocumentStream() { |
189 LOG_F(LS_VERBOSE) << "Enter"; | 189 LOG_F(LS_VERBOSE) << "Enter"; |
190 EXPECT_FALSE(http_stream); | 190 EXPECT_FALSE(http_stream); |
191 http_stream = base.GetDocumentStream(); | 191 http_stream = base.GetDocumentStream(); |
192 ASSERT_TRUE(NULL != http_stream); | 192 ASSERT_TRUE(nullptr != http_stream); |
193 sink.Monitor(http_stream); | 193 sink.Monitor(http_stream); |
194 LOG_F(LS_VERBOSE) << "Exit"; | 194 LOG_F(LS_VERBOSE) << "Exit"; |
195 } | 195 } |
196 | 196 |
197 void HttpBaseTest::VerifyDocumentStreamIsOpening() { | 197 void HttpBaseTest::VerifyDocumentStreamIsOpening() { |
198 LOG_F(LS_VERBOSE) << "Enter"; | 198 LOG_F(LS_VERBOSE) << "Enter"; |
199 ASSERT_TRUE(NULL != http_stream); | 199 ASSERT_TRUE(nullptr != http_stream); |
200 EXPECT_EQ(0, sink.Events(http_stream)); | 200 EXPECT_EQ(0, sink.Events(http_stream)); |
201 EXPECT_EQ(SS_OPENING, http_stream->GetState()); | 201 EXPECT_EQ(SS_OPENING, http_stream->GetState()); |
202 | 202 |
203 size_t read = 0; | 203 size_t read = 0; |
204 char buffer[5] = { 0 }; | 204 char buffer[5] = { 0 }; |
205 EXPECT_EQ(SR_BLOCK, http_stream->Read(buffer, sizeof(buffer), &read, NULL)); | 205 EXPECT_EQ(SR_BLOCK, |
| 206 http_stream->Read(buffer, sizeof(buffer), &read, nullptr)); |
206 LOG_F(LS_VERBOSE) << "Exit"; | 207 LOG_F(LS_VERBOSE) << "Exit"; |
207 } | 208 } |
208 | 209 |
209 void HttpBaseTest::VerifyDocumentStreamOpenEvent() { | 210 void HttpBaseTest::VerifyDocumentStreamOpenEvent() { |
210 LOG_F(LS_VERBOSE) << "Enter"; | 211 LOG_F(LS_VERBOSE) << "Enter"; |
211 | 212 |
212 ASSERT_TRUE(NULL != http_stream); | 213 ASSERT_TRUE(nullptr != http_stream); |
213 EXPECT_EQ(SE_OPEN | SE_READ, sink.Events(http_stream)); | 214 EXPECT_EQ(SE_OPEN | SE_READ, sink.Events(http_stream)); |
214 EXPECT_EQ(SS_OPEN, http_stream->GetState()); | 215 EXPECT_EQ(SS_OPEN, http_stream->GetState()); |
215 | 216 |
216 // HTTP headers haven't arrived yet | 217 // HTTP headers haven't arrived yet |
217 EXPECT_EQ(0U, events.size()); | 218 EXPECT_EQ(0U, events.size()); |
218 EXPECT_EQ(static_cast<uint32_t>(HC_INTERNAL_SERVER_ERROR), data.scode); | 219 EXPECT_EQ(static_cast<uint32_t>(HC_INTERNAL_SERVER_ERROR), data.scode); |
219 LOG_F(LS_VERBOSE) << "Exit"; | 220 LOG_F(LS_VERBOSE) << "Exit"; |
220 } | 221 } |
221 | 222 |
222 void HttpBaseTest::ReadDocumentStreamData(const char* expected_data) { | 223 void HttpBaseTest::ReadDocumentStreamData(const char* expected_data) { |
223 LOG_F(LS_VERBOSE) << "Enter"; | 224 LOG_F(LS_VERBOSE) << "Enter"; |
224 | 225 |
225 ASSERT_TRUE(NULL != http_stream); | 226 ASSERT_TRUE(nullptr != http_stream); |
226 EXPECT_EQ(SS_OPEN, http_stream->GetState()); | 227 EXPECT_EQ(SS_OPEN, http_stream->GetState()); |
227 | 228 |
228 // Pump the HTTP I/O using Read, and verify the results. | 229 // Pump the HTTP I/O using Read, and verify the results. |
229 size_t verified_length = 0; | 230 size_t verified_length = 0; |
230 const size_t expected_length = strlen(expected_data); | 231 const size_t expected_length = strlen(expected_data); |
231 while (verified_length < expected_length) { | 232 while (verified_length < expected_length) { |
232 size_t read = 0; | 233 size_t read = 0; |
233 char buffer[5] = { 0 }; | 234 char buffer[5] = { 0 }; |
234 size_t amt_to_read = | 235 size_t amt_to_read = |
235 std::min(expected_length - verified_length, sizeof(buffer)); | 236 std::min(expected_length - verified_length, sizeof(buffer)); |
236 EXPECT_EQ(SR_SUCCESS, http_stream->Read(buffer, amt_to_read, &read, NULL)); | 237 EXPECT_EQ(SR_SUCCESS, |
| 238 http_stream->Read(buffer, amt_to_read, &read, nullptr)); |
237 EXPECT_EQ(amt_to_read, read); | 239 EXPECT_EQ(amt_to_read, read); |
238 EXPECT_TRUE(0 == memcmp(expected_data + verified_length, buffer, read)); | 240 EXPECT_TRUE(0 == memcmp(expected_data + verified_length, buffer, read)); |
239 verified_length += read; | 241 verified_length += read; |
240 } | 242 } |
241 LOG_F(LS_VERBOSE) << "Exit"; | 243 LOG_F(LS_VERBOSE) << "Exit"; |
242 } | 244 } |
243 | 245 |
244 void HttpBaseTest::VerifyDocumentStreamIsEOS() { | 246 void HttpBaseTest::VerifyDocumentStreamIsEOS() { |
245 LOG_F(LS_VERBOSE) << "Enter"; | 247 LOG_F(LS_VERBOSE) << "Enter"; |
246 | 248 |
247 ASSERT_TRUE(NULL != http_stream); | 249 ASSERT_TRUE(nullptr != http_stream); |
248 size_t read = 0; | 250 size_t read = 0; |
249 char buffer[5] = { 0 }; | 251 char buffer[5] = { 0 }; |
250 EXPECT_EQ(SR_EOS, http_stream->Read(buffer, sizeof(buffer), &read, NULL)); | 252 EXPECT_EQ(SR_EOS, http_stream->Read(buffer, sizeof(buffer), &read, nullptr)); |
251 EXPECT_EQ(SS_CLOSED, http_stream->GetState()); | 253 EXPECT_EQ(SS_CLOSED, http_stream->GetState()); |
252 | 254 |
253 // When EOS is caused by Read, we don't expect SE_CLOSE | 255 // When EOS is caused by Read, we don't expect SE_CLOSE |
254 EXPECT_EQ(0, sink.Events(http_stream)); | 256 EXPECT_EQ(0, sink.Events(http_stream)); |
255 LOG_F(LS_VERBOSE) << "Exit"; | 257 LOG_F(LS_VERBOSE) << "Exit"; |
256 } | 258 } |
257 | 259 |
258 void HttpBaseTest::SetupDocument(const char* document_data) { | 260 void HttpBaseTest::SetupDocument(const char* document_data) { |
259 LOG_F(LS_VERBOSE) << "Enter"; | 261 LOG_F(LS_VERBOSE) << "Enter"; |
260 src.SetState(SS_OPEN); | 262 src.SetState(SS_OPEN); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // Begin send | 315 // Begin send |
314 base.send(&data); | 316 base.send(&data); |
315 | 317 |
316 // Send completed successfully | 318 // Send completed successfully |
317 VerifyTransferComplete(HM_SEND, HE_NONE); | 319 VerifyTransferComplete(HM_SEND, HE_NONE); |
318 VerifySourceContents(kHttpResponse); | 320 VerifySourceContents(kHttpResponse); |
319 } | 321 } |
320 | 322 |
321 TEST_F(HttpBaseTest, SupportsSendNoDocument) { | 323 TEST_F(HttpBaseTest, SupportsSendNoDocument) { |
322 // Queue response document | 324 // Queue response document |
323 SetupDocument(NULL); | 325 SetupDocument(nullptr); |
324 | 326 |
325 // Begin send | 327 // Begin send |
326 base.send(&data); | 328 base.send(&data); |
327 | 329 |
328 // Send completed successfully | 330 // Send completed successfully |
329 VerifyTransferComplete(HM_SEND, HE_NONE); | 331 VerifyTransferComplete(HM_SEND, HE_NONE); |
330 VerifySourceContents(kHttpEmptyResponse); | 332 VerifySourceContents(kHttpEmptyResponse); |
331 } | 333 } |
332 | 334 |
333 TEST_F(HttpBaseTest, SignalsCompleteOnInterruptedSend) { | 335 TEST_F(HttpBaseTest, SignalsCompleteOnInterruptedSend) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 obtain_stream = true; | 470 obtain_stream = true; |
469 | 471 |
470 // Begin receive | 472 // Begin receive |
471 base.recv(&data); | 473 base.recv(&data); |
472 | 474 |
473 // We've already seen the header, but not data has arrived | 475 // We've already seen the header, but not data has arrived |
474 VerifyHeaderComplete(1, true); | 476 VerifyHeaderComplete(1, true); |
475 VerifyDocumentContents(""); | 477 VerifyDocumentContents(""); |
476 | 478 |
477 // The document is still open, until we attempt to read | 479 // The document is still open, until we attempt to read |
478 ASSERT_TRUE(NULL != http_stream); | 480 ASSERT_TRUE(nullptr != http_stream); |
479 EXPECT_EQ(SS_OPEN, http_stream->GetState()); | 481 EXPECT_EQ(SS_OPEN, http_stream->GetState()); |
480 | 482 |
481 // Attempt to read data, and discover EOS | 483 // Attempt to read data, and discover EOS |
482 VerifyDocumentStreamIsEOS(); | 484 VerifyDocumentStreamIsEOS(); |
483 | 485 |
484 // Document completed successfully | 486 // Document completed successfully |
485 VerifyTransferComplete(HM_RECV, HE_NONE); | 487 VerifyTransferComplete(HM_RECV, HE_NONE); |
486 VerifyDocumentContents(""); | 488 VerifyDocumentContents(""); |
487 } | 489 } |
488 | 490 |
(...skipping 15 matching lines...) Expand all Loading... |
504 | 506 |
505 // Simulate unexpected close | 507 // Simulate unexpected close |
506 src.SetState(SS_CLOSED); | 508 src.SetState(SS_CLOSED); |
507 | 509 |
508 // Observe error event on document stream | 510 // Observe error event on document stream |
509 EXPECT_EQ(testing::SSE_ERROR, sink.Events(http_stream)); | 511 EXPECT_EQ(testing::SSE_ERROR, sink.Events(http_stream)); |
510 | 512 |
511 // Future reads give an error | 513 // Future reads give an error |
512 int error = 0; | 514 int error = 0; |
513 char buffer[5] = { 0 }; | 515 char buffer[5] = { 0 }; |
514 EXPECT_EQ(SR_ERROR, http_stream->Read(buffer, sizeof(buffer), NULL, &error)); | 516 EXPECT_EQ(SR_ERROR, |
| 517 http_stream->Read(buffer, sizeof(buffer), nullptr, &error)); |
515 EXPECT_EQ(HE_DISCONNECTED, error); | 518 EXPECT_EQ(HE_DISCONNECTED, error); |
516 | 519 |
517 // Document completed with error | 520 // Document completed with error |
518 VerifyHeaderComplete(2, false); | 521 VerifyHeaderComplete(2, false); |
519 VerifyTransferComplete(HM_RECV, HE_DISCONNECTED); | 522 VerifyTransferComplete(HM_RECV, HE_DISCONNECTED); |
520 VerifyDocumentContents(""); | 523 VerifyDocumentContents(""); |
521 } | 524 } |
522 | 525 |
523 } // namespace rtc | 526 } // namespace rtc |
OLD | NEW |