15
15
* See the License for the specific language governing permissions and
16
16
* limitations under the License.
17
17
*/
18
+ #include < pw_unit_test/framework.h>
19
+
18
20
#include < app/SubscriptionsInfoProvider.h>
19
21
#include < app/TestEventTriggerDelegate.h>
20
22
#include < app/icd/server/ICDConfigurationData.h>
24
26
#include < app/icd/server/ICDStateObserver.h>
25
27
#include < app/icd/server/tests/ICDConfigurationDataTestAccess.h>
26
28
#include < crypto/DefaultSessionKeystore.h>
27
- #include < gtest/gtest.h>
28
29
#include < lib/address_resolve/AddressResolve.h>
29
30
#include < lib/core/DataModelTypes.h>
30
31
#include < lib/core/NodeId.h>
@@ -124,18 +125,16 @@ class TestSubscriptionsInfoProvider : public SubscriptionsInfoProvider
124
125
bool mHasPersistedSubscription = false ;
125
126
};
126
127
127
- System::Clock::Internal::MockClock * pMockClock = nullptr ;
128
- System::Clock::ClockBase * pRealClock = nullptr ;
129
- chip::Test::LoopbackMessagingContext * pMessagingContext = nullptr ;
128
+ System::Clock::Internal::MockClock * pMockClock = nullptr ;
129
+ System::Clock::ClockBase * pRealClock = nullptr ;
130
130
131
131
} // namespace
132
132
133
133
namespace chip {
134
134
namespace app {
135
135
136
- class TestICDManager : public ::testing::Test
136
+ class TestICDManager : public Test ::LoopbackMessagingContext
137
137
{
138
-
139
138
public:
140
139
/*
141
140
* Advance the test Mock clock time by the amout passed in argument
@@ -147,7 +146,7 @@ class TestICDManager : public ::testing::Test
147
146
static void AdvanceClockAndRunEventLoop (Milliseconds64 time)
148
147
{
149
148
pMockClock->AdvanceMonotonic (time );
150
- pMessagingContext-> GetIOContext ().DriveIO ();
149
+ GetIOContext ().DriveIO ();
151
150
}
152
151
153
152
// Performs shared setup for all tests in the test suite
@@ -159,16 +158,12 @@ class TestICDManager : public ::testing::Test
159
158
ASSERT_NE (pMockClock, nullptr );
160
159
}
161
160
162
- if (pMessagingContext == nullptr )
163
- {
164
- pMessagingContext = new LoopbackMessagingContext ();
165
- ASSERT_NE (pMessagingContext, nullptr );
166
- }
161
+ LoopbackMessagingContext::SetUpTestSuite ();
162
+ VerifyOrReturn (!HasFailure ());
167
163
168
- pMessagingContext->SetUpTestSuite ();
169
164
ASSERT_EQ (chip::DeviceLayer::PlatformMgr ().InitChipStack (), CHIP_NO_ERROR);
170
165
171
- DeviceLayer::SetSystemLayerForTesting (&(pMessagingContext-> GetSystemLayer () ));
166
+ DeviceLayer::SetSystemLayerForTesting (&GetSystemLayer ());
172
167
pRealClock = &SystemClock ();
173
168
Clock::Internal::SetSystemClockForTesting (pMockClock);
174
169
}
@@ -180,39 +175,34 @@ class TestICDManager : public ::testing::Test
180
175
DeviceLayer::SetSystemLayerForTesting (nullptr );
181
176
182
177
DeviceLayer::PlatformMgr ().Shutdown ();
183
- pMessagingContext->TearDownTestSuite ();
178
+
179
+ LoopbackMessagingContext::TearDownTestSuite ();
184
180
185
181
if (pMockClock != nullptr )
186
182
{
187
183
delete pMockClock;
188
184
pMockClock = nullptr ;
189
185
}
190
186
191
- if (pMessagingContext != nullptr )
192
- {
193
- delete pMessagingContext;
194
- pMessagingContext = nullptr ;
195
- }
196
-
197
187
pRealClock = nullptr ;
198
188
}
199
189
200
190
// Performs setup for each individual test in the test suite
201
191
void SetUp () override
202
192
{
203
- pMessagingContext->SetUp ();
193
+ LoopbackMessagingContext::SetUp ();
194
+ VerifyOrReturn (!HasFailure ());
204
195
205
196
mICDStateObserver .ResetAll ();
206
197
mICDManager .RegisterObserver (&mICDStateObserver );
207
- mICDManager .Init (&testStorage, &(pMessagingContext->GetFabricTable ()), &mKeystore ,
208
- &(pMessagingContext->GetExchangeManager ()), &mSubInfoProvider );
198
+ mICDManager .Init (&testStorage, &GetFabricTable (), &mKeystore , &GetExchangeManager (), &mSubInfoProvider );
209
199
}
210
200
211
201
// Performs teardown for each individual test in the test suite
212
202
void TearDown () override
213
203
{
214
204
mICDManager .Shutdown ();
215
- pMessagingContext-> TearDown ();
205
+ LoopbackMessagingContext:: TearDown ();
216
206
}
217
207
218
208
TestSessionKeystoreImpl mKeystore ;
@@ -576,8 +566,7 @@ TEST_F(TestICDManager, TestICDCounter)
576
566
577
567
// Shut down and reinit ICDManager to increment counter
578
568
mICDManager .Shutdown ();
579
- mICDManager .Init (&(testStorage), &(pMessagingContext->GetFabricTable ()), &(mKeystore ),
580
- &(pMessagingContext->GetExchangeManager ()), &(mSubInfoProvider ));
569
+ mICDManager .Init (&(testStorage), &GetFabricTable (), &(mKeystore ), &GetExchangeManager (), &(mSubInfoProvider ));
581
570
mICDManager .RegisterObserver (&(mICDStateObserver ));
582
571
583
572
EXPECT_EQ (counter + ICDConfigurationData::kICDCounterPersistenceIncrement ,
@@ -982,8 +971,7 @@ TEST_F(TestICDManager, TestICDStateObserverOnICDModeChangeOnInit)
982
971
// Shut down and reinit ICDManager - We should go to LIT mode since we have a registration
983
972
mICDManager .Shutdown ();
984
973
mICDManager .RegisterObserver (&(mICDStateObserver ));
985
- mICDManager .Init (&testStorage, &(pMessagingContext->GetFabricTable ()), &mKeystore , &(pMessagingContext->GetExchangeManager ()),
986
- &mSubInfoProvider );
974
+ mICDManager .Init (&testStorage, &GetFabricTable (), &mKeystore , &GetExchangeManager (), &mSubInfoProvider );
987
975
988
976
// We have a registration, transition to LIT mode
989
977
EXPECT_TRUE (mICDStateObserver .mOnICDModeChangeCalled );
0 commit comments