OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
8 #include "net/dns/mock_mdns_socket_factory.h" | 8 #include "net/dns/mock_mdns_socket_factory.h" |
9 | 9 |
10 using testing::_; | 10 using testing::_; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 &MockMDnsSocketFactory::SendToInternal)); | 77 &MockMDnsSocketFactory::SendToInternal)); |
78 | 78 |
79 ON_CALL(*new_socket, RecvFrom(_, _, _, _)) | 79 ON_CALL(*new_socket, RecvFrom(_, _, _, _)) |
80 .WillByDefault(Invoke( | 80 .WillByDefault(Invoke( |
81 this, | 81 this, |
82 &MockMDnsSocketFactory::RecvFromInternal)); | 82 &MockMDnsSocketFactory::RecvFromInternal)); |
83 | 83 |
84 return new_socket.PassAs<DatagramServerSocket>(); | 84 return new_socket.PassAs<DatagramServerSocket>(); |
85 } | 85 } |
86 | 86 |
87 void MockMDnsSocketFactory::SimulateReceive(const char* packet, int size) { | 87 void MockMDnsSocketFactory::SimulateReceive(const uint8* packet, int size) { |
88 DCHECK(recv_buffer_size_ >= size); | 88 DCHECK(recv_buffer_size_ >= size); |
89 DCHECK(recv_buffer_.get()); | 89 DCHECK(recv_buffer_.get()); |
90 DCHECK(!recv_callback_.is_null()); | 90 DCHECK(!recv_callback_.is_null()); |
91 | 91 |
92 memcpy(recv_buffer_->data(), packet, size); | 92 memcpy(recv_buffer_->data(), packet, size); |
93 CompletionCallback recv_callback = recv_callback_; | 93 CompletionCallback recv_callback = recv_callback_; |
94 recv_callback_.Reset(); | 94 recv_callback_.Reset(); |
95 recv_callback.Run(size); | 95 recv_callback.Run(size); |
96 } | 96 } |
97 | 97 |
98 int MockMDnsSocketFactory::RecvFromInternal( | 98 int MockMDnsSocketFactory::RecvFromInternal( |
99 IOBuffer* buffer, int size, | 99 IOBuffer* buffer, int size, |
100 IPEndPoint* address, | 100 IPEndPoint* address, |
101 const CompletionCallback& callback) { | 101 const CompletionCallback& callback) { |
102 recv_buffer_ = buffer; | 102 recv_buffer_ = buffer; |
103 recv_buffer_size_ = size; | 103 recv_buffer_size_ = size; |
104 recv_callback_ = callback; | 104 recv_callback_ = callback; |
105 return ERR_IO_PENDING; | 105 return ERR_IO_PENDING; |
106 } | 106 } |
107 | 107 |
108 int MockMDnsSocketFactory::SendToInternal( | 108 int MockMDnsSocketFactory::SendToInternal( |
109 const std::string& packet, const std::string& address, | 109 const std::string& packet, const std::string& address, |
110 const CompletionCallback& callback) { | 110 const CompletionCallback& callback) { |
111 OnSendTo(packet); | 111 OnSendTo(packet); |
112 return packet.size(); | 112 return packet.size(); |
113 } | 113 } |
114 | 114 |
115 } // namespace net | 115 } // namespace net |
OLD | NEW |