@ -29,29 +29,6 @@
namespace grpc_binder {
namespace grpc_binder {
namespace end2end_testing {
namespace end2end_testing {
TEST ( FakeBinderTestWithoutTransaction , WritableParcelDataPosition ) {
std : : unique_ptr < WritableParcel > parcel =
absl : : make_unique < FakeWritableParcel > ( ) ;
EXPECT_EQ ( parcel - > GetDataPosition ( ) , 0 ) ;
EXPECT_TRUE ( parcel - > WriteInt32 ( 0 ) . ok ( ) ) ;
EXPECT_EQ ( parcel - > GetDataPosition ( ) , 1 ) ;
EXPECT_TRUE ( parcel - > WriteInt32 ( 1 ) . ok ( ) ) ;
EXPECT_TRUE ( parcel - > WriteInt32 ( 2 ) . ok ( ) ) ;
EXPECT_EQ ( parcel - > GetDataPosition ( ) , 3 ) ;
EXPECT_TRUE ( parcel - > WriteString ( " " ) . ok ( ) ) ;
EXPECT_EQ ( parcel - > GetDataPosition ( ) , 4 ) ;
EXPECT_TRUE ( parcel - > SetDataPosition ( 0 ) . ok ( ) ) ;
const char kBuffer [ ] = " test " ;
EXPECT_TRUE ( parcel
- > WriteByteArray ( reinterpret_cast < const int8_t * > ( kBuffer ) ,
strlen ( kBuffer ) )
. ok ( ) ) ;
EXPECT_EQ ( parcel - > GetDataPosition ( ) , 1 ) ;
EXPECT_TRUE ( parcel - > SetDataPosition ( 100 ) . ok ( ) ) ;
EXPECT_EQ ( parcel - > GetDataPosition ( ) , 100 ) ;
}
namespace {
namespace {
class FakeBinderTest : public : : testing : : TestWithParam < absl : : Duration > {
class FakeBinderTest : public : : testing : : TestWithParam < absl : : Duration > {
@ -70,8 +47,8 @@ TEST_P(FakeBinderTest, SendInt32) {
int called = 0 ;
int called = 0 ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : tie ( sender , tx_receiver ) = NewBinderPair (
std : : tie ( sender , tx_receiver ) =
[ & ] ( transaction_code_t tx_code , const ReadableParcel * parcel ) {
NewBinderPair ( [ & ] ( transaction_code_t tx_code , ReadableParcel * parcel ) {
EXPECT_EQ ( tx_code , kTxCode ) ;
EXPECT_EQ ( tx_code , kTxCode ) ;
int value = 0 ;
int value = 0 ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value ) . ok ( ) ) ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value ) . ok ( ) ) ;
@ -95,8 +72,8 @@ TEST_P(FakeBinderTest, SendString) {
int called = 0 ;
int called = 0 ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : tie ( sender , tx_receiver ) = NewBinderPair (
std : : tie ( sender , tx_receiver ) =
[ & ] ( transaction_code_t tx_code , const ReadableParcel * parcel ) {
NewBinderPair ( [ & ] ( transaction_code_t tx_code , ReadableParcel * parcel ) {
EXPECT_EQ ( tx_code , kTxCode ) ;
EXPECT_EQ ( tx_code , kTxCode ) ;
std : : string value ;
std : : string value ;
EXPECT_TRUE ( parcel - > ReadString ( & value ) . ok ( ) ) ;
EXPECT_TRUE ( parcel - > ReadString ( & value ) . ok ( ) ) ;
@ -120,8 +97,8 @@ TEST_P(FakeBinderTest, SendByteArray) {
int called = 0 ;
int called = 0 ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : tie ( sender , tx_receiver ) = NewBinderPair (
std : : tie ( sender , tx_receiver ) =
[ & ] ( transaction_code_t tx_code , const ReadableParcel * parcel ) {
NewBinderPair ( [ & ] ( transaction_code_t tx_code , ReadableParcel * parcel ) {
EXPECT_EQ ( tx_code , kTxCode ) ;
EXPECT_EQ ( tx_code , kTxCode ) ;
std : : string value ;
std : : string value ;
EXPECT_TRUE ( parcel - > ReadByteArray ( & value ) . ok ( ) ) ;
EXPECT_TRUE ( parcel - > ReadByteArray ( & value ) . ok ( ) ) ;
@ -150,8 +127,8 @@ TEST_P(FakeBinderTest, SendMultipleItems) {
int called = 0 ;
int called = 0 ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : tie ( sender , tx_receiver ) = NewBinderPair (
std : : tie ( sender , tx_receiver ) =
[ & ] ( transaction_code_t tx_code , const ReadableParcel * parcel ) {
NewBinderPair ( [ & ] ( transaction_code_t tx_code , ReadableParcel * parcel ) {
int value_result ;
int value_result ;
EXPECT_EQ ( tx_code , kTxCode ) ;
EXPECT_EQ ( tx_code , kTxCode ) ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value_result ) . ok ( ) ) ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value_result ) . ok ( ) ) ;
@ -186,8 +163,8 @@ TEST_P(FakeBinderTest, SendBinder) {
int called = 0 ;
int called = 0 ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < Binder > sender ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : tie ( sender , tx_receiver ) = NewBinderPair (
std : : tie ( sender , tx_receiver ) =
[ & ] ( transaction_code_t tx_code , const ReadableParcel * parcel ) {
NewBinderPair ( [ & ] ( transaction_code_t tx_code , ReadableParcel * parcel ) {
EXPECT_EQ ( tx_code , kTxCode ) ;
EXPECT_EQ ( tx_code , kTxCode ) ;
std : : unique_ptr < Binder > binder ;
std : : unique_ptr < Binder > binder ;
EXPECT_TRUE ( parcel - > ReadBinder ( & binder ) . ok ( ) ) ;
EXPECT_TRUE ( parcel - > ReadBinder ( & binder ) . ok ( ) ) ;
@ -202,8 +179,7 @@ TEST_P(FakeBinderTest, SendBinder) {
int called2 = 0 ;
int called2 = 0 ;
std : : unique_ptr < TransactionReceiver > tx_receiver2 =
std : : unique_ptr < TransactionReceiver > tx_receiver2 =
absl : : make_unique < FakeTransactionReceiver > (
absl : : make_unique < FakeTransactionReceiver > (
nullptr ,
nullptr , [ & ] ( transaction_code_t tx_code , ReadableParcel * parcel ) {
[ & ] ( transaction_code_t tx_code , const ReadableParcel * parcel ) {
int value ;
int value ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value ) . ok ( ) ) ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value ) . ok ( ) ) ;
EXPECT_EQ ( value , kValue ) ;
EXPECT_EQ ( value , kValue ) ;
@ -228,8 +204,8 @@ TEST_P(FakeBinderTest, SendTransactionAfterDestruction) {
int called = 0 ;
int called = 0 ;
{
{
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : tie ( sender , tx_receiver ) = NewBinderPair (
std : : tie ( sender , tx_receiver ) =
[ & ] ( transaction_code_t tx_code , const ReadableParcel * parcel ) {
NewBinderPair ( [ & ] ( transaction_code_t tx_code , ReadableParcel * parcel ) {
EXPECT_EQ ( tx_code , kTxCode ) ;
EXPECT_EQ ( tx_code , kTxCode ) ;
int value ;
int value ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value ) . ok ( ) ) ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value ) . ok ( ) ) ;
@ -299,10 +275,9 @@ TEST_P(FakeBinderTest, StressTest) {
std : : unique_ptr < TransactionReceiver > tx_receiver ;
std : : unique_ptr < TransactionReceiver > tx_receiver ;
int expected_tx_code = th_arg - > tx_code ;
int expected_tx_code = th_arg - > tx_code ;
std : : vector < std : : vector < int > > * cnt = th_arg - > global_cnts ;
std : : vector < std : : vector < int > > * cnt = th_arg - > global_cnts ;
std : : tie ( binder , tx_receiver ) =
std : : tie ( binder , tx_receiver ) = NewBinderPair (
NewBinderPair ( [ tid , p , cnt , expected_tx_code ] (
[ tid , p , cnt , expected_tx_code ] ( transaction_code_t tx_code ,
transaction_code_t tx_code ,
ReadableParcel * parcel ) mutable {
const ReadableParcel * parcel ) mutable {
EXPECT_EQ ( tx_code , expected_tx_code ) ;
EXPECT_EQ ( tx_code , expected_tx_code ) ;
int value ;
int value ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value ) . ok ( ) ) ;
EXPECT_TRUE ( parcel - > ReadInt32 ( & value ) . ok ( ) ) ;