|
11 | 11 | #include <qtils/test/outcome.hpp> |
12 | 12 | #include "mock/libp2p/connection/layer_connection_mock.hpp" |
13 | 13 | #include "mock/libp2p/crypto/key_marshaller_mock.hpp" |
| 14 | +#include "testutil/expect_read.hpp" |
| 15 | +#include "testutil/expect_write.hpp" |
14 | 16 | #include "testutil/gmock_actions.hpp" |
15 | 17 |
|
16 | 18 | using namespace libp2p::connection; |
@@ -120,63 +122,29 @@ TEST_F(PlaintextConnectionTest, RemoteMultiaddr) { |
120 | 122 | */ |
121 | 123 | TEST_F(PlaintextConnectionTest, Read) { |
122 | 124 | const int size = 100; |
123 | | - EXPECT_CALL(*connection_, read(_, _, _)).WillOnce(AsioSuccess(size)); |
| 125 | + EXPECT_CALL_READ(*connection_).WILL_READ_SIZE(size); |
124 | 126 | auto buf = std::make_shared<std::vector<uint8_t>>(size, 0); |
125 | 127 | secure_connection_->read(*buf, size, [size, buf](auto &&res) { |
126 | 128 | ASSERT_OUTCOME_SUCCESS(res); |
127 | 129 | ASSERT_EQ(res.value(), size); |
128 | 130 | }); |
129 | 131 | } |
130 | 132 |
|
131 | | -/** |
132 | | - * @given plaintext secure connection |
133 | | - * @when invoking readSome method of the connection |
134 | | - * @then method behaves as expected |
135 | | - */ |
136 | | -TEST_F(PlaintextConnectionTest, ReadSome) { |
137 | | - const int size = 100; |
138 | | - const int smaller = 50; |
139 | | - EXPECT_CALL(*connection_, readSome(_, _, _)) |
140 | | - .WillOnce(AsioSuccess(smaller /* less than 100 */)); |
141 | | - auto buf = std::make_shared<std::vector<uint8_t>>(size, 0); |
142 | | - secure_connection_->readSome(*buf, smaller, [smaller, buf](auto &&res) { |
143 | | - ASSERT_OUTCOME_SUCCESS(res); |
144 | | - ASSERT_EQ(res.value(), smaller); |
145 | | - }); |
146 | | -} |
147 | | - |
148 | 133 | /** |
149 | 134 | * @given plaintext secure connection |
150 | 135 | * @when invoking write method of the connection |
151 | 136 | * @then method behaves as expected |
152 | 137 | */ |
153 | 138 | TEST_F(PlaintextConnectionTest, Write) { |
154 | 139 | const int size = 100; |
155 | | - EXPECT_CALL(*connection_, writeSome(_, _, _)).WillOnce(AsioSuccess(size)); |
| 140 | + EXPECT_CALL_WRITE(*connection_).WILL_WRITE_SIZE(size); |
156 | 141 | auto buf = std::make_shared<std::vector<uint8_t>>(size, 0); |
157 | 142 | libp2p::writeReturnSize(secure_connection_, *buf, [size, buf](auto &&res) { |
158 | 143 | ASSERT_OUTCOME_SUCCESS(res); |
159 | 144 | ASSERT_EQ(res.value(), size); |
160 | 145 | }); |
161 | 146 | } |
162 | 147 |
|
163 | | -/** |
164 | | - * @given plaintext secure connection |
165 | | - * @when invoking writeSome method of the connection |
166 | | - * @then method behaves as expected |
167 | | - */ |
168 | | -TEST_F(PlaintextConnectionTest, WriteSome) { |
169 | | - const int size = 100; |
170 | | - const int smaller = 50; |
171 | | - EXPECT_CALL(*connection_, writeSome(_, _, _)) |
172 | | - .WillOnce(AsioSuccess(smaller /* less than 100 */)); |
173 | | - auto buf = std::make_shared<std::vector<uint8_t>>(size, 0); |
174 | | - secure_connection_->writeSome(*buf, smaller, [smaller, buf](auto &&res) { |
175 | | - ASSERT_OUTCOME_SUCCESS(res); |
176 | | - ASSERT_EQ(res.value(), smaller); |
177 | | - }); |
178 | | -} |
179 | | - |
180 | 148 | /** |
181 | 149 | * @given plaintext secure connection |
182 | 150 | * @when invoking isClosed method of the connection |
|
0 commit comments