17
17
18
18
#include < lib/support/Span.h>
19
19
#include < lib/support/UnitTestRegistration.h>
20
- #include < nlunit-test .h>
20
+ #include < pw_unit_test/framework .h>
21
21
#include < system/SystemPacketBuffer.h>
22
22
23
23
#include < app/icd/client/DefaultICDClientStorage.h>
@@ -55,7 +55,14 @@ struct TestClientInfo : public ICDClientInfo
55
55
}
56
56
};
57
57
58
- void TestClientInfoCount (nlTestSuite * apSuite, void * apContext)
58
+ class TestDefaultICDClientStorage : public ::testing::Test
59
+ {
60
+ public:
61
+ static void SetUpTestSuite () { ASSERT_EQ (chip::Platform::MemoryInit (), CHIP_NO_ERROR); }
62
+ static void TearDownTestSuite () { chip::Platform::MemoryShutdown (); }
63
+ };
64
+
65
+ TEST_F (TestDefaultICDClientStorage, TestClientInfoCount)
59
66
{
60
67
CHIP_ERROR err = CHIP_NO_ERROR;
61
68
FabricIndex fabricId = 1 ;
@@ -67,9 +74,9 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext)
67
74
{
68
75
DefaultICDClientStorage manager;
69
76
err = manager.Init (&clientInfoStorage, &keystore);
70
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
77
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
71
78
err = manager.UpdateFabricList (fabricId);
72
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
79
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
73
80
// Write some ClientInfos and see the counts are correct
74
81
ICDClientInfo clientInfo1;
75
82
clientInfo1.peer_node = ScopedNodeId (nodeId1, fabricId);
@@ -78,38 +85,38 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext)
78
85
ICDClientInfo clientInfo3;
79
86
clientInfo3.peer_node = ScopedNodeId (nodeId1, fabricId);
80
87
err = manager.SetKey (clientInfo1, ByteSpan (kKeyBuffer1 ));
81
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
88
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
82
89
err = manager.StoreEntry (clientInfo1);
83
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
90
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
84
91
85
92
err = manager.SetKey (clientInfo2, ByteSpan (kKeyBuffer2 ));
86
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
93
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
87
94
err = manager.StoreEntry (clientInfo2);
88
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
95
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
89
96
90
97
err = manager.SetKey (clientInfo3, ByteSpan (kKeyBuffer3 ));
91
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
98
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
92
99
err = manager.StoreEntry (clientInfo3);
93
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
100
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
94
101
95
102
ICDClientInfo clientInfo;
96
103
// Make sure iterator counts correctly
97
104
auto * iterator = manager.IterateICDClientInfo ();
98
105
// same nodeId for clientInfo2 and clientInfo3, so the new one replace old one
99
- NL_TEST_ASSERT (apSuite, iterator->Count () == 2 );
106
+ EXPECT_EQ ( iterator->Count (), 2u );
100
107
101
- NL_TEST_ASSERT (apSuite, iterator->Next (clientInfo));
102
- NL_TEST_ASSERT (apSuite, clientInfo.peer_node .GetNodeId () == nodeId2);
103
- NL_TEST_ASSERT (apSuite, iterator->Next (clientInfo));
104
- NL_TEST_ASSERT (apSuite, clientInfo.peer_node .GetNodeId () == nodeId1);
108
+ EXPECT_TRUE ( iterator->Next (clientInfo));
109
+ EXPECT_EQ ( clientInfo.peer_node .GetNodeId (), nodeId2);
110
+ EXPECT_TRUE ( iterator->Next (clientInfo));
111
+ EXPECT_EQ ( clientInfo.peer_node .GetNodeId (), nodeId1);
105
112
106
113
iterator->Release ();
107
114
108
115
// Delete all and verify iterator counts 0
109
116
err = manager.DeleteAllEntries (fabricId);
110
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
117
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
111
118
iterator = manager.IterateICDClientInfo ();
112
- NL_TEST_ASSERT (apSuite, iterator->Count () == 0 );
119
+ EXPECT_EQ ( iterator->Count (), 0u );
113
120
114
121
// Verify ClientInfos manually count correctly
115
122
size_t count = 0 ;
@@ -118,19 +125,19 @@ void TestClientInfoCount(nlTestSuite * apSuite, void * apContext)
118
125
count++;
119
126
}
120
127
iterator->Release ();
121
- NL_TEST_ASSERT (apSuite, count == 0 );
128
+ EXPECT_EQ (count, 0u );
122
129
}
123
130
124
131
{
125
132
DefaultICDClientStorage manager;
126
133
err = manager.Init (&clientInfoStorage, &keystore);
127
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
134
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
128
135
err = manager.UpdateFabricList (fabricId);
129
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
136
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
130
137
}
131
138
}
132
139
133
- void TestClientInfoCountMultipleFabric (nlTestSuite * apSuite, void * apContext )
140
+ TEST_F (TestDefaultICDClientStorage, TestClientInfoCountMultipleFabric )
134
141
{
135
142
CHIP_ERROR err = CHIP_NO_ERROR;
136
143
FabricIndex fabricId1 = 1 ;
@@ -142,11 +149,11 @@ void TestClientInfoCountMultipleFabric(nlTestSuite * apSuite, void * apContext)
142
149
TestPersistentStorageDelegate clientInfoStorage;
143
150
TestSessionKeystoreImpl keystore;
144
151
err = manager.Init (&clientInfoStorage, &keystore);
145
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
152
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
146
153
err = manager.UpdateFabricList (fabricId1);
147
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
154
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
148
155
err = manager.UpdateFabricList (fabricId2);
149
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
156
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
150
157
151
158
// Write some ClientInfos and see the counts are correct
152
159
ICDClientInfo clientInfo1;
@@ -157,39 +164,39 @@ void TestClientInfoCountMultipleFabric(nlTestSuite * apSuite, void * apContext)
157
164
clientInfo3.peer_node = ScopedNodeId (nodeId3, fabricId2);
158
165
159
166
err = manager.SetKey (clientInfo1, ByteSpan (kKeyBuffer1 ));
160
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
167
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
161
168
err = manager.StoreEntry (clientInfo1);
162
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
169
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
163
170
164
171
err = manager.SetKey (clientInfo2, ByteSpan (kKeyBuffer2 ));
165
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
172
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
166
173
err = manager.StoreEntry (clientInfo2);
167
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
174
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
168
175
169
176
err = manager.SetKey (clientInfo3, ByteSpan (kKeyBuffer3 ));
170
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
177
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
171
178
err = manager.StoreEntry (clientInfo3);
172
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
179
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
173
180
// Make sure iterator counts correctly
174
181
auto * iterator = manager.IterateICDClientInfo ();
175
- NL_TEST_ASSERT (apSuite, iterator->Count () == 3 );
182
+ EXPECT_EQ ( iterator->Count (), 3u );
176
183
iterator->Release ();
177
184
178
185
// Delete all and verify iterator counts 0
179
186
err = manager.DeleteEntry (ScopedNodeId (nodeId1, fabricId1));
180
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
187
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
181
188
iterator = manager.IterateICDClientInfo ();
182
- NL_TEST_ASSERT (apSuite, iterator != nullptr );
189
+ ASSERT_NE ( iterator, nullptr );
183
190
DefaultICDClientStorage::ICDClientInfoIteratorWrapper clientInfoIteratorWrapper (iterator);
184
- NL_TEST_ASSERT (apSuite, iterator->Count () == 2 );
191
+ EXPECT_EQ ( iterator->Count (), 2u );
185
192
186
193
err = manager.DeleteEntry (ScopedNodeId (nodeId2, fabricId1));
187
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
188
- NL_TEST_ASSERT (apSuite, iterator->Count () == 1 );
194
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
195
+ EXPECT_EQ ( iterator->Count (), 1u );
189
196
190
197
err = manager.DeleteEntry (ScopedNodeId (nodeId3, fabricId2));
191
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
192
- NL_TEST_ASSERT (apSuite, iterator->Count () == 0 );
198
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
199
+ EXPECT_EQ ( iterator->Count (), 0u );
193
200
194
201
// Verify ClientInfos manually count correctly
195
202
size_t count = 0 ;
@@ -199,10 +206,10 @@ void TestClientInfoCountMultipleFabric(nlTestSuite * apSuite, void * apContext)
199
206
count++;
200
207
}
201
208
202
- NL_TEST_ASSERT (apSuite, count == 0 );
209
+ EXPECT_FALSE ( count);
203
210
}
204
211
205
- void TestProcessCheckInPayload (nlTestSuite * apSuite, void * apContext )
212
+ TEST_F (TestDefaultICDClientStorage, TestProcessCheckInPayload )
206
213
{
207
214
CHIP_ERROR err = CHIP_NO_ERROR;
208
215
FabricIndex fabricId = 1 ;
@@ -212,98 +219,41 @@ void TestProcessCheckInPayload(nlTestSuite * apSuite, void * apContext)
212
219
213
220
DefaultICDClientStorage manager;
214
221
err = manager.Init (&clientInfoStorage, &keystore);
215
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
222
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
216
223
err = manager.UpdateFabricList (fabricId);
217
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
224
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
218
225
// Populate clientInfo
219
226
ICDClientInfo clientInfo;
220
227
clientInfo.peer_node = ScopedNodeId (nodeId, fabricId);
221
228
222
229
err = manager.SetKey (clientInfo, ByteSpan (kKeyBuffer1 ));
223
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
230
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
224
231
err = manager.StoreEntry (clientInfo);
225
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
232
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
226
233
227
234
uint32_t counter = 1 ;
228
235
System::PacketBufferHandle buffer = MessagePacketBuffer::New (chip::Protocols::SecureChannel::CheckinMessage::kMinPayloadSize );
229
236
MutableByteSpan output{ buffer->Start (), buffer->MaxDataLength () };
230
237
err = chip::Protocols::SecureChannel::CheckinMessage::GenerateCheckinMessagePayload (
231
238
clientInfo.aes_key_handle , clientInfo.hmac_key_handle , counter, ByteSpan (), output);
232
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
239
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
233
240
234
241
buffer->SetDataLength (static_cast <uint16_t >(output.size ()));
235
242
ICDClientInfo decodeClientInfo;
236
243
uint32_t checkInCounter = 0 ;
237
244
ByteSpan payload{ buffer->Start (), buffer->DataLength () };
238
245
err = manager.ProcessCheckInPayload (payload, decodeClientInfo, checkInCounter);
239
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
246
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
240
247
241
248
// 2. Use a key not available in the storage for encoding
242
249
err = manager.SetKey (clientInfo, ByteSpan (kKeyBuffer2 ));
243
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
250
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
244
251
err = chip::Protocols::SecureChannel::CheckinMessage::GenerateCheckinMessagePayload (
245
252
clientInfo.aes_key_handle , clientInfo.hmac_key_handle , counter, ByteSpan (), output);
246
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
253
+ EXPECT_EQ ( err, CHIP_NO_ERROR);
247
254
248
255
buffer->SetDataLength (static_cast <uint16_t >(output.size ()));
249
256
ByteSpan payload1{ buffer->Start (), buffer->DataLength () };
250
257
err = manager.ProcessCheckInPayload (payload1, decodeClientInfo, checkInCounter);
251
- NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_NOT_FOUND);
252
- }
253
-
254
- /* *
255
- * Set up the test suite.
256
- */
257
- int TestClientInfo_Setup (void * apContext)
258
- {
259
- VerifyOrReturnError (CHIP_NO_ERROR == Platform::MemoryInit (), FAILURE);
260
-
261
- return SUCCESS;
258
+ EXPECT_EQ (err, CHIP_ERROR_NOT_FOUND);
262
259
}
263
-
264
- /* *
265
- * Tear down the test suite.
266
- */
267
- int TestClientInfo_Teardown (void * apContext)
268
- {
269
- Platform::MemoryShutdown ();
270
- return SUCCESS;
271
- }
272
-
273
- // Test Suite
274
-
275
- /* *
276
- * Test Suite that lists all the test functions.
277
- */
278
- // clang-format off
279
- static const nlTest sTests [] =
280
- {
281
- NL_TEST_DEF (" TestClientInfoCount" , TestClientInfoCount),
282
- NL_TEST_DEF (" TestClientInfoCountMultipleFabric" , TestClientInfoCountMultipleFabric),
283
- NL_TEST_DEF (" TestProcessCheckInPayload" , TestProcessCheckInPayload),
284
-
285
- NL_TEST_SENTINEL ()
286
- };
287
- // clang-format on
288
-
289
- // clang-format off
290
- static nlTestSuite sSuite =
291
- {
292
- " TestDefaultICDClientStorage" ,
293
- &sTests [0 ],
294
- &TestClientInfo_Setup, &TestClientInfo_Teardown
295
- };
296
- // clang-format on
297
-
298
- /* *
299
- * Main
300
- */
301
- int TestDefaultICDClientStorage ()
302
- {
303
- // Run test suit against one context
304
- nlTestRunner (&sSuite , nullptr );
305
-
306
- return (nlTestRunnerStats (&sSuite ));
307
- }
308
-
309
- CHIP_REGISTER_TEST_SUITE (TestDefaultICDClientStorage)
0 commit comments