pw_unit_test migration: lib support batch 3 (#33177)
* pw_unit_test migration: lib support batch 3
* BUILD.gn typo fix
* integrating comments, changing EXPECT_NE to ASSERT_NE when checking pointers for null
diff --git a/src/lib/support/tests/BUILD.gn b/src/lib/support/tests/BUILD.gn
index 585233b..7a19ea2 100644
--- a/src/lib/support/tests/BUILD.gn
+++ b/src/lib/support/tests/BUILD.gn
@@ -25,18 +25,28 @@
test_sources = [
"TestBitMask.cpp",
"TestBufferReader.cpp",
+ "TestBufferWriter.cpp",
+ "TestBytesCircularBuffer.cpp",
"TestBytesToHex.cpp",
"TestDefer.cpp",
+ "TestErrorStr.cpp",
"TestFixedBufferAllocator.cpp",
"TestFold.cpp",
"TestIniEscaping.cpp",
+ "TestPrivateHeap.cpp",
"TestSafeInt.cpp",
"TestSafeString.cpp",
"TestScoped.cpp",
+ "TestScopedBuffer.cpp",
+ "TestSorting.cpp",
"TestSpan.cpp",
"TestStaticSupportSmartPtr.cpp",
+ "TestStringBuilder.cpp",
+ "TestStringSplitter.cpp",
"TestTestPersistentStorageDelegate.cpp",
+ "TestTimeUtils.cpp",
"TestUtf8.cpp",
+ "TestVariant.cpp",
]
sources = []
@@ -64,28 +74,18 @@
output_name = "libSupportTestsNL"
test_sources = [
- "TestBufferWriter.cpp",
- "TestBytesCircularBuffer.cpp",
"TestCHIPCounter.cpp",
"TestCHIPMem.cpp",
"TestCHIPMemString.cpp",
- "TestErrorStr.cpp",
"TestIntrusiveList.cpp",
"TestJsonToTlv.cpp",
"TestJsonToTlvToJson.cpp",
"TestPersistedCounter.cpp",
"TestPool.cpp",
- "TestPrivateHeap.cpp",
- "TestScopedBuffer.cpp",
- "TestSorting.cpp",
"TestStateMachine.cpp",
- "TestStringBuilder.cpp",
- "TestStringSplitter.cpp",
"TestThreadOperationalDataset.cpp",
- "TestTimeUtils.cpp",
"TestTlvJson.cpp",
"TestTlvToJson.cpp",
- "TestVariant.cpp",
"TestZclString.cpp",
]
sources = []
diff --git a/src/lib/support/tests/TestBufferWriter.cpp b/src/lib/support/tests/TestBufferWriter.cpp
index 2e8d187..e5d8951 100644
--- a/src/lib/support/tests/TestBufferWriter.cpp
+++ b/src/lib/support/tests/TestBufferWriter.cpp
@@ -15,9 +15,8 @@
* limitations under the License.
*/
#include <lib/support/BufferWriter.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
namespace {
@@ -77,7 +76,7 @@
using namespace chip::Encoding;
-void TestSpanVersusRegular(nlTestSuite * inSuite, void * inContext)
+TEST(TestBufferWriter, TestSpanVersusRegular)
{
uint8_t buf_regular[5] = { 0, 0, 0, 0, 0 };
uint8_t buf_span[5] = { 0, 0, 0, 0, 0 };
@@ -87,232 +86,213 @@
BufferWriter regular_writer(buf_regular, sizeof(buf_regular));
BufferWriter span_writer(chip::MutableByteSpan{ buf_span });
- NL_TEST_ASSERT(inSuite, regular_writer.Available() == sizeof(buf_regular));
- NL_TEST_ASSERT(inSuite, span_writer.Available() == sizeof(buf_span));
+ EXPECT_EQ(regular_writer.Available(), sizeof(buf_regular));
+ EXPECT_EQ(span_writer.Available(), sizeof(buf_span));
- NL_TEST_ASSERT(inSuite, 0 == memcmp(buf_regular, all_zeroes, sizeof(all_zeroes)));
- NL_TEST_ASSERT(inSuite, 0 == memcmp(buf_span, all_zeroes, sizeof(all_zeroes)));
+ EXPECT_EQ(0, memcmp(buf_regular, all_zeroes, sizeof(all_zeroes)));
+ EXPECT_EQ(0, memcmp(buf_span, all_zeroes, sizeof(all_zeroes)));
- NL_TEST_ASSERT(inSuite, regular_writer.Put(1).Put(2).Put(3).Put(4).Fit());
- NL_TEST_ASSERT(inSuite, span_writer.Put(1).Put(2).Put(3).Put(4).Fit());
+ EXPECT_TRUE(regular_writer.Put(1).Put(2).Put(3).Put(4).Fit());
+ EXPECT_TRUE(span_writer.Put(1).Put(2).Put(3).Put(4).Fit());
- NL_TEST_ASSERT(inSuite, 0 == memcmp(buf_regular, final_expected, sizeof(final_expected)));
- NL_TEST_ASSERT(inSuite, 0 == memcmp(buf_span, final_expected, sizeof(final_expected)));
+ EXPECT_EQ(0, memcmp(buf_regular, final_expected, sizeof(final_expected)));
+ EXPECT_EQ(0, memcmp(buf_span, final_expected, sizeof(final_expected)));
}
-void TestStringWrite(nlTestSuite * inSuite, void * inContext)
+TEST(TestBufferWriter, TestStringWrite)
{
{
BWTest<BufferWriter> bb(2);
bb.Put("hi");
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<BufferWriter> bb(1);
bb.Put("hi");
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(2);
bb.Put("hi");
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(1);
bb.Put("hi");
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(2);
bb.Put("hi");
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(1);
bb.Put("hi");
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
}
-void TestBufferWrite(nlTestSuite * inSuite, void * inContext)
+TEST(TestBufferWriter, TestBufferWrite)
{
{
BWTest<BufferWriter> bb(2);
bb.Put("hithere", 2);
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<BufferWriter> bb(1);
bb.Put("hithere", 2);
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(2);
bb.Put("hithere", 2);
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(1);
bb.Put("hithere", 2);
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(2);
bb.Put("hithere", 2);
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(1);
bb.Put("hithere", 2);
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
}
-void TestPutLittleEndian(nlTestSuite * inSuite, void * inContext)
+TEST(TestBufferWriter, TestPutLittleEndian)
{
{
BWTest<LittleEndian::BufferWriter> bb(2);
bb.Put16('h' + 'i' * 256);
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(4);
bb.Put32(0x01020304);
- NL_TEST_ASSERT(inSuite, bb.expect("\x04\x03\x02\x01", 4, 0));
+ EXPECT_TRUE(bb.expect("\x04\x03\x02\x01", 4, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(8);
bb.Put64(0x0102030405060708);
- NL_TEST_ASSERT(inSuite, bb.expect("\x08\x07\x06\x05\x04\x03\x02\x01", 8, 0));
+ EXPECT_TRUE(bb.expect("\x08\x07\x06\x05\x04\x03\x02\x01", 8, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(3);
bb.EndianPut(0x0102030405060708u, 3);
- NL_TEST_ASSERT(inSuite, bb.expect("\x08\x07\x06", 3, 0));
+ EXPECT_TRUE(bb.expect("\x08\x07\x06", 3, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(4);
bb.PutSigned8(static_cast<int8_t>(-6));
- NL_TEST_ASSERT(inSuite, bb.expect("\xfa", 1, 3));
+ EXPECT_TRUE(bb.expect("\xfa", 1, 3));
}
{
BWTest<LittleEndian::BufferWriter> bb(4);
bb.PutSigned16(static_cast<int16_t>(-2));
- NL_TEST_ASSERT(inSuite, bb.expect("\xfe\xff", 2, 2));
+ EXPECT_TRUE(bb.expect("\xfe\xff", 2, 2));
}
{
BWTest<LittleEndian::BufferWriter> bb(4);
bb.PutSigned32(static_cast<int32_t>(-2));
- NL_TEST_ASSERT(inSuite, bb.expect("\xfe\xff\xff\xff", 4, 0));
+ EXPECT_TRUE(bb.expect("\xfe\xff\xff\xff", 4, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(8);
bb.PutSigned64(static_cast<int64_t>(-2));
- NL_TEST_ASSERT(inSuite, bb.expect("\xfe\xff\xff\xff\xff\xff\xff\xff", 8, 0));
+ EXPECT_TRUE(bb.expect("\xfe\xff\xff\xff\xff\xff\xff\xff", 8, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(7);
bb.PutSigned64(static_cast<int64_t>(-2));
- NL_TEST_ASSERT(inSuite, bb.expect("\xfe\xff\xff\xff\xff\xff\xff", 8, 0));
+ EXPECT_TRUE(bb.expect("\xfe\xff\xff\xff\xff\xff\xff", 8, 0));
}
{
BWTest<LittleEndian::BufferWriter> bb(9);
bb.PutSigned64(static_cast<int64_t>(9223372036854775807LL));
- NL_TEST_ASSERT(inSuite, bb.expect("\xff\xff\xff\xff\xff\xff\xff\x7f", 8, 1));
+ EXPECT_TRUE(bb.expect("\xff\xff\xff\xff\xff\xff\xff\x7f", 8, 1));
}
}
-void TestPutBigEndian(nlTestSuite * inSuite, void * inContext)
+TEST(TestBufferWriter, TestPutBigEndian)
{
{
BWTest<BigEndian::BufferWriter> bb(2);
bb.Put16('i' + 'h' * 256);
- NL_TEST_ASSERT(inSuite, bb.expect("hi", 2, 0));
+ EXPECT_TRUE(bb.expect("hi", 2, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(4);
bb.Put32(0x01020304);
- NL_TEST_ASSERT(inSuite, bb.expect("\x01\x02\x03\x04", 4, 0));
+ EXPECT_TRUE(bb.expect("\x01\x02\x03\x04", 4, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(8);
bb.Put64(0x0102030405060708);
- NL_TEST_ASSERT(inSuite, bb.expect("\x01\x02\x03\x04\x05\x06\x07\x08", 8, 0));
+ EXPECT_TRUE(bb.expect("\x01\x02\x03\x04\x05\x06\x07\x08", 8, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(3);
bb.EndianPut(0x0102030405060708u, 3);
- NL_TEST_ASSERT(inSuite, bb.expect("\x06\x07\x08", 3, 0));
+ EXPECT_TRUE(bb.expect("\x06\x07\x08", 3, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(4);
bb.PutSigned8(static_cast<int8_t>(-6));
- NL_TEST_ASSERT(inSuite, bb.expect("\xfa", 1, 3));
+ EXPECT_TRUE(bb.expect("\xfa", 1, 3));
}
{
BWTest<BigEndian::BufferWriter> bb(4);
bb.PutSigned16(static_cast<int16_t>(-2));
- NL_TEST_ASSERT(inSuite, bb.expect("\xff\xfe", 2, 2));
+ EXPECT_TRUE(bb.expect("\xff\xfe", 2, 2));
}
{
BWTest<BigEndian::BufferWriter> bb(4);
bb.PutSigned32(static_cast<int32_t>(-2));
- NL_TEST_ASSERT(inSuite, bb.expect("\xff\xff\xff\xfe", 4, 0));
+ EXPECT_TRUE(bb.expect("\xff\xff\xff\xfe", 4, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(8);
bb.PutSigned64(static_cast<int64_t>(-2));
- NL_TEST_ASSERT(inSuite, bb.expect("\xff\xff\xff\xff\xff\xff\xff\xfe", 8, 0));
+ EXPECT_TRUE(bb.expect("\xff\xff\xff\xff\xff\xff\xff\xfe", 8, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(7);
bb.PutSigned64(static_cast<int64_t>(-2));
- NL_TEST_ASSERT(inSuite, bb.expect("\xff\xff\xff\xff\xff\xff\xff", 8, 0));
+ EXPECT_TRUE(bb.expect("\xff\xff\xff\xff\xff\xff\xff", 8, 0));
}
{
BWTest<BigEndian::BufferWriter> bb(9);
bb.PutSigned64(static_cast<int64_t>(9223372036854775807LL));
- NL_TEST_ASSERT(inSuite, bb.expect("\x7f\xff\xff\xff\xff\xff\xff\xff", 8, 1));
+ EXPECT_TRUE(bb.expect("\x7f\xff\xff\xff\xff\xff\xff\xff", 8, 1));
}
}
-
-const nlTest sTests[] = {
- NL_TEST_DEF("TestSpanVersusRegular", TestSpanVersusRegular), //
- NL_TEST_DEF("TestStringWrite", TestStringWrite), //
- NL_TEST_DEF("TestBufferWrite", TestBufferWrite), //
- NL_TEST_DEF("TestPutLittleEndian", TestPutLittleEndian), //
- NL_TEST_DEF("TestPutBigEndian", TestPutBigEndian), //
- NL_TEST_SENTINEL() //
-};
-
} // namespace
-
-int TestBufferWriter()
-{
- nlTestSuite theSuite = { "BufferWriter", sTests, nullptr, nullptr };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestBufferWriter)
diff --git a/src/lib/support/tests/TestBytesCircularBuffer.cpp b/src/lib/support/tests/TestBytesCircularBuffer.cpp
index be1576c..90305e0 100644
--- a/src/lib/support/tests/TestBytesCircularBuffer.cpp
+++ b/src/lib/support/tests/TestBytesCircularBuffer.cpp
@@ -23,35 +23,44 @@
#include <string.h>
#include <vector>
-#include <lib/support/BytesCircularBuffer.h>
-#include <lib/support/UnitTestRegistration.h>
+#include <gtest/gtest.h>
-#include <nlunit-test.h>
+#include <lib/support/BytesCircularBuffer.h>
namespace {
using namespace chip;
-void TestPushInvalid(nlTestSuite * inSuite, void * inContext)
+class TestBytesCircularBuffer : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite()
+ {
+ unsigned seed = static_cast<unsigned>(std::time(nullptr));
+ printf("Running " __FILE__ " using seed %d \n", seed);
+ std::srand(seed);
+ }
+};
+
+TEST_F(TestBytesCircularBuffer, TestPushInvalid)
{
uint8_t storage[10];
BytesCircularBuffer buffer(storage, sizeof(storage));
const uint8_t s[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s, static_cast<size_t>(-1))) == CHIP_ERROR_INVALID_ARGUMENT);
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_EQ(buffer.Push(ByteSpan(s, static_cast<size_t>(-1))), CHIP_ERROR_INVALID_ARGUMENT);
+ EXPECT_TRUE(buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s, 8)) == CHIP_ERROR_INVALID_ARGUMENT);
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s, 9)) == CHIP_ERROR_INVALID_ARGUMENT);
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s, 7)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
+ EXPECT_EQ(buffer.Push(ByteSpan(s, 8)), CHIP_ERROR_INVALID_ARGUMENT);
+ EXPECT_TRUE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.Push(ByteSpan(s, 9)), CHIP_ERROR_INVALID_ARGUMENT);
+ EXPECT_TRUE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.Push(ByteSpan(s, 7)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
}
-void RandomPushPop(nlTestSuite * inSuite, void * inContext, BytesCircularBuffer & buffer,
- std::list<std::vector<uint8_t>> & alreadyInBuffer)
+void RandomPushPop(BytesCircularBuffer & buffer, std::list<std::vector<uint8_t>> & alreadyInBuffer)
{
auto randomString = [] {
std::vector<uint8_t> str(static_cast<size_t>(std::rand()) % 8);
@@ -64,21 +73,21 @@
[](auto s, auto str) { return s + str.size() + 2; });
};
- auto verify = [&inSuite, &alreadyInBuffer, &buffer] {
+ auto verify = [&alreadyInBuffer, &buffer] {
if (alreadyInBuffer.empty())
{
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
}
else
{
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
+ EXPECT_FALSE(buffer.IsEmpty());
auto length = alreadyInBuffer.front().size();
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == length);
+ EXPECT_EQ(buffer.GetFrontSize(), length);
std::vector<uint8_t> str(length);
MutableByteSpan readSpan(str.data(), length);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, readSpan.size() == length);
- NL_TEST_ASSERT(inSuite, alreadyInBuffer.front() == str);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(readSpan.size(), length);
+ EXPECT_EQ(alreadyInBuffer.front(), str);
}
};
@@ -90,7 +99,7 @@
if (!buffer.IsEmpty() && std::rand() % 3 == 0)
{
// pop
- NL_TEST_ASSERT(inSuite, buffer.Pop() == CHIP_NO_ERROR);
+ EXPECT_EQ(buffer.Pop(), CHIP_NO_ERROR);
alreadyInBuffer.pop_front();
verify();
@@ -99,7 +108,7 @@
{
// push random string
auto str = randomString();
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(str.data(), str.size())) == CHIP_NO_ERROR);
+ EXPECT_EQ(buffer.Push(ByteSpan(str.data(), str.size())), CHIP_NO_ERROR);
alreadyInBuffer.push_back(str);
while (bufferSize() > 9)
@@ -112,144 +121,144 @@
}
}
-void TestPushPopRandom(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestBytesCircularBuffer, TestPushPopRandom)
{
uint8_t storage[10];
BytesCircularBuffer buffer(storage, sizeof(storage));
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
std::list<std::vector<uint8_t>> alreadyInBuffer;
- RandomPushPop(inSuite, inContext, buffer, alreadyInBuffer);
+ RandomPushPop(buffer, alreadyInBuffer);
}
-void TestPushToJustFull(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestBytesCircularBuffer, TestPushToJustFull)
{
uint8_t storage[10];
// Total space = 9
BytesCircularBuffer buffer(storage, sizeof(storage));
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
const uint8_t s1[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
const uint8_t s2[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
uint8_t o[sizeof(s1)];
MutableByteSpan readSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
// Used = 6, Free = 3
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s1, 4)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 4);
+ EXPECT_EQ(buffer.Push(ByteSpan(s1, 4)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 4u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s1, readSpan.data(), 4) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_FALSE(memcmp(s1, readSpan.data(), 4));
// Used = 9, Free = 0
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s2, 1)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 4);
+ EXPECT_EQ(buffer.Push(ByteSpan(s2, 1)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 4u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s1, readSpan.data(), 4) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_FALSE(memcmp(s1, readSpan.data(), 4));
// Try normal push/pop again
std::list<std::vector<uint8_t>> alreadyInBuffer;
alreadyInBuffer.push_back(std::vector<uint8_t>{ s1[0], s1[1], s1[2], s1[3] });
alreadyInBuffer.push_back(std::vector<uint8_t>{ s2[0] });
- RandomPushPop(inSuite, inContext, buffer, alreadyInBuffer);
+ RandomPushPop(buffer, alreadyInBuffer);
}
-void TestPushToJustFullOverOne(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestBytesCircularBuffer, TestPushToJustFullOverOne)
{
uint8_t storage[10];
// Total space = 9
BytesCircularBuffer buffer(storage, sizeof(storage));
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
const uint8_t s1[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
const uint8_t s2[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
uint8_t o[sizeof(s1)];
MutableByteSpan readSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
// Used = 6, Free = 3
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s1, 4)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 4);
+ EXPECT_EQ(buffer.Push(ByteSpan(s1, 4)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 4u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s1, readSpan.data(), 4) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s1, readSpan.data(), 4), 0);
// Used = 4, Free = 5
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s2, 2)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 2);
+ EXPECT_EQ(buffer.Push(ByteSpan(s2, 2)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 2u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s2, readSpan.data(), 2) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s2, readSpan.data(), 2), 0);
// Try normal push/pop again
std::list<std::vector<uint8_t>> alreadyInBuffer;
alreadyInBuffer.push_back(std::vector<uint8_t>{ s2[0], s2[1] });
- RandomPushPop(inSuite, inContext, buffer, alreadyInBuffer);
+ RandomPushPop(buffer, alreadyInBuffer);
}
-void TestPushWrap(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestBytesCircularBuffer, TestPushWrap)
{
uint8_t storage[10];
// Total space = 9
BytesCircularBuffer buffer(storage, sizeof(storage));
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
const uint8_t s1[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
const uint8_t s2[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
uint8_t o[sizeof(s1)];
MutableByteSpan readSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
// Used = 6, Free = 3
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s1, 4)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 4);
+ EXPECT_EQ(buffer.Push(ByteSpan(s1, 4)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 4u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s1, readSpan.data(), 4) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s1, readSpan.data(), 4), 0);
// Used = 6, Free = 3, s1 was discarded due to lack of storage
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s2, 4)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 4);
+ EXPECT_EQ(buffer.Push(ByteSpan(s2, 4)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 4u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s2, readSpan.data(), 4) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s2, readSpan.data(), 4), 0);
// Used = 9, Free = 0
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s1, 1)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 4);
+ EXPECT_EQ(buffer.Push(ByteSpan(s1, 1)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 4u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s2, readSpan.data(), 4) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s2, readSpan.data(), 4), 0);
// Used = 3, Free = 6
- NL_TEST_ASSERT(inSuite, buffer.Pop() == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 1);
+ EXPECT_EQ(buffer.Pop(), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_TRUE(buffer.GetFrontSize());
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s1, readSpan.data(), 1) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s1, readSpan.data(), 1), 0);
// All freed
- NL_TEST_ASSERT(inSuite, buffer.Pop() == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_EQ(buffer.Pop(), CHIP_NO_ERROR);
+ EXPECT_TRUE(buffer.IsEmpty());
}
-void TestPushWrapStartAtEdge(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestBytesCircularBuffer, TestPushWrapStartAtEdge)
{
uint8_t storage[10];
const uint8_t s1[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
@@ -259,47 +268,47 @@
// Total space = 9
BytesCircularBuffer buffer(storage, sizeof(storage));
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
// Used = 6, Free = 3, mDataStart = 0, mDataEnd = 6
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s1, 4)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 4);
+ EXPECT_EQ(buffer.Push(ByteSpan(s1, 4)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 4u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s1, readSpan.data(), 4) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s1, readSpan.data(), 4), 0);
// Used = 4, Free = 5, mDataStart = 6, mDataEnd = 0 wrap mDataEnd
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s2, 2)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 2);
+ EXPECT_EQ(buffer.Push(ByteSpan(s2, 2)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 2u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s2, readSpan.data(), 2) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s2, readSpan.data(), 2), 0);
// Used = 7, Free = 2, mDataStart = 6, mDataEnd = 3 wrap mDataEnd
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s1, 1)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 2);
+ EXPECT_EQ(buffer.Push(ByteSpan(s1, 1)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 2u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s2, readSpan.data(), 2) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s2, readSpan.data(), 2), 0);
// Used = 3, Free = 6, mDataStart = 0, mDataEnd = 3
- NL_TEST_ASSERT(inSuite, buffer.Pop() == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 1);
+ EXPECT_EQ(buffer.Pop(), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 1u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s1, readSpan.data(), 1) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s1, readSpan.data(), 1), 0);
// Try normal push/pop again
std::list<std::vector<uint8_t>> alreadyInBuffer;
alreadyInBuffer.push_back(std::vector<uint8_t>{ s1[0] });
- RandomPushPop(inSuite, inContext, buffer, alreadyInBuffer);
+ RandomPushPop(buffer, alreadyInBuffer);
}
-void TestPushWrapEndAtEdge(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestBytesCircularBuffer, TestPushWrapEndAtEdge)
{
uint8_t storage[10];
const uint8_t s1[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
@@ -309,31 +318,31 @@
// Total space = 9
BytesCircularBuffer buffer(storage, sizeof(storage));
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
// Used = 6, Free = 3, mDataStart = 0, mDataEnd = 6
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s1, 4)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 4);
+ EXPECT_EQ(buffer.Push(ByteSpan(s1, 4)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 4u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s1, readSpan.data(), 4) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s1, readSpan.data(), 4), 0);
// Used = 4, Free = 5, mDataStart = 6, mDataEnd = 0 wrap mDataEnd
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s2, 2)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 2);
+ EXPECT_EQ(buffer.Push(ByteSpan(s2, 2)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 2u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s2, readSpan.data(), 2) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s2, readSpan.data(), 2), 0);
// Try normal push/pop again
std::list<std::vector<uint8_t>> alreadyInBuffer;
alreadyInBuffer.push_back(std::vector<uint8_t>{ s2[0], s2[1] });
- RandomPushPop(inSuite, inContext, buffer, alreadyInBuffer);
+ RandomPushPop(buffer, alreadyInBuffer);
}
-void TestPushWhenFull(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestBytesCircularBuffer, TestPushWhenFull)
{
uint8_t storage[10];
const uint8_t s1[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
@@ -343,65 +352,31 @@
// Total space = 9
BytesCircularBuffer buffer(storage, sizeof(storage));
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_TRUE(buffer.IsEmpty());
// Used = 9, Free = 0
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s1, 7)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 7);
+ EXPECT_EQ(buffer.Push(ByteSpan(s1, 7)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 7u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s1, readSpan.data(), 7) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s1, readSpan.data(), 7), 0);
// Used = 5, Free = 4
- NL_TEST_ASSERT(inSuite, buffer.Push(ByteSpan(s2, 3)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, !buffer.IsEmpty());
- NL_TEST_ASSERT(inSuite, buffer.GetFrontSize() == 3);
+ EXPECT_EQ(buffer.Push(ByteSpan(s2, 3)), CHIP_NO_ERROR);
+ EXPECT_FALSE(buffer.IsEmpty());
+ EXPECT_EQ(buffer.GetFrontSize(), 3u);
readSpan = MutableByteSpan(o);
- NL_TEST_ASSERT(inSuite, buffer.ReadFront(readSpan) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(s2, readSpan.data(), 3) == 0);
+ EXPECT_EQ(buffer.ReadFront(readSpan), CHIP_NO_ERROR);
+ EXPECT_EQ(memcmp(s2, readSpan.data(), 3), 0);
// All freed
- NL_TEST_ASSERT(inSuite, buffer.Pop() == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, buffer.IsEmpty());
+ EXPECT_EQ(buffer.Pop(), CHIP_NO_ERROR);
+ EXPECT_TRUE(buffer.IsEmpty());
// Try normal push/pop again
std::list<std::vector<uint8_t>> alreadyInBuffer;
- RandomPushPop(inSuite, inContext, buffer, alreadyInBuffer);
-}
-
-int Setup(void * inContext)
-{
- return SUCCESS;
-}
-
-int Teardown(void * inContext)
-{
- return SUCCESS;
+ RandomPushPop(buffer, alreadyInBuffer);
}
} // namespace
-
-#define NL_TEST_DEF_FN(fn) NL_TEST_DEF("Test " #fn, fn)
-/**
- * Test Suite. It lists all the test functions.
- */
-static const nlTest sTests[] = {
- NL_TEST_DEF_FN(TestPushPopRandom), NL_TEST_DEF_FN(TestPushInvalid), NL_TEST_DEF_FN(TestPushToJustFull),
- NL_TEST_DEF_FN(TestPushToJustFullOverOne), NL_TEST_DEF_FN(TestPushWrap), NL_TEST_DEF_FN(TestPushWrapStartAtEdge),
- NL_TEST_DEF_FN(TestPushWrapEndAtEdge), NL_TEST_DEF_FN(TestPushWhenFull), NL_TEST_SENTINEL()
-};
-
-int TestBytesCircularBuffer()
-{
- nlTestSuite theSuite = { "CHIP BytesCircularBuffer tests", &sTests[0], Setup, Teardown };
-
- unsigned seed = static_cast<unsigned>(std::time(nullptr));
- printf("Running " __FILE__ " using seed %d", seed);
- std::srand(seed);
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestBytesCircularBuffer);
diff --git a/src/lib/support/tests/TestErrorStr.cpp b/src/lib/support/tests/TestErrorStr.cpp
index 45133e0..49ae9f5 100644
--- a/src/lib/support/tests/TestErrorStr.cpp
+++ b/src/lib/support/tests/TestErrorStr.cpp
@@ -19,33 +19,31 @@
#include <stdlib.h>
#include <string.h>
+#include <gtest/gtest.h>
+
#include <lib/core/CHIPCore.h>
-
#include <lib/core/ErrorStr.h>
-#include <lib/support/UnitTestRegistration.h>
-
-#include <nlunit-test.h>
using namespace chip;
#if CHIP_CONFIG_ERROR_SOURCE && !CHIP_CONFIG_SHORT_ERROR_STR
-const char * CheckAndSkipSource(nlTestSuite * inSuite, const char * s, const char * file, unsigned int line)
+const char * CheckAndSkipSource(const char * s, const char * file, unsigned int line)
{
size_t fileLength = strlen(file);
- NL_TEST_ASSERT(inSuite, strncmp(s, file, fileLength) == 0);
- NL_TEST_ASSERT(inSuite, s[fileLength] == ':');
+ EXPECT_EQ(strncmp(s, file, fileLength), 0);
+ EXPECT_EQ(s[fileLength], ':');
char * end;
- NL_TEST_ASSERT(inSuite, strtoul(&s[fileLength + 1], &end, 10) == line);
- NL_TEST_ASSERT(inSuite, strncmp(end, ": ", 2) == 0);
+ EXPECT_EQ(strtoul(&s[fileLength + 1], &end, 10), line);
+ EXPECT_EQ(strncmp(end, ": ", 2), 0);
return end + 2;
}
-#define CHECK_AND_SKIP_SOURCE(suite, s) CheckAndSkipSource((suite), (s), __FILE__, __LINE__)
+#define CHECK_AND_SKIP_SOURCE(s) CheckAndSkipSource((s), __FILE__, __LINE__)
#else // CHIP_CONFIG_ERROR_SOURCE && !CHIP_CONFIG_SHORT_ERROR_STR
-#define CHECK_AND_SKIP_SOURCE(suite, s) (s)
+#define CHECK_AND_SKIP_SOURCE(s) (s)
#endif // CHIP_CONFIG_ERROR_SOURCE && !CHIP_CONFIG_SHORT_ERROR_STR
@@ -68,7 +66,7 @@
return true; // means I handled it
}
-static void CheckRegisterDeregisterErrorFormatter(nlTestSuite * inSuite, void * inContext)
+TEST(TestErrorStr, CheckRegisterDeregisterErrorFormatter)
{
static ErrorFormatter falseFormatter = { falseFormat, nullptr };
static ErrorFormatter falseFormatter2 = { falseFormat2, nullptr };
@@ -77,22 +75,22 @@
// simple case
RegisterErrorFormatter(&falseFormatter);
ErrorStr(CHIP_ERROR_INTERNAL);
- NL_TEST_ASSERT(inSuite, falseFormatCalled == 1);
+ EXPECT_EQ(falseFormatCalled, 1);
// reset
falseFormatCalled = 0;
// re-registration should be ignored
RegisterErrorFormatter(&falseFormatter);
ErrorStr(CHIP_ERROR_INTERNAL);
- NL_TEST_ASSERT(inSuite, falseFormatCalled == 1);
+ EXPECT_EQ(falseFormatCalled, 1);
// reset
falseFormatCalled = 0;
// registration of a new handler, nobody handling anything
RegisterErrorFormatter(&falseFormatter2);
ErrorStr(CHIP_ERROR_INTERNAL);
- NL_TEST_ASSERT(inSuite, falseFormatCalled == 1);
- NL_TEST_ASSERT(inSuite, falseFormat2Called == 1);
+ EXPECT_EQ(falseFormatCalled, 1);
+ EXPECT_EQ(falseFormat2Called, 1);
// reset
falseFormatCalled = 0;
falseFormat2Called = 0;
@@ -100,29 +98,29 @@
// registration of a true handler, gets first crack
RegisterErrorFormatter(&trueFormatter);
ErrorStr(CHIP_ERROR_INTERNAL);
- NL_TEST_ASSERT(inSuite, trueFormatCalled == 1);
- NL_TEST_ASSERT(inSuite, falseFormatCalled == 0);
- NL_TEST_ASSERT(inSuite, falseFormat2Called == 0);
+ EXPECT_EQ(trueFormatCalled, 1);
+ EXPECT_EQ(falseFormatCalled, 0);
+ EXPECT_EQ(falseFormat2Called, 0);
// reset
trueFormatCalled = 0;
// deregister true
DeregisterErrorFormatter(&trueFormatter);
ErrorStr(CHIP_ERROR_INTERNAL);
- NL_TEST_ASSERT(inSuite, trueFormatCalled == 0);
- NL_TEST_ASSERT(inSuite, falseFormatCalled == 1);
- NL_TEST_ASSERT(inSuite, falseFormat2Called == 1);
+ EXPECT_EQ(trueFormatCalled, 0);
+ EXPECT_EQ(falseFormatCalled, 1);
+ EXPECT_EQ(falseFormat2Called, 1);
// verify this doesn't crash
DeregisterErrorFormatter(&trueFormatter);
}
-static void CheckNoError(nlTestSuite * inSuite, void * inContext)
+TEST(TestErrorStr, CheckNoError)
{
- NL_TEST_ASSERT(inSuite, strcmp(CHECK_AND_SKIP_SOURCE(inSuite, ErrorStr(CHIP_NO_ERROR)), CHIP_NO_ERROR_STRING) == 0);
+ EXPECT_STREQ(CHECK_AND_SKIP_SOURCE(ErrorStr(CHIP_NO_ERROR)), CHIP_NO_ERROR_STRING);
}
-static void CheckFormatErr(nlTestSuite * inSuite, void * inContext)
+TEST(TestErrorStr, CheckFormatErr)
{
#if CHIP_CONFIG_SHORT_ERROR_STR
@@ -137,63 +135,28 @@
strcpy(buf, "hi");
// shouldn't touch the buffer
FormatError(buf, 0, subsys, CHIP_ERROR_INTERNAL, desc);
- NL_TEST_ASSERT(inSuite, strcmp(buf, "hi") == 0);
+ EXPECT_STREQ(buf, "hi");
// guarantees null termination, doesn't touch past 1st byte
strcpy(buf, "hi");
FormatError(buf, 1, subsys, CHIP_ERROR_INTERNAL, desc);
- NL_TEST_ASSERT(inSuite, strcmp(buf, "") == 0);
- NL_TEST_ASSERT(inSuite, buf[1] == 'i');
+ EXPECT_STREQ(buf, "");
+ EXPECT_EQ(buf[1], 'i');
// whole shebang
FormatError(buf, kBufSize, subsys, CHIP_CORE_ERROR(1), desc);
- NL_TEST_ASSERT(inSuite, strcmp(buf, "subsys Error 0x00000001: desc") == 0);
+ EXPECT_STREQ(buf, "subsys Error 0x00000001: desc");
// skip desc
FormatError(buf, kBufSize, subsys, CHIP_CORE_ERROR(1), nullptr);
- NL_TEST_ASSERT(inSuite, strcmp(buf, "subsys Error 0x00000001") == 0);
+ EXPECT_STREQ(buf, "subsys Error 0x00000001");
// skip subsys
FormatError(buf, kBufSize, nullptr, CHIP_CORE_ERROR(1), desc);
- NL_TEST_ASSERT(inSuite, strcmp(buf, "Error 0x00000001: desc") == 0);
+ EXPECT_STREQ(buf, "Error 0x00000001: desc");
// skip both
FormatError(buf, kBufSize, nullptr, CHIP_CORE_ERROR(1), nullptr);
- NL_TEST_ASSERT(inSuite, strcmp(buf, "Error 0x00000001") == 0);
+ EXPECT_STREQ(buf, "Error 0x00000001");
#endif
}
-
-/**
- * Test Suite. It lists all the test functions.
- */
-
-// clang-format off
-static const nlTest sTests[] =
-{
- NL_TEST_DEF("NoError", CheckNoError),
- NL_TEST_DEF("RegisterDeregisterErrorFormatter", CheckRegisterDeregisterErrorFormatter),
- NL_TEST_DEF("FormatErr", CheckFormatErr),
-
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-int TestErrorStr()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "Test the ErrorStr primitives",
- &sTests[0],
- nullptr,
- nullptr
- };
- // clang-format on
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
-
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestErrorStr)
diff --git a/src/lib/support/tests/TestPrivateHeap.cpp b/src/lib/support/tests/TestPrivateHeap.cpp
index dae8395..f808c16 100644
--- a/src/lib/support/tests/TestPrivateHeap.cpp
+++ b/src/lib/support/tests/TestPrivateHeap.cpp
@@ -16,12 +16,11 @@
* limitations under the License.
*/
-#include <lib/support/PrivateHeap.h>
-#include <lib/support/UnitTestRegistration.h>
-
#include <string.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
+
+#include <lib/support/PrivateHeap.h>
namespace {
@@ -47,14 +46,14 @@
} mHeap;
};
-void SingleHeapAllocAndFree(nlTestSuite * inSuite, void * inContext)
+TEST(TestPrivateHeap, TestSingleHeapAllocAndFree)
{
PrivateHeapAllocator<16 + 2 * kBlockHeaderSize> allocator;
- NL_TEST_ASSERT(inSuite, nullptr == allocator.HeapAlloc(17)); // insufficient size
+ EXPECT_EQ(nullptr, allocator.HeapAlloc(17)); // insufficient size
void * ptr = allocator.HeapAlloc(16);
- NL_TEST_ASSERT(inSuite, nullptr != ptr);
- NL_TEST_ASSERT(inSuite, nullptr == allocator.HeapAlloc(1)); // insufficient size
+ ASSERT_NE(nullptr, ptr);
+ EXPECT_EQ(nullptr, allocator.HeapAlloc(1)); // insufficient size
memset(ptr, 0xab, 16);
allocator.HeapFree(ptr);
@@ -62,25 +61,25 @@
for (size_t i = 1; i < 17; ++i)
{
ptr = allocator.HeapAlloc(i);
- NL_TEST_ASSERT(inSuite, nullptr != ptr);
- NL_TEST_ASSERT(inSuite, nullptr == allocator.HeapAlloc(17 - i)); // insufficient size
+ ASSERT_NE(nullptr, ptr);
+ EXPECT_EQ(nullptr, allocator.HeapAlloc(17 - i)); // insufficient size
allocator.HeapFree(ptr);
}
}
-void SplitHeapAllocAndFree(nlTestSuite * inSuite, void * inContext)
+TEST(TestPrivateHeap, TestSplitHeapAllocAndFree)
{
PrivateHeapAllocator<128> allocator;
// allocator state:
// <HDR-FREE> 96 <HDR-END>
void * p1 = allocator.HeapAlloc(30);
- NL_TEST_ASSERT(inSuite, nullptr != p1);
+ ASSERT_NE(nullptr, p1);
// allocator state:
// <HDR-IN_USE> 32 <HRD-FREE> 48 <HDR-END>
void * p2 = allocator.HeapAlloc(4);
- NL_TEST_ASSERT(inSuite, nullptr != p2);
+ ASSERT_NE(nullptr, p2);
// allocator state:
// <HDR-IN_USE> 32 <HRD-IN_USE> 8 <HDR-FREE> 24 <HDR-END>
@@ -93,20 +92,20 @@
// <HDR-FREE> 96 <HDR-END>
p1 = allocator.HeapAlloc(90);
- NL_TEST_ASSERT(inSuite, nullptr != p1);
+ ASSERT_NE(nullptr, p1);
allocator.HeapFree(p1);
}
-void FreeMergeNext(nlTestSuite * inSuite, void * inContext)
+TEST(TestPrivateHeap, TestFreeMergeNext)
{
PrivateHeapAllocator<5 * 16> allocator;
void * p1 = allocator.HeapAlloc(16);
void * p2 = allocator.HeapAlloc(16);
- NL_TEST_ASSERT(inSuite, nullptr != p1);
- NL_TEST_ASSERT(inSuite, nullptr != p2);
- NL_TEST_ASSERT(inSuite, nullptr == allocator.HeapAlloc(1));
+ ASSERT_NE(nullptr, p1);
+ ASSERT_NE(nullptr, p2);
+ EXPECT_EQ(nullptr, allocator.HeapAlloc(1));
memset(p1, 0xab, 16);
memset(p2, 0xcd, 16);
@@ -116,20 +115,20 @@
allocator.HeapFree(p2);
p1 = allocator.HeapAlloc(3 * 16);
- NL_TEST_ASSERT(inSuite, nullptr != p1);
+ ASSERT_NE(nullptr, p1);
allocator.HeapFree(p1);
}
-void FreeMergePrevious(nlTestSuite * inSuite, void * inContext)
+TEST(TestPrivateHeap, TestFreeMergePrevious)
{
PrivateHeapAllocator<5 * 16> allocator;
void * p1 = allocator.HeapAlloc(16);
void * p2 = allocator.HeapAlloc(16);
- NL_TEST_ASSERT(inSuite, nullptr != p1);
- NL_TEST_ASSERT(inSuite, nullptr != p2);
- NL_TEST_ASSERT(inSuite, nullptr == allocator.HeapAlloc(1));
+ ASSERT_NE(nullptr, p1);
+ ASSERT_NE(nullptr, p2);
+ EXPECT_EQ(nullptr, allocator.HeapAlloc(1));
memset(p1, 0xab, 16);
memset(p2, 0xcd, 16);
@@ -138,11 +137,11 @@
allocator.HeapFree(p2);
allocator.HeapFree(p1);
p1 = allocator.HeapAlloc(3 * 16);
- NL_TEST_ASSERT(inSuite, nullptr != p1);
+ ASSERT_NE(nullptr, p1);
allocator.HeapFree(p1);
}
-void FreeMergePreviousAndNext(nlTestSuite * inSuite, void * inContext)
+TEST(TestPrivateHeap, TestFreeMergePreviousAndNext)
{
PrivateHeapAllocator<7 * 16> allocator;
@@ -151,10 +150,10 @@
void * p2 = allocator.HeapAlloc(16);
void * p3 = allocator.HeapAlloc(16);
- NL_TEST_ASSERT(inSuite, nullptr != p1);
- NL_TEST_ASSERT(inSuite, nullptr != p2);
- NL_TEST_ASSERT(inSuite, nullptr != p3);
- NL_TEST_ASSERT(inSuite, nullptr == allocator.HeapAlloc(1));
+ ASSERT_NE(nullptr, p1);
+ ASSERT_NE(nullptr, p2);
+ ASSERT_NE(nullptr, p3);
+ EXPECT_EQ(nullptr, allocator.HeapAlloc(1));
memset(p1, 0xab, 16);
memset(p2, 0xcd, 16);
@@ -163,16 +162,16 @@
allocator.HeapFree(p1);
allocator.HeapFree(p3);
// we have 2 slots of size 16 available now
- NL_TEST_ASSERT(inSuite, nullptr == allocator.HeapAlloc(17));
+ EXPECT_EQ(nullptr, allocator.HeapAlloc(17));
// Freeing p2 makes enoug space
allocator.HeapFree(p2);
p1 = allocator.HeapAlloc(5 * 16);
- NL_TEST_ASSERT(inSuite, nullptr != p1);
+ ASSERT_NE(nullptr, p1);
allocator.HeapFree(p1);
}
-void MultipleMerge(nlTestSuite * inSuite, void * inContext)
+TEST(TestPrivateHeap, TestMultipleMerge)
{
PrivateHeapAllocator<32 * kBlockHeaderSize> allocator;
@@ -184,19 +183,19 @@
void * p5 = allocator.HeapAlloc(7 * kBlockHeaderSize); // uses up 8 blocks
void * p6 = allocator.HeapAlloc(2 * kBlockHeaderSize); // uses up 2 (last given)
- NL_TEST_ASSERT(inSuite, nullptr != p1);
- NL_TEST_ASSERT(inSuite, nullptr != p2);
- NL_TEST_ASSERT(inSuite, nullptr != p3);
- NL_TEST_ASSERT(inSuite, nullptr != p4);
- NL_TEST_ASSERT(inSuite, nullptr != p5);
- NL_TEST_ASSERT(inSuite, nullptr != p6);
+ ASSERT_NE(nullptr, p1);
+ ASSERT_NE(nullptr, p2);
+ ASSERT_NE(nullptr, p3);
+ ASSERT_NE(nullptr, p4);
+ ASSERT_NE(nullptr, p5);
+ ASSERT_NE(nullptr, p6);
allocator.HeapFree(p3);
allocator.HeapFree(p4);
// 10 blocks available (9 from p3 without HDR and 2 from p4 + HDR)
p3 = allocator.HeapAlloc(10 * kBlockHeaderSize);
- NL_TEST_ASSERT(inSuite, nullptr != p3);
- NL_TEST_ASSERT(inSuite, nullptr == allocator.HeapAlloc(1)); // full
+ ASSERT_NE(nullptr, p3);
+ EXPECT_EQ(nullptr, allocator.HeapAlloc(1)); // full
allocator.HeapFree(p6);
allocator.HeapFree(p5);
@@ -205,11 +204,11 @@
allocator.HeapFree(p1);
p1 = allocator.HeapAlloc(30 * kBlockHeaderSize);
- NL_TEST_ASSERT(inSuite, nullptr != p1);
+ ASSERT_NE(nullptr, p1);
allocator.HeapFree(p1);
}
-void ForwardFreeAndRealloc(nlTestSuite * inSuite, void * inContext)
+TEST(TestPrivateHeap, TestForwardFreeAndRealloc)
{
constexpr int kNumBlocks = 16;
PrivateHeapAllocator<(2 * kNumBlocks + 1) * kBlockHeaderSize> allocator;
@@ -218,7 +217,7 @@
for (auto & ptr : ptrs)
{
ptr = allocator.HeapAlloc(kBlockHeaderSize);
- NL_TEST_ASSERT(inSuite, nullptr != ptr);
+ ASSERT_NE(nullptr, ptr);
memset(ptr, 0xab, kBlockHeaderSize);
}
@@ -232,12 +231,12 @@
allocator.HeapFree(ptrs[i]);
ptrs[0] = allocator.HeapAlloc((1 + 2 * i) * kBlockHeaderSize);
- NL_TEST_ASSERT(inSuite, nullptr != ptrs[0]);
+ ASSERT_NE(nullptr, ptrs[0]);
}
allocator.HeapFree(ptrs[0]);
}
-void BackwardFreeAndRealloc(nlTestSuite * inSuite, void * inContext)
+TEST(TestPrivateHeap, TestBackwardFreeAndRealloc)
{
constexpr int kNumBlocks = 16;
PrivateHeapAllocator<(2 * kNumBlocks + 1) * kBlockHeaderSize> allocator;
@@ -246,7 +245,7 @@
for (auto & ptr : ptrs)
{
ptr = allocator.HeapAlloc(kBlockHeaderSize);
- NL_TEST_ASSERT(inSuite, nullptr != ptr);
+ ASSERT_NE(nullptr, ptr);
memset(ptr, 0xab, kBlockHeaderSize);
}
@@ -260,7 +259,7 @@
allocator.HeapFree(ptrs[kNumBlocks - i - 1]);
ptrs[kNumBlocks - 1] = allocator.HeapAlloc((1 + 2 * i) * kBlockHeaderSize);
- NL_TEST_ASSERT(inSuite, nullptr != ptrs[kNumBlocks - 1]);
+ ASSERT_NE(nullptr, ptrs[kNumBlocks - 1]);
}
allocator.HeapFree(ptrs[kNumBlocks - 1]);
}
@@ -293,71 +292,49 @@
return true;
}
-void Realloc(nlTestSuite * inSuite, void * inContext)
+TEST(TestPrivateHeap, TestRealloc)
{
PrivateHeapAllocator<6 * 16> allocator;
void * p1 = allocator.HeapRealloc(nullptr, 16); // malloc basically
- NL_TEST_ASSERT(inSuite, p1 != nullptr);
+ ASSERT_NE(p1, nullptr);
FillKnownPattern(p1, 16, 11);
void * p2 = allocator.HeapRealloc(p1, 8); // resize, should fit
- NL_TEST_ASSERT(inSuite, p1 == p2);
- NL_TEST_ASSERT(inSuite, IsKnownPattern(p1, 8, 11));
+ EXPECT_EQ(p1, p2);
+ EXPECT_TRUE(IsKnownPattern(p1, 8, 11));
p2 = allocator.HeapRealloc(p1, 16); // resize, should fit
- NL_TEST_ASSERT(inSuite, p1 == p2);
- NL_TEST_ASSERT(inSuite, IsKnownPattern(p2, 8, 11)); // only 8 bytes are guaranteed
+ EXPECT_EQ(p1, p2);
+ EXPECT_TRUE(IsKnownPattern(p2, 8, 11)); // only 8 bytes are guaranteed
FillKnownPattern(p1, 16, 33);
p2 = allocator.HeapRealloc(p1, 32); // resize, does not fit. This frees p1
- NL_TEST_ASSERT(inSuite, p2 != nullptr);
- NL_TEST_ASSERT(inSuite, p2 != p1); // new reallocation occurred
- NL_TEST_ASSERT(inSuite, IsKnownPattern(p2, 16, 33));
+ ASSERT_NE(p2, nullptr);
+ EXPECT_NE(p2, p1); // new reallocation occurred
+ EXPECT_TRUE(IsKnownPattern(p2, 16, 33));
void * p3 = allocator.HeapAlloc(48); // insufficient heap for this
- NL_TEST_ASSERT(inSuite, p3 == nullptr);
+ EXPECT_EQ(p3, nullptr);
p1 = allocator.HeapRealloc(p2, 16); // reallocation does not change block size
- NL_TEST_ASSERT(inSuite, p1 == p2);
+ EXPECT_EQ(p1, p2);
p3 = allocator.HeapAlloc(48); // still insufficient heap for this
- NL_TEST_ASSERT(inSuite, p3 == nullptr);
+ EXPECT_EQ(p3, nullptr);
p2 = allocator.HeapRealloc(p1, 48); // insufficient heap, p1 is NOT freed
- NL_TEST_ASSERT(inSuite, p2 == nullptr);
+ EXPECT_EQ(p2, nullptr);
p2 = allocator.HeapRealloc(p1, 48); // Repeat the test to ensure p1 is not freed
- NL_TEST_ASSERT(inSuite, p2 == nullptr);
+ EXPECT_EQ(p2, nullptr);
allocator.HeapFree(p1);
p3 = allocator.HeapAlloc(48); // above free should have made sufficient space
- NL_TEST_ASSERT(inSuite, p3 != nullptr);
+ ASSERT_NE(p3, nullptr);
allocator.HeapFree(p3);
}
-const nlTest sTests[] = {
- NL_TEST_DEF("SingleHeapAllocAndFree", SingleHeapAllocAndFree), //
- NL_TEST_DEF("SplitHeapAllocAndFree", SplitHeapAllocAndFree), //
- NL_TEST_DEF("FreeMergeNext", FreeMergeNext), //
- NL_TEST_DEF("FreeMergePrevious", FreeMergePrevious), //
- NL_TEST_DEF("FreeMergePreviousAndNext", FreeMergePreviousAndNext), //
- NL_TEST_DEF("MultipleMerge", MultipleMerge), //
- NL_TEST_DEF("ForwardFreeAndRealloc", ForwardFreeAndRealloc), //
- NL_TEST_DEF("BackwardFreeAndRealloc", BackwardFreeAndRealloc), //
- NL_TEST_DEF("Realloc", Realloc), //
- NL_TEST_SENTINEL() //
-};
-
} // namespace
-
-int TestPrivateHeap()
-{
- nlTestSuite theSuite = { "PrivateHeap", sTests, nullptr, nullptr };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestPrivateHeap)
diff --git a/src/lib/support/tests/TestScopedBuffer.cpp b/src/lib/support/tests/TestScopedBuffer.cpp
index 8e77ba7..c7ec072 100644
--- a/src/lib/support/tests/TestScopedBuffer.cpp
+++ b/src/lib/support/tests/TestScopedBuffer.cpp
@@ -16,13 +16,19 @@
* limitations under the License.
*/
-#include <lib/support/ScopedBuffer.h>
-#include <lib/support/UnitTestRegistration.h>
+#include <gtest/gtest.h>
-#include <nlunit-test.h>
+#include <lib/support/ScopedBuffer.h>
namespace {
+class TestScopedBuffer : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
+
class TestCounterMemoryManagement
{
public:
@@ -52,102 +58,66 @@
using TestCounterScopedBuffer = chip::Platform::ScopedMemoryBuffer<char, TestCounterMemoryManagement>;
-void TestAutoFree(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestScopedBuffer, TestAutoFree)
{
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 0);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 0);
{
TestCounterScopedBuffer buffer;
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 0);
- NL_TEST_ASSERT(inSuite, buffer.Alloc(128));
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 1);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 0);
+ EXPECT_TRUE(buffer.Alloc(128));
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 1);
}
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 0);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 0);
}
-void TestFreeDuringAllocs(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestScopedBuffer, TestFreeDuringAllocs)
{
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 0);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 0);
{
TestCounterScopedBuffer buffer;
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 0);
- NL_TEST_ASSERT(inSuite, buffer.Alloc(128));
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 1);
- NL_TEST_ASSERT(inSuite, buffer.Alloc(64));
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 1);
- NL_TEST_ASSERT(inSuite, buffer.Calloc(10));
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 1);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 0);
+ EXPECT_TRUE(buffer.Alloc(128));
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 1);
+ EXPECT_TRUE(buffer.Alloc(64));
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 1);
+ EXPECT_TRUE(buffer.Calloc(10));
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 1);
}
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 0);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 0);
}
-void TestRelease(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestScopedBuffer, TestRelease)
{
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 0);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 0);
void * ptr = nullptr;
{
TestCounterScopedBuffer buffer;
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 0);
- NL_TEST_ASSERT(inSuite, buffer.Alloc(128));
- NL_TEST_ASSERT(inSuite, buffer.Get() != nullptr);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 0);
+ EXPECT_TRUE(buffer.Alloc(128));
+ EXPECT_NE(buffer.Get(), nullptr);
ptr = buffer.Release();
- NL_TEST_ASSERT(inSuite, ptr != nullptr);
- NL_TEST_ASSERT(inSuite, buffer.Get() == nullptr);
+ EXPECT_NE(ptr, nullptr);
+ EXPECT_EQ(buffer.Get(), nullptr);
}
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 1);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 1);
{
TestCounterScopedBuffer buffer;
- NL_TEST_ASSERT(inSuite, buffer.Alloc(128));
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 2);
+ EXPECT_TRUE(buffer.Alloc(128));
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 2);
TestCounterMemoryManagement::MemoryFree(ptr);
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 1);
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 1);
}
- NL_TEST_ASSERT(inSuite, TestCounterMemoryManagement::Counter() == 0);
-}
-
-int Setup(void * inContext)
-{
- CHIP_ERROR error = chip::Platform::MemoryInit();
- if (error != CHIP_NO_ERROR)
- return FAILURE;
- return SUCCESS;
-}
-
-int Teardown(void * inContext)
-{
- chip::Platform::MemoryShutdown();
- return SUCCESS;
+ EXPECT_EQ(TestCounterMemoryManagement::Counter(), 0);
}
} // namespace
-
-#define NL_TEST_DEF_FN(fn) NL_TEST_DEF("Test " #fn, fn)
-/**
- * Test Suite. It lists all the test functions.
- */
-static const nlTest sTests[] = {
- NL_TEST_DEF_FN(TestAutoFree), //
- NL_TEST_DEF_FN(TestFreeDuringAllocs), //
- NL_TEST_DEF_FN(TestRelease), //
- NL_TEST_SENTINEL() //
-};
-
-int TestScopedBuffer()
-{
- nlTestSuite theSuite = { "CHIP ScopedBuffer tests", &sTests[0], Setup, Teardown };
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestScopedBuffer)
diff --git a/src/lib/support/tests/TestSorting.cpp b/src/lib/support/tests/TestSorting.cpp
index 4fd5c09..1d04604 100644
--- a/src/lib/support/tests/TestSorting.cpp
+++ b/src/lib/support/tests/TestSorting.cpp
@@ -20,12 +20,11 @@
#include <array>
#include <stdio.h>
+#include <gtest/gtest.h>
+
#include <lib/support/SortUtils.h>
#include <lib/support/Span.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
-
using namespace chip;
using namespace chip::Sorting;
@@ -71,7 +70,7 @@
}
};
-void DoBasicSortTest(nlTestSuite * inSuite, Sorter & sorter)
+void DoBasicSortTest(Sorter & sorter)
{
Span<Datum> empty_to_sort;
Span<Datum> empty_expected;
@@ -115,7 +114,7 @@
const auto & expected = expected_outs[case_idx];
sorter.Sort(to_sort);
- NL_TEST_ASSERT(inSuite, to_sort.data_equal(expected));
+ EXPECT_TRUE(to_sort.data_equal(expected));
if (!to_sort.data_equal(expected))
{
for (size_t idx = 0; idx < to_sort.size(); ++idx)
@@ -126,44 +125,17 @@
sorted_item.associated_data, expected_item.key, expected_item.associated_data);
}
}
- NL_TEST_ASSERT(inSuite, sorter.compare_count() <= (to_sort.size() * to_sort.size()));
+ EXPECT_LE(sorter.compare_count(), (to_sort.size() * to_sort.size()));
printf("Compare counts: %d\n", static_cast<int>(sorter.compare_count()));
sorter.Reset();
}
}
-void TestBasicSort(nlTestSuite * inSuite, void * inContext)
+TEST(TestSorting, TestBasicSort)
{
printf("Testing insertion sorter.\n");
InsertionSorter insertion_sorter;
- DoBasicSortTest(inSuite, insertion_sorter);
+ DoBasicSortTest(insertion_sorter);
}
-// clang-format off
-static const nlTest sTests[] =
-{
- NL_TEST_DEF("Basic sort tests for custom sort utilities", TestBasicSort),
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
} // namespace
-
-int TestSortUtils()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "Test for SortUtils",
- &sTests[0],
- nullptr,
- nullptr
- };
- // clang-format on
-
- nlTestRunner(&theSuite, nullptr);
-
- return (nlTestRunnerStats(&theSuite));
-}
-
-CHIP_REGISTER_TEST_SUITE(TestSortUtils)
diff --git a/src/lib/support/tests/TestStringBuilder.cpp b/src/lib/support/tests/TestStringBuilder.cpp
index 34d0430..2f4ad51 100644
--- a/src/lib/support/tests/TestStringBuilder.cpp
+++ b/src/lib/support/tests/TestStringBuilder.cpp
@@ -15,78 +15,77 @@
* limitations under the License.
*/
#include <lib/support/StringBuilder.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
namespace {
using namespace chip;
-void TestStringBuilder(nlTestSuite * inSuite, void * inContext)
+TEST(TestStringBuilder, TestStringBuilder)
{
StringBuilder<64> builder;
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "");
builder.Add("foo");
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "foo") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "foo");
builder.Add("bar");
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "foobar") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "foobar");
}
-void TestIntegerAppend(nlTestSuite * inSuite, void * inContext)
+TEST(TestStringBuilder, TestIntegerAppend)
{
StringBuilder<64> builder;
builder.Add("nr: ").Add(1234);
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "nr: 1234") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "nr: 1234");
builder.Add(", ").Add(-22);
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "nr: 1234, -22") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "nr: 1234, -22");
}
-void TestOverflow(nlTestSuite * inSuite, void * inContext)
+TEST(TestStringBuilder, TestOverflow)
{
{
StringBuilder<4> builder;
builder.Add("foo");
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "foo") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "foo");
builder.Add("bar");
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "foo") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "foo");
}
{
StringBuilder<7> builder;
builder.Add("x: ").Add(12345);
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "x: 123") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "x: 123");
}
}
-void TestFormat(nlTestSuite * inSuite, void * inContext)
+TEST(TestStringBuilder, TestFormat)
{
{
StringBuilder<100> builder;
builder.AddFormat("Test: %d Hello %s\n", 123, "world");
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "Test: 123 Hello world\n") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "Test: 123 Hello world\n");
}
{
@@ -94,8 +93,8 @@
builder.AddFormat("Align: %-5s", "abc");
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "Align: abc ") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "Align: abc ");
}
{
@@ -104,20 +103,20 @@
builder.AddFormat("Multi: %d", 1234);
builder.AddFormat(", then 0x%04X", 0xab);
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "Multi: 1234, then 0x00AB") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "Multi: 1234, then 0x00AB");
}
}
-void TestFormatOverflow(nlTestSuite * inSuite, void * inContext)
+TEST(TestStringBuilder, TestFormatOverflow)
{
{
StringBuilder<13> builder;
builder.AddFormat("Test: %d Hello %s\n", 123, "world");
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "Test: 123 He") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "Test: 123 He");
}
{
@@ -125,48 +124,48 @@
builder.AddFormat("%d %d %d %d %d", 1, 2, 3, 4, 1234);
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "1 2 3 4 12") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "1 2 3 4 12");
builder.AddMarkerIfOverflow();
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "1 2 3 4...") == 0);
+ EXPECT_STREQ(builder.c_str(), "1 2 3 4...");
}
{
StringBuilder<11> builder;
builder.AddFormat("%d", 1234);
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "1234") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "1234");
builder.AddFormat("%s", "abc");
- NL_TEST_ASSERT(inSuite, builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "1234abc") == 0);
+ EXPECT_TRUE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "1234abc");
builder.AddMarkerIfOverflow(); // no overflow
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "1234abc") == 0);
+ EXPECT_STREQ(builder.c_str(), "1234abc");
builder.AddFormat("%08x", 0x123456);
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "1234abc001") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "1234abc001");
builder.AddMarkerIfOverflow();
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "1234abc...") == 0);
+ EXPECT_STREQ(builder.c_str(), "1234abc...");
}
}
-void TestOverflowMarker(nlTestSuite * inSuite, void * inContext)
+TEST(TestStringBuilder, TestOverflowMarker)
{
{
StringBuilder<1> builder; // useless builder, but ok
builder.Add("abc123");
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "");
builder.AddMarkerIfOverflow();
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "") == 0);
+ EXPECT_STREQ(builder.c_str(), "");
}
{
@@ -174,11 +173,11 @@
builder.Add("abc123");
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "a") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "a");
builder.AddMarkerIfOverflow();
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), ".") == 0);
+ EXPECT_STREQ(builder.c_str(), ".");
}
{
@@ -186,11 +185,11 @@
builder.Add("abc123");
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "ab") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "ab");
builder.AddMarkerIfOverflow();
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "..") == 0);
+ EXPECT_STREQ(builder.c_str(), "..");
}
{
@@ -198,11 +197,11 @@
builder.Add("abc123");
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "abc") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "abc");
builder.AddMarkerIfOverflow();
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "...") == 0);
+ EXPECT_STREQ(builder.c_str(), "...");
}
{
@@ -210,31 +209,12 @@
builder.Add("abc123");
- NL_TEST_ASSERT(inSuite, !builder.Fit());
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "abc1") == 0);
+ EXPECT_FALSE(builder.Fit());
+ EXPECT_STREQ(builder.c_str(), "abc1");
builder.AddMarkerIfOverflow();
- NL_TEST_ASSERT(inSuite, strcmp(builder.c_str(), "a...") == 0);
+ EXPECT_STREQ(builder.c_str(), "a...");
}
}
-const nlTest sTests[] = {
- NL_TEST_DEF("TestStringBuilder", TestStringBuilder), //
- NL_TEST_DEF("TestIntegerAppend", TestIntegerAppend), //
- NL_TEST_DEF("TestOverflow", TestOverflow), //
- NL_TEST_DEF("TestFormat", TestFormat), //
- NL_TEST_DEF("TestFormatOverflow", TestFormatOverflow), //
- NL_TEST_DEF("TestOverflowMarker", TestOverflowMarker), //
- NL_TEST_SENTINEL() //
-};
-
} // namespace
-
-int TestStringBuilder()
-{
- nlTestSuite theSuite = { "StringBuilder", sTests, nullptr, nullptr };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestStringBuilder)
diff --git a/src/lib/support/tests/TestStringSplitter.cpp b/src/lib/support/tests/TestStringSplitter.cpp
index 50b0ec0..c8dd1e9 100644
--- a/src/lib/support/tests/TestStringSplitter.cpp
+++ b/src/lib/support/tests/TestStringSplitter.cpp
@@ -15,15 +15,13 @@
* limitations under the License.
*/
#include <lib/support/StringSplitter.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
-
+#include <gtest/gtest.h>
namespace {
using namespace chip;
-void TestStrdupSplitter(nlTestSuite * inSuite, void * inContext)
+TEST(TestStringSplitter, TestStrdupSplitter)
{
CharSpan out;
@@ -32,122 +30,107 @@
StringSplitter splitter("", ',');
// next stays at nullptr
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data() == nullptr);
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data() == nullptr);
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data() == nullptr);
+ EXPECT_FALSE(splitter.Next(out));
+ EXPECT_EQ(out.data(), nullptr);
+ EXPECT_FALSE(splitter.Next(out));
+ EXPECT_EQ(out.data(), nullptr);
+ EXPECT_FALSE(splitter.Next(out));
+ EXPECT_EQ(out.data(), nullptr);
}
// single item
{
StringSplitter splitter("single", ',');
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("single"_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("single"_span));
// next stays at nullptr also after valid data
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data() == nullptr);
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data() == nullptr);
+ EXPECT_FALSE(splitter.Next(out));
+ EXPECT_EQ(out.data(), nullptr);
+ EXPECT_FALSE(splitter.Next(out));
+ EXPECT_EQ(out.data(), nullptr);
}
// multi-item
{
StringSplitter splitter("one,two,three", ',');
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("one"_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("two"_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("three"_span));
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data() == nullptr);
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("one"_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("two"_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("three"_span));
+ EXPECT_FALSE(splitter.Next(out));
+ EXPECT_EQ(out.data(), nullptr);
}
// mixed
{
StringSplitter splitter("a**bc*d,e*f", '*');
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("a"_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("bc"_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("d,e"_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("f"_span));
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("a"_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal(""_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("bc"_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("d,e"_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("f"_span));
+ EXPECT_FALSE(splitter.Next(out));
}
// some edge cases
{
StringSplitter splitter(",", ',');
// Note that even though "" is nullptr right away, "," becomes two empty strings
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal(""_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal(""_span));
+ EXPECT_FALSE(splitter.Next(out));
}
{
StringSplitter splitter("log,", ',');
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("log"_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("log"_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal(""_span));
+ EXPECT_FALSE(splitter.Next(out));
}
{
StringSplitter splitter(",log", ',');
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal("log"_span));
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal(""_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal("log"_span));
+ EXPECT_FALSE(splitter.Next(out));
}
{
StringSplitter splitter(",,,", ',');
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
- NL_TEST_ASSERT(inSuite, splitter.Next(out));
- NL_TEST_ASSERT(inSuite, out.data_equal(""_span));
- NL_TEST_ASSERT(inSuite, !splitter.Next(out));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal(""_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal(""_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal(""_span));
+ EXPECT_TRUE(splitter.Next(out));
+ EXPECT_TRUE(out.data_equal(""_span));
+ EXPECT_FALSE(splitter.Next(out));
}
}
-void TestNullResilience(nlTestSuite * inSuite, void * inContext)
+TEST(TestStringSplitter, TestNullResilience)
{
{
StringSplitter splitter(nullptr, ',');
CharSpan span;
- NL_TEST_ASSERT(inSuite, !splitter.Next(span));
- NL_TEST_ASSERT(inSuite, span.data() == nullptr);
+ EXPECT_FALSE(splitter.Next(span));
+ EXPECT_EQ(span.data(), nullptr);
}
}
-const nlTest sTests[] = {
- NL_TEST_DEF("TestSplitter", TestStrdupSplitter), //
- NL_TEST_DEF("TestNullResilience", TestNullResilience), //
- NL_TEST_SENTINEL() //
-};
-
} // namespace
-
-int TestStringSplitter()
-{
- nlTestSuite theSuite = { "StringSplitter", sTests, nullptr, nullptr };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestStringSplitter)
diff --git a/src/lib/support/tests/TestTimeUtils.cpp b/src/lib/support/tests/TestTimeUtils.cpp
index cc0f8bb..7d0a697 100644
--- a/src/lib/support/tests/TestTimeUtils.cpp
+++ b/src/lib/support/tests/TestTimeUtils.cpp
@@ -29,10 +29,9 @@
#include <stdlib.h>
#include <time.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
#include <lib/support/TimeUtils.h>
-#include <lib/support/UnitTestRegistration.h>
#include <lib/support/logging/CHIPLogging.h>
using namespace chip;
@@ -44,7 +43,7 @@
{ \
ChipLogError(NotSpecified, "%s", (message)); \
} \
- NL_TEST_ASSERT(inSuite, (cond)); \
+ EXPECT_TRUE((cond)); \
\
if (!(cond)) \
return; \
@@ -800,7 +799,7 @@
};
// clang-format on
-void TestOrdinalDateConversion(nlTestSuite * inSuite, void * inContext)
+TEST(TestTimeUtils, TestOrdinalDateConversion)
{
for (uint16_t year = 0; year <= 10000; year++)
{
@@ -823,7 +822,7 @@
}
}
-void TestDaysSinceEpochConversion(nlTestSuite * inSuite, void * inContext)
+TEST(TestTimeUtils, TestDaysSinceEpochConversion)
{
uint32_t daysSinceEpoch = 0;
@@ -870,7 +869,7 @@
}
}
-void TestSecondsSinceEpochConversion(nlTestSuite * inSuite, void * inContext)
+TEST(TestTimeUtils, TestSecondsSinceEpochConversion)
{
uint32_t daysSinceEpoch = 0;
uint32_t timeOfDay = 0; // in seconds
@@ -949,7 +948,7 @@
}
}
-void TestChipEpochTimeConversion(nlTestSuite * inSuite, void * inContext)
+TEST(TestTimeUtils, TestChipEpochTimeConversion)
{
uint32_t daysSinceEpoch = 0;
uint32_t timeOfDay = 0; // in seconds
@@ -1022,54 +1021,22 @@
}
}
-void TestChipEpochTimeEdgeConditions(nlTestSuite * inSuite, void * inContext)
+TEST(TestTimeUtils, TestChipEpochTimeEdgeConditions)
{
uint32_t chip_epoch_time_sec = 0;
- NL_TEST_ASSERT(inSuite, UnixEpochToChipEpochTime(INT32_MAX, chip_epoch_time_sec));
- NL_TEST_ASSERT(inSuite, chip_epoch_time_sec < INT32_MAX);
+ EXPECT_TRUE(UnixEpochToChipEpochTime(UINT32_MAX, chip_epoch_time_sec));
+ EXPECT_LT(chip_epoch_time_sec, UINT32_MAX);
// TODO(#30990): Bring back tests when implementation fixed.
#if 0
constexpr uint32_t kUnix2000Jan1 = 946702800; // Start of CHIP epoch.
- chip_epoch_time_sec = INT32_MAX;
- NL_TEST_ASSERT(inSuite, UnixEpochToChipEpochTime(kUnix2000Jan1, chip_epoch_time_sec) == true);
- NL_TEST_ASSERT(inSuite, chip_epoch_time_sec == 0);
+ chip_epoch_time_sec = UINT32_MAX;
+ EXPECT_EQ(UnixEpochToChipEpochTime(kUnix2000Jan1, chip_epoch_time_sec), true);
+ EXPECT_EQ(chip_epoch_time_sec, 0u);
chip_epoch_time_sec = 0;
- NL_TEST_ASSERT(inSuite, UnixEpochToChipEpochTime(kUnix2000Jan1 - 1, chip_epoch_time_sec) == false);
+ EXPECT_EQ(UnixEpochToChipEpochTime(kUnix2000Jan1 - 1, chip_epoch_time_sec), false);
#endif
}
-
-// clang-format off
-static const nlTest g_all_tests[] =
-{
- NL_TEST_DEF("Test Ordinal Date conversion", TestOrdinalDateConversion),
- NL_TEST_DEF("Test DaysSinceEpoch conversion", TestDaysSinceEpochConversion),
- NL_TEST_DEF("Test SecondsSinceEpoch conversion", TestSecondsSinceEpochConversion),
- NL_TEST_DEF("Test ChipEpochTime conversion", TestChipEpochTimeConversion),
- NL_TEST_DEF("Test edge conditions of time conversions", TestChipEpochTimeEdgeConditions),
-
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-int TestTimeUtils()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "Test common time utilities",
- &g_all_tests[0],
- nullptr,
- nullptr
- };
- // clang-format on
-
- nlTestRunner(&theSuite, nullptr);
-
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestTimeUtils);
diff --git a/src/lib/support/tests/TestVariant.cpp b/src/lib/support/tests/TestVariant.cpp
index 10cb9d4..cd51d25 100644
--- a/src/lib/support/tests/TestVariant.cpp
+++ b/src/lib/support/tests/TestVariant.cpp
@@ -18,10 +18,9 @@
#include <functional>
-#include <lib/support/UnitTestRegistration.h>
-#include <lib/support/Variant.h>
+#include <gtest/gtest.h>
-#include <nlunit-test.h>
+#include <lib/support/Variant.h>
namespace {
@@ -73,159 +72,159 @@
using namespace chip;
-void TestVariantSimple(nlTestSuite * inSuite, void * inContext)
+TEST(TestVariant, TestVariantSimple)
{
Variant<Simple, Pod> v;
- NL_TEST_ASSERT(inSuite, !v.Valid());
+ EXPECT_FALSE(v.Valid());
v.Set<Pod>(5, 10);
- NL_TEST_ASSERT(inSuite, v.Valid());
- NL_TEST_ASSERT(inSuite, v.Is<Pod>());
- NL_TEST_ASSERT(inSuite, v.Get<Pod>().m1 == 5);
- NL_TEST_ASSERT(inSuite, v.Get<Pod>().m2 == 10);
+ EXPECT_TRUE(v.Valid());
+ EXPECT_TRUE(v.Is<Pod>());
+ EXPECT_EQ(v.Get<Pod>().m1, 5);
+ EXPECT_EQ(v.Get<Pod>().m2, 10);
}
-void TestVariantMovable(nlTestSuite * inSuite, void * inContext)
+TEST(TestVariant, TestVariantMovable)
{
Variant<Simple, Movable> v;
v.Set<Simple>();
v.Set<Movable>(Movable{ 5, 10 });
- NL_TEST_ASSERT(inSuite, v.Get<Movable>().m1 == 5);
- NL_TEST_ASSERT(inSuite, v.Get<Movable>().m2 == 10);
+ EXPECT_EQ(v.Get<Movable>().m1, 5);
+ EXPECT_EQ(v.Get<Movable>().m2, 10);
auto & m = v.Get<Movable>();
- NL_TEST_ASSERT(inSuite, m.m1 == 5);
- NL_TEST_ASSERT(inSuite, m.m2 == 10);
+ EXPECT_EQ(m.m1, 5);
+ EXPECT_EQ(m.m2, 10);
v.Set<Simple>();
}
-void TestVariantCtorDtor(nlTestSuite * inSuite, void * inContext)
+TEST(TestVariant, TestVariantCtorDtor)
{
{
Variant<Simple, Count> v;
- NL_TEST_ASSERT(inSuite, Count::created == 0);
+ EXPECT_EQ(Count::created, 0);
v.Set<Simple>();
- NL_TEST_ASSERT(inSuite, Count::created == 0);
+ EXPECT_EQ(Count::created, 0);
v.Get<Simple>();
- NL_TEST_ASSERT(inSuite, Count::created == 0);
+ EXPECT_EQ(Count::created, 0);
}
{
Variant<Simple, Count> v;
- NL_TEST_ASSERT(inSuite, Count::created == 0);
+ EXPECT_EQ(Count::created, 0);
v.Set<Simple>();
- NL_TEST_ASSERT(inSuite, Count::created == 0);
+ EXPECT_EQ(Count::created, 0);
v.Set<Count>();
- NL_TEST_ASSERT(inSuite, Count::created == 1);
- NL_TEST_ASSERT(inSuite, Count::destroyed == 0);
+ EXPECT_EQ(Count::created, 1);
+ EXPECT_EQ(Count::destroyed, 0);
v.Get<Count>();
- NL_TEST_ASSERT(inSuite, Count::created == 1);
- NL_TEST_ASSERT(inSuite, Count::destroyed == 0);
+ EXPECT_EQ(Count::created, 1);
+ EXPECT_EQ(Count::destroyed, 0);
v.Set<Simple>();
- NL_TEST_ASSERT(inSuite, Count::created == 1);
- NL_TEST_ASSERT(inSuite, Count::destroyed == 1);
+ EXPECT_EQ(Count::created, 1);
+ EXPECT_EQ(Count::destroyed, 1);
v.Set<Count>();
- NL_TEST_ASSERT(inSuite, Count::created == 2);
- NL_TEST_ASSERT(inSuite, Count::destroyed == 1);
+ EXPECT_EQ(Count::created, 2);
+ EXPECT_EQ(Count::destroyed, 1);
}
- NL_TEST_ASSERT(inSuite, Count::destroyed == 2);
+ EXPECT_EQ(Count::destroyed, 2);
{
Variant<Simple, Count> v1;
v1.Set<Count>();
Variant<Simple, Count> v2(v1);
}
- NL_TEST_ASSERT(inSuite, Count::created == 4);
- NL_TEST_ASSERT(inSuite, Count::destroyed == 4);
+ EXPECT_EQ(Count::created, 4);
+ EXPECT_EQ(Count::destroyed, 4);
{
Variant<Simple, Count> v1;
v1.Set<Count>();
Variant<Simple, Count> v2(std::move(v1));
}
- NL_TEST_ASSERT(inSuite, Count::created == 6);
- NL_TEST_ASSERT(inSuite, Count::destroyed == 6);
+ EXPECT_EQ(Count::created, 6);
+ EXPECT_EQ(Count::destroyed, 6);
{
Variant<Simple, Count> v1, v2;
v1.Set<Count>();
v2 = v1;
}
- NL_TEST_ASSERT(inSuite, Count::created == 8);
- NL_TEST_ASSERT(inSuite, Count::destroyed == 8);
+ EXPECT_EQ(Count::created, 8);
+ EXPECT_EQ(Count::destroyed, 8);
{
Variant<Simple, Count> v1, v2;
v1.Set<Count>();
v2 = std::move(v1);
}
- NL_TEST_ASSERT(inSuite, Count::created == 10);
- NL_TEST_ASSERT(inSuite, Count::destroyed == 10);
+ EXPECT_EQ(Count::created, 10);
+ EXPECT_EQ(Count::destroyed, 10);
}
-void TestVariantCopy(nlTestSuite * inSuite, void * inContext)
+TEST(TestVariant, TestVariantCopy)
{
Variant<Simple, Pod> v1;
v1.Set<Pod>(5, 10);
Variant<Simple, Pod> v2 = v1;
- NL_TEST_ASSERT(inSuite, v1.Valid());
- NL_TEST_ASSERT(inSuite, v1.Get<Pod>().m1 == 5);
- NL_TEST_ASSERT(inSuite, v1.Get<Pod>().m2 == 10);
- NL_TEST_ASSERT(inSuite, v2.Valid());
- NL_TEST_ASSERT(inSuite, v2.Get<Pod>().m1 == 5);
- NL_TEST_ASSERT(inSuite, v2.Get<Pod>().m2 == 10);
+ EXPECT_TRUE(v1.Valid());
+ EXPECT_EQ(v1.Get<Pod>().m1, 5);
+ EXPECT_EQ(v1.Get<Pod>().m2, 10);
+ EXPECT_TRUE(v2.Valid());
+ EXPECT_EQ(v2.Get<Pod>().m1, 5);
+ EXPECT_EQ(v2.Get<Pod>().m2, 10);
}
-void TestVariantMove(nlTestSuite * inSuite, void * inContext)
+TEST(TestVariant, TestVariantMove)
{
Variant<Simple, Movable> v1;
v1.Set<Movable>(5, 10);
Variant<Simple, Movable> v2 = std::move(v1);
- NL_TEST_ASSERT(inSuite, !v1.Valid()); // NOLINT(bugprone-use-after-move)
- NL_TEST_ASSERT(inSuite, v2.Valid());
- NL_TEST_ASSERT(inSuite, v2.Get<Movable>().m1 == 5);
- NL_TEST_ASSERT(inSuite, v2.Get<Movable>().m2 == 10);
+ EXPECT_FALSE(v1.Valid()); // NOLINT(bugprone-use-after-move)
+ EXPECT_TRUE(v2.Valid());
+ EXPECT_EQ(v2.Get<Movable>().m1, 5);
+ EXPECT_EQ(v2.Get<Movable>().m2, 10);
}
-void TestVariantCopyAssign(nlTestSuite * inSuite, void * inContext)
+TEST(TestVariant, TestVariantCopyAssign)
{
Variant<Simple, Pod> v1;
Variant<Simple, Pod> v2;
v1.Set<Pod>(5, 10);
v2 = v1;
- NL_TEST_ASSERT(inSuite, v1.Valid());
- NL_TEST_ASSERT(inSuite, v1.Get<Pod>().m1 == 5);
- NL_TEST_ASSERT(inSuite, v1.Get<Pod>().m2 == 10);
- NL_TEST_ASSERT(inSuite, v2.Valid());
- NL_TEST_ASSERT(inSuite, v2.Get<Pod>().m1 == 5);
- NL_TEST_ASSERT(inSuite, v2.Get<Pod>().m2 == 10);
+ EXPECT_TRUE(v1.Valid());
+ EXPECT_EQ(v1.Get<Pod>().m1, 5);
+ EXPECT_EQ(v1.Get<Pod>().m2, 10);
+ EXPECT_TRUE(v2.Valid());
+ EXPECT_EQ(v2.Get<Pod>().m1, 5);
+ EXPECT_EQ(v2.Get<Pod>().m2, 10);
}
-void TestVariantMoveAssign(nlTestSuite * inSuite, void * inContext)
+TEST(TestVariant, TestVariantMoveAssign)
{
Variant<Simple, Pod> v1;
Variant<Simple, Pod> v2;
v1.Set<Pod>(5, 10);
v2 = std::move(v1);
- NL_TEST_ASSERT(inSuite, !v1.Valid()); // NOLINT(bugprone-use-after-move)
- NL_TEST_ASSERT(inSuite, v2.Valid());
- NL_TEST_ASSERT(inSuite, v2.Get<Pod>().m1 == 5);
- NL_TEST_ASSERT(inSuite, v2.Get<Pod>().m2 == 10);
+ EXPECT_FALSE(v1.Valid()); // NOLINT(bugprone-use-after-move)
+ EXPECT_TRUE(v2.Valid());
+ EXPECT_EQ(v2.Get<Pod>().m1, 5);
+ EXPECT_EQ(v2.Get<Pod>().m2, 10);
}
-void TestVariantInPlace(nlTestSuite * inSuite, void * inContext)
+TEST(TestVariant, TestVariantInPlace)
{
int i = 0;
Variant<std::reference_wrapper<int>> v1 = Variant<std::reference_wrapper<int>>(InPlaceTemplate<std::reference_wrapper<int>>, i);
- NL_TEST_ASSERT(inSuite, v1.Valid());
- NL_TEST_ASSERT(inSuite, v1.Is<std::reference_wrapper<int>>());
- NL_TEST_ASSERT(inSuite, &v1.Get<std::reference_wrapper<int>>().get() == &i);
+ EXPECT_TRUE(v1.Valid());
+ EXPECT_TRUE(v1.Is<std::reference_wrapper<int>>());
+ EXPECT_EQ(&v1.Get<std::reference_wrapper<int>>().get(), &i);
Variant<std::reference_wrapper<int>> v2 = Variant<std::reference_wrapper<int>>::Create<std::reference_wrapper<int>>(i);
- NL_TEST_ASSERT(inSuite, v2.Valid());
- NL_TEST_ASSERT(inSuite, v2.Is<std::reference_wrapper<int>>());
- NL_TEST_ASSERT(inSuite, &v2.Get<std::reference_wrapper<int>>().get() == &i);
+ EXPECT_TRUE(v2.Valid());
+ EXPECT_TRUE(v2.Is<std::reference_wrapper<int>>());
+ EXPECT_EQ(&v2.Get<std::reference_wrapper<int>>().get(), &i);
}
-void TestVariantCompare(nlTestSuite * inSuite, void * inContext)
+TEST(TestVariant, TestVariantCompare)
{
Variant<Simple, Pod> v0;
Variant<Simple, Pod> v1;
@@ -238,66 +237,35 @@
v3.Set<Pod>(5, 10);
v4.Set<Pod>(5, 11);
- NL_TEST_ASSERT(inSuite, (v0 == v0));
- NL_TEST_ASSERT(inSuite, !(v0 == v1));
- NL_TEST_ASSERT(inSuite, !(v0 == v2));
- NL_TEST_ASSERT(inSuite, !(v0 == v3));
- NL_TEST_ASSERT(inSuite, !(v0 == v4));
+ EXPECT_TRUE(v0 == v0);
+ EXPECT_FALSE(v0 == v1);
+ EXPECT_FALSE(v0 == v2);
+ EXPECT_FALSE(v0 == v3);
+ EXPECT_FALSE(v0 == v4);
- NL_TEST_ASSERT(inSuite, !(v1 == v0));
- NL_TEST_ASSERT(inSuite, (v1 == v1));
- NL_TEST_ASSERT(inSuite, !(v1 == v2));
- NL_TEST_ASSERT(inSuite, !(v1 == v3));
- NL_TEST_ASSERT(inSuite, !(v1 == v4));
+ EXPECT_FALSE(v1 == v0);
+ EXPECT_TRUE(v1 == v1);
+ EXPECT_FALSE(v1 == v2);
+ EXPECT_FALSE(v1 == v3);
+ EXPECT_FALSE(v1 == v4);
- NL_TEST_ASSERT(inSuite, !(v2 == v0));
- NL_TEST_ASSERT(inSuite, !(v2 == v1));
- NL_TEST_ASSERT(inSuite, (v2 == v2));
- NL_TEST_ASSERT(inSuite, (v2 == v3));
- NL_TEST_ASSERT(inSuite, !(v2 == v4));
+ EXPECT_FALSE(v2 == v0);
+ EXPECT_FALSE(v2 == v1);
+ EXPECT_TRUE(v2 == v2);
+ EXPECT_TRUE(v2 == v3);
+ EXPECT_FALSE(v2 == v4);
- NL_TEST_ASSERT(inSuite, !(v3 == v0));
- NL_TEST_ASSERT(inSuite, !(v3 == v1));
- NL_TEST_ASSERT(inSuite, (v3 == v2));
- NL_TEST_ASSERT(inSuite, (v3 == v3));
- NL_TEST_ASSERT(inSuite, !(v3 == v4));
+ EXPECT_FALSE(v3 == v0);
+ EXPECT_FALSE(v3 == v1);
+ EXPECT_TRUE(v3 == v2);
+ EXPECT_TRUE(v3 == v3);
+ EXPECT_FALSE(v3 == v4);
- NL_TEST_ASSERT(inSuite, !(v4 == v0));
- NL_TEST_ASSERT(inSuite, !(v4 == v1));
- NL_TEST_ASSERT(inSuite, !(v4 == v2));
- NL_TEST_ASSERT(inSuite, !(v4 == v3));
- NL_TEST_ASSERT(inSuite, (v4 == v4));
-}
-
-int Setup(void * inContext)
-{
- return SUCCESS;
-}
-
-int Teardown(void * inContext)
-{
- return SUCCESS;
+ EXPECT_FALSE(v4 == v0);
+ EXPECT_FALSE(v4 == v1);
+ EXPECT_FALSE(v4 == v2);
+ EXPECT_FALSE(v4 == v3);
+ EXPECT_TRUE(v4 == v4);
}
} // namespace
-
-#define NL_TEST_DEF_FN(fn) NL_TEST_DEF("Test " #fn, fn)
-/**
- * Test Suite. It lists all the test functions.
- */
-static const nlTest sTests[] = { NL_TEST_DEF_FN(TestVariantSimple), NL_TEST_DEF_FN(TestVariantMovable),
- NL_TEST_DEF_FN(TestVariantCtorDtor), NL_TEST_DEF_FN(TestVariantCopy),
- NL_TEST_DEF_FN(TestVariantMove), NL_TEST_DEF_FN(TestVariantCopyAssign),
- NL_TEST_DEF_FN(TestVariantMoveAssign), NL_TEST_DEF_FN(TestVariantInPlace),
- NL_TEST_DEF_FN(TestVariantCompare), NL_TEST_SENTINEL() };
-
-int TestVariant()
-{
- nlTestSuite theSuite = { "CHIP Variant tests", &sTests[0], Setup, Teardown };
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestVariant);