Skip to content

Commit 5e653df

Browse files
Expose SetModeDurations via ICDManager
1 parent a579c8d commit 5e653df

File tree

6 files changed

+19
-95
lines changed

6 files changed

+19
-95
lines changed

docs/testing/unit_testing.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,7 @@ own text context class.
288288
member you need, you can add a function to that class to do so. Note that
289289
you should make these functions as minimal as possible, with no logic
290290
besides just exposing the private/protected member.
291-
- For an example see `ICDConfigurationDataTestAccess` which is defined in
292-
[ICDConfigurationDataTestAccess.h](https://github.com/project-chip/connectedhomeip/blob/master/src/app/icd/server/tests/ICDConfigurationDataTestAccess.h),
293-
friends the underlying class in
294-
[ICDConfigurationData.h](https://github.com/project-chip/connectedhomeip/blob/master/src/app/icd/server/ICDConfigurationData.h),
295-
is included as a source in
296-
[BUILD.gn](https://github.com/project-chip/connectedhomeip/blob/master/src/app/icd/server/tests/BUILD.gn),
297-
and is used by a test in
298-
[TestICDManager.cpp](https://github.com/project-chip/connectedhomeip/blob/master/src/app/icd/server/tests/TestICDManager.cpp).
299-
- For another example see `TCPBaseTestAccess` which is defined in
291+
- For an example see `TCPBaseTestAccess` which is defined in
300292
[TCPBaseTestAccess.h](https://github.com/project-chip/connectedhomeip/blob/master/src/transport/raw/tests/TCPBaseTestAccess.h),
301293
friends the underlying class in
302294
[TCP.h](https://github.com/project-chip/connectedhomeip/blob/master/src/transport/raw/TCP.h),

src/app/icd/server/ICDConfigurationData.h

-8
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ namespace app {
3333
class ICDManager;
3434
} // namespace app
3535

36-
namespace Test {
37-
// Forward declaration of ICDConfigurationDataTestAccess tests to allow it to be friend with the ICDConfigurationData.
38-
// Used in unit tests
39-
class ICDConfigurationDataTestAccess;
40-
} // namespace Test
41-
4236
/**
4337
* @brief ICDConfigurationData manages and stores ICD related configurations for the ICDManager.
4438
* Goal of the class is to expose ICD information to all consummers without creating circular dependencies
@@ -120,8 +114,6 @@ class ICDConfigurationData
120114
// value is changed, they can leverage the Observer events the ICDManager generates. See src/app/icd/server/ICDStateObserver.h
121115
friend class chip::app::ICDManager;
122116

123-
friend class chip::Test::ICDConfigurationDataTestAccess;
124-
125117
void SetICDMode(ICDMode mode) { mICDMode = mode; };
126118
void SetSlowPollingInterval(System::Clock::Milliseconds32 slowPollInterval) { mSlowPollingInterval = slowPollInterval; };
127119
void SetFastPollingInterval(System::Clock::Milliseconds32 fastPollInterval) { mFastPollingInterval = fastPollInterval; };

src/app/icd/server/ICDManager.h

+7
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ class ICDManager : public ICDListener, public TestEventTriggerHandler
174174
*/
175175
bool SupportsFeature(Clusters::IcdManagement::Feature feature);
176176

177+
// See ICDConfigurationData::SetModeDurations
178+
CHIP_ERROR SetModeDurations(Optional<System::Clock::Milliseconds32> activeModeDuration,
179+
Optional<System::Clock::Milliseconds32> idleModeDuration)
180+
{
181+
ICDConfigurationData::GetInstance().SetModeDurations(activeModeDuration, idleModeDuration);
182+
}
183+
177184
ICDConfigurationData::ICDMode GetICDMode() { return ICDConfigurationData::GetInstance().GetICDMode(); };
178185

179186
OperationalState GetOperaionalState() { return mOperationalState; };

src/app/icd/server/tests/BUILD.gn

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ chip_test_suite("tests") {
2727
"TestICDMonitoringTable.cpp",
2828
]
2929

30-
sources = [ "ICDConfigurationDataTestAccess.h" ]
31-
3230
public_deps = [
3331
"${chip_root}/src/app/icd/server:default-check-in-back-off",
3432
"${chip_root}/src/app/icd/server:manager",

src/app/icd/server/tests/ICDConfigurationDataTestAccess.h

-51
This file was deleted.

src/app/icd/server/tests/TestICDManager.cpp

+11-25
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <app/icd/server/ICDMonitoringTable.h>
2828
#include <app/icd/server/ICDNotifier.h>
2929
#include <app/icd/server/ICDStateObserver.h>
30-
#include <app/icd/server/tests/ICDConfigurationDataTestAccess.h>
3130
#include <crypto/DefaultSessionKeystore.h>
3231
#include <lib/address_resolve/AddressResolve.h>
3332
#include <lib/core/DataModelTypes.h>
@@ -260,7 +259,6 @@ TEST_F(TestICDManager, TestICDModeDurationsWith0ActiveModeDurationWithoutActiveS
260259
{
261260
typedef ICDListener::ICDManagementEvents ICDMEvent;
262261
ICDConfigurationData & icdConfigData = ICDConfigurationData::GetInstance();
263-
ICDConfigurationDataTestAccess privateIcdConfigData(&icdConfigData);
264262

265263
using Feature = Clusters::IcdManagement::Feature;
266264
BitFlags<Feature> featureMap;
@@ -273,7 +271,7 @@ TEST_F(TestICDManager, TestICDModeDurationsWith0ActiveModeDurationWithoutActiveS
273271

274272
// Set New durations for test case
275273
Milliseconds32 oldActiveModeDuration = icdConfigData.GetActiveModeDuration();
276-
privateIcdConfigData.SetModeDurations(MakeOptional<Milliseconds32>(0), NullOptional);
274+
mICDManager.SetModeDurations(MakeOptional<Milliseconds32>(0), NullOptional);
277275

278276
// Verify That ICDManager starts in Idle
279277
EXPECT_EQ(mICDManager.GetOperaionalState(), ICDManager::OperationalState::IdleMode);
@@ -331,7 +329,7 @@ TEST_F(TestICDManager, TestICDModeDurationsWith0ActiveModeDurationWithoutActiveS
331329
EXPECT_EQ(mICDManager.GetOperaionalState(), ICDManager::OperationalState::IdleMode);
332330

333331
// Reset Old durations
334-
privateIcdConfigData.SetModeDurations(MakeOptional(oldActiveModeDuration), NullOptional);
332+
mICDManager.SetModeDurations(MakeOptional(oldActiveModeDuration), NullOptional);
335333
}
336334

337335
/**
@@ -342,7 +340,6 @@ TEST_F(TestICDManager, TestICDModeDurationsWith0ActiveModeDurationWithActiveSub)
342340
{
343341
typedef ICDListener::ICDManagementEvents ICDMEvent;
344342
ICDConfigurationData & icdConfigData = ICDConfigurationData::GetInstance();
345-
ICDConfigurationDataTestAccess privateIcdConfigData(&icdConfigData);
346343

347344
using Feature = Clusters::IcdManagement::Feature;
348345
BitFlags<Feature> featureMap;
@@ -355,7 +352,7 @@ TEST_F(TestICDManager, TestICDModeDurationsWith0ActiveModeDurationWithActiveSub)
355352

356353
// Set New durations for test case
357354
Milliseconds32 oldActiveModeDuration = icdConfigData.GetActiveModeDuration();
358-
privateIcdConfigData.SetModeDurations(MakeOptional<Milliseconds32>(0), NullOptional);
355+
mICDManager.SetModeDurations(MakeOptional<Milliseconds32>(0), NullOptional);
359356

360357
// Verify That ICDManager starts in Idle
361358
EXPECT_EQ(mICDManager.GetOperaionalState(), ICDManager::OperationalState::IdleMode);
@@ -424,7 +421,7 @@ TEST_F(TestICDManager, TestICDModeDurationsWith0ActiveModeDurationWithActiveSub)
424421
EXPECT_EQ(mICDManager.GetOperaionalState(), ICDManager::OperationalState::IdleMode);
425422

426423
// Reset Old durations
427-
privateIcdConfigData.SetModeDurations(MakeOptional<Milliseconds32>(oldActiveModeDuration), NullOptional);
424+
mICDManager.SetModeDurations(MakeOptional<Milliseconds32>(oldActiveModeDuration), NullOptional);
428425
}
429426
#endif // CHIP_CONFIG_ENABLE_ICD_CIP
430427

@@ -485,7 +482,6 @@ TEST_F(TestICDManager, TestICDMRegisterUnregisterEvents)
485482
{
486483
typedef ICDListener::ICDManagementEvents ICDMEvent;
487484
ICDNotifier notifier = ICDNotifier::GetInstance();
488-
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());
489485

490486
using Feature = Clusters::IcdManagement::Feature;
491487
BitFlags<Feature> featureMap;
@@ -711,7 +707,6 @@ TEST_F(TestICDManager, TestICDMDSLS)
711707
{
712708
typedef ICDListener::ICDManagementEvents ICDMEvent;
713709
ICDNotifier notifier = ICDNotifier::GetInstance();
714-
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());
715710

716711
using Feature = Clusters::IcdManagement::Feature;
717712
BitFlags<Feature> featureMap;
@@ -1000,7 +995,6 @@ TEST_F(TestICDManager, TestICDStateObserverOnEnterActiveMode)
1000995
TEST_F(TestICDManager, TestICDStateObserverOnICDModeChange)
1001996
{
1002997
typedef ICDListener::ICDManagementEvents ICDMEvent;
1003-
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());
1004998

1005999
using Feature = Clusters::IcdManagement::Feature;
10061000
BitFlags<Feature> featureMap;
@@ -1049,8 +1043,6 @@ TEST_F(TestICDManager, TestICDStateObserverOnICDModeChange)
10491043

10501044
TEST_F(TestICDManager, TestICDStateObserverOnICDModeChangeOnInit)
10511045
{
1052-
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());
1053-
10541046
using Feature = Clusters::IcdManagement::Feature;
10551047
BitFlags<Feature> featureMap;
10561048
featureMap.Set(Feature::kLongIdleTimeSupport).Set(Feature::kUserActiveModeTrigger).Set(Feature::kCheckInProtocolSupport);
@@ -1096,12 +1088,10 @@ TEST_F(TestICDManager, TestICDStateObserverOnICDModeChangeOnInit)
10961088
*/
10971089
TEST_F(TestICDManager, TestICDStateObserverOnTransitionToIdleModeGreaterActiveModeDuration)
10981090
{
1099-
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());
1100-
11011091
// Set New durations for test case - ActiveModeDuration must be longuer than ICD_ACTIVE_TIME_JITTER_MS
11021092
Milliseconds32 oldActiveModeDuration = ICDConfigurationData::GetInstance().GetActiveModeDuration();
1103-
privateIcdConfigData.SetModeDurations(
1104-
MakeOptional<Milliseconds32>(Milliseconds32(200) + Milliseconds32(ICD_ACTIVE_TIME_JITTER_MS)), NullOptional);
1093+
mICDManager.SetModeDurations(MakeOptional<Milliseconds32>(Milliseconds32(200) + Milliseconds32(ICD_ACTIVE_TIME_JITTER_MS)),
1094+
NullOptional);
11051095

11061096
// Advance clock just before IdleMode timer expires
11071097
AdvanceClockAndRunEventLoop(ICDConfigurationData::GetInstance().GetIdleModeDuration() - 1_s);
@@ -1138,7 +1128,7 @@ TEST_F(TestICDManager, TestICDStateObserverOnTransitionToIdleModeGreaterActiveMo
11381128
EXPECT_FALSE(mICDStateObserver.mOnTransitionToIdleCalled);
11391129

11401130
// Reset Old durations
1141-
privateIcdConfigData.SetModeDurations(MakeOptional(oldActiveModeDuration), NullOptional);
1131+
mICDManager.SetModeDurations(MakeOptional(oldActiveModeDuration), NullOptional);
11421132
}
11431133

11441134
/**
@@ -1147,11 +1137,9 @@ TEST_F(TestICDManager, TestICDStateObserverOnTransitionToIdleModeGreaterActiveMo
11471137
*/
11481138
TEST_F(TestICDManager, TestICDStateObserverOnTransitionToIdleModeEqualActiveModeDuration)
11491139
{
1150-
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());
1151-
11521140
// Set New durations for test case - ActiveModeDuration must be equal to ICD_ACTIVE_TIME_JITTER_MS
11531141
Milliseconds32 oldActiveModeDuration = ICDConfigurationData::GetInstance().GetActiveModeDuration();
1154-
privateIcdConfigData.SetModeDurations(MakeOptional<Milliseconds32>(Milliseconds32(ICD_ACTIVE_TIME_JITTER_MS)), NullOptional);
1142+
mICDManager.SetModeDurations(MakeOptional<Milliseconds32>(Milliseconds32(ICD_ACTIVE_TIME_JITTER_MS)), NullOptional);
11551143

11561144
// Advance clock just before IdleMode timer expires
11571145
AdvanceClockAndRunEventLoop(ICDConfigurationData::GetInstance().GetIdleModeDuration() - 1_s);
@@ -1171,19 +1159,17 @@ TEST_F(TestICDManager, TestICDStateObserverOnTransitionToIdleModeEqualActiveMode
11711159
EXPECT_TRUE(mICDStateObserver.mOnTransitionToIdleCalled);
11721160

11731161
// Reset Old durations
1174-
privateIcdConfigData.SetModeDurations(MakeOptional(oldActiveModeDuration), NullOptional);
1162+
mICDManager.SetModeDurations(MakeOptional(oldActiveModeDuration), NullOptional);
11751163
}
11761164

11771165
/**
11781166
* @brief Test verifies the OnTransitionToIdleMode event when the ActiveModeDuration is 0 and without an ActiveMode req
11791167
*/
11801168
TEST_F(TestICDManager, TestICDStateObserverOnTransitionToIdleMode0ActiveModeDurationWithoutReq)
11811169
{
1182-
ICDConfigurationDataTestAccess privateIcdConfigData(&ICDConfigurationData::GetInstance());
1183-
11841170
// Set New durations for test case - ActiveModeDuration equal 0
11851171
Milliseconds32 oldActiveModeDuration = ICDConfigurationData::GetInstance().GetActiveModeDuration();
1186-
privateIcdConfigData.SetModeDurations(MakeOptional<Milliseconds32>(0), NullOptional);
1172+
mICDManager.SetModeDurations(MakeOptional<Milliseconds32>(0), NullOptional);
11871173

11881174
// Advance clock just before IdleMode timer expires
11891175
AdvanceClockAndRunEventLoop(ICDConfigurationData::GetInstance().GetIdleModeDuration() - 1_s);
@@ -1203,7 +1189,7 @@ TEST_F(TestICDManager, TestICDStateObserverOnTransitionToIdleMode0ActiveModeDura
12031189
EXPECT_TRUE(mICDStateObserver.mOnTransitionToIdleCalled);
12041190

12051191
// Reset Old durations
1206-
privateIcdConfigData.SetModeDurations(MakeOptional(oldActiveModeDuration), NullOptional);
1192+
mICDManager.SetModeDurations(MakeOptional(oldActiveModeDuration), NullOptional);
12071193
}
12081194

12091195
/**

0 commit comments

Comments
 (0)