27 #include <gtest/gtest.h>
29 #include "absl/memory/memory.h"
42 using ::testing::StrictMock;
48 void SetUp()
override { SetUp(
true); }
49 void SetUp(
bool is_client) {
51 std::make_shared<StrictMock<MockTransportStreamReceiver>>();
58 void ExpectReadInt32(
int result) {
64 ExpectReadInt32(
buffer.length());
82 void UnblockSetupTransport() {
87 wire_reader_->SetupTransport(absl::make_unique<MockBinder>());
97 std::shared_ptr<StrictMock<MockTransportStreamReceiver>>
104 if (!
arg.ok())
return false;
109 if (!
arg.ok())
return false;
116 auto mock_binder = absl::make_unique<MockBinder>();
131 TEST_F(WireReaderTest, ProcessTransactionControlMessageSetupTransport) {
133 UnblockSetupTransport();
136 TEST_F(WireReaderTest, ProcessTransactionControlMessagePingResponse) {
138 UnblockSetupTransport();
144 TEST_F(WireReaderTest, ProcessTransactionServerRpcDataEmptyFlagIgnored) {
146 UnblockSetupTransport();
155 ProcessTransactionServerRpcDataFlagPrefixWithoutMetadata) {
157 UnblockSetupTransport();
173 TEST_F(WireReaderTest, ProcessTransactionServerRpcDataFlagPrefixWithMetadata) {
175 UnblockSetupTransport();
182 const std::vector<std::pair<std::string, std::string>> kMetadata = {
187 {
"another-key",
"another-value"},
191 ExpectReadInt32(kMetadata.size());
192 for (
const auto&
md : kMetadata) {
194 ExpectReadByteArray(
md.first);
197 ExpectReadByteArray(
md.second);
201 NotifyRecvInitialMetadata(
kFirstCallId, StatusOrContainerEq(kMetadata)));
206 TEST_F(WireReaderTest, ProcessTransactionServerRpcDataFlagMessageDataNonEmpty) {
208 UnblockSetupTransport();
218 ExpectReadByteArray(kMessageData);
220 NotifyRecvMessage(
kFirstCallId, StatusOrStrEq(kMessageData)));
225 TEST_F(WireReaderTest, ProcessTransactionServerRpcDataFlagMessageDataEmpty) {
227 UnblockSetupTransport();
237 ExpectReadByteArray(kMessageData);
239 NotifyRecvMessage(
kFirstCallId, StatusOrStrEq(kMessageData)));
244 TEST_F(WireReaderTest, ProcessTransactionServerRpcDataFlagSuffixWithStatus) {
246 UnblockSetupTransport();
248 constexpr
int kStatus = 0x1234;
258 NotifyRecvTrailingMetadata(
264 TEST_F(WireReaderTest, ProcessTransactionServerRpcDataFlagSuffixWithoutStatus) {
266 UnblockSetupTransport();
277 StatusOrContainerEq(
Metadata{}), 0));
282 TEST_F(WireReaderTest, InBoundFlowControl) {
284 UnblockSetupTransport();
293 ExpectReadInt32(1000);
307 ExpectReadInt32(1000);
319 TEST_F(WireReaderTest, ServerInitialMetadata) {
323 UnblockSetupTransport();
330 const std::vector<std::pair<std::string, std::string>> kMetadata = {
335 {
"another-key",
"another-value"},
339 ExpectReadString(
"test.service/rpc.method");
344 ExpectReadInt32(kMetadata.size());
345 for (
const auto&
md : kMetadata) {
347 ExpectReadByteArray(
md.first);
350 ExpectReadByteArray(
md.second);
357 auto metadata_expectation = kMetadata;
358 metadata_expectation.push_back({
":path",
"/test.service/rpc.method"});
359 metadata_expectation.push_back({
":authority",
"binder.authority"});
362 NotifyRecvInitialMetadata(
363 kFirstCallId, StatusOrContainerEq(metadata_expectation)));
370 int main(
int argc,
char** argv) {