From 797f3472a28f52e3ac29f53de2a704f1cf43d9a3 Mon Sep 17 00:00:00 2001 From: Maksymilian Knust Date: Fri, 19 Apr 2024 11:31:57 +0200 Subject: [PATCH 1/2] Switched to pw_unit_test in src/lib/dnssd/minimal_mdns/core/ --- .../dnssd/minimal_mdns/core/tests/BUILD.gn | 5 +- .../core/tests/TestFlatAllocatedQName.cpp | 66 ++---- .../minimal_mdns/core/tests/TestHeapQName.cpp | 77 ++----- .../minimal_mdns/core/tests/TestQName.cpp | 206 +++++++----------- .../core/tests/TestRecordWriter.cpp | 60 ++--- .../openiotsdk/unit-tests/test_components.txt | 1 + .../unit-tests/test_components_nl.txt | 1 - 7 files changed, 145 insertions(+), 271 deletions(-) diff --git a/src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn b/src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn index ce985ffc651b9a..39b59bb999c9ad 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn +++ b/src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn @@ -14,7 +14,6 @@ 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") @@ -27,7 +26,7 @@ source_set("support") { ] } -chip_test_suite_using_nltest("tests") { +chip_test_suite("tests") { output_name = "libMinimalMdnsCoreTests" test_sources = [ @@ -43,7 +42,5 @@ chip_test_suite_using_nltest("tests") { ":support", "${chip_root}/src/lib/core", "${chip_root}/src/lib/dnssd/minimal_mdns/core", - "${chip_root}/src/lib/support:testing_nlunit", - "${nlunit_test_root}:nlunit-test", ] } diff --git a/src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp b/src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp index db9aa23d2a7eb1..c9ab4f222ef6f0 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp +++ b/src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp @@ -14,10 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include +#include -#include +#include namespace { @@ -38,28 +37,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"; @@ -79,23 +78,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 +109,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) diff --git a/src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp b/src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp index 51e31ca0112205..912a87be120acb 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp +++ b/src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp @@ -16,17 +16,23 @@ * limitations under the License. */ +#include + #include #include -#include - -#include namespace { using namespace mdns::Minimal; -void Construction(nlTestSuite * inSuite, void * inContext) +class TestHeapQName : public ::testing::Test +{ +public: + static void SetUpTestSuite() { VerifyOrDie(chip::Platform::MemoryInit() == CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + +TEST_F(TestHeapQName, Construction) { { @@ -34,9 +40,9 @@ void Construction(nlTestSuite * inSuite, void * inContext) HeapQName heapQName(kShort.Serialized()); - NL_TEST_ASSERT(inSuite, heapQName.IsOk()); - NL_TEST_ASSERT(inSuite, heapQName.Content() == kShort.Full()); - NL_TEST_ASSERT(inSuite, kShort.Serialized() == heapQName.Content()); + EXPECT_TRUE(heapQName.IsOk()); + EXPECT_EQ(heapQName.Content(), kShort.Full()); + EXPECT_EQ(kShort.Serialized(), heapQName.Content()); } { @@ -45,13 +51,13 @@ void Construction(nlTestSuite * inSuite, void * inContext) HeapQName heapQName(kLonger.Serialized()); - NL_TEST_ASSERT(inSuite, heapQName.IsOk()); - NL_TEST_ASSERT(inSuite, heapQName.Content() == kLonger.Full()); - NL_TEST_ASSERT(inSuite, kLonger.Serialized() == heapQName.Content()); + EXPECT_TRUE(heapQName.IsOk()); + EXPECT_EQ(heapQName.Content(), kLonger.Full()); + EXPECT_EQ(kLonger.Serialized(), heapQName.Content()); } } -void Copying(nlTestSuite * inSuite, void * inContext) +TEST_F(TestHeapQName, Copying) { const testing::TestQName<2> kShort({ "some", "test" }); @@ -61,50 +67,11 @@ void Copying(nlTestSuite * inSuite, void * inContext) name3 = name2; - NL_TEST_ASSERT(inSuite, name1.IsOk()); - NL_TEST_ASSERT(inSuite, name2.IsOk()); - NL_TEST_ASSERT(inSuite, name3.IsOk()); - NL_TEST_ASSERT(inSuite, name1.Content() == name2.Content()); - NL_TEST_ASSERT(inSuite, name1.Content() == name3.Content()); -} - -static const nlTest sTests[] = { // - NL_TEST_DEF("Construction", Construction), // - NL_TEST_DEF("Copying", Copying), // - NL_TEST_SENTINEL() -}; - -int Setup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - if (error != CHIP_NO_ERROR) - return FAILURE; - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -int Teardown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; + EXPECT_TRUE(name1.IsOk()); + EXPECT_TRUE(name2.IsOk()); + EXPECT_TRUE(name3.IsOk()); + EXPECT_EQ(name1.Content(), name2.Content()); + EXPECT_EQ(name1.Content(), name3.Content()); } } // namespace - -int TestHeapQName() -{ - nlTestSuite theSuite = { - "HeapQName", - &sTests[0], - &Setup, - &Teardown, - }; - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestHeapQName) diff --git a/src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp b/src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp index da2f91013b3217..5f430bd3c76a7a 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp +++ b/src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp @@ -16,10 +16,9 @@ * limitations under the License. */ -#include -#include +#include -#include +#include namespace { @@ -40,67 +39,67 @@ static SerializedQNameIterator AsSerializedQName(const uint8_t (&v)[N]) return SerializedQNameIterator(BytesRange(v, v + N - 1), v); } -void IteratorTest(nlTestSuite * inSuite, void * inContext) +TEST(TestQName, IteratorTest) { { static const uint8_t kOneItem[] = "\04test\00"; SerializedQNameIterator it = AsSerializedQName(kOneItem); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "test") == 0); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, it.IsValid()); + EXPECT_TRUE(it.Next()); + EXPECT_STREQ(it.Value(), "test"); + EXPECT_FALSE(it.Next()); + EXPECT_TRUE(it.IsValid()); } { static const uint8_t kManyItems[] = "\04this\02is\01a\04test\00"; SerializedQNameIterator it = AsSerializedQName(kManyItems); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "this") == 0); + EXPECT_TRUE(it.Next()); + EXPECT_STREQ(it.Value(), "this"); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "is") == 0); + EXPECT_TRUE(it.Next()); + EXPECT_STREQ(it.Value(), "is"); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "a") == 0); + EXPECT_TRUE(it.Next()); + EXPECT_STREQ(it.Value(), "a"); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "test") == 0); + EXPECT_TRUE(it.Next()); + EXPECT_STREQ(it.Value(), "test"); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, it.IsValid()); + EXPECT_FALSE(it.Next()); + EXPECT_TRUE(it.IsValid()); } { static const uint8_t kPtrItems[] = "abc\02is\01a\04test\00\04this\xc0\03"; SerializedQNameIterator it(BytesRange(kPtrItems, kPtrItems + sizeof(kPtrItems)), kPtrItems + 14); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "this") == 0); + EXPECT_TRUE(it.Next()); + EXPECT_STREQ(it.Value(), "this"); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "is") == 0); + EXPECT_TRUE(it.Next()); + EXPECT_STREQ(it.Value(), "is"); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "a") == 0); + EXPECT_TRUE(it.Next()); + EXPECT_STREQ(it.Value(), "a"); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "test") == 0); + EXPECT_TRUE(it.Next()); + EXPECT_STREQ(it.Value(), "test"); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, it.IsValid()); + EXPECT_FALSE(it.Next()); + EXPECT_TRUE(it.IsValid()); } } -void ErrorTest(nlTestSuite * inSuite, void * inContext) +TEST(TestQName, ErrorTest) { { // Truncated before the end static const uint8_t kData[] = "\04test"; SerializedQNameIterator it = AsSerializedQName(kData); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, !it.IsValid()); + EXPECT_FALSE(it.Next()); + EXPECT_FALSE(it.IsValid()); } { @@ -108,8 +107,8 @@ void ErrorTest(nlTestSuite * inSuite, void * inContext) static const uint8_t kData[] = "\02"; SerializedQNameIterator it = AsSerializedQName(kData); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, !it.IsValid()); + EXPECT_FALSE(it.Next()); + EXPECT_FALSE(it.IsValid()); } { @@ -117,12 +116,12 @@ void ErrorTest(nlTestSuite * inSuite, void * inContext) static const uint8_t kData[] = "\xc0"; SerializedQNameIterator it = AsSerializedQName(kData); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, !it.IsValid()); + EXPECT_FALSE(it.Next()); + EXPECT_FALSE(it.IsValid()); } } -void InvalidReferencing(nlTestSuite * inSuite, void * inContext) +TEST(TestQName, InvalidReferencing) { { // Truncated before the end (but seemingly valid in case of error) @@ -130,8 +129,8 @@ void InvalidReferencing(nlTestSuite * inSuite, void * inContext) static const uint8_t kData[] = "\00\xc0\x00"; SerializedQNameIterator it(BytesRange(kData, kData + 2), kData + 1); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, !it.IsValid()); + EXPECT_FALSE(it.Next()); + EXPECT_FALSE(it.IsValid()); } { @@ -139,9 +138,9 @@ void InvalidReferencing(nlTestSuite * inSuite, void * inContext) static const uint8_t kData[] = "\03test\xc0\x00"; SerializedQNameIterator it = AsSerializedQName(kData); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, !it.IsValid()); + EXPECT_TRUE(it.Next()); + EXPECT_FALSE(it.Next()); + EXPECT_FALSE(it.IsValid()); } { @@ -149,9 +148,9 @@ void InvalidReferencing(nlTestSuite * inSuite, void * inContext) static const uint8_t kData[] = "\03test\xc0\x05"; SerializedQNameIterator it = AsSerializedQName(kData); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, !it.IsValid()); + EXPECT_TRUE(it.Next()); + EXPECT_FALSE(it.Next()); + EXPECT_FALSE(it.IsValid()); } { @@ -159,8 +158,8 @@ void InvalidReferencing(nlTestSuite * inSuite, void * inContext) static const uint8_t kData[] = "\xc0\x00"; SerializedQNameIterator it = AsSerializedQName(kData); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, !it.IsValid()); + EXPECT_FALSE(it.Next()); + EXPECT_FALSE(it.IsValid()); } { @@ -168,171 +167,134 @@ void InvalidReferencing(nlTestSuite * inSuite, void * inContext) static const uint8_t kData[] = "\03test\xc0\x07"; SerializedQNameIterator it = AsSerializedQName(kData); - NL_TEST_ASSERT(inSuite, it.Next()); - NL_TEST_ASSERT(inSuite, !it.Next()); - NL_TEST_ASSERT(inSuite, !it.IsValid()); + EXPECT_TRUE(it.Next()); + EXPECT_FALSE(it.Next()); + EXPECT_FALSE(it.IsValid()); } } -void Comparison(nlTestSuite * inSuite, void * inContext) +TEST(TestQName, Comparison) { static const uint8_t kManyItems[] = "\04this\02is\01a\04test\00"; { const QNamePart kTestName[] = { "this" }; - NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName)); + EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName)); } { const QNamePart kTestName[] = { "this", "is" }; - NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName)); + EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName)); } { const QNamePart kTestName[] = { "is", "a", "test" }; - NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName)); + EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName)); } { const QNamePart kTestName[] = { "this", "is", "a", "test" }; - NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) == FullQName(kTestName)); + EXPECT_EQ(AsSerializedQName(kManyItems), FullQName(kTestName)); } { const QNamePart kTestName[] = { "this", "is", "a", "test", "suffix" }; - NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName)); + EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName)); } { const QNamePart kTestName[] = { "prefix", "this", "is", "a", "test" }; - NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName)); + EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName)); } } -void CaseInsensitiveSerializedCompare(nlTestSuite * inSuite, void * inContext) +TEST(TestQName, CaseInsensitiveSerializedCompare) { static const uint8_t kManyItems[] = "\04thIs\02iS\01a\04tEst\00"; { const QNamePart kTestName[] = { "this", "is", "a", "test" }; - NL_TEST_ASSERT(inSuite, - SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems) == - FullQName(kTestName)); + EXPECT_EQ(SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems), + FullQName(kTestName)); } { const QNamePart kTestName[] = { "THIS", "IS", "A", "test" }; - NL_TEST_ASSERT(inSuite, - SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems) == - FullQName(kTestName)); + EXPECT_EQ(SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems), + FullQName(kTestName)); } { const QNamePart kTestName[] = { "THIS", "IS", "A", "TEST" }; - NL_TEST_ASSERT(inSuite, - SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems) == - FullQName(kTestName)); + EXPECT_EQ(SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems), + FullQName(kTestName)); } } -void CaseInsensitiveFullQNameCompare(nlTestSuite * inSuite, void * inContext) +TEST(TestQName, CaseInsensitiveFullQNameCompare) { { const QNamePart kName1[] = { "this", "is", "a", "test" }; const QNamePart kName2[] = { "this", "IS", "a", "TEST" }; - NL_TEST_ASSERT(inSuite, FullQName(kName1) == FullQName(kName2)); + EXPECT_EQ(FullQName(kName1), FullQName(kName2)); } { const QNamePart kName1[] = { "THIS", "IS", "a", "tesT" }; const QNamePart kName2[] = { "this", "IS", "A", "TEst" }; - NL_TEST_ASSERT(inSuite, FullQName(kName1) == FullQName(kName2)); + EXPECT_EQ(FullQName(kName1), FullQName(kName2)); } { const QNamePart kName1[] = { "THIS", "IS", "a", "test" }; const QNamePart kName2[] = { "this", "IS", "A", "NEST" }; - NL_TEST_ASSERT(inSuite, FullQName(kName1) != FullQName(kName2)); + EXPECT_NE(FullQName(kName1), FullQName(kName2)); } { const QNamePart kName1[] = { "THIS", "IS", "a" }; const QNamePart kName2[] = { "this", "IS", "A", "NEST" }; - NL_TEST_ASSERT(inSuite, FullQName(kName1) != FullQName(kName2)); + EXPECT_NE(FullQName(kName1), FullQName(kName2)); } { const QNamePart kName1[] = { "THIS", "IS", "a" }; const QNamePart kName2[] = { "this", "IS" }; - NL_TEST_ASSERT(inSuite, FullQName(kName1) != FullQName(kName2)); + EXPECT_NE(FullQName(kName1), FullQName(kName2)); } { const QNamePart kName[] = { "this" }; - NL_TEST_ASSERT(inSuite, FullQName() != FullQName(kName)); - NL_TEST_ASSERT(inSuite, FullQName(kName) != FullQName()); + EXPECT_NE(FullQName(), FullQName(kName)); + EXPECT_NE(FullQName(kName), FullQName()); } } -void SerializedCompare(nlTestSuite * inSuite, void * inContext) +TEST(TestQName, SerializedCompare) { static const uint8_t kThisIsATest1[] = "\04this\02is\01a\04test\00"; static const uint8_t kThisIsATest2[] = "\04ThIs\02is\01A\04tESt\00"; static const uint8_t kThisIsDifferent[] = "\04this\02is\09different\00"; static const uint8_t kThisIs[] = "\04this\02is"; - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest1) == AsSerializedQName(kThisIsATest1)); - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest2) == AsSerializedQName(kThisIsATest2)); - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest1) == AsSerializedQName(kThisIsATest2)); - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest1) != AsSerializedQName(kThisIsDifferent)); - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsDifferent) != AsSerializedQName(kThisIsATest1)); - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsDifferent) != AsSerializedQName(kThisIs)); - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIs) != AsSerializedQName(kThisIsDifferent)); + EXPECT_EQ(AsSerializedQName(kThisIsATest1), AsSerializedQName(kThisIsATest1)); + EXPECT_EQ(AsSerializedQName(kThisIsATest2), AsSerializedQName(kThisIsATest2)); + EXPECT_EQ(AsSerializedQName(kThisIsATest1), AsSerializedQName(kThisIsATest2)); + EXPECT_NE(AsSerializedQName(kThisIsATest1), AsSerializedQName(kThisIsDifferent)); + EXPECT_NE(AsSerializedQName(kThisIsDifferent), AsSerializedQName(kThisIsATest1)); + EXPECT_NE(AsSerializedQName(kThisIsDifferent), AsSerializedQName(kThisIs)); + EXPECT_NE(AsSerializedQName(kThisIs), AsSerializedQName(kThisIsDifferent)); // These items have back references and are "this.is.a.test" static const uint8_t kPtrItems[] = "\03abc\02is\01a\04test\00\04this\xc0\04"; SerializedQNameIterator thisIsATestPtr(BytesRange(kPtrItems, kPtrItems + sizeof(kPtrItems)), kPtrItems + 15); - NL_TEST_ASSERT(inSuite, thisIsATestPtr == AsSerializedQName(kThisIsATest1)); - NL_TEST_ASSERT(inSuite, thisIsATestPtr == AsSerializedQName(kThisIsATest2)); - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest1) == thisIsATestPtr); - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest2) == thisIsATestPtr); - NL_TEST_ASSERT(inSuite, thisIsATestPtr != AsSerializedQName(kThisIs)); - NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIs) != thisIsATestPtr); + EXPECT_EQ(thisIsATestPtr, AsSerializedQName(kThisIsATest1)); + EXPECT_EQ(thisIsATestPtr, AsSerializedQName(kThisIsATest2)); + EXPECT_EQ(AsSerializedQName(kThisIsATest1), thisIsATestPtr); + EXPECT_EQ(AsSerializedQName(kThisIsATest2), thisIsATestPtr); + EXPECT_NE(thisIsATestPtr, AsSerializedQName(kThisIs)); + EXPECT_NE(AsSerializedQName(kThisIs), thisIsATestPtr); } } // namespace - -// clang-format off -static const nlTest sTests[] = -{ - NL_TEST_DEF("IteratorTest", IteratorTest), - NL_TEST_DEF("ErrorTest", ErrorTest), - NL_TEST_DEF("Comparison", Comparison), - NL_TEST_DEF("CaseInsensitiveSerializedCompare", CaseInsensitiveSerializedCompare), - NL_TEST_DEF("CaseInsensitiveFullQNameCompare", CaseInsensitiveFullQNameCompare), - NL_TEST_DEF("SerializedCompare", SerializedCompare), - NL_TEST_DEF("InvalidReferencing", InvalidReferencing), - - NL_TEST_SENTINEL() -}; -// clang-format on - -int TestQName() -{ - // clang-format off - nlTestSuite theSuite = - { - "QName", - &sTests[0], - nullptr, - nullptr - }; - // clang-format on - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestQName) diff --git a/src/lib/dnssd/minimal_mdns/core/tests/TestRecordWriter.cpp b/src/lib/dnssd/minimal_mdns/core/tests/TestRecordWriter.cpp index e6e2e9611f38c6..f8dbc220978c87 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/TestRecordWriter.cpp +++ b/src/lib/dnssd/minimal_mdns/core/tests/TestRecordWriter.cpp @@ -16,17 +16,16 @@ * limitations under the License. */ -#include -#include +#include -#include +#include namespace { using namespace mdns::Minimal; using namespace chip::Encoding::BigEndian; -void BasicWriteTest(nlTestSuite * inSuite, void * inContext) +TEST(TestRecordWriter, BasicWriteTest) { const QNamePart kName1[] = { "some", "name" }; const QNamePart kName2[] = { "abc", "xyz", "here" }; @@ -52,11 +51,11 @@ void BasicWriteTest(nlTestSuite * inSuite, void * inContext) }; // clang-format on - NL_TEST_ASSERT(inSuite, output.Needed() == sizeof(expectedOutput)); - NL_TEST_ASSERT(inSuite, memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)) == 0); + EXPECT_EQ(output.Needed(), sizeof(expectedOutput)); + EXPECT_EQ(memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)), 0); } -void SimpleDedup(nlTestSuite * inSuite, void * inContext) +TEST(TestRecordWriter, SimpleDedup) { const QNamePart kName1[] = { "some", "name" }; const QNamePart kName2[] = { "other", "name" }; @@ -80,11 +79,11 @@ void SimpleDedup(nlTestSuite * inSuite, void * inContext) }; // clang-format on - NL_TEST_ASSERT(inSuite, output.Needed() == sizeof(expectedOutput)); - NL_TEST_ASSERT(inSuite, memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)) == 0); + EXPECT_EQ(output.Needed(), sizeof(expectedOutput)); + EXPECT_EQ(memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)), 0); } -void ComplexDedup(nlTestSuite * inSuite, void * inContext) +TEST(TestRecordWriter, ComplexDedup) { const QNamePart kName1[] = { "some", "name" }; const QNamePart kName2[] = { "other", "name" }; @@ -125,11 +124,11 @@ void ComplexDedup(nlTestSuite * inSuite, void * inContext) }; // clang-format on - NL_TEST_ASSERT(inSuite, output.Needed() == sizeof(expectedOutput)); - NL_TEST_ASSERT(inSuite, memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)) == 0); + EXPECT_EQ(output.Needed(), sizeof(expectedOutput)); + EXPECT_EQ(memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)), 0); } -void TonsOfReferences(nlTestSuite * inSuite, void * inContext) +TEST(TestRecordWriter, TonsOfReferences) { const QNamePart kName1[] = { "some", "name" }; const QNamePart kName2[] = { "different", "name" }; @@ -159,39 +158,8 @@ void TonsOfReferences(nlTestSuite * inSuite, void * inContext) writer.WriteQName(FullQName(kName2)); } - NL_TEST_ASSERT(inSuite, output.Fit()); - NL_TEST_ASSERT(inSuite, output.Needed() == 423); + EXPECT_TRUE(output.Fit()); + EXPECT_EQ(output.Needed(), 423u); } } // namespace - -// clang-format off -static const nlTest sTests[] = -{ - NL_TEST_DEF("BasicWriteTest", BasicWriteTest), - NL_TEST_DEF("SimpleDedup", SimpleDedup), - NL_TEST_DEF("ComplexDedup", ComplexDedup), - NL_TEST_DEF("TonsOfReferences", TonsOfReferences), - - NL_TEST_SENTINEL() -}; -// clang-format on - -int TestRecordWriter() -{ - // clang-format off - nlTestSuite theSuite = - { - "RecordWriter", - &sTests[0], - nullptr, - nullptr - }; - // clang-format on - - nlTestRunner(&theSuite, nullptr); - - return (nlTestRunnerStats(&theSuite)); -} - -CHIP_REGISTER_TEST_SUITE(TestRecordWriter) diff --git a/src/test_driver/openiotsdk/unit-tests/test_components.txt b/src/test_driver/openiotsdk/unit-tests/test_components.txt index bc9d77e48d075f..4371d668594ca8 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components.txt @@ -1,2 +1,3 @@ accesstest +MinimalMdnsCoreTests PlatformTests diff --git a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt index 0e012ff3354f02..eb80af8247457d 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt @@ -8,7 +8,6 @@ DataModelTests InetLayerTests MdnsTests MessagingLayerTests -MinimalMdnsCoreTests MinimalMdnsRecordsTests MinimalMdnsRespondersTests RawTransportTests From d51eeec9e45866304fb80c9c5f43d46437988a92 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Sat, 20 Apr 2024 06:59:53 +0200 Subject: [PATCH 2/2] Update src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp --- src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp b/src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp index 912a87be120acb..22287751ac5f05 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp +++ b/src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp @@ -28,7 +28,7 @@ using namespace mdns::Minimal; class TestHeapQName : public ::testing::Test { public: - static void SetUpTestSuite() { VerifyOrDie(chip::Platform::MemoryInit() == CHIP_NO_ERROR); } + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } };