15
15
* limitations under the License.
16
16
*/
17
17
18
+ #include < lib/support/CodeUtils.h>
18
19
#include < lib/support/DefaultStorageKeyAllocator.h>
19
20
#include < lib/support/TestPersistentStorageDelegate.h>
20
21
#include < lib/support/UnitTestRegistration.h>
24
25
// Use SimpleSessionResumptionStorage, which extends it, to test.
25
26
#include < protocols/secure_channel/SimpleSessionResumptionStorage.h>
26
27
27
- #define ARRAY_SIZE (_array ) ((sizeof (_array) / sizeof (_array[0 ])))
28
-
29
28
void TestSave (nlTestSuite * inSuite, void * inContext)
30
29
{
31
30
chip::SimpleSessionResumptionStorage sessionStorage;
@@ -40,7 +39,7 @@ void TestSave(nlTestSuite * inSuite, void * inContext)
40
39
} vectors[CHIP_CONFIG_CASE_SESSION_RESUME_CACHE_SIZE + 1 ];
41
40
42
41
// Populate test vectors.
43
- for (size_t i = 0 ; i < ARRAY_SIZE (vectors); ++i)
42
+ for (size_t i = 0 ; i < ArraySize (vectors); ++i)
44
43
{
45
44
NL_TEST_ASSERT (
46
45
inSuite, CHIP_NO_ERROR == chip::Crypto::DRBG_get_bytes (vectors[i].resumptionId .data (), vectors[i].resumptionId .size ()));
@@ -70,7 +69,7 @@ void TestSave(nlTestSuite * inSuite, void * inContext)
70
69
// If more sophisticated LRU behavior is implemented, this test
71
70
// case should be modified to match.
72
71
{
73
- size_t last = ARRAY_SIZE (vectors) - 1 ;
72
+ size_t last = ArraySize (vectors) - 1 ;
74
73
NL_TEST_ASSERT (inSuite,
75
74
sessionStorage.Save (vectors[last].node , vectors[last].resumptionId , vectors[last].sharedSecret ,
76
75
vectors[last].cats ) == CHIP_NO_ERROR);
@@ -99,7 +98,7 @@ void TestSave(nlTestSuite * inSuite, void * inContext)
99
98
NL_TEST_ASSERT (inSuite, vector.cats .values [1 ] == outCats.values [1 ]);
100
99
NL_TEST_ASSERT (inSuite, vector.cats .values [2 ] == outCats.values [2 ]);
101
100
102
- // Validate retreiveal by resumption ID.
101
+ // Validate retrieval by resumption ID.
103
102
NL_TEST_ASSERT (inSuite,
104
103
sessionStorage.FindByResumptionId (vector.resumptionId , outNode, outSharedSecret, outCats) == CHIP_NO_ERROR);
105
104
NL_TEST_ASSERT (inSuite, vector.node == outNode);
@@ -123,12 +122,12 @@ void TestInPlaceSave(nlTestSuite * inSuite, void * inContext)
123
122
chip::CATValues cats;
124
123
} vectors[CHIP_CONFIG_CASE_SESSION_RESUME_CACHE_SIZE + 10 ];
125
124
126
- // Construct only a few unique node identities to simiulate talking to a
125
+ // Construct only a few unique node identities to simulate talking to a
127
126
// couple peers.
128
127
chip::ScopedNodeId nodes[3 ];
129
- static_assert (ARRAY_SIZE (nodes) < CHIP_CONFIG_CASE_SESSION_RESUME_CACHE_SIZE,
128
+ static_assert (ArraySize (nodes) < CHIP_CONFIG_CASE_SESSION_RESUME_CACHE_SIZE,
130
129
" must have fewer nodes than slots in session resumption storage" );
131
- for (size_t i = 0 ; i < ARRAY_SIZE (nodes); ++i)
130
+ for (size_t i = 0 ; i < ArraySize (nodes); ++i)
132
131
{
133
132
do
134
133
{
@@ -137,7 +136,7 @@ void TestInPlaceSave(nlTestSuite * inSuite, void * inContext)
137
136
}
138
137
139
138
// Populate test vectors.
140
- for (size_t i = 0 ; i < ARRAY_SIZE (vectors); ++i)
139
+ for (size_t i = 0 ; i < ArraySize (vectors); ++i)
141
140
{
142
141
NL_TEST_ASSERT (
143
142
inSuite, CHIP_NO_ERROR == chip::Crypto::DRBG_get_bytes (vectors[i].resumptionId .data (), vectors[i].resumptionId .size ()));
@@ -147,22 +146,22 @@ void TestInPlaceSave(nlTestSuite * inSuite, void * inContext)
147
146
NL_TEST_ASSERT (inSuite,
148
147
CHIP_NO_ERROR ==
149
148
chip::Crypto::DRBG_get_bytes (vectors[i].sharedSecret .Bytes (), vectors[i].sharedSecret .Length ()));
150
- vectors[i].node = nodes[i % ARRAY_SIZE (nodes)];
149
+ vectors[i].node = nodes[i % ArraySize (nodes)];
151
150
vectors[i].cats .values [0 ] = static_cast <chip::CASEAuthTag>(rand ());
152
151
vectors[i].cats .values [1 ] = static_cast <chip::CASEAuthTag>(rand ());
153
152
vectors[i].cats .values [2 ] = static_cast <chip::CASEAuthTag>(rand ());
154
153
}
155
154
156
155
// Add one entry for each node.
157
- for (size_t i = 0 ; i < ARRAY_SIZE (nodes); ++i)
156
+ for (size_t i = 0 ; i < ArraySize (nodes); ++i)
158
157
{
159
158
NL_TEST_ASSERT (inSuite,
160
159
sessionStorage.Save (vectors[i].node , vectors[i].resumptionId , vectors[i].sharedSecret , vectors[i].cats ) ==
161
160
CHIP_NO_ERROR);
162
161
}
163
162
164
163
// Read back and verify values.
165
- for (size_t i = 0 ; i < ARRAY_SIZE (nodes); ++i)
164
+ for (size_t i = 0 ; i < ArraySize (nodes); ++i)
166
165
{
167
166
chip::ScopedNodeId outNode;
168
167
chip::SessionResumptionStorage::ResumptionIdStorage outResumptionId;
@@ -180,7 +179,7 @@ void TestInPlaceSave(nlTestSuite * inSuite, void * inContext)
180
179
NL_TEST_ASSERT (inSuite, vectors[i].cats .values [1 ] == outCats.values [1 ]);
181
180
NL_TEST_ASSERT (inSuite, vectors[i].cats .values [2 ] == outCats.values [2 ]);
182
181
183
- // Validate retreiveal by resumption ID.
182
+ // Validate retrieval by resumption ID.
184
183
NL_TEST_ASSERT (inSuite,
185
184
sessionStorage.FindByResumptionId (vectors[i].resumptionId , outNode, outSharedSecret, outCats) ==
186
185
CHIP_NO_ERROR);
@@ -200,7 +199,7 @@ void TestInPlaceSave(nlTestSuite * inSuite, void * inContext)
200
199
}
201
200
202
201
// Read back and verify that only the last record for each node was retained.
203
- for (size_t i = ARRAY_SIZE (vectors) - ARRAY_SIZE (nodes); i < ARRAY_SIZE (vectors); ++i)
202
+ for (size_t i = ArraySize (vectors) - ArraySize (nodes); i < ArraySize (vectors); ++i)
204
203
{
205
204
chip::ScopedNodeId outNode;
206
205
chip::SessionResumptionStorage::ResumptionIdStorage outResumptionId;
@@ -218,7 +217,7 @@ void TestInPlaceSave(nlTestSuite * inSuite, void * inContext)
218
217
NL_TEST_ASSERT (inSuite, vectors[i].cats .values [1 ] == outCats.values [1 ]);
219
218
NL_TEST_ASSERT (inSuite, vectors[i].cats .values [2 ] == outCats.values [2 ]);
220
219
221
- // Validate retreiveal by resumption ID.
220
+ // Validate retrieval by resumption ID.
222
221
NL_TEST_ASSERT (inSuite,
223
222
sessionStorage.FindByResumptionId (vectors[i].resumptionId , outNode, outSharedSecret, outCats) ==
224
223
CHIP_NO_ERROR);
@@ -290,7 +289,7 @@ void TestDelete(nlTestSuite * inSuite, void * inContext)
290
289
NL_TEST_ASSERT (inSuite, CHIP_NO_ERROR == chip::Crypto::DRBG_get_bytes (sharedSecret.Bytes (), sharedSecret.Length ()));
291
290
292
291
// Populate test vectors.
293
- for (size_t i = 0 ; i < ARRAY_SIZE (vectors); ++i)
292
+ for (size_t i = 0 ; i < ArraySize (vectors); ++i)
294
293
{
295
294
NL_TEST_ASSERT (
296
295
inSuite, CHIP_NO_ERROR == chip::Crypto::DRBG_get_bytes (vectors[i].resumptionId .data (), vectors[i].resumptionId .size ()));
@@ -308,7 +307,7 @@ void TestDelete(nlTestSuite * inSuite, void * inContext)
308
307
}
309
308
310
309
// Delete values in turn from storage and verify they are removed.
311
- for (size_t i = 0 ; i < ARRAY_SIZE (vectors); ++i)
310
+ for (size_t i = 0 ; i < ArraySize (vectors); ++i)
312
311
{
313
312
chip::ScopedNodeId outNode;
314
313
chip::SessionResumptionStorage::ResumptionIdStorage outResumptionId;
0 commit comments