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,21 @@ 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 ()
53
+ {
54
+ CHIP_ERROR error = chip::Platform::MemoryInit ();
55
+ EXPECT_EQ (error, CHIP_NO_ERROR);
56
+ }
57
+
58
+ static void TearDownTestSuite () { chip::Platform::MemoryShutdown (); }
59
+ };
60
+
61
+ TEST_F (TestCommissionerDUTVectors, TestCommissionerDUTVectors)
53
62
{
54
63
DeviceAttestationVerifier * example_dac_verifier = GetDefaultDACVerifier (GetTestAttestationTrustStore ());
55
- NL_TEST_ASSERT (inSuite, example_dac_verifier != nullptr );
64
+ EXPECT_NE ( example_dac_verifier, nullptr );
56
65
57
66
std::string dirPath (" ../../../../../credentials/development/commissioner_dut/" );
58
67
DIR * dir = opendir (dirPath.c_str ());
@@ -105,14 +114,14 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext)
105
114
VendorId vid = TestVendor1;
106
115
uint16_t pid = strstr (entry->d_name , " _vidpid_fallback_encoding_" ) ? 0x00B1 : 0x8000 ;
107
116
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));
117
+ EXPECT_EQ ( dacProvider.GetCertificationDeclaration (certDeclSpan), CHIP_NO_ERROR );
118
+ EXPECT_EQ ( dacProvider.GetDeviceAttestationCert (dacCertSpan), CHIP_NO_ERROR );
119
+ EXPECT_EQ ( dacProvider.GetProductAttestationIntermediateCert (paiCertSpan), CHIP_NO_ERROR );
111
120
112
121
size_t attestationElementsLen =
113
122
TLV::EstimateStructOverhead (certDeclSpan.size (), attestationNonceSpan.size (), sizeof (uint64_t ) * 8 );
114
123
Platform::ScopedMemoryBuffer<uint8_t > attestationElements;
115
- NL_TEST_ASSERT (inSuite, attestationElements.Alloc (attestationElementsLen + attestationChallengeSpan.size ()));
124
+ EXPECT_TRUE ( attestationElements.Alloc (attestationElementsLen + attestationChallengeSpan.size ()));
116
125
MutableByteSpan attestationElementsSpan (attestationElements.Get (), attestationElementsLen);
117
126
118
127
// Construct attestation elements
@@ -121,10 +130,9 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext)
121
130
Credentials::DeviceAttestationVendorReservedConstructor emptyVendorReserved (nullptr , 0 );
122
131
const ByteSpan kEmptyFirmwareInfo ;
123
132
124
- NL_TEST_ASSERT_SUCCESS (inSuite,
125
- Credentials::ConstructAttestationElements (certDeclSpan, attestationNonceSpan, timestamp,
126
- kEmptyFirmwareInfo , emptyVendorReserved,
127
- attestationElementsSpan));
133
+ EXPECT_EQ (Credentials::ConstructAttestationElements (certDeclSpan, attestationNonceSpan, timestamp, kEmptyFirmwareInfo ,
134
+ emptyVendorReserved, attestationElementsSpan),
135
+ CHIP_NO_ERROR);
128
136
}
129
137
130
138
// Generate attestation signature
@@ -134,8 +142,8 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext)
134
142
attestationChallengeSpan.size ());
135
143
ByteSpan tbsSpan (attestationElementsSpan.data (), attestationElementsSpan.size () + attestationChallengeSpan.size ());
136
144
137
- NL_TEST_ASSERT_SUCCESS (inSuite, dacProvider.SignWithDeviceAttestationKey (tbsSpan, attestationSignatureSpan));
138
- NL_TEST_ASSERT (inSuite, attestationSignatureSpan.size () == signature.Capacity ());
145
+ EXPECT_EQ ( dacProvider.SignWithDeviceAttestationKey (tbsSpan, attestationSignatureSpan), CHIP_NO_ERROR );
146
+ EXPECT_EQ ( attestationSignatureSpan.size (), signature.Capacity ());
139
147
}
140
148
141
149
AttestationVerificationResult attestationResult = AttestationVerificationResult::kNotImplemented ;
@@ -167,63 +175,12 @@ static void TestCommissionerDUTVectors(nlTestSuite * inSuite, void * inContext)
167
175
168
176
if (isSuccessCase)
169
177
{
170
- NL_TEST_ASSERT (inSuite, attestationResult == AttestationVerificationResult::kSuccess );
178
+ EXPECT_EQ ( attestationResult, AttestationVerificationResult::kSuccess );
171
179
}
172
180
else
173
181
{
174
- NL_TEST_ASSERT (inSuite, attestationResult != AttestationVerificationResult::kSuccess );
182
+ EXPECT_NE ( attestationResult, AttestationVerificationResult::kSuccess );
175
183
}
176
184
}
177
185
closedir (dir);
178
186
}
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