-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract duplicated code for app test cases into AppTestContext (#10968)
- Loading branch information
Showing
23 changed files
with
371 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <app/tests/AppTestContext.h> | ||
|
||
#include <app/InteractionModelEngine.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <lib/support/ErrorStr.h> | ||
|
||
namespace chip { | ||
namespace Test { | ||
|
||
CHIP_ERROR AppContext::Init() | ||
{ | ||
ReturnErrorOnFailure(chip::Platform::MemoryInit()); | ||
ReturnErrorOnFailure(mIOContext.Init()); | ||
ReturnErrorOnFailure(mTransportManager.Init("LOOPBACK")); | ||
ReturnErrorOnFailure(MessagingContext::Init(&mTransportManager, &mIOContext)); | ||
ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->Init(&GetExchangeManager(), nullptr)); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR AppContext::Shutdown() | ||
{ | ||
ReturnErrorOnFailure(MessagingContext::Shutdown()); | ||
ReturnErrorOnFailure(mIOContext.Shutdown()); | ||
chip::Platform::MemoryShutdown(); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
} // namespace Test | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <messaging/tests/MessagingContext.h> | ||
#include <transport/raw/tests/NetworkTestHelpers.h> | ||
|
||
#include <nlunit-test.h> | ||
|
||
namespace chip { | ||
namespace Test { | ||
|
||
/** | ||
* @brief The context of test cases for messaging layer. It wil initialize network layer and system layer, and create | ||
* two secure sessions, connected with each other. Exchanges can be created for each secure session. | ||
*/ | ||
class AppContext : public MessagingContext | ||
{ | ||
public: | ||
/// Initialize the underlying layers and test suite pointer | ||
CHIP_ERROR Init(); | ||
|
||
// Shutdown all layers, finalize operations | ||
CHIP_ERROR Shutdown(); | ||
|
||
static int Initialize(void * context) | ||
{ | ||
auto * ctx = static_cast<AppContext *>(context); | ||
return ctx->Init() == CHIP_NO_ERROR ? SUCCESS : FAILURE; | ||
} | ||
|
||
static int Finalize(void * context) | ||
{ | ||
auto * ctx = static_cast<AppContext *>(context); | ||
return ctx->Shutdown() == CHIP_NO_ERROR ? SUCCESS : FAILURE; | ||
} | ||
|
||
private: | ||
chip::TransportMgr<chip::Test::LoopbackTransport> mTransportManager; | ||
chip::Test::IOContext mIOContext; | ||
}; | ||
|
||
} // namespace Test | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.