16
16
* limitations under the License.
17
17
*/
18
18
19
- #include < lib/support/UnitTestRegistration.h>
20
- #include < nlunit-test.h>
19
+ #include < gtest/gtest.h>
21
20
22
21
#include < lib/core/CASEAuthTag.h>
23
22
24
23
using namespace chip ;
25
24
26
- void TestEqualityOperator (nlTestSuite * inSuite, void * inContext )
25
+ TEST (TestCATValues, TestEqualityOperator )
27
26
{
28
27
{
29
28
auto a = CATValues{ { 0x1111'0001 , 0x2222'0002 , 0x3333'0003 } };
@@ -37,7 +36,7 @@ void TestEqualityOperator(nlTestSuite * inSuite, void * inContext)
37
36
{
38
37
for (auto & inner : candidates)
39
38
{
40
- NL_TEST_ASSERT (inSuite, inner == outer);
39
+ EXPECT_EQ ( inner, outer);
41
40
}
42
41
}
43
42
}
@@ -49,7 +48,7 @@ void TestEqualityOperator(nlTestSuite * inSuite, void * inContext)
49
48
{
50
49
for (auto & inner : candidates)
51
50
{
52
- NL_TEST_ASSERT (inSuite, inner == outer);
51
+ EXPECT_EQ ( inner, outer);
53
52
}
54
53
}
55
54
}
@@ -65,13 +64,13 @@ void TestEqualityOperator(nlTestSuite * inSuite, void * inContext)
65
64
{
66
65
for (auto & inner : candidates)
67
66
{
68
- NL_TEST_ASSERT (inSuite, inner == outer);
67
+ EXPECT_EQ ( inner, outer);
69
68
}
70
69
}
71
70
}
72
71
}
73
72
74
- void TestInequalityOperator (nlTestSuite * inSuite, void * inContext )
73
+ TEST (TestCATValues, TestInequalityOperator )
75
74
{
76
75
auto a = CATValues{ { 0x1111'0001 } };
77
76
auto b = CATValues{ { 0x1111'0001 , 0x2222'0002 } };
@@ -103,12 +102,12 @@ void TestInequalityOperator(nlTestSuite * inSuite, void * inContext)
103
102
{
104
103
continue ;
105
104
}
106
- NL_TEST_ASSERT (inSuite, inner != outer);
105
+ EXPECT_NE ( inner, outer);
107
106
}
108
107
}
109
108
}
110
109
111
- void TestValidity (nlTestSuite * inSuite, void * inContext )
110
+ TEST (TestCATValues, TestValidity )
112
111
{
113
112
{
114
113
auto a = CATValues{ { 0x1111'0001 , 0x2222'0002 , 0x3333'0003 } };
@@ -119,7 +118,7 @@ void TestValidity(nlTestSuite * inSuite, void * inContext)
119
118
CATValues validCandidates[] = { a, b, c, d, e };
120
119
for (auto & candidate : validCandidates)
121
120
{
122
- NL_TEST_ASSERT (inSuite, candidate.AreValid ());
121
+ EXPECT_TRUE ( candidate.AreValid ());
123
122
}
124
123
}
125
124
@@ -130,117 +129,69 @@ void TestValidity(nlTestSuite * inSuite, void * inContext)
130
129
CATValues invalidCandidates[] = { versionZero1, versionZero2, collidingId };
131
130
for (auto & candidate : invalidCandidates)
132
131
{
133
- NL_TEST_ASSERT (inSuite, ! candidate.AreValid ());
132
+ EXPECT_FALSE ( candidate.AreValid ());
134
133
}
135
134
}
136
135
}
137
136
138
- void TestMembership (nlTestSuite * inSuite, void * inContext )
137
+ TEST (TestCATValues, TestMembership )
139
138
{
140
139
auto a = CATValues{ { 0x1111'0001 } };
141
140
auto b = CATValues{ { 0x1111'0001 , 0x2222'0002 } };
142
141
auto c = CATValues{ { 0x1111'0001 , 0x2222'0002 , 0x3333'0003 } };
143
142
144
- NL_TEST_ASSERT (inSuite, a.Contains (0x1111'0001 ));
145
- NL_TEST_ASSERT (inSuite, a.GetNumTagsPresent () == 1 );
146
- NL_TEST_ASSERT (inSuite, ! a.Contains (0x1111'0002 ));
147
- NL_TEST_ASSERT (inSuite, ! a.Contains (0x2222'0002 ));
148
- NL_TEST_ASSERT (inSuite, a.ContainsIdentifier (0x1111 ));
149
- NL_TEST_ASSERT (inSuite, ! a.ContainsIdentifier (0x2222 ));
150
- NL_TEST_ASSERT (inSuite, a.AreValid ());
151
-
152
- NL_TEST_ASSERT (inSuite, b.Contains (0x1111'0001 ));
153
- NL_TEST_ASSERT (inSuite, b.Contains (0x2222'0002 ));
154
- NL_TEST_ASSERT (inSuite, b.GetNumTagsPresent () == 2 );
155
- NL_TEST_ASSERT (inSuite, b.ContainsIdentifier (0x1111 ));
156
- NL_TEST_ASSERT (inSuite, b.ContainsIdentifier (0x2222 ));
157
- NL_TEST_ASSERT (inSuite, b.AreValid ());
158
-
159
- NL_TEST_ASSERT (inSuite, c.Contains (0x1111'0001 ));
160
- NL_TEST_ASSERT (inSuite, c.Contains (0x2222'0002 ));
161
- NL_TEST_ASSERT (inSuite, c.Contains (0x3333'0003 ));
162
- NL_TEST_ASSERT (inSuite, c.GetNumTagsPresent () == 3 );
163
- NL_TEST_ASSERT (inSuite, c.ContainsIdentifier (0x1111 ));
164
- NL_TEST_ASSERT (inSuite, c.ContainsIdentifier (0x2222 ));
165
- NL_TEST_ASSERT (inSuite, c.ContainsIdentifier (0x3333 ));
166
- NL_TEST_ASSERT (inSuite, c.AreValid ());
143
+ EXPECT_TRUE ( a.Contains (0x1111'0001 ));
144
+ EXPECT_EQ ( a.GetNumTagsPresent (), 1u );
145
+ EXPECT_FALSE ( a.Contains (0x1111'0002 ));
146
+ EXPECT_FALSE ( a.Contains (0x2222'0002 ));
147
+ EXPECT_TRUE ( a.ContainsIdentifier (0x1111 ));
148
+ EXPECT_FALSE ( a.ContainsIdentifier (0x2222 ));
149
+ EXPECT_TRUE ( a.AreValid ());
150
+
151
+ EXPECT_TRUE ( b.Contains (0x1111'0001 ));
152
+ EXPECT_TRUE ( b.Contains (0x2222'0002 ));
153
+ EXPECT_EQ ( b.GetNumTagsPresent (), 2u );
154
+ EXPECT_TRUE ( b.ContainsIdentifier (0x1111 ));
155
+ EXPECT_TRUE ( b.ContainsIdentifier (0x2222 ));
156
+ EXPECT_TRUE ( b.AreValid ());
157
+
158
+ EXPECT_TRUE ( c.Contains (0x1111'0001 ));
159
+ EXPECT_TRUE ( c.Contains (0x2222'0002 ));
160
+ EXPECT_TRUE ( c.Contains (0x3333'0003 ));
161
+ EXPECT_EQ ( c.GetNumTagsPresent (), 3u );
162
+ EXPECT_TRUE ( c.ContainsIdentifier (0x1111 ));
163
+ EXPECT_TRUE ( c.ContainsIdentifier (0x2222 ));
164
+ EXPECT_TRUE ( c.ContainsIdentifier (0x3333 ));
165
+ EXPECT_TRUE ( c.AreValid ());
167
166
}
168
167
169
- void TestSubjectMatching (nlTestSuite * inSuite, void * inContext )
168
+ TEST (TestCATValues, TestSubjectMatching )
170
169
{
171
170
// Check operational node IDs don't match
172
171
auto a = CATValues{ { 0x2222'0002 } };
173
- NL_TEST_ASSERT (inSuite, ! a.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0x0001'0002'0003'0004ull )));
174
- NL_TEST_ASSERT (inSuite, ! a.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0x0001'0002'2222'0002ull )));
172
+ EXPECT_FALSE ( a.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0x0001'0002'0003'0004ull )));
173
+ EXPECT_FALSE ( a.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0x0001'0002'2222'0002ull )));
175
174
176
175
auto b = CATValues{ { 0x1111'0001 } };
177
- NL_TEST_ASSERT (inSuite, b.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'1111'0001ull )));
178
- NL_TEST_ASSERT (inSuite, ! b.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'1111'0002ull )));
176
+ EXPECT_TRUE ( b.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'1111'0001ull )));
177
+ EXPECT_FALSE ( b.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'1111'0002ull )));
179
178
180
179
auto c = CATValues{ { 0x1111'0001 , 0x2222'0002 } };
181
- NL_TEST_ASSERT (inSuite, c.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'2222'0001ull )));
182
- NL_TEST_ASSERT (inSuite, c.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'2222'0002ull )));
183
- NL_TEST_ASSERT (inSuite, ! c.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'2222'0003ull )));
180
+ EXPECT_TRUE ( c.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'2222'0001ull )));
181
+ EXPECT_TRUE ( c.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'2222'0002ull )));
182
+ EXPECT_FALSE ( c.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'2222'0003ull )));
184
183
185
184
auto d = CATValues{ { 0x1111'0001 , 0x2222'0002 , 0x3333'0003 } };
186
- NL_TEST_ASSERT (inSuite, d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0001ull )));
187
- NL_TEST_ASSERT (inSuite, d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0002ull )));
188
- NL_TEST_ASSERT (inSuite, d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0003ull )));
189
- NL_TEST_ASSERT (inSuite, ! d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0004ull )));
190
- NL_TEST_ASSERT (inSuite, ! d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'ffffull )));
185
+ EXPECT_TRUE ( d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0001ull )));
186
+ EXPECT_TRUE ( d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0002ull )));
187
+ EXPECT_TRUE ( d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0003ull )));
188
+ EXPECT_FALSE ( d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0004ull )));
189
+ EXPECT_FALSE ( d.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'ffffull )));
191
190
192
191
auto e = CATValues{ { 0x1111'0001 , 0x2222'0002 , 0x3333'ffff } };
193
- NL_TEST_ASSERT (inSuite, e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0001ull )));
194
- NL_TEST_ASSERT (inSuite, e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0002ull )));
195
- NL_TEST_ASSERT (inSuite, e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0003ull )));
196
- NL_TEST_ASSERT (inSuite, e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0004ull )));
197
- NL_TEST_ASSERT (inSuite, e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'ffffull )));
192
+ EXPECT_TRUE ( e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0001ull )));
193
+ EXPECT_TRUE ( e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0002ull )));
194
+ EXPECT_TRUE ( e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0003ull )));
195
+ EXPECT_TRUE ( e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'0004ull )));
196
+ EXPECT_TRUE ( e.CheckSubjectAgainstCATs (static_cast <chip::NodeId>(0xFFFF'FFFD'3333'ffffull )));
198
197
}
199
- // Test Suite
200
-
201
- /* *
202
- * Test Suite that lists all the test functions.
203
- */
204
- // clang-format off
205
- static const nlTest sTests [] =
206
- {
207
- NL_TEST_DEF (" Equality operator" , TestEqualityOperator),
208
- NL_TEST_DEF (" Inequality operator" , TestInequalityOperator),
209
- NL_TEST_DEF (" Validity checks" , TestValidity),
210
- NL_TEST_DEF (" Set operations" , TestMembership),
211
- NL_TEST_DEF (" Subject matching for ACL" , TestSubjectMatching),
212
- NL_TEST_SENTINEL ()
213
- };
214
- // clang-format on
215
-
216
- int TestCATValues_Setup (void * inContext)
217
- {
218
- return SUCCESS;
219
- }
220
-
221
- /* *
222
- * Tear down the test suite.
223
- */
224
- int TestCATValues_Teardown (void * inContext)
225
- {
226
- return SUCCESS;
227
- }
228
-
229
- int TestCATValues ()
230
- {
231
- // clang-format off
232
- nlTestSuite theSuite =
233
- {
234
- " CATValues" ,
235
- &sTests [0 ],
236
- TestCATValues_Setup,
237
- TestCATValues_Teardown,
238
- };
239
- // clang-format on
240
-
241
- nlTestRunner (&theSuite, nullptr );
242
-
243
- return (nlTestRunnerStats (&theSuite));
244
- }
245
-
246
- CHIP_REGISTER_TEST_SUITE (TestCATValues)
0 commit comments