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

Side by Side Diff: net/quic/test_tools/quic_crypto_server_config_peer.cc

Issue 2671273003: Get rid of more va_arg methods in favor of std::vector<> arguments. Much simpler and more readable … (Closed)
Patch Set: address Ryan's comment. Created 3 years, 10 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 | « net/quic/test_tools/quic_crypto_server_config_peer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/quic/test_tools/quic_crypto_server_config_peer.h" 5 #include "net/quic/test_tools/quic_crypto_server_config_peer.h"
6 6
7 #include <cstdarg> 7 #include <cstdarg>
8 8
9 #include "net/quic/test_tools/mock_clock.h" 9 #include "net/quic/test_tools/mock_clock.h"
10 #include "net/quic/test_tools/mock_random.h" 10 #include "net/quic/test_tools/mock_random.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 EXPECT_EQ(1, tokens.tokens_size()); 90 EXPECT_EQ(1, tokens.tokens_size());
91 return server_config_->ValidateSingleSourceAddressToken(tokens.tokens(0), ip, 91 return server_config_->ValidateSingleSourceAddressToken(tokens.tokens(0), ip,
92 now); 92 now);
93 } 93 }
94 94
95 string QuicCryptoServerConfigPeer::NewServerNonce(QuicRandom* rand, 95 string QuicCryptoServerConfigPeer::NewServerNonce(QuicRandom* rand,
96 QuicWallTime now) const { 96 QuicWallTime now) const {
97 return server_config_->NewServerNonce(rand, now); 97 return server_config_->NewServerNonce(rand, now);
98 } 98 }
99 99
100 void QuicCryptoServerConfigPeer::CheckConfigs(const char* server_config_id1, 100 void QuicCryptoServerConfigPeer::CheckConfigs(
101 ...) { 101 std::vector<std::pair<string, bool>> expected_ids_and_status) {
102 va_list ap;
103 va_start(ap, server_config_id1);
104
105 std::vector<std::pair<ServerConfigID, bool>> expected;
106 bool first = true;
107 for (;;) {
108 const char* server_config_id;
109 if (first) {
110 server_config_id = server_config_id1;
111 first = false;
112 } else {
113 server_config_id = va_arg(ap, const char*);
114 }
115
116 if (!server_config_id) {
117 break;
118 }
119
120 // varargs will promote the value to an int so we have to read that from
121 // the stack and cast down.
122 const bool is_primary = static_cast<bool>(va_arg(ap, int));
123 expected.push_back(std::make_pair(server_config_id, is_primary));
124 }
125
126 va_end(ap);
127
128 QuicReaderMutexLock locked(&server_config_->configs_lock_); 102 QuicReaderMutexLock locked(&server_config_->configs_lock_);
129 103
130 ASSERT_EQ(expected.size(), server_config_->configs_.size()) << ConfigsDebug(); 104 ASSERT_EQ(expected_ids_and_status.size(), server_config_->configs_.size())
105 << ConfigsDebug();
131 106
132 for (const std::pair< 107 for (const std::pair<
133 const ServerConfigID, 108 const ServerConfigID,
134 QuicReferenceCountedPointer<QuicCryptoServerConfig::Config>>& i : 109 QuicReferenceCountedPointer<QuicCryptoServerConfig::Config>>& i :
135 server_config_->configs_) { 110 server_config_->configs_) {
136 bool found = false; 111 bool found = false;
137 for (std::pair<ServerConfigID, bool>& j : expected) { 112 for (std::pair<ServerConfigID, bool>& j : expected_ids_and_status) {
138 if (i.first == j.first && i.second->is_primary == j.second) { 113 if (i.first == j.first && i.second->is_primary == j.second) {
139 found = true; 114 found = true;
140 j.first.clear(); 115 j.first.clear();
141 break; 116 break;
142 } 117 }
143 } 118 }
144 119
145 ASSERT_TRUE(found) << "Failed to find match for " << i.first 120 ASSERT_TRUE(found) << "Failed to find match for " << i.first
146 << " in configs:\n" 121 << " in configs:\n"
147 << ConfigsDebug(); 122 << ConfigsDebug();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 uint32_t QuicCryptoServerConfigPeer::source_address_token_future_secs() { 167 uint32_t QuicCryptoServerConfigPeer::source_address_token_future_secs() {
193 return server_config_->source_address_token_future_secs_; 168 return server_config_->source_address_token_future_secs_;
194 } 169 }
195 170
196 uint32_t QuicCryptoServerConfigPeer::source_address_token_lifetime_secs() { 171 uint32_t QuicCryptoServerConfigPeer::source_address_token_lifetime_secs() {
197 return server_config_->source_address_token_lifetime_secs_; 172 return server_config_->source_address_token_lifetime_secs_;
198 } 173 }
199 174
200 } // namespace test 175 } // namespace test
201 } // namespace net 176 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_crypto_server_config_peer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698