29
29
#include < lib/core/CHIPError.h>
30
30
#include < lib/support/CHIPMem.h>
31
31
#include < lib/support/Span.h>
32
- #include < lib/support/UnitTestExtendedAssertions.h>
33
- #include < lib/support/UnitTestRegistration.h>
34
32
35
- #include < nlunit-test .h>
33
+ #include < gtest/gtest .h>
36
34
37
35
#include < dirent.h>
38
36
#include < stdio.h>
@@ -49,10 +47,17 @@ static void OnAttestationInformationVerificationCallback(void * context, const D
49
47
*pResult = result;
50
48
}
51
49
52
- static void TestCommissionerDUTVectors (nlTestSuite * inSuite, void * inContext)
50
+ struct TestCommissionerDUTVectors : public ::testing::Test
51
+ {
52
+ static void SetUpTestSuite () { ASSERT_EQ (chip::Platform::MemoryInit (), CHIP_NO_ERROR); }
53
+
54
+ static void TearDownTestSuite () { chip::Platform::MemoryShutdown (); }
55
+ };
56
+
57
+ TEST_F (TestCommissionerDUTVectors, TestCommissionerDUTVectors)
53
58
{
54
59
DeviceAttestationVerifier * example_dac_verifier = GetDefaultDACVerifier (GetTestAttestationTrustStore ());
55
- NL_TEST_ASSERT (inSuite, example_dac_verifier != nullptr );
60
+ ASSERT_NE ( example_dac_verifier, nullptr );
56
61
57
62
std::string dirPath (" ../../../../../credentials/development/commissioner_dut/" );
58
63
DIR * dir = opendir (dirPath.c_str ());
@@ -105,14 +110,14 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext)
105
110
VendorId vid = TestVendor1;
106
111
uint16_t pid = strstr (entry->d_name , " _vidpid_fallback_encoding_" ) ? 0x00B1 : 0x8000 ;
107
112
108
- NL_TEST_ASSERT_SUCCESS (inSuite, dacProvider.GetCertificationDeclaration (certDeclSpan));
109
- NL_TEST_ASSERT_SUCCESS (inSuite, dacProvider.GetDeviceAttestationCert (dacCertSpan));
110
- NL_TEST_ASSERT_SUCCESS (inSuite, dacProvider.GetProductAttestationIntermediateCert (paiCertSpan));
113
+ EXPECT_EQ ( dacProvider.GetCertificationDeclaration (certDeclSpan), CHIP_NO_ERROR );
114
+ EXPECT_EQ ( dacProvider.GetDeviceAttestationCert (dacCertSpan), CHIP_NO_ERROR );
115
+ EXPECT_EQ ( dacProvider.GetProductAttestationIntermediateCert (paiCertSpan), CHIP_NO_ERROR );
111
116
112
117
size_t attestationElementsLen =
113
118
TLV::EstimateStructOverhead (certDeclSpan.size (), attestationNonceSpan.size (), sizeof (uint64_t ) * 8 );
114
119
Platform::ScopedMemoryBuffer<uint8_t > attestationElements;
115
- NL_TEST_ASSERT (inSuite, attestationElements.Alloc (attestationElementsLen + attestationChallengeSpan.size ()));
120
+ EXPECT_TRUE ( attestationElements.Alloc (attestationElementsLen + attestationChallengeSpan.size ()));
116
121
MutableByteSpan attestationElementsSpan (attestationElements.Get (), attestationElementsLen);
117
122
118
123
// Construct attestation elements
@@ -121,10 +126,9 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext)
121
126
Credentials::DeviceAttestationVendorReservedConstructor emptyVendorReserved (nullptr , 0 );
122
127
const ByteSpan kEmptyFirmwareInfo ;
123
128
124
- NL_TEST_ASSERT_SUCCESS (inSuite,
125
- Credentials::ConstructAttestationElements (certDeclSpan, attestationNonceSpan, timestamp,
126
- kEmptyFirmwareInfo , emptyVendorReserved,
127
- attestationElementsSpan));
129
+ EXPECT_EQ (Credentials::ConstructAttestationElements (certDeclSpan, attestationNonceSpan, timestamp, kEmptyFirmwareInfo ,
130
+ emptyVendorReserved, attestationElementsSpan),
131
+ CHIP_NO_ERROR);
128
132
}
129
133
130
134
// Generate attestation signature
@@ -134,8 +138,8 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext)
134
138
attestationChallengeSpan.size ());
135
139
ByteSpan tbsSpan (attestationElementsSpan.data (), attestationElementsSpan.size () + attestationChallengeSpan.size ());
136
140
137
- NL_TEST_ASSERT_SUCCESS (inSuite, dacProvider.SignWithDeviceAttestationKey (tbsSpan, attestationSignatureSpan));
138
- NL_TEST_ASSERT (inSuite, attestationSignatureSpan.size () == signature.Capacity ());
141
+ EXPECT_EQ ( dacProvider.SignWithDeviceAttestationKey (tbsSpan, attestationSignatureSpan), CHIP_NO_ERROR );
142
+ EXPECT_EQ ( attestationSignatureSpan.size (), signature.Capacity ());
139
143
}
140
144
141
145
AttestationVerificationResult attestationResult = AttestationVerificationResult::kNotImplemented ;
@@ -167,63 +171,12 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext)
167
171
168
172
if (isSuccessCase)
169
173
{
170
- NL_TEST_ASSERT (inSuite, attestationResult == AttestationVerificationResult::kSuccess );
174
+ EXPECT_EQ ( attestationResult, AttestationVerificationResult::kSuccess );
171
175
}
172
176
else
173
177
{
174
- NL_TEST_ASSERT (inSuite, attestationResult != AttestationVerificationResult::kSuccess );
178
+ EXPECT_NE ( attestationResult, AttestationVerificationResult::kSuccess );
175
179
}
176
180
}
177
181
closedir (dir);
178
182
}
179
-
180
- /* *
181
- * Set up the test suite.
182
- */
183
- int TestCommissionerDUT_Setup (void * inContext)
184
- {
185
- CHIP_ERROR error = chip::Platform::MemoryInit ();
186
-
187
- if (error != CHIP_NO_ERROR)
188
- {
189
- return FAILURE;
190
- }
191
-
192
- return SUCCESS;
193
- }
194
-
195
- /* *
196
- * Tear down the test suite.
197
- */
198
- int TestCommissionerDUT_Teardown (void * inContext)
199
- {
200
- chip::Platform::MemoryShutdown ();
201
- return SUCCESS;
202
- }
203
-
204
- /* *
205
- * Test Suite. It lists all the test functions.
206
- */
207
- // clang-format off
208
- static const nlTest sTests [] = {
209
- NL_TEST_DEF (" Test Device Attestation Credentials Vectors" , TestCommissionerDUTVectors),
210
- NL_TEST_SENTINEL ()
211
- };
212
- // clang-format on
213
-
214
- int TestCommissionerDUT ()
215
- {
216
- // clang-format off
217
- nlTestSuite theSuite =
218
- {
219
- " Device Attestation Credentials Test Vectors" ,
220
- &sTests [0 ],
221
- TestCommissionerDUT_Setup,
222
- TestCommissionerDUT_Teardown
223
- };
224
- // clang-format on
225
- nlTestRunner (&theSuite, nullptr );
226
- return (nlTestRunnerStats (&theSuite));
227
- }
228
-
229
- CHIP_REGISTER_TEST_SUITE (TestCommissionerDUT);
0 commit comments