16
16
* limitations under the License.
17
17
*/
18
18
19
+ #include < lib/core/StringBuilderAdapters.h>
20
+ #include < pw_unit_test/framework.h>
21
+
19
22
#include < access/examples/PermissiveAccessControlDelegate.h>
20
23
#include < app/ConcreteAttributePath.h>
21
24
#include < app/ConcreteEventPath.h>
34
37
#include < lib/core/TLVDebug.h>
35
38
#include < lib/core/TLVUtilities.h>
36
39
#include < lib/support/CHIPCounter.h>
37
- #include < lib/support/UnitTestContext.h>
38
- #include < lib/support/UnitTestRegistration.h>
39
40
#include < messaging/ExchangeContext.h>
40
41
#include < messaging/Flags.h>
41
- #include < nlunit-test.h>
42
42
#include < protocols/interaction_model/Constants.h>
43
43
44
44
#include < type_traits>
@@ -73,18 +73,6 @@ class TestDeviceTypeResolver : public AccessControl::DeviceTypeResolver
73
73
bool IsDeviceTypeOnEndpoint (DeviceTypeId deviceType, EndpointId endpoint) override { return false ; }
74
74
} gDeviceTypeResolver ;
75
75
76
- class TestAccessContext : public chip ::Test::AppContext
77
- {
78
- public:
79
- // Performs setup for each individual test in the test suite
80
- void SetUp () override
81
- {
82
- chip::Test::AppContext::SetUp ();
83
- Access::GetAccessControl ().Finish ();
84
- Access::GetAccessControl ().Init (GetTestAccessControlDelegate (), gDeviceTypeResolver );
85
- }
86
- };
87
-
88
76
class MockInteractionModelApp : public chip ::app::ReadClient::Callback
89
77
{
90
78
public:
@@ -121,29 +109,50 @@ class MockInteractionModelApp : public chip::app::ReadClient::Callback
121
109
namespace chip {
122
110
namespace app {
123
111
124
- class TestAclAttribute
112
+ class TestAclAttribute : public ::testing::Test
125
113
{
126
114
public:
127
- static void TestACLDeniedAttribute (nlTestSuite * apSuite, void * apContext);
115
+ static void SetUpTestSuite ()
116
+ {
117
+
118
+ mpTestContext = new chip::Test::AppContext;
119
+ mpTestContext->SetUpTestSuite ();
120
+ }
121
+ static void TearDownTestSuite ()
122
+ {
123
+ mpTestContext->TearDownTestSuite ();
124
+ delete mpTestContext;
125
+ }
126
+
127
+ void SetUp () override
128
+ {
129
+ mpTestContext->SetUp ();
130
+
131
+ Access::GetAccessControl ().Finish ();
132
+ Access::GetAccessControl ().Init (GetTestAccessControlDelegate (), gDeviceTypeResolver );
133
+ }
134
+ void TearDown () override { mpTestContext->TearDown (); }
135
+
136
+ static chip::Test::AppContext * mpTestContext;
128
137
};
129
138
139
+ chip::Test::AppContext * TestAclAttribute::mpTestContext = nullptr ;
140
+
130
141
// Read Client sends a malformed subscribe request, interaction model engine fails to parse the request and generates a status
131
142
// report to client, and client is closed.
132
- void TestAclAttribute::TestACLDeniedAttribute (nlTestSuite * apSuite, void * apContext )
143
+ TEST_F (TestAclAttribute, TestACLDeniedAttribute )
133
144
{
134
- TestAccessContext & ctx = *static_cast <TestAccessContext *>(apContext);
135
- CHIP_ERROR err = CHIP_NO_ERROR;
136
-
137
- Messaging::ReliableMessageMgr * rm = ctx.GetExchangeManager ().GetReliableMessageMgr ();
138
- NL_TEST_ASSERT (apSuite, rm->TestGetCountRetransTable () == 0 );
145
+ Messaging::ReliableMessageMgr * rm = mpTestContext->GetExchangeManager ().GetReliableMessageMgr ();
146
+ EXPECT_EQ (rm->TestGetCountRetransTable (), 0 );
139
147
140
148
MockInteractionModelApp delegate;
141
149
auto * engine = chip::app::InteractionModelEngine::GetInstance ();
142
- err = engine->Init (&ctx.GetExchangeManager (), &ctx.GetFabricTable (), app::reporting::GetDefaultReportScheduler ());
143
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
150
+ EXPECT_EQ (engine->Init (&mpTestContext->GetExchangeManager (), &mpTestContext->GetFabricTable (),
151
+ app::reporting::GetDefaultReportScheduler ()),
152
+ CHIP_NO_ERROR);
144
153
145
154
{
146
- app::ReadClient readClient (chip::app::InteractionModelEngine::GetInstance (), &ctx. GetExchangeManager (), delegate,
155
+ app::ReadClient readClient (chip::app::InteractionModelEngine::GetInstance (), &mpTestContext-> GetExchangeManager (), delegate,
147
156
chip::app::ReadClient::InteractionType::Subscribe);
148
157
149
158
chip::app::AttributePathParams attributePathParams[2 ];
@@ -155,22 +164,21 @@ void TestAclAttribute::TestACLDeniedAttribute(nlTestSuite * apSuite, void * apCo
155
164
attributePathParams[1 ].mClusterId = chip::Test::kTestDeniedClusterId1 ;
156
165
attributePathParams[1 ].mAttributeId = 2 ;
157
166
158
- ReadPrepareParams readPrepareParams (ctx. GetSessionBobToAlice ());
167
+ ReadPrepareParams readPrepareParams (mpTestContext-> GetSessionBobToAlice ());
159
168
readPrepareParams.mpAttributePathParamsList = attributePathParams;
160
169
readPrepareParams.mAttributePathParamsListSize = 2 ;
161
170
162
- err = readClient.SendRequest (readPrepareParams);
163
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
171
+ EXPECT_EQ (readClient.SendRequest (readPrepareParams), CHIP_NO_ERROR);
164
172
165
- ctx. DrainAndServiceIO ();
166
- NL_TEST_ASSERT (apSuite, delegate.mError == CHIP_IM_GLOBAL_STATUS (InvalidAction));
167
- NL_TEST_ASSERT (apSuite, ! delegate.mGotReport );
173
+ mpTestContext-> DrainAndServiceIO ();
174
+ EXPECT_EQ ( delegate.mError , CHIP_IM_GLOBAL_STATUS (InvalidAction));
175
+ EXPECT_FALSE ( delegate.mGotReport );
168
176
delegate.mError = CHIP_NO_ERROR;
169
177
delegate.mGotReport = false ;
170
178
}
171
179
172
180
{
173
- app::ReadClient readClient (chip::app::InteractionModelEngine::GetInstance (), &ctx. GetExchangeManager (), delegate,
181
+ app::ReadClient readClient (chip::app::InteractionModelEngine::GetInstance (), &mpTestContext-> GetExchangeManager (), delegate,
174
182
chip::app::ReadClient::InteractionType::Subscribe);
175
183
176
184
chip::app::AttributePathParams attributePathParams[2 ];
@@ -181,22 +189,21 @@ void TestAclAttribute::TestACLDeniedAttribute(nlTestSuite * apSuite, void * apCo
181
189
attributePathParams[1 ].mClusterId = chip::Test::kTestDeniedClusterId2 ;
182
190
attributePathParams[1 ].mAttributeId = 2 ;
183
191
184
- ReadPrepareParams readPrepareParams (ctx. GetSessionBobToAlice ());
192
+ ReadPrepareParams readPrepareParams (mpTestContext-> GetSessionBobToAlice ());
185
193
readPrepareParams.mpAttributePathParamsList = attributePathParams;
186
194
readPrepareParams.mAttributePathParamsListSize = 2 ;
187
195
188
- err = readClient.SendRequest (readPrepareParams);
189
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
196
+ EXPECT_EQ (readClient.SendRequest (readPrepareParams), CHIP_NO_ERROR);
190
197
191
- ctx. DrainAndServiceIO ();
192
- NL_TEST_ASSERT (apSuite, delegate.mError == CHIP_IM_GLOBAL_STATUS (InvalidAction));
193
- NL_TEST_ASSERT (apSuite, ! delegate.mGotReport );
198
+ mpTestContext-> DrainAndServiceIO ();
199
+ EXPECT_EQ ( delegate.mError , CHIP_IM_GLOBAL_STATUS (InvalidAction));
200
+ EXPECT_FALSE ( delegate.mGotReport );
194
201
delegate.mError = CHIP_NO_ERROR;
195
202
delegate.mGotReport = false ;
196
203
}
197
204
198
205
{
199
- app::ReadClient readClient (chip::app::InteractionModelEngine::GetInstance (), &ctx. GetExchangeManager (), delegate,
206
+ app::ReadClient readClient (chip::app::InteractionModelEngine::GetInstance (), &mpTestContext-> GetExchangeManager (), delegate,
200
207
chip::app::ReadClient::InteractionType::Subscribe);
201
208
202
209
chip::app::AttributePathParams attributePathParams[2 ];
@@ -208,49 +215,23 @@ void TestAclAttribute::TestACLDeniedAttribute(nlTestSuite * apSuite, void * apCo
208
215
attributePathParams[1 ].mClusterId = chip::Test::kTestClusterId ;
209
216
attributePathParams[1 ].mAttributeId = 2 ;
210
217
211
- ReadPrepareParams readPrepareParams (ctx. GetSessionBobToAlice ());
218
+ ReadPrepareParams readPrepareParams (mpTestContext-> GetSessionBobToAlice ());
212
219
readPrepareParams.mpAttributePathParamsList = attributePathParams;
213
220
readPrepareParams.mAttributePathParamsListSize = 2 ;
214
221
215
- err = readClient.SendRequest (readPrepareParams);
216
- NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
222
+ EXPECT_EQ (readClient.SendRequest (readPrepareParams), CHIP_NO_ERROR);
217
223
218
- ctx. DrainAndServiceIO ();
219
- NL_TEST_ASSERT (apSuite, delegate.mError == CHIP_NO_ERROR);
220
- NL_TEST_ASSERT (apSuite, delegate.mGotReport );
221
- NL_TEST_ASSERT (apSuite, engine->GetNumActiveReadHandlers (ReadHandler::InteractionType::Subscribe) == 1 );
224
+ mpTestContext-> DrainAndServiceIO ();
225
+ EXPECT_EQ ( delegate.mError , CHIP_NO_ERROR);
226
+ EXPECT_TRUE ( delegate.mGotReport );
227
+ EXPECT_EQ ( engine->GetNumActiveReadHandlers (ReadHandler::InteractionType::Subscribe), 1u );
222
228
delegate.mError = CHIP_NO_ERROR;
223
229
delegate.mGotReport = false ;
224
230
}
225
231
226
- NL_TEST_ASSERT (apSuite, engine->GetNumActiveReadClients () == 0 );
232
+ EXPECT_EQ ( engine->GetNumActiveReadClients (), 0u );
227
233
engine->Shutdown ();
228
- NL_TEST_ASSERT (apSuite, ctx. GetExchangeManager ().GetNumActiveExchanges () == 0 );
234
+ EXPECT_EQ (mpTestContext-> GetExchangeManager ().GetNumActiveExchanges (), 0u );
229
235
}
230
236
} // namespace app
231
237
} // namespace chip
232
-
233
- namespace {
234
-
235
- const nlTest sTests [] = {
236
- NL_TEST_DEF (" TestACLDeniedAttribute" , chip::app::TestAclAttribute::TestACLDeniedAttribute),
237
- NL_TEST_SENTINEL (),
238
- };
239
-
240
- nlTestSuite sSuite = {
241
- " TestAclAttribute" ,
242
- &sTests [0 ],
243
- NL_TEST_WRAP_FUNCTION (TestAccessContext::SetUpTestSuite),
244
- NL_TEST_WRAP_FUNCTION (TestAccessContext::TearDownTestSuite),
245
- NL_TEST_WRAP_METHOD (TestAccessContext, SetUp),
246
- NL_TEST_WRAP_METHOD (TestAccessContext, TearDown),
247
- };
248
-
249
- } // namespace
250
-
251
- int TestAclAttribute ()
252
- {
253
- return chip::ExecuteTestsWithContext<TestAccessContext>(&sSuite );
254
- }
255
-
256
- CHIP_REGISTER_TEST_SUITE (TestAclAttribute)
0 commit comments