OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/socket/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
6 | 6 |
| 7 #include <string.h> |
| 8 |
| 9 #include "base/memory/ref_counted.h" |
7 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
9 | 12 |
10 //----------------------------------------------------------------------------- | 13 //----------------------------------------------------------------------------- |
11 | 14 |
12 namespace { | 15 namespace { |
13 | 16 |
14 static const char kMsg1[] = "\0hello!\xff"; | 17 static const char kMsg1[] = "\0hello!\xff"; |
15 static const int kLen1 = arraysize(kMsg1); | 18 static const int kLen1 = arraysize(kMsg1); |
16 static const char kMsg2[] = "\012345678\0"; | 19 static const char kMsg2[] = "\012345678\0"; |
(...skipping 20 matching lines...) Expand all Loading... |
37 void AssertReadReturns(const char* data, int len, int rv); | 40 void AssertReadReturns(const char* data, int len, int rv); |
38 void AssertReadBufferEquals(const char* data, int len); | 41 void AssertReadBufferEquals(const char* data, int len); |
39 | 42 |
40 void AssertSyncWriteEquals(const char* data, int len); | 43 void AssertSyncWriteEquals(const char* data, int len); |
41 void AssertAsyncWriteEquals(const char* data, int len); | 44 void AssertAsyncWriteEquals(const char* data, int len); |
42 void AssertWriteReturns(const char* data, int len, int rv); | 45 void AssertWriteReturns(const char* data, int len, int rv); |
43 | 46 |
44 TestCompletionCallback read_callback_; | 47 TestCompletionCallback read_callback_; |
45 TestCompletionCallback write_callback_; | 48 TestCompletionCallback write_callback_; |
46 StreamSocket* sock_; | 49 StreamSocket* sock_; |
47 scoped_refptr<DeterministicSocketData> data_; | 50 scoped_ptr<DeterministicSocketData> data_; |
48 | 51 |
49 private: | 52 private: |
50 scoped_refptr<IOBuffer> read_buf_; | 53 scoped_refptr<IOBuffer> read_buf_; |
51 MockConnect connect_data_; | 54 MockConnect connect_data_; |
52 | 55 |
53 HostPortPair endpoint_; | 56 HostPortPair endpoint_; |
54 scoped_refptr<TransportSocketParams> tcp_params_; | 57 scoped_refptr<TransportSocketParams> tcp_params_; |
55 ClientSocketPoolHistograms histograms_; | 58 ClientSocketPoolHistograms histograms_; |
56 DeterministicMockClientSocketFactory socket_factory_; | 59 DeterministicMockClientSocketFactory socket_factory_; |
57 MockTransportClientSocketPool socket_pool_; | 60 MockTransportClientSocketPool socket_pool_; |
(...skipping 20 matching lines...) Expand all Loading... |
78 void DeterministicSocketDataTest::TearDown() { | 81 void DeterministicSocketDataTest::TearDown() { |
79 // Empty the current queue. | 82 // Empty the current queue. |
80 MessageLoop::current()->RunAllPending(); | 83 MessageLoop::current()->RunAllPending(); |
81 PlatformTest::TearDown(); | 84 PlatformTest::TearDown(); |
82 } | 85 } |
83 | 86 |
84 void DeterministicSocketDataTest::Initialize(MockRead* reads, | 87 void DeterministicSocketDataTest::Initialize(MockRead* reads, |
85 size_t reads_count, | 88 size_t reads_count, |
86 MockWrite* writes, | 89 MockWrite* writes, |
87 size_t writes_count) { | 90 size_t writes_count) { |
88 data_ = new DeterministicSocketData(reads, reads_count, writes, writes_count); | 91 data_.reset(new DeterministicSocketData(reads, reads_count, |
| 92 writes, writes_count)); |
89 data_->set_connect_data(connect_data_); | 93 data_->set_connect_data(connect_data_); |
90 socket_factory_.AddSocketDataProvider(data_.get()); | 94 socket_factory_.AddSocketDataProvider(data_.get()); |
91 | 95 |
92 // Perform the TCP connect | 96 // Perform the TCP connect |
93 EXPECT_EQ(OK, | 97 EXPECT_EQ(OK, |
94 connection_.Init(endpoint_.ToString(), | 98 connection_.Init(endpoint_.ToString(), |
95 tcp_params_, | 99 tcp_params_, |
96 LOWEST, | 100 LOWEST, |
97 CompletionCallback(), | 101 CompletionCallback(), |
98 reinterpret_cast<TransportClientSocketPool*>(&socket_pool_), | 102 reinterpret_cast<TransportClientSocketPool*>(&socket_pool_), |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 // Issue the writes which will complete immediately | 528 // Issue the writes which will complete immediately |
525 data_->StopAfter(1); | 529 data_->StopAfter(1); |
526 AssertSyncWriteEquals(kMsg3, kLen3); | 530 AssertSyncWriteEquals(kMsg3, kLen3); |
527 | 531 |
528 data_->RunFor(1); | 532 data_->RunFor(1); |
529 ASSERT_EQ(kLen2, read_callback_.WaitForResult()); | 533 ASSERT_EQ(kLen2, read_callback_.WaitForResult()); |
530 AssertReadBufferEquals(kMsg2, kLen2); | 534 AssertReadBufferEquals(kMsg2, kLen2); |
531 } | 535 } |
532 | 536 |
533 } // namespace net | 537 } // namespace net |
OLD | NEW |