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

Replaced nlunit-test with pw_unit_test in src/lib/dnssd/platform/ #33072

Merged
merged 2 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
9 changes: 2 additions & 7 deletions src/lib/dnssd/platform/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@

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")

chip_test_suite_using_nltest("tests") {
chip_test_suite("tests") {
output_name = "libMdnsFakePlatformTests"
if (chip_device_platform == "fake") {
test_sources = [ "TestPlatform.cpp" ]

public_deps = [
"${chip_root}/src/lib/dnssd",
"${chip_root}/src/lib/support:testing_nlunit",
"${nlunit_test_root}:nlunit-test",
]
public_deps = [ "${chip_root}/src/lib/dnssd" ]
}
}
111 changes: 48 additions & 63 deletions src/lib/dnssd/platform/tests/TestPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

#include <lib/core/PeerId.h>
#include <lib/dnssd/Discovery_ImplPlatform.h>
#include <lib/support/UnitTestRegistration.h>

#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/fake/DnssdImpl.h>

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

#if CHIP_DEVICE_LAYER_TARGET_FAKE != 1
#error "This test is designed for use only with the fake platform"
Expand Down Expand Up @@ -152,102 +152,87 @@ test::ExpectedCall commissionableLargeEnhanced = test::ExpectedCall()
.AddSubtype("_V555")
.AddSubtype("_T70000")
.AddSubtype("_CM");
void TestStub(nlTestSuite * inSuite, void * inContext)

class TestDnssdPlatform : public ::testing::Test
{
public:
static void SetUpTestSuite()
{
ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR);
DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance();
EXPECT_EQ(mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()), CHIP_NO_ERROR);
EXPECT_EQ(mdnsPlatform.RemoveServices(), CHIP_NO_ERROR);
}

static void TearDownTestSuite()
{
DiscoveryImplPlatform::GetInstance().Shutdown();
chip::Platform::MemoryShutdown();
}

void TearDown() override { test::Reset(); }
};

TEST_F(TestDnssdPlatform, TestStub)
{
// This is a test of the fake platform impl. We want
// We want the platform to return unexpected event if it gets a start
// without an expected event.
ChipLogError(Discovery, "Test platform returns error correctly");
DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance();
NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, mdnsPlatform.RemoveServices() == CHIP_NO_ERROR);
OperationalAdvertisingParameters params;
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(params) == CHIP_ERROR_UNEXPECTED_EVENT);
EXPECT_EQ(mdnsPlatform.Advertise(params), CHIP_ERROR_UNEXPECTED_EVENT);
}

void TestOperational(nlTestSuite * inSuite, void * inContext)
TEST_F(TestDnssdPlatform, TestOperational)
{
ChipLogError(Discovery, "Test operational");
test::Reset();
DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance();
NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, mdnsPlatform.RemoveServices() == CHIP_NO_ERROR);

operationalCall1.callType = test::CallType::kStart;
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(operationalCall1) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(operationalParams1) == CHIP_NO_ERROR);
EXPECT_EQ(test::AddExpectedCall(operationalCall1), CHIP_NO_ERROR);
EXPECT_EQ(mdnsPlatform.Advertise(operationalParams1), CHIP_NO_ERROR);

// Next call to advertise should call start again with just the new data.
test::Reset();
operationalCall2.callType = test::CallType::kStart;
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(operationalCall2) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(operationalParams2) == CHIP_NO_ERROR);
EXPECT_EQ(test::AddExpectedCall(operationalCall2), CHIP_NO_ERROR);
EXPECT_EQ(mdnsPlatform.Advertise(operationalParams2), CHIP_NO_ERROR);

NL_TEST_ASSERT(inSuite, mdnsPlatform.FinalizeServiceUpdate() == CHIP_NO_ERROR);
EXPECT_EQ(mdnsPlatform.FinalizeServiceUpdate(), CHIP_NO_ERROR);
}

