Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Local and Peer in message tests into Alice and Bob #9561

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/app/tests/TestReadInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void TestReadInteraction::TestReadClient(nlTestSuite * apSuite, void * apContext
System::PacketBufferHandle buf = System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize);
err = readClient.Init(&ctx.GetExchangeManager(), &delegate, 0 /* application identifier */);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
ReadPrepareParams readPrepareParams(ctx.GetSessionLocalToPeer());
ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice());
err = readClient.SendReadRequest(readPrepareParams);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

Expand All @@ -347,7 +347,7 @@ void TestReadInteraction::TestReadHandler(nlTestSuite * apSuite, void * apContex
auto * engine = chip::app::InteractionModelEngine::GetInstance();
err = engine->Init(&ctx.GetExchangeManager(), &delegate);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
Messaging::ExchangeContext * exchangeCtx = ctx.NewExchangeToPeer(nullptr);
Messaging::ExchangeContext * exchangeCtx = ctx.NewExchangeToAlice(nullptr);
readHandler.Init(&ctx.GetExchangeManager(), nullptr, exchangeCtx);

GenerateReportData(apSuite, apContext, reportDatabuf);
Expand Down Expand Up @@ -449,7 +449,7 @@ void TestReadInteraction::TestReadClientInvalidReport(nlTestSuite * apSuite, voi
err = readClient.Init(&ctx.GetExchangeManager(), &delegate, 0 /* application identifier */);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

ReadPrepareParams readPrepareParams(ctx.GetSessionLocalToPeer());
ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice());
err = readClient.SendReadRequest(readPrepareParams);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

Expand All @@ -475,7 +475,7 @@ void TestReadInteraction::TestReadHandlerInvalidAttributePath(nlTestSuite * apSu
auto * engine = chip::app::InteractionModelEngine::GetInstance();
err = engine->Init(&ctx.GetExchangeManager(), &delegate);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
Messaging::ExchangeContext * exchangeCtx = ctx.NewExchangeToPeer(nullptr);
Messaging::ExchangeContext * exchangeCtx = ctx.NewExchangeToAlice(nullptr);
readHandler.Init(&ctx.GetExchangeManager(), nullptr, exchangeCtx);

GenerateReportData(apSuite, apContext, reportDatabuf);
Expand Down Expand Up @@ -656,7 +656,7 @@ void TestReadInteraction::TestReadRoundtrip(nlTestSuite * apSuite, void * apCont
attributePathParams[1].mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);
attributePathParams[1].mFlags.Set(chip::app::AttributePathParams::Flags::kListIndexValid);

ReadPrepareParams readPrepareParams(ctx.GetSessionLocalToPeer());
ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice());
readPrepareParams.mpEventPathParamsList = eventPathParams;
readPrepareParams.mEventPathParamsListSize = 2;
readPrepareParams.mpAttributePathParamsList = attributePathParams;
Expand Down Expand Up @@ -701,7 +701,7 @@ void TestReadInteraction::TestReadInvalidAttributePathRoundtrip(nlTestSuite * ap
attributePathParams[0].mListIndex = 0;
attributePathParams[0].mFlags.Set(chip::app::AttributePathParams::Flags::kFieldIdValid);

ReadPrepareParams readPrepareParams(ctx.GetSessionLocalToPeer());
ReadPrepareParams readPrepareParams(ctx.GetSessionBobToAlice());
readPrepareParams.mpAttributePathParamsList = attributePathParams;
readPrepareParams.mAttributePathParamsListSize = 1;
err = chip::app::InteractionModelEngine::GetInstance()->SendReadRequest(readPrepareParams);
Expand Down
11 changes: 5 additions & 6 deletions src/app/tests/TestWriteInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ void TestWriteInteraction::TestWriteClient(nlTestSuite * apSuite, void * apConte
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
AddAttributeDataElement(apSuite, apContext, writeClientHandle);

SessionHandle session = ctx.GetSessionLocalToPeer();
err = writeClientHandle.SendWriteRequest(ctx.GetDestinationNodeId(), ctx.GetFabricIndex(),
Optional<SessionHandle>::Value(session));
SessionHandle session = ctx.GetSessionBobToAlice();
err = writeClientHandle.SendWriteRequest(ctx.GetAliceNodeId(), ctx.GetFabricIndex(), Optional<SessionHandle>::Value(session));
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
// The internal WriteClient should be nullptr once we SendWriteRequest.
NL_TEST_ASSERT(apSuite, nullptr == writeClientHandle.mpWriteClient);
Expand Down Expand Up @@ -249,7 +248,7 @@ void TestWriteInteraction::TestWriteHandler(nlTestSuite * apSuite, void * apCont
GenerateWriteRequest(apSuite, apContext, buf);

TestExchangeDelegate delegate;
Messaging::ExchangeContext * exchange = ctx.NewExchangeToLocal(&delegate);
Messaging::ExchangeContext * exchange = ctx.NewExchangeToBob(&delegate);
err = writeHandler.OnWriteRequest(exchange, std::move(buf));
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

Expand Down Expand Up @@ -305,9 +304,9 @@ void TestWriteInteraction::TestWriteRoundtrip(nlTestSuite * apSuite, void * apCo

NL_TEST_ASSERT(apSuite, !delegate.mGotResponse);

SessionHandle session = ctx.GetSessionLocalToPeer();
SessionHandle session = ctx.GetSessionBobToAlice();

err = writeClient.SendWriteRequest(ctx.GetDestinationNodeId(), ctx.GetFabricIndex(), Optional<SessionHandle>::Value(session));
err = writeClient.SendWriteRequest(ctx.GetAliceNodeId(), ctx.GetFabricIndex(), Optional<SessionHandle>::Value(session));
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

NL_TEST_ASSERT(apSuite, delegate.mGotResponse);
Expand Down
20 changes: 10 additions & 10 deletions src/messaging/tests/MessagingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ CHIP_ERROR MessagingContext::Init(nlTestSuite * suite, TransportMgrBase * transp
ReturnErrorOnFailure(mExchangeManager.Init(&mSecureSessionMgr));
ReturnErrorOnFailure(mMessageCounterManager.Init(&mExchangeManager));

ReturnErrorOnFailure(mSecureSessionMgr.NewPairing(mPeer, GetDestinationNodeId(), &mPairingLocalToPeer,
ReturnErrorOnFailure(mSecureSessionMgr.NewPairing(mAddress, GetAliceNodeId(), &mPairingBobToAlice,
SecureSession::SessionRole::kInitiator, mSrcFabricIndex));

return mSecureSessionMgr.NewPairing(mPeer, GetSourceNodeId(), &mPairingPeerToLocal, SecureSession::SessionRole::kResponder,
return mSecureSessionMgr.NewPairing(mAddress, GetBobNodeId(), &mPairingAliceToBob, SecureSession::SessionRole::kResponder,
mDestFabricIndex);
}

Expand All @@ -55,28 +55,28 @@ CHIP_ERROR MessagingContext::Shutdown()
return CHIP_NO_ERROR;
}

SessionHandle MessagingContext::GetSessionLocalToPeer()
SessionHandle MessagingContext::GetSessionBobToAlice()
{
// TODO: temporarily create a SessionHandle from node id, will be fixed in PR 3602
return SessionHandle(GetDestinationNodeId(), GetLocalKeyId(), GetPeerKeyId(), GetFabricIndex());
return SessionHandle(GetAliceNodeId(), GetBobKeyId(), GetAliceKeyId(), GetFabricIndex());
}

SessionHandle MessagingContext::GetSessionPeerToLocal()
SessionHandle MessagingContext::GetSessionAliceToBob()
{
// TODO: temporarily create a SessionHandle from node id, will be fixed in PR 3602
return SessionHandle(GetSourceNodeId(), GetPeerKeyId(), GetLocalKeyId(), mDestFabricIndex);
return SessionHandle(GetBobNodeId(), GetAliceKeyId(), GetBobKeyId(), mDestFabricIndex);
}

Messaging::ExchangeContext * MessagingContext::NewExchangeToPeer(Messaging::ExchangeDelegate * delegate)
Messaging::ExchangeContext * MessagingContext::NewExchangeToAlice(Messaging::ExchangeDelegate * delegate)
{
// TODO: temprary create a SessionHandle from node id, will be fix in PR 3602
return mExchangeManager.NewContext(GetSessionLocalToPeer(), delegate);
return mExchangeManager.NewContext(GetSessionBobToAlice(), delegate);
}

Messaging::ExchangeContext * MessagingContext::NewExchangeToLocal(Messaging::ExchangeDelegate * delegate)
Messaging::ExchangeContext * MessagingContext::NewExchangeToBob(Messaging::ExchangeDelegate * delegate)
{
// TODO: temprary create a SessionHandle from node id, will be fix in PR 3602
return mExchangeManager.NewContext(GetSessionPeerToLocal(), delegate);
return mExchangeManager.NewContext(GetSessionAliceToBob(), delegate);
}

} // namespace Test
Expand Down
42 changes: 21 additions & 21 deletions src/messaging/tests/MessagingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class MessagingContext
{
public:
MessagingContext() :
mInitialized(false), mPeer(Transport::PeerAddress::UDP(GetAddress(), CHIP_PORT)),
mPairingPeerToLocal(GetLocalKeyId(), GetPeerKeyId()), mPairingLocalToPeer(GetPeerKeyId(), GetLocalKeyId())
mInitialized(false), mAddress(Transport::PeerAddress::UDP(GetAddress(), CHIP_PORT)),
mPairingAliceToBob(GetBobKeyId(), GetAliceKeyId()), mPairingBobToAlice(GetAliceKeyId(), GetBobKeyId())
{}
~MessagingContext() { VerifyOrDie(mInitialized == false); }

Expand All @@ -54,17 +54,17 @@ class MessagingContext
Inet::IPAddress::FromString("127.0.0.1", addr);
return addr;
}
NodeId GetSourceNodeId() const { return mSourceNodeId; }
NodeId GetDestinationNodeId() const { return mDestinationNodeId; }
NodeId GetBobNodeId() const { return mBobNodeId; }
NodeId GetAliceNodeId() const { return mAliceNodeId; }

void SetSourceNodeId(NodeId nodeId) { mSourceNodeId = nodeId; }
void SetDestinationNodeId(NodeId nodeId) { mDestinationNodeId = nodeId; }
void SetBobNodeId(NodeId nodeId) { mBobNodeId = nodeId; }
void SetAliceNodeId(NodeId nodeId) { mAliceNodeId = nodeId; }

uint16_t GetLocalKeyId() const { return mLocalKeyId; }
uint16_t GetPeerKeyId() const { return mPeerKeyId; }
uint16_t GetBobKeyId() const { return mBobKeyId; }
uint16_t GetAliceKeyId() const { return mAliceKeyId; }

void SetLocalKeyId(uint16_t id) { mLocalKeyId = id; }
void SetPeerKeyId(uint16_t id) { mPeerKeyId = id; }
void SetBobKeyId(uint16_t id) { mBobKeyId = id; }
void SetAliceKeyId(uint16_t id) { mAliceKeyId = id; }

FabricIndex GetFabricIndex() const { return mSrcFabricIndex; }
void SetFabricIndex(FabricIndex id)
Expand All @@ -77,11 +77,11 @@ class MessagingContext
Messaging::ExchangeManager & GetExchangeManager() { return mExchangeManager; }
secure_channel::MessageCounterManager & GetMessageCounterManager() { return mMessageCounterManager; }

SessionHandle GetSessionLocalToPeer();
SessionHandle GetSessionPeerToLocal();
SessionHandle GetSessionBobToAlice();
SessionHandle GetSessionAliceToBob();

Messaging::ExchangeContext * NewExchangeToPeer(Messaging::ExchangeDelegate * delegate);
Messaging::ExchangeContext * NewExchangeToLocal(Messaging::ExchangeDelegate * delegate);
Messaging::ExchangeContext * NewExchangeToAlice(Messaging::ExchangeDelegate * delegate);
Messaging::ExchangeContext * NewExchangeToBob(Messaging::ExchangeDelegate * delegate);

Credentials::OperationalCredentialSet & GetOperationalCredentialSet() { return mOperationalCredentialSet; }

Expand All @@ -94,13 +94,13 @@ class MessagingContext
secure_channel::MessageCounterManager mMessageCounterManager;
IOContext * mIOContext;

NodeId mSourceNodeId = 123654;
NodeId mDestinationNodeId = 111222333;
uint16_t mLocalKeyId = 1;
uint16_t mPeerKeyId = 2;
Optional<Transport::PeerAddress> mPeer;
SecurePairingUsingTestSecret mPairingPeerToLocal;
SecurePairingUsingTestSecret mPairingLocalToPeer;
NodeId mBobNodeId = 123654;
NodeId mAliceNodeId = 111222333;
uint16_t mBobKeyId = 1;
uint16_t mAliceKeyId = 2;
Optional<Transport::PeerAddress> mAddress;
SecurePairingUsingTestSecret mPairingAliceToBob;
SecurePairingUsingTestSecret mPairingBobToAlice;
Transport::FabricTable mFabrics;
FabricIndex mSrcFabricIndex = 0;
FabricIndex mDestFabricIndex = 0;
Expand Down
20 changes: 10 additions & 10 deletions src/messaging/tests/TestExchangeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ void CheckNewContextTest(nlTestSuite * inSuite, void * inContext)
TestContext & ctx = *reinterpret_cast<TestContext *>(inContext);

MockAppDelegate mockAppDelegate;
ExchangeContext * ec1 = ctx.NewExchangeToLocal(&mockAppDelegate);
ExchangeContext * ec1 = ctx.NewExchangeToBob(&mockAppDelegate);
NL_TEST_ASSERT(inSuite, ec1 != nullptr);
NL_TEST_ASSERT(inSuite, ec1->IsInitiator() == true);
NL_TEST_ASSERT(inSuite, ec1->GetExchangeId() != 0);
auto sessionPeerToLocal = ctx.GetSecureSessionManager().GetPeerConnectionState(ec1->GetSecureSession());
NL_TEST_ASSERT(inSuite, sessionPeerToLocal->GetPeerNodeId() == ctx.GetSourceNodeId());
NL_TEST_ASSERT(inSuite, sessionPeerToLocal->GetPeerKeyID() == ctx.GetLocalKeyId());
NL_TEST_ASSERT(inSuite, sessionPeerToLocal->GetPeerNodeId() == ctx.GetBobNodeId());
NL_TEST_ASSERT(inSuite, sessionPeerToLocal->GetPeerKeyID() == ctx.GetBobKeyId());
NL_TEST_ASSERT(inSuite, ec1->GetDelegate() == &mockAppDelegate);

ExchangeContext * ec2 = ctx.NewExchangeToPeer(&mockAppDelegate);
ExchangeContext * ec2 = ctx.NewExchangeToAlice(&mockAppDelegate);
NL_TEST_ASSERT(inSuite, ec2 != nullptr);
NL_TEST_ASSERT(inSuite, ec2->GetExchangeId() > ec1->GetExchangeId());
auto sessionLocalToPeer = ctx.GetSecureSessionManager().GetPeerConnectionState(ec2->GetSecureSession());
NL_TEST_ASSERT(inSuite, sessionLocalToPeer->GetPeerNodeId() == ctx.GetDestinationNodeId());
NL_TEST_ASSERT(inSuite, sessionLocalToPeer->GetPeerKeyID() == ctx.GetPeerKeyId());
NL_TEST_ASSERT(inSuite, sessionLocalToPeer->GetPeerNodeId() == ctx.GetAliceNodeId());
NL_TEST_ASSERT(inSuite, sessionLocalToPeer->GetPeerKeyID() == ctx.GetAliceKeyId());

ec1->Close();
ec2->Close();
Expand All @@ -120,7 +120,7 @@ void CheckSessionExpirationBasics(nlTestSuite * inSuite, void * inContext)
TestContext & ctx = *reinterpret_cast<TestContext *>(inContext);

MockAppDelegate sendDelegate;
ExchangeContext * ec1 = ctx.NewExchangeToLocal(&sendDelegate);
ExchangeContext * ec1 = ctx.NewExchangeToBob(&sendDelegate);

// Expire the session this exchange is supposedly on.
ctx.GetExchangeManager().OnConnectionExpired(ec1->GetSecureSession());
Expand All @@ -145,7 +145,7 @@ void CheckSessionExpirationTimeout(nlTestSuite * inSuite, void * inContext)
TestContext & ctx = *reinterpret_cast<TestContext *>(inContext);

WaitForTimeoutDelegate sendDelegate;
ExchangeContext * ec1 = ctx.NewExchangeToLocal(&sendDelegate);
ExchangeContext * ec1 = ctx.NewExchangeToBob(&sendDelegate);

ec1->SendMessage(Protocols::BDX::Id, kMsgType_TEST1, System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize),
SendFlags(Messaging::SendMessageFlags::kExpectResponse).Set(Messaging::SendMessageFlags::kNoAutoRequestAck));
Expand Down Expand Up @@ -191,7 +191,7 @@ void CheckExchangeMessages(nlTestSuite * inSuite, void * inContext)

// create solicited exchange
MockAppDelegate mockSolicitedAppDelegate;
ExchangeContext * ec1 = ctx.NewExchangeToPeer(&mockSolicitedAppDelegate);
ExchangeContext * ec1 = ctx.NewExchangeToAlice(&mockSolicitedAppDelegate);

// create unsolicited exchange
MockAppDelegate mockUnsolicitedAppDelegate;
Expand All @@ -204,7 +204,7 @@ void CheckExchangeMessages(nlTestSuite * inSuite, void * inContext)
SendFlags(Messaging::SendMessageFlags::kNoAutoRequestAck));
NL_TEST_ASSERT(inSuite, !mockUnsolicitedAppDelegate.IsOnMessageReceivedCalled);

ec1 = ctx.NewExchangeToPeer(&mockSolicitedAppDelegate);
ec1 = ctx.NewExchangeToAlice(&mockSolicitedAppDelegate);

// send a good packet
ec1->SendMessage(Protocols::BDX::Id, kMsgType_TEST1, System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize),
Expand Down
Loading