Skip to content

Commit

Permalink
Convert TestICDManager to gtest
Browse files Browse the repository at this point in the history
  • Loading branch information
mkardous-silabs committed May 2, 2024
1 parent 335ae19 commit 22a9898
Show file tree
Hide file tree
Showing 6 changed files with 838 additions and 886 deletions.
1 change: 0 additions & 1 deletion src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ if (chip_build_tests) {
"${chip_root}/src/protocols/user_directed_commissioning/tests",
"${chip_root}/src/transport/retransmit/tests",
"${chip_root}/src/app/icd/server/tests",
"${chip_root}/src/app/icd/server/tests:tests_nltest",
]

# Skip DNSSD tests for Mbed platform due to flash memory size limitations
Expand Down
22 changes: 19 additions & 3 deletions src/app/icd/server/ICDConfigurationData.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ namespace app {
// Forward declaration of ICDManager to allow it to be friend with ICDConfigurationData.
class ICDManager;

// Forward declaration of TestICDManager to allow it to be friend with the ICDConfigurationData.
// Forward declaration of TestICDManager tests to allow it to be friend with the ICDConfigurationData.
// Used in unit tests
class TestICDManager;
class TestICDManager_TestICDStateObserverOnTransitionToIdleModeGreaterActiveModeDuration_Test;
class TestICDManager_TestICDStateObserverOnTransitionToIdleModeEqualActiveModeDuration_Test;
class TestICDManager_TestICDStateObserverOnTransitionToIdleMode0ActiveModeDurationWithoutReq_Test;
class TestICDManager_TestICDStateObserverOnTransitionToIdleModeEqualActiveModeDuration_Test;
class TestICDManager_TestICDStateObserverOnTransitionToIdleMode0ActiveModeDurationWithoutReq_Test;
class TestICDManager_TestICDStateObserverOnTransitionToIdleMode0ActiveModeDurationWittReq_Test;
class TestICDManager_TestICDModeDurationsWith0ActiveModeDurationWithoutActiveSub_Test;
class TestICDManager_TestICDModeDurationsWith0ActiveModeDurationWithActiveSub_Test;

} // namespace app

Expand Down Expand Up @@ -99,7 +106,16 @@ class ICDConfigurationData
// the ICDManager, the ICDManager is a friend that can access the private setters. If a consummer needs to be notified when a
// value is changed, they can leverage the Observer events the ICDManager generates. See src/app/icd/server/ICDStateObserver.h
friend class chip::app::ICDManager;
friend class chip::app::TestICDManager;

// TODO : Once <gtest/gtest_prod.h> can be included, use FRIEND_TEST for the friend class.
friend class chip::app::TestICDManager_TestICDStateObserverOnTransitionToIdleModeGreaterActiveModeDuration_Test;
friend class chip::app::TestICDManager_TestICDStateObserverOnTransitionToIdleModeEqualActiveModeDuration_Test;
friend class chip::app::TestICDManager_TestICDStateObserverOnTransitionToIdleMode0ActiveModeDurationWithoutReq_Test;
friend class chip::app::TestICDManager_TestICDStateObserverOnTransitionToIdleModeEqualActiveModeDuration_Test;
friend class chip::app::TestICDManager_TestICDStateObserverOnTransitionToIdleMode0ActiveModeDurationWithoutReq_Test;
friend class chip::app::TestICDManager_TestICDStateObserverOnTransitionToIdleMode0ActiveModeDurationWittReq_Test;
friend class chip::app::TestICDManager_TestICDModeDurationsWith0ActiveModeDurationWithoutActiveSub_Test;
friend class chip::app::TestICDManager_TestICDModeDurationsWith0ActiveModeDurationWithActiveSub_Test;

void SetICDMode(ICDMode mode) { mICDMode = mode; };
void SetSlowPollingInterval(System::Clock::Milliseconds32 slowPollInterval) { mSlowPollingInterval = slowPollInterval; };
Expand Down
10 changes: 7 additions & 3 deletions src/app/icd/server/ICDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ using SymmetricKeystore = SessionKeystore;
namespace chip {
namespace app {

// Forward declaration of TestICDManager to allow it to be friend with ICDManager
// Forward declaration of TestICDManager tests to allow it to be friend with ICDManager
// Used in unit tests
class TestICDManager;
class TestICDManager_TestShouldCheckInMsgsBeSentAtActiveModeFunction_Test;

/**
* @brief ICD Manager is responsible of processing the events and triggering the correct action for an ICD
Expand Down Expand Up @@ -132,6 +132,8 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler

ICDConfigurationData::ICDMode GetICDMode() { return ICDConfigurationData::GetInstance().GetICDMode(); };

OperationalState GetOperaionalState() { return mOperationalState; };

/**
* @brief Adds the referenced observer in parameters to the mStateObserverPool
* A maximum of CHIP_CONFIG_ICD_OBSERVERS_POOL_SIZE observers can be concurrently registered
Expand Down Expand Up @@ -199,7 +201,9 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
void OnSubscriptionReport() override;

private:
friend class TestICDManager;
// TODO : Once <gtest/gtest_prod.h> can be included, use FRIEND_TEST for the friend class.
friend class ::chip::app::TestICDManager_TestShouldCheckInMsgsBeSentAtActiveModeFunction_Test;

/**
* @brief UpdateICDMode evaluates in which mode the ICD can be in; SIT or LIT mode.
* If the current operating mode does not match the evaluated operating mode, function updates the ICDMode and triggers
Expand Down
23 changes: 6 additions & 17 deletions src/app/icd/server/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,20 @@ import("//build_overrides/pigweed.gni")
import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/src/app/icd/icd.gni")

chip_test_suite_using_nltest("tests_nltest") {
output_name = "libICDServerTestsNL"

test_sources = [ "TestICDManager.cpp" ]

public_deps = [
"${chip_root}/src/app/icd/server:manager",
"${chip_root}/src/app/icd/server:monitoring-table",
"${chip_root}/src/lib/support:test_utils",
"${chip_root}/src/lib/support:testing",
"${chip_root}/src/lib/support:testing_nlunit",
"${chip_root}/src/messaging/tests:helpers",
"${nlunit_test_root}:nlunit-test",
]
}

chip_test_suite("tests") {
output_name = "libICDServerTests"

test_sources = [ "TestICDMonitoringTable.cpp" ]
test_sources = [
"TestICDManager.cpp",
"TestICDMonitoringTable.cpp",
]

public_deps = [
"${chip_root}/src/app/icd/server:manager",
"${chip_root}/src/app/icd/server:monitoring-table",
"${chip_root}/src/lib/support:test_utils",
"${chip_root}/src/lib/support:testing",
"${chip_root}/src/messaging/tests:helpers",
]

cflags = [ "-Wconversion" ]
Expand Down
Loading

0 comments on commit 22a9898

Please sign in to comment.