33 static std::shared_ptr<MockAsyncSSLSocket>
newSocket(
34 const std::shared_ptr<SSLContext>& ctx,
36 auto sock = std::shared_ptr<MockAsyncSSLSocket>(
38 sock->ssl_.reset(SSL_new(ctx->getSSLCtx()));
39 SSL_set_fd(sock->ssl_.get(), -1);
47 state_ = AsyncSocket::StateEnum::ESTABLISHED;
48 sslState_ = AsyncSSLSocket::SSLStateEnum::STATE_ESTABLISHED;
52 MOCK_METHOD3(sslWriteImpl,
int(SSL* ssl,
const void* buf,
int n));
64 return performWrite(vec, count, flags, countWritten, partialWritten);
82 for (
int i = 0;
i < 500;
i++) {
83 memcpy(source_ +
i * 26,
"abcdefghijklmnopqrstuvwxyz", 26);
90 std::unique_ptr<iovec[]>
vec(
new iovec[sizes.size()]);
93 for (
auto size : sizes) {
94 vec[
i].iov_base = (
void*)(source_ + pos);
103 ASSERT_EQ(memcmp(source_ + pos, buf, n), 0);
108 vec[countWritten].iov_base =
109 ((
char*)vec[countWritten].iov_base) + partialWritten;
110 vec[countWritten].iov_len -= partialWritten;
115 std::shared_ptr<MockAsyncSSLSocket>
sock_;
116 char source_[26 * 500];
122 auto vec = makeVec({3, 3, 3});
124 .WillOnce(
Invoke([
this](SSL*,
const void* buf,
int m) {
125 verifyVec(buf, m, 0);
130 sock_->testPerformWrite(
131 vec.get(), n, WriteFlags::NONE, &countWritten, &partialWritten);
139 auto vec = makeVec({1500, 3, 3});
142 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
143 verifyVec(buf, m, pos);
148 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
149 verifyVec(buf, m, pos);
155 sock_->testPerformWrite(
156 vec.get(), n, WriteFlags::NONE, &countWritten, &partialWritten);
164 auto vec = makeVec({1000, 1000, 1000});
168 .WillRepeatedly(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
169 verifyVec(buf, m, pos);
175 sock_->testPerformWrite(
176 vec.get(), n, WriteFlags::NONE, &countWritten, &partialWritten);
184 auto vec = makeVec({300, 300, 300, 300, 300});
187 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
188 verifyVec(buf, m, pos);
194 sock_->testPerformWrite(
195 vec.get(), n, WriteFlags::NONE, &countWritten, &partialWritten);
198 consumeVec(
vec.get(), countWritten, partialWritten);
200 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
201 verifyVec(buf, m, pos);
205 sock_->testPerformWrite(
206 vec.get() + countWritten,
218 auto vec = makeVec({1000, 500, 500});
221 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
222 verifyVec(buf, m, pos);
227 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
228 verifyVec(buf, m, pos);
234 sock_->testPerformWrite(
235 vec.get(), n, WriteFlags::NONE, &countWritten, &partialWritten);
243 auto vec = makeVec({1000, 500});
246 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
247 verifyVec(buf, m, pos);
253 sock_->testPerformWrite(
254 vec.get(), n, WriteFlags::NONE, &countWritten, &partialWritten);
257 consumeVec(
vec.get(), countWritten, partialWritten);
259 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
260 verifyVec(buf, m, pos);
264 sock_->testPerformWrite(
265 vec.get() + countWritten,
277 auto vec = makeVec({1500, 3, 3});
279 const size_t initAppBytesWritten = 500;
280 const size_t appEor = initAppBytesWritten + 1506;
282 sock_->setAppBytesWritten(initAppBytesWritten);
284 sock_->setEorTracking(
true);
295 .WillOnce(
Invoke([=, &pos](SSL*,
const void* buf,
int m) {
297 sock_->checkEor(0, 0);
298 verifyVec(buf, m, pos);
303 .WillOnce(
Invoke([=, &pos](SSL*,
const void* buf,
int m) {
304 sock_->checkEor(appEor, 3600 + m);
305 verifyVec(buf, m, pos);
312 sock_->testPerformWrite(
313 vec.get(), n, WriteFlags::EOR, &countWritten, &partialWritten);
316 sock_->checkEor(0, 0);
323 auto vec = makeVec({600, 600, 600});
325 const size_t initAppBytesWritten = 500;
326 const size_t appEor = initAppBytesWritten + 1800;
328 sock_->setAppBytesWritten(initAppBytesWritten);
329 sock_->setEorTracking(
true);
339 .WillOnce(
Invoke([=, &pos](SSL*,
const void* buf,
int m) {
341 sock_->checkEor(0, 0);
342 verifyVec(buf, m, pos);
347 .WillOnce(
Invoke([=, &pos](SSL*,
const void* buf,
int m) {
348 sock_->checkEor(appEor, 3600 + m);
349 verifyVec(buf, m, pos);
356 sock_->testPerformWrite(
357 vec.get(), n, WriteFlags::EOR, &countWritten, &partialWritten);
360 sock_->checkEor(0, 0);
368 auto vec = makeVec({1600});
370 static constexpr
size_t initAppBytesWritten = 500;
371 static constexpr
size_t appEor = initAppBytesWritten + 1600;
373 sock_->setAppBytesWritten(initAppBytesWritten);
374 sock_->setEorTracking(
true);
385 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
386 sock_->checkEor(appEor, 2000 + m);
387 verifyVec(buf, m, pos);
394 sock_->testPerformWrite(
395 vec.get(), n, WriteFlags::EOR, &countWritten, &partialWritten);
398 sock_->checkEor(appEor, 2000 + 1600);
399 consumeVec(
vec.get(), countWritten, partialWritten);
405 .WillOnce(
Invoke([
this, &pos](SSL*,
const void* buf,
int m) {
406 sock_->checkEor(appEor, 3100 + m);
407 verifyVec(buf, m, pos);
411 sock_->testPerformWrite(
412 vec.get() + countWritten,
419 sock_->checkEor(0, 0);
std::unique_ptr< iovec[]> makeVec(std::vector< uint32_t > sizes)
void consumeVec(iovec *vec, uint32_t countWritten, uint32_t partialWritten)
void setAppBytesWritten(size_t n)
#define ASSERT_EQ(val1, val2)
TEST_F(TestInfoTest, Names)
MockAsyncSSLSocket(const std::shared_ptr< SSLContext > &ctx, EventBase *evb)
#define EXPECT_EQ(val1, val2)
—— Concurrent Priority Queue Implementation ——
std::shared_ptr< MockAsyncSSLSocket > sock_
#define MOCK_METHOD3(m,...)
WriteResult testPerformWrite(const iovec *vec, uint32_t count, WriteFlags flags, uint32_t *countWritten, uint32_t *partialWritten)
constexpr auto size(C const &c) -> decltype(c.size())
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
static map< string, int > m
AsyncSocket::UniquePtr sock_
void checkEor(size_t appEor, size_t rawEor)
std::shared_ptr< SSLContext > sslContext_
#define EXPECT_TRUE(condition)
#define MOCK_CONST_METHOD0(m,...)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
static std::shared_ptr< MockAsyncSSLSocket > newSocket(const std::shared_ptr< SSLContext > &ctx, EventBase *evb)
#define EXPECT_FALSE(condition)
AsyncSSLSocketWriteTest()
void verifyVec(const void *buf, int n, int pos)
internal::ReturnAction< R > Return(R value)