Skip to content

Commit 2eeffec

Browse files
committed
Switched to pw_unit_test in src/lib/dnssd/minimal_mdns/tests/
1 parent 80b2f61 commit 2eeffec

7 files changed

+402
-531
lines changed

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
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
import("${chip_root}/build/chip/fuzz_test.gni")
2120

22-
chip_test_suite_using_nltest("tests") {
21+
chip_test_suite("tests") {
2322
output_name = "libMinimalMdnstests"
2423

2524
sources = [ "CheckOnlyServer.h" ]
@@ -40,9 +39,7 @@ chip_test_suite_using_nltest("tests") {
4039
"${chip_root}/src/lib/core",
4140
"${chip_root}/src/lib/dnssd",
4241
"${chip_root}/src/lib/dnssd/minimal_mdns",
43-
"${chip_root}/src/lib/support:testing_nlunit",
4442
"${chip_root}/src/transport/raw/tests:helpers",
45-
"${nlunit_test_root}:nlunit-test",
4643
]
4744
}
4845

src/lib/dnssd/minimal_mdns/tests/CheckOnlyServer.h

+11-22
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
#include <lib/dnssd/minimal_mdns/records/Srv.h>
3030
#include <lib/dnssd/minimal_mdns/records/Txt.h>
3131
#include <lib/support/CHIPMemString.h>
32-
#include <lib/support/UnitTestRegistration.h>
3332
#include <system/SystemMutex.h>
3433

35-
#include <nlunit-test.h>
34+
#include <gtest/gtest.h>
3635

3736
namespace mdns {
3837
namespace Minimal {
@@ -78,23 +77,19 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
7877
public TxtRecordDelegate
7978
{
8079
public:
81-
CheckOnlyServer(nlTestSuite * inSuite) : ServerBase(*static_cast<ServerBase::EndpointInfoPoolType *>(this)), mInSuite(inSuite)
82-
{
83-
Reset();
84-
}
85-
CheckOnlyServer() : ServerBase(*static_cast<ServerBase::EndpointInfoPoolType *>(this)), mInSuite(nullptr) { Reset(); }
80+
CheckOnlyServer() : ServerBase(*static_cast<ServerBase::EndpointInfoPoolType *>(this)) { Reset(); }
8681
~CheckOnlyServer() {}
8782

8883
// Parser delegates
8984
void OnHeader(ConstHeaderRef & header) override
9085
{
91-
NL_TEST_ASSERT(mInSuite, header.GetFlags().IsResponse());
92-
NL_TEST_ASSERT(mInSuite, header.GetFlags().IsValidMdns());
86+
EXPECT_TRUE(header.GetFlags().IsResponse());
87+
EXPECT_TRUE(header.GetFlags().IsValidMdns());
9388
mTotalRecords += header.GetAnswerCount() + header.GetAdditionalCount();
9489

9590
if (!header.GetFlags().IsTruncated())
9691
{
97-
NL_TEST_ASSERT(mInSuite, mTotalRecords == GetNumExpectedRecords());
92+
EXPECT_EQ(mTotalRecords, GetNumExpectedRecords());
9893
if (mTotalRecords != GetNumExpectedRecords())
9994
{
10095
ChipLogError(Discovery, "Received %d records, expected %d", mTotalRecords, GetNumExpectedRecords());
@@ -114,7 +109,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
114109
case QType::SRV: {
115110
SrvRecord srv;
116111
bool srvParseOk = srv.Parse(data.GetData(), mPacketData);
117-
NL_TEST_ASSERT(mInSuite, srvParseOk);
112+
EXPECT_TRUE(srvParseOk);
118113
if (!srvParseOk)
119114
{
120115
return;
@@ -146,7 +141,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
146141
for (size_t t = 0; t < expectedTxt->GetNumEntries(); ++t)
147142
{
148143
bool ok = AddExpectedTxtRecord(expectedTxt->GetEntries()[t]);
149-
NL_TEST_ASSERT(mInSuite, ok);
144+
EXPECT_TRUE(ok);
150145
}
151146
ParseTxtRecord(data.GetData(), this);
152147
if (CheckTxtRecordMatches())
@@ -164,7 +159,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
164159
}
165160
}
166161
}
167-
NL_TEST_ASSERT(mInSuite, recordIsExpected);
162+
EXPECT_TRUE(recordIsExpected);
168163
if (!recordIsExpected)
169164
{
170165
char nameStr[64];
@@ -253,7 +248,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
253248
void AddExpectedRecord(SrvResourceRecord * srv)
254249
{
255250
RecordInfo * info = AddExpectedRecordBase(srv);
256-
NL_TEST_ASSERT(mInSuite, info != nullptr);
251+
ASSERT_NE(info, nullptr);
257252
if (info == nullptr)
258253
{
259254
return;
@@ -263,7 +258,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
263258
void AddExpectedRecord(TxtResourceRecord * txt)
264259
{
265260
RecordInfo * info = AddExpectedRecordBase(txt);
266-
NL_TEST_ASSERT(mInSuite, info != nullptr);
261+
ASSERT_NE(info, nullptr);
267262
if (info == nullptr)
268263
{
269264
return;
@@ -272,7 +267,6 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
272267
}
273268
bool GetSendCalled() { return mSendCalled; }
274269
bool GetHeaderFound() { return mHeaderFound; }
275-
void SetTestSuite(nlTestSuite * suite) { mInSuite = suite; }
276270
void Reset()
277271
{
278272
for (auto & info : mExpectedRecordInfo)
@@ -287,7 +281,6 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
287281
}
288282

289283
private:
290-
nlTestSuite * mInSuite;
291284
static constexpr size_t kMaxExpectedRecords = 10;
292285
struct RecordInfo
293286
{
@@ -335,17 +328,13 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
335328
}
336329
void TestGotAllExpectedPackets()
337330
{
338-
if (mInSuite == nullptr)
339-
{
340-
return;
341-
}
342331
for (auto & info : mExpectedRecordInfo)
343332
{
344333
if (info.record == nullptr)
345334
{
346335
continue;
347336
}
348-
NL_TEST_ASSERT(mInSuite, info.found == true);
337+
EXPECT_TRUE(info.found);
349338
if (!info.found)
350339
{
351340
char name[64];

0 commit comments

Comments
 (0)