16
16
* limitations under the License.
17
17
*/
18
18
19
- #include < gtest/gtest.h>
20
-
21
19
#include " app-common/zap-generated/ids/Attributes.h"
22
20
#include " app-common/zap-generated/ids/Clusters.h"
23
21
#include " app/ClusterStateCache.h"
37
35
#include < lib/support/TimeUtils.h>
38
36
#include < lib/support/UnitTestUtils.h>
39
37
#include < lib/support/logging/CHIPLogging.h>
40
- #include < messaging/tests/MessagingContext.h>
41
38
42
39
using namespace chip ;
43
40
using namespace chip ::app;
@@ -50,42 +47,17 @@ static uint8_t gInfoEventBuffer[4096];
50
47
static uint8_t gCritEventBuffer [4096 ];
51
48
static chip::app::CircularEventBuffer gCircularEventBuffer [3 ];
52
49
53
- using TestContext = chip::Test::AppContext;
54
-
55
50
//
56
51
// The generated endpoint_config for the controller app has Endpoint 1
57
52
// already used in the fixed endpoint set of size 1. Consequently, let's use the next
58
53
// number higher than that for our dynamic test endpoint.
59
54
//
60
55
constexpr EndpointId kTestEndpointId = 2 ;
61
56
62
- class TestEventCaching : public ::testing::Test
57
+ class TestEventCaching : public Test ::AppContext
63
58
{
64
- public:
65
- // Performs shared setup for all tests in the test suite
66
- static void SetUpTestSuite ()
67
- {
68
- if (mpContext == nullptr )
69
- {
70
- mpContext = new TestContext ();
71
- ASSERT_NE (mpContext, nullptr );
72
- }
73
- mpContext->SetUpTestSuite ();
74
- }
75
-
76
- // Performs shared teardown for all tests in the test suite
77
- static void TearDownTestSuite ()
78
- {
79
- mpContext->TearDownTestSuite ();
80
- if (mpContext != nullptr )
81
- {
82
- delete mpContext;
83
- mpContext = nullptr ;
84
- }
85
- }
86
-
87
59
protected:
88
- // Performs setup for each test in the suite
60
+ // Performs setup for each test in the suite. Run once for each test function.
89
61
void SetUp ()
90
62
{
91
63
const chip::app::LogStorageResources logStorageResources[] = {
@@ -94,29 +66,24 @@ class TestEventCaching : public ::testing::Test
94
66
{ &gCritEventBuffer [0 ], sizeof (gCritEventBuffer ), chip::app::PriorityLevel::Critical },
95
67
};
96
68
97
- mpContext->SetUp ();
69
+ AppContext::SetUp (); // Call parent.
70
+ VerifyOrReturn (!HasFailure ()); // Stop if parent had a failure.
98
71
99
- CHIP_ERROR err = CHIP_NO_ERROR;
100
- // TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
101
- VerifyOrDieWithMsg ((err = mEventCounter .Init (0 )) == CHIP_NO_ERROR, AppServer,
102
- " Init EventCounter failed: %" CHIP_ERROR_FORMAT, err.Format ());
103
- chip::app::EventManagement::CreateEventManagement (&mpContext->GetExchangeManager (), ArraySize (logStorageResources),
72
+ ASSERT_EQ (mEventCounter .Init (0 ), CHIP_NO_ERROR);
73
+ chip::app::EventManagement::CreateEventManagement (&GetExchangeManager (), ArraySize (logStorageResources),
104
74
gCircularEventBuffer , logStorageResources, &mEventCounter );
105
75
}
106
76
107
- // Performs teardown for each test in the suite
77
+ // Performs teardown for each test in the suite. Run once for each test function.
108
78
void TearDown ()
109
79
{
110
80
chip::app::EventManagement::DestroyEventManagement ();
111
- mpContext-> TearDown ();
81
+ AppContext:: TearDown (); // Call parent.
112
82
}
113
83
114
- static TestContext * mpContext;
115
-
116
84
private:
117
85
MonotonicallyIncreasingCounter<EventNumber> mEventCounter ;
118
86
};
119
- TestContext * TestEventCaching::mpContext = nullptr ;
120
87
121
88
// clang-format off
122
89
DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN (testClusterAttrs)
@@ -179,7 +146,7 @@ void GenerateEvents(chip::EventNumber & firstEventNumber, chip::EventNumber & la
179
146
*/
180
147
TEST_F (TestEventCaching, TestBasicCaching)
181
148
{
182
- auto sessionHandle = mpContext-> GetSessionBobToAlice ();
149
+ auto sessionHandle = GetSessionBobToAlice ();
183
150
app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance ();
184
151
185
152
// Initialize the ember side server logic
@@ -207,12 +174,12 @@ TEST_F(TestEventCaching, TestBasicCaching)
207
174
TestReadCallback readCallback;
208
175
209
176
{
210
- app::ReadClient readClient (engine, &mpContext-> GetExchangeManager (),
211
- readCallback. mClusterCacheAdapter . GetBufferedCallback (), app::ReadClient::InteractionType::Read);
177
+ app::ReadClient readClient (engine, &GetExchangeManager (), readCallback. mClusterCacheAdapter . GetBufferedCallback (),
178
+ app::ReadClient::InteractionType::Read);
212
179
213
180
EXPECT_EQ (readClient.SendRequest (readParams), CHIP_NO_ERROR);
214
181
215
- mpContext-> DrainAndServiceIO ();
182
+ DrainAndServiceIO ();
216
183
217
184
uint8_t generationCount = 0 ;
218
185
readCallback.mClusterCacheAdapter .ForEachEventData (
@@ -340,12 +307,12 @@ TEST_F(TestEventCaching, TestBasicCaching)
340
307
GenerateEvents (firstEventNumber, lastEventNumber);
341
308
342
309
{
343
- app::ReadClient readClient (engine, &mpContext-> GetExchangeManager (),
344
- readCallback. mClusterCacheAdapter . GetBufferedCallback (), app::ReadClient::InteractionType::Read);
310
+ app::ReadClient readClient (engine, &GetExchangeManager (), readCallback. mClusterCacheAdapter . GetBufferedCallback (),
311
+ app::ReadClient::InteractionType::Read);
345
312
346
313
EXPECT_EQ (readClient.SendRequest (readParams), CHIP_NO_ERROR);
347
314
348
- mpContext-> DrainAndServiceIO ();
315
+ DrainAndServiceIO ();
349
316
350
317
//
351
318
// Validate that we still have all 5 of the old events we received, as well as the new ones that just got generated.
@@ -392,8 +359,8 @@ TEST_F(TestEventCaching, TestBasicCaching)
392
359
// we don't receive events lower than that value.
393
360
//
394
361
{
395
- app::ReadClient readClient (engine, &mpContext-> GetExchangeManager (),
396
- readCallback. mClusterCacheAdapter . GetBufferedCallback (), app::ReadClient::InteractionType::Read);
362
+ app::ReadClient readClient (engine, &GetExchangeManager (), readCallback. mClusterCacheAdapter . GetBufferedCallback (),
363
+ app::ReadClient::InteractionType::Read);
397
364
398
365
readCallback.mClusterCacheAdapter .ClearEventCache ();
399
366
constexpr EventNumber kLastSeenEventNumber = 3 ;
@@ -405,7 +372,7 @@ TEST_F(TestEventCaching, TestBasicCaching)
405
372
406
373
EXPECT_EQ (readClient.SendRequest (readParams), CHIP_NO_ERROR);
407
374
408
- mpContext-> DrainAndServiceIO ();
375
+ DrainAndServiceIO ();
409
376
410
377
// We should only get events with event numbers larger than kHighestEventNumberSeen.
411
378
EXPECT_EQ (readCallback.mEventsSeen , lastEventNumber - kLastSeenEventNumber );
@@ -441,12 +408,12 @@ TEST_F(TestEventCaching, TestBasicCaching)
441
408
442
409
{
443
410
readParams.mEventNumber .SetValue (5 );
444
- app::ReadClient readClient (engine, &mpContext-> GetExchangeManager (),
445
- readCallback. mClusterCacheAdapter . GetBufferedCallback (), app::ReadClient::InteractionType::Read);
411
+ app::ReadClient readClient (engine, &GetExchangeManager (), readCallback. mClusterCacheAdapter . GetBufferedCallback (),
412
+ app::ReadClient::InteractionType::Read);
446
413
readCallback.mClusterCacheAdapter .ClearEventCache (true );
447
414
EXPECT_EQ (readClient.SendRequest (readParams), CHIP_NO_ERROR);
448
415
449
- mpContext-> DrainAndServiceIO ();
416
+ DrainAndServiceIO ();
450
417
451
418
//
452
419
// Validate that we would receive 5 events
@@ -474,7 +441,7 @@ TEST_F(TestEventCaching, TestBasicCaching)
474
441
EXPECT_TRUE (highestEventNumber.HasValue () && highestEventNumber.Value () == 9 );
475
442
}
476
443
477
- EXPECT_EQ (mpContext-> GetExchangeManager ().GetNumActiveExchanges (), 0u );
444
+ EXPECT_EQ (GetExchangeManager ().GetNumActiveExchanges (), 0u );
478
445
479
446
emberAfClearDynamicEndpoint (0 );
480
447
}
0 commit comments