|
|
|
@ -30,7 +30,8 @@ using ::testing::Return; |
|
|
|
|
using ::testing::StrictMock; |
|
|
|
|
|
|
|
|
|
MATCHER_P(StrEqInt8Ptr, target, "") { |
|
|
|
|
return std::string(reinterpret_cast<const char*>(arg)) == target; |
|
|
|
|
return std::string(reinterpret_cast<const char*>(arg), target.size()) == |
|
|
|
|
target; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(WireWriterTest, RpcCall) { |
|
|
|
@ -53,7 +54,6 @@ TEST(WireWriterTest, RpcCall) { |
|
|
|
|
|
|
|
|
|
::testing::InSequence sequence; |
|
|
|
|
int sequence_number = 0; |
|
|
|
|
int tx_code = kFirstCallId; |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
// flag
|
|
|
|
@ -61,18 +61,18 @@ TEST(WireWriterTest, RpcCall) { |
|
|
|
|
// sequence number
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(sequence_number)); |
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mock_binder_ref, Transact(BinderTransportTxCode(tx_code))); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, Transact(BinderTransportTxCode(kFirstCallId))); |
|
|
|
|
|
|
|
|
|
Transaction tx(tx_code, sequence_number, /*is_client=*/true); |
|
|
|
|
Transaction tx(kFirstCallId, /*is_client=*/true); |
|
|
|
|
EXPECT_TRUE(wire_writer.RpcCall(tx).ok()); |
|
|
|
|
sequence_number++; |
|
|
|
|
tx_code++; |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
// flag
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(kFlagPrefix)); |
|
|
|
|
// sequence number
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(sequence_number)); |
|
|
|
|
// sequence number. This is another stream so the sequence number starts
|
|
|
|
|
// with 0.
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(0)); |
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, |
|
|
|
|
WriteString(absl::string_view("/example/method/ref"))); |
|
|
|
@ -96,12 +96,10 @@ TEST(WireWriterTest, RpcCall) { |
|
|
|
|
EXPECT_CALL(mock_binder_ref, |
|
|
|
|
Transact(BinderTransportTxCode(kFirstCallId + 1))); |
|
|
|
|
|
|
|
|
|
Transaction tx(kFirstCallId + 1, 1, /*is_client=*/true); |
|
|
|
|
Transaction tx(kFirstCallId + 1, /*is_client=*/true); |
|
|
|
|
tx.SetPrefix(kMetadata); |
|
|
|
|
tx.SetMethodRef("/example/method/ref"); |
|
|
|
|
EXPECT_TRUE(wire_writer.RpcCall(tx).ok()); |
|
|
|
|
sequence_number++; |
|
|
|
|
tx_code++; |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
// flag
|
|
|
|
@ -110,11 +108,12 @@ TEST(WireWriterTest, RpcCall) { |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(sequence_number)); |
|
|
|
|
|
|
|
|
|
ExpectWriteByteArray("data"); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, Transact(BinderTransportTxCode(tx_code))); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, Transact(BinderTransportTxCode(kFirstCallId))); |
|
|
|
|
|
|
|
|
|
Transaction tx(tx_code, sequence_number, /*is_client=*/true); |
|
|
|
|
Transaction tx(kFirstCallId, /*is_client=*/true); |
|
|
|
|
tx.SetData("data"); |
|
|
|
|
EXPECT_TRUE(wire_writer.RpcCall(tx).ok()); |
|
|
|
|
sequence_number++; |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
// flag
|
|
|
|
@ -122,13 +121,12 @@ TEST(WireWriterTest, RpcCall) { |
|
|
|
|
// sequence number
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(sequence_number)); |
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mock_binder_ref, Transact(BinderTransportTxCode(tx_code))); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, Transact(BinderTransportTxCode(kFirstCallId))); |
|
|
|
|
|
|
|
|
|
Transaction tx(tx_code, sequence_number, /*is_client=*/true); |
|
|
|
|
Transaction tx(kFirstCallId, /*is_client=*/true); |
|
|
|
|
tx.SetSuffix({}); |
|
|
|
|
EXPECT_TRUE(wire_writer.RpcCall(tx).ok()); |
|
|
|
|
sequence_number++; |
|
|
|
|
tx_code++; |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
// flag
|
|
|
|
@ -159,9 +157,9 @@ TEST(WireWriterTest, RpcCall) { |
|
|
|
|
// Empty message data
|
|
|
|
|
ExpectWriteByteArray(""); |
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mock_binder_ref, Transact(BinderTransportTxCode(tx_code))); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, Transact(BinderTransportTxCode(kFirstCallId))); |
|
|
|
|
|
|
|
|
|
Transaction tx(tx_code, sequence_number, /*is_client=*/true); |
|
|
|
|
Transaction tx(kFirstCallId, /*is_client=*/true); |
|
|
|
|
// TODO(waynetu): Implement a helper function that automatically creates
|
|
|
|
|
// EXPECT_CALL based on the tx object.
|
|
|
|
|
tx.SetPrefix(kMetadata); |
|
|
|
@ -170,7 +168,68 @@ TEST(WireWriterTest, RpcCall) { |
|
|
|
|
tx.SetSuffix({}); |
|
|
|
|
EXPECT_TRUE(wire_writer.RpcCall(tx).ok()); |
|
|
|
|
sequence_number++; |
|
|
|
|
tx_code++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Really large message
|
|
|
|
|
{ |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, |
|
|
|
|
WriteInt32(kFlagMessageData | kFlagMessageDataIsPartial)); |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(0)); |
|
|
|
|
ExpectWriteByteArray(std::string(WireWriterImpl::kBlockSize, 'a')); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, |
|
|
|
|
Transact(BinderTransportTxCode(kFirstCallId + 2))); |
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, |
|
|
|
|
WriteInt32(kFlagMessageData | kFlagMessageDataIsPartial)); |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(1)); |
|
|
|
|
ExpectWriteByteArray(std::string(WireWriterImpl::kBlockSize, 'a')); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, |
|
|
|
|
Transact(BinderTransportTxCode(kFirstCallId + 2))); |
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(kFlagMessageData)); |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(2)); |
|
|
|
|
ExpectWriteByteArray("a"); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, |
|
|
|
|
Transact(BinderTransportTxCode(kFirstCallId + 2))); |
|
|
|
|
|
|
|
|
|
// Use a new stream.
|
|
|
|
|
Transaction tx(kFirstCallId + 2, /*is_client=*/true); |
|
|
|
|
tx.SetData(std::string(2 * WireWriterImpl::kBlockSize + 1, 'a')); |
|
|
|
|
EXPECT_TRUE(wire_writer.RpcCall(tx).ok()); |
|
|
|
|
} |
|
|
|
|
// Really large message with metadata
|
|
|
|
|
{ |
|
|
|
|
EXPECT_CALL( |
|
|
|
|
mock_writable_parcel, |
|
|
|
|
WriteInt32(kFlagPrefix | kFlagMessageData | kFlagMessageDataIsPartial)); |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(0)); |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteString(absl::string_view("123"))); |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(0)); |
|
|
|
|
ExpectWriteByteArray(std::string(WireWriterImpl::kBlockSize, 'a')); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, |
|
|
|
|
Transact(BinderTransportTxCode(kFirstCallId + 3))); |
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, |
|
|
|
|
WriteInt32(kFlagMessageData | kFlagMessageDataIsPartial)); |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(1)); |
|
|
|
|
ExpectWriteByteArray(std::string(WireWriterImpl::kBlockSize, 'a')); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, |
|
|
|
|
Transact(BinderTransportTxCode(kFirstCallId + 3))); |
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mock_writable_parcel, |
|
|
|
|
WriteInt32(kFlagMessageData | kFlagSuffix)); |
|
|
|
|
EXPECT_CALL(mock_writable_parcel, WriteInt32(2)); |
|
|
|
|
ExpectWriteByteArray("a"); |
|
|
|
|
EXPECT_CALL(mock_binder_ref, |
|
|
|
|
Transact(BinderTransportTxCode(kFirstCallId + 3))); |
|
|
|
|
|
|
|
|
|
// Use a new stream.
|
|
|
|
|
Transaction tx(kFirstCallId + 3, /*is_client=*/true); |
|
|
|
|
tx.SetPrefix({}); |
|
|
|
|
tx.SetMethodRef("123"); |
|
|
|
|
tx.SetData(std::string(2 * WireWriterImpl::kBlockSize + 1, 'a')); |
|
|
|
|
tx.SetSuffix({}); |
|
|
|
|
EXPECT_TRUE(wire_writer.RpcCall(tx).ok()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|