Replaced nlunit-test with pw_unit_test in src/lib/dnssd/tests/ (#33045)
* Replaced nlunit-test with pw_unit_test in src/lib/dnssd/tests/
* Update openiotsdk test components
diff --git a/src/lib/dnssd/tests/BUILD.gn b/src/lib/dnssd/tests/BUILD.gn
index e64d0c7..cdcb4ba 100644
--- a/src/lib/dnssd/tests/BUILD.gn
+++ b/src/lib/dnssd/tests/BUILD.gn
@@ -14,11 +14,10 @@
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")
-chip_test_suite_using_nltest("tests") {
+chip_test_suite("tests") {
output_name = "libMdnsTests"
test_sources = [
@@ -26,11 +25,7 @@
"TestTxtFields.cpp",
]
- public_deps = [
- "${chip_root}/src/lib/dnssd",
- "${chip_root}/src/lib/support:testing_nlunit",
- "${nlunit_test_root}:nlunit-test",
- ]
+ public_deps = [ "${chip_root}/src/lib/dnssd" ]
if (chip_mdns == "minimal") {
test_sources += [
diff --git a/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp b/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp
index f4ef2f2..58c1cf8 100644
--- a/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp
+++ b/src/lib/dnssd/tests/TestActiveResolveAttempts.cpp
@@ -16,9 +16,7 @@
*/
#include <lib/dnssd/ActiveResolveAttempts.h>
-#include <lib/support/UnitTestRegistration.h>
-
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
namespace {
@@ -43,7 +41,7 @@
return Optional<ActiveResolveAttempts::ScheduledAttempt>::Value(ActiveResolveAttempts::ScheduledAttempt(filter, type, first));
}
-void TestSinglePeerAddRemove(nlTestSuite * inSuite, void * inContext)
+TEST(TestActiveResolveAttempts, TestSinglePeerAddRemove)
{
System::Clock::Internal::MockClock mockClock;
mdns::Minimal::ActiveResolveAttempts attempts(&mockClock);
@@ -51,42 +49,42 @@
mockClock.AdvanceMonotonic(1234_ms32);
// Starting up, no scheduled peers are expected
- NL_TEST_ASSERT(inSuite, !attempts.GetTimeUntilNextExpectedResponse().HasValue());
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_FALSE(attempts.GetTimeUntilNextExpectedResponse().HasValue());
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// Adding a single peer should result in it being scheduled
attempts.MarkPending(MakePeerId(1));
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(1, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(1, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// one Next schedule is called, expect to have a delay of 1000 ms
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1000_ms32));
mockClock.AdvanceMonotonic(500_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(500_ms32));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(500_ms32));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// past due date: timeout should be 0
mockClock.AdvanceMonotonic(800_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(1, false));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(1, false));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// one Next schedule is called, expect to have a delay of 2000 ms
// sincve the timeout doubles every time
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(2000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(2000_ms32));
mockClock.AdvanceMonotonic(100_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1900_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1900_ms32));
// once complete, nothing to schedule
attempts.Complete(MakePeerId(1));
- NL_TEST_ASSERT(inSuite, !attempts.GetTimeUntilNextExpectedResponse().HasValue());
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_FALSE(attempts.GetTimeUntilNextExpectedResponse().HasValue());
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
}
-void TestSingleBrowseAddRemove(nlTestSuite * inSuite, void * inContext)
+TEST(TestActiveResolveAttempts, TestSingleBrowseAddRemove)
{
System::Clock::Internal::MockClock mockClock;
mdns::Minimal::ActiveResolveAttempts attempts(&mockClock);
@@ -96,43 +94,43 @@
mockClock.AdvanceMonotonic(1234_ms32);
// Starting up, no scheduled peers are expected
- NL_TEST_ASSERT(inSuite, !attempts.GetTimeUntilNextExpectedResponse().HasValue());
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_FALSE(attempts.GetTimeUntilNextExpectedResponse().HasValue());
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// Adding a single attempt should result in it being scheduled
attempts.MarkPending(filter, type);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledBrowse(filter, type, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledBrowse(filter, type, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// one Next schedule is called, expect to have a delay of 1000 ms
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1000_ms32));
mockClock.AdvanceMonotonic(500_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(500_ms32));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(500_ms32));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// past due date: timeout should be 0
mockClock.AdvanceMonotonic(800_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledBrowse(filter, type, false));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledBrowse(filter, type, false));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// one Next schedule is called, expect to have a delay of 2000 ms
// sincve the timeout doubles every time
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(2000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(2000_ms32));
mockClock.AdvanceMonotonic(100_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1900_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1900_ms32));
// once complete, nothing to schedule
Dnssd::DiscoveredNodeData data;
data.nodeData.longDiscriminator = 1234;
attempts.CompleteCommissionable(data);
- NL_TEST_ASSERT(inSuite, !attempts.GetTimeUntilNextExpectedResponse().HasValue());
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_FALSE(attempts.GetTimeUntilNextExpectedResponse().HasValue());
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
}
-void TestRescheduleSamePeerId(nlTestSuite * inSuite, void * inContext)
+TEST(TestActiveResolveAttempts, TestRescheduleSamePeerId)
{
System::Clock::Internal::MockClock mockClock;
mdns::Minimal::ActiveResolveAttempts attempts(&mockClock);
@@ -141,30 +139,30 @@
attempts.MarkPending(MakePeerId(1));
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(1, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(1, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// one Next schedule is called, expect to have a delay of 1000 ms
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1000_ms32));
// 2nd try goes to 2 seconds (once at least 1 second passes)
mockClock.AdvanceMonotonic(1234_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(1, false));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(2000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(1, false));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(2000_ms32));
// reschedule starts fresh
attempts.MarkPending(MakePeerId(1));
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(1, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(1, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1000_ms32));
}
-void TestRescheduleSameFilter(nlTestSuite * inSuite, void * inContext)
+TEST(TestActiveResolveAttempts, TestRescheduleSameFilter)
{
System::Clock::Internal::MockClock mockClock;
mdns::Minimal::ActiveResolveAttempts attempts(&mockClock);
@@ -175,30 +173,30 @@
attempts.MarkPending(filter, type);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledBrowse(filter, type, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledBrowse(filter, type, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// one Next schedule is called, expect to have a delay of 1000 ms
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1000_ms32));
// 2nd try goes to 2 seconds (once at least 1 second passes)
mockClock.AdvanceMonotonic(1234_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledBrowse(filter, type, false));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(2000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledBrowse(filter, type, false));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(2000_ms32));
// reschedule starts fresh
attempts.MarkPending(filter, type);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledBrowse(filter, type, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledBrowse(filter, type, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1000_ms32));
}
-void TestLRU(nlTestSuite * inSuite, void * inContext)
+TEST(TestActiveResolveAttempts, TestLRU)
{
// validates that the LRU logic is working
System::Clock::Internal::MockClock mockClock;
@@ -208,16 +206,16 @@
// add a single very old peer
attempts.MarkPending(MakePeerId(9999));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(9999, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(9999, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
mockClock.AdvanceMonotonic(1000_ms32);
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(9999, false));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(9999, false));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
mockClock.AdvanceMonotonic(2000_ms32);
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(9999, false));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(9999, false));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// at this point, peer 9999 has a delay of 4 seconds. Fill up the rest of the table
@@ -226,15 +224,14 @@
attempts.MarkPending(MakePeerId(i));
mockClock.AdvanceMonotonic(1_ms32);
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(i, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(i, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
}
// +2 because: 1 element skipped, one element is the "current" that has a delay of 1000ms
- NL_TEST_ASSERT(inSuite,
- attempts.GetTimeUntilNextExpectedResponse() ==
- Optional<System::Clock::Timeout>::Value(
- System::Clock::Milliseconds32(1000 - mdns::Minimal::ActiveResolveAttempts::kRetryQueueSize + 2)));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(),
+ Optional<System::Clock::Timeout>::Value(
+ System::Clock::Milliseconds32(1000 - mdns::Minimal::ActiveResolveAttempts::kRetryQueueSize + 2)));
// add another element - this should overwrite peer 9999
attempts.MarkPending(MakePeerId(mdns::Minimal::ActiveResolveAttempts::kRetryQueueSize));
@@ -242,11 +239,11 @@
for (Optional<ActiveResolveAttempts::ScheduledAttempt> s = attempts.NextScheduled(); s.HasValue(); s = attempts.NextScheduled())
{
- NL_TEST_ASSERT(inSuite, s.Value().ResolveData().peerId.GetNodeId() != 9999);
+ EXPECT_NE(s.Value().ResolveData().peerId.GetNodeId(), 9999u);
}
// Still have active pending items (queue is full)
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse().HasValue());
+ EXPECT_TRUE(attempts.GetTimeUntilNextExpectedResponse().HasValue());
// expire all of them. Since we double timeout every expiry, we expect a
// few iteratios to be able to expire the entire queue
@@ -266,14 +263,14 @@
Optional<ActiveResolveAttempts::ScheduledAttempt> s = attempts.NextScheduled();
while (s.HasValue())
{
- NL_TEST_ASSERT(inSuite, s.Value().ResolveData().peerId.GetNodeId() != 9999);
+ EXPECT_NE(s.Value().ResolveData().peerId.GetNodeId(), 9999u);
s = attempts.NextScheduled();
}
}
- NL_TEST_ASSERT(inSuite, i < kMaxIterations);
+ EXPECT_LT(i, kMaxIterations);
}
-void TestNextPeerOrdering(nlTestSuite * inSuite, void * inContext)
+TEST(TestActiveResolveAttempts, TestNextPeerOrdering)
{
System::Clock::Internal::MockClock mockClock;
mdns::Minimal::ActiveResolveAttempts attempts(&mockClock);
@@ -283,52 +280,52 @@
// add a single peer that will be resolved quickly
attempts.MarkPending(MakePeerId(1));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(1, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1000_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(1, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1000_ms32));
mockClock.AdvanceMonotonic(20_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(980_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(980_ms32));
// expect peerid to be resolve within 1 second from now
attempts.MarkPending(MakePeerId(2));
// mock that we are querying 2 as well
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(2, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(2, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
mockClock.AdvanceMonotonic(80_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(900_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(900_ms32));
// Peer 1 is done, now peer2 should be pending (in 980ms)
attempts.Complete(MakePeerId(1));
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(920_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(920_ms32));
mockClock.AdvanceMonotonic(20_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(900_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(900_ms32));
// Once peer 3 is added, queue should be
// - 900 ms until peer id 2 is pending
// - 1000 ms until peer id 3 is pending
attempts.MarkPending(MakePeerId(3));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(3, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(900_ms32));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(3, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(900_ms32));
// After the clock advance
// - 400 ms until peer id 2 is pending
// - 500 ms until peer id 3 is pending
mockClock.AdvanceMonotonic(500_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(400_ms32));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(400_ms32));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// advancing the clock 'too long' will return both other entries, in reverse order due to how
// the internal cache is built
mockClock.AdvanceMonotonic(500_ms32);
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(3, false));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(2, false));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(3, false));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(2, false));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
}
-void TestCombination(nlTestSuite * inSuite, void * inContext)
+TEST(TestActiveResolveAttempts, TestCombination)
{
System::Clock::Internal::MockClock mockClock;
mdns::Minimal::ActiveResolveAttempts attempts(&mockClock);
@@ -342,34 +339,34 @@
mockClock.AdvanceMonotonic(20_ms32);
attempts.MarkPending(filter, type);
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(1, true));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledBrowse(filter, type, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(1, true));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledBrowse(filter, type, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// At this point, both should reset, so we're back to 1000ms
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(1000_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(1000_ms32));
// We used 20 ms, so the next time for the peer and resolve should be 980 ms
mockClock.AdvanceMonotonic(20_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(980_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(980_ms32));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// Add a second Peer
mockClock.AdvanceMonotonic(20_ms32);
attempts.MarkPending(MakePeerId(2));
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(2, true));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(2, true));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// Advance to the retry time of peer 1 and the resolve
mockClock.AdvanceMonotonic(960_ms32);
- NL_TEST_ASSERT(inSuite, attempts.GetTimeUntilNextExpectedResponse() == Optional<Timeout>(0_ms32));
+ EXPECT_EQ(attempts.GetTimeUntilNextExpectedResponse(), Optional<Timeout>(0_ms32));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledPeer(1, false));
- NL_TEST_ASSERT(inSuite, attempts.NextScheduled() == ScheduledBrowse(filter, type, false));
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledPeer(1, false));
+ EXPECT_EQ(attempts.NextScheduled(), ScheduledBrowse(filter, type, false));
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
// Complete all, we should see no more scheduled.
attempts.Complete(MakePeerId(2));
@@ -378,28 +375,7 @@
data.nodeData.longDiscriminator = 1234;
attempts.CompleteCommissionable(data);
- NL_TEST_ASSERT(inSuite, !attempts.GetTimeUntilNextExpectedResponse().HasValue());
- NL_TEST_ASSERT(inSuite, !attempts.NextScheduled().HasValue());
+ EXPECT_FALSE(attempts.GetTimeUntilNextExpectedResponse().HasValue());
+ EXPECT_FALSE(attempts.NextScheduled().HasValue());
}
-
-const nlTest sTests[] = {
- NL_TEST_DEF("TestSinglePeerAddRemove", TestSinglePeerAddRemove), //
- NL_TEST_DEF("TestSingleBrowseAddRemove", TestSingleBrowseAddRemove), //
- NL_TEST_DEF("TestRescheduleSamePeerId", TestRescheduleSamePeerId), //
- NL_TEST_DEF("TestRescheduleSameFilter", TestRescheduleSameFilter), //
- NL_TEST_DEF("TestLRU", TestLRU), //
- NL_TEST_DEF("TestNextPeerOrdering", TestNextPeerOrdering), //
- NL_TEST_DEF("TestCombination", TestCombination), //
- NL_TEST_SENTINEL() //
-};
-
} // namespace
-
-int TestActiveResolveAttempts()
-{
- nlTestSuite theSuite = { "ActiveResolveAttempts", sTests, nullptr, nullptr };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestActiveResolveAttempts)
diff --git a/src/lib/dnssd/tests/TestIncrementalResolve.cpp b/src/lib/dnssd/tests/TestIncrementalResolve.cpp
index 03b585c..646e4ab 100644
--- a/src/lib/dnssd/tests/TestIncrementalResolve.cpp
+++ b/src/lib/dnssd/tests/TestIncrementalResolve.cpp
@@ -27,9 +27,8 @@
#include <lib/dnssd/minimal_mdns/records/Srv.h>
#include <lib/dnssd/minimal_mdns/records/Txt.h>
#include <lib/support/ScopedBuffer.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
using namespace chip;
using namespace chip::Dnssd;
@@ -51,7 +50,7 @@
const auto kIrrelevantHostName = testing::TestQName<2>({ "different", "local" });
-void PreloadSrvRecord(nlTestSuite * inSuite, SrvRecord & record)
+void PreloadSrvRecord(SrvRecord & record)
{
uint8_t headerBuffer[HeaderRef::kSizeBytes] = {};
HeaderRef dummyHeader(headerBuffer);
@@ -62,16 +61,15 @@
chip::Encoding::BigEndian::BufferWriter output(dataBuffer, sizeof(dataBuffer));
RecordWriter writer(&output);
- NL_TEST_ASSERT(inSuite,
- SrvResourceRecord(kTestOperationalName.Full(), kTestHostName.Full(), 0x1234 /* port */)
- .Append(dummyHeader, ResourceType::kAnswer, writer));
+ EXPECT_TRUE(SrvResourceRecord(kTestOperationalName.Full(), kTestHostName.Full(), 0x1234 /* port */)
+ .Append(dummyHeader, ResourceType::kAnswer, writer));
ResourceData resource;
BytesRange packet(dataBuffer, dataBuffer + sizeof(dataBuffer));
const uint8_t * _ptr = dataBuffer;
- NL_TEST_ASSERT(inSuite, resource.Parse(packet, &_ptr));
- NL_TEST_ASSERT(inSuite, record.Parse(resource.GetData(), packet));
+ EXPECT_TRUE(resource.Parse(packet, &_ptr));
+ EXPECT_TRUE(record.Parse(resource.GetData(), packet));
}
/// Convenience method to have a serialized QName.
@@ -84,7 +82,7 @@
return SerializedQNameIterator(BytesRange(v, v + N - 1), v);
}
-void CallOnRecord(nlTestSuite * inSuite, IncrementalResolver & resolver, const ResourceRecord & record)
+void CallOnRecord(IncrementalResolver & resolver, const ResourceRecord & record)
{
uint8_t headerBuffer[HeaderRef::kSizeBytes] = {};
HeaderRef dummyHeader(headerBuffer);
@@ -93,39 +91,39 @@
chip::Encoding::BigEndian::BufferWriter output(dataBuffer, sizeof(dataBuffer));
RecordWriter writer(&output);
- NL_TEST_ASSERT(inSuite, record.Append(dummyHeader, ResourceType::kAnswer, writer));
- NL_TEST_ASSERT(inSuite, writer.Fit());
+ EXPECT_TRUE(record.Append(dummyHeader, ResourceType::kAnswer, writer));
+ EXPECT_TRUE(writer.Fit());
ResourceData resource;
BytesRange packet(dataBuffer, dataBuffer + sizeof(dataBuffer));
const uint8_t * _ptr = dataBuffer;
- NL_TEST_ASSERT(inSuite, resource.Parse(packet, &_ptr));
- NL_TEST_ASSERT(inSuite, resolver.OnRecord(chip::Inet::InterfaceId::Null(), resource, packet) == CHIP_NO_ERROR);
+ EXPECT_TRUE(resource.Parse(packet, &_ptr));
+ EXPECT_EQ(resolver.OnRecord(chip::Inet::InterfaceId::Null(), resource, packet), CHIP_NO_ERROR);
}
-void TestStoredServerName(nlTestSuite * inSuite, void * inContext)
+TEST(TestIncrementalResolve, TestStoredServerName)
{
StoredServerName name;
// name should start of as cleared
- NL_TEST_ASSERT(inSuite, !name.Get().Next());
+ EXPECT_FALSE(name.Get().Next());
// Data should be storable in server name
- NL_TEST_ASSERT(inSuite, name.Set(kTestOperationalName.Serialized()) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, name.Get() == kTestOperationalName.Serialized());
- NL_TEST_ASSERT(inSuite, name.Get() != kTestCommissionerNode.Serialized());
- NL_TEST_ASSERT(inSuite, name.Get() != kTestCommissionableNode.Serialized());
+ EXPECT_EQ(name.Set(kTestOperationalName.Serialized()), CHIP_NO_ERROR);
+ EXPECT_EQ(name.Get(), kTestOperationalName.Serialized());
+ EXPECT_NE(name.Get(), kTestCommissionerNode.Serialized());
+ EXPECT_NE(name.Get(), kTestCommissionableNode.Serialized());
- NL_TEST_ASSERT(inSuite, name.Set(kTestCommissionerNode.Serialized()) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, name.Get() != kTestOperationalName.Serialized());
- NL_TEST_ASSERT(inSuite, name.Get() == kTestCommissionerNode.Serialized());
- NL_TEST_ASSERT(inSuite, name.Get() != kTestCommissionableNode.Serialized());
+ EXPECT_EQ(name.Set(kTestCommissionerNode.Serialized()), CHIP_NO_ERROR);
+ EXPECT_NE(name.Get(), kTestOperationalName.Serialized());
+ EXPECT_EQ(name.Get(), kTestCommissionerNode.Serialized());
+ EXPECT_NE(name.Get(), kTestCommissionableNode.Serialized());
- NL_TEST_ASSERT(inSuite, name.Set(kTestCommissionableNode.Serialized()) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, name.Get() != kTestOperationalName.Serialized());
- NL_TEST_ASSERT(inSuite, name.Get() != kTestCommissionerNode.Serialized());
- NL_TEST_ASSERT(inSuite, name.Get() == kTestCommissionableNode.Serialized());
+ EXPECT_EQ(name.Set(kTestCommissionableNode.Serialized()), CHIP_NO_ERROR);
+ EXPECT_NE(name.Get(), kTestOperationalName.Serialized());
+ EXPECT_NE(name.Get(), kTestCommissionerNode.Serialized());
+ EXPECT_EQ(name.Get(), kTestCommissionableNode.Serialized());
{
// setting to a too long value should reset it
@@ -145,135 +143,130 @@
if (writer.WritePos() < 64)
{
// this is how much data can be fit by the copy
- NL_TEST_ASSERT_LOOP(inSuite, idx, name.Set(AsSerializedQName(largeBuffer)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT_LOOP(inSuite, idx, name.Get() == AsSerializedQName(largeBuffer));
- NL_TEST_ASSERT_LOOP(inSuite, idx, name.Get() != kTestOperationalName.Serialized());
+ EXPECT_EQ(name.Set(AsSerializedQName(largeBuffer)), CHIP_NO_ERROR) << "idx = " << idx;
+ EXPECT_EQ(name.Get(), AsSerializedQName(largeBuffer)) << "idx = " << idx;
+ EXPECT_NE(name.Get(), kTestOperationalName.Serialized()) << "idx = " << idx;
}
else
{
- NL_TEST_ASSERT_LOOP(inSuite, idx, name.Set(AsSerializedQName(largeBuffer)) == CHIP_ERROR_NO_MEMORY);
- NL_TEST_ASSERT_LOOP(inSuite, idx, !name.Get().Next());
+ EXPECT_EQ(name.Set(AsSerializedQName(largeBuffer)), CHIP_ERROR_NO_MEMORY) << "idx = " << idx;
+ EXPECT_FALSE(name.Get().Next()) << "idx = " << idx;
}
}
}
}
-void TestCreation(nlTestSuite * inSuite, void * inContext)
+TEST(TestIncrementalResolve, TestCreation)
{
IncrementalResolver resolver;
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
- NL_TEST_ASSERT(inSuite, !resolver.IsActiveBrowseParse());
- NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse());
- NL_TEST_ASSERT(
- inSuite,
+ EXPECT_FALSE(resolver.IsActive());
+ EXPECT_FALSE(resolver.IsActiveBrowseParse());
+ EXPECT_FALSE(resolver.IsActiveOperationalParse());
+ EXPECT_TRUE(
resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kSrvInitialization));
}
-void TestInactiveResetOnInitError(nlTestSuite * inSuite, void * inContext)
+TEST(TestIncrementalResolve, TestInactiveResetOnInitError)
{
IncrementalResolver resolver;
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
+ EXPECT_FALSE(resolver.IsActive());
SrvRecord srvRecord;
- PreloadSrvRecord(inSuite, srvRecord);
+ PreloadSrvRecord(srvRecord);
// test host name is not a 'matter' name
- NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestHostName.Serialized(), srvRecord) != CHIP_NO_ERROR);
+ EXPECT_NE(resolver.InitializeParsing(kTestHostName.Serialized(), srvRecord), CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
- NL_TEST_ASSERT(inSuite, !resolver.IsActiveBrowseParse());
- NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse());
+ EXPECT_FALSE(resolver.IsActive());
+ EXPECT_FALSE(resolver.IsActiveBrowseParse());
+ EXPECT_FALSE(resolver.IsActiveOperationalParse());
}
-void TestStartOperational(nlTestSuite * inSuite, void * inContext)
+TEST(TestIncrementalResolve, TestStartOperational)
{
IncrementalResolver resolver;
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
+ EXPECT_FALSE(resolver.IsActive());
SrvRecord srvRecord;
- PreloadSrvRecord(inSuite, srvRecord);
+ PreloadSrvRecord(srvRecord);
- NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestOperationalName.Serialized(), srvRecord) == CHIP_NO_ERROR);
+ EXPECT_EQ(resolver.InitializeParsing(kTestOperationalName.Serialized(), srvRecord), CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, resolver.IsActive());
- NL_TEST_ASSERT(inSuite, !resolver.IsActiveBrowseParse());
- NL_TEST_ASSERT(inSuite, resolver.IsActiveOperationalParse());
- NL_TEST_ASSERT(inSuite,
- resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
- NL_TEST_ASSERT(inSuite, resolver.GetTargetHostName() == kTestHostName.Serialized());
+ EXPECT_TRUE(resolver.IsActive());
+ EXPECT_FALSE(resolver.IsActiveBrowseParse());
+ EXPECT_TRUE(resolver.IsActiveOperationalParse());
+ EXPECT_TRUE(resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
+ EXPECT_EQ(resolver.GetTargetHostName(), kTestHostName.Serialized());
}
-void TestStartCommissionable(nlTestSuite * inSuite, void * inContext)
+TEST(TestIncrementalResolve, TestStartCommissionable)
{
IncrementalResolver resolver;
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
+ EXPECT_FALSE(resolver.IsActive());
SrvRecord srvRecord;
- PreloadSrvRecord(inSuite, srvRecord);
+ PreloadSrvRecord(srvRecord);
- NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionableNode.Serialized(), srvRecord) == CHIP_NO_ERROR);
+ EXPECT_EQ(resolver.InitializeParsing(kTestCommissionableNode.Serialized(), srvRecord), CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, resolver.IsActive());
- NL_TEST_ASSERT(inSuite, resolver.IsActiveBrowseParse());
- NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse());
- NL_TEST_ASSERT(inSuite,
- resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
- NL_TEST_ASSERT(inSuite, resolver.GetTargetHostName() == kTestHostName.Serialized());
+ EXPECT_TRUE(resolver.IsActive());
+ EXPECT_TRUE(resolver.IsActiveBrowseParse());
+ EXPECT_FALSE(resolver.IsActiveOperationalParse());
+ EXPECT_TRUE(resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
+ EXPECT_EQ(resolver.GetTargetHostName(), kTestHostName.Serialized());
}
-void TestStartCommissioner(nlTestSuite * inSuite, void * inContext)
+TEST(TestIncrementalResolve, TestStartCommissioner)
{
IncrementalResolver resolver;
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
+ EXPECT_FALSE(resolver.IsActive());
SrvRecord srvRecord;
- PreloadSrvRecord(inSuite, srvRecord);
+ PreloadSrvRecord(srvRecord);
- NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionerNode.Serialized(), srvRecord) == CHIP_NO_ERROR);
+ EXPECT_EQ(resolver.InitializeParsing(kTestCommissionerNode.Serialized(), srvRecord), CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, resolver.IsActive());
- NL_TEST_ASSERT(inSuite, resolver.IsActiveBrowseParse());
- NL_TEST_ASSERT(inSuite, !resolver.IsActiveOperationalParse());
- NL_TEST_ASSERT(inSuite,
- resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
- NL_TEST_ASSERT(inSuite, resolver.GetTargetHostName() == kTestHostName.Serialized());
+ EXPECT_TRUE(resolver.IsActive());
+ EXPECT_TRUE(resolver.IsActiveBrowseParse());
+ EXPECT_FALSE(resolver.IsActiveOperationalParse());
+ EXPECT_TRUE(resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
+ EXPECT_EQ(resolver.GetTargetHostName(), kTestHostName.Serialized());
}
-void TestParseOperational(nlTestSuite * inSuite, void * inContext)
+TEST(TestIncrementalResolve, TestParseOperational)
{
IncrementalResolver resolver;
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
+ EXPECT_FALSE(resolver.IsActive());
SrvRecord srvRecord;
- PreloadSrvRecord(inSuite, srvRecord);
+ PreloadSrvRecord(srvRecord);
- NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestOperationalName.Serialized(), srvRecord) == CHIP_NO_ERROR);
+ EXPECT_EQ(resolver.InitializeParsing(kTestOperationalName.Serialized(), srvRecord), CHIP_NO_ERROR);
// once initialized, parsing should be ready however no IP address is available
- NL_TEST_ASSERT(inSuite, resolver.IsActiveOperationalParse());
- NL_TEST_ASSERT(inSuite,
- resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
- NL_TEST_ASSERT(inSuite, resolver.GetTargetHostName() == kTestHostName.Serialized());
+ EXPECT_TRUE(resolver.IsActiveOperationalParse());
+ EXPECT_TRUE(resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
+ EXPECT_EQ(resolver.GetTargetHostName(), kTestHostName.Serialized());
// Send an IP for an irrelevant host name
{
Inet::IPAddress addr;
- NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::aabb:ccdd:2233:4455", addr));
+ EXPECT_TRUE(Inet::IPAddress::FromString("fe80::aabb:ccdd:2233:4455", addr));
- CallOnRecord(inSuite, resolver, IPResourceRecord(kIrrelevantHostName.Full(), addr));
+ CallOnRecord(resolver, IPResourceRecord(kIrrelevantHostName.Full(), addr));
}
// Send a useful IP address here
{
Inet::IPAddress addr;
- NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr));
- CallOnRecord(inSuite, resolver, IPResourceRecord(kTestHostName.Full(), addr));
+ EXPECT_TRUE(Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr));
+ CallOnRecord(resolver, IPResourceRecord(kTestHostName.Full(), addr));
}
// Send a TXT record for an irrelevant host name
@@ -285,7 +278,7 @@
"T=1" // TCP supported
};
- CallOnRecord(inSuite, resolver, TxtResourceRecord(kTestHostName.Full(), entries));
+ CallOnRecord(resolver, TxtResourceRecord(kTestHostName.Full(), entries));
}
// Adding actual text entries that are useful
@@ -297,70 +290,68 @@
"SII=23" // session idle interval
};
- CallOnRecord(inSuite, resolver, TxtResourceRecord(kTestOperationalName.Full(), entries));
+ CallOnRecord(resolver, TxtResourceRecord(kTestOperationalName.Full(), entries));
}
// Resolver should have all data
- NL_TEST_ASSERT(inSuite, !resolver.GetMissingRequiredInformation().HasAny());
+ EXPECT_FALSE(resolver.GetMissingRequiredInformation().HasAny());
// At this point taking value should work. Once taken, the resolver is reset.
ResolvedNodeData nodeData;
- NL_TEST_ASSERT(inSuite, resolver.Take(nodeData) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
+ EXPECT_EQ(resolver.Take(nodeData), CHIP_NO_ERROR);
+ EXPECT_FALSE(resolver.IsActive());
// validate data as it was passed in
- NL_TEST_ASSERT(inSuite,
- nodeData.operationalData.peerId ==
- PeerId().SetCompressedFabricId(0x1234567898765432LL).SetNodeId(0xABCDEFEDCBAABCDELL));
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.numIPs == 1);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.port == 0x1234);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.supportsTcp);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalIdle().Value() == chip::System::Clock::Milliseconds32(23));
+ EXPECT_EQ(nodeData.operationalData.peerId,
+ PeerId().SetCompressedFabricId(0x1234567898765432LL).SetNodeId(0xABCDEFEDCBAABCDELL));
+ EXPECT_EQ(nodeData.resolutionData.numIPs, 1u);
+ EXPECT_EQ(nodeData.resolutionData.port, 0x1234);
+ EXPECT_FALSE(nodeData.resolutionData.supportsTcp);
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle().Value(), chip::System::Clock::Milliseconds32(23));
Inet::IPAddress addr;
- NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr));
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.ipAddress[0] == addr);
+ EXPECT_TRUE(Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr));
+ EXPECT_EQ(nodeData.resolutionData.ipAddress[0], addr);
}
-void TestParseCommissionable(nlTestSuite * inSuite, void * inContext)
+TEST(TestIncrementalResolve, TestParseCommissionable)
{
IncrementalResolver resolver;
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
+ EXPECT_FALSE(resolver.IsActive());
SrvRecord srvRecord;
- PreloadSrvRecord(inSuite, srvRecord);
+ PreloadSrvRecord(srvRecord);
- NL_TEST_ASSERT(inSuite, resolver.InitializeParsing(kTestCommissionableNode.Serialized(), srvRecord) == CHIP_NO_ERROR);
+ EXPECT_EQ(resolver.InitializeParsing(kTestCommissionableNode.Serialized(), srvRecord), CHIP_NO_ERROR);
// once initialized, parsing should be ready however no IP address is available
- NL_TEST_ASSERT(inSuite, resolver.IsActiveBrowseParse());
- NL_TEST_ASSERT(inSuite,
- resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
- NL_TEST_ASSERT(inSuite, resolver.GetTargetHostName() == kTestHostName.Serialized());
+ EXPECT_TRUE(resolver.IsActiveBrowseParse());
+ EXPECT_TRUE(resolver.GetMissingRequiredInformation().HasOnly(IncrementalResolver::RequiredInformationBitFlags::kIpAddress));
+ EXPECT_EQ(resolver.GetTargetHostName(), kTestHostName.Serialized());
// Send an IP for an irrelevant host name
{
Inet::IPAddress addr;
- NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::aabb:ccdd:2233:4455", addr));
- CallOnRecord(inSuite, resolver, IPResourceRecord(kIrrelevantHostName.Full(), addr));
+ EXPECT_TRUE(Inet::IPAddress::FromString("fe80::aabb:ccdd:2233:4455", addr));
+ CallOnRecord(resolver, IPResourceRecord(kIrrelevantHostName.Full(), addr));
}
// Send a useful IP address here
{
Inet::IPAddress addr;
- NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr));
- CallOnRecord(inSuite, resolver, IPResourceRecord(kTestHostName.Full(), addr));
+ EXPECT_TRUE(Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr));
+ CallOnRecord(resolver, IPResourceRecord(kTestHostName.Full(), addr));
}
// Send another IP address
{
Inet::IPAddress addr;
- NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::f0f1:f2f3:f4f5:1234", addr));
- CallOnRecord(inSuite, resolver, IPResourceRecord(kTestHostName.Full(), addr));
+ EXPECT_TRUE(Inet::IPAddress::FromString("fe80::f0f1:f2f3:f4f5:1234", addr));
+ CallOnRecord(resolver, IPResourceRecord(kTestHostName.Full(), addr));
}
// Send a TXT record for an irrelevant host name
@@ -372,7 +363,7 @@
"SII=123" // session idle interval
};
- CallOnRecord(inSuite, resolver, TxtResourceRecord(kTestHostName.Full(), entries));
+ CallOnRecord(resolver, TxtResourceRecord(kTestHostName.Full(), entries));
}
// Adding actual text entries that are useful
@@ -387,61 +378,35 @@
"DN=mytest" // Device name
};
- CallOnRecord(inSuite, resolver, TxtResourceRecord(kTestCommissionableNode.Full(), entries));
+ CallOnRecord(resolver, TxtResourceRecord(kTestCommissionableNode.Full(), entries));
}
// Resolver should have all data
- NL_TEST_ASSERT(inSuite, !resolver.GetMissingRequiredInformation().HasAny());
+ EXPECT_FALSE(resolver.GetMissingRequiredInformation().HasAny());
// At this point taking value should work. Once taken, the resolver is reset.
DiscoveredNodeData nodeData;
- NL_TEST_ASSERT(inSuite, resolver.Take(nodeData) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !resolver.IsActive());
+ EXPECT_EQ(resolver.Take(nodeData), CHIP_NO_ERROR);
+ EXPECT_FALSE(resolver.IsActive());
// validate data as it was passed in
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.numIPs == 2);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.port == 0x1234);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.supportsTcp);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
- NL_TEST_ASSERT(inSuite,
- nodeData.resolutionData.GetMrpRetryIntervalActive().Value() == chip::System::Clock::Milliseconds32(321));
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_EQ(nodeData.resolutionData.numIPs, 2u);
+ EXPECT_EQ(nodeData.resolutionData.port, 0x1234);
+ EXPECT_FALSE(nodeData.resolutionData.supportsTcp);
+ EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalActive().Value(), chip::System::Clock::Milliseconds32(321));
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
Inet::IPAddress addr;
- NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr));
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.ipAddress[0] == addr);
- NL_TEST_ASSERT(inSuite, Inet::IPAddress::FromString("fe80::f0f1:f2f3:f4f5:1234", addr));
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.ipAddress[1] == addr);
+ EXPECT_TRUE(Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr));
+ EXPECT_EQ(nodeData.resolutionData.ipAddress[0], addr);
+ EXPECT_TRUE(Inet::IPAddress::FromString("fe80::f0f1:f2f3:f4f5:1234", addr));
+ EXPECT_EQ(nodeData.resolutionData.ipAddress[1], addr);
// parsed txt data for discovered nodes
- NL_TEST_ASSERT(inSuite, nodeData.nodeData.longDiscriminator == 22345);
- NL_TEST_ASSERT(inSuite, nodeData.nodeData.vendorId == 321);
- NL_TEST_ASSERT(inSuite, nodeData.nodeData.productId == 654);
- NL_TEST_ASSERT(inSuite, strcmp(nodeData.nodeData.deviceName, "mytest") == 0);
+ EXPECT_EQ(nodeData.nodeData.longDiscriminator, 22345);
+ EXPECT_EQ(nodeData.nodeData.vendorId, 321);
+ EXPECT_EQ(nodeData.nodeData.productId, 654);
+ EXPECT_STREQ(nodeData.nodeData.deviceName, "mytest");
}
-
-const nlTest sTests[] = {
- // Tests for helper class
- NL_TEST_DEF("StoredServerName", TestStoredServerName), //
-
- // Actual resolver tests
- NL_TEST_DEF("Creation", TestCreation), //
- NL_TEST_DEF("InactiveResetOnInitError", TestInactiveResetOnInitError), //
- NL_TEST_DEF("StartOperational", TestStartOperational), //
- NL_TEST_DEF("StartCommissionable", TestStartCommissionable), //
- NL_TEST_DEF("StartCommissioner", TestStartCommissioner), //
- NL_TEST_DEF("ParseOperational", TestParseOperational), //
- NL_TEST_DEF("ParseCommissionable", TestParseCommissionable), //
- NL_TEST_SENTINEL() //
-};
-
} // namespace
-
-int TestChipDnsSdIncrementalResolve()
-{
- nlTestSuite theSuite = { "IncrementalResolve", &sTests[0], nullptr, nullptr };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestChipDnsSdIncrementalResolve)
diff --git a/src/lib/dnssd/tests/TestServiceNaming.cpp b/src/lib/dnssd/tests/TestServiceNaming.cpp
index 646a51e..0fa2672 100644
--- a/src/lib/dnssd/tests/TestServiceNaming.cpp
+++ b/src/lib/dnssd/tests/TestServiceNaming.cpp
@@ -20,84 +20,78 @@
#include <string.h>
-#include <lib/support/UnitTestRegistration.h>
-
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
using namespace chip;
using namespace chip::Dnssd;
namespace {
-void TestMakeInstanceName(nlTestSuite * inSuite, void * inContext)
+TEST(TestServiceNaming, TestMakeInstanceName)
{
char buffer[128];
- NL_TEST_ASSERT(inSuite,
- MakeInstanceName(buffer, sizeof(buffer), PeerId().SetCompressedFabricId(0x1234).SetNodeId(0x5678)) ==
- CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "0000000000001234-0000000000005678") == 0);
+ EXPECT_EQ(MakeInstanceName(buffer, sizeof(buffer), PeerId().SetCompressedFabricId(0x1234).SetNodeId(0x5678)), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "0000000000001234-0000000000005678");
- NL_TEST_ASSERT(inSuite,
- MakeInstanceName(buffer, sizeof(buffer),
- PeerId().SetCompressedFabricId(0x1122334455667788ULL).SetNodeId(0x123456789abcdefULL)) ==
- CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "1122334455667788-0123456789ABCDEF") == 0);
+ EXPECT_EQ(MakeInstanceName(buffer, sizeof(buffer),
+ PeerId().SetCompressedFabricId(0x1122334455667788ULL).SetNodeId(0x123456789abcdefULL)),
+ CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "1122334455667788-0123456789ABCDEF");
// insufficient buffer size:
// buffer needs at least space for hex encoding + separator + 0 terminator
constexpr size_t kMinBufferSize = 2 * 16 + 1 + 1;
for (size_t shortSize = 0; shortSize < kMinBufferSize; shortSize++)
{
- NL_TEST_ASSERT(inSuite, MakeInstanceName(buffer, shortSize, PeerId()) != CHIP_NO_ERROR);
+ EXPECT_NE(MakeInstanceName(buffer, shortSize, PeerId()), CHIP_NO_ERROR);
}
- NL_TEST_ASSERT(inSuite, MakeInstanceName(buffer, kMinBufferSize, PeerId()) == CHIP_NO_ERROR);
+ EXPECT_EQ(MakeInstanceName(buffer, kMinBufferSize, PeerId()), CHIP_NO_ERROR);
}
-void TestExtractIdFromInstanceName(nlTestSuite * inSuite, void * inContext)
+TEST(TestServiceNaming, TestExtractIdFromInstanceName)
{
PeerId peerId;
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName(nullptr, nullptr) == CHIP_ERROR_INVALID_ARGUMENT);
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("ACDEF1234567890-1234567890ABCDEF", nullptr) == CHIP_ERROR_INVALID_ARGUMENT);
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName(nullptr, &peerId) == CHIP_ERROR_INVALID_ARGUMENT);
+ EXPECT_EQ(ExtractIdFromInstanceName(nullptr, nullptr), CHIP_ERROR_INVALID_ARGUMENT);
+ EXPECT_EQ(ExtractIdFromInstanceName("ACDEF1234567890-1234567890ABCDEF", nullptr), CHIP_ERROR_INVALID_ARGUMENT);
+ EXPECT_EQ(ExtractIdFromInstanceName(nullptr, &peerId), CHIP_ERROR_INVALID_ARGUMENT);
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("ABCDEF1234567890-1234567890ABCDEF", &peerId) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, peerId == PeerId().SetCompressedFabricId(0xABCDEF1234567890ULL).SetNodeId(0x1234567890ABCDEFULL));
+ EXPECT_EQ(ExtractIdFromInstanceName("ABCDEF1234567890-1234567890ABCDEF", &peerId), CHIP_NO_ERROR);
+ EXPECT_EQ(peerId, PeerId().SetCompressedFabricId(0xABCDEF1234567890ULL).SetNodeId(0x1234567890ABCDEFULL));
// ending in period (partial name) is acceptable
- NL_TEST_ASSERT(inSuite,
- ExtractIdFromInstanceName("1122334455667788-AABBCCDDEEFF1122.some.suffix.here", &peerId) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, peerId == PeerId().SetCompressedFabricId(0x1122334455667788ULL).SetNodeId(0xaabbccddeeff1122ULL));
+ EXPECT_EQ(ExtractIdFromInstanceName("1122334455667788-AABBCCDDEEFF1122.some.suffix.here", &peerId), CHIP_NO_ERROR);
+ EXPECT_EQ(peerId, PeerId().SetCompressedFabricId(0x1122334455667788ULL).SetNodeId(0xaabbccddeeff1122ULL));
// Invalid: non hex character
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("1x22334455667788-AABBCCDDEEDD1122", &peerId) != CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("1x22334455667788-AABBCCDDEEDD1122", &peerId), CHIP_NO_ERROR);
// Invalid: missing node id part (no - separator)
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("1122334455667788x2233445566778899", &peerId) != CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("1122334455667788x2233445566778899.12-33.4455", &peerId) != CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("1122334455667788x2233445566778899.4455", &peerId) != CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("1122334455667788x2233445566778899", &peerId), CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("1122334455667788x2233445566778899.12-33.4455", &peerId), CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("1122334455667788x2233445566778899.4455", &peerId), CHIP_NO_ERROR);
// Invalid: missing part
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("-1234567890ABCDEF", &peerId) != CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("1234567890ABCDEF-", &peerId) != CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("-1234567890ABCDEF", &peerId), CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("1234567890ABCDEF-", &peerId), CHIP_NO_ERROR);
// Invalid: separator in wrong place
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("112233445566778-8AABBCCDDEEFF1122", &peerId) != CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("1122334455667788A-ABBCCDDEEFF1122", &peerId) != CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("112233445566778-8AABBCCDDEEFF1122", &peerId), CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("1122334455667788A-ABBCCDDEEFF1122", &peerId), CHIP_NO_ERROR);
// Invalid: fabric part too short
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("11223344556677-AABBCCDDEEFF1122", &peerId) != CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("11223344556677-AABBCCDDEEFF1122", &peerId), CHIP_NO_ERROR);
// Invalid: fabric part too long
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("112233445566778899-AABBCCDDEEFF1122", &peerId) != CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("112233445566778899-AABBCCDDEEFF1122", &peerId), CHIP_NO_ERROR);
// Invalid: node part too short
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("1122334455667788-AABBCCDDEEFF11", &peerId) != CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("1122334455667788-AABBCCDDEEFF11", &peerId), CHIP_NO_ERROR);
// Invalid: node part too long
- NL_TEST_ASSERT(inSuite, ExtractIdFromInstanceName("1122334455667788-AABBCCDDEEFF112233", &peerId) != CHIP_NO_ERROR);
+ EXPECT_NE(ExtractIdFromInstanceName("1122334455667788-AABBCCDDEEFF112233", &peerId), CHIP_NO_ERROR);
}
-void TestMakeServiceNameSubtype(nlTestSuite * inSuite, void * inContext)
+TEST(TestServiceNaming, TestMakeServiceNameSubtype)
{
constexpr size_t kSize = 19;
char buffer[kSize];
@@ -106,71 +100,71 @@
// Long tests
filter.type = DiscoveryFilterType::kLongDiscriminator;
filter.code = 3;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_L3") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_L3");
filter.code = (1 << 12) - 1;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_L4095") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_L4095");
filter.code = 1 << 12;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) != CHIP_NO_ERROR);
+ EXPECT_NE(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
// Short tests
filter.type = DiscoveryFilterType::kShortDiscriminator;
filter.code = 3;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S3") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_S3");
filter.code = (1 << 4) - 1;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S15") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_S15");
filter.code = 1 << 4;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) != CHIP_NO_ERROR);
+ EXPECT_NE(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
// Vendor tests
filter.type = DiscoveryFilterType::kVendorId;
filter.code = 3;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_V3") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_V3");
filter.code = 0xFFFF;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_V65535") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_V65535");
filter.code = 1 << 16;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) != CHIP_NO_ERROR);
+ EXPECT_NE(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
// Device Type tests
filter.type = DiscoveryFilterType::kDeviceType;
filter.code = 3;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_T3") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_T3");
// TODO: Add tests for longer device types once spec issue #3226 is closed.
// Commissioning mode tests
filter.type = DiscoveryFilterType::kCommissioningMode;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_CM") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_CM");
// Compressed fabric ID tests.
filter.type = DiscoveryFilterType::kCompressedFabricId;
filter.code = 0xABCD12341111BBBB;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_IABCD12341111BBBB") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_IABCD12341111BBBB");
// None tests.
filter.type = DiscoveryFilterType::kNone;
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "");
// instance name - "1234567890123456._matterc"
filter.type = DiscoveryFilterType::kInstanceName;
filter.instanceName = (char *) "1234567890123456";
- NL_TEST_ASSERT(inSuite, MakeServiceSubtype(buffer, sizeof(buffer), filter) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "1234567890123456") == 0);
+ EXPECT_EQ(MakeServiceSubtype(buffer, sizeof(buffer), filter), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "1234567890123456");
}
-void TestMakeServiceTypeName(nlTestSuite * inSuite, void * inContext)
+TEST(TestServiceNaming, TestMakeServiceTypeName)
{
// TODO(cecille): These need to be changed to remove leading zeros
constexpr size_t kSize = 128;
@@ -180,110 +174,80 @@
// Long tests
filter.type = DiscoveryFilterType::kLongDiscriminator;
filter.code = 3;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_L3._sub._matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_L3._sub._matterc");
filter.code = (1 << 12) - 1;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_L4095._sub._matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_L4095._sub._matterc");
filter.code = 1 << 12;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) != CHIP_NO_ERROR);
+ EXPECT_NE(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
// Short tests
filter.type = DiscoveryFilterType::kShortDiscriminator;
filter.code = 3;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S3._sub._matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_S3._sub._matterc");
filter.code = (1 << 4) - 1;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_S15._sub._matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_S15._sub._matterc");
filter.code = 1 << 4;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) != CHIP_NO_ERROR);
+ EXPECT_NE(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
// Vendor tests
filter.type = DiscoveryFilterType::kVendorId;
filter.code = 3;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_V3._sub._matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_V3._sub._matterc");
filter.code = (1 << 16) - 1;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_V65535._sub._matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_V65535._sub._matterc");
filter.code = 1 << 16;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) != CHIP_NO_ERROR);
+ EXPECT_NE(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
// Device Type tests
filter.type = DiscoveryFilterType::kDeviceType;
filter.code = 3;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_T3._sub._matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_T3._sub._matterc");
// Commissioning mode tests
filter.type = DiscoveryFilterType::kCommissioningMode;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_CM._sub._matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_CM._sub._matterc");
// Compressed fabric ID tests
filter.type = DiscoveryFilterType::kCompressedFabricId;
filter.code = 0x1234ABCD0000AAAA;
- NL_TEST_ASSERT(inSuite, MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kOperational) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_I1234ABCD0000AAAA._sub._matter") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kOperational), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_I1234ABCD0000AAAA._sub._matter");
// None tests
filter.type = DiscoveryFilterType::kNone;
- NL_TEST_ASSERT(inSuite,
- MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_matterc");
filter.type = DiscoveryFilterType::kNone;
- NL_TEST_ASSERT(inSuite, MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionerNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_matterd") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, sizeof(buffer), filter, DiscoveryType::kCommissionerNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_matterd");
// Test buffer just under the right size - "_matterc" = 8 + nullchar = 9
filter.type = DiscoveryFilterType::kNone;
- NL_TEST_ASSERT(inSuite, MakeServiceTypeName(buffer, 8, filter, DiscoveryType::kCommissionableNode) == CHIP_ERROR_NO_MEMORY);
+ EXPECT_EQ(MakeServiceTypeName(buffer, 8, filter, DiscoveryType::kCommissionableNode), CHIP_ERROR_NO_MEMORY);
// Test buffer exactly the right size - "_matterc" = 8 + nullchar = 9
filter.type = DiscoveryFilterType::kNone;
- NL_TEST_ASSERT(inSuite, MakeServiceTypeName(buffer, 9, filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, 9, filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_matterc");
// Test buffer exactly the right size for subtype - "_CM._sub._matterc" = 17 + nullchar = 18
filter.type = DiscoveryFilterType::kCommissioningMode;
- NL_TEST_ASSERT(inSuite, MakeServiceTypeName(buffer, 18, filter, DiscoveryType::kCommissionableNode) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strcmp(buffer, "_CM._sub._matterc") == 0);
+ EXPECT_EQ(MakeServiceTypeName(buffer, 18, filter, DiscoveryType::kCommissionableNode), CHIP_NO_ERROR);
+ EXPECT_STREQ(buffer, "_CM._sub._matterc");
}
-
-const nlTest sTests[] = {
- NL_TEST_DEF("MakeInstanceName", TestMakeInstanceName), //
- NL_TEST_DEF("ExtractIdFromInstandceName", TestExtractIdFromInstanceName), //
- NL_TEST_DEF("TestMakeServiceNameSubtype", TestMakeServiceNameSubtype), //
- NL_TEST_DEF("TestMakeCommisisonableNodeServiceTypeName", TestMakeServiceTypeName), //
- NL_TEST_SENTINEL() //
-};
-
} // namespace
-
-int TestCHIPServiceNaming()
-{
- nlTestSuite theSuite = { "ServiceNaming", &sTests[0], nullptr, nullptr };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestCHIPServiceNaming)
diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp
index d6e7e6e..d487c26 100644
--- a/src/lib/dnssd/tests/TestTxtFields.cpp
+++ b/src/lib/dnssd/tests/TestTxtFields.cpp
@@ -23,9 +23,8 @@
#include <string.h>
#include <lib/dnssd/Resolver.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
using namespace chip;
using namespace chip::Dnssd;
@@ -41,161 +40,161 @@
return ByteSpan(reinterpret_cast<uint8_t *>(key), len);
}
-void TestGetTxtFieldKey(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetTxtFieldKey)
{
char key[4];
strcpy(key, "D");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kLongDiscriminator);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kLongDiscriminator);
strcpy(key, "VP");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kVendorProduct);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kVendorProduct);
strcpy(key, "CM");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kCommissioningMode);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kCommissioningMode);
strcpy(key, "DT");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kDeviceType);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kDeviceType);
strcpy(key, "DN");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kDeviceName);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kDeviceName);
strcpy(key, "RI");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kRotatingDeviceId);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kRotatingDeviceId);
strcpy(key, "PI");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kPairingInstruction);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kPairingInstruction);
strcpy(key, "PH");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kPairingHint);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kPairingHint);
strcpy(key, "SII");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kSessionIdleInterval);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kSessionIdleInterval);
strcpy(key, "SAI");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kSessionActiveInterval);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kSessionActiveInterval);
strcpy(key, "SAT");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kSessionActiveThreshold);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kSessionActiveThreshold);
strcpy(key, "T");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kTcpSupported);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kTcpSupported);
strcpy(key, "ICD");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kLongIdleTimeICD);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kLongIdleTimeICD);
strcpy(key, "XX");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kUnknown);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kUnknown);
strcpy(key, "CP");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kCommissionerPasscode);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kCommissionerPasscode);
}
-void TestGetTxtFieldKeyCaseInsensitive(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetTxtFieldKeyCaseInsensitive)
{
char key[3];
strcpy(key, "d");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kLongDiscriminator);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kLongDiscriminator);
strcpy(key, "vp");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kVendorProduct);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kVendorProduct);
strcpy(key, "Vp");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kVendorProduct);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kVendorProduct);
strcpy(key, "vP");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kVendorProduct);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kVendorProduct);
strcpy(key, "Xx");
- NL_TEST_ASSERT(inSuite, GetTxtFieldKey(GetSpan(key)) == TxtFieldKey::kUnknown);
+ EXPECT_EQ(GetTxtFieldKey(GetSpan(key)), TxtFieldKey::kUnknown);
}
-void TestGetProduct(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetProduct)
{
// Product and vendor are given as part of the same key, on either side of a + sign. Product is after the +
char vp[64];
strcpy(vp, "123+456");
- NL_TEST_ASSERT(inSuite, GetProduct(GetSpan(vp)) == 456);
+ EXPECT_EQ(GetProduct(GetSpan(vp)), 456);
strcpy(vp, "123+");
- NL_TEST_ASSERT(inSuite, GetProduct(GetSpan(vp)) == 0);
+ EXPECT_EQ(GetProduct(GetSpan(vp)), 0);
strcpy(vp, "+456");
- NL_TEST_ASSERT(inSuite, GetProduct(GetSpan(vp)) == 456);
+ EXPECT_EQ(GetProduct(GetSpan(vp)), 456);
strcpy(vp, "123");
- NL_TEST_ASSERT(inSuite, GetProduct(GetSpan(vp)) == 0);
+ EXPECT_EQ(GetProduct(GetSpan(vp)), 0);
// overflow a uint16
sprintf(vp, "123+%" PRIu32, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
- NL_TEST_ASSERT(inSuite, GetProduct(GetSpan(vp)) == 0);
+ EXPECT_EQ(GetProduct(GetSpan(vp)), 0);
}
-void TestGetVendor(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetVendor)
{
// Product and vendor are given as part of the same key, on either side of a + sign. Vendor is first
char vp[64];
strcpy(vp, "123+456");
- NL_TEST_ASSERT(inSuite, GetVendor(GetSpan(vp)) == 123);
+ EXPECT_EQ(GetVendor(GetSpan(vp)), 123);
strcpy(vp, "123+");
- NL_TEST_ASSERT(inSuite, GetVendor(GetSpan(vp)) == 123);
+ EXPECT_EQ(GetVendor(GetSpan(vp)), 123);
strcpy(vp, "+456");
- NL_TEST_ASSERT(inSuite, GetVendor(GetSpan(vp)) == 0);
+ EXPECT_EQ(GetVendor(GetSpan(vp)), 0);
strcpy(vp, "123");
- NL_TEST_ASSERT(inSuite, GetVendor(GetSpan(vp)) == 123);
+ EXPECT_EQ(GetVendor(GetSpan(vp)), 123);
// overflow a uint16
sprintf(vp, "%" PRIu32 "+456", static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
- NL_TEST_ASSERT(inSuite, GetVendor(GetSpan(vp)) == 0);
+ EXPECT_EQ(GetVendor(GetSpan(vp)), 0);
}
-void TestGetLongDiscriminator(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetLongDiscriminator)
{
char ld[64];
strcpy(ld, "1234");
- NL_TEST_ASSERT(inSuite, GetLongDiscriminator(GetSpan(ld)) == 1234);
+ EXPECT_EQ(GetLongDiscriminator(GetSpan(ld)), 1234);
// overflow a uint16
sprintf(ld, "%" PRIu32, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
printf("ld = %s\n", ld);
- NL_TEST_ASSERT(inSuite, GetLongDiscriminator(GetSpan(ld)) == 0);
+ EXPECT_EQ(GetLongDiscriminator(GetSpan(ld)), 0);
}
-void TestGetCommissioningMode(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetCommissioningMode)
{
char cm[64];
strcpy(cm, "0");
- NL_TEST_ASSERT(inSuite, GetCommissioningMode(GetSpan(cm)) == 0);
+ EXPECT_EQ(GetCommissioningMode(GetSpan(cm)), 0);
strcpy(cm, "1");
- NL_TEST_ASSERT(inSuite, GetCommissioningMode(GetSpan(cm)) == 1);
+ EXPECT_EQ(GetCommissioningMode(GetSpan(cm)), 1);
strcpy(cm, "2");
- NL_TEST_ASSERT(inSuite, GetCommissioningMode(GetSpan(cm)) == 2);
+ EXPECT_EQ(GetCommissioningMode(GetSpan(cm)), 2);
// overflow a uint8
sprintf(cm, "%u", static_cast<uint16_t>(std::numeric_limits<uint8_t>::max()) + 1);
- NL_TEST_ASSERT(inSuite, GetCommissioningMode(GetSpan(cm)) == 0);
+ EXPECT_EQ(GetCommissioningMode(GetSpan(cm)), 0);
}
-void TestGetDeviceType(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetDeviceType)
{
char dt[64];
strcpy(dt, "1234");
- NL_TEST_ASSERT(inSuite, GetDeviceType(GetSpan(dt)) == 1234);
+ EXPECT_EQ(GetDeviceType(GetSpan(dt)), 1234u);
// overflow a uint32
sprintf(dt, "%" PRIu64, static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) + 1);
- NL_TEST_ASSERT(inSuite, GetDeviceType(GetSpan(dt)) == 0);
+ EXPECT_EQ(GetDeviceType(GetSpan(dt)), 0u);
}
-void TestGetDeviceName(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetDeviceName)
{
char name[kMaxDeviceNameLen + 1] = "";
char val[kMaxDeviceNameLen + 2];
strcpy(val, "testname");
GetDeviceName(GetSpan(val), name);
- NL_TEST_ASSERT(inSuite, strcmp(name, "testname") == 0);
+ EXPECT_STREQ(name, "testname");
// If the data passed in is too long, it should truncate the end.
memset(val, 'a', kMaxDeviceNameLen);
@@ -204,10 +203,10 @@
GetDeviceName(GetSpan(val), name);
val[kMaxDeviceNameLen] = '\0';
- NL_TEST_ASSERT(inSuite, strcmp(name, val) == 0);
+ EXPECT_STREQ(name, val);
}
-void TestGetRotatingDeviceId(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetRotatingDeviceId)
{
// Rotating device ID is given as up to 50 hex bytes
char ri[kMaxRotatingIdLen * 2 + 1];
@@ -217,58 +216,58 @@
strcpy(ri, "0A1B");
GetRotatingDeviceId(GetSpan(ri), id, &len);
printf("id[0] = %x\n", id[0]);
- NL_TEST_ASSERT(inSuite, id[0] == 0x0A);
- NL_TEST_ASSERT(inSuite, id[1] == 0x1B);
- NL_TEST_ASSERT(inSuite, len == 2);
+ EXPECT_EQ(id[0], 0x0A);
+ EXPECT_EQ(id[1], 0x1B);
+ EXPECT_EQ(len, 2u);
// odd number of characters can't be parsed.
strcpy(ri, "0A1BC");
GetRotatingDeviceId(GetSpan(ri), id, &len);
- NL_TEST_ASSERT(inSuite, len == 0);
+ EXPECT_EQ(len, 0u);
// non-hex characters can't be parsed
strcpy(ri, "0ATT");
GetRotatingDeviceId(GetSpan(ri), id, &len);
- NL_TEST_ASSERT(inSuite, len == 0);
+ EXPECT_EQ(len, 0u);
// Lower case should work on SDK even though devices shouldn't be sending that.
strcpy(ri, "0a1b");
GetRotatingDeviceId(GetSpan(ri), id, &len);
- NL_TEST_ASSERT(inSuite, id[0] == 0x0A);
- NL_TEST_ASSERT(inSuite, id[1] == 0x1B);
- NL_TEST_ASSERT(inSuite, len == 2);
+ EXPECT_EQ(id[0], 0x0A);
+ EXPECT_EQ(id[1], 0x1B);
+ EXPECT_EQ(len, 2u);
strcpy(ri, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F3031");
GetRotatingDeviceId(GetSpan(ri), id, &len);
- NL_TEST_ASSERT(inSuite, len == sizeof(id));
+ EXPECT_EQ(len, sizeof(id));
for (size_t i = 0; i < sizeof(id); ++i)
{
- NL_TEST_ASSERT(inSuite, id[i] == i);
+ EXPECT_EQ(id[i], i);
}
}
-void TestGetPairingHint(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetPairingHint)
{
char ph[64];
strcpy(ph, "0");
- NL_TEST_ASSERT(inSuite, GetPairingHint(GetSpan(ph)) == 0);
+ EXPECT_EQ(GetPairingHint(GetSpan(ph)), 0);
strcpy(ph, "9");
- NL_TEST_ASSERT(inSuite, GetPairingHint(GetSpan(ph)) == 9);
+ EXPECT_EQ(GetPairingHint(GetSpan(ph)), 9);
// overflow a uint16
sprintf(ph, "%" PRIu32, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
- NL_TEST_ASSERT(inSuite, GetPairingHint(GetSpan(ph)) == 0);
+ EXPECT_EQ(GetPairingHint(GetSpan(ph)), 0);
}
-void TestGetPairingInstruction(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetPairingInstruction)
{
char data[kMaxPairingInstructionLen + 2];
char ret[kMaxPairingInstructionLen + 1] = "";
strcpy(data, "something");
GetPairingInstruction(GetSpan(data), ret);
- NL_TEST_ASSERT(inSuite, strcmp(ret, "something") == 0);
+ EXPECT_STREQ(ret, "something");
// Exactly the max len.
memset(data, 'a', kMaxPairingInstructionLen);
@@ -276,7 +275,7 @@
GetPairingInstruction(GetSpan(data), ret);
// Add back the null terminator removed by GetSpan.
data[kMaxPairingInstructionLen] = '\0';
- NL_TEST_ASSERT(inSuite, strcmp(data, ret) == 0);
+ EXPECT_STREQ(data, ret);
// Too long - should truncate end.
memset(data, 'a', kMaxPairingInstructionLen);
@@ -284,21 +283,21 @@
data[kMaxPairingInstructionLen + 1] = '\0';
GetPairingInstruction(GetSpan(data), ret);
data[kMaxPairingInstructionLen] = '\0';
- NL_TEST_ASSERT(inSuite, strcmp(ret, data) == 0);
+ EXPECT_STREQ(ret, data);
}
-void TestGetCommissionerPasscode(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestGetCommissionerPasscode)
{
char cm[64];
strcpy(cm, "0");
- NL_TEST_ASSERT(inSuite, GetCommissionerPasscode(GetSpan(cm)) == 0);
+ EXPECT_EQ(GetCommissionerPasscode(GetSpan(cm)), 0);
strcpy(cm, "1");
- NL_TEST_ASSERT(inSuite, GetCommissionerPasscode(GetSpan(cm)) == 1);
+ EXPECT_EQ(GetCommissionerPasscode(GetSpan(cm)), 1);
// overflow a uint8
sprintf(cm, "%u", static_cast<uint16_t>(std::numeric_limits<uint8_t>::max()) + 1);
- NL_TEST_ASSERT(inSuite, GetCommissionerPasscode(GetSpan(cm)) == 0);
+ EXPECT_EQ(GetCommissionerPasscode(GetSpan(cm)), 0);
}
bool NodeDataIsEmpty(const DiscoveredNodeData & node)
@@ -328,7 +327,7 @@
}
// The individual fill tests test the error cases for each key type, this test is used to ensure the proper record is filled.
-void TestFillDiscoveredNodeDataFromTxt(nlTestSuite * inSuite, void * inContext)
+TEST(TestTxtFields, TestFillDiscoveredNodeDataFromTxt)
{
char key[3];
char val[16];
@@ -338,78 +337,78 @@
strcpy(key, "D");
strcpy(val, "840");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
- NL_TEST_ASSERT(inSuite, filled.nodeData.longDiscriminator == 840);
+ EXPECT_EQ(filled.nodeData.longDiscriminator, 840);
filled.nodeData.longDiscriminator = 0;
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
+ EXPECT_TRUE(NodeDataIsEmpty(filled));
// vendor and product
strcpy(key, "VP");
strcpy(val, "123+456");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
- NL_TEST_ASSERT(inSuite, filled.nodeData.vendorId == 123);
- NL_TEST_ASSERT(inSuite, filled.nodeData.productId == 456);
+ EXPECT_EQ(filled.nodeData.vendorId, 123);
+ EXPECT_EQ(filled.nodeData.productId, 456);
filled.nodeData.vendorId = 0;
filled.nodeData.productId = 0;
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
+ EXPECT_TRUE(NodeDataIsEmpty(filled));
// Commissioning mode
strcpy(key, "CM");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
- NL_TEST_ASSERT(inSuite, filled.nodeData.commissioningMode == 1);
+ EXPECT_EQ(filled.nodeData.commissioningMode, 1);
filled.nodeData.commissioningMode = 0;
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
+ EXPECT_TRUE(NodeDataIsEmpty(filled));
// Supports Commissioner Generated Passcode
strcpy(key, "CP");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
- NL_TEST_ASSERT(inSuite, filled.nodeData.supportsCommissionerGeneratedPasscode == true);
+ EXPECT_TRUE(filled.nodeData.supportsCommissionerGeneratedPasscode);
filled.nodeData.supportsCommissionerGeneratedPasscode = false;
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
+ EXPECT_TRUE(NodeDataIsEmpty(filled));
// Device type
strcpy(key, "DT");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
- NL_TEST_ASSERT(inSuite, filled.nodeData.deviceType == 1);
+ EXPECT_EQ(filled.nodeData.deviceType, 1u);
filled.nodeData.deviceType = 0;
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
+ EXPECT_TRUE(NodeDataIsEmpty(filled));
// Device name
strcpy(key, "DN");
strcpy(val, "abc");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
- NL_TEST_ASSERT(inSuite, strcmp(filled.nodeData.deviceName, "abc") == 0);
+ EXPECT_STREQ(filled.nodeData.deviceName, "abc");
memset(filled.nodeData.deviceName, 0, sizeof(filled.nodeData.deviceName));
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
+ EXPECT_TRUE(NodeDataIsEmpty(filled));
// Rotating device id
strcpy(key, "RI");
strcpy(val, "1A2B");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
- NL_TEST_ASSERT(inSuite, filled.nodeData.rotatingId[0] == 0x1A);
- NL_TEST_ASSERT(inSuite, filled.nodeData.rotatingId[1] == 0x2B);
- NL_TEST_ASSERT(inSuite, filled.nodeData.rotatingIdLen == 2);
+ EXPECT_EQ(filled.nodeData.rotatingId[0], 0x1A);
+ EXPECT_EQ(filled.nodeData.rotatingId[1], 0x2B);
+ EXPECT_EQ(filled.nodeData.rotatingIdLen, 2u);
filled.nodeData.rotatingIdLen = 0;
memset(filled.nodeData.rotatingId, 0, sizeof(filled.nodeData.rotatingId));
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
+ EXPECT_TRUE(NodeDataIsEmpty(filled));
// Pairing instruction
strcpy(key, "PI");
strcpy(val, "hint");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
- NL_TEST_ASSERT(inSuite, strcmp(filled.nodeData.pairingInstruction, "hint") == 0);
+ EXPECT_STREQ(filled.nodeData.pairingInstruction, "hint");
memset(filled.nodeData.pairingInstruction, 0, sizeof(filled.nodeData.pairingInstruction));
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
+ EXPECT_TRUE(NodeDataIsEmpty(filled));
// Pairing hint
strcpy(key, "PH");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), filled.nodeData);
- NL_TEST_ASSERT(inSuite, filled.nodeData.pairingHint == 1);
+ EXPECT_EQ(filled.nodeData.pairingHint, 1);
filled.nodeData.pairingHint = 0;
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(filled));
+ EXPECT_TRUE(NodeDataIsEmpty(filled));
}
bool NodeDataIsEmpty(const ResolvedNodeData & nodeData)
@@ -452,7 +451,7 @@
// Test SAI (formally CRI)
template <class NodeData>
-void TxtFieldSessionIdleInterval(nlTestSuite * inSuite, void * inContext)
+void TxtFieldSessionIdleInterval()
{
char key[4];
char val[16];
@@ -462,60 +461,70 @@
strcpy(key, "SII");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalIdle().Value() == 1_ms32);
+ EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle().Value(), 1_ms32);
// Maximum
strcpy(key, "SII");
strcpy(val, "3600000");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalIdle().Value() == 3600000_ms32);
+ EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle().Value(), 3600000_ms32);
// Test no other fields were populated
ResetRetryIntervalIdle(nodeData);
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData));
+ EXPECT_TRUE(NodeDataIsEmpty(nodeData));
// Invalid SII - negative value
strcpy(key, "SII");
strcpy(val, "-1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
// Invalid SII - greater than maximum
strcpy(key, "SII");
strcpy(val, "3600001");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
// Invalid SII - much greater than maximum
strcpy(key, "SII");
strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32)
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
// Invalid SII - hexadecimal value
strcpy(key, "SII");
strcpy(val, "0x20");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
// Invalid SII - leading zeros
strcpy(key, "SII");
strcpy(val, "0700");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
// Invalid SII - text at the end
strcpy(key, "SII");
strcpy(val, "123abc");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue());
+}
+
+TEST(TestTxtFields, TxtDiscoveredFieldMrpRetryIntervalIdle)
+{
+ TxtFieldSessionIdleInterval<DiscoveredNodeData>();
+}
+
+TEST(TestTxtFields, TxtResolvedFieldMrpRetryIntervalIdle)
+{
+ TxtFieldSessionIdleInterval<ResolvedNodeData>();
}
// Test SAI (formerly CRA)
template <class NodeData>
-void TxtFieldSessionActiveInterval(nlTestSuite * inSuite, void * inContext)
+void TxtFieldSessionActiveInterval()
{
char key[4];
char val[16];
@@ -525,60 +534,70 @@
strcpy(key, "SAI");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalActive().Value() == 1_ms32);
+ EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalActive().Value(), 1_ms32);
// Maximum
strcpy(key, "SAI");
strcpy(val, "3600000");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryIntervalActive().Value() == 3600000_ms32);
+ EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalActive().Value(), 3600000_ms32);
// Test no other fields were populated
ResetRetryIntervalActive(nodeData);
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData));
+ EXPECT_TRUE(NodeDataIsEmpty(nodeData));
// Invalid SAI - negative value
strcpy(key, "SAI");
strcpy(val, "-1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
// Invalid SAI - greater than maximum
strcpy(key, "SAI");
strcpy(val, "3600001");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
// Invalid SAI - much greater than maximum
strcpy(key, "SAI");
strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32)
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
// Invalid SAI - hexadecimal value
strcpy(key, "SAI");
strcpy(val, "0x20");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
// Invalid SAI - leading zeros
strcpy(key, "SAI");
strcpy(val, "0700");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
// Invalid SAI - text at the end
strcpy(key, "SAI");
strcpy(val, "123abc");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue());
+}
+
+TEST(TestTxtFields, TxtDiscoveredFieldMrpRetryIntervalActive)
+{
+ TxtFieldSessionActiveInterval<DiscoveredNodeData>();
+}
+
+TEST(TestTxtFields, TxtResolvedFieldMrpRetryIntervalActive)
+{
+ TxtFieldSessionActiveInterval<ResolvedNodeData>();
}
// Test SAT (Session Active Threshold)
template <class NodeData>
-void TxtFieldSessionActiveThreshold(nlTestSuite * inSuite, void * inContext)
+void TxtFieldSessionActiveThreshold()
{
char key[4];
char val[16];
@@ -588,60 +607,70 @@
strcpy(key, "SAT");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryActiveThreshold().Value() == 1_ms16);
+ EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
+ EXPECT_EQ(nodeData.resolutionData.GetMrpRetryActiveThreshold().Value(), 1_ms16);
// Maximum
strcpy(key, "SAT");
strcpy(val, "65535");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.GetMrpRetryActiveThreshold().Value() == 65535_ms16);
+ EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
+ EXPECT_EQ(nodeData.resolutionData.GetMrpRetryActiveThreshold().Value(), 65535_ms16);
// Test no other fields were populated
ResetRetryActiveThreshold(nodeData);
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData));
+ EXPECT_TRUE(NodeDataIsEmpty(nodeData));
// Invalid SAI - negative value
strcpy(key, "SAT");
strcpy(val, "-1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
// Invalid SAI - greater than maximum
strcpy(key, "SAT");
strcpy(val, "65536");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
// Invalid SAT - much greater than maximum
strcpy(key, "SAT");
strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32)
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
// Invalid SAT - hexadecimal value
strcpy(key, "SAT");
strcpy(val, "0x20");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
// Invalid SAT - leading zeros
strcpy(key, "SAT");
strcpy(val, "0700");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
// Invalid SAT - text at the end
strcpy(key, "SAT");
strcpy(val, "123abc");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
+ EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue());
+}
+
+TEST(TestTxtFields, TxtDiscoveredFieldMrpRetryActiveThreshold)
+{
+ TxtFieldSessionActiveThreshold<DiscoveredNodeData>();
+}
+
+TEST(TestTxtFields, TxtResolvedFieldMrpRetryActiveThreshold)
+{
+ TxtFieldSessionActiveThreshold<ResolvedNodeData>();
}
// Test T (TCP support)
template <class NodeData>
-void TxtFieldTcpSupport(nlTestSuite * inSuite, void * inContext)
+void TxtFieldTcpSupport()
{
char key[4];
char val[8];
@@ -651,28 +680,38 @@
strcpy(key, "T");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.supportsTcp);
+ EXPECT_TRUE(nodeData.resolutionData.supportsTcp);
// Test no other fields were populated
nodeData.resolutionData.supportsTcp = false;
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData));
+ EXPECT_TRUE(NodeDataIsEmpty(nodeData));
// False
strcpy(key, "T");
strcpy(val, "0");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.supportsTcp == false);
+ EXPECT_EQ(nodeData.resolutionData.supportsTcp, false);
// Invalid value, stil false
strcpy(key, "T");
strcpy(val, "asdf");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.supportsTcp == false);
+ EXPECT_EQ(nodeData.resolutionData.supportsTcp, false);
+}
+
+TEST(TestTxtFields, TxtDiscoveredFieldTcpSupport)
+{
+ TxtFieldTcpSupport<DiscoveredNodeData>();
+}
+
+TEST(TestTxtFields, TxtResolvedFieldTcpSupport)
+{
+ TxtFieldTcpSupport<ResolvedNodeData>();
}
// Test ICD (ICD operation Mode)
template <class NodeData>
-void TxtFieldICDoperatesAsLIT(nlTestSuite * inSuite, void * inContext)
+void TxtFieldICDoperatesAsLIT()
{
char key[4];
char val[16];
@@ -682,32 +721,42 @@
strcpy(key, "ICD");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.isICDOperatingAsLIT.HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.isICDOperatingAsLIT.Value());
+ EXPECT_TRUE(nodeData.resolutionData.isICDOperatingAsLIT.HasValue());
+ EXPECT_TRUE(nodeData.resolutionData.isICDOperatingAsLIT.Value());
// Test no other fields were populated
nodeData.resolutionData.isICDOperatingAsLIT.ClearValue();
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData));
+ EXPECT_TRUE(NodeDataIsEmpty(nodeData));
// ICD is operating as a SIT device
strcpy(key, "ICD");
strcpy(val, "0");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.isICDOperatingAsLIT.HasValue());
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.isICDOperatingAsLIT.Value() == false);
+ EXPECT_TRUE(nodeData.resolutionData.isICDOperatingAsLIT.HasValue());
+ EXPECT_EQ(nodeData.resolutionData.isICDOperatingAsLIT.Value(), false);
nodeData.resolutionData.isICDOperatingAsLIT.ClearValue();
- NL_TEST_ASSERT(inSuite, NodeDataIsEmpty(nodeData));
+ EXPECT_TRUE(NodeDataIsEmpty(nodeData));
// Invalid value, No key set
strcpy(key, "ICD");
strcpy(val, "asdf");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.isICDOperatingAsLIT.HasValue() == false);
+ EXPECT_EQ(nodeData.resolutionData.isICDOperatingAsLIT.HasValue(), false);
+}
+
+TEST(TestTxtFields, TxtDiscoveredIsICDoperatingAsLIT)
+{
+ TxtFieldICDoperatesAsLIT<DiscoveredNodeData>();
+}
+
+TEST(TestTxtFields, TxtResolvedFieldICDoperatingAsLIT)
+{
+ TxtFieldICDoperatesAsLIT<ResolvedNodeData>();
}
// Test IsDeviceTreatedAsSleepy() with CRI
template <class NodeData>
-void TestIsDeviceSessionIdle(nlTestSuite * inSuite, void * inContext)
+void TestIsDeviceSessionIdle()
{
char key[4];
char val[32];
@@ -716,24 +765,34 @@
CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL);
// No key/val set, so the device can't be sleepy
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
+ EXPECT_FALSE(nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
// If the interval is the default value, the device is not sleepy
strcpy(key, "SII");
sprintf(val, "%d", static_cast<int>(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL.count()));
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
+ EXPECT_FALSE(nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
// If the interval is greater than the default value, the device is sleepy
sprintf(key, "SII");
sprintf(val, "%d", static_cast<int>(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL.count() + 1));
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
+ EXPECT_TRUE(nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
+}
+
+TEST(TestTxtFields, TxtDiscoveredIsDeviceSessionIdle)
+{
+ TestIsDeviceSessionIdle<DiscoveredNodeData>();
+}
+
+TEST(TestTxtFields, TxtResolvedIsDeviceSessionIdle)
+{
+ TestIsDeviceSessionIdle<ResolvedNodeData>();
}
// Test IsDeviceTreatedAsSleepy() with CRA
template <class NodeData>
-void TestIsDeviceSessionActive(nlTestSuite * inSuite, void * inContext)
+void TestIsDeviceSessionActive()
{
char key[4];
char val[32];
@@ -742,59 +801,29 @@
CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL);
// No key/val set, so the device can't be sleepy
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
+ EXPECT_FALSE(nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
// If the interval is the default value, the device is not sleepy
sprintf(key, "SAI");
sprintf(val, "%d", static_cast<int>(CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL.count()));
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, !nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
+ EXPECT_FALSE(nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
// If the interval is greater than the default value, the device is sleepy
strcpy(key, "SAI");
sprintf(val, "%d", static_cast<int>(CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL.count() + 1));
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData);
- NL_TEST_ASSERT(inSuite, nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
+ EXPECT_TRUE(nodeData.resolutionData.IsDeviceTreatedAsSleepy(&defaultMRPConfig));
}
-const nlTest sTests[] = {
- NL_TEST_DEF("TxtFieldKey", TestGetTxtFieldKey), //
- NL_TEST_DEF("TxtFieldKeyCaseInsensitive", TestGetTxtFieldKeyCaseInsensitive), //
- NL_TEST_DEF("TxtFieldProduct", TestGetProduct), //
- NL_TEST_DEF("TxtFieldVendor", TestGetVendor), //
- NL_TEST_DEF("TxtFieldLongDiscriminator", TestGetLongDiscriminator), //
- NL_TEST_DEF("TxtFieldCommissioningMode", TestGetCommissioningMode), //
- NL_TEST_DEF("TxtFieldDeviceType", TestGetDeviceType), //
- NL_TEST_DEF("TxtFieldDeviceName", TestGetDeviceName), //
- NL_TEST_DEF("TxtFieldRotatingDeviceId", TestGetRotatingDeviceId), //
- NL_TEST_DEF("TxtFieldPairingHint", TestGetPairingHint), //
- NL_TEST_DEF("TxtFieldPairingInstruction", TestGetPairingInstruction), //
- NL_TEST_DEF("TxtFieldCommissionerPasscode", TestGetCommissionerPasscode), //
- NL_TEST_DEF("TxtFieldFillDiscoveredNodeDataFromTxt", TestFillDiscoveredNodeDataFromTxt), //
- NL_TEST_DEF("TxtDiscoveredFieldMrpRetryIntervalIdle", TxtFieldSessionIdleInterval<DiscoveredNodeData>),
- NL_TEST_DEF("TxtDiscoveredFieldMrpRetryIntervalActive", TxtFieldSessionActiveInterval<DiscoveredNodeData>),
- NL_TEST_DEF("TxtDiscoveredFieldMrpRetryActiveThreshold", TxtFieldSessionActiveThreshold<DiscoveredNodeData>),
- NL_TEST_DEF("TxtDiscoveredFieldTcpSupport", (TxtFieldTcpSupport<DiscoveredNodeData>) ),
- NL_TEST_DEF("TxtDiscoveredIsICDoperatingAsLIT", (TxtFieldICDoperatesAsLIT<DiscoveredNodeData>) ),
- NL_TEST_DEF("TxtDiscoveredIsDeviceSessionIdle", TestIsDeviceSessionIdle<DiscoveredNodeData>),
- NL_TEST_DEF("TxtDiscoveredIsDeviceSessionActive", TestIsDeviceSessionActive<DiscoveredNodeData>),
- NL_TEST_DEF("TxtResolvedFieldMrpRetryIntervalIdle", TxtFieldSessionIdleInterval<ResolvedNodeData>),
- NL_TEST_DEF("TxtResolvedFieldMrpRetryIntervalActive", TxtFieldSessionActiveInterval<ResolvedNodeData>),
- NL_TEST_DEF("TxtResolvedFieldMrpRetryActiveThreshold", TxtFieldSessionActiveThreshold<ResolvedNodeData>),
- NL_TEST_DEF("TxtResolvedFieldTcpSupport", (TxtFieldTcpSupport<ResolvedNodeData>) ),
- NL_TEST_DEF("TxtResolvedFieldICDoperatingAsLIT", (TxtFieldICDoperatesAsLIT<ResolvedNodeData>) ),
- NL_TEST_DEF("TxtResolvedIsDeviceSessionIdle", TestIsDeviceSessionIdle<ResolvedNodeData>),
- NL_TEST_DEF("TxtResolvedIsDeviceSessionActive", TestIsDeviceSessionActive<ResolvedNodeData>),
- NL_TEST_SENTINEL()
-};
+TEST(TestTxtFields, TxtDiscoveredIsDeviceSessionActive)
+{
+ TestIsDeviceSessionActive<DiscoveredNodeData>();
+}
+
+TEST(TestTxtFields, TxtResolvedIsDeviceSessionActive)
+{
+ TestIsDeviceSessionActive<ResolvedNodeData>();
+}
} // namespace
-
-int TestCHIPTxtFields()
-{
- nlTestSuite theSuite = { "TxtFields", &sTests[0], nullptr, nullptr };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestCHIPTxtFields);
diff --git a/src/test_driver/openiotsdk/unit-tests/test_components.txt b/src/test_driver/openiotsdk/unit-tests/test_components.txt
index e112a8b..5c3dcba 100644
--- a/src/test_driver/openiotsdk/unit-tests/test_components.txt
+++ b/src/test_driver/openiotsdk/unit-tests/test_components.txt
@@ -4,6 +4,7 @@
MinimalMdnsRecordsTests
MinimalMdnsRespondersTests
CoreTests
+MdnsTests
PlatformTests
SystemLayerTests
TestShell
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 13a59af..7806ae3 100644
--- a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt
+++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt
@@ -4,7 +4,6 @@
CredentialsTest
DataModelTests
InetLayerTests
-MdnsTests
MessagingLayerTests
RawTransportTests
RetransmitTests