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

Aa/nlsetup #33078

Closed
wants to merge 4 commits into from
Closed
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
@@ -86,6 +86,7 @@ if (chip_build_tests) {
chip_device_platform != "efr32") {
tests += [
"${chip_root}/src/setup_payload/tests",
"${chip_root}/src/setup_payload/tests:tests_nltest",
"${chip_root}/src/transport/raw/tests",
]
}
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
@@ -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")

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

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

namespace {

@@ -38,28 +36,30 @@ 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";
@@ -79,23 +79,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";
@@ -111,33 +110,15 @@ 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