pw_unit_test migration: lib support batch 4 (#33199)
* pw_unit_test migration: lib support batch 4
* fix merge error BUILD.gn
diff --git a/src/lib/support/tests/BUILD.gn b/src/lib/support/tests/BUILD.gn
index 6a7c790..4854020 100644
--- a/src/lib/support/tests/BUILD.gn
+++ b/src/lib/support/tests/BUILD.gn
@@ -29,11 +29,16 @@
"TestBytesCircularBuffer.cpp",
"TestBytesToHex.cpp",
"TestCHIPCounter.cpp",
+ "TestCHIPMem.cpp",
+ "TestCHIPMemString.cpp",
"TestDefer.cpp",
"TestErrorStr.cpp",
"TestFixedBufferAllocator.cpp",
"TestFold.cpp",
"TestIniEscaping.cpp",
+ "TestIntrusiveList.cpp",
+ "TestJsonToTlv.cpp",
+ "TestJsonToTlvToJson.cpp",
"TestPersistedCounter.cpp",
"TestPrivateHeap.cpp",
"TestSafeInt.cpp",
@@ -47,8 +52,11 @@
"TestStringSplitter.cpp",
"TestTestPersistentStorageDelegate.cpp",
"TestTimeUtils.cpp",
+ "TestTlvJson.cpp",
+ "TestTlvToJson.cpp",
"TestUtf8.cpp",
"TestVariant.cpp",
+ "TestZclString.cpp",
]
sources = []
@@ -76,17 +84,9 @@
output_name = "libSupportTestsNL"
test_sources = [
- "TestCHIPMem.cpp",
- "TestCHIPMemString.cpp",
- "TestIntrusiveList.cpp",
- "TestJsonToTlv.cpp",
- "TestJsonToTlvToJson.cpp",
"TestPool.cpp",
"TestStateMachine.cpp",
"TestThreadOperationalDataset.cpp",
- "TestTlvJson.cpp",
- "TestTlvToJson.cpp",
- "TestZclString.cpp",
]
sources = []
diff --git a/src/lib/support/tests/TestCHIPCounter.cpp b/src/lib/support/tests/TestCHIPCounter.cpp
index d1212b9..b2c5e21 100644
--- a/src/lib/support/tests/TestCHIPCounter.cpp
+++ b/src/lib/support/tests/TestCHIPCounter.cpp
@@ -16,10 +16,12 @@
* limitations under the License.
*/
-#include <gtest/gtest.h>
-#include <lib/support/CHIPCounter.h>
#include <stdint.h>
+#include <gtest/gtest.h>
+
+#include <lib/support/CHIPCounter.h>
+
using namespace chip;
TEST(TestCHIPCounter, TestStartWithZero)
diff --git a/src/lib/support/tests/TestCHIPMem.cpp b/src/lib/support/tests/TestCHIPMem.cpp
index 2520da4..c19d356 100644
--- a/src/lib/support/tests/TestCHIPMem.cpp
+++ b/src/lib/support/tests/TestCHIPMem.cpp
@@ -29,11 +29,10 @@
#include <stdlib.h>
#include <string.h>
+#include <gtest/gtest.h>
+
#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
-#include <lib/support/UnitTestContext.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
using namespace chip;
using namespace chip::Logging;
@@ -43,7 +42,14 @@
// Unit tests
// =================================
-static void TestMemAlloc_Malloc(nlTestSuite * inSuite, void * inContext)
+class TestCHIPMem : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
+
+TEST_F(TestCHIPMem, TestMemAlloc_Malloc)
{
char * p1 = nullptr;
char * p2 = nullptr;
@@ -51,52 +57,52 @@
// Verify long-term allocation
p1 = static_cast<char *>(MemoryAlloc(64));
- NL_TEST_ASSERT(inSuite, p1 != nullptr);
+ EXPECT_NE(p1, nullptr);
p2 = static_cast<char *>(MemoryAlloc(256));
- NL_TEST_ASSERT(inSuite, p2 != nullptr);
+ EXPECT_NE(p2, nullptr);
chip::Platform::MemoryFree(p1);
chip::Platform::MemoryFree(p2);
// Verify short-term allocation
p1 = static_cast<char *>(MemoryAlloc(256));
- NL_TEST_ASSERT(inSuite, p1 != nullptr);
+ EXPECT_NE(p1, nullptr);
p2 = static_cast<char *>(MemoryAlloc(256));
- NL_TEST_ASSERT(inSuite, p2 != nullptr);
+ EXPECT_NE(p2, nullptr);
p3 = static_cast<char *>(MemoryAlloc(256));
- NL_TEST_ASSERT(inSuite, p3 != nullptr);
+ EXPECT_NE(p3, nullptr);
chip::Platform::MemoryFree(p1);
chip::Platform::MemoryFree(p2);
chip::Platform::MemoryFree(p3);
}
-static void TestMemAlloc_Calloc(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestCHIPMem, TestMemAlloc_Calloc)
{
- char * p = static_cast<char *>(MemoryCalloc(128, true));
- NL_TEST_EXIT_ON_FAILED_ASSERT(inSuite, p != nullptr);
+ char * p = static_cast<char *>(MemoryCalloc(128, sizeof(char)));
+ ASSERT_NE(p, nullptr);
for (int i = 0; i < 128; i++)
- NL_TEST_ASSERT(inSuite, p[i] == 0);
+ EXPECT_EQ(p[i], 0);
chip::Platform::MemoryFree(p);
}
-static void TestMemAlloc_Realloc(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestCHIPMem, TestMemAlloc_Realloc)
{
char * pa = static_cast<char *>(MemoryAlloc(128));
- NL_TEST_ASSERT(inSuite, pa != nullptr);
+ EXPECT_NE(pa, nullptr);
char * pb = static_cast<char *>(MemoryRealloc(pa, 256));
- NL_TEST_ASSERT(inSuite, pb != nullptr);
+ EXPECT_NE(pb, nullptr);
chip::Platform::MemoryFree(pb);
}
-static void TestMemAlloc_UniquePtr(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestCHIPMem, TestMemAlloc_UniquePtr)
{
// UniquePtr is a wrapper of std::unique_ptr for platform allocators, we just check if we created a correct wrapper here.
int constructorCalled = 0;
@@ -114,15 +120,15 @@
{
auto ptr = MakeUnique<Cls>(&constructorCalled, &destructorCalled);
- NL_TEST_ASSERT(inSuite, constructorCalled == 1);
- NL_TEST_ASSERT(inSuite, destructorCalled == 0);
+ EXPECT_EQ(constructorCalled, 1);
+ EXPECT_EQ(destructorCalled, 0);
IgnoreUnusedVariable(ptr);
}
- NL_TEST_ASSERT(inSuite, destructorCalled == 1);
+ EXPECT_TRUE(destructorCalled);
}
-static void TestMemAlloc_SharedPtr(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestCHIPMem, TestMemAlloc_SharedPtr)
{
// SharedPtr is a wrapper of std::shared_ptr for platform allocators.
int instanceConstructorCalled = 0;
@@ -145,62 +151,21 @@
SharedPtr<Cls> otherReference;
{
auto ptr = MakeShared<Cls>(&instanceConstructorCalled, &instanceDestructorCalled);
- NL_TEST_ASSERT(inSuite, instanceConstructorCalled == 1);
+ EXPECT_EQ(instanceConstructorCalled, 1);
// Capture a shared reference so we aren't destructed when we leave this scope.
otherReference = ptr;
}
// Verify that by sharing to otherReference, we weren't destructed.
- NL_TEST_ASSERT(inSuite, instanceDestructorCalled == 0);
+ EXPECT_EQ(instanceDestructorCalled, 0);
// Now drop our reference.
otherReference = MakeShared<Cls>(&otherInstanceConstructorCalled, &otherInstanceDestructorCalled);
// Verify that the new instance was constructed and the first instance was
// destructed, and that we retain a reference to the new instance.
- NL_TEST_ASSERT(inSuite, instanceConstructorCalled == 1);
- NL_TEST_ASSERT(inSuite, instanceDestructorCalled == 1);
- NL_TEST_ASSERT(inSuite, otherInstanceConstructorCalled == 1);
- NL_TEST_ASSERT(inSuite, otherInstanceDestructorCalled == 0);
+ EXPECT_EQ(instanceConstructorCalled, 1);
+ EXPECT_EQ(instanceDestructorCalled, 1);
+ EXPECT_EQ(otherInstanceConstructorCalled, 1);
+ EXPECT_EQ(otherInstanceDestructorCalled, 0);
}
-
-/**
- * Test Suite. It lists all the test functions.
- */
-static const nlTest sTests[] = { NL_TEST_DEF("Test MemAlloc::Malloc", TestMemAlloc_Malloc),
- NL_TEST_DEF("Test MemAlloc::Calloc", TestMemAlloc_Calloc),
- NL_TEST_DEF("Test MemAlloc::Realloc", TestMemAlloc_Realloc),
- NL_TEST_DEF("Test MemAlloc::UniquePtr", TestMemAlloc_UniquePtr),
- NL_TEST_DEF("Test MemAlloc::SharedPtr", TestMemAlloc_SharedPtr),
- NL_TEST_SENTINEL() };
-
-/**
- * Set up the test suite.
- */
-int TestMemAlloc_Setup(void * inContext)
-{
- CHIP_ERROR error = MemoryInit();
- if (error != CHIP_NO_ERROR)
- return (FAILURE);
- return (SUCCESS);
-}
-
-/**
- * Tear down the test suite.
- */
-int TestMemAlloc_Teardown(void * inContext)
-{
- MemoryShutdown();
- return (SUCCESS);
-}
-
-int TestMemAlloc()
-{
- nlTestSuite theSuite = { "CHIP Memory Allocation tests", &sTests[0], TestMemAlloc_Setup, TestMemAlloc_Teardown };
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestMemAlloc)
diff --git a/src/lib/support/tests/TestCHIPMemString.cpp b/src/lib/support/tests/TestCHIPMemString.cpp
index 90507fd..10101bd 100644
--- a/src/lib/support/tests/TestCHIPMemString.cpp
+++ b/src/lib/support/tests/TestCHIPMemString.cpp
@@ -22,12 +22,12 @@
#include <stdlib.h>
#include <string.h>
+#include <gtest/gtest.h>
+
#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/ScopedBuffer.h>
#include <lib/support/Span.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
using namespace chip;
using namespace chip::Platform;
@@ -36,6 +36,13 @@
// Unit tests
// =================================
+class TestCHIPMemString : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
+
namespace {
template <size_t kTestBufLen>
struct TestBuffers
@@ -51,28 +58,28 @@
memset(wayTooSmallBuf, 1, sizeof(wayTooSmallBuf));
memset(tooBigBuf, 1, sizeof(tooBigBuf));
}
- void CheckCorrectness(nlTestSuite * inSuite, const char * testStr)
+ void CheckCorrectness(const char * testStr)
{
// correctSizeBuf and tooBigBuf should have the complete string.
- NL_TEST_ASSERT(inSuite, correctSizeBuf[kTestBufLen - 1] == '\0');
- NL_TEST_ASSERT(inSuite, tooBigBuf[kTestBufLen - 1] == '\0');
- NL_TEST_ASSERT(inSuite, strcmp(correctSizeBuf, testStr) == 0);
- NL_TEST_ASSERT(inSuite, strcmp(tooBigBuf, testStr) == 0);
- NL_TEST_ASSERT(inSuite, strlen(correctSizeBuf) == strlen(testStr));
- NL_TEST_ASSERT(inSuite, strlen(tooBigBuf) == strlen(testStr));
+ EXPECT_EQ(correctSizeBuf[kTestBufLen - 1], '\0');
+ EXPECT_EQ(tooBigBuf[kTestBufLen - 1], '\0');
+ EXPECT_STREQ(correctSizeBuf, testStr);
+ EXPECT_STREQ(tooBigBuf, testStr);
+ EXPECT_EQ(strlen(correctSizeBuf), strlen(testStr));
+ EXPECT_EQ(strlen(tooBigBuf), strlen(testStr));
// wayTooSmallBuf is tiny and thus will only have the null terminator
- NL_TEST_ASSERT(inSuite, wayTooSmallBuf[0] == '\0');
+ EXPECT_EQ(wayTooSmallBuf[0], '\0');
// tooSmallBuf should still have a null terminator on the end
- NL_TEST_ASSERT(inSuite, tooSmallBuf[kTestBufLen - 2] == '\0');
- NL_TEST_ASSERT(inSuite, memcmp(tooSmallBuf, testStr, kTestBufLen - 2) == 0);
+ EXPECT_EQ(tooSmallBuf[kTestBufLen - 2], '\0');
+ EXPECT_EQ(memcmp(tooSmallBuf, testStr, kTestBufLen - 2), 0);
}
};
} // namespace
-static void TestCopyString(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestCHIPMemString, TestCopyString)
{
static constexpr char testWord[] = "testytest";
ByteSpan testWordSpan = ByteSpan(reinterpret_cast<const uint8_t *>(testWord), sizeof(testWord) - 1);
@@ -85,7 +92,7 @@
CopyString(testBuffers.tooSmallBuf, sizeof(testBuffers.tooSmallBuf), testWord);
CopyString(testBuffers.wayTooSmallBuf, sizeof(testBuffers.wayTooSmallBuf), testWord);
CopyString(testBuffers.tooBigBuf, sizeof(testBuffers.tooBigBuf), testWord);
- testBuffers.CheckCorrectness(inSuite, testWord);
+ testBuffers.CheckCorrectness(testWord);
// CopyString with array size
testBuffers.Reset();
@@ -93,7 +100,7 @@
CopyString(testBuffers.tooSmallBuf, testWord);
CopyString(testBuffers.wayTooSmallBuf, testWord);
CopyString(testBuffers.tooBigBuf, testWord);
- testBuffers.CheckCorrectness(inSuite, testWord);
+ testBuffers.CheckCorrectness(testWord);
// CopyString with explicit size from ByteSpan
testBuffers.Reset();
@@ -101,7 +108,7 @@
CopyString(testBuffers.tooSmallBuf, sizeof(testBuffers.tooSmallBuf), testWordSpan);
CopyString(testBuffers.wayTooSmallBuf, sizeof(testBuffers.wayTooSmallBuf), testWordSpan);
CopyString(testBuffers.tooBigBuf, sizeof(testBuffers.tooBigBuf), testWordSpan);
- testBuffers.CheckCorrectness(inSuite, testWord);
+ testBuffers.CheckCorrectness(testWord);
// CopyString with array size from ByteSpan
testBuffers.Reset();
@@ -109,7 +116,7 @@
CopyString(testBuffers.tooSmallBuf, testWordSpan);
CopyString(testBuffers.wayTooSmallBuf, testWordSpan);
CopyString(testBuffers.tooBigBuf, testWordSpan);
- testBuffers.CheckCorrectness(inSuite, testWord);
+ testBuffers.CheckCorrectness(testWord);
// CopyString with explicit size from CharSpan
testBuffers.Reset();
@@ -117,7 +124,7 @@
CopyString(testBuffers.tooSmallBuf, sizeof(testBuffers.tooSmallBuf), testWordSpan2);
CopyString(testBuffers.wayTooSmallBuf, sizeof(testBuffers.wayTooSmallBuf), testWordSpan2);
CopyString(testBuffers.tooBigBuf, sizeof(testBuffers.tooBigBuf), testWordSpan2);
- testBuffers.CheckCorrectness(inSuite, testWord);
+ testBuffers.CheckCorrectness(testWord);
// CopyString with array size from CharSpan
testBuffers.Reset();
@@ -125,59 +132,24 @@
CopyString(testBuffers.tooSmallBuf, testWordSpan2);
CopyString(testBuffers.wayTooSmallBuf, testWordSpan2);
CopyString(testBuffers.tooBigBuf, testWordSpan2);
- testBuffers.CheckCorrectness(inSuite, testWord);
+ testBuffers.CheckCorrectness(testWord);
}
-static void TestMemoryAllocString(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestCHIPMemString, TestMemoryAllocString)
{
static constexpr char testStr[] = "testytestString";
char * allocatedStr = MemoryAllocString(testStr, sizeof(testStr));
- NL_TEST_ASSERT(inSuite, allocatedStr != nullptr);
- if (allocatedStr == nullptr)
- {
- return;
- }
- NL_TEST_ASSERT(inSuite, strcmp(testStr, allocatedStr) == 0);
+ ASSERT_NE(allocatedStr, nullptr);
+
+ EXPECT_STREQ(testStr, allocatedStr);
MemoryFree(allocatedStr);
}
-static void TestScopedBuffer(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestCHIPMemString, TestScopedBuffer)
{
// Scoped buffer has its own tests that check the memory properly. Here we are just testing that the string is copied in
// properly.
static constexpr char testStr[] = "testytestString";
ScopedMemoryString scopedString = ScopedMemoryString(testStr, sizeof(testStr));
- NL_TEST_ASSERT(inSuite, strcmp(scopedString.Get(), testStr) == 0);
+ EXPECT_STREQ(scopedString.Get(), testStr);
}
-
-static const nlTest sTests[] = { NL_TEST_DEF("Test CopyString", TestCopyString),
- NL_TEST_DEF("Test MemoryAllocString", TestMemoryAllocString),
- NL_TEST_DEF("Test ScopedBuffer", TestScopedBuffer), NL_TEST_SENTINEL() };
-
-int TestMemString_Setup(void * inContext)
-{
- CHIP_ERROR error = MemoryInit();
- if (error != CHIP_NO_ERROR)
- return (FAILURE);
- return (SUCCESS);
-}
-
-/**
- * Tear down the test suite.
- */
-int TestMemString_Teardown(void * inContext)
-{
- MemoryShutdown();
- return (SUCCESS);
-}
-
-int TestMemString()
-{
- nlTestSuite theSuite = { "CHIP Memory Allocation tests", &sTests[0], TestMemString_Setup, TestMemString_Teardown };
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestMemString)
diff --git a/src/lib/support/tests/TestIntrusiveList.cpp b/src/lib/support/tests/TestIntrusiveList.cpp
index 0d1779b..50ace6a 100644
--- a/src/lib/support/tests/TestIntrusiveList.cpp
+++ b/src/lib/support/tests/TestIntrusiveList.cpp
@@ -18,20 +18,30 @@
#include <ctime>
#include <list>
-#include <lib/support/IntrusiveList.h>
-#include <lib/support/UnitTestRegistration.h>
+#include <gtest/gtest.h>
-#include <nlunit-test.h>
+#include <lib/support/IntrusiveList.h>
namespace {
using namespace chip;
+class TestIntrusiveList : 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);
+ }
+};
+
class ListNode : public IntrusiveListNodeBase<>
{
};
-void TestIntrusiveListRandom(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestIntrusiveList, TestIntrusiveListRandom)
{
IntrusiveList<ListNode> l1;
ListNode node[100];
@@ -86,9 +96,8 @@
break;
}
- NL_TEST_ASSERT(inSuite,
- std::equal(l1.begin(), l1.end(), l2.begin(), l2.end(),
- [](const ListNode & p1, const ListNode * p2) { return &p1 == p2; }));
+ EXPECT_TRUE(std::equal(l1.begin(), l1.end(), l2.begin(), l2.end(),
+ [](const ListNode & p1, const ListNode * p2) { return &p1 == p2; }));
}
while (!l1.Empty())
@@ -97,85 +106,85 @@
}
}
-void TestContains(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestIntrusiveList, TestContains)
{
ListNode a, b, c;
IntrusiveList<ListNode> list;
- NL_TEST_ASSERT(inSuite, !list.Contains(&a));
- NL_TEST_ASSERT(inSuite, !list.Contains(&b));
- NL_TEST_ASSERT(inSuite, !list.Contains(&c));
+ EXPECT_FALSE(list.Contains(&a));
+ EXPECT_FALSE(list.Contains(&b));
+ EXPECT_FALSE(list.Contains(&c));
list.PushBack(&a);
list.PushFront(&c);
- NL_TEST_ASSERT(inSuite, list.Contains(&a));
- NL_TEST_ASSERT(inSuite, !list.Contains(&b));
- NL_TEST_ASSERT(inSuite, list.Contains(&c));
+ EXPECT_TRUE(list.Contains(&a));
+ EXPECT_FALSE(list.Contains(&b));
+ EXPECT_TRUE(list.Contains(&c));
list.PushBack(&b);
- NL_TEST_ASSERT(inSuite, list.Contains(&a));
- NL_TEST_ASSERT(inSuite, list.Contains(&b));
- NL_TEST_ASSERT(inSuite, list.Contains(&c));
+ EXPECT_TRUE(list.Contains(&a));
+ EXPECT_TRUE(list.Contains(&b));
+ EXPECT_TRUE(list.Contains(&c));
list.Remove(&a);
list.Remove(&c);
- NL_TEST_ASSERT(inSuite, !list.Contains(&a));
- NL_TEST_ASSERT(inSuite, list.Contains(&b));
- NL_TEST_ASSERT(inSuite, !list.Contains(&c));
+ EXPECT_FALSE(list.Contains(&a));
+ EXPECT_TRUE(list.Contains(&b));
+ EXPECT_FALSE(list.Contains(&c));
// all nodes have to be removed from the list on destruction. Lists do NOT do
// this automatically
list.Remove(&b);
}
-void TestClear(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestIntrusiveList, TestClear)
{
ListNode a, b, c;
IntrusiveList<ListNode> list;
- NL_TEST_ASSERT(inSuite, !list.Contains(&a));
- NL_TEST_ASSERT(inSuite, !list.Contains(&b));
- NL_TEST_ASSERT(inSuite, !list.Contains(&c));
+ EXPECT_FALSE(list.Contains(&a));
+ EXPECT_FALSE(list.Contains(&b));
+ EXPECT_FALSE(list.Contains(&c));
list.PushBack(&a);
list.PushFront(&c);
- NL_TEST_ASSERT(inSuite, list.Contains(&a));
- NL_TEST_ASSERT(inSuite, !list.Contains(&b));
- NL_TEST_ASSERT(inSuite, list.Contains(&c));
+ EXPECT_TRUE(list.Contains(&a));
+ EXPECT_FALSE(list.Contains(&b));
+ EXPECT_TRUE(list.Contains(&c));
list.PushBack(&b);
- NL_TEST_ASSERT(inSuite, list.Contains(&a));
- NL_TEST_ASSERT(inSuite, list.Contains(&b));
- NL_TEST_ASSERT(inSuite, list.Contains(&c));
+ EXPECT_TRUE(list.Contains(&a));
+ EXPECT_TRUE(list.Contains(&b));
+ EXPECT_TRUE(list.Contains(&c));
list.Clear();
- NL_TEST_ASSERT(inSuite, !list.Contains(&a));
- NL_TEST_ASSERT(inSuite, !list.Contains(&b));
- NL_TEST_ASSERT(inSuite, !list.Contains(&c));
+ EXPECT_FALSE(list.Contains(&a));
+ EXPECT_FALSE(list.Contains(&b));
+ EXPECT_FALSE(list.Contains(&c));
}
-void TestReplaceNode(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestIntrusiveList, TestReplaceNode)
{
ListNode a, b;
IntrusiveList<ListNode> list;
list.PushBack(&a);
list.Replace(&a, &b);
- NL_TEST_ASSERT(inSuite, !a.IsInList());
- NL_TEST_ASSERT(inSuite, b.IsInList());
- NL_TEST_ASSERT(inSuite, !list.Empty());
- NL_TEST_ASSERT(inSuite, !list.Contains(&a));
- NL_TEST_ASSERT(inSuite, list.Contains(&b));
+ EXPECT_FALSE(a.IsInList());
+ EXPECT_TRUE(b.IsInList());
+ EXPECT_FALSE(list.Empty());
+ EXPECT_FALSE(list.Contains(&a));
+ EXPECT_TRUE(list.Contains(&b));
list.Remove(&b);
}
-void TestMoveList(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestIntrusiveList, TestMoveList)
{
ListNode a, b;
@@ -183,8 +192,8 @@
// Test case 1: Move construct an empty list
IntrusiveList<ListNode> listA;
IntrusiveList<ListNode> listB(std::move(listA));
- NL_TEST_ASSERT(inSuite, listA.Empty()); // NOLINT(bugprone-use-after-move)
- NL_TEST_ASSERT(inSuite, listB.Empty());
+ EXPECT_TRUE(listA.Empty()); // NOLINT(bugprone-use-after-move)
+ EXPECT_TRUE(listB.Empty());
}
{
@@ -193,8 +202,8 @@
listA.PushBack(&a);
IntrusiveList<ListNode> listB(std::move(listA));
- NL_TEST_ASSERT(inSuite, listA.Empty()); // NOLINT(bugprone-use-after-move)
- NL_TEST_ASSERT(inSuite, listB.Contains(&a));
+ EXPECT_TRUE(listA.Empty()); // NOLINT(bugprone-use-after-move)
+ EXPECT_TRUE(listB.Contains(&a));
listB.Remove(&a);
}
@@ -203,8 +212,8 @@
IntrusiveList<ListNode> listA;
IntrusiveList<ListNode> listB;
listB = std::move(listA);
- NL_TEST_ASSERT(inSuite, listA.Empty()); // NOLINT(bugprone-use-after-move)
- NL_TEST_ASSERT(inSuite, listB.Empty());
+ EXPECT_TRUE(listA.Empty()); // NOLINT(bugprone-use-after-move)
+ EXPECT_TRUE(listB.Empty());
}
{
@@ -214,8 +223,8 @@
IntrusiveList<ListNode> listB;
listB = std::move(listA);
- NL_TEST_ASSERT(inSuite, listA.Empty()); // NOLINT(bugprone-use-after-move)
- NL_TEST_ASSERT(inSuite, listB.Contains(&a));
+ EXPECT_TRUE(listA.Empty()); // NOLINT(bugprone-use-after-move)
+ EXPECT_TRUE(listB.Contains(&a));
listB.Remove(&a);
}
}
@@ -224,68 +233,29 @@
{
};
-void TestAutoUnlink(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestIntrusiveList, TestAutoUnlink)
{
IntrusiveList<ListNodeAutoUnlink, IntrusiveMode::AutoUnlink> list;
// Test case 1: Test node->Unlink()
{
ListNodeAutoUnlink a;
- NL_TEST_ASSERT(inSuite, !list.Contains(&a));
+ EXPECT_FALSE(list.Contains(&a));
list.PushBack(&a);
- NL_TEST_ASSERT(inSuite, list.Contains(&a));
+ EXPECT_TRUE(list.Contains(&a));
a.Unlink();
- NL_TEST_ASSERT(inSuite, !list.Contains(&a));
- NL_TEST_ASSERT(inSuite, list.Empty());
+ EXPECT_FALSE(list.Contains(&a));
+ EXPECT_TRUE(list.Empty());
}
// Test case 2: The node is automatically removed when goes out of scope
{
ListNodeAutoUnlink a;
- NL_TEST_ASSERT(inSuite, !list.Contains(&a));
+ EXPECT_FALSE(list.Contains(&a));
list.PushBack(&a);
- NL_TEST_ASSERT(inSuite, list.Contains(&a));
+ EXPECT_TRUE(list.Contains(&a));
}
- NL_TEST_ASSERT(inSuite, list.Empty());
-}
-
-int Setup(void * inContext)
-{
- return SUCCESS;
-}
-
-int Teardown(void * inContext)
-{
- return SUCCESS;
+ EXPECT_TRUE(list.Empty());
}
} // 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(TestIntrusiveListRandom), //
- NL_TEST_DEF_FN(TestContains), //
- NL_TEST_DEF_FN(TestReplaceNode), //
- NL_TEST_DEF_FN(TestMoveList), //
- NL_TEST_DEF_FN(TestAutoUnlink), //
- NL_TEST_DEF_FN(TestClear), //
- NL_TEST_SENTINEL(), //
-};
-
-int TestIntrusiveList()
-{
- nlTestSuite theSuite = { "CHIP IntrusiveList 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(TestIntrusiveList);
diff --git a/src/lib/support/tests/TestJsonToTlv.cpp b/src/lib/support/tests/TestJsonToTlv.cpp
index a531447..9bc8696 100644
--- a/src/lib/support/tests/TestJsonToTlv.cpp
+++ b/src/lib/support/tests/TestJsonToTlv.cpp
@@ -15,19 +15,18 @@
* limitations under the License.
*/
+#include <string>
+
+#include <gtest/gtest.h>
+
#include <app-common/zap-generated/cluster-objects.h>
#include <app/data-model/Decode.h>
#include <app/data-model/Encode.h>
#include <lib/core/TLVDebug.h>
#include <lib/core/TLVReader.h>
-#include <lib/support/UnitTestRegistration.h>
#include <lib/support/jsontlv/JsonToTlv.h>
#include <lib/support/jsontlv/TextFormat.h>
#include <lib/support/jsontlv/TlvToJson.h>
-#include <nlunit-test.h>
-
-#include <string>
-
namespace {
using namespace chip::Encoding;
@@ -40,7 +39,13 @@
uint8_t gBuf2[1024];
TLV::TLVWriter gWriter1;
TLV::TLVWriter gWriter2;
-nlTestSuite * gSuite;
+
+class TestJsonToTlv : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
void SetupWriters()
{
@@ -87,29 +92,27 @@
SetupWriters();
err = gWriter1.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, container);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = DataModel::Encode(gWriter1, TLV::ContextTag(1), val);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = gWriter1.EndContainer(container);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = gWriter1.Finalize();
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = JsonToTlv(jsonString, gWriter2);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(gSuite, MatchWriter1and2());
+ EXPECT_TRUE(MatchWriter1and2());
}
-void TestConverter(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlv, TestConverter)
{
std::string jsonString;
- gSuite = inSuite;
-
jsonString = "{\n"
" \"1:UINT\" : 30\n"
"}\n";
@@ -239,7 +242,7 @@
ConvertJsonToTlvAndValidate(structList, jsonString);
}
-void Test32BitConvert(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlv, Test32BitConvert)
{
// JSON TLV format explicitly wants to support 32-bit integer preservation.
//
@@ -258,69 +261,69 @@
{
SetupWriters();
JsonToTlv("{\"1:INT\": 321}", gWriter1);
- NL_TEST_ASSERT(inSuite, gWriter1.Finalize() == CHIP_NO_ERROR);
+ EXPECT_EQ(gWriter1.Finalize(), CHIP_NO_ERROR);
reader.Init(gBuf1, gWriter1.GetLengthWritten());
reader.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::AnonymousTag()) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_Structure);
- NL_TEST_ASSERT(inSuite, reader.EnterContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::ContextTag(1)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_SignedInteger);
- NL_TEST_ASSERT(inSuite, reader.Get(value) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, value == 321);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
- NL_TEST_ASSERT(inSuite, reader.ExitContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.Next(TLV::AnonymousTag()), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_Structure);
+ EXPECT_EQ(reader.EnterContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(TLV::ContextTag(1)), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_SignedInteger);
+ EXPECT_EQ(reader.Get(value), CHIP_NO_ERROR);
+ EXPECT_EQ(value, 321);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.ExitContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
}
// convert a single value that is larger than 8 bit
{
SetupWriters();
JsonToTlv("{\"1234:INT\": 321}", gWriter1);
- NL_TEST_ASSERT(inSuite, gWriter1.Finalize() == CHIP_NO_ERROR);
+ EXPECT_EQ(gWriter1.Finalize(), CHIP_NO_ERROR);
reader.Init(gBuf1, gWriter1.GetLengthWritten());
reader.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::AnonymousTag()) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_Structure);
- NL_TEST_ASSERT(inSuite, reader.EnterContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::ProfileTag(kImplicitProfileId, 1234)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_SignedInteger);
- NL_TEST_ASSERT(inSuite, reader.Get(value) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, value == 321);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
- NL_TEST_ASSERT(inSuite, reader.ExitContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.Next(TLV::AnonymousTag()), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_Structure);
+ EXPECT_EQ(reader.EnterContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(TLV::ProfileTag(kImplicitProfileId, 1234)), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_SignedInteger);
+ EXPECT_EQ(reader.Get(value), CHIP_NO_ERROR);
+ EXPECT_EQ(value, 321);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.ExitContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
}
// Convert to a full 32-bit value, unsigned
{
SetupWriters();
JsonToTlv("{\"4275878552:INT\": 321}", gWriter1);
- NL_TEST_ASSERT(inSuite, gWriter1.Finalize() == CHIP_NO_ERROR);
+ EXPECT_EQ(gWriter1.Finalize(), CHIP_NO_ERROR);
reader.Init(gBuf1, gWriter1.GetLengthWritten());
reader.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::AnonymousTag()) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_Structure);
- NL_TEST_ASSERT(inSuite, reader.EnterContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::ProfileTag((4275878552 >> 16) & 0xFFFF, 0, 4275878552 & 0xFFFF)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_SignedInteger);
- NL_TEST_ASSERT(inSuite, reader.Get(value) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, value == 321);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
- NL_TEST_ASSERT(inSuite, reader.ExitContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.Next(TLV::AnonymousTag()), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_Structure);
+ EXPECT_EQ(reader.EnterContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(TLV::ProfileTag((4275878552 >> 16) & 0xFFFF, 0, 4275878552 & 0xFFFF)), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_SignedInteger);
+ EXPECT_EQ(reader.Get(value), CHIP_NO_ERROR);
+ EXPECT_EQ(value, 321);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.ExitContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
}
// FIXME: implement
}
-void TestMEIConvert(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlv, TestMEIConvert)
{
TLV::TLVReader reader;
TLV::TLVType tlvType;
@@ -330,95 +333,63 @@
{
SetupWriters();
JsonToTlv("{\"65536:INT\": 321}", gWriter1);
- NL_TEST_ASSERT(inSuite, gWriter1.Finalize() == CHIP_NO_ERROR);
+ EXPECT_EQ(gWriter1.Finalize(), CHIP_NO_ERROR);
reader.Init(gBuf1, gWriter1.GetLengthWritten());
reader.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::AnonymousTag()) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_Structure);
- NL_TEST_ASSERT(inSuite, reader.EnterContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::ProfileTag(1, 0, 0)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_SignedInteger);
- NL_TEST_ASSERT(inSuite, reader.Get(value) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, value == 321);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
- NL_TEST_ASSERT(inSuite, reader.ExitContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.Next(TLV::AnonymousTag()), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_Structure);
+ EXPECT_EQ(reader.EnterContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(TLV::ProfileTag(1, 0, 0)), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_SignedInteger);
+ EXPECT_EQ(reader.Get(value), CHIP_NO_ERROR);
+ EXPECT_EQ(value, 321);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.ExitContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
}
// Vendor ID = 0xFFFF, Tag ID = 0
{
SetupWriters();
JsonToTlv("{\"4294901760:INT\": 123}", gWriter1);
- NL_TEST_ASSERT(inSuite, gWriter1.Finalize() == CHIP_NO_ERROR);
+ EXPECT_EQ(gWriter1.Finalize(), CHIP_NO_ERROR);
reader.Init(gBuf1, gWriter1.GetLengthWritten());
reader.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::AnonymousTag()) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_Structure);
- NL_TEST_ASSERT(inSuite, reader.EnterContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::ProfileTag(0xFFFF, 0, 0)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_SignedInteger);
- NL_TEST_ASSERT(inSuite, reader.Get(value) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, value == 123);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
- NL_TEST_ASSERT(inSuite, reader.ExitContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.Next(TLV::AnonymousTag()), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_Structure);
+ EXPECT_EQ(reader.EnterContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(TLV::ProfileTag(0xFFFF, 0, 0)), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_SignedInteger);
+ EXPECT_EQ(reader.Get(value), CHIP_NO_ERROR);
+ EXPECT_EQ(value, 123);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.ExitContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
}
// Vendor ID = 0xFFFF, Tag ID = 0xFFFF
{
SetupWriters();
JsonToTlv("{\"4294967295:INT\": 123}", gWriter1);
- NL_TEST_ASSERT(inSuite, gWriter1.Finalize() == CHIP_NO_ERROR);
+ EXPECT_EQ(gWriter1.Finalize(), CHIP_NO_ERROR);
reader.Init(gBuf1, gWriter1.GetLengthWritten());
reader.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::AnonymousTag()) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_Structure);
- NL_TEST_ASSERT(inSuite, reader.EnterContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next(TLV::ProfileTag(0xFFFF, 0, 0xFFFF)) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetType() == TLV::kTLVType_SignedInteger);
- NL_TEST_ASSERT(inSuite, reader.Get(value) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, value == 123);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
- NL_TEST_ASSERT(inSuite, reader.ExitContainer(tlvType) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.Next(TLV::AnonymousTag()), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_Structure);
+ EXPECT_EQ(reader.EnterContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(TLV::ProfileTag(0xFFFF, 0, 0xFFFF)), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetType(), TLV::kTLVType_SignedInteger);
+ EXPECT_EQ(reader.Get(value), CHIP_NO_ERROR);
+ EXPECT_EQ(value, 123);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.ExitContainer(tlvType), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
}
}
-
-int Initialize(void * apSuite)
-{
- VerifyOrReturnError(chip::Platform::MemoryInit() == CHIP_NO_ERROR, FAILURE);
- return SUCCESS;
-}
-
-int Finalize(void * aContext)
-{
- chip::Platform::MemoryShutdown();
- return SUCCESS;
-}
-
-// clang-format off
-const nlTest sTests[] =
-{
- NL_TEST_DEF("TestConverter", TestConverter),
- NL_TEST_DEF("Test32BitConvert", Test32BitConvert),
- NL_TEST_DEF("TestMEIConvert", TestMEIConvert),
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
} // namespace
-
-int TestJsonToTlv()
-{
- nlTestSuite theSuite = { "JsonToTlv", sTests, Initialize, Finalize };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestJsonToTlv)
diff --git a/src/lib/support/tests/TestJsonToTlvToJson.cpp b/src/lib/support/tests/TestJsonToTlvToJson.cpp
index 2ac6467..665df4d 100644
--- a/src/lib/support/tests/TestJsonToTlvToJson.cpp
+++ b/src/lib/support/tests/TestJsonToTlvToJson.cpp
@@ -16,17 +16,16 @@
*/
#include <stdio.h>
+#include <string>
+
+#include <gtest/gtest.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app/data-model/Decode.h>
#include <app/data-model/Encode.h>
-#include <lib/support/UnitTestRegistration.h>
#include <lib/support/jsontlv/JsonToTlv.h>
#include <lib/support/jsontlv/TextFormat.h>
#include <lib/support/jsontlv/TlvToJson.h>
-#include <nlunit-test.h>
-
-#include <string>
namespace {
@@ -36,7 +35,12 @@
constexpr uint32_t kImplicitProfileId = 0x1122;
-nlTestSuite * gSuite;
+class TestJsonToTlvToJson : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
void PrintSpan(const char * prefix, const ByteSpan & span)
{
@@ -56,10 +60,10 @@
uint8_t buf[256];
MutableByteSpan tlvEncodingLocal(buf);
err = JsonToTlv(jsonOriginal, tlvEncodingLocal);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
match = tlvEncodingLocal.data_equal(tlvEncoding);
- NL_TEST_ASSERT(gSuite, match);
+ EXPECT_TRUE(match);
if (!match)
{
printf("ERROR: TLV Encoding Doesn't Match!\n");
@@ -69,12 +73,12 @@
std::string generatedJsonString;
err = TlvToJson(tlvEncoding, generatedJsonString);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
auto compactExpectedString = PrettyPrintJsonString(jsonExpected);
auto compactGeneratedString = PrettyPrintJsonString(generatedJsonString);
match = (compactGeneratedString == compactExpectedString);
- NL_TEST_ASSERT(gSuite, match);
+ EXPECT_TRUE(match);
if (!match)
{
printf("ERROR: Json String Doesn't Match!\n");
@@ -85,10 +89,10 @@
// Verify that Expected Json String Converts to the Same TLV Encoding
tlvEncodingLocal = MutableByteSpan(buf);
err = JsonToTlv(jsonOriginal, tlvEncodingLocal);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
match = tlvEncodingLocal.data_equal(tlvEncoding);
- NL_TEST_ASSERT(gSuite, match);
+ EXPECT_TRUE(match);
if (!match)
{
printf("ERROR: TLV Encoding Doesn't Match!\n");
@@ -98,19 +102,18 @@
}
// Boolean true
-void TestConverter_Boolean_True(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Boolean_True)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1:BOOL\" : true\n"
@@ -121,19 +124,18 @@
}
// Signed Integer 42, 1-octet
-void TestConverter_SignedInt_1BytePositive(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_SignedInt_1BytePositive)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(2), static_cast<int8_t>(42)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(2), static_cast<int8_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"2:INT\" : 42\n"
@@ -144,19 +146,18 @@
}
// Signed Integer -17, 1-octet
-void TestConverter_SignedInt_1ByteNegative(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_SignedInt_1ByteNegative)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(3), static_cast<int8_t>(-17)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(3), static_cast<int8_t>(-17)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"3:INT\" : -17\n"
@@ -167,19 +168,18 @@
}
// Unsigned Integer 42, 1-octet
-void TestConverter_UnsignedInt_1Byte(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_UnsignedInt_1Byte)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(4), static_cast<uint8_t>(42)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(4), static_cast<uint8_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"value:4:UINT\" : 42\n"
@@ -194,19 +194,18 @@
}
// Signed Integer 4242, 2-octet
-void TestConverter_SignedInt_2Bytes(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_SignedInt_2Bytes)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(7), static_cast<int16_t>(4242)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(7), static_cast<int16_t>(4242)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"7:INT\" : 4242\n"
@@ -217,19 +216,18 @@
}
// Signed Integer -170000, 4-octet
-void TestConverter_SignedInt_4Bytes(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_SignedInt_4Bytes)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(80), static_cast<int32_t>(-170000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(80), static_cast<int32_t>(-170000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"80:INT\" : -170000\n"
@@ -240,19 +238,18 @@
}
// Signed Long Integer (int64_t) 40000000000, 8-octet
-void TestConverter_SignedInt_8Bytes(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_SignedInt_8Bytes)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(202), static_cast<int64_t>(40000000000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(202), static_cast<int64_t>(40000000000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"202:INT\" : \"40000000000\"\n"
@@ -263,19 +260,18 @@
}
// Unsigned Long Integer (uint64_t) 40000000000, 8-octet
-void TestConverter_UnsignedInt_8Bytes(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_UnsignedInt_8Bytes)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(222), static_cast<uint64_t>(40000000000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(222), static_cast<uint64_t>(40000000000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"222:UINT\" : \"40000000000\"\n"
@@ -286,19 +282,18 @@
}
// UTF-8 String, 1-octet length, "Hello!"
-void TestConverter_UTF8String_Hello(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_UTF8String_Hello)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::ContextTag(0), "Hello!"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::ContextTag(0), "Hello!"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:STRING\" : \"Hello!\"\n"
@@ -309,9 +304,8 @@
}
// Octet String, 1-octet length, octets { 00 01 02 03 04 }
-void TestConverter_OctetString(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_OctetString)
{
- gSuite = inSuite;
uint8_t v[] = { 0, 1, 2, 3, 4 };
uint8_t buf[256];
@@ -319,10 +313,10 @@
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutBytes(TLV::ContextTag(1), v, sizeof(v)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutBytes(TLV::ContextTag(1), v, sizeof(v)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1:BYTES\" : \"AAECAwQ=\"\n"
@@ -333,19 +327,18 @@
}
// Octet String, empty
-void TestConverter_OctetString_Empty(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_OctetString_Empty)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutBytes(TLV::ContextTag(1), nullptr, 0));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutBytes(TLV::ContextTag(1), nullptr, 0));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1:BYTES\" : \"\"\n"
@@ -356,19 +349,18 @@
}
// Null
-void TestConverter_Null(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Null)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutNull(TLV::ContextTag(1)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutNull(TLV::ContextTag(1)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1:NULL\" : null\n"
@@ -379,19 +371,18 @@
}
// Single precision floating point 0.0
-void TestConverter_Float_0(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Float_0)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), static_cast<float>(0.0)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), static_cast<float>(0.0)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1:FLOAT\" : 0.0\n"
@@ -402,19 +393,18 @@
}
// Single precision floating point (1.0 / 3.0)
-void TestConverter_Float_1third(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Float_1third)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(100), static_cast<float>(1.0 / 3.0)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(100), static_cast<float>(1.0 / 3.0)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"100:FLOAT\" : 0.33333334\n"
@@ -428,19 +418,18 @@
}
// Single precision floating point 17.9
-void TestConverter_Float_17_9(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Float_17_9)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(101), static_cast<float>(17.9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(101), static_cast<float>(17.9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"101:FLOAT\" : 17.9\n"
@@ -454,19 +443,18 @@
}
// Single precision floating point positive infinity
-void TestConverter_Float_PositiveInfinity(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Float_PositiveInfinity)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(101), std::numeric_limits<float>::infinity()));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(101), std::numeric_limits<float>::infinity()));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"101:FLOAT\" : \"Infinity\"\n"
@@ -477,19 +465,18 @@
}
// Single precision floating point negative infinity
-void TestConverter_Float_NegativeInfinity(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Float_NegativeInfinity)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(101), -std::numeric_limits<float>::infinity()));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(101), -std::numeric_limits<float>::infinity()));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"101:FLOAT\" : \"-Infinity\"\n"
@@ -500,19 +487,18 @@
}
// Double precision floating point 0.0
-void TestConverter_Double_0(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Double_0)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), static_cast<double>(0.0)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), static_cast<double>(0.0)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1:DOUBLE\" : 0.0\n"
@@ -523,19 +509,18 @@
}
// Double precision floating point (1.0 / 3.0)
-void TestConverter_Double_1third(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Double_1third)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(100), static_cast<double>(1.0 / 3.0)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(100), static_cast<double>(1.0 / 3.0)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"100:DOUBLE\" : 0.33333333333333331\n"
@@ -546,19 +531,18 @@
}
// Double precision floating point 17.9
-void TestConverter_Double_17_9(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Double_17_9)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(101), static_cast<double>(17.9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(101), static_cast<double>(17.9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"101:DOUBLE\" : 17.899999999999999\n"
@@ -569,19 +553,18 @@
}
// Double precision floating point positive infinity
-void TestConverter_Double_PositiveInfinity(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Double_PositiveInfinity)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(101), std::numeric_limits<double>::infinity()));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(101), std::numeric_limits<double>::infinity()));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"101:DOUBLE\" : \"Infinity\"\n"
@@ -592,19 +575,18 @@
}
// Double precision floating point negative infinity
-void TestConverter_Double_NegativeInfinity(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Double_NegativeInfinity)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(101), -std::numeric_limits<double>::infinity()));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(101), -std::numeric_limits<double>::infinity()));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"101:DOUBLE\" : \"-Infinity\"\n"
@@ -615,18 +597,17 @@
}
// Empty Top-Level Structure, {}
-void TestConverter_Structure_TopLevelEmpty(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Structure_TopLevelEmpty)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{ }";
@@ -635,9 +616,8 @@
}
// Empty Nested Structure, { {} }
-void TestConverter_Structure_NestedEmpty(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Structure_NestedEmpty)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -645,11 +625,11 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Structure, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Structure, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1:STRUCT\" : { }\n"
@@ -660,9 +640,8 @@
}
// Empty Array, { [] }
-void TestConverter_Array_Empty(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Empty)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -670,11 +649,11 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1:ARRAY-?\" : []\n"
@@ -684,9 +663,8 @@
CheckValidConversion(jsonString, tlvSpan, jsonString);
}
-void TestConverter_Array_Empty_ImplicitProfileTag2(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Empty_ImplicitProfileTag2)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -697,13 +675,12 @@
writer.Init(buf);
writer.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite,
- CHIP_NO_ERROR ==
- writer.StartContainer(TLV::ProfileTag(kImplicitProfileId, 10000), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR,
+ writer.StartContainer(TLV::ProfileTag(kImplicitProfileId, 10000), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"emptyarray:10000:ARRAY-?\" : []\n"
@@ -716,9 +693,8 @@
CheckValidConversion(jsonString, tlvSpan, jsonExpected);
}
-void TestConverter_Array_Empty_ImplicitProfileTag4(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Empty_ImplicitProfileTag4)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -729,14 +705,13 @@
writer.Init(buf);
writer.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite,
- CHIP_NO_ERROR ==
- writer.StartContainer(TLV::ProfileTag((1000000 >> 16) & 0xFFFF, 0, 1000000 & 0xFFFF), TLV::kTLVType_Array,
- containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(
+ CHIP_NO_ERROR,
+ writer.StartContainer(TLV::ProfileTag((1000000 >> 16) & 0xFFFF, 0, 1000000 & 0xFFFF), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1000000:ARRAY-?\" : []\n"
@@ -747,20 +722,19 @@
}
// Two Signed Integers with context specific tags: {0 = 42, 1 = -17}
-void TestConverter_IntsWithContextTags(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_IntsWithContextTags)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
TLV::TLVType containerType;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(0), static_cast<int8_t>(42)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), static_cast<int8_t>(-17)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(0), static_cast<int8_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), static_cast<int8_t>(-17)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:INT\" : 42,\n"
@@ -772,9 +746,8 @@
}
// Structure with Two Signed Integers with context specific tags: { {0 = 42, 1 = -17} }
-void TestConverter_Struct_IntsWithContextTags(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Struct_IntsWithContextTags)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -782,13 +755,13 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(0), static_cast<int8_t>(42)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), static_cast<int8_t>(-17)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(0), static_cast<int8_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), static_cast<int8_t>(-17)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:STRUCT\" : {\n"
@@ -802,9 +775,8 @@
}
// Array of Signed Integers: { [0, 1, 2, 3, 4] }
-void TestConverter_Array_Ints(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Ints)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -812,16 +784,16 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(0)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(1)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(2)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(3)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(4)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(0)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(1)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(2)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(3)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(4)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:ARRAY-INT\" : [\n"
@@ -838,9 +810,8 @@
}
// Array of Long Signed Integers: { [42, -17, -170000, 40000000000] }
-void TestConverter_Array_Ints2(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Ints2)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -848,15 +819,15 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(42)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(-17)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(-170000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(40000000000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(-17)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(-170000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(40000000000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:ARRAY-INT\" : [\n"
@@ -872,9 +843,8 @@
}
// Array of Signed Integers with MIN/MAX values for each type int8_t/int16_t/int32_t/int64_t
-void TestConverter_Array_IntsMinMax(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_IntsMinMax)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -882,19 +852,19 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT8_MIN)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT8_MAX)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT16_MIN)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT16_MAX)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT32_MIN)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT32_MAX)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT64_MIN)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT64_MAX)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT8_MIN)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT8_MAX)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT16_MIN)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT16_MAX)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT32_MIN)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT32_MAX)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT64_MIN)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(INT64_MAX)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:ARRAY-INT\" : [\n"
@@ -926,9 +896,8 @@
}
// Array of Long Unsigned Integers: { [42, 170000, 40000000000] }
-void TestConverter_Array_UInts(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_UInts)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -936,14 +905,14 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(42)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(170000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(40000000000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(170000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(40000000000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:ARRAY-UINT\" : [\n"
@@ -959,9 +928,8 @@
// Array of Unsigned Integers, where each element represents MAX possible value for unsigned
// integere types uint8_t, uint16_t, uint32_t, uint64_t: [0xFF, 0xFFFF, 0xFFFFFFFF, 0xFFFFFFFF_FFFFFFFF]
-void TestConverter_Array_UIntsMax(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_UIntsMax)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -969,15 +937,15 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<uint8_t>(UINT8_MAX)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<uint16_t>(UINT16_MAX)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<uint32_t>(UINT32_MAX)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(UINT64_MAX)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<uint8_t>(UINT8_MAX)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<uint16_t>(UINT16_MAX)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<uint32_t>(UINT32_MAX)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(UINT64_MAX)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:ARRAY-UINT\" : [\n"
@@ -1001,9 +969,8 @@
}
// Array of Doubles: { [1.1, 134.2763, -12345.87] }
-void TestConverter_Array_Doubles(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Doubles)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1011,14 +978,14 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<double>(1.1)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<double>(134.2763)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<double>(-12345.87)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<double>(1.1)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<double>(134.2763)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<double>(-12345.87)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:ARRAY-DOUBLE\" : [\n"
@@ -1040,9 +1007,8 @@
}
// Array of Floats: { [1.1, 134.2763, -12345.87] }
-void TestConverter_Array_Floats(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Floats)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1052,16 +1018,14 @@
writer.Init(buf);
writer.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite,
- CHIP_NO_ERROR ==
- writer.StartContainer(TLV::ProfileTag(kImplicitProfileId, 1000), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<float>(1.1)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<float>(134.2763)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<float>(-12345.87)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ProfileTag(kImplicitProfileId, 1000), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<float>(1.1)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<float>(134.2763)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<float>(-12345.87)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1000:ARRAY-FLOAT\" : [\n"
@@ -1083,9 +1047,8 @@
}
// Array of Strings: ["ABC", "Options", "more"]
-void TestConverter_Array_Strings(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Strings)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1095,17 +1058,16 @@
writer.Init(buf);
writer.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite,
- CHIP_NO_ERROR ==
- writer.StartContainer(TLV::ProfileTag((100000 >> 16) & 0xFFFF, 0, 100000 & 0xFFFF), TLV::kTLVType_Array,
- containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::AnonymousTag(), "ABC"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::AnonymousTag(), "Options"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::AnonymousTag(), "more"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(
+ CHIP_NO_ERROR,
+ writer.StartContainer(TLV::ProfileTag((100000 >> 16) & 0xFFFF, 0, 100000 & 0xFFFF), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::AnonymousTag(), "ABC"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::AnonymousTag(), "Options"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::AnonymousTag(), "more"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"100000:ARRAY-STRING\" : [\n"
@@ -1120,9 +1082,8 @@
}
// Array of Booleans: [true, false, false]
-void TestConverter_Array_Booleans(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Booleans)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1130,14 +1091,14 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(255), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), false));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), false));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(255), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), false));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), false));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"255:ARRAY-BOOL\" : [\n"
@@ -1152,9 +1113,8 @@
}
// Array of Nulls: [null, null]
-void TestConverter_Array_Nulls(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Nulls)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1162,13 +1122,13 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutNull(TLV::AnonymousTag()));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutNull(TLV::AnonymousTag()));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutNull(TLV::AnonymousTag()));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutNull(TLV::AnonymousTag()));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1:ARRAY-NULL\" : [\n"
@@ -1182,9 +1142,8 @@
}
// Context tag 255 (max), Unsigned Integer, 1-octet value: {255 = 42U}
-void TestConverter_Struct_UInt(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Struct_UInt)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1192,12 +1151,12 @@
TLV::TLVType containerType2;
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(255), static_cast<uint8_t>(42)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(255), static_cast<uint8_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"value:0:STRUCT\" : {\n"
@@ -1216,9 +1175,8 @@
// Context and Common Profile tags, Unsigned Integer structure: {255 = 42, 256 = 17000, 65535 =
// 1, 65536 = 345678, 4294967295 = 500000000000}
-void TestConverter_Struct_MixedTags(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Struct_MixedTags)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1228,16 +1186,16 @@
writer.Init(buf);
writer.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(255), static_cast<uint64_t>(42)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ProfileTag(0x0001u, 0, 0), static_cast<uint64_t>(345678)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ProfileTag(kImplicitProfileId, 256), static_cast<uint64_t>(17000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ProfileTag(0xFFFFu, 0, 0xFFFFu), static_cast<uint64_t>(500000000000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ProfileTag(kImplicitProfileId, 65535), static_cast<uint64_t>(1)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(255), static_cast<uint64_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ProfileTag(0x0001u, 0, 0), static_cast<uint64_t>(345678)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ProfileTag(kImplicitProfileId, 256), static_cast<uint64_t>(17000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ProfileTag(0xFFFFu, 0, 0xFFFFu), static_cast<uint64_t>(500000000000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ProfileTag(kImplicitProfileId, 65535), static_cast<uint64_t>(1)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:STRUCT\" : {\n"
@@ -1254,9 +1212,8 @@
}
// Structure with mixed elements
-void TestConverter_Struct_MixedElements(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Struct_MixedElements)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1265,22 +1222,20 @@
char bytes[] = "Test ByteString Value";
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(0), static_cast<int64_t>(20)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(2), static_cast<uint64_t>(0)));
- NL_TEST_ASSERT(
- gSuite,
- CHIP_NO_ERROR ==
- writer.PutBytes(TLV::ContextTag(3), reinterpret_cast<uint8_t *>(bytes), static_cast<uint32_t>(strlen(bytes))));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::ContextTag(4), "hello"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(5), static_cast<int64_t>(-500000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(6), static_cast<double>(17.9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(7), static_cast<float>(17.9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(0), static_cast<int64_t>(20)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(2), static_cast<uint64_t>(0)));
+ EXPECT_EQ(CHIP_NO_ERROR,
+ writer.PutBytes(TLV::ContextTag(3), reinterpret_cast<uint8_t *>(bytes), static_cast<uint32_t>(strlen(bytes))));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::ContextTag(4), "hello"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(5), static_cast<int64_t>(-500000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(6), static_cast<double>(17.9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(7), static_cast<float>(17.9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"c:0:STRUCT\" : {\n"
@@ -1312,9 +1267,8 @@
}
// Array of structures with mixed elements
-void TestConverter_Array_Structures(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Array_Structures)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1327,39 +1281,33 @@
writer.Init(buf);
writer.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite,
- CHIP_NO_ERROR ==
- writer.StartContainer(TLV::ProfileTag(kImplicitProfileId, 1000), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(0), static_cast<int64_t>(20)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(2), static_cast<uint64_t>(0)));
- NL_TEST_ASSERT(
- gSuite,
- CHIP_NO_ERROR ==
- writer.PutBytes(TLV::ContextTag(3), reinterpret_cast<uint8_t *>(bytes1), static_cast<uint32_t>(strlen(bytes1))));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::ContextTag(4), "hello1"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(5), static_cast<int64_t>(-500000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(6), static_cast<double>(17.9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(7), static_cast<float>(17.9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(0), static_cast<int64_t>(-10)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), false));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(2), static_cast<uint64_t>(128)));
- NL_TEST_ASSERT(
- gSuite,
- CHIP_NO_ERROR ==
- writer.PutBytes(TLV::ContextTag(3), reinterpret_cast<uint8_t *>(bytes2), static_cast<uint32_t>(strlen(bytes2))));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::ContextTag(4), "hello2"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(5), static_cast<int64_t>(40000000000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(6), static_cast<double>(-1754.923)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(7), static_cast<float>(97.945)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ProfileTag(kImplicitProfileId, 1000), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(0), static_cast<int64_t>(20)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(2), static_cast<uint64_t>(0)));
+ EXPECT_EQ(CHIP_NO_ERROR,
+ writer.PutBytes(TLV::ContextTag(3), reinterpret_cast<uint8_t *>(bytes1), static_cast<uint32_t>(strlen(bytes1))));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::ContextTag(4), "hello1"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(5), static_cast<int64_t>(-500000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(6), static_cast<double>(17.9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(7), static_cast<float>(17.9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(0), static_cast<int64_t>(-10)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), false));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(2), static_cast<uint64_t>(128)));
+ EXPECT_EQ(CHIP_NO_ERROR,
+ writer.PutBytes(TLV::ContextTag(3), reinterpret_cast<uint8_t *>(bytes2), static_cast<uint32_t>(strlen(bytes2))));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::ContextTag(4), "hello2"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(5), static_cast<int64_t>(40000000000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(6), static_cast<double>(-1754.923)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(7), static_cast<float>(97.945)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"1000:ARRAY-STRUCT\": [\n"
@@ -1415,9 +1363,8 @@
}
// Top level with mixed elements
-void TestConverter_TopLevel_MixedElements(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_TopLevel_MixedElements)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1427,39 +1374,37 @@
char bytes[] = "Test array member 0";
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(0), static_cast<int64_t>(42)));
- NL_TEST_ASSERT(
- gSuite,
- CHIP_NO_ERROR ==
- writer.PutBytes(TLV::ContextTag(1), reinterpret_cast<uint8_t *>(bytes), static_cast<uint32_t>(strlen(bytes))));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(2), static_cast<double>(156.398)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(3), static_cast<uint64_t>(73709551615)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(4), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutNull(TLV::ContextTag(5)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(6), TLV::kTLVType_Structure, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::ContextTag(1), "John"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(2), static_cast<uint64_t>(34)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(3), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(4), TLV::kTLVType_Array, containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(5)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(10)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(5), TLV::kTLVType_Array, containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::AnonymousTag(), "Ammy"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::AnonymousTag(), "David"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::AnonymousTag(), "Larry"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(6), TLV::kTLVType_Array, containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), false));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(7), static_cast<float>(0.0)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(0), static_cast<int64_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR,
+ writer.PutBytes(TLV::ContextTag(1), reinterpret_cast<uint8_t *>(bytes), static_cast<uint32_t>(strlen(bytes))));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(2), static_cast<double>(156.398)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(3), static_cast<uint64_t>(73709551615)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(4), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutNull(TLV::ContextTag(5)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(6), TLV::kTLVType_Structure, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::ContextTag(1), "John"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(2), static_cast<uint64_t>(34)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(3), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(4), TLV::kTLVType_Array, containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(5)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(10)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(5), TLV::kTLVType_Array, containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::AnonymousTag(), "Ammy"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::AnonymousTag(), "David"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::AnonymousTag(), "Larry"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(6), TLV::kTLVType_Array, containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), false));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(7), static_cast<float>(0.0)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"value:0:INT\": 42,\n"
@@ -1525,9 +1470,8 @@
}
// Complex Structure from README
-void TestConverter_Structure_FromReadme(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Structure_FromReadme)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1540,53 +1484,51 @@
char bytes4[] = "Test Bytes";
writer.Init(buf);
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(0), static_cast<int8_t>(8)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Structure, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(0), static_cast<int8_t>(12)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), false));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::ContextTag(2), "example"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(2), static_cast<int64_t>(40000000000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(3), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(4), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(5), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<double>(1.1)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<double>(134.2763)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<double>(-12345.87)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), std::numeric_limits<double>::infinity()));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<double>(62534)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<double>(-62534)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(6), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutBytes(TLV::AnonymousTag(), bytes1, static_cast<uint32_t>(sizeof(bytes1))));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutBytes(TLV::AnonymousTag(), bytes2, static_cast<uint32_t>(sizeof(bytes2))));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutBytes(TLV::AnonymousTag(), bytes3, static_cast<uint32_t>(sizeof(bytes3))));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(
- gSuite,
- CHIP_NO_ERROR ==
- writer.PutBytes(TLV::ContextTag(7), reinterpret_cast<uint8_t *>(bytes4), static_cast<uint32_t>(strlen(bytes4))));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(8), static_cast<double>(17.9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(9), static_cast<float>(17.9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(10), -std::numeric_limits<float>::infinity()));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(11), TLV::kTLVType_Structure, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.PutString(TLV::ContextTag(1), "John"));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(2), static_cast<uint32_t>(34)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(3), true));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(4), TLV::kTLVType_Array, containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(5)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(9)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(10)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType3));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(0), static_cast<int8_t>(8)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Structure, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(0), static_cast<int8_t>(12)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), false));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::ContextTag(2), "example"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(2), static_cast<int64_t>(40000000000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(3), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(4), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(5), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<double>(1.1)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<double>(134.2763)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<double>(-12345.87)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), std::numeric_limits<double>::infinity()));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<double>(62534)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<double>(-62534)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(6), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutBytes(TLV::AnonymousTag(), bytes1, static_cast<uint32_t>(sizeof(bytes1))));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutBytes(TLV::AnonymousTag(), bytes2, static_cast<uint32_t>(sizeof(bytes2))));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutBytes(TLV::AnonymousTag(), bytes3, static_cast<uint32_t>(sizeof(bytes3))));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR,
+ writer.PutBytes(TLV::ContextTag(7), reinterpret_cast<uint8_t *>(bytes4), static_cast<uint32_t>(strlen(bytes4))));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(8), static_cast<double>(17.9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(9), static_cast<float>(17.9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(10), -std::numeric_limits<float>::infinity()));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(11), TLV::kTLVType_Structure, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutString(TLV::ContextTag(1), "John"));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(2), static_cast<uint32_t>(34)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(3), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(4), TLV::kTLVType_Array, containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(5)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(9)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int8_t>(10)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType3));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
std::string jsonString = "{\n"
" \"0:ARRAY-STRUCT\" : [\n"
@@ -1679,7 +1621,7 @@
CheckValidConversion(jsonString, tlvSpan, jsonExpected);
}
-void TestConverter_TlvToJson_ErrorCases(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_TlvToJson_ErrorCases)
{
CHIP_ERROR err;
TLV::TLVWriter writer;
@@ -1695,48 +1637,48 @@
uint8_t buf1[32];
writer.Init(buf1);
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::CommonTag(1), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), true));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::CommonTag(1), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
ByteSpan topLevelStructWithTag(buf1, writer.GetLengthWritten());
uint8_t buf2[32];
writer.Init(buf2);
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Array, containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), true));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Array, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
ByteSpan topLevelIsArray(buf2, writer.GetLengthWritten());
uint8_t buf3[32];
writer.Init(buf3);
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_List, containerType2));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Put(TLV::ContextTag(1), true));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_List, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ContextTag(1), true));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
ByteSpan usingList(buf3, writer.GetLengthWritten());
uint8_t buf8[32];
writer.Init(buf8);
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Array, containerType2));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(42)));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(-170000)));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(42456)));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(1), TLV::kTLVType_Array, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<int64_t>(-170000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::AnonymousTag(), static_cast<uint64_t>(42456)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
ByteSpan arrayWithMixedElements(buf8, writer.GetLengthWritten());
uint8_t buf9[32];
writer.Init(buf9);
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Put(TLV::ProfileTag(0xFEED, 234), static_cast<uint64_t>(42)));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(inSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ProfileTag(0xFEED, 234), static_cast<uint64_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
ByteSpan useFullyQualifiedTag(buf9, writer.GetLengthWritten());
// clang-format off
@@ -1755,11 +1697,11 @@
{
std::string jsonString;
err = TlvToJson(testCase.nEncodedTlv, jsonString);
- NL_TEST_ASSERT(inSuite, err == testCase.mExpectedResult);
+ EXPECT_EQ(err, testCase.mExpectedResult);
}
}
-void TestConverter_JsonToTlv_ErrorCases(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_JsonToTlv_ErrorCases)
{
CHIP_ERROR err;
@@ -1873,7 +1815,7 @@
uint8_t buf[256];
MutableByteSpan tlvSpan(buf);
err = JsonToTlv(testCase.mJsonString, tlvSpan);
- NL_TEST_ASSERT(inSuite, err == testCase.mExpectedResult);
+ EXPECT_EQ(err, testCase.mExpectedResult);
#if CHIP_CONFIG_ERROR_FORMAT_AS_STRING
if (err != testCase.mExpectedResult)
{
@@ -1888,9 +1830,8 @@
}
// Full Qualified Profile tags, Unsigned Integer structure: {65536 = 42, 4294901760 = 17000, 4294967295 = 500000000000}
-void TestConverter_Struct_MEITags(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestJsonToTlvToJson, TestConverter_Struct_MEITags)
{
- gSuite = inSuite;
uint8_t buf[256];
TLV::TLVWriter writer;
@@ -1900,14 +1841,14 @@
writer.Init(buf);
writer.ImplicitProfileId = kImplicitProfileId;
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ProfileTag(0xFFFFu, 0, 0), static_cast<uint64_t>(17000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ProfileTag(0x0001u, 0, 0), static_cast<uint64_t>(42)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Put(TLV::ProfileTag(0xFFFFu, 0, 0xFFFFu), static_cast<uint64_t>(500000000000)));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType2));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.EndContainer(containerType));
- NL_TEST_ASSERT(gSuite, CHIP_NO_ERROR == writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(TLV::ContextTag(0), TLV::kTLVType_Structure, containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ProfileTag(0xFFFFu, 0, 0), static_cast<uint64_t>(17000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ProfileTag(0x0001u, 0, 0), static_cast<uint64_t>(42)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Put(TLV::ProfileTag(0xFFFFu, 0, 0xFFFFu), static_cast<uint64_t>(500000000000)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType2));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(containerType));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
std::string jsonString = "{\n"
" \"0:STRUCT\" : {\n"
@@ -1920,84 +1861,4 @@
ByteSpan tlvSpan(buf, writer.GetLengthWritten());
CheckValidConversion(jsonString, tlvSpan, jsonString);
}
-
-int Initialize(void * apSuite)
-{
- VerifyOrReturnError(chip::Platform::MemoryInit() == CHIP_NO_ERROR, FAILURE);
- return SUCCESS;
-}
-
-int Finalize(void * aContext)
-{
- chip::Platform::MemoryShutdown();
- return SUCCESS;
-}
-
-const nlTest sTests[] = {
- NL_TEST_DEF("Test Json Tlv Converter - Boolean True", TestConverter_Boolean_True),
- NL_TEST_DEF("Test Json Tlv Converter - Signed Integer 1-Byte Positive", TestConverter_SignedInt_1BytePositive),
- NL_TEST_DEF("Test Json Tlv Converter - Signed Integer 1-Byte Negative", TestConverter_SignedInt_1ByteNegative),
- NL_TEST_DEF("Test Json Tlv Converter - Unsigned Integer 1-Byte", TestConverter_UnsignedInt_1Byte),
- NL_TEST_DEF("Test Json Tlv Converter - Signed Integer 2-Bytes", TestConverter_SignedInt_2Bytes),
- NL_TEST_DEF("Test Json Tlv Converter - Signed Integer 4-Bytes", TestConverter_SignedInt_4Bytes),
- NL_TEST_DEF("Test Json Tlv Converter - Signed Integer 8-Bytes", TestConverter_SignedInt_8Bytes),
- NL_TEST_DEF("Test Json Tlv Converter - Unsigned Integer 8-Bytes", TestConverter_UnsignedInt_8Bytes),
- NL_TEST_DEF("Test Json Tlv Converter - UTF-8 String Hello!", TestConverter_UTF8String_Hello),
- NL_TEST_DEF("Test Json Tlv Converter - Octet String", TestConverter_OctetString),
- NL_TEST_DEF("Test Json Tlv Converter - Empty Octet String", TestConverter_OctetString_Empty),
- NL_TEST_DEF("Test Json Tlv Converter - Null", TestConverter_Null),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Single Precision 0.0", TestConverter_Float_0),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Single Precision 1/3", TestConverter_Float_1third),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Single Precision 17.9", TestConverter_Float_17_9),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Single Precision Positive Infinity",
- TestConverter_Float_PositiveInfinity),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Single Precision Negative Infinity",
- TestConverter_Float_NegativeInfinity),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Double Precision 0.0", TestConverter_Double_0),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Double Precision 1/3", TestConverter_Double_1third),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Double Precision 17.9", TestConverter_Double_17_9),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Double Precision Positive Infinity",
- TestConverter_Double_PositiveInfinity),
- NL_TEST_DEF("Test Json Tlv Converter - Floating Point Double Precision Negative Infinity",
- TestConverter_Double_NegativeInfinity),
- NL_TEST_DEF("Test Json Tlv Converter - Structure Top-Level Empty", TestConverter_Structure_TopLevelEmpty),
- NL_TEST_DEF("Test Json Tlv Converter - Structure Nested Empty", TestConverter_Structure_NestedEmpty),
- NL_TEST_DEF("Test Json Tlv Converter - Array Empty", TestConverter_Array_Empty),
- NL_TEST_DEF("Test Json Tlv Converter - Array Empty with Implicit Profile Tag (length 2)",
- TestConverter_Array_Empty_ImplicitProfileTag2),
- NL_TEST_DEF("Test Json Tlv Converter - Array Empty with Implicit Profile Tag (length 4)",
- TestConverter_Array_Empty_ImplicitProfileTag4),
- NL_TEST_DEF("Test Json Tlv Converter - Two Signed Integers", TestConverter_IntsWithContextTags),
- NL_TEST_DEF("Test Json Tlv Converter - Structure With Two Signed Integers", TestConverter_Struct_IntsWithContextTags),
- NL_TEST_DEF("Test Json Tlv Converter - Array Of Signed Integers", TestConverter_Array_Ints),
- NL_TEST_DEF("Test Json Tlv Converter - Array Of Long Signed Integers", TestConverter_Array_Ints2),
- NL_TEST_DEF("Test Json Tlv Converter - Array Of Min/Max Signed Integers", TestConverter_Array_IntsMinMax),
- NL_TEST_DEF("Test Json Tlv Converter - Array Of Long Unsigned Integers", TestConverter_Array_UInts),
- NL_TEST_DEF("Test Json Tlv Converter - Array of Unsigned Integers with Max values", TestConverter_Array_UIntsMax),
- NL_TEST_DEF("Test Json Tlv Converter - Array Of Doubles", TestConverter_Array_Doubles),
- NL_TEST_DEF("Test Json Tlv Converter - Array Of Floats", TestConverter_Array_Floats),
- NL_TEST_DEF("Test Json Tlv Converter - Array Of Strings", TestConverter_Array_Strings),
- NL_TEST_DEF("Test Json Tlv Converter - Array Of Booleans", TestConverter_Array_Booleans),
- NL_TEST_DEF("Test Json Tlv Converter - Array Of Nulls", TestConverter_Array_Nulls),
- NL_TEST_DEF("Test Json Tlv Converter - Structure with Unsigned Integer", TestConverter_Struct_UInt),
- NL_TEST_DEF("Test Json Tlv Converter - Structure Elements with Mixed Tags", TestConverter_Struct_MixedTags),
- NL_TEST_DEF("Test Json Tlv Converter - Structure with Mixed Elements", TestConverter_Struct_MixedElements),
- NL_TEST_DEF("Test Json Tlv Converter - Array of Structures with Mixed Elements", TestConverter_Array_Structures),
- NL_TEST_DEF("Test Json Tlv Converter - Top-Level Structure with Mixed Elements", TestConverter_TopLevel_MixedElements),
- NL_TEST_DEF("Test Json Tlv Converter - Complex Structure from the README File", TestConverter_Structure_FromReadme),
- NL_TEST_DEF("Test Json Tlv Converter - Tlv to Json Error Cases", TestConverter_TlvToJson_ErrorCases),
- NL_TEST_DEF("Test Json Tlv Converter - Json To Tlv Error Cases", TestConverter_JsonToTlv_ErrorCases),
- NL_TEST_DEF("Test Json Tlv Converter - Structure with MEI Elements", TestConverter_Struct_MEITags),
- NL_TEST_SENTINEL()
-};
-
} // namespace
-
-int TestJsonToTlvToJson()
-{
- nlTestSuite theSuite = { "JsonToTlvToJson", sTests, Initialize, Finalize };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestJsonToTlvToJson)
diff --git a/src/lib/support/tests/TestTlvJson.cpp b/src/lib/support/tests/TestTlvJson.cpp
index 9d9a91e..83b538d 100644
--- a/src/lib/support/tests/TestTlvJson.cpp
+++ b/src/lib/support/tests/TestTlvJson.cpp
@@ -15,12 +15,12 @@
* limitations under the License.
*/
+#include <gtest/gtest.h>
+
#include <app-common/zap-generated/cluster-objects.h>
#include <app/data-model/Decode.h>
#include <app/data-model/Encode.h>
-#include <lib/support/UnitTestRegistration.h>
#include <lib/support/jsontlv/TlvJson.h>
-#include <nlunit-test.h>
#include <system/SystemPacketBuffer.h>
#include <system/TLVPacketBufferBackingStore.h>
@@ -33,7 +33,17 @@
System::TLVPacketBufferBackingStore gStore;
TLV::TLVWriter gWriter;
TLV::TLVReader gReader;
-nlTestSuite * gSuite;
+
+class TestTlvJson : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite()
+ {
+ (void) gStore.Release();
+ chip::Platform::MemoryShutdown();
+ }
+};
void SetupBuf()
{
@@ -88,25 +98,24 @@
SetupBuf();
err = DataModel::Encode(gWriter, TLV::AnonymousTag(), val);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = gWriter.Finalize();
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = SetupReader();
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
Json::Value d;
err = TlvToJson(gReader, d);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
bool matches = Matches(expectedJsonString, d);
- NL_TEST_ASSERT(gSuite, matches);
+ EXPECT_TRUE(matches);
}
-void TestConverter(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTlvJson, TestConverter)
{
- gSuite = inSuite;
EncodeAndValidate(static_cast<uint32_t>(30),
"{\n"
@@ -231,28 +240,4 @@
"}\n");
}
-int Initialize(void * apSuite)
-{
- VerifyOrReturnError(chip::Platform::MemoryInit() == CHIP_NO_ERROR, FAILURE);
- return SUCCESS;
-}
-
-int Finalize(void * aContext)
-{
- (void) gStore.Release();
- chip::Platform::MemoryShutdown();
- return SUCCESS;
-}
-
-const nlTest sTests[] = { NL_TEST_DEF("TestConverter", TestConverter), NL_TEST_SENTINEL() };
-
} // namespace
-
-int TestTlvJson()
-{
- nlTestSuite theSuite = { "TlvJson", sTests, Initialize, Finalize };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestTlvJson)
diff --git a/src/lib/support/tests/TestTlvToJson.cpp b/src/lib/support/tests/TestTlvToJson.cpp
index 1467744..b313b84 100644
--- a/src/lib/support/tests/TestTlvToJson.cpp
+++ b/src/lib/support/tests/TestTlvToJson.cpp
@@ -15,18 +15,18 @@
* limitations under the License.
*/
+#include <string>
+
+#include <gtest/gtest.h>
+
#include <app-common/zap-generated/cluster-objects.h>
#include <app/data-model/Decode.h>
#include <app/data-model/Encode.h>
-#include <lib/support/UnitTestRegistration.h>
#include <lib/support/jsontlv/TextFormat.h>
#include <lib/support/jsontlv/TlvToJson.h>
-#include <nlunit-test.h>
#include <system/SystemPacketBuffer.h>
#include <system/TLVPacketBufferBackingStore.h>
-#include <string>
-
namespace {
using namespace chip::Encoding;
@@ -36,7 +36,17 @@
System::TLVPacketBufferBackingStore gStore;
TLV::TLVWriter gWriter;
TLV::TLVReader gReader;
-nlTestSuite * gSuite;
+
+class TestTlvToJson : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite()
+ {
+ (void) gStore.Release();
+ chip::Platform::MemoryShutdown();
+ }
+};
void SetupBuf()
{
@@ -84,34 +94,32 @@
SetupBuf();
err = gWriter.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, container);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = DataModel::Encode(gWriter, TLV::ContextTag(1), val);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = gWriter.EndContainer(container);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = gWriter.Finalize();
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = SetupReader();
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
std::string jsonString;
err = TlvToJson(gReader, jsonString);
- NL_TEST_ASSERT(gSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
bool matches = Matches(expectedJsonString, jsonString);
- NL_TEST_ASSERT(gSuite, matches);
+ EXPECT_TRUE(matches);
}
-void TestConverter(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTlvToJson, TestConverter)
{
std::string jsonString;
- gSuite = inSuite;
-
jsonString = "{\n"
" \"1:UINT\" : 30\n"
"}\n";
@@ -236,28 +244,4 @@
EncodeAndValidate(structList, jsonString);
}
-int Initialize(void * apSuite)
-{
- VerifyOrReturnError(chip::Platform::MemoryInit() == CHIP_NO_ERROR, FAILURE);
- return SUCCESS;
-}
-
-int Finalize(void * aContext)
-{
- (void) gStore.Release();
- chip::Platform::MemoryShutdown();
- return SUCCESS;
-}
-
-const nlTest sTests[] = { NL_TEST_DEF("TestConverter", TestConverter), NL_TEST_SENTINEL() };
-
} // namespace
-
-int TestTlvToJson()
-{
- nlTestSuite theSuite = { "TlvToJson", sTests, Initialize, Finalize };
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestTlvToJson)
diff --git a/src/lib/support/tests/TestZclString.cpp b/src/lib/support/tests/TestZclString.cpp
index 3110c66..1317424 100644
--- a/src/lib/support/tests/TestZclString.cpp
+++ b/src/lib/support/tests/TestZclString.cpp
@@ -26,18 +26,24 @@
#include <stdlib.h>
#include <string.h>
+#include <gtest/gtest.h>
+
#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/ScopedBuffer.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
-
#include <lib/support/ZclString.h>
using namespace chip;
using namespace chip::Logging;
using namespace chip::Platform;
+class TestZclString : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
+
bool allCharactersSame(uint8_t zclString[])
{
int n = zclString[0];
@@ -48,132 +54,88 @@
return true;
}
-static void TestZclStringWhenBufferIsZero(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestZclString, TestZclStringWhenBufferIsZero)
{
uint8_t bufferMemory[1];
MutableByteSpan zclString(bufferMemory);
chip::Platform::ScopedMemoryBuffer<char> cString1;
- NL_TEST_ASSERT(inSuite, cString1.Calloc(1024));
+ EXPECT_TRUE(cString1.Calloc(1024));
memset(cString1.Get(), 'A', 1);
CHIP_ERROR err = MakeZclCharString(zclString, cString1.Get());
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG);
- NL_TEST_ASSERT(inSuite, zclString.data()[0] == 0);
+ EXPECT_EQ(err, CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG);
+ EXPECT_EQ(zclString.data()[0], 0);
}
-static void TestZclStringLessThanMaximumSize_Length_64(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestZclString, TestZclStringLessThanMaximumSize_Length_64)
{
uint8_t bufferMemory[256];
MutableByteSpan zclString(bufferMemory);
chip::Platform::ScopedMemoryBuffer<char> cString64;
- NL_TEST_ASSERT(inSuite, cString64.Calloc(1024));
+ EXPECT_TRUE(cString64.Calloc(1024));
memset(cString64.Get(), 'A', 64);
CHIP_ERROR err = MakeZclCharString(zclString, cString64.Get());
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, zclString.data()[0] == 64);
- NL_TEST_ASSERT(inSuite, allCharactersSame(zclString.data()) == true);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ EXPECT_EQ(zclString.data()[0], 64);
+ EXPECT_TRUE(allCharactersSame(zclString.data()));
}
-static void TestZclStringEqualsMaximumSize(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestZclString, TestZclStringEqualsMaximumSize)
{
uint8_t bufferMemory[256];
MutableByteSpan zclString(bufferMemory);
chip::Platform::ScopedMemoryBuffer<char> cString254;
- NL_TEST_ASSERT(inSuite, cString254.Calloc(1024));
+ EXPECT_TRUE(cString254.Calloc(1024));
memset(cString254.Get(), 'A', 254);
CHIP_ERROR err = MakeZclCharString(zclString, cString254.Get());
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, zclString.data()[0] == 254);
- NL_TEST_ASSERT(inSuite, allCharactersSame(zclString.data()) == true);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ EXPECT_EQ(zclString.data()[0], 254);
+ EXPECT_TRUE(allCharactersSame(zclString.data()));
}
-static void TestSizeZclStringBiggerThanMaximumSize_Length_255(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestZclString, TestSizeZclStringBiggerThanMaximumSize_Length_255)
{
uint8_t bufferMemory[256];
MutableByteSpan zclString(bufferMemory);
chip::Platform::ScopedMemoryBuffer<char> cString255;
- NL_TEST_ASSERT(inSuite, cString255.Calloc(1024));
+ EXPECT_TRUE(cString255.Calloc(1024));
memset(cString255.Get(), 'A', 255);
CHIP_ERROR err = MakeZclCharString(zclString, cString255.Get());
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG);
- NL_TEST_ASSERT(inSuite, zclString.data()[0] == 0);
+ EXPECT_EQ(err, CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG);
+ EXPECT_EQ(zclString.data()[0], 0);
}
-static void TestSizeZclStringBiggerThanMaximumSize_Length_256(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestZclString, TestSizeZclStringBiggerThanMaximumSize_Length_256)
{
uint8_t bufferMemory[256];
MutableByteSpan zclString(bufferMemory);
chip::Platform::ScopedMemoryBuffer<char> cString256;
- NL_TEST_ASSERT(inSuite, cString256.Calloc(1024));
+ EXPECT_TRUE(cString256.Calloc(1024));
memset(cString256.Get(), 'A', 256);
CHIP_ERROR err = MakeZclCharString(zclString, cString256.Get());
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG);
- NL_TEST_ASSERT(inSuite, zclString.data()[0] == 0);
+ EXPECT_EQ(err, CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG);
+ EXPECT_EQ(zclString.data()[0], 0);
}
-static void TestZclStringBiggerThanMaximumSize_Length_257(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestZclString, TestZclStringBiggerThanMaximumSize_Length_257)
{
uint8_t bufferMemory[257];
MutableByteSpan zclString(bufferMemory);
chip::Platform::ScopedMemoryBuffer<char> cString257;
- NL_TEST_ASSERT(inSuite, cString257.Calloc(1024));
+ EXPECT_TRUE(cString257.Calloc(1024));
memset(cString257.Get(), 'A', 257);
CHIP_ERROR err = MakeZclCharString(zclString, cString257.Get());
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG);
- NL_TEST_ASSERT(inSuite, zclString.data()[0] == 0);
+ EXPECT_EQ(err, CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG);
+ EXPECT_EQ(zclString.data()[0], 0);
}
-
-#define NL_TEST_DEF_FN(fn) NL_TEST_DEF("Test " #fn, fn)
-
-/**
- * Set up the test suite.
- */
-int TestZclString_Setup(void * inContext)
-{
- CHIP_ERROR error = MemoryInit();
- if (error != CHIP_NO_ERROR)
- return (FAILURE);
- return (SUCCESS);
-}
-
-/**
- * Tear down the test suite.
- */
-int TestZclString_Teardown(void * inContext)
-{
- MemoryShutdown();
- return (SUCCESS);
-}
-
-/**
- * Test Suite. It lists all the test functions.
- */
-static const nlTest sTests[] = { NL_TEST_DEF_FN(TestZclStringWhenBufferIsZero),
- NL_TEST_DEF_FN(TestZclStringLessThanMaximumSize_Length_64),
- NL_TEST_DEF_FN(TestZclStringEqualsMaximumSize),
- NL_TEST_DEF_FN(TestSizeZclStringBiggerThanMaximumSize_Length_255),
- NL_TEST_DEF_FN(TestSizeZclStringBiggerThanMaximumSize_Length_256),
- NL_TEST_DEF_FN(TestZclStringBiggerThanMaximumSize_Length_257),
- NL_TEST_SENTINEL() };
-
-int TestZclString()
-{
- nlTestSuite theSuite = { "CHIP Memory Allocation tests", &sTests[0], TestZclString_Setup, TestZclString_Teardown };
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestZclString)