Skip to content

Commit

Permalink
Revert "converting 3 minimal mDNS unit tests from NL_unit to pw_unit"
Browse files Browse the repository at this point in the history
This reverts commit 4271f3f.
  • Loading branch information
Alami-Amine committed Apr 19, 2024
1 parent 801e3dc commit bcdef5e
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 152 deletions.
19 changes: 2 additions & 17 deletions src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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 @@ -28,32 +27,18 @@ source_set("support") {
]
}

chip_test_suite("tests") {
chip_test_suite_using_nltest("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
65 changes: 42 additions & 23 deletions src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
* limitations under the License.
*/
#include <lib/dnssd/minimal_mdns/core/FlatAllocatedQName.h>
#include <gtest/gtest.h>
#include <lib/support/UnitTestRegistration.h>

#include <nlunit-test.h>

namespace {

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


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

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

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

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

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

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


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

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

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

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

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


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

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

EXPECT_EQ(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 4));
NL_TEST_ASSERT(inSuite, 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.
EXPECT_EQ(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 4));
NL_TEST_ASSERT(inSuite, kTestQName == FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 4));
// If we add the extra word, the names
EXPECT_NE(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 5));
NL_TEST_ASSERT(inSuite, kTestQName != FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 5));

EXPECT_NE(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
EXPECT_EQ(FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 3), FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
NL_TEST_ASSERT(inSuite, kTestQName != FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
NL_TEST_ASSERT(inSuite,
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

0 comments on commit bcdef5e

Please sign in to comment.