Skip to content

Commit

Permalink
Adding refactor to test file as well
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs authored and pull[bot] committed Sep 18, 2023
1 parent 1d304d6 commit 1156671
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/app/tests/TestSceneTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ void TestStoreScenes(nlTestSuite * aSuite, void * aContext)
ResetSceneTable(sceneTable);

// Test SceneHandlers
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(onOffEFS1.ID, &oo_from_cluster_cb1, &oo_to_cluster_cb1));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(lvCtrEFS1.ID, &lc_from_cluster_cb1, &lc_to_cluster_cb1));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(coCtrEFS2.ID, &cc_from_cluster_cb1, &cc_to_cluster_cb1));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(onOffEFS1.mID, &oo_from_cluster_cb1, &oo_to_cluster_cb1));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(lvCtrEFS1.mID, &lc_from_cluster_cb1, &lc_to_cluster_cb1));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(coCtrEFS2.mID, &cc_from_cluster_cb1, &cc_to_cluster_cb1));

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene1.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene2.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene3.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene4.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene5.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene1.mStorageData.mExtentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene2.mStorageData.mExtentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene3.mStorageData.mExtentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene4.mStorageData.mExtentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene5.mStorageData.mExtentsionFieldsSets));

SceneTableEntry scene;

Expand All @@ -199,23 +199,23 @@ void TestStoreScenes(nlTestSuite * aSuite, void * aContext)
// Get test
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene));
NL_TEST_ASSERT(aSuite, scene == scene1);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.mStorageData.mExtentsionFieldsSets));

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId2, scene));
NL_TEST_ASSERT(aSuite, scene == scene2);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.mStorageData.mExtentsionFieldsSets));

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId3, scene));
NL_TEST_ASSERT(aSuite, scene == scene3);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.mStorageData.mExtentsionFieldsSets));

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId4, scene));
NL_TEST_ASSERT(aSuite, scene == scene4);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.mStorageData.mExtentsionFieldsSets));

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene));
NL_TEST_ASSERT(aSuite, scene == scene5);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.mStorageData.mExtentsionFieldsSets));

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId6, scene));
NL_TEST_ASSERT(aSuite, scene == scene6);
Expand All @@ -231,13 +231,13 @@ void TestOverwriteScenes(nlTestSuite * aSuite, void * aContext)
NL_TEST_ASSERT(aSuite, sceneTable);

// Test SceneHandlers overwrite
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(onOffEFS2.ID, &oo_from_cluster_cb2, &oo_to_cluster_cb2));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(lvCtrEFS2.ID, &lc_from_cluster_cb2, &lc_to_cluster_cb2));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(coCtrEFS2.ID, &cc_from_cluster_cb2, &cc_to_cluster_cb2));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(onOffEFS2.mID, &oo_from_cluster_cb2, &oo_to_cluster_cb2));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(lvCtrEFS2.mID, &lc_from_cluster_cb2, &lc_to_cluster_cb2));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->registerHandler(coCtrEFS2.mID, &cc_from_cluster_cb2, &cc_to_cluster_cb2));

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene10.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene11.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene12.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene10.mStorageData.mExtentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene11.mStorageData.mExtentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesFromCluster(scene12.mStorageData.mExtentsionFieldsSets));

// Verfies the overwrite hasn't changed the handlers number
NL_TEST_ASSERT(aSuite, sceneTable->getHandlerNum() == 3);
Expand All @@ -253,15 +253,15 @@ void TestOverwriteScenes(nlTestSuite * aSuite, void * aContext)
// Scene 10 has the same sceneId as scene 1, Get->sceneId1 should thus return scene 10, etc.
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId1, scene));
NL_TEST_ASSERT(aSuite, scene == scene10);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.mStorageData.mExtentsionFieldsSets));

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId5, scene));
NL_TEST_ASSERT(aSuite, scene == scene11);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.mStorageData.mExtentsionFieldsSets));

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId8, scene));
NL_TEST_ASSERT(aSuite, scene == scene12);
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.storageData.extentsionFieldsSets));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->EFSValuesToCluster(scene.mStorageData.mExtentsionFieldsSets));
}

void TestIterateScenes(nlTestSuite * aSuite, void * aContext)
Expand Down Expand Up @@ -306,7 +306,7 @@ void TestRemoveScenes(nlTestSuite * aSuite, void * aContext)
SceneTableEntry scene;

// Remove middle
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene5.storageId));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene5.mStorageId));
auto * iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 7);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
Expand All @@ -320,59 +320,59 @@ void TestRemoveScenes(nlTestSuite * aSuite, void * aContext)
NL_TEST_ASSERT(aSuite, scene == scene9);

// Remove the recently added scene 9
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene9.storageId));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene9.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 7);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene10);

// Remove first
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene1.storageId));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene1.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 6);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene2);

// Remove Next
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene3.storageId));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene3.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 5);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene2);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene4);

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene2.storageId));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene2.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 4);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene4);

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene4.storageId));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene4.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 3);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene6);

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene6.storageId));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene6.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 2);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene7);

NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene7.storageId));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene7.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 1);
NL_TEST_ASSERT(aSuite, iterator->Next(scene));
NL_TEST_ASSERT(aSuite, scene == scene12);

// Remove last
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene8.storageId));
NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene8.mStorageId));
iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 0);
NL_TEST_ASSERT(aSuite, iterator->Next(scene) == false);

NL_TEST_ASSERT(aSuite, CHIP_ERROR_NOT_FOUND == sceneTable->RemoveSceneTableEntry(kFabric1, scene8.storageId));
NL_TEST_ASSERT(aSuite, CHIP_ERROR_NOT_FOUND == sceneTable->RemoveSceneTableEntry(kFabric1, scene8.mStorageId));

iterator = sceneTable->IterateSceneEntry(kFabric1);
NL_TEST_ASSERT(aSuite, iterator->Count() == 0);
Expand Down

0 comments on commit 1156671

Please sign in to comment.