Skip to content

Commit

Permalink
testing forward_as_tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaven committed May 27, 2024
1 parent c311301 commit 6dc2b54
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
39 changes: 26 additions & 13 deletions test/src/TestEthAbiWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ GTEST_TEST(TestEthAbiWriter, WriteStaticTuple)

const SimpleObjects::BaseObj& inVal1Ref = std::get<0>(inVal);
const SimpleObjects::BaseObj& inVal2Ref = std::get<1>(inVal);
auto inValRef = std::tie(inVal1Ref, inVal2Ref);
auto inValRef = std::forward_as_tuple(inVal1Ref, inVal2Ref);

EXPECT_EQ(writer.GetNumTailChunks(inValRef), 0);
TestObjWriter(
Expand Down Expand Up @@ -1112,7 +1112,8 @@ GTEST_TEST(TestEthAbiWriter, WriteDynamicTuple)

const SimpleObjects::BaseObj& inVal1Ref = std::get<0>(inVal);
const SimpleObjects::BaseObj& inVal2Ref = std::get<1>(inVal);
auto inValRef = std::tie(inVal1Ref, inVal2Ref);

auto inValRef = std::forward_as_tuple(inVal1Ref, inVal2Ref);

EXPECT_EQ(writer.GetNumTailChunks(inValRef), 6);
TestObjWriter(
Expand Down Expand Up @@ -1202,7 +1203,8 @@ GTEST_TEST(TestEthAbiWriter, WriteMixedTuple)
const SimpleObjects::BaseObj& inVal1Ref = std::get<0>(inVal);
const SimpleObjects::BaseObj& inVal2Ref = std::get<1>(inVal);
const SimpleObjects::BaseObj& inVal3Ref = std::get<2>(inVal);
auto inValRef = std::tie(inVal1Ref, inVal2Ref, inVal3Ref);

auto inValRef = std::forward_as_tuple(inVal1Ref, inVal2Ref, inVal3Ref);

EXPECT_EQ(writer.GetNumTailChunks(inValRef), 6);
TestObjWriter(
Expand Down Expand Up @@ -1277,14 +1279,17 @@ GTEST_TEST(TestEthAbiWriter, WriteMixedTuple)
const SimpleObjects::BaseObj& inVal21Ref = std::get<0>(std::get<1>(inVal));
const SimpleObjects::BaseObj& inVal22Ref = std::get<1>(std::get<1>(inVal));
const SimpleObjects::BaseObj& inVal3Ref = std::get<2>(inVal);
auto inVal2Ref = std::tie(inVal21Ref, inVal22Ref);
auto inValRef = std::tie(

const auto inValRef = std::forward_as_tuple(
inVal1Ref,
inVal2Ref,
std::forward_as_tuple(inVal21Ref, inVal22Ref),
inVal3Ref
);

const void* test = nullptr;
test = &(std::get<0>(std::get<1>(inValRef))); std::cout << test << std::endl; ASSERT_NE(test, nullptr);
EXPECT_EQ(writer.GetNumTailChunks(inValRef), 0);
test = &(std::get<0>(std::get<1>(inValRef))); std::cout << test << std::endl; ASSERT_NE(test, nullptr);
TestObjWriter(
writer,
inValRef,
Expand Down Expand Up @@ -1366,14 +1371,17 @@ GTEST_TEST(TestEthAbiWriter, WriteMixedTuple)
const SimpleObjects::BaseObj& inVal21Ref = std::get<0>(std::get<1>(inVal));
const SimpleObjects::BaseObj& inVal22Ref = std::get<1>(std::get<1>(inVal));
const SimpleObjects::BaseObj& inVal3Ref = std::get<2>(inVal);
auto inVal2Ref = std::tie(inVal21Ref, inVal22Ref);
auto inValRef = std::tie(

const auto inValRef = std::forward_as_tuple(
inVal1Ref,
inVal2Ref,
std::forward_as_tuple(inVal21Ref, inVal22Ref),
inVal3Ref
);

const void* test = nullptr;
test = &(std::get<0>(std::get<1>(inValRef))); std::cout << test << std::endl; ASSERT_NE(test, nullptr);
EXPECT_EQ(writer.GetNumTailChunks(inValRef), 7);
test = &(std::get<0>(std::get<1>(inValRef))); std::cout << test << std::endl; ASSERT_NE(test, nullptr);
TestObjWriter(
writer,
inValRef,
Expand Down Expand Up @@ -1471,15 +1479,20 @@ GTEST_TEST(TestEthAbiWriter, WriteMixedTuple)
const SimpleObjects::BaseObj& inVal221Ref = std::get<0>(std::get<1>(std::get<1>(inVal)));
const SimpleObjects::BaseObj& inVal222Ref = std::get<1>(std::get<1>(std::get<1>(inVal)));
const SimpleObjects::BaseObj& inVal3Ref = std::get<2>(inVal);
auto inVal22Ref = std::tie(inVal221Ref, inVal222Ref);
auto inVal2Ref = std::tie(inVal21Ref, inVal22Ref);
auto inValRef = std::tie(

const auto inValRef = std::forward_as_tuple(
inVal1Ref,
inVal2Ref,
std::forward_as_tuple(
inVal21Ref,
std::forward_as_tuple(inVal221Ref, inVal222Ref)
),
inVal3Ref
);

const void* test = nullptr;
test = &(std::get<0>(std::get<1>(inValRef))); std::cout << test << std::endl; ASSERT_NE(test, nullptr);
EXPECT_EQ(writer.GetNumTailChunks(inValRef), 9);
test = &(std::get<0>(std::get<1>(inValRef))); std::cout << test << std::endl; ASSERT_NE(test, nullptr);
TestObjWriter(
writer,
inValRef,
Expand Down
13 changes: 11 additions & 2 deletions test/src/TestEthTxnContractFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ GTEST_TEST(TestEthTxnContractFunc, ContractFuncStaticDef_CallByTxn)
const SimpleObjects::BaseObj& valRef3 = val3;
const SimpleObjects::BaseObj& valRef4 = val4;

auto txn = func.CallByTxn(valRef1, std::tie(valRef2, valRef3), valRef4);
auto txn = func.CallByTxn(
valRef1,
std::forward_as_tuple(valRef2, valRef3),
valRef4
);

txn.SetChainID(1900);
txn.SetNonce(34);
Expand Down Expand Up @@ -192,7 +196,12 @@ GTEST_TEST(TestEthTxnContractFunc, ContractFuncStaticDef_CallByTxn)
const SimpleObjects::BaseObj& valRef4 = val4;

auto txn = func.CallByTxn(
valRef1, std::forward_as_tuple(valRef2, std::forward_as_tuple(valRef3, valRef4)), valRef4
valRef1,
std::forward_as_tuple(
valRef2,
std::forward_as_tuple(valRef3, valRef4)
),
valRef4
);

txn.SetChainID(1900);
Expand Down

0 comments on commit 6dc2b54

Please sign in to comment.