Skip to content

Commit 8fe265d

Browse files
committed
Replaced nlunit-test with pw_unit_test in src/lib/dnssd/platform/
1 parent a860932 commit 8fe265d

File tree

2 files changed

+47
-68
lines changed

2 files changed

+47
-68
lines changed

src/lib/dnssd/platform/tests/BUILD.gn

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,14 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17-
import("//build_overrides/nlunit_test.gni")
1817

1918
import("${chip_root}/build/chip/chip_test_suite.gni")
2019

21-
chip_test_suite_using_nltest("tests") {
20+
chip_test_suite("tests") {
2221
output_name = "libMdnsFakePlatformTests"
2322
if (chip_device_platform == "fake") {
2423
test_sources = [ "TestPlatform.cpp" ]
2524

26-
public_deps = [
27-
"${chip_root}/src/lib/dnssd",
28-
"${chip_root}/src/lib/support:testing_nlunit",
29-
"${nlunit_test_root}:nlunit-test",
30-
]
25+
public_deps = [ "${chip_root}/src/lib/dnssd" ]
3126
}
3227
}

src/lib/dnssd/platform/tests/TestPlatform.cpp

+45-61
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
#include <lib/core/PeerId.h>
2020
#include <lib/dnssd/Discovery_ImplPlatform.h>
21-
#include <lib/support/UnitTestRegistration.h>
21+
2222
#include <lib/support/logging/CHIPLogging.h>
2323
#include <platform/CHIPDeviceLayer.h>
2424
#include <platform/fake/DnssdImpl.h>
2525

26-
#include <nlunit-test.h>
26+
#include <gtest/gtest.h>
2727

2828
#if CHIP_DEVICE_LAYER_TARGET_FAKE != 1
2929
#error "This test is designed for use only with the fake platform"
@@ -152,102 +152,86 @@ test::ExpectedCall commissionableLargeEnhanced = test::ExpectedCall()
152152
.AddSubtype("_V555")
153153
.AddSubtype("_T70000")
154154
.AddSubtype("_CM");
155-
void TestStub(nlTestSuite * inSuite, void * inContext)
155+
156+
class TestDnssdPlatform : public ::testing::Test
157+
{
158+
public:
159+
static void SetUpTestSuite() { VerifyOrDie(chip::Platform::MemoryInit() == CHIP_NO_ERROR); }
160+
static void TearDownTestSuite()
161+
{
162+
DiscoveryImplPlatform::GetInstance().Shutdown();
163+
chip::Platform::MemoryShutdown();
164+
}
165+
};
166+
167+
TEST_F(TestDnssdPlatform, TestStub)
156168
{
157169
// This is a test of the fake platform impl. We want
158170
// We want the platform to return unexpected event if it gets a start
159171
// without an expected event.
160172
ChipLogError(Discovery, "Test platform returns error correctly");
161173
DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance();
162-
NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR);
163-
NL_TEST_ASSERT(inSuite, mdnsPlatform.RemoveServices() == CHIP_NO_ERROR);
174+
EXPECT_EQ(mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()), CHIP_NO_ERROR);
175+
EXPECT_EQ(mdnsPlatform.RemoveServices(), CHIP_NO_ERROR);
164176
OperationalAdvertisingParameters params;
165-
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(params) == CHIP_ERROR_UNEXPECTED_EVENT);
177+
EXPECT_EQ(mdnsPlatform.Advertise(params), CHIP_ERROR_UNEXPECTED_EVENT);
166178
}
167179

168-
void TestOperational(nlTestSuite * inSuite, void * inContext)
180+
TEST_F(TestDnssdPlatform, TestOperational)
169181
{
170182
ChipLogError(Discovery, "Test operational");
171183
test::Reset();
172184
DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance();
173-
NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR);
174-
NL_TEST_ASSERT(inSuite, mdnsPlatform.RemoveServices() == CHIP_NO_ERROR);
185+
EXPECT_EQ(mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()), CHIP_NO_ERROR);
186+
EXPECT_EQ(mdnsPlatform.RemoveServices(), CHIP_NO_ERROR);
175187

176188
operationalCall1.callType = test::CallType::kStart;
177-
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(operationalCall1) == CHIP_NO_ERROR);
178-
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(operationalParams1) == CHIP_NO_ERROR);
189+
EXPECT_EQ(test::AddExpectedCall(operationalCall1), CHIP_NO_ERROR);
190+
EXPECT_EQ(mdnsPlatform.Advertise(operationalParams1), CHIP_NO_ERROR);
179191

180192
// Next call to advertise should call start again with just the new data.
181193
test::Reset();
182194
operationalCall2.callType = test::CallType::kStart;
183-
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(operationalCall2) == CHIP_NO_ERROR);
184-
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(operationalParams2) == CHIP_NO_ERROR);
195+
EXPECT_EQ(test::AddExpectedCall(operationalCall2), CHIP_NO_ERROR);
196+
EXPECT_EQ(mdnsPlatform.Advertise(operationalParams2), CHIP_NO_ERROR);
185197

186-
NL_TEST_ASSERT(inSuite, mdnsPlatform.FinalizeServiceUpdate() == CHIP_NO_ERROR);
198+
EXPECT_EQ(mdnsPlatform.FinalizeServiceUpdate(), CHIP_NO_ERROR);
187199
}
188200

