Skip to content

Commit 99823f9

Browse files
committed
Make test suite setup and teardown functions static
1 parent 6cd1690 commit 99823f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+318
-286
lines changed

src/app/tests/AppTestContext.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void AppContext::SetUpTestSuite()
4343
CHIP_ERROR err = CHIP_NO_ERROR;
4444
LoopbackMessagingContext::SetUpTestSuite();
4545
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
46-
VerifyOrDieWithMsg(chip::DeviceLayer::PlatformMgr().InitChipStack() == CHIP_NO_ERROR, AppServer,
46+
VerifyOrDieWithMsg((err = chip::DeviceLayer::PlatformMgr().InitChipStack()) == CHIP_NO_ERROR, AppServer,
4747
"Init CHIP stack failed: %" CHIP_ERROR_FORMAT, err.Format());
4848
}
4949

@@ -58,12 +58,13 @@ void AppContext::SetUp()
5858
CHIP_ERROR err = CHIP_NO_ERROR;
5959
LoopbackMessagingContext::SetUp();
6060
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
61-
VerifyOrDieWithMsg(app::InteractionModelEngine::GetInstance()->Init(
62-
&GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler()) == CHIP_NO_ERROR,
61+
VerifyOrDieWithMsg((err = app::InteractionModelEngine::GetInstance()->Init(&GetExchangeManager(), &GetFabricTable(),
62+
app::reporting::GetDefaultReportScheduler())) ==
63+
CHIP_NO_ERROR,
6364
AppServer, "Init InteractionModelEngine failed: %" CHIP_ERROR_FORMAT, err.Format());
6465
Access::SetAccessControl(gPermissiveAccessControl);
65-
VerifyOrDieWithMsg(Access::GetAccessControl().Init(chip::Access::Examples::GetPermissiveAccessControlDelegate(),
66-
gDeviceTypeResolver) == CHIP_NO_ERROR,
66+
VerifyOrDieWithMsg((err = Access::GetAccessControl().Init(chip::Access::Examples::GetPermissiveAccessControlDelegate(),
67+
gDeviceTypeResolver)) == CHIP_NO_ERROR,
6768
AppServer, "Init AccessControl failed: %" CHIP_ERROR_FORMAT, err.Format());
6869
}
6970

src/app/tests/AppTestContext.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class AppContext : public LoopbackMessagingContext
2828
{
2929
public:
3030
// Performs shared setup for all tests in the test suite
31-
void SetUpTestSuite() override;
31+
static void SetUpTestSuite();
3232
// Performs shared teardown for all tests in the test suite
33-
void TearDownTestSuite() override;
33+
static void TearDownTestSuite();
3434
// Performs setup for each individual test in the test suite
35-
void SetUp() override;
35+
void SetUp();
3636
// Performs teardown for each individual test in the test suite
37-
void TearDown() override;
37+
void TearDown();
3838
};
3939

4040
} // namespace Test

src/app/tests/TestAclAttribute.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ const nlTest sTests[] = {
259259
nlTestSuite sSuite = {
260260
"TestAclAttribute",
261261
&sTests[0],
262-
TestAccessContext::nlTestSetUpTestSuite,
263-
TestAccessContext::nlTestTearDownTestSuite,
264-
TestAccessContext::nlTestSetUp,
265-
TestAccessContext::nlTestTearDown,
262+
NL_TEST_WRAP_FUNCTION(TestAccessContext::SetUpTestSuite),
263+
NL_TEST_WRAP_FUNCTION(TestAccessContext::TearDownTestSuite),
264+
NL_TEST_WRAP_METHOD(TestAccessContext, SetUp),
265+
NL_TEST_WRAP_METHOD(TestAccessContext, TearDown),
266266
};
267267

268268
} // namespace

src/app/tests/TestAclEvent.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,10 @@ nlTestSuite sSuite =
377377
{
378378
"TestAclEvent",
379379
&sTests[0],
380-
TestContext::nlTestSetUpTestSuite,
381-
TestContext::nlTestTearDownTestSuite,
382-
TestContext::nlTestSetUp,
383-
TestContext::nlTestTearDown,
380+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
381+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
382+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
383+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
384384
};
385385
// clang-format on
386386

