Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched to pw_unit_test in src/lib/dnssd/minimal_mdns/tests/ #33068

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/lib/dnssd/minimal_mdns/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/nlunit_test.gni")

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

chip_test_suite_using_nltest("tests") {
chip_test_suite("tests") {
output_name = "libMinimalMdnstests"

sources = [ "CheckOnlyServer.h" ]
Expand All @@ -40,9 +39,7 @@ chip_test_suite_using_nltest("tests") {
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/dnssd",
"${chip_root}/src/lib/dnssd/minimal_mdns",
"${chip_root}/src/lib/support:testing_nlunit",
"${chip_root}/src/transport/raw/tests:helpers",
"${nlunit_test_root}:nlunit-test",
]
}

Expand Down
33 changes: 11 additions & 22 deletions src/lib/dnssd/minimal_mdns/tests/CheckOnlyServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
#include <lib/dnssd/minimal_mdns/records/Srv.h>
#include <lib/dnssd/minimal_mdns/records/Txt.h>
#include <lib/support/CHIPMemString.h>
#include <lib/support/UnitTestRegistration.h>
#include <system/SystemMutex.h>

#include <nlunit-test.h>
#include <gtest/gtest.h>

namespace mdns {
namespace Minimal {
Expand Down Expand Up @@ -78,23 +77,19 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
public TxtRecordDelegate
{
public:
CheckOnlyServer(nlTestSuite * inSuite) : ServerBase(*static_cast<ServerBase::EndpointInfoPoolType *>(this)), mInSuite(inSuite)
{
Reset();
}
CheckOnlyServer() : ServerBase(*static_cast<ServerBase::EndpointInfoPoolType *>(this)), mInSuite(nullptr) { Reset(); }
CheckOnlyServer() : ServerBase(*static_cast<ServerBase::EndpointInfoPoolType *>(this)) { Reset(); }
~CheckOnlyServer() {}

// Parser delegates
void OnHeader(ConstHeaderRef & header) override
{
NL_TEST_ASSERT(mInSuite, header.GetFlags().IsResponse());
NL_TEST_ASSERT(mInSuite, header.GetFlags().IsValidMdns());
EXPECT_TRUE(header.GetFlags().IsResponse());
EXPECT_TRUE(header.GetFlags().IsValidMdns());
mTotalRecords += header.GetAnswerCount() + header.GetAdditionalCount();

if (!header.GetFlags().IsTruncated())
{
NL_TEST_ASSERT(mInSuite, mTotalRecords == GetNumExpectedRecords());
EXPECT_EQ(mTotalRecords, GetNumExpectedRecords());
if (mTotalRecords != GetNumExpectedRecords())
{
ChipLogError(Discovery, "Received %d records, expected %d", mTotalRecords, GetNumExpectedRecords());
Expand All @@ -114,7 +109,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
case QType::SRV: {
SrvRecord srv;
bool srvParseOk = srv.Parse(data.GetData(), mPacketData);
NL_TEST_ASSERT(mInSuite, srvParseOk);
EXPECT_TRUE(srvParseOk);
if (!srvParseOk)
{
return;
Expand Down Expand Up @@ -146,7 +141,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
for (size_t t = 0; t < expectedTxt->GetNumEntries(); ++t)
{
bool ok = AddExpectedTxtRecord(expectedTxt->GetEntries()[t]);
NL_TEST_ASSERT(mInSuite, ok);
EXPECT_TRUE(ok);
}
ParseTxtRecord(data.GetData(), this);
if (CheckTxtRecordMatches())
Expand All @@ -164,7 +159,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
}
}
}
NL_TEST_ASSERT(mInSuite, recordIsExpected);
EXPECT_TRUE(recordIsExpected);
if (!recordIsExpected)
{
char nameStr[64];
Expand Down Expand Up @@ -253,7 +248,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
void AddExpectedRecord(SrvResourceRecord * srv)
{
RecordInfo * info = AddExpectedRecordBase(srv);
NL_TEST_ASSERT(mInSuite, info != nullptr);
ASSERT_NE(info, nullptr);
if (info == nullptr)
{
return;
Expand All @@ -263,7 +258,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
void AddExpectedRecord(TxtResourceRecord * txt)
{
RecordInfo * info = AddExpectedRecordBase(txt);
NL_TEST_ASSERT(mInSuite, info != nullptr);
ASSERT_NE(info, nullptr);
if (info == nullptr)
{
return;
Expand All @@ -272,7 +267,6 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
}
bool GetSendCalled() { return mSendCalled; }
bool GetHeaderFound() { return mHeaderFound; }
void SetTestSuite(nlTestSuite * suite) { mInSuite = suite; }
void Reset()
{
for (auto & info : mExpectedRecordInfo)
Expand All @@ -287,7 +281,6 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
}

private:
nlTestSuite * mInSuite;
static constexpr size_t kMaxExpectedRecords = 10;
struct RecordInfo
{
Expand Down Expand Up @@ -335,17 +328,13 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
}
void TestGotAllExpectedPackets()
{
if (mInSuite == nullptr)
{
return;
}
for (auto & info : mExpectedRecordInfo)
{
if (info.record == nullptr)
{
continue;
}
NL_TEST_ASSERT(mInSuite, info.found == true);
EXPECT_TRUE(info.found);
if (!info.found)
{
char name[64];
Expand Down
Loading
Loading