Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 7 additions & 5 deletions src/app/icd/server/ICDConfigurationData.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ namespace chip {
namespace app {
// Forward declaration of ICDManager to allow it to be friend with ICDConfigurationData.
class ICDManager;
} // namespace app

// Forward declaration of TestICDManager to allow it to be friend with the ICDConfigurationData.
namespace Test {
// Forward declaration of ICDConfigurationDataTestAccess tests to allow it to be friend with the ICDConfigurationData.
// Used in unit tests
class TestICDManager;

} // namespace app
class ICDConfigurationDataTestAccess;
} // namespace Test

/**
* @brief ICDConfigurationData manages and stores ICD related configurations for the ICDManager.
Expand Down Expand Up @@ -99,7 +100,8 @@ 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;

friend class chip::Test::ICDConfigurationDataTestAccess;

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 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
25 changes: 8 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,22 @@ 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",
]

sources = [ "ICDConfigurationDataTestAccess.h" ]

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
47 changes: 47 additions & 0 deletions src/app/icd/server/tests/ICDConfigurationDataTestAccess.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* Copyright (c) 2024 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.
*/

#pragma once

#include <app/icd/server/ICDConfigurationData.h>

namespace chip {
namespace Test {
/**
* @brief Class acts as an accessor to private methods of the ICDConfigurationData class without needing to give friend access to
* each individual test.
* This design is necessary because certain tests validate specific edge cases around specific configurations.
* See ICDConfigurationData.h for more details why SetModeDurations cannot be a public API.
*/
class ICDConfigurationDataTestAccess
{
public:
ICDConfigurationDataTestAccess() = delete;
ICDConfigurationDataTestAccess(ICDConfigurationData * data) : mData(data) {}

CHIP_ERROR SetModeDurations(Optional<System::Clock::Milliseconds32> activeModeDuration,
Optional<System::Clock::Milliseconds32> idleModeDuration)
{
return mData->SetModeDurations(activeModeDuration, idleModeDuration);
}

private:
ICDConfigurationData * mData = nullptr;
};

} // namespace Test
} // namespace chip
Loading