src/app/tests/TestBufferedReadCallback.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,10 @@ nlTestSuite theSuite =
610610
{
611611
"TestBufferedReadCallback",
612612
&sTests[0],
613-
TestContext::nlTestSetUpTestSuite,
614-
TestContext::nlTestTearDownTestSuite,
615-
TestContext::nlTestSetUp,
616-
TestContext::nlTestTearDown,
613+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
614+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
615+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
616+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
617617
};
618618

619619
}

src/app/tests/TestClusterStateCache.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,10 @@ nlTestSuite theSuite =
695695
{
696696
"TestClusterStateCache",
697697
&sTests[0],
698-
TestContext::nlTestSetUpTestSuite,
699-
TestContext::nlTestTearDownTestSuite,
700-
TestContext::nlTestSetUp,
701-
TestContext::nlTestTearDown,
698+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
699+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
700+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
701+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
702702
};
703703

704704
}

src/app/tests/TestCommandInteraction.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2118,10 +2118,10 @@ nlTestSuite sSuite =
21182118
{
21192119
"TestCommandInteraction",
21202120
&sTests[0],
2121-
TestContext::nlTestSetUpTestSuite,
2122-
TestContext::nlTestTearDownTestSuite,
2123-
TestContext::nlTestSetUp,
2124-
TestContext::nlTestTearDown,
2121+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
2122+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
2123+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
2124+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
21252125
};
21262126
// clang-format on
21272127

src/app/tests/TestEventLogging.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ const nlTest sTests[] = {
318318
nlTestSuite sSuite = {
319319
"EventLogging",
320320
&sTests[0],
321-
TestContext::nlTestSetUpTestSuite,
322-
TestContext::nlTestTearDownTestSuite,
323-
TestContext::nlTestSetUp,
324-
TestContext::nlTestTearDown,
321+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
322+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
323+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
324+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
325325
};
326326

327327
} // namespace

src/app/tests/TestEventLoggingNoUTCTime.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ class TestContext : public chip::Test::AppContext
8484
{
8585
public:
8686
// Performs shared setup for all tests in the test suite
87-
void SetUpTestSuite() override
87+
static void SetUpTestSuite()
8888
{
8989
chip::Test::AppContext::SetUpTestSuite();
90-
mClock.Emplace(chip::System::SystemClock());
90+
sClock.Emplace(chip::System::SystemClock());
9191
}
9292

9393
// Performs shared teardown for all tests in the test suite
94-
void TearDownTestSuite() override
94+
static void TearDownTestSuite()
9595
{
96-
mClock.ClearValue();
96+
sClock.ClearValue();
9797
chip::Test::AppContext::TearDownTestSuite();
9898
}
9999

@@ -125,9 +125,11 @@ class TestContext : public chip::Test::AppContext
125125

126126
private:
127127
chip::MonotonicallyIncreasingCounter<chip::EventNumber> mEventCounter;
128-
chip::Optional<MockClock> mClock;
128+
static chip::Optional<MockClock> sClock;
129129
};
130130

