-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IC-Device] Initial implementation of Client Monitoring Registration …
…table (#24096) * Client Monitoring table implementation * CM table tests * Add sub-struct to add a validation function Add unit test for invalid values * Address PR comments * Apply suggestions from code review Co-authored-by: Boris Zbarsky <[email protected]> * Increase max unit test limit * Apply suggestions from code review Co-authored-by: Damian Królik <[email protected]> * Move comments to headeR * update test assert * Add provisional comment * restyle Co-authored-by: Boris Zbarsky <[email protected]> Co-authored-by: Damian Królik <[email protected]>
- Loading branch information
Showing
7 changed files
with
237 additions
and
48 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
141 changes: 141 additions & 0 deletions
141
src/app/tests/TestClientMonitoringRegistrationTable.cpp
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,141 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 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/util/ClientMonitoringRegistrationTable.h> | ||
#include <lib/core/CHIPError.h> | ||
#include <lib/support/DefaultStorageKeyAllocator.h> | ||
#include <lib/support/TestPersistentStorageDelegate.h> | ||
#include <lib/support/UnitTestRegistration.h> | ||
#include <nlunit-test.h> | ||
|
||
using chip::ClientMonitoringRegistrationTable; | ||
using chip::NullOptional; | ||
|
||
namespace { | ||
|
||
constexpr chip::FabricIndex kTestFabricIndex = 1; | ||
constexpr uint64_t kTestICid = 10; | ||
constexpr chip::NodeId kTestClientNodeId = 11; | ||
|
||
constexpr chip::FabricIndex kTestFabricIndex_2 = 2; | ||
constexpr uint64_t kTestICid_2 = 20; | ||
constexpr chip::NodeId kTestClientNodeId_2 = 21; | ||
|
||
void TestDefaultClientValues(nlTestSuite * aSuite, void * aContext) | ||
{ | ||
chip::TestPersistentStorageDelegate testStorage; | ||
ClientMonitoringRegistrationTable registration(testStorage); | ||
|
||
NL_TEST_ASSERT(aSuite, !registration.GetClientRegistrationEntry().IsValid()); | ||
NL_TEST_ASSERT(aSuite, registration.GetClientRegistrationEntry().clientNodeId == chip::kUndefinedFabricIndex); | ||
NL_TEST_ASSERT(aSuite, registration.GetClientRegistrationEntry().ICid == chip::kUndefinedNodeId); | ||
NL_TEST_ASSERT(aSuite, registration.GetClientRegistrationEntry().fabricIndex == chip::kInvalidIcId); | ||
} | ||
|
||
void TestLoadFromStorageEmptyValue(nlTestSuite * aSuite, void * aContext) | ||
{ | ||
chip::TestPersistentStorageDelegate testStorage; | ||
ClientMonitoringRegistrationTable registration(testStorage); | ||
|
||
CHIP_ERROR err = registration.LoadFromStorage(kTestFabricIndex); | ||
NL_TEST_ASSERT(aSuite, err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); | ||
} | ||
|
||
void TestSaveAndLoadRegistrationValue(nlTestSuite * aSuite, void * aContext) | ||
{ | ||
chip::TestPersistentStorageDelegate testStorage; | ||
ClientMonitoringRegistrationTable savedRegistration(testStorage); | ||
ClientMonitoringRegistrationTable loadedRegistration(testStorage); | ||
|
||
savedRegistration.GetClientRegistrationEntry().clientNodeId = kTestClientNodeId; | ||
savedRegistration.GetClientRegistrationEntry().ICid = kTestICid; | ||
savedRegistration.GetClientRegistrationEntry().fabricIndex = kTestFabricIndex; | ||
|
||
CHIP_ERROR err = savedRegistration.SaveToStorage(); | ||
NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); | ||
|
||
err = loadedRegistration.LoadFromStorage(kTestFabricIndex); | ||
NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); | ||
|
||
NL_TEST_ASSERT(aSuite, loadedRegistration.GetClientRegistrationEntry().clientNodeId == kTestClientNodeId); | ||
NL_TEST_ASSERT(aSuite, loadedRegistration.GetClientRegistrationEntry().ICid == kTestICid); | ||
NL_TEST_ASSERT(aSuite, loadedRegistration.GetClientRegistrationEntry().fabricIndex == kTestFabricIndex); | ||
} | ||
|
||
void TestSaveLoadRegistrationValueForMultipleFabrics(nlTestSuite * aSuite, void * aContexT) | ||
{ | ||
chip::TestPersistentStorageDelegate testStorage; | ||
ClientMonitoringRegistrationTable savedRegistration(testStorage); | ||
ClientMonitoringRegistrationTable loadedRegistration(testStorage); | ||
|
||
savedRegistration.GetClientRegistrationEntry().clientNodeId = kTestClientNodeId; | ||
savedRegistration.GetClientRegistrationEntry().ICid = kTestICid; | ||
savedRegistration.GetClientRegistrationEntry().fabricIndex = kTestFabricIndex; | ||
|
||
CHIP_ERROR err = savedRegistration.SaveToStorage(); | ||
NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); | ||
|
||
savedRegistration.GetClientRegistrationEntry().clientNodeId = kTestClientNodeId_2; | ||
savedRegistration.GetClientRegistrationEntry().ICid = kTestICid_2; | ||
savedRegistration.GetClientRegistrationEntry().fabricIndex = kTestFabricIndex_2; | ||
|
||
err = savedRegistration.SaveToStorage(); | ||
NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); | ||
|
||
err = loadedRegistration.LoadFromStorage(kTestFabricIndex); | ||
NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); | ||
|
||
NL_TEST_ASSERT(aSuite, loadedRegistration.GetClientRegistrationEntry().clientNodeId == kTestClientNodeId); | ||
NL_TEST_ASSERT(aSuite, loadedRegistration.GetClientRegistrationEntry().ICid == kTestICid); | ||
NL_TEST_ASSERT(aSuite, loadedRegistration.GetClientRegistrationEntry().fabricIndex == kTestFabricIndex); | ||
|
||
err = loadedRegistration.LoadFromStorage(kTestFabricIndex_2); | ||
NL_TEST_ASSERT(aSuite, err == CHIP_NO_ERROR); | ||
|
||
NL_TEST_ASSERT(aSuite, loadedRegistration.GetClientRegistrationEntry().clientNodeId == kTestClientNodeId_2); | ||
NL_TEST_ASSERT(aSuite, loadedRegistration.GetClientRegistrationEntry().ICid == kTestICid_2); | ||
NL_TEST_ASSERT(aSuite, loadedRegistration.GetClientRegistrationEntry().fabricIndex == kTestFabricIndex_2); | ||
} | ||
|
||
void TestSaveAllInvalidRegistrationValues(nlTestSuite * aSuite, void * context) | ||
{ | ||
chip::TestPersistentStorageDelegate testStorage; | ||
ClientMonitoringRegistrationTable registration(testStorage); | ||
|
||
CHIP_ERROR err = registration.SaveToStorage(); | ||
NL_TEST_ASSERT(aSuite, err == CHIP_ERROR_INCORRECT_STATE); | ||
} | ||
|
||
} // namespace | ||
|
||
int TestClientMonitoringRegistrationTable() | ||
{ | ||
static nlTest sTests[] = { NL_TEST_DEF("TestDefaultClientValues", TestDefaultClientValues), | ||
NL_TEST_DEF("TestLoadFromStorageEmptyValue", TestLoadFromStorageEmptyValue), | ||
NL_TEST_DEF("TestSaveAndLoadRegistrationValue", TestSaveAndLoadRegistrationValue), | ||
NL_TEST_DEF("TestSaveAllInvalidRegistrationValues", TestSaveAllInvalidRegistrationValues), | ||
NL_TEST_DEF("TestSaveLoadRegistrationValueForMultipleFabrics", | ||
TestSaveLoadRegistrationValueForMultipleFabrics), | ||
NL_TEST_SENTINEL() }; | ||
|
||
nlTestSuite cmSuite = { "TestClientMonitoringRegistrationTable", &sTests[0], nullptr, nullptr }; | ||
|
||
nlTestRunner(&cmSuite, nullptr); | ||
return (nlTestRunnerStats(&cmSuite)); | ||
} | ||
|
||
CHIP_REGISTER_TEST_SUITE(TestClientMonitoringRegistrationTable) |
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
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
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
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
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