RDKB-65004: Refactor gtest testcases in source test application#79
Open
jayasrikadiyal wants to merge 1 commit into
Open
RDKB-65004: Refactor gtest testcases in source test application#79jayasrikadiyal wants to merge 1 commit into
jayasrikadiyal wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the advanced security gtest “source test application” by centralizing common mock setup/teardown in a shared base fixture and replacing repeated per-test malloc/free blocks with shared agent allocation/deallocation helpers.
Changes:
- Introduces
CcspAdvSecurityBaseFixtureto consolidate common mockSetUp()/TearDown()across test suites. - Adds
AllocateAdvSecAgent()/DeallocateAdvSecAgent()helpers and updates DML, internal, and webconfig tests to use them. - Removes dead commented-out test blocks and standardizes some allocation patterns.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| source/test/CcspAdvSecurityDmlTest/CcspAdvSecurityWebconfigTest.cpp | Switches the suite to the shared base fixture and replaces manual agent allocation/free with shared helpers. |
| source/test/CcspAdvSecurityDmlTest/CcspAdvSecurityMock.h | Adds the shared base fixture plus shared agent allocation/deallocation and sentinel-file helpers. |
| source/test/CcspAdvSecurityDmlTest/CcspAdvSecurityInternalTest.cpp | Refactors internal tests to inherit from the shared base fixture and use shared agent allocation/deallocation. |
| source/test/CcspAdvSecurityDmlTest/CcspAdvSecurityDmlTest.cpp | Refactors DML tests to inherit from the shared base fixture and use shared agent allocation/deallocation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+148
to
+152
| // Helper to allocate g_pAdvSecAgent with all sub-structures (zero-initialized) | ||
| inline void AllocateAdvSecAgent() { | ||
| g_pAdvSecAgent = (COSA_DATAMODEL_AGENT *)calloc(1, sizeof(COSA_DATAMODEL_AGENT)); | ||
| ASSERT_NE(g_pAdvSecAgent, nullptr); | ||
| g_pAdvSecAgent->pAdvSec = (COSA_DATAMODEL_ADVSEC *)calloc(1, sizeof(COSA_DATAMODEL_ADVSEC)); |
Comment on lines
+166
to
+178
| // Helper to deallocate g_pAdvSecAgent and all sub-structures | ||
| inline void DeallocateAdvSecAgent() { | ||
| if (g_pAdvSecAgent) { | ||
| if (g_pAdvSecAgent->pAdvSec) { | ||
| free(g_pAdvSecAgent->pAdvSec->pSoftFlowd); | ||
| free(g_pAdvSecAgent->pAdvSec->pSafeBrows); | ||
| free(g_pAdvSecAgent->pAdvSec); | ||
| } | ||
| free(g_pAdvSecAgent->pAdvPC); | ||
| free(g_pAdvSecAgent->pPrivProt); | ||
| free(g_pAdvSecAgent->pRabid); | ||
| free(g_pAdvSecAgent); | ||
| g_pAdvSecAgent = nullptr; |
Comment on lines
+296
to
299
| AllocateAdvSecAgent(); | ||
|
|
||
| g_pAdvSecAgent->pRaptr_RFC->bEnable = TRUE; | ||
|
|
Comment on lines
+1862
to
1867
| AllocateAdvSecAgent(); | ||
| g_pAdvSecAgent->bEnable = TRUE; | ||
|
|
||
| g_pAdvSecAgent->pAdvSecUserSpace_RFC = (COSA_DATAMODEL_ADVSECUSERSPACE_RFC *)malloc(sizeof(COSA_DATAMODEL_ADVSECUSERSPACE_RFC)); | ||
| ASSERT_NE(g_pAdvSecAgent->pAdvSecUserSpace_RFC, nullptr); | ||
| g_pAdvSecAgent->pAdvSecUserSpace_RFC->bEnable = TRUE; | ||
|
|
||
| g_pAdvSecAgent->pAdvWifiDataCollection_RFC = (COSA_DATAMODEL_ADVSECWIFIDATACOLLECTION_RFC *)malloc(sizeof(COSA_DATAMODEL_ADVSECWIFIDATACOLLECTION_RFC)); | ||
| ASSERT_NE(g_pAdvSecAgent->pAdvWifiDataCollection_RFC, nullptr); | ||
| g_pAdvSecAgent->pAdvWifiDataCollection_RFC->bEnable = TRUE; | ||
|
|
Comment on lines
+148
to
+165
| // Helper to allocate g_pAdvSecAgent with all sub-structures (zero-initialized) | ||
| inline void AllocateAdvSecAgent() { | ||
| g_pAdvSecAgent = (COSA_DATAMODEL_AGENT *)calloc(1, sizeof(COSA_DATAMODEL_AGENT)); | ||
| ASSERT_NE(g_pAdvSecAgent, nullptr); | ||
| g_pAdvSecAgent->pAdvSec = (COSA_DATAMODEL_ADVSEC *)calloc(1, sizeof(COSA_DATAMODEL_ADVSEC)); | ||
| ASSERT_NE(g_pAdvSecAgent->pAdvSec, nullptr); | ||
| g_pAdvSecAgent->pAdvSec->pSoftFlowd = (COSA_DATAMODEL_SOFTFLOWD *)calloc(1, sizeof(COSA_DATAMODEL_SOFTFLOWD)); | ||
| ASSERT_NE(g_pAdvSecAgent->pAdvSec->pSoftFlowd, nullptr); | ||
| g_pAdvSecAgent->pAdvSec->pSafeBrows = (COSA_DATAMODEL_SB *)calloc(1, sizeof(COSA_DATAMODEL_SB)); | ||
| ASSERT_NE(g_pAdvSecAgent->pAdvSec->pSafeBrows, nullptr); | ||
| g_pAdvSecAgent->pAdvPC = (COSA_DATAMODEL_ADVPARENTALCONTROL *)calloc(1, sizeof(COSA_DATAMODEL_ADVPARENTALCONTROL)); | ||
| ASSERT_NE(g_pAdvSecAgent->pAdvPC, nullptr); | ||
| g_pAdvSecAgent->pPrivProt = (COSA_DATAMODEL_PRIVACYPROTECTION *)calloc(1, sizeof(COSA_DATAMODEL_PRIVACYPROTECTION)); | ||
| ASSERT_NE(g_pAdvSecAgent->pPrivProt, nullptr); | ||
| g_pAdvSecAgent->pRabid = (COSA_DATAMODEL_RABID *)calloc(1, sizeof(COSA_DATAMODEL_RABID)); | ||
| ASSERT_NE(g_pAdvSecAgent->pRabid, nullptr); | ||
| } | ||
|
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validation
Jira
GitHub Issue