131+
chip::Optional<MockClock> TestContext::sClock;
132+
131133
void ENFORCE_FORMAT(1, 2) SimpleDumpWriter(const char * aFormat, ...)
132134
{
133135
va_list args;
@@ -370,10 +372,10 @@ const nlTest sTests[] = {
370372
nlTestSuite sSuite = {
371373
"EventLogging",
372374
&sTests[0],
373-
TestContext::nlTestSetUpTestSuite,
374-
TestContext::nlTestTearDownTestSuite,
375-
TestContext::nlTestSetUp,
376-
TestContext::nlTestTearDown,
375+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
376+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
377+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
378+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
377379
};
378380

379381
} // namespace

src/app/tests/TestEventOverflow.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ nlTestSuite sSuite =
169169
{
170170
"TestEventOverflow",
171171
&sTests[0],
172-
TestContext::nlTestSetUpTestSuite,
173-
TestContext::nlTestTearDownTestSuite,
174-
TestContext::nlTestSetUp,
175-
TestContext::nlTestTearDown,
172+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
173+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
174+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
175+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
176176
};
177177
// clang-format on
178178

src/app/tests/TestFabricScopedEventLogging.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ nlTestSuite sSuite =
278278
{
279279
"TestFabricScopedEventLogging",
280280
&sTests[0],
281-
TestContext::nlTestSetUpTestSuite,
282-
TestContext::nlTestTearDownTestSuite,
283-
TestContext::nlTestSetUp,
284-
TestContext::nlTestTearDown,
281+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
282+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
283+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
284+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
285285
};
286286
// clang-format on
287287

src/app/tests/TestICDManager.cpp

+16-13
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,18 @@ class TestContext : public chip::Test::AppContext
103103
{
104104
public:
105105
// Performs shared setup for all tests in the test suite
106-
void SetUpTestSuite() override
106+
static void SetUpTestSuite()
107107
{
108108
chip::Test::AppContext::SetUpTestSuite();
109109
DeviceLayer::SetSystemLayerForTesting(&GetSystemLayer());
110-
mRealClock = &chip::System::SystemClock();
111-
System::Clock::Internal::SetSystemClockForTesting(&mMockClock);
112-
return CHIP_NO_ERROR;
110+
sRealClock = &chip::System::SystemClock();
111+
System::Clock::Internal::SetSystemClockForTesting(&sMockClock);
113112
}
114113

115114
// Performs shared teardown for all tests in the test suite
116-
void TearDownTestSuite() override
115+
static void TearDownTestSuite()
117116
{
118-
System::Clock::Internal::SetSystemClockForTesting(mRealClock);
117+
System::Clock::Internal::SetSystemClockForTesting(sRealClock);
119118
DeviceLayer::SetSystemLayerForTesting(nullptr);
120119
chip::Test::AppContext::TearDownTestSuite();
121120
}
@@ -135,17 +134,21 @@ class TestContext : public chip::Test::AppContext
135134
chip::Test::AppContext::TearDown();
136135
}
137136

138-
System::Clock::Internal::MockClock mMockClock;
137+
static System::Clock::Internal::MockClock sMockClock;
138+
139139
TestSessionKeystoreImpl mKeystore;
140140
app::ICDManager mICDManager;
141141
TestSubscriptionsInfoProvider mSubInfoProvider;
142142
TestPersistentStorageDelegate testStorage;
143143
TestICDStateObserver mICDStateObserver;
144144

145145
private:
146-
System::Clock::ClockBase * mRealClock;
146+
static System::Clock::ClockBase * sRealClock;
147147
};
148148

149+
System::Clock::Internal::MockClock TestContext::sMockClock;
150+
System::Clock::ClockBase * TestContext::sRealClock;
151+
149152
} // namespace
150153

151154
namespace chip {
@@ -162,7 +165,7 @@ class TestICDManager
162165
*/
163166
static void AdvanceClockAndRunEventLoop(TestContext * ctx, Milliseconds64 time)
164167
{
165-
ctx->mMockClock.AdvanceMonotonic(time);
168+
TestContext::sMockClock.AdvanceMonotonic(time);
166169
ctx->GetIOContext().DriveIO();
167170
}
168171

@@ -744,10 +747,10 @@ static const nlTest sTests[] = {
744747
nlTestSuite cmSuite = {
745748
"TestICDManager",
746749
&sTests[0],
747-
TestContext::nlTestSetUpTestSuite,
748-
TestContext::nlTestTearDownTestSuite,
749-
TestContext::nlTestSetUp,
750-
TestContext::nlTestTearDown,
750+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
751+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
752+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
753+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
751754
};
752755
} // namespace
753756

src/app/tests/TestInteractionModelEngine.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,10 @@ nlTestSuite sSuite =
773773
{
774774
"TestInteractionModelEngine",
775775
&sTests[0],
776-
TestContext::nlTestSetUpTestSuite,
777-
TestContext::nlTestTearDownTestSuite,
778-
TestContext::nlTestSetUp,
779-
TestContext::nlTestTearDown,
776+
NL_TEST_WRAP_FUNCTION(TestContext::SetUpTestSuite),
777+
NL_TEST_WRAP_FUNCTION(TestContext::TearDownTestSuite),
778+
NL_TEST_WRAP_METHOD(TestContext, SetUp),
779+
NL_TEST_WRAP_METHOD(TestContext, TearDown),
780780
};
781781
// clang-format on
782782

0 commit comments

Comments
 (0)