Skip to content

RDKB-65004: Refactor gtest testcases in source test application#79

Open
jayasrikadiyal wants to merge 1 commit into
developfrom
72-refactor-gtest-testcases
Open

RDKB-65004: Refactor gtest testcases in source test application#79
jayasrikadiyal wants to merge 1 commit into
developfrom
72-refactor-gtest-testcases

Conversation

@jayasrikadiyal
Copy link
Copy Markdown

Summary

  • extract a shared base fixture for all advanced security gtest fixtures
  • replace repeated mock setup/teardown with inherited base fixture lifecycle
  • add reusable helpers for adv security agent allocation/deallocation
  • apply allocation/deallocation helpers across DML, internal, and webconfig tests
  • standardize DeviceFingerPrint tests to C-style allocation via shared helpers
  • remove dead commented-out testcase blocks

Validation

  • static review of refactored test coverage paths and helper usage consistency
  • ensured no test assertion logic changes were introduced

Jira

  • RDKB-65004

GitHub Issue

Copilot AI review requested due to automatic review settings May 26, 2026 18:16
@jayasrikadiyal jayasrikadiyal requested review from a team as code owners May 26, 2026 18:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CcspAdvSecurityBaseFixture to consolidate common mock SetUp()/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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task: Analyse the Source Test Application and refactor the gtest testcases.

2 participants