diff --git a/src/BUILD.gn b/src/BUILD.gn index 25f0a57211766b..95d5ded33269a3 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -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", diff --git a/src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn b/src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn index ce985ffc651b9a..973f571ec9b623 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn +++ b/src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn @@ -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", diff --git a/src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp b/src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp index db9aa23d2a7eb1..11490ed0f83468 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp +++ b/src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp @@ -14,10 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include -#include - -#include namespace { @@ -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"; @@ -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"; @@ -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) diff --git a/src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp b/src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp index da2f91013b3217..2d87009460d744 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp +++ b/src/lib/dnssd/minimal_mdns/core/tests/TestQName.cpp @@ -16,10 +16,8 @@ * limitations under the License. */ +#include #include -#include - -#include namespace { @@ -40,67 +38,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 +106,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 +115,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 +128,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 +137,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 +147,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 +157,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 +166,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..70cd442d56d4e6 100644 --- a/src/lib/dnssd/minimal_mdns/core/tests/TestRecordWriter.cpp +++ b/src/lib/dnssd/minimal_mdns/core/tests/TestRecordWriter.cpp @@ -17,16 +17,15 @@ */ #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(), size_t(423)); } } // 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 2da3c15c3e7934..40f81182a767ac 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components.txt @@ -1,4 +1,5 @@ accesstest +MinimalMdnsCoreTests SystemLayerTests ASN1Tests MinimalMdnsRecordsTests 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 848fd2fc43e3a3..a19bfb88e446b4 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt @@ -7,7 +7,7 @@ DataModelTests InetLayerTests MdnsTests MessagingLayerTests -MinimalMdnsCoreTests +MinimalMdnsCoreTestsNL RawTransportTests RetransmitTests SecureChannelTests