-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathmock_quic_data.cc
76 lines (59 loc) · 2.25 KB
/
mock_quic_data.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/quic/mock_quic_data.h"
#include "net/base/hex_utils.h"
namespace net::test {
MockQuicData::MockQuicData(quic::ParsedQuicVersion version)
: printer_(version) {}
MockQuicData::~MockQuicData() = default;
void MockQuicData::AddConnect(IoMode mode, int rv) {
connect_ = std::make_unique<MockConnect>(mode, rv);
}
void MockQuicData::AddRead(IoMode mode,
std::unique_ptr<quic::QuicEncryptedPacket> packet) {
reads_.emplace_back(mode, packet->data(), packet->length(),
sequence_number_++);
packets_.push_back(std::move(packet));
}
void MockQuicData::AddRead(IoMode mode, int rv) {
reads_.emplace_back(mode, rv, sequence_number_++);
}
void MockQuicData::AddWrite(IoMode mode,
std::unique_ptr<quic::QuicEncryptedPacket> packet) {
writes_.emplace_back(mode, packet->data(), packet->length(),
sequence_number_++);
packets_.push_back(std::move(packet));
}
void MockQuicData::AddWrite(IoMode mode, int rv) {
writes_.emplace_back(mode, rv, sequence_number_++);
}
void MockQuicData::AddWrite(IoMode mode,
int rv,
std::unique_ptr<quic::QuicEncryptedPacket> packet) {
writes_.emplace_back(mode, rv, sequence_number_++);
packets_.push_back(std::move(packet));
}
void MockQuicData::AddSocketDataToFactory(MockClientSocketFactory* factory) {
factory->AddSocketDataProvider(InitializeAndGetSequencedSocketData());
}
bool MockQuicData::AllReadDataConsumed() {
return socket_data_->AllReadDataConsumed();
}
bool MockQuicData::AllWriteDataConsumed() {
return socket_data_->AllWriteDataConsumed();
}
void MockQuicData::Resume() {
socket_data_->Resume();
}
SequencedSocketData* MockQuicData::InitializeAndGetSequencedSocketData() {
socket_data_ = std::make_unique<SequencedSocketData>(reads_, writes_);
socket_data_->set_printer(&printer_);
if (connect_ != nullptr)
socket_data_->set_connect_data(*connect_);
return socket_data_.get();
}
SequencedSocketData* MockQuicData::GetSequencedSocketData() {
return socket_data_.get();
}
} // namespace net::test