189-
void TestCommissionableNode(nlTestSuite * inSuite, void * inContext)
201+
TEST_F(TestDnssdPlatform, TestCommissionableNode)
190202
{
191203
ChipLogError(Discovery, "Test commissionable");
192204
test::Reset();
193205
DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance();
194-
NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR);
195-
NL_TEST_ASSERT(inSuite, mdnsPlatform.RemoveServices() == CHIP_NO_ERROR);
206+
EXPECT_EQ(mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()), CHIP_NO_ERROR);
207+
EXPECT_EQ(mdnsPlatform.RemoveServices(), CHIP_NO_ERROR);
196208

197209
commissionableSmall.callType = test::CallType::kStart;
198-
NL_TEST_ASSERT(inSuite,
199-
mdnsPlatform.GetCommissionableInstanceName(commissionableSmall.instanceName,
200-
sizeof(commissionableSmall.instanceName)) == CHIP_NO_ERROR);
201-
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(commissionableSmall) == CHIP_NO_ERROR);
202-
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(commissionableNodeParamsSmall) == CHIP_NO_ERROR);
210+
EXPECT_EQ(
211+
mdnsPlatform.GetCommissionableInstanceName(commissionableSmall.instanceName, sizeof(commissionableSmall.instanceName)),
212+
CHIP_NO_ERROR);
213+
EXPECT_EQ(test::AddExpectedCall(commissionableSmall), CHIP_NO_ERROR);
214+
EXPECT_EQ(mdnsPlatform.Advertise(commissionableNodeParamsSmall), CHIP_NO_ERROR);
203215

204216
// TODO: Right now, platform impl doesn't stop commissionable node before starting a new one. Add stop call here once that is
205217
// fixed.
206218
test::Reset();
207219
commissionableLargeBasic.callType = test::CallType::kStart;
208-
NL_TEST_ASSERT(inSuite,
209-
mdnsPlatform.GetCommissionableInstanceName(commissionableLargeBasic.instanceName,
210-
sizeof(commissionableLargeBasic.instanceName)) == CHIP_NO_ERROR);
211-
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(commissionableLargeBasic) == CHIP_NO_ERROR);
212-
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(commissionableNodeParamsLargeBasic) == CHIP_NO_ERROR);
220+
EXPECT_EQ(mdnsPlatform.GetCommissionableInstanceName(commissionableLargeBasic.instanceName,
221+
sizeof(commissionableLargeBasic.instanceName)),
222+
CHIP_NO_ERROR);
223+
EXPECT_EQ(test::AddExpectedCall(commissionableLargeBasic), CHIP_NO_ERROR);
224+
EXPECT_EQ(mdnsPlatform.Advertise(commissionableNodeParamsLargeBasic), CHIP_NO_ERROR);
213225

214226
test::Reset();
215227
commissionableLargeEnhanced.callType = test::CallType::kStart;
216-
NL_TEST_ASSERT(inSuite,
217-
mdnsPlatform.GetCommissionableInstanceName(commissionableLargeEnhanced.instanceName,
218-
sizeof(commissionableLargeEnhanced.instanceName)) == CHIP_NO_ERROR);
219-
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(commissionableLargeEnhanced) == CHIP_NO_ERROR);
220-
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(commissionableNodeParamsLargeEnhanced) == CHIP_NO_ERROR);
228+
EXPECT_EQ(mdnsPlatform.GetCommissionableInstanceName(commissionableLargeEnhanced.instanceName,
229+
sizeof(commissionableLargeEnhanced.instanceName)),
230+
CHIP_NO_ERROR);
231+
EXPECT_EQ(test::AddExpectedCall(commissionableLargeEnhanced), CHIP_NO_ERROR);
232+
EXPECT_EQ(mdnsPlatform.Advertise(commissionableNodeParamsLargeEnhanced), CHIP_NO_ERROR);
221233

222-
NL_TEST_ASSERT(inSuite, mdnsPlatform.FinalizeServiceUpdate() == CHIP_NO_ERROR);
234+
EXPECT_EQ(mdnsPlatform.FinalizeServiceUpdate(), CHIP_NO_ERROR);
223235
}
224236

225-
int TestSetup(void * inContext)
226-
{
227-
return chip::Platform::MemoryInit() == CHIP_NO_ERROR ? SUCCESS : FAILURE;
228-
}
229-
230-
int TestTeardown(void * inContext)
231-
{
232-
DiscoveryImplPlatform::GetInstance().Shutdown();
233-
chip::Platform::MemoryShutdown();
234-
return SUCCESS;
235-
}
236-
237-
const nlTest sTests[] = {
238-
NL_TEST_DEF("TestStub", TestStub), //
239-
NL_TEST_DEF("TestOperational", TestOperational), //
240-
NL_TEST_DEF("TestCommissionableNode", TestCommissionableNode), //
241-
NL_TEST_SENTINEL() //
242-
};
243-
244237
} // namespace
245-
246-
int TestDnssdPlatform()
247-
{
248-
nlTestSuite theSuite = { "DnssdPlatform", &sTests[0], &TestSetup, &TestTeardown };
249-
nlTestRunner(&theSuite, nullptr);
250-
return nlTestRunnerStats(&theSuite);
251-
}
252-
253-
CHIP_REGISTER_TEST_SUITE(TestDnssdPlatform)

0 commit comments

Comments
 (0)