void TestCommissionableNode(nlTestSuite * inSuite, void * inContext)
TEST_F(TestDnssdPlatform, TestCommissionableNode)
{
ChipLogError(Discovery, "Test commissionable");
test::Reset();
DiscoveryImplPlatform & mdnsPlatform = DiscoveryImplPlatform::GetInstance();
NL_TEST_ASSERT(inSuite, mdnsPlatform.Init(DeviceLayer::UDPEndPointManager()) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, mdnsPlatform.RemoveServices() == CHIP_NO_ERROR);

commissionableSmall.callType = test::CallType::kStart;
NL_TEST_ASSERT(inSuite,
mdnsPlatform.GetCommissionableInstanceName(commissionableSmall.instanceName,
sizeof(commissionableSmall.instanceName)) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(commissionableSmall) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(commissionableNodeParamsSmall) == CHIP_NO_ERROR);
EXPECT_EQ(
mdnsPlatform.GetCommissionableInstanceName(commissionableSmall.instanceName, sizeof(commissionableSmall.instanceName)),
CHIP_NO_ERROR);
EXPECT_EQ(test::AddExpectedCall(commissionableSmall), CHIP_NO_ERROR);
EXPECT_EQ(mdnsPlatform.Advertise(commissionableNodeParamsSmall), CHIP_NO_ERROR);

// TODO: Right now, platform impl doesn't stop commissionable node before starting a new one. Add stop call here once that is
// fixed.
test::Reset();
commissionableLargeBasic.callType = test::CallType::kStart;
NL_TEST_ASSERT(inSuite,
mdnsPlatform.GetCommissionableInstanceName(commissionableLargeBasic.instanceName,
sizeof(commissionableLargeBasic.instanceName)) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(commissionableLargeBasic) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(commissionableNodeParamsLargeBasic) == CHIP_NO_ERROR);
EXPECT_EQ(mdnsPlatform.GetCommissionableInstanceName(commissionableLargeBasic.instanceName,
sizeof(commissionableLargeBasic.instanceName)),
CHIP_NO_ERROR);
EXPECT_EQ(test::AddExpectedCall(commissionableLargeBasic), CHIP_NO_ERROR);
EXPECT_EQ(mdnsPlatform.Advertise(commissionableNodeParamsLargeBasic), CHIP_NO_ERROR);

test::Reset();
commissionableLargeEnhanced.callType = test::CallType::kStart;
NL_TEST_ASSERT(inSuite,
mdnsPlatform.GetCommissionableInstanceName(commissionableLargeEnhanced.instanceName,
sizeof(commissionableLargeEnhanced.instanceName)) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, test::AddExpectedCall(commissionableLargeEnhanced) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, mdnsPlatform.Advertise(commissionableNodeParamsLargeEnhanced) == CHIP_NO_ERROR);
EXPECT_EQ(mdnsPlatform.GetCommissionableInstanceName(commissionableLargeEnhanced.instanceName,
sizeof(commissionableLargeEnhanced.instanceName)),
CHIP_NO_ERROR);
EXPECT_EQ(test::AddExpectedCall(commissionableLargeEnhanced), CHIP_NO_ERROR);
EXPECT_EQ(mdnsPlatform.Advertise(commissionableNodeParamsLargeEnhanced), CHIP_NO_ERROR);

NL_TEST_ASSERT(inSuite, mdnsPlatform.FinalizeServiceUpdate() == CHIP_NO_ERROR);
}

int TestSetup(void * inContext)
{
return chip::Platform::MemoryInit() == CHIP_NO_ERROR ? SUCCESS : FAILURE;
EXPECT_EQ(mdnsPlatform.FinalizeServiceUpdate(), CHIP_NO_ERROR);
}

int TestTeardown(void * inContext)
{
DiscoveryImplPlatform::GetInstance().Shutdown();
chip::Platform::MemoryShutdown();
return SUCCESS;
}

const nlTest sTests[] = {
NL_TEST_DEF("TestStub", TestStub), //
NL_TEST_DEF("TestOperational", TestOperational), //
NL_TEST_DEF("TestCommissionableNode", TestCommissionableNode), //
NL_TEST_SENTINEL() //
};

} // namespace

int TestDnssdPlatform()
{
nlTestSuite theSuite = { "DnssdPlatform", &sTests[0], &TestSetup, &TestTeardown };
nlTestRunner(&theSuite, nullptr);
return nlTestRunnerStats(&theSuite);
}

CHIP_REGISTER_TEST_SUITE(TestDnssdPlatform)
Loading