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

converting 3 minimal mDNS unit tests from NL_unit to pw_unit #33048

Closed
wants to merge 15 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ if (chip_build_tests) {
if (current_os != "mbed") {
tests += [
"${chip_root}/src/lib/dnssd/minimal_mdns/core/tests",
"${chip_root}/src/lib/dnssd/minimal_mdns/core/tests:tests_nltest",
"${chip_root}/src/lib/dnssd/minimal_mdns/responders/tests",
"${chip_root}/src/lib/dnssd/minimal_mdns/tests",
"${chip_root}/src/lib/dnssd/tests",
Expand Down
19 changes: 17 additions & 2 deletions src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/nlunit_test.gni")
import("//build_overrides/pigweed.gni")

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

Expand All @@ -27,18 +28,32 @@ source_set("support") {
]
}

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

test_sources = [
"TestFlatAllocatedQName.cpp",
"TestHeapQName.cpp",
"TestQName.cpp",
"TestRecordWriter.cpp",
]

cflags = [ "-Wconversion" ]

public_deps = [
":support",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/dnssd/minimal_mdns/core",
]
}

#nl tests will not be compiled
chip_test_suite_using_nltest("tests_nltest") {
output_name = "libMinimalMdnsCoreTestsNL"

test_sources = [ "TestHeapQName.cpp" ]

cflags = [ "-Wconversion" ]

public_deps = [
":support",
"${chip_root}/src/lib/core",
Expand Down
64 changes: 22 additions & 42 deletions src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <lib/dnssd/minimal_mdns/core/FlatAllocatedQName.h>
#include <lib/support/UnitTestRegistration.h>

#include <nlunit-test.h>

namespace {

Expand All @@ -38,28 +36,28 @@ class AutoFreeBuffer
void * mBuffer;
};

void TestFlatAllocatedQName(nlTestSuite * inSuite, void * inContext)
TEST(TestFlatAllocatedQName, TestFlatAllocatedQName)
{
AutoFreeBuffer buffer(128);

NL_TEST_ASSERT(inSuite, FlatAllocatedQName::RequiredStorageSize("some", "test") == (sizeof(char * [2]) + 5 + 5));
EXPECT_EQ(FlatAllocatedQName::RequiredStorageSize("some", "test"), (sizeof(char * [2]) + 5 + 5));

{
FullQName built = FlatAllocatedQName::Build(buffer.Buffer(), "some", "test");
const QNamePart expected[] = { "some", "test" };

NL_TEST_ASSERT(inSuite, FullQName(expected) == built);
EXPECT_EQ(FullQName(expected), built);
}

{
FullQName built = FlatAllocatedQName::Build(buffer.Buffer(), "1", "2", "3");
const QNamePart expected[] = { "1", "2", "3" };

NL_TEST_ASSERT(inSuite, FullQName(expected) == built);
EXPECT_EQ(FullQName(expected), built);
}
}

void SizeCompare(nlTestSuite * inSuite, void * inContext)
TEST(TestFlatAllocatedQName, SizeCompare)
{
static const char kThis[] = "this";
static const char kIs[] = "is";
Expand All @@ -79,23 +77,22 @@ void SizeCompare(nlTestSuite * inSuite, void * inContext)

const size_t kTestStorageSize = FlatAllocatedQName::RequiredStorageSize(kThis, kIs, kA, kTest);

NL_TEST_ASSERT(inSuite, kTestStorageSize == FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 4));
NL_TEST_ASSERT(inSuite, kTestStorageSize == FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferentArraySameSize, 4));
NL_TEST_ASSERT(inSuite, kTestStorageSize < FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayLongerWord, 4));
NL_TEST_ASSERT(inSuite, kTestStorageSize > FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayShorterWord, 4));
EXPECT_EQ(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 4));
EXPECT_EQ(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferentArraySameSize, 4));
EXPECT_LT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayLongerWord, 4));
EXPECT_GT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayShorterWord, 4));

// Although the size of the array is larger, if we tell the function there are only 4 words, it should still work.
NL_TEST_ASSERT(inSuite, kTestStorageSize == FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 4));
EXPECT_EQ(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 4));
// If we add the extra word, the sizes should not match
NL_TEST_ASSERT(inSuite, kTestStorageSize < FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 5));
EXPECT_LT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 5));

NL_TEST_ASSERT(inSuite, kTestStorageSize > FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
NL_TEST_ASSERT(inSuite,
FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 3) ==
FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
EXPECT_GT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
EXPECT_EQ(FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 3),
FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
}

void BuildCompare(nlTestSuite * inSuite, void * inContext)
TEST(TestFlatAllocatedQName, BuildCompare)
{
static const char kThis[] = "this";
static const char kIs[] = "is";
Expand All @@ -111,33 +108,16 @@ void BuildCompare(nlTestSuite * inSuite, void * inContext)

const FullQName kTestQName = FlatAllocatedQName::Build(storage, kThis, kIs, kA, kTest);

NL_TEST_ASSERT(inSuite, kTestQName == FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 4));
EXPECT_EQ(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 4));

// Although the size of the array is larger, if we tell the function there are only 4 words, it should still work.
NL_TEST_ASSERT(inSuite, kTestQName == FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 4));
EXPECT_EQ(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 4));
// If we add the extra word, the names
NL_TEST_ASSERT(inSuite, kTestQName != FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 5));
EXPECT_NE(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 5));

NL_TEST_ASSERT(inSuite, kTestQName != FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
NL_TEST_ASSERT(inSuite,
FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 3) ==
FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
EXPECT_NE(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
EXPECT_EQ(FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 3),
FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
}

const nlTest sTests[] = {
NL_TEST_DEF("TestFlatAllocatedQName", TestFlatAllocatedQName), //
NL_TEST_DEF("TestFlatAllocatedQNameRequiredSizes", SizeCompare), //
NL_TEST_DEF("TestFlatAllocatedQNameBuild", BuildCompare), //
NL_TEST_SENTINEL() //
};

} // namespace

int TestFlatAllocatedQName()
{
nlTestSuite theSuite = { "FlatAllocatedQName", sTests, nullptr, nullptr };
nlTestRunner(&theSuite, nullptr);
return nlTestRunnerStats(&theSuite);
}

CHIP_REGISTER_TEST_SUITE(TestFlatAllocatedQName)
Loading
Loading