Replaced nlunit-test with pw_unit_test in src/lib/core/ (#33062)
* Replaced nlunit-test with pw_unit_test in src/lib/core/
* Restyled by whitespace
* Restyled by clang-format
* Update openiotsdk test components
* Use ASSERT_EQ instead of VerifyOrDie
* Removed redundant nullptr checks
* Use EXPECT_STREQ
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/lib/core/tests/BUILD.gn b/src/lib/core/tests/BUILD.gn
index 1e3373d..3092ac3 100644
--- a/src/lib/core/tests/BUILD.gn
+++ b/src/lib/core/tests/BUILD.gn
@@ -14,12 +14,11 @@
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
-import("//build_overrides/nlunit_test.gni")
import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/build/chip/fuzz_test.gni")
-chip_test_suite_using_nltest("tests") {
+chip_test_suite("tests") {
output_name = "libCoreTests"
test_sources = [
@@ -39,9 +38,7 @@
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/core:vectortlv",
"${chip_root}/src/lib/support:test_utils",
- "${chip_root}/src/lib/support:testing_nlunit",
"${chip_root}/src/platform",
- "${nlunit_test_root}:nlunit-test",
]
}
diff --git a/src/lib/core/tests/TestCATValues.cpp b/src/lib/core/tests/TestCATValues.cpp
index 86551d0..a856390 100644
--- a/src/lib/core/tests/TestCATValues.cpp
+++ b/src/lib/core/tests/TestCATValues.cpp
@@ -16,14 +16,13 @@
* limitations under the License.
*/
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
#include <lib/core/CASEAuthTag.h>
using namespace chip;
-void TestEqualityOperator(nlTestSuite * inSuite, void * inContext)
+TEST(TestCATValues, TestEqualityOperator)
{
{
auto a = CATValues{ { 0x1111'0001, 0x2222'0002, 0x3333'0003 } };
@@ -37,7 +36,7 @@
{
for (auto & inner : candidates)
{
- NL_TEST_ASSERT(inSuite, inner == outer);
+ EXPECT_EQ(inner, outer);
}
}
}
@@ -49,7 +48,7 @@
{
for (auto & inner : candidates)
{
- NL_TEST_ASSERT(inSuite, inner == outer);
+ EXPECT_EQ(inner, outer);
}
}
}
@@ -65,13 +64,13 @@
{
for (auto & inner : candidates)
{
- NL_TEST_ASSERT(inSuite, inner == outer);
+ EXPECT_EQ(inner, outer);
}
}
}
}
-void TestInequalityOperator(nlTestSuite * inSuite, void * inContext)
+TEST(TestCATValues, TestInequalityOperator)
{
auto a = CATValues{ { 0x1111'0001 } };
auto b = CATValues{ { 0x1111'0001, 0x2222'0002 } };
@@ -103,12 +102,12 @@
{
continue;
}
- NL_TEST_ASSERT(inSuite, inner != outer);
+ EXPECT_NE(inner, outer);
}
}
}
-void TestValidity(nlTestSuite * inSuite, void * inContext)
+TEST(TestCATValues, TestValidity)
{
{
auto a = CATValues{ { 0x1111'0001, 0x2222'0002, 0x3333'0003 } };
@@ -119,7 +118,7 @@
CATValues validCandidates[] = { a, b, c, d, e };
for (auto & candidate : validCandidates)
{
- NL_TEST_ASSERT(inSuite, candidate.AreValid());
+ EXPECT_TRUE(candidate.AreValid());
}
}
@@ -130,117 +129,69 @@
CATValues invalidCandidates[] = { versionZero1, versionZero2, collidingId };
for (auto & candidate : invalidCandidates)
{
- NL_TEST_ASSERT(inSuite, !candidate.AreValid());
+ EXPECT_FALSE(candidate.AreValid());
}
}
}
-void TestMembership(nlTestSuite * inSuite, void * inContext)
+TEST(TestCATValues, TestMembership)
{
auto a = CATValues{ { 0x1111'0001 } };
auto b = CATValues{ { 0x1111'0001, 0x2222'0002 } };
auto c = CATValues{ { 0x1111'0001, 0x2222'0002, 0x3333'0003 } };
- NL_TEST_ASSERT(inSuite, a.Contains(0x1111'0001));
- NL_TEST_ASSERT(inSuite, a.GetNumTagsPresent() == 1);
- NL_TEST_ASSERT(inSuite, !a.Contains(0x1111'0002));
- NL_TEST_ASSERT(inSuite, !a.Contains(0x2222'0002));
- NL_TEST_ASSERT(inSuite, a.ContainsIdentifier(0x1111));
- NL_TEST_ASSERT(inSuite, !a.ContainsIdentifier(0x2222));
- NL_TEST_ASSERT(inSuite, a.AreValid());
+ EXPECT_TRUE(a.Contains(0x1111'0001));
+ EXPECT_EQ(a.GetNumTagsPresent(), 1u);
+ EXPECT_FALSE(a.Contains(0x1111'0002));
+ EXPECT_FALSE(a.Contains(0x2222'0002));
+ EXPECT_TRUE(a.ContainsIdentifier(0x1111));
+ EXPECT_FALSE(a.ContainsIdentifier(0x2222));
+ EXPECT_TRUE(a.AreValid());
- NL_TEST_ASSERT(inSuite, b.Contains(0x1111'0001));
- NL_TEST_ASSERT(inSuite, b.Contains(0x2222'0002));
- NL_TEST_ASSERT(inSuite, b.GetNumTagsPresent() == 2);
- NL_TEST_ASSERT(inSuite, b.ContainsIdentifier(0x1111));
- NL_TEST_ASSERT(inSuite, b.ContainsIdentifier(0x2222));
- NL_TEST_ASSERT(inSuite, b.AreValid());
+ EXPECT_TRUE(b.Contains(0x1111'0001));
+ EXPECT_TRUE(b.Contains(0x2222'0002));
+ EXPECT_EQ(b.GetNumTagsPresent(), 2u);
+ EXPECT_TRUE(b.ContainsIdentifier(0x1111));
+ EXPECT_TRUE(b.ContainsIdentifier(0x2222));
+ EXPECT_TRUE(b.AreValid());
- NL_TEST_ASSERT(inSuite, c.Contains(0x1111'0001));
- NL_TEST_ASSERT(inSuite, c.Contains(0x2222'0002));
- NL_TEST_ASSERT(inSuite, c.Contains(0x3333'0003));
- NL_TEST_ASSERT(inSuite, c.GetNumTagsPresent() == 3);
- NL_TEST_ASSERT(inSuite, c.ContainsIdentifier(0x1111));
- NL_TEST_ASSERT(inSuite, c.ContainsIdentifier(0x2222));
- NL_TEST_ASSERT(inSuite, c.ContainsIdentifier(0x3333));
- NL_TEST_ASSERT(inSuite, c.AreValid());
+ EXPECT_TRUE(c.Contains(0x1111'0001));
+ EXPECT_TRUE(c.Contains(0x2222'0002));
+ EXPECT_TRUE(c.Contains(0x3333'0003));
+ EXPECT_EQ(c.GetNumTagsPresent(), 3u);
+ EXPECT_TRUE(c.ContainsIdentifier(0x1111));
+ EXPECT_TRUE(c.ContainsIdentifier(0x2222));
+ EXPECT_TRUE(c.ContainsIdentifier(0x3333));
+ EXPECT_TRUE(c.AreValid());
}
-void TestSubjectMatching(nlTestSuite * inSuite, void * inContext)
+TEST(TestCATValues, TestSubjectMatching)
{
// Check operational node IDs don't match
auto a = CATValues{ { 0x2222'0002 } };
- NL_TEST_ASSERT(inSuite, !a.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0x0001'0002'0003'0004ull)));
- NL_TEST_ASSERT(inSuite, !a.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0x0001'0002'2222'0002ull)));
+ EXPECT_FALSE(a.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0x0001'0002'0003'0004ull)));
+ EXPECT_FALSE(a.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0x0001'0002'2222'0002ull)));
auto b = CATValues{ { 0x1111'0001 } };
- NL_TEST_ASSERT(inSuite, b.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'1111'0001ull)));
- NL_TEST_ASSERT(inSuite, !b.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'1111'0002ull)));
+ EXPECT_TRUE(b.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'1111'0001ull)));
+ EXPECT_FALSE(b.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'1111'0002ull)));
auto c = CATValues{ { 0x1111'0001, 0x2222'0002 } };
- NL_TEST_ASSERT(inSuite, c.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'2222'0001ull)));
- NL_TEST_ASSERT(inSuite, c.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'2222'0002ull)));
- NL_TEST_ASSERT(inSuite, !c.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'2222'0003ull)));
+ EXPECT_TRUE(c.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'2222'0001ull)));
+ EXPECT_TRUE(c.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'2222'0002ull)));
+ EXPECT_FALSE(c.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'2222'0003ull)));
auto d = CATValues{ { 0x1111'0001, 0x2222'0002, 0x3333'0003 } };
- NL_TEST_ASSERT(inSuite, d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0001ull)));
- NL_TEST_ASSERT(inSuite, d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0002ull)));
- NL_TEST_ASSERT(inSuite, d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0003ull)));
- NL_TEST_ASSERT(inSuite, !d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0004ull)));
- NL_TEST_ASSERT(inSuite, !d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'ffffull)));
+ EXPECT_TRUE(d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0001ull)));
+ EXPECT_TRUE(d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0002ull)));
+ EXPECT_TRUE(d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0003ull)));
+ EXPECT_FALSE(d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0004ull)));
+ EXPECT_FALSE(d.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'ffffull)));
auto e = CATValues{ { 0x1111'0001, 0x2222'0002, 0x3333'ffff } };
- NL_TEST_ASSERT(inSuite, e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0001ull)));
- NL_TEST_ASSERT(inSuite, e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0002ull)));
- NL_TEST_ASSERT(inSuite, e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0003ull)));
- NL_TEST_ASSERT(inSuite, e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0004ull)));
- NL_TEST_ASSERT(inSuite, e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'ffffull)));
+ EXPECT_TRUE(e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0001ull)));
+ EXPECT_TRUE(e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0002ull)));
+ EXPECT_TRUE(e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0003ull)));
+ EXPECT_TRUE(e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'0004ull)));
+ EXPECT_TRUE(e.CheckSubjectAgainstCATs(static_cast<chip::NodeId>(0xFFFF'FFFD'3333'ffffull)));
}
-// Test Suite
-
-/**
- * Test Suite that lists all the test functions.
- */
-// clang-format off
-static const nlTest sTests[] =
-{
- NL_TEST_DEF("Equality operator", TestEqualityOperator),
- NL_TEST_DEF("Inequality operator", TestInequalityOperator),
- NL_TEST_DEF("Validity checks", TestValidity),
- NL_TEST_DEF("Set operations", TestMembership),
- NL_TEST_DEF("Subject matching for ACL", TestSubjectMatching),
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-int TestCATValues_Setup(void * inContext)
-{
- return SUCCESS;
-}
-
-/**
- * Tear down the test suite.
- */
-int TestCATValues_Teardown(void * inContext)
-{
- return SUCCESS;
-}
-
-int TestCATValues()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "CATValues",
- &sTests[0],
- TestCATValues_Setup,
- TestCATValues_Teardown,
- };
- // clang-format on
-
- nlTestRunner(&theSuite, nullptr);
-
- return (nlTestRunnerStats(&theSuite));
-}
-
-CHIP_REGISTER_TEST_SUITE(TestCATValues)
diff --git a/src/lib/core/tests/TestCHIPCallback.cpp b/src/lib/core/tests/TestCHIPCallback.cpp
index fe12cfd..111a8a7 100644
--- a/src/lib/core/tests/TestCHIPCallback.cpp
+++ b/src/lib/core/tests/TestCHIPCallback.cpp
@@ -21,11 +21,11 @@
* This file implements a test for CHIP Callback
*
*/
+#include <gtest/gtest.h>
+
#include <lib/core/CHIPCallback.h>
#include <lib/support/CHIPMem.h>
-#include <lib/support/UnitTestRegistration.h>
-
-#include <nlunit-test.h>
+#include <lib/support/CodeUtils.h>
using namespace chip::Callback;
@@ -87,7 +87,14 @@
ca->Cancel();
}
-static void ResumerTest(nlTestSuite * inSuite, void * inContext)
+class TestCHIPCallback : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
+
+TEST_F(TestCHIPCallback, ResumerTest)
{
int n = 1;
Callback<> cb(reinterpret_cast<CallFn>(increment), &n);
@@ -99,21 +106,21 @@
resumer.Dispatch();
resumer.Resume(&cb);
resumer.Dispatch();
- NL_TEST_ASSERT(inSuite, n == 3);
+ EXPECT_EQ(n, 3);
n = 1;
// test cb->Cancel() cancels
resumer.Resume(&cb);
cb.Cancel();
resumer.Dispatch();
- NL_TEST_ASSERT(inSuite, n == 1);
+ EXPECT_EQ(n, 1);
n = 1;
// Cancel cb before Dispatch() gets around to us (tests FIFO *and* cancel() from readylist)
resumer.Resume(&cancelcb);
resumer.Resume(&cb);
resumer.Dispatch();
- NL_TEST_ASSERT(inSuite, n == 1);
+ EXPECT_EQ(n, 1);
n = 1;
// 2nd Resume() cancels first registration
@@ -121,7 +128,7 @@
resumer.Resume(&cb); // cancels previous registration
resumer.Dispatch(); // runs the list
resumer.Dispatch(); // runs an empty list
- NL_TEST_ASSERT(inSuite, n == 2);
+ EXPECT_EQ(n, 2);
n = 1;
// Resume() during Dispatch() runs only once, but enqueues for next dispatch
@@ -130,9 +137,9 @@
resumer.Resume(&cb);
resumer.Resume(&resumecb);
resumer.Dispatch();
- NL_TEST_ASSERT(inSuite, n == 2);
+ EXPECT_EQ(n, 2);
resumer.Dispatch();
- NL_TEST_ASSERT(inSuite, n == 3);
+ EXPECT_EQ(n, 3);
Callback<> * pcb = chip::Platform::New<Callback<>>(reinterpret_cast<CallFn>(increment), &n);
@@ -140,12 +147,12 @@
// cancel on destruct
resumer.Resume(pcb);
resumer.Dispatch();
- NL_TEST_ASSERT(inSuite, n == 2);
+ EXPECT_EQ(n, 2);
resumer.Resume(pcb);
chip::Platform::Delete(pcb);
resumer.Dispatch();
- NL_TEST_ASSERT(inSuite, n == 2);
+ EXPECT_EQ(n, 2);
}
/**
@@ -190,7 +197,7 @@
*n += by;
}
-static void NotifierTest(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestCHIPCallback, NotifierTest)
{
int n = 1;
Callback<Notifier::NotifyFn> cb(reinterpret_cast<Notifier::NotifyFn>(increment_by), &n);
@@ -205,68 +212,15 @@
notifier.Register(&cb);
notifier.Notify(1);
notifier.Notify(8);
- NL_TEST_ASSERT(inSuite, n == 10);
+ EXPECT_EQ(n, 10);
n = 1;
// Cancel cb before Dispatch() gets around to us (tests FIFO *and* cancel() from readylist)
notifier.Register(&cancelcb);
notifier.Register(&cb);
notifier.Notify(8);
- NL_TEST_ASSERT(inSuite, n == 1);
+ EXPECT_EQ(n, 1);
cb.Cancel();
cancelcb.Cancel();
}
-
-/**
- * Set up the test suite.
- */
-int TestCHIPCallback_Setup(void * inContext)
-{
- CHIP_ERROR error = chip::Platform::MemoryInit();
- if (error != CHIP_NO_ERROR)
- return FAILURE;
- return SUCCESS;
-}
-
-/**
- * Tear down the test suite.
- */
-int TestCHIPCallback_Teardown(void * inContext)
-{
- chip::Platform::MemoryShutdown();
- return SUCCESS;
-}
-
-/**
- * Test Suite. It lists all the test functions.
- */
-
-// clang-format off
-static const nlTest sTests[] =
-{
- NL_TEST_DEF("ResumerTest", ResumerTest),
- NL_TEST_DEF("NotifierTest", NotifierTest),
-
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-int TestCHIPCallback()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "CHIPCallback",
- &sTests[0],
- TestCHIPCallback_Setup,
- TestCHIPCallback_Teardown
- };
- // clang-format on
-
- nlTestRunner(&theSuite, nullptr);
-
- return (nlTestRunnerStats(&theSuite));
-}
-
-CHIP_REGISTER_TEST_SUITE(TestCHIPCallback)
diff --git a/src/lib/core/tests/TestCHIPErrorStr.cpp b/src/lib/core/tests/TestCHIPErrorStr.cpp
index 8f21a2e..730a484 100644
--- a/src/lib/core/tests/TestCHIPErrorStr.cpp
+++ b/src/lib/core/tests/TestCHIPErrorStr.cpp
@@ -28,12 +28,10 @@
#include <stdint.h>
#include <string.h>
+#include <gtest/gtest.h>
+
#include <lib/core/CHIPError.h>
#include <lib/core/ErrorStr.h>
-#include <lib/support/UnitTestContext.h>
-#include <lib/support/UnitTestRegistration.h>
-
-#include <nlunit-test.h>
using namespace chip;
@@ -169,7 +167,7 @@
};
// clang-format on
-static void CheckCoreErrorStr(nlTestSuite * inSuite, void * inContext)
+TEST(TestCHIPErrorStr, CheckCoreErrorStr)
{
// Register the layer error formatter
@@ -183,52 +181,19 @@
// Assert that the error string contains the error number in hex.
snprintf(expectedText, sizeof(expectedText), "%08" PRIX32, static_cast<uint32_t>(err.AsInteger()));
- NL_TEST_ASSERT(inSuite, (strstr(errStr, expectedText) != nullptr));
+ EXPECT_TRUE((strstr(errStr, expectedText) != nullptr));
#if !CHIP_CONFIG_SHORT_ERROR_STR
// Assert that the error string contains a description, which is signaled
// by a presence of a colon proceeding the description.
- NL_TEST_ASSERT(inSuite, (strchr(errStr, ':') != nullptr));
+ EXPECT_TRUE((strchr(errStr, ':') != nullptr));
#endif // !CHIP_CONFIG_SHORT_ERROR_STR
#if CHIP_CONFIG_ERROR_SOURCE
// GetFile() should be relative to ${chip_root}
char const * const file = err.GetFile();
- NL_TEST_EXIT_ON_FAILED_ASSERT(inSuite, file != nullptr);
- NL_TEST_ASSERT(inSuite, strstr(file, "src/lib/core/") == file);
+ ASSERT_NE(file, nullptr);
+ EXPECT_EQ(strstr(file, "src/lib/core/"), file);
#endif // CHIP_CONFIG_ERROR_SOURCE
}
}
-
-/**
- * Test Suite. It lists all the test functions.
- */
-
-// clang-format off
-static const nlTest sTests[] =
-{
- NL_TEST_DEF("CoreErrorStr", CheckCoreErrorStr),
-
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-int TestCHIPErrorStr()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "Test CHIP_ERROR string conversions",
- &sTests[0],
- nullptr,
- nullptr
- };
- // clang-format on
-
- // Run test suite against one context.
- nlTestRunner(&theSuite, nullptr);
-
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestCHIPErrorStr)
diff --git a/src/lib/core/tests/TestOTAImageHeader.cpp b/src/lib/core/tests/TestOTAImageHeader.cpp
index 0a05799..8413dbd 100644
--- a/src/lib/core/tests/TestOTAImageHeader.cpp
+++ b/src/lib/core/tests/TestOTAImageHeader.cpp
@@ -17,9 +17,8 @@
*/
#include <lib/core/OTAImageHeader.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
using namespace chip;
@@ -70,42 +69,49 @@
0x42, 0x36, 0x67, 0xdb, 0xb7, 0x3b, 0x6e, 0x15, 0x45, 0x4f, 0x0e, 0xb1, 0xab,
0xd4, 0x59, 0x7f, 0x9a, 0x1b, 0x07, 0x8e, 0x3f, 0x5b, 0x5a, 0x6b, 0xc7, 0x18 };
-void TestHappyPath(nlTestSuite * inSuite, void * inContext)
+class TestOTAImageHeader : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
+
+TEST_F(TestOTAImageHeader, TestHappyPath)
{
ByteSpan buffer(kOtaImage);
OTAImageHeader header;
OTAImageHeaderParser parser;
parser.Init();
- NL_TEST_ASSERT(inSuite, parser.AccumulateAndDecode(buffer, header) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, parser.IsInitialized());
- NL_TEST_ASSERT(inSuite, buffer.size() == strlen("test payload"));
- NL_TEST_ASSERT(inSuite, header.mVendorId == 0xDEAD);
- NL_TEST_ASSERT(inSuite, header.mProductId == 0xBEEF);
- NL_TEST_ASSERT(inSuite, header.mSoftwareVersion == 0xFFFFFFFF);
- NL_TEST_ASSERT(inSuite, header.mSoftwareVersionString.data_equal("1.0"_span));
- NL_TEST_ASSERT(inSuite, header.mPayloadSize == strlen("test payload"));
- NL_TEST_ASSERT(inSuite, header.mMinApplicableVersion.HasValue());
- NL_TEST_ASSERT(inSuite, header.mMinApplicableVersion.Value() == 1);
- NL_TEST_ASSERT(inSuite, header.mMaxApplicableVersion.HasValue());
- NL_TEST_ASSERT(inSuite, header.mMaxApplicableVersion.Value() == 2);
- NL_TEST_ASSERT(inSuite, header.mReleaseNotesURL.data_equal("https://rn"_span));
- NL_TEST_ASSERT(inSuite, header.mImageDigestType == OTAImageDigestType::kSha256);
- NL_TEST_ASSERT(inSuite, header.mImageDigest.size() == 256 / 8);
+ EXPECT_EQ(parser.AccumulateAndDecode(buffer, header), CHIP_NO_ERROR);
+ EXPECT_TRUE(parser.IsInitialized());
+ EXPECT_EQ(buffer.size(), strlen("test payload"));
+ EXPECT_EQ(header.mVendorId, 0xDEAD);
+ EXPECT_EQ(header.mProductId, 0xBEEF);
+ EXPECT_EQ(header.mSoftwareVersion, 0xFFFFFFFF);
+ EXPECT_TRUE(header.mSoftwareVersionString.data_equal("1.0"_span));
+ EXPECT_EQ(header.mPayloadSize, strlen("test payload"));
+ EXPECT_TRUE(header.mMinApplicableVersion.HasValue());
+ EXPECT_EQ(header.mMinApplicableVersion.Value(), 1u);
+ EXPECT_TRUE(header.mMaxApplicableVersion.HasValue());
+ EXPECT_EQ(header.mMaxApplicableVersion.Value(), 2u);
+ EXPECT_TRUE(header.mReleaseNotesURL.data_equal("https://rn"_span));
+ EXPECT_EQ(header.mImageDigestType, OTAImageDigestType::kSha256);
+ EXPECT_EQ(header.mImageDigest.size(), 256u / 8);
}
-void TestEmptyBuffer(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestOTAImageHeader, TestEmptyBuffer)
{
ByteSpan buffer{};
OTAImageHeader header;
OTAImageHeaderParser parser;
parser.Init();
- NL_TEST_ASSERT(inSuite, parser.AccumulateAndDecode(buffer, header) == CHIP_ERROR_BUFFER_TOO_SMALL);
- NL_TEST_ASSERT(inSuite, parser.IsInitialized());
+ EXPECT_EQ(parser.AccumulateAndDecode(buffer, header), CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_TRUE(parser.IsInitialized());
}
-void TestInvalidFileIdentifier(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestOTAImageHeader, TestInvalidFileIdentifier)
{
static const uint8_t otaImage[] = { 0x1e, 0xf1, 0xee, 0x1c, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
@@ -115,37 +121,37 @@
OTAImageHeaderParser parser;
parser.Init();
- NL_TEST_ASSERT(inSuite, parser.AccumulateAndDecode(buffer, header) == CHIP_ERROR_INVALID_FILE_IDENTIFIER);
- NL_TEST_ASSERT(inSuite, !parser.IsInitialized());
+ EXPECT_EQ(parser.AccumulateAndDecode(buffer, header), CHIP_ERROR_INVALID_FILE_IDENTIFIER);
+ EXPECT_FALSE(parser.IsInitialized());
}
-void TestTooSmallHeader(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestOTAImageHeader, TestTooSmallHeader)
{
ByteSpan buffer(kMinOtaImage);
OTAImageHeader header;
OTAImageHeaderParser parser;
parser.Init();
- NL_TEST_ASSERT(inSuite, parser.AccumulateAndDecode(buffer, header) == CHIP_NO_ERROR);
+ EXPECT_EQ(parser.AccumulateAndDecode(buffer, header), CHIP_NO_ERROR);
buffer = ByteSpan(kMinOtaImage, sizeof(kMinOtaImage) - 1);
parser.Init();
- NL_TEST_ASSERT(inSuite, parser.AccumulateAndDecode(buffer, header) == CHIP_ERROR_BUFFER_TOO_SMALL);
- NL_TEST_ASSERT(inSuite, parser.IsInitialized());
+ EXPECT_EQ(parser.AccumulateAndDecode(buffer, header), CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_TRUE(parser.IsInitialized());
}
-void TestMissingMandatoryField(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestOTAImageHeader, TestMissingMandatoryField)
{
ByteSpan buffer(kMinOtaImageWithoutVendor);
OTAImageHeader header;
OTAImageHeaderParser parser;
parser.Init();
- NL_TEST_ASSERT(inSuite, parser.AccumulateAndDecode(buffer, header) == CHIP_ERROR_UNEXPECTED_TLV_ELEMENT);
- NL_TEST_ASSERT(inSuite, !parser.IsInitialized());
+ EXPECT_EQ(parser.AccumulateAndDecode(buffer, header), CHIP_ERROR_UNEXPECTED_TLV_ELEMENT);
+ EXPECT_FALSE(parser.IsInitialized());
}
-void TestSmallBlocks(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestOTAImageHeader, TestSmallBlocks)
{
constexpr size_t kImageSize = sizeof(kOtaImage);
@@ -164,55 +170,20 @@
error = parser.AccumulateAndDecode(block, header);
}
- NL_TEST_ASSERT(inSuite, error == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, parser.IsInitialized());
- NL_TEST_ASSERT(inSuite, header.mVendorId == 0xDEAD);
- NL_TEST_ASSERT(inSuite, header.mProductId == 0xBEEF);
- NL_TEST_ASSERT(inSuite, header.mSoftwareVersion == 0xFFFFFFFF);
- NL_TEST_ASSERT(inSuite, header.mSoftwareVersionString.data_equal("1.0"_span));
- NL_TEST_ASSERT(inSuite, header.mPayloadSize == strlen("test payload"));
- NL_TEST_ASSERT(inSuite, header.mMinApplicableVersion.HasValue());
- NL_TEST_ASSERT(inSuite, header.mMinApplicableVersion.Value() == 1);
- NL_TEST_ASSERT(inSuite, header.mMaxApplicableVersion.HasValue());
- NL_TEST_ASSERT(inSuite, header.mMaxApplicableVersion.Value() == 2);
- NL_TEST_ASSERT(inSuite, header.mReleaseNotesURL.data_equal("https://rn"_span));
- NL_TEST_ASSERT(inSuite, header.mImageDigestType == OTAImageDigestType::kSha256);
- NL_TEST_ASSERT(inSuite, header.mImageDigest.size() == 256 / 8);
+ EXPECT_EQ(error, CHIP_NO_ERROR);
+ EXPECT_TRUE(parser.IsInitialized());
+ EXPECT_EQ(header.mVendorId, 0xDEAD);
+ EXPECT_EQ(header.mProductId, 0xBEEF);
+ EXPECT_EQ(header.mSoftwareVersion, 0xFFFFFFFF);
+ EXPECT_TRUE(header.mSoftwareVersionString.data_equal("1.0"_span));
+ EXPECT_EQ(header.mPayloadSize, strlen("test payload"));
+ EXPECT_TRUE(header.mMinApplicableVersion.HasValue());
+ EXPECT_EQ(header.mMinApplicableVersion.Value(), 1u);
+ EXPECT_TRUE(header.mMaxApplicableVersion.HasValue());
+ EXPECT_EQ(header.mMaxApplicableVersion.Value(), 2u);
+ EXPECT_TRUE(header.mReleaseNotesURL.data_equal("https://rn"_span));
+ EXPECT_EQ(header.mImageDigestType, OTAImageDigestType::kSha256);
+ EXPECT_EQ(header.mImageDigest.size(), 256u / 8);
}
}
-
-// clang-format off
-const nlTest sTests[] =
-{
- NL_TEST_DEF("Test happy path", TestHappyPath),
- NL_TEST_DEF("Test empty buffer", TestEmptyBuffer),
- NL_TEST_DEF("Test invalid File Identifier", TestInvalidFileIdentifier),
- NL_TEST_DEF("Test too small header", TestTooSmallHeader),
- NL_TEST_DEF("Test missing mandatory field", TestMissingMandatoryField),
- NL_TEST_DEF("Test small blocks", TestSmallBlocks),
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-int SetupSuite(void * inContext)
-{
- return Platform::MemoryInit() == CHIP_NO_ERROR ? SUCCESS : FAILURE;
-}
-
-int TearDownSuite(void * inContext)
-{
- Platform::MemoryShutdown();
- return SUCCESS;
-}
-
} // namespace
-
-int TestOTAImageHeader()
-{
- nlTestSuite theSuite = { "OTA Image header test", &sTests[0], SetupSuite, TearDownSuite };
- nlTestRunner(&theSuite, nullptr);
-
- return nlTestRunnerStats(&theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestOTAImageHeader)
diff --git a/src/lib/core/tests/TestOptional.cpp b/src/lib/core/tests/TestOptional.cpp
index b54d8de..9a0e95f 100644
--- a/src/lib/core/tests/TestOptional.cpp
+++ b/src/lib/core/tests/TestOptional.cpp
@@ -30,9 +30,8 @@
#include <lib/core/Optional.h>
#include <lib/support/Span.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
using namespace chip;
@@ -76,7 +75,7 @@
int Count::created;
int Count::destroyed;
-static void TestBasic(nlTestSuite * inSuite, void * inContext)
+TEST(TestOptional, TestBasic)
{
// Set up our test Count objects, which will mess with counts, before we reset the
// counts.
@@ -86,107 +85,107 @@
{
auto testOptional = Optional<Count>::Value(100);
- NL_TEST_ASSERT(inSuite, Count::created == 1 && Count::destroyed == 0);
- NL_TEST_ASSERT(inSuite, testOptional.HasValue() && testOptional.Value().m == 100);
- NL_TEST_ASSERT(inSuite, testOptional == c100);
- NL_TEST_ASSERT(inSuite, testOptional != c101);
- NL_TEST_ASSERT(inSuite, testOptional != c102);
+ EXPECT_TRUE(Count::created == 1 && Count::destroyed == 0);
+ EXPECT_TRUE(testOptional.HasValue() && testOptional.Value().m == 100);
+ EXPECT_EQ(testOptional, c100);
+ EXPECT_NE(testOptional, c101);
+ EXPECT_NE(testOptional, c102);
testOptional.ClearValue();
- NL_TEST_ASSERT(inSuite, Count::created == 1 && Count::destroyed == 1);
- NL_TEST_ASSERT(inSuite, !testOptional.HasValue());
- NL_TEST_ASSERT(inSuite, testOptional != c100);
- NL_TEST_ASSERT(inSuite, testOptional != c101);
- NL_TEST_ASSERT(inSuite, testOptional != c102);
+ EXPECT_TRUE(Count::created == 1 && Count::destroyed == 1);
+ EXPECT_FALSE(testOptional.HasValue());
+ EXPECT_NE(testOptional, c100);
+ EXPECT_NE(testOptional, c101);
+ EXPECT_NE(testOptional, c102);
testOptional.SetValue(Count(101));
- NL_TEST_ASSERT(inSuite, Count::created == 3 && Count::destroyed == 2);
- NL_TEST_ASSERT(inSuite, testOptional.HasValue() && testOptional.Value().m == 101);
- NL_TEST_ASSERT(inSuite, testOptional != c100);
- NL_TEST_ASSERT(inSuite, testOptional == c101);
- NL_TEST_ASSERT(inSuite, testOptional != c102);
+ EXPECT_TRUE(Count::created == 3 && Count::destroyed == 2);
+ EXPECT_TRUE(testOptional.HasValue() && testOptional.Value().m == 101);
+ EXPECT_NE(testOptional, c100);
+ EXPECT_EQ(testOptional, c101);
+ EXPECT_NE(testOptional, c102);
testOptional.Emplace(102);
- NL_TEST_ASSERT(inSuite, Count::created == 4 && Count::destroyed == 3);
- NL_TEST_ASSERT(inSuite, testOptional.HasValue() && testOptional.Value().m == 102);
- NL_TEST_ASSERT(inSuite, testOptional != c100);
- NL_TEST_ASSERT(inSuite, testOptional != c101);
- NL_TEST_ASSERT(inSuite, testOptional == c102);
+ EXPECT_TRUE(Count::created == 4 && Count::destroyed == 3);
+ EXPECT_TRUE(testOptional.HasValue() && testOptional.Value().m == 102);
+ EXPECT_NE(testOptional, c100);
+ EXPECT_NE(testOptional, c101);
+ EXPECT_EQ(testOptional, c102);
}
// Our test Count objects are still in scope here.
- NL_TEST_ASSERT(inSuite, Count::created == 4 && Count::destroyed == 4);
+ EXPECT_TRUE(Count::created == 4 && Count::destroyed == 4);
}
-static void TestMake(nlTestSuite * inSuite, void * inContext)
+TEST(TestOptional, TestMake)
{
Count::ResetCounter();
{
auto testOptional = MakeOptional<Count>(200);
- NL_TEST_ASSERT(inSuite, Count::created == 1 && Count::destroyed == 0);
- NL_TEST_ASSERT(inSuite, testOptional.HasValue() && testOptional.Value().m == 200);
+ EXPECT_TRUE(Count::created == 1 && Count::destroyed == 0);
+ EXPECT_TRUE(testOptional.HasValue() && testOptional.Value().m == 200);
}
- NL_TEST_ASSERT(inSuite, Count::created == 1 && Count::destroyed == 1);
+ EXPECT_TRUE(Count::created == 1 && Count::destroyed == 1);
}
-static void TestCopy(nlTestSuite * inSuite, void * inContext)
+TEST(TestOptional, TestCopy)
{
Count::ResetCounter();
{
auto testSrc = Optional<Count>::Value(300);
- NL_TEST_ASSERT(inSuite, Count::created == 1 && Count::destroyed == 0);
- NL_TEST_ASSERT(inSuite, testSrc.HasValue() && testSrc.Value().m == 300);
+ EXPECT_TRUE(Count::created == 1 && Count::destroyed == 0);
+ EXPECT_TRUE(testSrc.HasValue() && testSrc.Value().m == 300);
{
Optional<Count> testDst(testSrc);
- NL_TEST_ASSERT(inSuite, Count::created == 2 && Count::destroyed == 0);
- NL_TEST_ASSERT(inSuite, testDst.HasValue() && testDst.Value().m == 300);
+ EXPECT_TRUE(Count::created == 2 && Count::destroyed == 0);
+ EXPECT_TRUE(testDst.HasValue() && testDst.Value().m == 300);
}
- NL_TEST_ASSERT(inSuite, Count::created == 2 && Count::destroyed == 1);
+ EXPECT_TRUE(Count::created == 2 && Count::destroyed == 1);
{
Optional<Count> testDst;
- NL_TEST_ASSERT(inSuite, Count::created == 2 && Count::destroyed == 1);
- NL_TEST_ASSERT(inSuite, !testDst.HasValue());
+ EXPECT_TRUE(Count::created == 2 && Count::destroyed == 1);
+ EXPECT_FALSE(testDst.HasValue());
testDst = testSrc;
- NL_TEST_ASSERT(inSuite, Count::created == 3 && Count::destroyed == 1);
- NL_TEST_ASSERT(inSuite, testDst.HasValue() && testDst.Value().m == 300);
+ EXPECT_TRUE(Count::created == 3 && Count::destroyed == 1);
+ EXPECT_TRUE(testDst.HasValue() && testDst.Value().m == 300);
}
- NL_TEST_ASSERT(inSuite, Count::created == 3 && Count::destroyed == 2);
+ EXPECT_TRUE(Count::created == 3 && Count::destroyed == 2);
}
- NL_TEST_ASSERT(inSuite, Count::created == 3 && Count::destroyed == 3);
+ EXPECT_TRUE(Count::created == 3 && Count::destroyed == 3);
}
-static void TestMove(nlTestSuite * inSuite, void * inContext)
+TEST(TestOptional, TestMove)
{
Count::ResetCounter();
{
auto testSrc = MakeOptional<CountMovable>(400);
Optional<CountMovable> testDst(std::move(testSrc));
- NL_TEST_ASSERT(inSuite, Count::created == 2 && Count::destroyed == 1);
- NL_TEST_ASSERT(inSuite, testDst.HasValue() && testDst.Value().m == 400);
+ EXPECT_TRUE(Count::created == 2 && Count::destroyed == 1);
+ EXPECT_TRUE(testDst.HasValue() && testDst.Value().m == 400);
}
- NL_TEST_ASSERT(inSuite, Count::created == 2 && Count::destroyed == 2);
+ EXPECT_TRUE(Count::created == 2 && Count::destroyed == 2);
{
Optional<CountMovable> testDst;
- NL_TEST_ASSERT(inSuite, Count::created == 2 && Count::destroyed == 2);
- NL_TEST_ASSERT(inSuite, !testDst.HasValue());
+ EXPECT_TRUE(Count::created == 2 && Count::destroyed == 2);
+ EXPECT_FALSE(testDst.HasValue());
auto testSrc = MakeOptional<CountMovable>(401);
testDst = std::move(testSrc);
- NL_TEST_ASSERT(inSuite, Count::created == 4 && Count::destroyed == 3);
- NL_TEST_ASSERT(inSuite, testDst.HasValue() && testDst.Value().m == 401);
+ EXPECT_TRUE(Count::created == 4 && Count::destroyed == 3);
+ EXPECT_TRUE(testDst.HasValue() && testDst.Value().m == 401);
}
- NL_TEST_ASSERT(inSuite, Count::created == 4 && Count::destroyed == 4);
+ EXPECT_TRUE(Count::created == 4 && Count::destroyed == 4);
}
-static void TestConversion(nlTestSuite * inSuite, void * inContext)
+TEST(TestOptional, TestConversion)
{
// FixedSpan is implicitly convertible from std::array
using WidgetView = FixedSpan<const bool, 10>;
@@ -197,17 +196,17 @@
auto optOtherStorage = MakeOptional<WidgetStorage>();
auto const & constOptOtherStorage = optOtherStorage;
- NL_TEST_ASSERT(inSuite, optStorage.HasValue());
- NL_TEST_ASSERT(inSuite, optOtherStorage.HasValue());
+ EXPECT_TRUE(optStorage.HasValue());
+ EXPECT_TRUE(optOtherStorage.HasValue());
Optional<WidgetView> optView(constOptStorage);
- NL_TEST_ASSERT(inSuite, optView.HasValue());
- NL_TEST_ASSERT(inSuite, &optView.Value()[0] == &optStorage.Value()[0]);
+ EXPECT_TRUE(optView.HasValue());
+ EXPECT_EQ(&optView.Value()[0], &optStorage.Value()[0]);
optView = optOtherStorage;
optView = constOptOtherStorage;
- NL_TEST_ASSERT(inSuite, optView.HasValue());
- NL_TEST_ASSERT(inSuite, &optView.Value()[0] == &optOtherStorage.Value()[0]);
+ EXPECT_TRUE(optView.HasValue());
+ EXPECT_EQ(&optView.Value()[0], &optOtherStorage.Value()[0]);
struct ExplicitBool
{
@@ -218,48 +217,3 @@
// The following should not compile
// e = Optional<bool>(false); // relies on implicit conversion
}
-
-/**
- * Test Suite. It lists all the test functions.
- */
-
-// clang-format off
-static const nlTest sTests[] =
-{
- NL_TEST_DEF("OptionalBasic", TestBasic),
- NL_TEST_DEF("OptionalMake", TestMake),
- NL_TEST_DEF("OptionalCopy", TestCopy),
- NL_TEST_DEF("OptionalMove", TestMove),
- NL_TEST_DEF("OptionalConversion", TestConversion),
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-int TestOptional_Setup(void * inContext)
-{
- return SUCCESS;
-}
-
-int TestOptional_Teardown(void * inContext)
-{
- return SUCCESS;
-}
-
-int TestOptional()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "Optional",
- &sTests[0],
- TestOptional_Setup,
- TestOptional_Teardown
- };
- // clang-format on
-
- nlTestRunner(&theSuite, nullptr);
-
- return (nlTestRunnerStats(&theSuite));
-}
-
-CHIP_REGISTER_TEST_SUITE(TestOptional)
diff --git a/src/lib/core/tests/TestReferenceCounted.cpp b/src/lib/core/tests/TestReferenceCounted.cpp
index 9c292c4..4f3c3cd 100644
--- a/src/lib/core/tests/TestReferenceCounted.cpp
+++ b/src/lib/core/tests/TestReferenceCounted.cpp
@@ -28,24 +28,30 @@
#include <string.h>
#include <lib/core/ReferenceCounted.h>
-#include <lib/support/UnitTestRegistration.h>
-#include <nlunit-test.h>
+#include <gtest/gtest.h>
using namespace chip;
+class TestReferenceCounted : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
+
class TestClass : public ReferenceCounted<TestClass>
{
};
-static void TestRetainRelease(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestReferenceCounted, TestRetainRelease)
{
TestClass * testObj = chip::Platform::New<TestClass>();
- NL_TEST_ASSERT(inSuite, testObj->GetReferenceCount() == 1);
+ EXPECT_EQ(testObj->GetReferenceCount(), 1u);
testObj->Retain();
- NL_TEST_ASSERT(inSuite, testObj->GetReferenceCount() == 2);
+ EXPECT_EQ(testObj->GetReferenceCount(), 2u);
testObj->Release();
- NL_TEST_ASSERT(inSuite, testObj->GetReferenceCount() == 1);
+ EXPECT_EQ(testObj->GetReferenceCount(), 1u);
testObj->Release();
}
@@ -67,66 +73,19 @@
obj->deleted = true;
}
-static void TestRetainReleaseNonHeap(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestReferenceCounted, TestRetainReleaseNonHeap)
{
TestClassNonHeap testObj;
testObj.deleted = false;
- NL_TEST_ASSERT(inSuite, testObj.GetReferenceCount() == 1);
- NL_TEST_ASSERT(inSuite, testObj.deleted == false);
+ EXPECT_EQ(testObj.GetReferenceCount(), 1u);
+ EXPECT_EQ(testObj.deleted, false);
testObj.Retain();
- NL_TEST_ASSERT(inSuite, testObj.GetReferenceCount() == 2);
- NL_TEST_ASSERT(inSuite, testObj.deleted == false);
+ EXPECT_EQ(testObj.GetReferenceCount(), 2u);
+ EXPECT_EQ(testObj.deleted, false);
testObj.Release();
- NL_TEST_ASSERT(inSuite, testObj.GetReferenceCount() == 1);
- NL_TEST_ASSERT(inSuite, testObj.deleted == false);
+ EXPECT_EQ(testObj.GetReferenceCount(), 1u);
+ EXPECT_EQ(testObj.deleted, false);
testObj.Release();
- NL_TEST_ASSERT(inSuite, testObj.GetReferenceCount() == 0);
- NL_TEST_ASSERT(inSuite, testObj.deleted == true);
+ EXPECT_EQ(testObj.GetReferenceCount(), 0u);
+ EXPECT_EQ(testObj.deleted, true);
}
-
-/**
- * Test Suite. It lists all the test functions.
- */
-
-// clang-format off
-static const nlTest sTests[] =
-{
- NL_TEST_DEF("ReferenceCountedRetain", TestRetainRelease),
- NL_TEST_DEF("ReferenceCountedRetainNonHeap", TestRetainReleaseNonHeap),
-
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-int TestReferenceCounted_Setup(void * inContext)
-{
- CHIP_ERROR error = chip::Platform::MemoryInit();
- if (error != CHIP_NO_ERROR)
- return FAILURE;
- return SUCCESS;
-}
-
-int TestReferenceCounted_Teardown(void * inContext)
-{
- chip::Platform::MemoryShutdown();
- return SUCCESS;
-}
-
-int TestReferenceCounted()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "Reference-Counted",
- &sTests[0],
- TestReferenceCounted_Setup,
- TestReferenceCounted_Teardown
- };
- // clang-format on
-
- nlTestRunner(&theSuite, nullptr);
-
- return (nlTestRunnerStats(&theSuite));
-}
-
-CHIP_REGISTER_TEST_SUITE(TestReferenceCounted)
diff --git a/src/lib/core/tests/TestTLV.cpp b/src/lib/core/tests/TestTLV.cpp
index f71bce1..4b391c4 100644
--- a/src/lib/core/tests/TestTLV.cpp
+++ b/src/lib/core/tests/TestTLV.cpp
@@ -23,8 +23,8 @@
*
*/
+#include <gtest/gtest.h>
#include <nlbyteorder.h>
-#include <nlunit-test.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/TLV.h>
@@ -37,9 +37,7 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/ScopedBuffer.h>
#include <lib/support/Span.h>
-#include <lib/support/UnitTestContext.h>
-#include <lib/support/UnitTestExtendedAssertions.h>
-#include <lib/support/UnitTestRegistration.h>
+
#include <lib/support/UnitTestUtils.h>
#include <lib/support/logging/Constants.h>
@@ -66,105 +64,104 @@
"...END";
// clang-format on
-void TestAndOpenContainer(nlTestSuite * inSuite, TLVReader & reader, TLVType type, Tag tag, TLVReader & containerReader)
+void TestAndOpenContainer(TLVReader & reader, TLVType type, Tag tag, TLVReader & containerReader)
{
- NL_TEST_ASSERT(inSuite, reader.GetType() == type);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == tag);
- NL_TEST_ASSERT(inSuite, reader.GetLength() == 0);
+ EXPECT_EQ(reader.GetType(), type);
+ EXPECT_EQ(reader.GetTag(), tag);
+ EXPECT_EQ(reader.GetLength(), 0u);
CHIP_ERROR err = reader.OpenContainer(containerReader);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, containerReader.GetContainerType() == type);
+ EXPECT_EQ(containerReader.GetContainerType(), type);
}
template <class T>
-void TestAndEnterContainer(nlTestSuite * inSuite, T & t, TLVType type, Tag tag, TLVType & outerContainerType)
+void TestAndEnterContainer(T & t, TLVType type, Tag tag, TLVType & outerContainerType)
{
- NL_TEST_ASSERT(inSuite, t.GetType() == type);
- NL_TEST_ASSERT(inSuite, t.GetTag() == tag);
- NL_TEST_ASSERT(inSuite, t.GetLength() == 0);
+ EXPECT_EQ(t.GetType(), type);
+ EXPECT_EQ(t.GetTag(), tag);
+ EXPECT_EQ(t.GetLength(), 0u);
TLVType expectedContainerType = t.GetContainerType();
CHIP_ERROR err = t.EnterContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, outerContainerType == expectedContainerType);
- NL_TEST_ASSERT(inSuite, t.GetContainerType() == type);
+ EXPECT_EQ(outerContainerType, expectedContainerType);
+ EXPECT_EQ(t.GetContainerType(), type);
}
template <class T>
-void TestNext(nlTestSuite * inSuite, T & t)
+void TestNext(T & t)
{
CHIP_ERROR err = t.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
-void TestSkip(nlTestSuite * inSuite, TLVReader & reader)
+void TestSkip(TLVReader & reader)
{
CHIP_ERROR err = reader.Skip();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
-void TestMove(nlTestSuite * inSuite, TLVUpdater & updater)
+void TestMove(TLVUpdater & updater)
{
CHIP_ERROR err = updater.Move();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
template <class T>
-void TestEnd(nlTestSuite * inSuite, T & t)
+void TestEnd(T & t)
{
CHIP_ERROR err;
err = t.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_END_OF_TLV);
+ EXPECT_EQ(err, CHIP_END_OF_TLV);
}
-void TestEndAndCloseContainer(nlTestSuite * inSuite, TLVReader & reader, TLVReader & containerReader)
+void TestEndAndCloseContainer(TLVReader & reader, TLVReader & containerReader)
{
CHIP_ERROR err;
- TestEnd<TLVReader>(inSuite, containerReader);
+ TestEnd<TLVReader>(containerReader);
err = reader.CloseContainer(containerReader);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
template <class T>
-void TestEndAndExitContainer(nlTestSuite * inSuite, T & t, TLVType outerContainerType)
+void TestEndAndExitContainer(T & t, TLVType outerContainerType)
{
CHIP_ERROR err;
- TestEnd<T>(inSuite, t);
+ TestEnd<T>(t);
err = t.ExitContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, t.GetContainerType() == outerContainerType);
+ EXPECT_EQ(t.GetContainerType(), outerContainerType);
}
-#define TEST_GET(inSuite, s, type, tag, expectedVal, expectedErr) \
+#define TEST_GET(s, type, tag, expectedVal, expectedErr) \
do \
{ \
- NL_TEST_ASSERT(inSuite, s.GetType() == type); \
- NL_TEST_ASSERT(inSuite, s.GetTag() == tag); \
- NL_TEST_ASSERT(inSuite, s.GetLength() == 0); \
+ EXPECT_EQ(s.GetType(), type); \
+ EXPECT_EQ(s.GetTag(), tag); \
+ EXPECT_EQ(s.GetLength(), 0u); \
\
decltype(expectedVal) __val; \
CHIP_ERROR __err = s.Get(__val); \
- NL_TEST_ASSERT(inSuite, __err == expectedErr); \
+ EXPECT_EQ(__err, expectedErr); \
if (__err == CHIP_NO_ERROR) \
{ \
- NL_TEST_ASSERT(inSuite, __val == expectedVal); \
+ EXPECT_EQ(__val, expectedVal); \
} \
} while (false)
-#define TEST_GET_NOERROR(inSuite, s, type, tag, expectedVal) TEST_GET(inSuite, s, type, tag, expectedVal, CHIP_NO_ERROR)
+#define TEST_GET_NOERROR(s, type, tag, expectedVal) TEST_GET(s, type, tag, expectedVal, CHIP_NO_ERROR)
-void ForEachElement(nlTestSuite * inSuite, TLVReader & reader, void * context,
- void (*cb)(nlTestSuite * inSuite, TLVReader & reader, void * context))
+void ForEachElement(TLVReader & reader, void * context, void (*cb)(TLVReader & reader, void * context))
{
CHIP_ERROR err;
@@ -175,11 +172,11 @@
{
return;
}
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
if (cb != nullptr)
{
- cb(inSuite, reader, context);
+ cb(reader, context);
}
if (TLVTypeIsContainer(reader.GetType()))
@@ -187,12 +184,12 @@
TLVType outerContainerType;
err = reader.EnterContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- ForEachElement(inSuite, reader, context, cb);
+ ForEachElement(reader, context, cb);
err = reader.ExitContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
}
}
@@ -203,84 +200,84 @@
struct TestTLVContext
{
- nlTestSuite * mSuite = nullptr;
int mEvictionCount = 0;
uint32_t mEvictedBytes = 0;
-
- TestTLVContext(nlTestSuite * suite) : mSuite(suite) {}
};
-void TestNull(nlTestSuite * inSuite, TLVReader & reader, Tag tag)
+class TestTLV : public ::testing::Test
{
- NL_TEST_ASSERT(inSuite, reader.GetType() == kTLVType_Null);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == tag);
- NL_TEST_ASSERT(inSuite, reader.GetLength() == 0);
+public:
+ static TestTLVContext ctx;
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
+
+TestTLVContext TestTLV::ctx;
+
+void TestNull(TLVReader & reader, Tag tag)
+{
+ EXPECT_EQ(reader.GetType(), kTLVType_Null);
+ EXPECT_EQ(reader.GetTag(), tag);
+ EXPECT_EQ(reader.GetLength(), 0u);
}
-void TestString(nlTestSuite * inSuite, TLVReader & reader, Tag tag, const char * expectedVal)
+void TestString(TLVReader & reader, Tag tag, const char * expectedVal)
{
- NL_TEST_ASSERT(inSuite, reader.GetType() == kTLVType_UTF8String);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == tag);
+ EXPECT_EQ(reader.GetType(), kTLVType_UTF8String);
+ EXPECT_EQ(reader.GetTag(), tag);
size_t expectedLen = strlen(expectedVal);
- NL_TEST_ASSERT(inSuite, reader.GetLength() == expectedLen);
+ EXPECT_EQ(reader.GetLength(), expectedLen);
chip::Platform::ScopedMemoryBuffer<char> valBuffer;
char * val = static_cast<char *>(valBuffer.Alloc(expectedLen + 1).Get());
CHIP_ERROR err = reader.GetString(val, static_cast<uint32_t>(expectedLen) + 1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(val, expectedVal, expectedLen + 1) == 0);
+ EXPECT_EQ(memcmp(val, expectedVal, expectedLen + 1), 0);
}
-void TestDupString(nlTestSuite * inSuite, TLVReader & reader, Tag tag, const char * expectedVal)
+void TestDupString(TLVReader & reader, Tag tag, const char * expectedVal)
{
- NL_TEST_ASSERT(inSuite, reader.GetType() == kTLVType_UTF8String);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == tag);
+ EXPECT_EQ(reader.GetType(), kTLVType_UTF8String);
+ EXPECT_EQ(reader.GetTag(), tag);
size_t expectedLen = strlen(expectedVal);
- NL_TEST_ASSERT(inSuite, reader.GetLength() == expectedLen);
+ EXPECT_EQ(reader.GetLength(), expectedLen);
char * val = nullptr;
CHIP_ERROR err = reader.DupString(val);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, val != nullptr);
- if (val != nullptr)
- {
- NL_TEST_ASSERT(inSuite, memcmp(val, expectedVal, expectedLen + 1) == 0);
- }
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ ASSERT_NE(val, nullptr);
+ EXPECT_EQ(memcmp(val, expectedVal, expectedLen + 1), 0);
chip::Platform::MemoryFree(val);
}
-void TestDupBytes(nlTestSuite * inSuite, TLVReader & reader, Tag tag, const uint8_t * expectedVal, uint32_t expectedLen)
+void TestDupBytes(TLVReader & reader, Tag tag, const uint8_t * expectedVal, uint32_t expectedLen)
{
- NL_TEST_ASSERT(inSuite, reader.GetType() == kTLVType_UTF8String);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == tag);
+ EXPECT_EQ(reader.GetType(), kTLVType_UTF8String);
+ EXPECT_EQ(reader.GetTag(), tag);
- NL_TEST_ASSERT(inSuite, reader.GetLength() == expectedLen);
+ EXPECT_EQ(reader.GetLength(), expectedLen);
uint8_t * val = nullptr;
CHIP_ERROR err = reader.DupBytes(val, expectedLen);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, val != nullptr);
- if (val != nullptr)
- {
- NL_TEST_ASSERT(inSuite, memcmp(val, expectedVal, expectedLen) == 0);
- }
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ ASSERT_NE(val, nullptr);
+ EXPECT_EQ(memcmp(val, expectedVal, expectedLen), 0);
chip::Platform::MemoryFree(val);
}
-void TestBufferContents(nlTestSuite * inSuite, const System::PacketBufferHandle & buffer, const uint8_t * expectedVal,
- uint32_t expectedLen)
+void TestBufferContents(const System::PacketBufferHandle & buffer, const uint8_t * expectedVal, uint32_t expectedLen)
{
System::PacketBufferHandle buf = buffer.Retain();
while (!buf.IsNull())
{
uint16_t len = buf->DataLength();
- NL_TEST_ASSERT(inSuite, len <= expectedLen);
+ EXPECT_LE(len, expectedLen);
- NL_TEST_ASSERT(inSuite, memcmp(buf->Start(), expectedVal, len) == 0);
+ EXPECT_EQ(memcmp(buf->Start(), expectedVal, len), 0);
expectedVal += len;
expectedLen -= len;
@@ -288,7 +285,7 @@
buf.Advance();
}
- NL_TEST_ASSERT(inSuite, expectedLen == 0);
+ EXPECT_EQ(expectedLen, 0u);
}
// clang-format off
@@ -371,455 +368,450 @@
};
// clang-format on
-static CHIP_ERROR WriteIntMinMax(nlTestSuite * inSuite, TLVWriter & writer)
+static CHIP_ERROR WriteIntMinMax(TLVWriter & writer)
{
CHIP_ERROR err;
err = writer.Put(AnonymousTag(), static_cast<int8_t>(INT8_MIN));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<int8_t>(INT8_MAX));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<int16_t>(INT16_MIN));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<int16_t>(INT16_MAX));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<int32_t>(INT32_MIN));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<int32_t>(INT32_MAX));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<int64_t>(INT64_MIN));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<int64_t>(INT64_MAX));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<uint8_t>(UINT8_MAX));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<uint16_t>(UINT16_MAX));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<uint32_t>(UINT32_MAX));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(AnonymousTag(), static_cast<uint64_t>(UINT64_MAX));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
return err;
}
-static void CheckIntMinMax(nlTestSuite * inSuite, TLVReader & reader)
+static void CheckIntMinMax(TLVReader & reader)
{
// Writer did Put(AnonymousTag(), static_cast<int8_t>(INT8_MIN))
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(INT8_MIN));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(INT8_MIN));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT8_MIN));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT8_MIN));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(INT8_MIN));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(INT8_MIN));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT8_MIN));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT8_MIN));
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<int8_t>(INT8_MAX))
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(INT8_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(INT8_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT8_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT8_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(INT8_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(INT8_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT8_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT8_MAX));
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<int16_t>(INT16_MIN))
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(INT16_MIN));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT16_MIN));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT16_MIN));
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(INT16_MIN));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT16_MIN));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT16_MIN));
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<int16_t>(INT16_MAX))
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(INT16_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT16_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT16_MAX));
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(INT16_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT16_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT16_MAX));
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<int32_t>(INT32_MIN))
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT32_MIN));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT32_MIN));
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT32_MIN));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT32_MIN));
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<int32_t>(INT32_MAX))
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT32_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT32_MAX));
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(INT32_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT32_MAX));
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<int64_t>(INT64_MIN))
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT64_MIN));
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT64_MIN));
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<int64_t>(INT64_MAX))
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT64_MAX));
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(INT64_MAX));
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<uint8_t>(UINT8_MAX))
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint8_t>(UINT8_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint16_t>(UINT8_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint32_t>(UINT8_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(UINT8_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint8_t>(UINT8_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint16_t>(UINT8_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint32_t>(UINT8_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(UINT8_MAX));
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<uint16_t>(UINT16_MAX))
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint16_t>(UINT16_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint32_t>(UINT16_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(UINT16_MAX));
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint16_t>(UINT16_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint32_t>(UINT16_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(UINT16_MAX));
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<uint32_t>(UINT32_MAX))
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint32_t>(UINT32_MAX));
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(UINT32_MAX));
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint32_t>(UINT32_MAX));
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(UINT32_MAX));
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// Writer did Put(AnonymousTag(), static_cast<uint64_t>(UINT64_MAX))
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int8_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int16_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int32_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(0), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(UINT64_MAX));
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint8_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint16_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint32_t>(0), CHIP_ERROR_INVALID_INTEGER_VALUE);
+ TEST_GET_NOERROR(reader, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(UINT64_MAX));
}
-void WriteEncoding1(nlTestSuite * inSuite, TLVWriter & writer)
+void WriteEncoding1(TLVWriter & writer)
{
CHIP_ERROR err;
TLVWriter writer2;
err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
{
TLVWriter writer3;
err = writer2.OpenContainer(ContextTag(0), kTLVType_Array, writer3);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// TODO(#1306): expand coverage of inttype encoding tests.
err = writer3.Put(AnonymousTag(), static_cast<int32_t>(42));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<int32_t>(-17));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<int32_t>(-170000));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<uint64_t>(40000000000ULL));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
{
TLVWriter writer4;
err = writer3.OpenContainer(AnonymousTag(), kTLVType_Structure, writer4);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.CloseContainer(writer4);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
{
TLVWriter writer5;
err = writer3.OpenContainer(AnonymousTag(), kTLVType_List, writer5);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer5.PutNull(ProfileTag(TestProfile_1, 17));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer5.PutNull(ProfileTag(TestProfile_2, 900000));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer5.PutNull(AnonymousTag());
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
{
TLVType outerContainerType;
err = writer5.StartContainer(ProfileTag(TestProfile_2, 4000000000ULL), kTLVType_Structure, outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer5.PutString(CommonTag(70000), sLargeString);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer5.EndContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer3.CloseContainer(writer5);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer2.CloseContainer(writer3);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer2.PutString(ProfileTag(TestProfile_1, 5), "This is a test");
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(ProfileTag(TestProfile_2, 65535), static_cast<float>(17.9));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(ProfileTag(TestProfile_2, 65536), 17.9);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
-void WriteEmptyEncoding(nlTestSuite * inSuite, TLVWriter & writer)
+void WriteEmptyEncoding(TLVWriter & writer)
{
CHIP_ERROR err;
TLVWriter writer2;
err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
{
TLVWriter writer3;
err = writer2.OpenContainer(ProfileTag(TestProfile_1, 256), kTLVType_Array, writer3);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.CloseContainer(writer3);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
-void ReadEncoding1(nlTestSuite * inSuite, TLVReader & reader)
+void ReadEncoding1(TLVReader & reader)
{
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
{
TLVReader reader2;
- TestAndOpenContainer(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader2);
+ TestAndOpenContainer(reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader2);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TEST_GET_NOERROR(reader2, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
{
TLVReader reader3;
- TestAndOpenContainer(inSuite, reader2, kTLVType_Array, ContextTag(0), reader3);
+ TestAndOpenContainer(reader2, kTLVType_Array, ContextTag(0), reader3);
- TestNext<TLVReader>(inSuite, reader3);
+ TestNext<TLVReader>(reader3);
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(42));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(42));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(42));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(42));
- TEST_GET(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(42), CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(42),
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(42));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(42));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(42));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(42));
+ TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(42), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(42), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(42), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(42), CHIP_ERROR_WRONG_TLV_TYPE);
+
+ TestNext<TLVReader>(reader3);
+
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(-17));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(-17));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(-17));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(-17));
+ TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(-17), CHIP_ERROR_WRONG_TLV_TYPE);
+
+ TestNext<TLVReader>(reader3);
+
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(-170000));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(-170000));
+
+ TestNext<TLVReader>(reader3);
+
+ TEST_GET(reader3, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(40000000000ULL),
CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(42),
- CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(42),
- CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET_NOERROR(reader3, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(40000000000ULL));
- TestNext<TLVReader>(inSuite, reader3);
-
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(-17));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(-17));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(-17));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(-17));
- TEST_GET(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(-17),
- CHIP_ERROR_WRONG_TLV_TYPE);
-
- TestNext<TLVReader>(inSuite, reader3);
-
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(-170000));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(-170000));
-
- TestNext<TLVReader>(inSuite, reader3);
-
- TEST_GET(inSuite, reader3, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(40000000000ULL),
- CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(40000000000ULL));
-
- TestNext<TLVReader>(inSuite, reader3);
+ TestNext<TLVReader>(reader3);
{
TLVReader reader4;
- TestAndOpenContainer(inSuite, reader3, kTLVType_Structure, AnonymousTag(), reader4);
+ TestAndOpenContainer(reader3, kTLVType_Structure, AnonymousTag(), reader4);
- TestEndAndCloseContainer(inSuite, reader3, reader4);
+ TestEndAndCloseContainer(reader3, reader4);
}
- TestNext<TLVReader>(inSuite, reader3);
+ TestNext<TLVReader>(reader3);
{
TLVReader reader5;
- TestAndOpenContainer(inSuite, reader3, kTLVType_List, AnonymousTag(), reader5);
+ TestAndOpenContainer(reader3, kTLVType_List, AnonymousTag(), reader5);
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
- TestNull(inSuite, reader5, ProfileTag(TestProfile_1, 17));
+ TestNull(reader5, ProfileTag(TestProfile_1, 17));
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
- TestNull(inSuite, reader5, ProfileTag(TestProfile_2, 900000));
+ TestNull(reader5, ProfileTag(TestProfile_2, 900000));
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
- TestNull(inSuite, reader5, AnonymousTag());
+ TestNull(reader5, AnonymousTag());
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
{
TLVType outerContainerType;
- TestAndEnterContainer<TLVReader>(inSuite, reader5, kTLVType_Structure, ProfileTag(TestProfile_2, 4000000000ULL),
+ TestAndEnterContainer<TLVReader>(reader5, kTLVType_Structure, ProfileTag(TestProfile_2, 4000000000ULL),
outerContainerType);
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
- TestString(inSuite, reader5, CommonTag(70000), sLargeString);
+ TestString(reader5, CommonTag(70000), sLargeString);
- TestEndAndExitContainer<TLVReader>(inSuite, reader5, outerContainerType);
+ TestEndAndExitContainer<TLVReader>(reader5, outerContainerType);
}
- TestEndAndCloseContainer(inSuite, reader3, reader5);
+ TestEndAndCloseContainer(reader3, reader5);
}
- TestEndAndCloseContainer(inSuite, reader2, reader3);
+ TestEndAndCloseContainer(reader2, reader3);
}
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TestString(inSuite, reader2, ProfileTag(TestProfile_1, 5), "This is a test");
+ TestString(reader2, ProfileTag(TestProfile_1, 5), "This is a test");
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), 17.9f);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535),
- static_cast<double>(17.9f));
+ TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), 17.9f);
+ TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), static_cast<double>(17.9f));
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65536), 17.9);
+ TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65536), 17.9);
- TestEndAndCloseContainer(inSuite, reader, reader2);
+ TestEndAndCloseContainer(reader, reader2);
}
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
-void WriteEncoding2(nlTestSuite * inSuite, TLVWriter & writer)
+void WriteEncoding2(TLVWriter & writer)
{
CHIP_ERROR err;
@@ -827,39 +819,39 @@
TLVWriter writer1;
err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.CloseContainer(writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
{ // Container 2
TLVWriter writer1;
err = writer.OpenContainer(ProfileTag(TestProfile_2, 1), kTLVType_Structure, writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.CloseContainer(writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
-void WriteEncoding3(nlTestSuite * inSuite, TLVWriter & writer)
+void WriteEncoding3(TLVWriter & writer)
{
CHIP_ERROR err;
@@ -868,30 +860,30 @@
err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer1);
if (err != CHIP_NO_ERROR)
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.CloseContainer(writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
-void ReadEncoding3(nlTestSuite * inSuite, TLVReader & reader)
+void ReadEncoding3(TLVReader & reader)
{
TLVReader reader2;
- TestAndOpenContainer(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader2);
+ TestAndOpenContainer(reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader2);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestEndAndCloseContainer(inSuite, reader, reader2);
+ TestEndAndCloseContainer(reader, reader2);
}
// clang-format off
static const uint8_t Encoding5_DataMacro [] =
@@ -920,7 +912,7 @@
};
// clang-format on
-void WriteEncoding5(nlTestSuite * inSuite, TLVWriter & writer)
+void WriteEncoding5(TLVWriter & writer)
{
CHIP_ERROR err;
@@ -928,74 +920,74 @@
TLVWriter writer1;
err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_1, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_2, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
{ // Inner Container 1
TLVWriter writer2;
err = writer1.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
{ // Inner Container 2
TLVWriter writer2;
err = writer1.OpenContainer(ProfileTag(TestProfile_2, 1), kTLVType_Structure, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer.CloseContainer(writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
{ // Container 2
TLVWriter writer1;
err = writer.OpenContainer(ProfileTag(TestProfile_2, 1), kTLVType_Structure, writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.CloseContainer(writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
/**
@@ -1012,66 +1004,66 @@
* <TestProfile_1, 1, kTLVType_Structure, <TestProfile_1, 2, true> <TestProfile_2, 2, false> >,
* <TestProfile_2, 1, kTLVType_Structure, <TestProfile_2, 2, false> <TestProfile_1, 2, true> >
*/
-void AppendEncoding2(nlTestSuite * inSuite, uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen)
+void AppendEncoding2(uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen)
{
CHIP_ERROR err;
TLVUpdater updater;
err = updater.Init(buf, dataLen, maxLen);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
updater.SetImplicitProfileId(TestProfile_2);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
{
TLVType outerContainerType;
- TestAndEnterContainer<TLVUpdater>(inSuite, updater, kTLVType_Structure, ProfileTag(TestProfile_1, 1), outerContainerType);
+ TestAndEnterContainer<TLVUpdater>(updater, kTLVType_Structure, ProfileTag(TestProfile_1, 1), outerContainerType);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
// Move the element without modification
- TestMove(inSuite, updater);
+ TestMove(updater);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
// Read and copy the element with/without modification
- TEST_GET_NOERROR(inSuite, updater, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(updater, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
err = updater.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// TestEnd and add data at the end of the container
- TestEnd<TLVUpdater>(inSuite, updater);
+ TestEnd<TLVUpdater>(updater);
// Put new values in the encoding using the updater
// Add <TestProfile_1, 2, false>
err = updater.PutBoolean(ProfileTag(TestProfile_1, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_2, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_2, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add a new container
{
TLVType outerContainerType1;
err = updater.StartContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, outerContainerType1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_1, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_1, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Close the container
err = updater.EndContainer(outerContainerType1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
// Add another new container
@@ -1079,33 +1071,33 @@
TLVType outerContainerType1;
err = updater.StartContainer(ProfileTag(TestProfile_2, 1), kTLVType_Structure, outerContainerType1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_2, 2, false>
err = updater.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_1, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Close the container
err = updater.EndContainer(outerContainerType1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
- TestEndAndExitContainer<TLVUpdater>(inSuite, updater, outerContainerType);
+ TestEndAndExitContainer<TLVUpdater>(updater, outerContainerType);
}
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
// Move the container unmodified
- TestMove(inSuite, updater);
+ TestMove(updater);
- TestEnd<TLVUpdater>(inSuite, updater);
+ TestEnd<TLVUpdater>(updater);
err = updater.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
updatedLen = updater.GetLengthWritten();
}
@@ -1126,8 +1118,7 @@
* <TestProfile_1, 1, kTLVType_Structure, <TestProfile_1, 2, true> <TestProfile_2, 2, false> >,
* <TestProfile_2, 1, kTLVType_Structure, <TestProfile_2, 2, false> <TestProfile_1, 2, true> >
*/
-void FindAppendEncoding2(nlTestSuite * inSuite, uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen,
- bool findContainer)
+void FindAppendEncoding2(uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen, bool findContainer)
{
CHIP_ERROR err;
@@ -1144,76 +1135,76 @@
TLVReader tagReader;
TLVType outerContainerType;
err = chip::TLV::Utilities::Find(reader, ProfileTag(TestProfile_1, 1), tagReader);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = tagReader.EnterContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
do
{
err = tagReader.Next();
} while (err != CHIP_END_OF_TLV);
- TestEnd<TLVReader>(inSuite, tagReader);
+ TestEnd<TLVReader>(tagReader);
// Init a TLVUpdater using the TLVReader
err = updater.Init(tagReader, maxLen - dataLen);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
else
{
// Find
TLVReader tagReader;
err = chip::TLV::Utilities::Find(reader, ProfileTag(TestProfile_2, 2), tagReader);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Test Find(recurse = true)
TLVReader tagReader2;
err = chip::TLV::Utilities::Find(reader, ProfileTag(TestProfile_2, 2), tagReader2, true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
//
// Test Find(recurse = false)
TLVReader tagReader3;
err = chip::TLV::Utilities::Find(reader, ProfileTag(TestProfile_2, 2), tagReader3, false);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_TLV_TAG_NOT_FOUND);
+ EXPECT_EQ(err, CHIP_ERROR_TLV_TAG_NOT_FOUND);
// Init a TLVUpdater using the TLVReader
err = updater.Init(tagReader, maxLen - dataLen);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
// Move the element without modification
- TestMove(inSuite, updater);
+ TestMove(updater);
}
// Put new values in the encoding using the updater
// Add <TestProfile_1, 2, false>
err = updater.PutBoolean(ProfileTag(TestProfile_1, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_2, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_2, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add a new container
{
TLVType outerContainerType1;
err = updater.StartContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, outerContainerType1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_1, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_1, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Close the container
err = updater.EndContainer(outerContainerType1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
// Add another new container
@@ -1221,79 +1212,79 @@
TLVType outerContainerType1;
err = updater.StartContainer(ProfileTag(TestProfile_2, 1), kTLVType_Structure, outerContainerType1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_2, 2, false>
err = updater.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_1, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Close the container
err = updater.EndContainer(outerContainerType1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
// Move everything else unmodified
updater.MoveUntilEnd();
- TestEnd<TLVUpdater>(inSuite, updater);
+ TestEnd<TLVUpdater>(updater);
err = updater.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
updatedLen = updater.GetLengthWritten();
}
-void AppendEncoding3(nlTestSuite * inSuite, uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen)
+void AppendEncoding3(uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen)
{
CHIP_ERROR err;
TLVUpdater updater;
err = updater.Init(buf, dataLen, maxLen);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
updater.SetImplicitProfileId(TestProfile_2);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
{
TLVType outerContainerType;
- TestAndEnterContainer<TLVUpdater>(inSuite, updater, kTLVType_Structure, ProfileTag(TestProfile_1, 1), outerContainerType);
+ TestAndEnterContainer<TLVUpdater>(updater, kTLVType_Structure, ProfileTag(TestProfile_1, 1), outerContainerType);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
// Move the element without modification
- TestMove(inSuite, updater);
+ TestMove(updater);
// Put new value in the encoding using the updater
// Add <TestProfile_2, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_2, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- TestEndAndExitContainer<TLVUpdater>(inSuite, updater, outerContainerType);
+ TestEndAndExitContainer<TLVUpdater>(updater, outerContainerType);
}
- TestEnd<TLVUpdater>(inSuite, updater);
+ TestEnd<TLVUpdater>(updater);
err = updater.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
updatedLen = updater.GetLengthWritten();
}
-void AppendEncoding4(nlTestSuite * inSuite, uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen)
+void AppendEncoding4(uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen)
{
CHIP_ERROR err;
TLVUpdater updater;
err = updater.Init(buf, dataLen, maxLen);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
updater.SetImplicitProfileId(TestProfile_2);
@@ -1302,59 +1293,59 @@
TLVType outerContainerType;
err = updater.StartContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Add <TestProfile_1, 2, true>
err = updater.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Close the container
err = updater.EndContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = updater.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
updatedLen = updater.GetLengthWritten();
}
-void DeleteEncoding5(nlTestSuite * inSuite, uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen)
+void DeleteEncoding5(uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen)
{
CHIP_ERROR err;
TLVUpdater updater;
err = updater.Init(buf, dataLen, maxLen);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
updater.SetImplicitProfileId(TestProfile_2);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
{
TLVType outerContainerType;
- TestAndEnterContainer<TLVUpdater>(inSuite, updater, kTLVType_Structure, ProfileTag(TestProfile_1, 1), outerContainerType);
+ TestAndEnterContainer<TLVUpdater>(updater, kTLVType_Structure, ProfileTag(TestProfile_1, 1), outerContainerType);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
- TestMove(inSuite, updater);
+ TestMove(updater);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
- TestMove(inSuite, updater);
+ TestMove(updater);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
// Get the value to inspect and skip writing it
- TEST_GET_NOERROR(inSuite, updater, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
+ TEST_GET_NOERROR(updater, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
// Skip the next boolean type and don't copy by doing nothing
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
// Read ahead into the next container and decide whether to skip or
// not based on elements in the container
@@ -1364,206 +1355,206 @@
updater.GetReader(reader);
- TestAndEnterContainer<TLVReader>(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), containerType);
+ TestAndEnterContainer<TLVReader>(reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), containerType);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
// If the container's first element has the tag <TestProfile_1, 2>
// skip the whole container, and if NOT copy the container
if (reader.GetTag() != ProfileTag(TestProfile_1, 2))
- TestMove(inSuite, updater);
+ TestMove(updater);
}
- TestNext<TLVUpdater>(inSuite, updater);
+ TestNext<TLVUpdater>(updater);
// Skip the next container and don't copy by doing nothing
- TestEndAndExitContainer<TLVUpdater>(inSuite, updater, outerContainerType);
+ TestEndAndExitContainer<TLVUpdater>(updater, outerContainerType);
}
// Move everything else unmodified
updater.MoveUntilEnd();
- TestEnd<TLVUpdater>(inSuite, updater);
+ TestEnd<TLVUpdater>(updater);
err = updater.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
updatedLen = updater.GetLengthWritten();
}
-void ReadAppendedEncoding2(nlTestSuite * inSuite, TLVReader & reader)
+void ReadAppendedEncoding2(TLVReader & reader)
{
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
{ // Container 1
TLVReader reader1;
- TestAndOpenContainer(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader1);
+ TestAndOpenContainer(reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader1);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), true);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), true);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
{
TLVReader reader2;
- TestAndOpenContainer(inSuite, reader1, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader2);
+ TestAndOpenContainer(reader1, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader2);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TEST_GET_NOERROR(reader2, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestEndAndCloseContainer(inSuite, reader1, reader2);
+ TestEndAndCloseContainer(reader1, reader2);
}
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
{
TLVReader reader2;
- TestAndOpenContainer(inSuite, reader1, kTLVType_Structure, ProfileTag(TestProfile_2, 1), reader2);
+ TestAndOpenContainer(reader1, kTLVType_Structure, ProfileTag(TestProfile_2, 1), reader2);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TEST_GET_NOERROR(reader2, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestEndAndCloseContainer(inSuite, reader1, reader2);
+ TestEndAndCloseContainer(reader1, reader2);
}
- TestEndAndCloseContainer(inSuite, reader, reader1);
+ TestEndAndCloseContainer(reader, reader1);
}
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
{ // Container 2
TLVReader reader1;
- TestAndOpenContainer(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_2, 1), reader1);
+ TestAndOpenContainer(reader, kTLVType_Structure, ProfileTag(TestProfile_2, 1), reader1);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestEndAndCloseContainer(inSuite, reader, reader1);
+ TestEndAndCloseContainer(reader, reader1);
}
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
-void ReadAppendedEncoding3(nlTestSuite * inSuite, TLVReader & reader)
+void ReadAppendedEncoding3(TLVReader & reader)
{
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
{ // Container 1
TLVReader reader1;
- TestAndOpenContainer(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader1);
+ TestAndOpenContainer(reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader1);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), true);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), true);
- TestEndAndCloseContainer(inSuite, reader, reader1);
+ TestEndAndCloseContainer(reader, reader1);
}
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
-void ReadAppendedEncoding4(nlTestSuite * inSuite, TLVReader & reader)
+void ReadAppendedEncoding4(TLVReader & reader)
{
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
{ // Container 1
TLVReader reader1;
- TestAndOpenContainer(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader1);
+ TestAndOpenContainer(reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader1);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestEndAndCloseContainer(inSuite, reader, reader1);
+ TestEndAndCloseContainer(reader, reader1);
}
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
-void ReadDeletedEncoding5(nlTestSuite * inSuite, TLVReader & reader)
+void ReadDeletedEncoding5(TLVReader & reader)
{
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
{ // Container 1
TLVReader reader1;
- TestAndOpenContainer(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader1);
+ TestAndOpenContainer(reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader1);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestEndAndCloseContainer(inSuite, reader, reader1);
+ TestEndAndCloseContainer(reader, reader1);
}
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
{ // Container 2
TLVReader reader1;
- TestAndOpenContainer(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_2, 1), reader1);
+ TestAndOpenContainer(reader, kTLVType_Structure, ProfileTag(TestProfile_2, 1), reader1);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- TEST_GET_NOERROR(inSuite, reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TEST_GET_NOERROR(reader1, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestEndAndCloseContainer(inSuite, reader, reader1);
+ TestEndAndCloseContainer(reader, reader1);
}
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
/**
* Test Simple Write and Reader
*/
-void CheckSimpleWriteRead(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckSimpleWriteRead)
{
uint8_t buf[2048];
TLVWriter writer;
@@ -1574,9 +1565,9 @@
writer.ImplicitProfileId = TestProfile_2;
remainingFreedLen = writer.GetRemainingFreeLength();
- NL_TEST_ASSERT(inSuite, sizeof(buf) == remainingFreedLen);
+ EXPECT_EQ(sizeof(buf), remainingFreedLen);
- WriteEncoding1(inSuite, writer);
+ WriteEncoding1(writer);
uint32_t encodedLen = writer.GetLengthWritten();
@@ -1590,16 +1581,16 @@
printf("\n");
#endif
- NL_TEST_ASSERT(inSuite, encodedLen == sizeof(Encoding1));
- NL_TEST_ASSERT(inSuite, memcmp(buf, Encoding1, encodedLen) == 0);
+ EXPECT_EQ(encodedLen, sizeof(Encoding1));
+ EXPECT_EQ(memcmp(buf, Encoding1, encodedLen), 0);
reader.Init(buf, encodedLen);
reader.ImplicitProfileId = TestProfile_2;
- ReadEncoding1(inSuite, reader);
+ ReadEncoding1(reader);
}
-static void TestIntMinMax(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, TestIntMinMax)
{
CHIP_ERROR err;
@@ -1611,25 +1602,25 @@
writer.ImplicitProfileId = TestProfile_3;
err = writer.OpenContainer(ProfileTag(TestProfile_3, 1), kTLVType_Array, writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- WriteIntMinMax(inSuite, writer1);
+ WriteIntMinMax(writer1);
err = writer.CloseContainer(writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(buf, sizeof(buf));
reader.ImplicitProfileId = TestProfile_3;
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- TestAndOpenContainer(inSuite, reader, kTLVType_Array, ProfileTag(TestProfile_3, 1), reader1);
+ TestAndOpenContainer(reader, kTLVType_Array, ProfileTag(TestProfile_3, 1), reader1);
- TestNext<TLVReader>(inSuite, reader1);
+ TestNext<TLVReader>(reader1);
- CheckIntMinMax(inSuite, reader1);
+ CheckIntMinMax(reader1);
- TestEndAndCloseContainer(inSuite, reader, reader1);
+ TestEndAndCloseContainer(reader, reader1);
}
/**
@@ -1657,7 +1648,7 @@
/**
* Test Pretty Printer
*/
-void CheckPrettyPrinter(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckPrettyPrinter)
{
uint8_t buf[2048];
TLVWriter writer;
@@ -1666,12 +1657,12 @@
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding1(inSuite, writer);
+ WriteEncoding1(writer);
uint32_t encodedLen = writer.GetLengthWritten();
- NL_TEST_ASSERT(inSuite, encodedLen == sizeof(Encoding1));
- NL_TEST_ASSERT(inSuite, memcmp(buf, Encoding1, encodedLen) == 0);
+ EXPECT_EQ(encodedLen, sizeof(Encoding1));
+ EXPECT_EQ(memcmp(buf, Encoding1, encodedLen), 0);
reader.Init(buf, encodedLen);
reader.ImplicitProfileId = TestProfile_2;
@@ -1707,7 +1698,7 @@
/**
* Test Octet String Pretty Printer
*/
-void CheckOctetStringPrettyPrinter(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckOctetStringPrettyPrinter)
{
const uint8_t testOctetString[] = { 0x62, 0xFA, 0x82, 0x33, 0x59, 0xAC, 0xFA, 0xA9 };
const char expectedPrint[] =
@@ -1716,35 +1707,34 @@
TLVWriter writer;
writer.Init(encodedBuf);
- NL_TEST_ASSERT_SUCCESS(inSuite, writer.PutBytes(CommonTag(0), testOctetString, sizeof(testOctetString)));
- NL_TEST_ASSERT_SUCCESS(inSuite, writer.Finalize());
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutBytes(CommonTag(0), testOctetString, sizeof(testOctetString)));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.Finalize());
TLVReader reader;
reader.Init(encodedBuf, writer.GetLengthWritten());
chip::TLV::Debug::Dump(reader, StringDumpWriter);
- NL_TEST_ASSERT(inSuite, strlen(expectedPrint) == strlen(gStringDumpWriterBuf));
- NL_TEST_ASSERT(inSuite, strcmp(expectedPrint, gStringDumpWriterBuf) == 0);
+ EXPECT_STREQ(expectedPrint, gStringDumpWriterBuf);
}
/**
* Test Data Macros
*/
-void CheckDataMacro(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckDataMacro)
{
- NL_TEST_ASSERT(inSuite, sizeof(Encoding1_DataMacro) == sizeof(Encoding1));
- NL_TEST_ASSERT(inSuite, memcmp(Encoding1, Encoding1_DataMacro, sizeof(Encoding1)) == 0);
+ EXPECT_EQ(sizeof(Encoding1_DataMacro), sizeof(Encoding1));
+ EXPECT_EQ(memcmp(Encoding1, Encoding1_DataMacro, sizeof(Encoding1)), 0);
uint8_t buf[2048];
TLVWriter writer;
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding5(inSuite, writer);
+ WriteEncoding5(writer);
uint32_t encodedLen = writer.GetLengthWritten();
- NL_TEST_ASSERT(inSuite, sizeof(Encoding5_DataMacro) == encodedLen);
- NL_TEST_ASSERT(inSuite, memcmp(buf, Encoding5_DataMacro, encodedLen) == 0);
+ EXPECT_EQ(sizeof(Encoding5_DataMacro), encodedLen);
+ EXPECT_EQ(memcmp(buf, Encoding5_DataMacro, encodedLen), 0);
}
static CHIP_ERROR NullIterateHandler(const TLVReader & aReader, size_t aDepth, void * aContext)
@@ -1789,7 +1779,7 @@
/**
* Test CHIP TLV Utilities
*/
-void CheckTLVUtilities(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVUtilities)
{
uint8_t buf[2048];
TLVWriter writer;
@@ -1799,32 +1789,32 @@
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding1(inSuite, writer);
+ WriteEncoding1(writer);
uint32_t encodedLen = writer.GetLengthWritten();
- NL_TEST_ASSERT(inSuite, encodedLen == sizeof(Encoding1));
- NL_TEST_ASSERT(inSuite, memcmp(buf, Encoding1, encodedLen) == 0);
+ EXPECT_EQ(encodedLen, sizeof(Encoding1));
+ EXPECT_EQ(memcmp(buf, Encoding1, encodedLen), 0);
reader.Init(buf, encodedLen);
reader.ImplicitProfileId = TestProfile_2;
reader1.Init(reader);
err = reader1.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Find a tag
TLVReader tagReader;
err = chip::TLV::Utilities::Find(reader, ProfileTag(TestProfile_2, 65536), tagReader);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Find with reader positioned "on" the element of interest
err = chip::TLV::Utilities::Find(reader1, ProfileTag(TestProfile_1, 1), tagReader);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Find a tag that's not present
err = chip::TLV::Utilities::Find(reader, ProfileTag(TestProfile_2, 1024), tagReader);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_TLV_TAG_NOT_FOUND);
+ EXPECT_EQ(err, CHIP_ERROR_TLV_TAG_NOT_FOUND);
// Find with a predicate
{
@@ -1833,7 +1823,7 @@
writer.Init(buf1);
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding2(inSuite, writer);
+ WriteEncoding2(writer);
// Initialize a reader
reader1.Init(buf1, writer.GetLengthWritten());
@@ -1843,20 +1833,20 @@
reader1.Next();
Tag tag = ProfileTag(TestProfile_1, 1);
err = chip::TLV::Utilities::Find(reader1, FindContainerWithElement, &tag, tagReader, false);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_TLV_TAG_NOT_FOUND);
+ EXPECT_EQ(err, CHIP_ERROR_TLV_TAG_NOT_FOUND);
tag = ProfileTag(TestProfile_2, 2);
err = chip::TLV::Utilities::Find(reader1, FindContainerWithElement, &tag, tagReader, false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, tagReader.GetType() == kTLVType_Structure);
- NL_TEST_ASSERT(inSuite, tagReader.GetTag() == ProfileTag(TestProfile_1, 1));
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ EXPECT_EQ(tagReader.GetType(), kTLVType_Structure);
+ EXPECT_EQ(tagReader.GetTag(), ProfileTag(TestProfile_1, 1));
// Position the reader on the second element
reader1.Next();
err = chip::TLV::Utilities::Find(reader1, FindContainerWithElement, &tag, tagReader, false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, tagReader.GetType() == kTLVType_Structure);
- NL_TEST_ASSERT(inSuite, tagReader.GetTag() == ProfileTag(TestProfile_2, 1));
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ EXPECT_EQ(tagReader.GetType(), kTLVType_Structure);
+ EXPECT_EQ(tagReader.GetTag(), ProfileTag(TestProfile_2, 1));
}
// Count
@@ -1866,23 +1856,23 @@
reader1.Next();
err = chip::TLV::Utilities::Count(reader, count);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, count == expectedCount);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ EXPECT_EQ(count, expectedCount);
// Count with reader already positioned "on" the first element in the encoding
err = chip::TLV::Utilities::Count(reader1, count);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, count == expectedCount);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ EXPECT_EQ(count, expectedCount);
// Iterate
err = chip::TLV::Utilities::Iterate(reader, NullIterateHandler, nullptr);
- NL_TEST_ASSERT(inSuite, err == CHIP_END_OF_TLV);
+ EXPECT_EQ(err, CHIP_END_OF_TLV);
}
/**
* Test CHIP TLV Empty Find
*/
-void CheckTLVEmptyFind(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVEmptyFind)
{
uint8_t buf[30];
TLVWriter writer;
@@ -1892,7 +1882,7 @@
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- WriteEmptyEncoding(inSuite, writer);
+ WriteEmptyEncoding(writer);
uint32_t encodedLen = writer.GetLengthWritten();
@@ -1902,7 +1892,7 @@
// Find the empty container
TLVReader tagReader;
err = chip::TLV::Utilities::Find(reader, ProfileTag(TestProfile_1, 256), tagReader);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
// clang-format off
@@ -1945,7 +1935,7 @@
};
// clang-format on
-void WriteAppendReadTest0(nlTestSuite * inSuite)
+void WriteAppendReadTest0()
{
uint8_t buf[74];
uint32_t updatedLen;
@@ -1956,7 +1946,7 @@
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding2(inSuite, writer);
+ WriteEncoding2(writer);
uint32_t encodedLen = writer.GetLengthWritten();
@@ -1971,11 +1961,11 @@
printf("\n");
#endif
- NL_TEST_ASSERT(inSuite, encodedLen == sizeof(Encoding2));
- NL_TEST_ASSERT(inSuite, memcmp(buf, Encoding2, encodedLen) == 0);
+ EXPECT_EQ(encodedLen, sizeof(Encoding2));
+ EXPECT_EQ(memcmp(buf, Encoding2, encodedLen), 0);
// Append new data into encoding
- AppendEncoding2(inSuite, buf, encodedLen, sizeof(buf), updatedLen);
+ AppendEncoding2(buf, encodedLen, sizeof(buf), updatedLen);
#ifdef DUMP_ENCODING
printf("Updated encoding:\n");
@@ -1988,16 +1978,16 @@
printf("\n");
#endif
- NL_TEST_ASSERT(inSuite, updatedLen == sizeof(AppendedEncoding2));
- NL_TEST_ASSERT(inSuite, memcmp(buf, AppendedEncoding2, updatedLen) == 0);
+ EXPECT_EQ(updatedLen, sizeof(AppendedEncoding2));
+ EXPECT_EQ(memcmp(buf, AppendedEncoding2, updatedLen), 0);
reader.Init(buf, updatedLen);
reader.ImplicitProfileId = TestProfile_2;
- ReadAppendedEncoding2(inSuite, reader);
+ ReadAppendedEncoding2(reader);
}
-void WriteFindAppendReadTest(nlTestSuite * inSuite, bool findContainer)
+void WriteFindAppendReadTest(bool findContainer)
{
uint8_t buf[74];
uint32_t updatedLen;
@@ -2008,7 +1998,7 @@
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding2(inSuite, writer);
+ WriteEncoding2(writer);
uint32_t encodedLen = writer.GetLengthWritten();
@@ -2023,11 +2013,11 @@
printf("\n");
#endif
- NL_TEST_ASSERT(inSuite, encodedLen == sizeof(Encoding2));
- NL_TEST_ASSERT(inSuite, memcmp(buf, Encoding2, encodedLen) == 0);
+ EXPECT_EQ(encodedLen, sizeof(Encoding2));
+ EXPECT_EQ(memcmp(buf, Encoding2, encodedLen), 0);
// Append new data into encoding
- FindAppendEncoding2(inSuite, buf, encodedLen, sizeof(buf), updatedLen, findContainer);
+ FindAppendEncoding2(buf, encodedLen, sizeof(buf), updatedLen, findContainer);
#ifdef DUMP_ENCODING
printf("Updated encoding:\n");
@@ -2040,13 +2030,13 @@
printf("\n");
#endif
- NL_TEST_ASSERT(inSuite, updatedLen == sizeof(AppendedEncoding2));
- NL_TEST_ASSERT(inSuite, memcmp(buf, AppendedEncoding2, updatedLen) == 0);
+ EXPECT_EQ(updatedLen, sizeof(AppendedEncoding2));
+ EXPECT_EQ(memcmp(buf, AppendedEncoding2, updatedLen), 0);
reader.Init(buf, updatedLen);
reader.ImplicitProfileId = TestProfile_2;
- ReadAppendedEncoding2(inSuite, reader);
+ ReadAppendedEncoding2(reader);
}
// clang-format off
@@ -2068,7 +2058,7 @@
};
// clang-format on
-void WriteAppendReadTest1(nlTestSuite * inSuite)
+void WriteAppendReadTest1()
{
uint8_t buf[14];
uint32_t updatedLen;
@@ -2079,7 +2069,7 @@
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
uint32_t encodedLen = writer.GetLengthWritten();
@@ -2094,11 +2084,11 @@
printf("\n");
#endif
- NL_TEST_ASSERT(inSuite, encodedLen == sizeof(Encoding3));
- NL_TEST_ASSERT(inSuite, memcmp(buf, Encoding3, encodedLen) == 0);
+ EXPECT_EQ(encodedLen, sizeof(Encoding3));
+ EXPECT_EQ(memcmp(buf, Encoding3, encodedLen), 0);
// Append new data into encoding
- AppendEncoding3(inSuite, buf, encodedLen, sizeof(buf), updatedLen);
+ AppendEncoding3(buf, encodedLen, sizeof(buf), updatedLen);
#ifdef DUMP_ENCODING
printf("Updated encoding:\n");
@@ -2111,13 +2101,13 @@
printf("\n");
#endif
- NL_TEST_ASSERT(inSuite, updatedLen == sizeof(AppendedEncoding3));
- NL_TEST_ASSERT(inSuite, memcmp(buf, AppendedEncoding3, updatedLen) == 0);
+ EXPECT_EQ(updatedLen, sizeof(AppendedEncoding3));
+ EXPECT_EQ(memcmp(buf, AppendedEncoding3, updatedLen), 0);
reader.Init(buf, updatedLen);
reader.ImplicitProfileId = TestProfile_2;
- ReadAppendedEncoding3(inSuite, reader);
+ ReadAppendedEncoding3(reader);
}
// clang-format off
@@ -2130,7 +2120,7 @@
};
// clang-format on
-void AppendReadTest(nlTestSuite * inSuite)
+void AppendReadTest()
{
uint8_t buf[11];
uint32_t updatedLen;
@@ -2149,7 +2139,7 @@
#endif
// Append new data to encoding
- AppendEncoding4(inSuite, buf, 0, sizeof(buf), updatedLen);
+ AppendEncoding4(buf, 0, sizeof(buf), updatedLen);
#ifdef DUMP_ENCODING
printf("Updated encoding:\n");
@@ -2162,14 +2152,14 @@
printf("\n");
#endif
- NL_TEST_ASSERT(inSuite, updatedLen == sizeof(AppendedEncoding4));
- NL_TEST_ASSERT(inSuite, memcmp(buf, AppendedEncoding4, updatedLen) == 0);
+ EXPECT_EQ(updatedLen, sizeof(AppendedEncoding4));
+ EXPECT_EQ(memcmp(buf, AppendedEncoding4, updatedLen), 0);
TLVReader reader;
reader.Init(buf, updatedLen);
reader.ImplicitProfileId = TestProfile_2;
- ReadAppendedEncoding4(inSuite, reader);
+ ReadAppendedEncoding4(reader);
}
// clang-format off
@@ -2212,7 +2202,7 @@
};
// clang-format on
-void WriteDeleteReadTest(nlTestSuite * inSuite)
+void WriteDeleteReadTest()
{
uint8_t buf[74];
uint32_t updatedLen;
@@ -2223,7 +2213,7 @@
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding5(inSuite, writer);
+ WriteEncoding5(writer);
uint32_t encodedLen = writer.GetLengthWritten();
@@ -2237,25 +2227,25 @@
printf("\n");
#endif
- NL_TEST_ASSERT(inSuite, encodedLen == sizeof(Encoding5));
- NL_TEST_ASSERT(inSuite, memcmp(buf, Encoding5, encodedLen) == 0);
+ EXPECT_EQ(encodedLen, sizeof(Encoding5));
+ EXPECT_EQ(memcmp(buf, Encoding5, encodedLen), 0);
// Delete some elements from the encoding
- DeleteEncoding5(inSuite, buf, encodedLen, sizeof(buf), updatedLen);
+ DeleteEncoding5(buf, encodedLen, sizeof(buf), updatedLen);
- NL_TEST_ASSERT(inSuite, updatedLen == sizeof(DeletedEncoding5));
- NL_TEST_ASSERT(inSuite, memcmp(buf, DeletedEncoding5, updatedLen) == 0);
+ EXPECT_EQ(updatedLen, sizeof(DeletedEncoding5));
+ EXPECT_EQ(memcmp(buf, DeletedEncoding5, updatedLen), 0);
reader.Init(buf, updatedLen);
reader.ImplicitProfileId = TestProfile_2;
- ReadDeletedEncoding5(inSuite, reader);
+ ReadDeletedEncoding5(reader);
}
/**
* Test Packet Buffer
*/
-void CheckPacketBuffer(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckPacketBuffer)
{
System::PacketBufferHandle buf = System::PacketBufferHandle::New(sizeof(Encoding1), 0);
System::PacketBufferTLVWriter writer;
@@ -2264,19 +2254,19 @@
writer.Init(buf.Retain());
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding1(inSuite, writer);
+ WriteEncoding1(writer);
- TestBufferContents(inSuite, buf, Encoding1, sizeof(Encoding1));
+ TestBufferContents(buf, Encoding1, sizeof(Encoding1));
reader.Init(buf.Retain());
reader.ImplicitProfileId = TestProfile_2;
- ReadEncoding1(inSuite, reader);
+ ReadEncoding1(reader);
reader.Init(buf.Retain());
reader.ImplicitProfileId = TestProfile_2;
- ReadEncoding1(inSuite, reader);
+ ReadEncoding1(reader);
}
CHIP_ERROR CountEvictedMembers(TLVCircularBuffer & inBuffer, void * inAppData, TLVReader & inReader)
@@ -2286,10 +2276,10 @@
// "Process" the first element in the reader
err = inReader.Next();
- NL_TEST_ASSERT(context->mSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = inReader.Skip();
- NL_TEST_ASSERT(context->mSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
context->mEvictionCount++;
context->mEvictedBytes += inReader.GetLengthRead();
@@ -2297,7 +2287,7 @@
return CHIP_NO_ERROR;
}
-void CheckCircularTLVBufferSimple(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckCircularTLVBufferSimple)
{
// Write 40 bytes as 4 separate events into a 30 byte buffer. On
// completion of the test, the buffer should contain 2 elements
@@ -2307,7 +2297,7 @@
uint8_t backingStore[30];
CircularTLVWriter writer;
CircularTLVReader reader;
- TestTLVContext * context = static_cast<TestTLVContext *>(inContext);
+ TestTLVContext * context = &TestTLV::ctx;
TLVCircularBuffer buffer(backingStore, 30);
writer.Init(buffer);
writer.ImplicitProfileId = TestProfile_2;
@@ -2316,38 +2306,38 @@
context->mEvictedBytes = 0;
buffer.mProcessEvictedElement = CountEvictedMembers;
- buffer.mAppData = inContext;
+ buffer.mAppData = &TestTLV::ctx;
writer.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- NL_TEST_ASSERT(inSuite, context->mEvictionCount == 2);
- NL_TEST_ASSERT(inSuite, context->mEvictedBytes == 18);
- NL_TEST_ASSERT(inSuite, buffer.DataLength() == 22);
- NL_TEST_ASSERT(inSuite, (buffer.DataLength() + context->mEvictedBytes) == writer.GetLengthWritten());
+ EXPECT_EQ(context->mEvictionCount, 2);
+ EXPECT_EQ(context->mEvictedBytes, 18u);
+ EXPECT_EQ(buffer.DataLength(), 22u);
+ EXPECT_EQ((buffer.DataLength() + context->mEvictedBytes), writer.GetLengthWritten());
// At this point the buffer should contain 2 instances of Encoding3.
reader.Init(buffer);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- ReadEncoding3(inSuite, reader);
+ ReadEncoding3(reader);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- ReadEncoding3(inSuite, reader);
+ ReadEncoding3(reader);
// Check that the reader is out of data
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
-void CheckCircularTLVBufferStartMidway(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckCircularTLVBufferStartMidway)
{
// Write 40 bytes as 4 separate events into a 30 byte buffer. On
// completion of the test, the buffer should contain 2 elements
@@ -2357,7 +2347,7 @@
uint8_t backingStore[30];
CircularTLVWriter writer;
CircularTLVReader reader;
- TestTLVContext * context = static_cast<TestTLVContext *>(inContext);
+ TestTLVContext * context = &TestTLV::ctx;
TLVCircularBuffer buffer(backingStore, 30, &(backingStore[15]));
writer.Init(buffer);
writer.ImplicitProfileId = TestProfile_2;
@@ -2366,38 +2356,38 @@
context->mEvictedBytes = 0;
buffer.mProcessEvictedElement = CountEvictedMembers;
- buffer.mAppData = inContext;
+ buffer.mAppData = &TestTLV::ctx;
writer.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- NL_TEST_ASSERT(inSuite, context->mEvictionCount == 2);
- NL_TEST_ASSERT(inSuite, context->mEvictedBytes == 18);
- NL_TEST_ASSERT(inSuite, buffer.DataLength() == 22);
- NL_TEST_ASSERT(inSuite, (buffer.DataLength() + context->mEvictedBytes) == writer.GetLengthWritten());
+ EXPECT_EQ(context->mEvictionCount, 2);
+ EXPECT_EQ(context->mEvictedBytes, 18u);
+ EXPECT_EQ(buffer.DataLength(), 22u);
+ EXPECT_EQ((buffer.DataLength() + context->mEvictedBytes), writer.GetLengthWritten());
// At this point the buffer should contain 2 instances of Encoding3.
reader.Init(buffer);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- ReadEncoding3(inSuite, reader);
+ ReadEncoding3(reader);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- ReadEncoding3(inSuite, reader);
+ ReadEncoding3(reader);
// Check that the reader is out of data
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
-void CheckCircularTLVBufferEvictStraddlingEvent(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckCircularTLVBufferEvictStraddlingEvent)
{
// Write 95 bytes to the buffer as 9 different TLV elements: 1
// 7-byte element and 8 11-byte elements.
@@ -2405,7 +2395,7 @@
// and 7 elements should have been evicted in the last call to
// WriteEncoding.
- TestTLVContext * context = static_cast<TestTLVContext *>(inContext);
+ TestTLVContext * context = &TestTLV::ctx;
uint8_t backingStore[30];
CircularTLVWriter writer;
CircularTLVReader reader;
@@ -2417,53 +2407,52 @@
context->mEvictedBytes = 0;
buffer.mProcessEvictedElement = CountEvictedMembers;
- buffer.mAppData = inContext;
+ buffer.mAppData = &TestTLV::ctx;
writer.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
// the write below will evict an element that straddles the buffer boundary.
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- WriteEncoding3(inSuite, writer);
+ WriteEncoding3(writer);
- NL_TEST_ASSERT(inSuite,
- writer.GetLengthWritten() ==
- (8 * 11 + 7)); // 8 writes of Encoding3 (11 bytes each) and 7 bytes for the initial boolean.
- NL_TEST_ASSERT(inSuite, buffer.DataLength() == 22);
- NL_TEST_ASSERT(inSuite, (buffer.DataLength() + context->mEvictedBytes) == writer.GetLengthWritten());
- NL_TEST_ASSERT(inSuite, context->mEvictionCount == 7);
+ EXPECT_EQ(writer.GetLengthWritten(),
+ (8u * 11 + 7)); // 8 writes of Encoding3 (11 bytes each) and 7 bytes for the initial boolean.
+ EXPECT_EQ(buffer.DataLength(), 22u);
+ EXPECT_EQ((buffer.DataLength() + context->mEvictedBytes), writer.GetLengthWritten());
+ EXPECT_EQ(context->mEvictionCount, 7);
// At this point the buffer should contain 2 instances of Encoding3.
reader.Init(buffer);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- ReadEncoding3(inSuite, reader);
+ ReadEncoding3(reader);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- ReadEncoding3(inSuite, reader);
+ ReadEncoding3(reader);
// Check that the reader is out of data
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
-void CheckCircularTLVBufferEdge(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckCircularTLVBufferEdge)
{
- TestTLVContext * context = static_cast<TestTLVContext *>(inContext);
+ TestTLVContext * context = &TestTLV::ctx;
CHIP_ERROR err;
uint8_t backingStore[7];
uint8_t backingStore1[14];
@@ -2480,33 +2469,33 @@
context->mEvictedBytes = 0;
buffer.mProcessEvictedElement = CountEvictedMembers;
- buffer.mAppData = inContext;
+ buffer.mAppData = &TestTLV::ctx;
// Test eviction for an element that fits in the underlying buffer exactly
err = writer.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.PutBoolean(ProfileTag(TestProfile_1, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// At this point the buffer should contain only the boolean we just wrote
reader.Init(buffer);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
+ TestNext<TLVReader>(reader);
+ TEST_GET_NOERROR(reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
// Check that the reader is out of data
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
// verify that an element larger than the underlying buffer fails out.
err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_2, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_END_OF_TLV);
+ EXPECT_EQ(err, CHIP_END_OF_TLV);
// Verify reader correctness
@@ -2520,23 +2509,23 @@
writer.ImplicitProfileId = TestProfile_2;
err = writer.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(buffer1);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestEnd<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
+ TEST_GET_NOERROR(reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TestEnd<TLVReader>(reader);
buffer1.EvictHead();
reader.Init(buffer1);
reader.ImplicitProfileId = TestProfile_2;
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
writer.Init(buffer1);
@@ -2546,14 +2535,14 @@
context->mEvictedBytes = 0;
buffer1.mProcessEvictedElement = CountEvictedMembers;
- buffer1.mAppData = inContext;
+ buffer1.mAppData = &TestTLV::ctx;
// Two elements fit in the buffer exactly
err = writer.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.PutBoolean(ProfileTag(TestProfile_1, 2), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
@@ -2561,13 +2550,13 @@
reader.Init(buffer1);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TestNext<TLVReader>(reader);
+ TEST_GET_NOERROR(reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestNext<TLVReader>(inSuite, reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
+ TestNext<TLVReader>(reader);
+ TEST_GET_NOERROR(reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
// Check that the eviction works as expected
@@ -2577,11 +2566,11 @@
reader.Init(buffer1);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
+ TestNext<TLVReader>(reader);
+ TEST_GET_NOERROR(reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
// Check that the reader is out of data
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
// Write another boolean, verify that the buffer is full and contains two booleans
@@ -2589,22 +2578,22 @@
writer.ImplicitProfileId = TestProfile_2;
err = writer.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Verify that we can read out two elements from the buffer
reader.Init(buffer1);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
+ TestNext<TLVReader>(reader);
+ TEST_GET_NOERROR(reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), false);
- TestNext<TLVReader>(inSuite, reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TestNext<TLVReader>(reader);
+ TEST_GET_NOERROR(reader, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
// Evict the elements from the buffer, verfiy that we have an
// empty reader on our hands
@@ -2615,9 +2604,9 @@
reader.Init(buffer1);
reader.ImplicitProfileId = TestProfile_2;
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
-void CheckTLVPutStringF(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVPutStringF)
{
const size_t bufsize = 24;
char strBuffer[bufsize];
@@ -2632,22 +2621,22 @@
snprintf(strBuffer, sizeof(strBuffer), "Sample string %u", static_cast<unsigned int>(num));
err = writer.PutStringF(ProfileTag(TestProfile_1, 1), "Sample string %u", static_cast<unsigned int>(num));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(backingStore, writer.GetLengthWritten());
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = reader.GetString(valStr, bufsize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strncmp(valStr, strBuffer, bufsize) == 0);
+ EXPECT_EQ(strncmp(valStr, strBuffer, bufsize), 0);
}
-void CheckTLVPutStringSpan(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVPutStringSpan)
{
const size_t bufsize = 24;
char strBuffer[bufsize] = "Sample string";
@@ -2670,7 +2659,7 @@
strSpan = { strBuffer, static_cast<size_t>(0xffffffffff) };
err = writer.PutString(ProfileTag(TestProfile_1, 1), strSpan);
- NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
+ EXPECT_NE(err, CHIP_NO_ERROR);
}
{
@@ -2680,23 +2669,23 @@
strSpan = { strBuffer, strlen("Sample string") };
err = writer.PutString(ProfileTag(TestProfile_1, 1), strSpan);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(backingStore, writer.GetLengthWritten());
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = reader.GetString(valStr, bufsize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strncmp(valStr, strBuffer, bufsize) == 0);
+ EXPECT_EQ(strncmp(valStr, strBuffer, bufsize), 0);
}
}
-void CheckTLVPutStringFCircular(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVPutStringFCircular)
{
const size_t bufsize = 40;
char strBuffer[bufsize];
@@ -2714,30 +2703,30 @@
snprintf(strBuffer, sizeof(strBuffer), "Sample string %u", static_cast<unsigned int>(num));
err = writer.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.PutStringF(ProfileTag(TestProfile_1, 1), "Sample string %u", static_cast<unsigned int>(num));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(buffer);
// Skip over the initial element
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = reader.GetString(valStr, bufsize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strncmp(valStr, strBuffer, bufsize) == 0);
+ EXPECT_EQ(strncmp(valStr, strBuffer, bufsize), 0);
// Verify that the PutStringF will handle correctly the case with the discontinuous buffer
// This print will both stradle the boundary of the buffer and displace the previous two elements.
@@ -2746,22 +2735,22 @@
snprintf(strBuffer, sizeof(strBuffer), "Sample string %u", static_cast<unsigned int>(num));
err = writer.PutStringF(ProfileTag(TestProfile_1, 1), "Sample string %u", static_cast<unsigned int>(num));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(buffer);
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = reader.GetString(valStr, bufsize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strncmp(valStr, strBuffer, bufsize) == 0);
+ EXPECT_EQ(strncmp(valStr, strBuffer, bufsize), 0);
}
-void CheckTLVByteSpan(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVByteSpan)
{
const size_t bufSize = 14;
uint8_t bytesBuffer[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
@@ -2774,25 +2763,25 @@
ByteSpan writerSpan(bytesBuffer);
err = writer.Put(ProfileTag(TestProfile_1, 1), writerSpan);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(backingStore, writer.GetLengthWritten());
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
chip::ByteSpan readerSpan;
err = reader.Get(readerSpan);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, memcmp(readerSpan.data(), bytesBuffer, sizeof(bytesBuffer)) == 0);
+ EXPECT_EQ(memcmp(readerSpan.data(), bytesBuffer, sizeof(bytesBuffer)), 0);
}
#define IS1_CHAR "\x1F"
-void CheckTLVCharSpan(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVCharSpan)
{
struct CharSpanTestCase
{
@@ -2823,25 +2812,25 @@
writer.Init(backingStore);
err = writer.PutString(ProfileTag(TestProfile_1, 1), testCase.testString);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(backingStore, writer.GetLengthWritten());
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
chip::CharSpan readerSpan;
err = reader.Get(readerSpan);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, strlen(testCase.expectedString) == readerSpan.size());
- NL_TEST_ASSERT(inSuite, memcmp(readerSpan.data(), testCase.expectedString, strlen(testCase.expectedString)) == 0);
+ EXPECT_EQ(strlen(testCase.expectedString), readerSpan.size());
+ EXPECT_EQ(memcmp(readerSpan.data(), testCase.expectedString, strlen(testCase.expectedString)), 0);
}
}
-void CheckTLVGetLocalizedStringIdentifier(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVGetLocalizedStringIdentifier)
{
struct CharSpanTestCase
{
@@ -2881,19 +2870,19 @@
writer.Init(backingStore);
err = writer.PutString(ProfileTag(TestProfile_1, 1), testCase.testString);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(backingStore, writer.GetLengthWritten());
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
Optional<LocalizedStringIdentifier> readerLSID;
err = reader.Get(readerLSID);
- NL_TEST_ASSERT(inSuite, testCase.expectedResult == err);
- NL_TEST_ASSERT(inSuite, testCase.expectedLSID == readerLSID);
+ EXPECT_EQ(testCase.expectedResult, err);
+ EXPECT_EQ(testCase.expectedLSID, readerLSID);
}
// Error case: A case of TLVReader buffer underrun.
@@ -2907,14 +2896,14 @@
writer.Init(backingStore);
err = writer.PutString(ProfileTag(TestProfile_1, 1), sCharSpanTestCases[2].testString);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(backingStore, writer.GetLengthWritten() - 1);
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_TLV_UNDERRUN);
+ EXPECT_EQ(err, CHIP_ERROR_TLV_UNDERRUN);
}
// Error case: the reader is on a bytestring, not utf-8 string.
@@ -2929,23 +2918,23 @@
err = writer.PutBytes(ProfileTag(TestProfile_1, 1), reinterpret_cast<const uint8_t *>(sCharSpanTestCases[2].testString),
static_cast<uint32_t>(strlen(sCharSpanTestCases[2].testString)));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(backingStore, writer.GetLengthWritten());
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
Optional<LocalizedStringIdentifier> readerLSID;
err = reader.Get(readerLSID);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
- NL_TEST_ASSERT(inSuite, readerLSID == Optional<LocalizedStringIdentifier>());
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(readerLSID, Optional<LocalizedStringIdentifier>());
}
}
-void CheckTLVSkipCircular(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVSkipCircular)
{
const size_t bufsize = 40; // large enough s.t. 2 elements fit, 3rd causes eviction
uint8_t backingStore[bufsize];
@@ -2959,33 +2948,33 @@
writer.Init(buffer);
err = writer.PutString(AnonymousTag(), testString);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.PutString(AnonymousTag(), testString);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.PutString(AnonymousTag(), testString); // This event straddles the boundary
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.PutString(AnonymousTag(), testString); // This one does not.
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
reader.Init(buffer);
err = reader.Next(); // position the reader at the straddling element
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = reader.Skip(); // // Test that the buf ptr is handled correctly within the ReadData() function.
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
/**
* Test Buffer Overflow
*/
-void CheckBufferOverflow(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckBufferOverflow)
{
System::PacketBufferTLVReader reader;
@@ -3007,10 +2996,10 @@
writer.Init(buf.Retain(), /* useChainedBuffers = */ true);
writer.ImplicitProfileId = TestProfile_2;
- WriteEncoding1(inSuite, writer);
+ WriteEncoding1(writer);
}
- TestBufferContents(inSuite, buf, Encoding1, sizeof(Encoding1));
+ TestBufferContents(buf, Encoding1, sizeof(Encoding1));
// Compact the buffer, since we don't allow reading from chained
// buffers.
@@ -3019,7 +3008,7 @@
reader.Init(buf.Retain());
reader.ImplicitProfileId = TestProfile_2;
- ReadEncoding1(inSuite, reader);
+ ReadEncoding1(reader);
buf = System::PacketBufferHandle::New(sizeof(Encoding1), 0);
}
@@ -3050,7 +3039,7 @@
static const uint32_t kIdentifyResponseLen = 53;
-void CheckStrictAliasing(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckStrictAliasing)
{
const uint32_t kProfile_Id = 0x0000000e;
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -3060,15 +3049,15 @@
reader.ImplicitProfileId = kProfile_Id;
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == ProfileTag(kProfile_Id, 1));
+ EXPECT_EQ(reader.GetTag(), ProfileTag(kProfile_Id, 1));
}
/**
* Test CHIP TLV Writer Copy Container
*/
-void TestTLVWriterCopyContainer(nlTestSuite * inSuite)
+void TestTLVWriterCopyContainer()
{
uint8_t buf[2048];
@@ -3079,19 +3068,19 @@
reader.Init(Encoding1);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
CHIP_ERROR err = writer.CopyContainer(reader);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
uint32_t encodedLen = writer.GetLengthWritten();
- NL_TEST_ASSERT(inSuite, encodedLen == sizeof(Encoding1));
+ EXPECT_EQ(encodedLen, sizeof(Encoding1));
int memcmpRes = memcmp(buf, Encoding1, encodedLen);
- NL_TEST_ASSERT(inSuite, memcmpRes == 0);
+ EXPECT_EQ(memcmpRes, 0);
}
{
@@ -3101,20 +3090,20 @@
writer.ImplicitProfileId = TestProfile_2;
CHIP_ERROR err = writer.CopyContainer(ProfileTag(TestProfile_1, 1), Encoding1, sizeof(Encoding1));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
uint32_t encodedLen = writer.GetLengthWritten();
- NL_TEST_ASSERT(inSuite, encodedLen == sizeof(Encoding1));
+ EXPECT_EQ(encodedLen, sizeof(Encoding1));
int memcmpRes = memcmp(buf, Encoding1, encodedLen);
- NL_TEST_ASSERT(inSuite, memcmpRes == 0);
+ EXPECT_EQ(memcmpRes, 0);
}
}
/**
* Test CHIP TLV Writer Copy Element
*/
-void TestTLVWriterCopyElement(nlTestSuite * inSuite)
+void TestTLVWriterCopyElement()
{
CHIP_ERROR err;
uint8_t expectedBuf[2048], testBuf[2048];
@@ -3130,18 +3119,18 @@
writer.ImplicitProfileId = TestProfile_2;
err = writer.StartContainer(AnonymousTag(), kTLVType_Structure, outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
for (int i = 0; i < kRepeatCount; i++)
{
- WriteEncoding1(inSuite, writer);
+ WriteEncoding1(writer);
}
err = writer.EndContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
expectedLen = writer.GetLengthWritten();
@@ -3149,7 +3138,7 @@
writer.ImplicitProfileId = TestProfile_2;
err = writer.StartContainer(AnonymousTag(), kTLVType_Structure, outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
for (int i = 0; i < kRepeatCount; i++)
{
@@ -3158,99 +3147,99 @@
reader.Init(Encoding1);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
err = writer.CopyElement(reader);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer.EndContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
testLen = writer.GetLengthWritten();
- NL_TEST_ASSERT(inSuite, testLen == expectedLen);
+ EXPECT_EQ(testLen, expectedLen);
int memcmpRes = memcmp(testBuf, expectedBuf, testLen);
- NL_TEST_ASSERT(inSuite, memcmpRes == 0);
+ EXPECT_EQ(memcmpRes, 0);
}
-void PreserveSizeWrite(nlTestSuite * inSuite, TLVWriter & writer, bool preserveSize)
+void PreserveSizeWrite(TLVWriter & writer, bool preserveSize)
{
CHIP_ERROR err;
TLVWriter writer2;
// TLVTagControl::FullyQualified_8Bytes
err = writer.Put(ProfileTag(TestProfile_1, 4000000000ULL), static_cast<int64_t>(40000000000ULL), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(ProfileTag(TestProfile_1, 4000000000ULL), static_cast<int16_t>(12345), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Put(ProfileTag(TestProfile_1, 4000000000ULL), static_cast<float>(1.0));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
{
TLVWriter writer3;
err = writer2.OpenContainer(ContextTag(0), kTLVType_Array, writer3);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<uint8_t>(42), preserveSize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<uint16_t>(42), preserveSize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<uint32_t>(42), preserveSize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<uint64_t>(40000000000ULL), preserveSize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<int8_t>(-17), preserveSize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<int16_t>(-17), preserveSize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<int32_t>(-170000), preserveSize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<int64_t>(-170000), preserveSize);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// the below cases are for full coverage of PUTs
err = writer3.Put(AnonymousTag(), static_cast<uint64_t>(65535), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<int64_t>(32767), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer3.Put(AnonymousTag(), static_cast<int64_t>(40000000000ULL), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.CloseContainer(writer3);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
/**
* Test CHIP TLV Writer with Preserve Size
*/
-void TestTLVWriterPreserveSize(nlTestSuite * inSuite)
+void TestTLVWriterPreserveSize()
{
uint8_t buf[2048];
TLVWriter writer;
@@ -3258,16 +3247,16 @@
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- PreserveSizeWrite(inSuite, writer, true);
+ PreserveSizeWrite(writer, true);
uint32_t encodedLen = writer.GetLengthWritten();
- NL_TEST_ASSERT(inSuite, encodedLen == 105);
+ EXPECT_EQ(encodedLen, 105u);
}
/**
* Test error handling of CHIP TLV Writer
*/
-void TestTLVWriterErrorHandling(nlTestSuite * inSuite)
+void TestTLVWriterErrorHandling()
{
CHIP_ERROR err;
uint8_t buf[2048];
@@ -3278,45 +3267,45 @@
// OpenContainer() for non-container
err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Boolean, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
// Since OpenContainer failed, writer2 remains uninitialized.
writer2.Init(nullptr, 0);
// CloseContainer() for non-container
err = writer.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
// OpenContainer() failure
err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer3);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// CloseContainer() failure
err = writer.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_TLV_CONTAINER_OPEN);
+ EXPECT_EQ(err, CHIP_ERROR_TLV_CONTAINER_OPEN);
// StartContainer()
TLVType outerContainerType;
err = writer.StartContainer(ProfileTag(TestProfile_2, 4000000000ULL), kTLVType_Boolean, outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
// EndContainer()
outerContainerType = kTLVType_Boolean;
err = writer.EndContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
// PutPreEncodedContainer()
TLVReader reader;
reader.Init(buf, 2048);
err = writer.PutPreEncodedContainer(ProfileTag(TestProfile_2, 4000000000ULL), kTLVType_Boolean, reader.GetReadPoint(),
reader.GetRemainingLength());
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INVALID_ARGUMENT);
+ EXPECT_EQ(err, CHIP_ERROR_INVALID_ARGUMENT);
}
-void TestTLVEmptyString(nlTestSuite * inSuite)
+void TestTLVEmptyString()
{
uint8_t buf[2];
TLVWriter writer;
@@ -3326,42 +3315,42 @@
writer.Init(buf);
err = writer.PutString(AnonymousTag(), nullptr, 0);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
TLVReader reader;
reader.Init(buf);
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = reader.Get(s);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, s.data() == nullptr);
- NL_TEST_ASSERT(inSuite, s.size() == 0);
+ EXPECT_EQ(s.data(), nullptr);
+ EXPECT_EQ(s.size(), 0u);
}
/**
* Test CHIP TLV Writer
*/
-void CheckTLVWriter(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVWriter)
{
- TestTLVWriterCopyContainer(inSuite);
+ TestTLVWriterCopyContainer();
- TestTLVWriterCopyElement(inSuite);
+ TestTLVWriterCopyElement();
- TestTLVWriterPreserveSize(inSuite);
+ TestTLVWriterPreserveSize();
- TestTLVWriterErrorHandling(inSuite);
+ TestTLVWriterErrorHandling();
- TestTLVEmptyString(inSuite);
+ TestTLVEmptyString();
}
-void SkipNonContainer(nlTestSuite * inSuite)
+void SkipNonContainer()
{
TLVReader reader;
const uint8_t * readpoint1 = nullptr;
@@ -3370,19 +3359,19 @@
reader.Init(Encoding1);
reader.ImplicitProfileId = TestProfile_2;
- TestSkip(inSuite, reader);
+ TestSkip(reader);
readpoint1 = reader.GetReadPoint();
// Skip again, to check the operation is idempotent
- TestSkip(inSuite, reader);
+ TestSkip(reader);
readpoint2 = reader.GetReadPoint();
- NL_TEST_ASSERT(inSuite, readpoint1 == readpoint2);
+ EXPECT_EQ(readpoint1, readpoint2);
}
-void SkipContainer(nlTestSuite * inSuite)
+void SkipContainer()
{
TLVReader reader;
const uint8_t * readpoint1 = nullptr;
@@ -3391,179 +3380,176 @@
reader.Init(Encoding1);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- TestSkip(inSuite, reader);
+ TestSkip(reader);
readpoint1 = reader.GetReadPoint();
// Skip again, to check the operation is idempotent
- TestSkip(inSuite, reader);
+ TestSkip(reader);
readpoint2 = reader.GetReadPoint();
- NL_TEST_ASSERT(inSuite, readpoint1 == readpoint2);
+ EXPECT_EQ(readpoint1, readpoint2);
}
-void NextContainer(nlTestSuite * inSuite)
+void NextContainer()
{
TLVReader reader;
reader.Init(Encoding1);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
CHIP_ERROR err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_END_OF_TLV);
+ EXPECT_EQ(err, CHIP_END_OF_TLV);
}
/**
* Test CHIP TLV Reader Skip functions
*/
-void TestTLVReaderSkip(nlTestSuite * inSuite)
+void TestTLVReaderSkip()
{
- SkipNonContainer(inSuite);
+ SkipNonContainer();
- SkipContainer(inSuite);
+ SkipContainer();
- NextContainer(inSuite);
+ NextContainer();
}
/**
* Test CHIP TLV Reader Dup functions
*/
-void TestTLVReaderDup(nlTestSuite * inSuite)
+void TestTLVReaderDup()
{
TLVReader reader;
reader.Init(Encoding1);
reader.ImplicitProfileId = TestProfile_2;
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
{
TLVReader reader2;
- TestAndOpenContainer(inSuite, reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader2);
+ TestAndOpenContainer(reader, kTLVType_Structure, ProfileTag(TestProfile_1, 1), reader2);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
+ TEST_GET_NOERROR(reader2, kTLVType_Boolean, ProfileTag(TestProfile_1, 2), true);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
+ TEST_GET_NOERROR(reader2, kTLVType_Boolean, ProfileTag(TestProfile_2, 2), false);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
{
TLVReader reader3;
- TestAndOpenContainer(inSuite, reader2, kTLVType_Array, ContextTag(0), reader3);
+ TestAndOpenContainer(reader2, kTLVType_Array, ContextTag(0), reader3);
- TestNext<TLVReader>(inSuite, reader3);
+ TestNext<TLVReader>(reader3);
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(42));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(42));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(42));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(42));
- TEST_GET(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(42),
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(42));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(42));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(42));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(42));
+ TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(42), CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(42), CHIP_ERROR_WRONG_TLV_TYPE);
+
+ TestNext<TLVReader>(reader3);
+
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(-17));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(-17));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(-17));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(-17));
+
+ TestNext<TLVReader>(reader3);
+
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(-170000));
+ TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(-170000));
+
+ TestNext<TLVReader>(reader3);
+
+ TEST_GET(reader3, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(40000000000ULL),
CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(42),
- CHIP_ERROR_WRONG_TLV_TYPE);
+ TEST_GET_NOERROR(reader3, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(40000000000ULL));
- TestNext<TLVReader>(inSuite, reader3);
-
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(-17));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(-17));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(-17));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(-17));
-
- TestNext<TLVReader>(inSuite, reader3);
-
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(-170000));
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(-170000));
-
- TestNext<TLVReader>(inSuite, reader3);
-
- TEST_GET(inSuite, reader3, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<int64_t>(40000000000ULL),
- CHIP_ERROR_WRONG_TLV_TYPE);
- TEST_GET_NOERROR(inSuite, reader3, kTLVType_UnsignedInteger, AnonymousTag(), static_cast<uint64_t>(40000000000ULL));
-
- TestNext<TLVReader>(inSuite, reader3);
+ TestNext<TLVReader>(reader3);
{
TLVReader reader4;
- TestAndOpenContainer(inSuite, reader3, kTLVType_Structure, AnonymousTag(), reader4);
+ TestAndOpenContainer(reader3, kTLVType_Structure, AnonymousTag(), reader4);
- TestEndAndCloseContainer(inSuite, reader3, reader4);
+ TestEndAndCloseContainer(reader3, reader4);
}
- TestNext<TLVReader>(inSuite, reader3);
+ TestNext<TLVReader>(reader3);
{
TLVReader reader5;
- TestAndOpenContainer(inSuite, reader3, kTLVType_List, AnonymousTag(), reader5);
+ TestAndOpenContainer(reader3, kTLVType_List, AnonymousTag(), reader5);
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
- TestNull(inSuite, reader5, ProfileTag(TestProfile_1, 17));
+ TestNull(reader5, ProfileTag(TestProfile_1, 17));
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
- TestNull(inSuite, reader5, ProfileTag(TestProfile_2, 900000));
+ TestNull(reader5, ProfileTag(TestProfile_2, 900000));
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
- TestNull(inSuite, reader5, AnonymousTag());
+ TestNull(reader5, AnonymousTag());
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
{
TLVType outerContainerType;
- TestAndEnterContainer<TLVReader>(inSuite, reader5, kTLVType_Structure, ProfileTag(TestProfile_2, 4000000000ULL),
+ TestAndEnterContainer<TLVReader>(reader5, kTLVType_Structure, ProfileTag(TestProfile_2, 4000000000ULL),
outerContainerType);
- TestNext<TLVReader>(inSuite, reader5);
+ TestNext<TLVReader>(reader5);
- TestDupString(inSuite, reader5, CommonTag(70000), sLargeString);
+ TestDupString(reader5, CommonTag(70000), sLargeString);
- TestEndAndExitContainer<TLVReader>(inSuite, reader5, outerContainerType);
+ TestEndAndExitContainer<TLVReader>(reader5, outerContainerType);
}
- TestEndAndCloseContainer(inSuite, reader3, reader5);
+ TestEndAndCloseContainer(reader3, reader5);
}
- TestEndAndCloseContainer(inSuite, reader2, reader3);
+ TestEndAndCloseContainer(reader2, reader3);
}
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TestDupBytes(inSuite, reader2, ProfileTag(TestProfile_1, 5), reinterpret_cast<const uint8_t *>("This is a test"), 14);
+ TestDupBytes(reader2, ProfileTag(TestProfile_1, 5), reinterpret_cast<const uint8_t *>("This is a test"), 14);
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), 17.9f);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535),
- static_cast<double>(17.9f));
+ TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), 17.9f);
+ TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), static_cast<double>(17.9f));
- TestNext<TLVReader>(inSuite, reader2);
+ TestNext<TLVReader>(reader2);
- TEST_GET_NOERROR(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65536), 17.9);
+ TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65536), 17.9);
- TestEndAndCloseContainer(inSuite, reader, reader2);
+ TestEndAndCloseContainer(reader, reader2);
}
- TestEnd<TLVReader>(inSuite, reader);
+ TestEnd<TLVReader>(reader);
}
/**
* Test error handling of CHIP TLV Reader
*/
-void TestTLVReaderErrorHandling(nlTestSuite * inSuite)
+void TestTLVReaderErrorHandling()
{
CHIP_ERROR err;
uint8_t buf[2048] = { 0 };
@@ -3575,118 +3561,118 @@
// Get(bool&)
bool val;
err = reader.Get(val);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
// Get(float&)
float numF;
err = reader.Get(numF);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
// Get(double&)
double numD;
err = reader.Get(numD);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
// Get(uint64_t&)
uint64_t num;
err = reader.Get(num);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
// GetBytes()
uint8_t bBuf[16];
err = reader.GetBytes(bBuf, sizeof(bBuf));
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
// GetString()
char sBuf[16];
err = reader.GetString(sBuf, sizeof(sBuf));
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
// OpenContainer()
TLVReader reader2;
err = reader.OpenContainer(reader2);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
// CloseContainer()
err = reader.CloseContainer(reader2);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
// EnterContainer()
TLVType outerContainerType = kTLVType_Boolean;
err = reader.EnterContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
// DupString()
char * str = static_cast<char *>(chip::Platform::MemoryAlloc(16));
err = reader.DupString(str);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
chip::Platform::MemoryFree(str);
// GetDataPtr()
const uint8_t * data = static_cast<uint8_t *>(chip::Platform::MemoryAlloc(16));
err = reader.GetDataPtr(data);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
chip::Platform::MemoryFree(const_cast<uint8_t *>(data));
}
-void TestTLVReaderExpect(nlTestSuite * inSuite)
+void TestTLVReaderExpect()
{
// Prepare some test data
uint8_t buffer[20];
TLVWriter writer;
writer.Init(buffer, sizeof(buffer));
TLVType outerContainer;
- NL_TEST_ASSERT_SUCCESS(inSuite, writer.StartContainer(AnonymousTag(), kTLVType_Structure, outerContainer));
- NL_TEST_ASSERT_SUCCESS(inSuite, writer.PutBoolean(ContextTag(23), false));
- NL_TEST_ASSERT_SUCCESS(inSuite, writer.EndContainer(outerContainer));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.StartContainer(AnonymousTag(), kTLVType_Structure, outerContainer));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.PutBoolean(ContextTag(23), false));
+ EXPECT_EQ(CHIP_NO_ERROR, writer.EndContainer(outerContainer));
TLVReader reader;
reader.Init(buffer, writer.GetLengthWritten());
// Positioned before the first element
- NL_TEST_ASSERT(inSuite, reader.GetType() == kTLVType_NotSpecified);
+ EXPECT_EQ(reader.GetType(), kTLVType_NotSpecified);
- NL_TEST_ASSERT(inSuite, reader.Expect(AnonymousTag()) == CHIP_ERROR_WRONG_TLV_TYPE);
- NL_TEST_ASSERT(inSuite, reader.Expect(ContextTag(23)) == CHIP_ERROR_WRONG_TLV_TYPE);
- NL_TEST_ASSERT(inSuite, reader.Expect(kTLVType_Boolean, AnonymousTag()) == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(reader.Expect(AnonymousTag()), CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(reader.Expect(ContextTag(23)), CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(reader.Expect(kTLVType_Boolean, AnonymousTag()), CHIP_ERROR_WRONG_TLV_TYPE);
// Positioned on kTLVType_Structure / AnonymousTag(),
- NL_TEST_ASSERT_SUCCESS(inSuite, reader.Next());
- NL_TEST_ASSERT(inSuite, reader.GetType() == kTLVType_Structure);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == AnonymousTag());
+ EXPECT_EQ(CHIP_NO_ERROR, reader.Next());
+ EXPECT_EQ(reader.GetType(), kTLVType_Structure);
+ EXPECT_EQ(reader.GetTag(), AnonymousTag());
- NL_TEST_ASSERT(inSuite, reader.Expect(ContextTag(23)) == CHIP_ERROR_UNEXPECTED_TLV_ELEMENT);
- NL_TEST_ASSERT_SUCCESS(inSuite, reader.Expect(AnonymousTag()));
+ EXPECT_EQ(reader.Expect(ContextTag(23)), CHIP_ERROR_UNEXPECTED_TLV_ELEMENT);
+ EXPECT_EQ(CHIP_NO_ERROR, reader.Expect(AnonymousTag()));
- NL_TEST_ASSERT(inSuite, reader.Expect(kTLVType_SignedInteger, AnonymousTag()) == CHIP_ERROR_WRONG_TLV_TYPE);
- NL_TEST_ASSERT_SUCCESS(inSuite, reader.Expect(kTLVType_Structure, AnonymousTag()));
+ EXPECT_EQ(reader.Expect(kTLVType_SignedInteger, AnonymousTag()), CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(CHIP_NO_ERROR, reader.Expect(kTLVType_Structure, AnonymousTag()));
// Positioned before first struct element
- NL_TEST_ASSERT_SUCCESS(inSuite, reader.EnterContainer(outerContainer));
- NL_TEST_ASSERT(inSuite, reader.GetType() == kTLVType_NotSpecified);
+ EXPECT_EQ(CHIP_NO_ERROR, reader.EnterContainer(outerContainer));
+ EXPECT_EQ(reader.GetType(), kTLVType_NotSpecified);
- NL_TEST_ASSERT(inSuite, reader.Expect(AnonymousTag()) == CHIP_ERROR_WRONG_TLV_TYPE);
- NL_TEST_ASSERT(inSuite, reader.Expect(ContextTag(23)) == CHIP_ERROR_WRONG_TLV_TYPE);
- NL_TEST_ASSERT(inSuite, reader.Expect(kTLVType_Boolean, AnonymousTag()) == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(reader.Expect(AnonymousTag()), CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(reader.Expect(ContextTag(23)), CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(reader.Expect(kTLVType_Boolean, AnonymousTag()), CHIP_ERROR_WRONG_TLV_TYPE);
// Positioned on kTLVType_Boolean / ContextTag(23)
- NL_TEST_ASSERT_SUCCESS(inSuite, reader.Next());
- NL_TEST_ASSERT(inSuite, reader.GetType() == kTLVType_Boolean);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == ContextTag(23));
+ EXPECT_EQ(CHIP_NO_ERROR, reader.Next());
+ EXPECT_EQ(reader.GetType(), kTLVType_Boolean);
+ EXPECT_EQ(reader.GetTag(), ContextTag(23));
- NL_TEST_ASSERT(inSuite, reader.Expect(AnonymousTag()) == CHIP_ERROR_UNEXPECTED_TLV_ELEMENT);
- NL_TEST_ASSERT(inSuite, reader.Expect(ContextTag(42)) == CHIP_ERROR_UNEXPECTED_TLV_ELEMENT);
- NL_TEST_ASSERT_SUCCESS(inSuite, reader.Expect(ContextTag(23)));
+ EXPECT_EQ(reader.Expect(AnonymousTag()), CHIP_ERROR_UNEXPECTED_TLV_ELEMENT);
+ EXPECT_EQ(reader.Expect(ContextTag(42)), CHIP_ERROR_UNEXPECTED_TLV_ELEMENT);
+ EXPECT_EQ(CHIP_NO_ERROR, reader.Expect(ContextTag(23)));
- NL_TEST_ASSERT(inSuite, reader.Expect(kTLVType_SignedInteger, ContextTag(23)) == CHIP_ERROR_WRONG_TLV_TYPE);
- NL_TEST_ASSERT_SUCCESS(inSuite, reader.Expect(kTLVType_Boolean, ContextTag(23)));
+ EXPECT_EQ(reader.Expect(kTLVType_SignedInteger, ContextTag(23)), CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(CHIP_NO_ERROR, reader.Expect(kTLVType_Boolean, ContextTag(23)));
}
/**
* Test that CHIP TLV reader returns an error when a read is requested that
* would truncate the output.
*/
-void TestTLVReaderTruncatedReads(nlTestSuite * inSuite)
+void TestTLVReaderTruncatedReads()
{
uint8_t buf[2048];
TLVWriter writer;
@@ -3700,23 +3686,23 @@
writer.ImplicitProfileId = TestProfile_2;
err = writer.Put(AnonymousTag(), double{ 12.5 });
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Test reading values from the buffer
reader.Init(buf);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_FloatingPointNumber, AnonymousTag(), 12.5);
+ TEST_GET_NOERROR(reader, kTLVType_FloatingPointNumber, AnonymousTag(), 12.5);
err = reader.Get(outF);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE);
+ EXPECT_EQ(err, CHIP_ERROR_WRONG_TLV_TYPE);
}
/**
* Test CHIP TLV Reader in a use case
*/
-void TestTLVReaderInPractice(nlTestSuite * inSuite)
+void TestTLVReaderInPractice()
{
uint8_t buf[2048];
TLVWriter writer;
@@ -3725,27 +3711,25 @@
writer.Init(buf);
writer.ImplicitProfileId = TestProfile_2;
- PreserveSizeWrite(inSuite, writer, true);
+ PreserveSizeWrite(writer, true);
reader.Init(buf);
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, ProfileTag(TestProfile_1, 4000000000ULL),
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, ProfileTag(TestProfile_1, 4000000000ULL),
static_cast<int64_t>(40000000000ULL));
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_SignedInteger, ProfileTag(TestProfile_1, 4000000000ULL),
- static_cast<int64_t>(12345));
+ TEST_GET_NOERROR(reader, kTLVType_SignedInteger, ProfileTag(TestProfile_1, 4000000000ULL), static_cast<int64_t>(12345));
- TestNext<TLVReader>(inSuite, reader);
+ TestNext<TLVReader>(reader);
- TEST_GET_NOERROR(inSuite, reader, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_1, 4000000000ULL),
- static_cast<float>(1.0));
+ TEST_GET_NOERROR(reader, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_1, 4000000000ULL), static_cast<float>(1.0));
}
-void TestTLVReader_NextOverContainer_ProcessElement(nlTestSuite * inSuite, TLVReader & reader, void * context)
+void TestTLVReader_NextOverContainer_ProcessElement(TLVReader & reader, void * context)
{
CHIP_ERROR err, nextRes1, nextRes2;
TLVType outerContainerType;
@@ -3759,38 +3743,38 @@
// Manually advance one of the readers to the element immediately after the container (if any).
err = readerClone1.EnterContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- ForEachElement(inSuite, readerClone1, nullptr, nullptr);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ ForEachElement(readerClone1, nullptr, nullptr);
err = readerClone1.ExitContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
nextRes1 = readerClone1.Next();
- NL_TEST_ASSERT(inSuite, nextRes1 == CHIP_NO_ERROR || nextRes1 == CHIP_END_OF_TLV);
+ EXPECT_TRUE(nextRes1 == CHIP_NO_ERROR || nextRes1 == CHIP_END_OF_TLV);
// For the other reader, skip over the entire container using the Next() method.
nextRes2 = readerClone2.Next();
- NL_TEST_ASSERT(inSuite, nextRes2 == CHIP_NO_ERROR || nextRes2 == CHIP_END_OF_TLV);
+ EXPECT_TRUE(nextRes2 == CHIP_NO_ERROR || nextRes2 == CHIP_END_OF_TLV);
// Verify the two readers end up in the same state/position.
- NL_TEST_ASSERT(inSuite, nextRes1 == nextRes2);
- NL_TEST_ASSERT(inSuite, readerClone1.GetType() == readerClone2.GetType());
- NL_TEST_ASSERT(inSuite, readerClone1.GetReadPoint() == readerClone2.GetReadPoint());
+ EXPECT_EQ(nextRes1, nextRes2);
+ EXPECT_EQ(readerClone1.GetType(), readerClone2.GetType());
+ EXPECT_EQ(readerClone1.GetReadPoint(), readerClone2.GetReadPoint());
}
}
/**
* Test using CHIP TLV Reader Next() method to skip over containers.
*/
-void TestTLVReader_NextOverContainer(nlTestSuite * inSuite)
+void TestTLVReader_NextOverContainer()
{
TLVReader reader;
reader.Init(Encoding1);
reader.ImplicitProfileId = TestProfile_2;
- ForEachElement(inSuite, reader, nullptr, TestTLVReader_NextOverContainer_ProcessElement);
+ ForEachElement(reader, nullptr, TestTLVReader_NextOverContainer_ProcessElement);
}
-void TestTLVReader_SkipOverContainer_ProcessElement(nlTestSuite * inSuite, TLVReader & reader, void * context)
+void TestTLVReader_SkipOverContainer_ProcessElement(TLVReader & reader, void * context)
{
CHIP_ERROR err;
TLVType outerContainerType;
@@ -3804,83 +3788,83 @@
// Manually advance one of the readers to immediately after the container.
err = readerClone1.EnterContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- ForEachElement(inSuite, readerClone1, nullptr, nullptr);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ ForEachElement(readerClone1, nullptr, nullptr);
err = readerClone1.ExitContainer(outerContainerType);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// For the other reader, skip over the entire container using the Skip() method.
err = readerClone2.Skip();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// Verify the two readers end up in the same state/position.
- NL_TEST_ASSERT(inSuite, readerClone1.GetType() == readerClone2.GetType());
- NL_TEST_ASSERT(inSuite, readerClone1.GetReadPoint() == readerClone2.GetReadPoint());
+ EXPECT_EQ(readerClone1.GetType(), readerClone2.GetType());
+ EXPECT_EQ(readerClone1.GetReadPoint(), readerClone2.GetReadPoint());
}
}
/**
* Test using CHIP TLV Reader Skip() method to skip over containers.
*/
-void TestTLVReader_SkipOverContainer(nlTestSuite * inSuite)
+void TestTLVReader_SkipOverContainer()
{
TLVReader reader;
reader.Init(Encoding1);
reader.ImplicitProfileId = TestProfile_2;
- ForEachElement(inSuite, reader, nullptr, TestTLVReader_SkipOverContainer_ProcessElement);
+ ForEachElement(reader, nullptr, TestTLVReader_SkipOverContainer_ProcessElement);
}
/**
* Tests using an uninitialized TLVReader.
*/
-void TestTLVReaderUninitialized(nlTestSuite * inSuite)
+void TestTLVReaderUninitialized()
{
TLVReader reader;
- NL_TEST_ASSERT(inSuite, reader.GetType() == kTLVType_NotSpecified);
- NL_TEST_ASSERT(inSuite, reader.GetLength() == 0);
- NL_TEST_ASSERT(inSuite, reader.GetControlByte() == kTLVControlByte_NotSpecified);
- NL_TEST_ASSERT(inSuite, reader.GetContainerType() == kTLVType_NotSpecified);
- NL_TEST_ASSERT(inSuite, reader.GetLengthRead() == 0);
- NL_TEST_ASSERT(inSuite, reader.GetRemainingLength() == 0);
- NL_TEST_ASSERT(inSuite, reader.GetTotalLength() == 0);
- NL_TEST_ASSERT(inSuite, reader.GetBackingStore() == nullptr);
- NL_TEST_ASSERT(inSuite, reader.IsElementDouble() == false);
- NL_TEST_ASSERT(inSuite, reader.GetReadPoint() == nullptr);
- NL_TEST_ASSERT(inSuite, reader.ImplicitProfileId == kProfileIdNotSpecified);
- NL_TEST_ASSERT(inSuite, reader.AppData == nullptr);
+ EXPECT_EQ(reader.GetType(), kTLVType_NotSpecified);
+ EXPECT_EQ(reader.GetLength(), 0u);
+ EXPECT_EQ(reader.GetControlByte(), kTLVControlByte_NotSpecified);
+ EXPECT_EQ(reader.GetContainerType(), kTLVType_NotSpecified);
+ EXPECT_EQ(reader.GetLengthRead(), 0u);
+ EXPECT_EQ(reader.GetRemainingLength(), 0u);
+ EXPECT_EQ(reader.GetTotalLength(), 0u);
+ EXPECT_EQ(reader.GetBackingStore(), nullptr);
+ EXPECT_EQ(reader.IsElementDouble(), false);
+ EXPECT_EQ(reader.GetReadPoint(), nullptr);
+ EXPECT_EQ(reader.ImplicitProfileId, kProfileIdNotSpecified);
+ EXPECT_EQ(reader.AppData, nullptr);
}
/**
* Test CHIP TLV Reader
*/
-void CheckTLVReader(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVReader)
{
- TestTLVReaderSkip(inSuite);
+ TestTLVReaderSkip();
- TestTLVReaderDup(inSuite);
+ TestTLVReaderDup();
- TestTLVReaderErrorHandling(inSuite);
+ TestTLVReaderErrorHandling();
- TestTLVReaderExpect(inSuite);
+ TestTLVReaderExpect();
- TestTLVReaderTruncatedReads(inSuite);
+ TestTLVReaderTruncatedReads();
- TestTLVReaderInPractice(inSuite);
+ TestTLVReaderInPractice();
- TestTLVReader_NextOverContainer(inSuite);
+ TestTLVReader_NextOverContainer();
- TestTLVReader_SkipOverContainer(inSuite);
+ TestTLVReader_SkipOverContainer();
- TestTLVReaderUninitialized(inSuite);
+ TestTLVReaderUninitialized();
}
/**
* Test CHIP TLV Items
*/
-static void TestItems(nlTestSuite * inSuite, void * inContext)
+static void TestItems()
{
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -3891,83 +3875,83 @@
TLVWriter writer2;
err = writer.OpenContainer(AnonymousTag(), kTLVType_Array, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
{
err = writer2.PutBoolean(AnonymousTag(), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<int8_t>(-1));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<int16_t>(-2));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<int32_t>(-3));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<int64_t>(-4));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<float>(-5.5));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<double>(-3.14159265358979323846));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.OpenContainer(AnonymousTag(), kTLVType_Array, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
{
err = writer2.PutBoolean(AnonymousTag(), false);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<int8_t>(1));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<int16_t>(2));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<int32_t>(3));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<int64_t>(4));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<uint8_t>(5));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<uint16_t>(6));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<uint32_t>(7));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<uint64_t>(8));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<float>(9.9));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.Put(AnonymousTag(), static_cast<double>(3.14159265358979323846));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
err = writer.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
/**
* Test CHIP TLV Containers
*/
-static void TestContainers(nlTestSuite * inSuite, void * inContext)
+static void TestContainers()
{
CHIP_ERROR err = CHIP_NO_ERROR;
TLVWriter writer;
@@ -3977,52 +3961,52 @@
TLVWriter writer2;
err = writer.OpenContainer(AnonymousTag(), kTLVType_Array, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
TLVType type = writer2.GetContainerType();
- NL_TEST_ASSERT(inSuite, type == kTLVType_Array);
+ EXPECT_EQ(type, kTLVType_Array);
err = writer.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.OpenContainer(AnonymousTag(), kTLVType_Structure, writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
type = writer2.GetContainerType();
- NL_TEST_ASSERT(inSuite, type == kTLVType_Structure);
+ EXPECT_EQ(type, kTLVType_Structure);
err = writer.CloseContainer(writer2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
}
/**
* Test CHIP TLV Basics
*/
-static void CheckTLVBasics(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVBasics)
{
- TestItems(inSuite, inContext);
- TestContainers(inSuite, inContext);
+ TestItems();
+ TestContainers();
}
/**
* Test CHIP TLV Updater
*/
-static void CheckCHIPUpdater(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckCHIPUpdater)
{
- WriteAppendReadTest0(inSuite);
+ WriteAppendReadTest0();
- WriteAppendReadTest1(inSuite);
+ WriteAppendReadTest1();
- WriteFindAppendReadTest(inSuite, false); // Find an element
+ WriteFindAppendReadTest(false); // Find an element
- WriteFindAppendReadTest(inSuite, true); // Find a container
+ WriteFindAppendReadTest(true); // Find a container
- AppendReadTest(inSuite);
+ AppendReadTest();
- WriteDeleteReadTest(inSuite);
+ WriteDeleteReadTest();
}
/**
@@ -4041,7 +4025,7 @@
SetCloseContainerReserved(false);
}
-static void CheckCloseContainerReserve(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckCloseContainerReserve)
{
// We are writing the structure looking like:
//
@@ -4070,114 +4054,114 @@
writer1.Init(buf);
err = writer1.OpenContainer(AnonymousTag(), kTLVType_Array, innerWriter1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = innerWriter1.OpenContainer(AnonymousTag(), kTLVType_Structure, innerWriter2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = innerWriter2.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
err = innerWriter1.CloseContainer(innerWriter2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.CloseContainer(innerWriter1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
writer2.Init(buf, sizeof(buf));
err = writer2.OpenContainer(AnonymousTag(), kTLVType_Array, innerWriter1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = innerWriter1.OpenContainer(AnonymousTag(), kTLVType_Structure, innerWriter2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = innerWriter2.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = innerWriter1.CloseContainer(innerWriter2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.CloseContainer(innerWriter1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
// test the same scheme works on the Start/End container
writer1.Init(buf);
err = writer1.StartContainer(AnonymousTag(), kTLVType_Array, container1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.StartContainer(AnonymousTag(), kTLVType_Structure, container2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
err = writer1.EndContainer(container2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer1.EndContainer(container1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
writer2.Init(buf, sizeof(buf));
err = writer2.StartContainer(AnonymousTag(), kTLVType_Array, container1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.StartContainer(AnonymousTag(), kTLVType_Structure, container2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.PutBoolean(ProfileTag(TestProfile_1, 2), true);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.EndContainer(container2);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.EndContainer(container1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
// Test that the reservations work for the empty containers
writer1.Init(buf1);
err = writer1.OpenContainer(ProfileTag(TestProfile_1, 2), kTLVType_Structure, innerWriter1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
err = writer1.CloseContainer(innerWriter1);
- NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
+ EXPECT_NE(err, CHIP_NO_ERROR);
writer2.Init(buf1, sizeof(buf1));
err = writer2.OpenContainer(ProfileTag(TestProfile_1, 2), kTLVType_Structure, innerWriter1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.CloseContainer(innerWriter1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
writer1.Init(buf1);
err = writer1.StartContainer(ProfileTag(TestProfile_1, 2), kTLVType_Structure, container1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
err = writer1.EndContainer(container1);
- NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
+ EXPECT_NE(err, CHIP_NO_ERROR);
writer2.Init(buf1, sizeof(buf1));
err = writer2.StartContainer(ProfileTag(TestProfile_1, 2), kTLVType_Structure, container1);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer2.EndContainer(container1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
// Test that the reservations work if the writer has a maxLen of 0.
writer1.Init(buf1, 0);
err = writer1.OpenContainer(ProfileTag(TestProfile_1, 2), kTLVType_Structure, innerWriter1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
err = writer1.StartContainer(AnonymousTag(), kTLVType_Array, container1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
// Test again all cases from 0 to the length of buf1
@@ -4201,7 +4185,7 @@
if (err == CHIP_NO_ERROR)
err = writer1.CloseContainer(innerWriter1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
// Start/EndContainer
@@ -4222,11 +4206,11 @@
if (err == CHIP_NO_ERROR)
err = writer1.EndContainer(container1);
- NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL);
+ EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL);
}
}
-static CHIP_ERROR ReadFuzzedEncoding1(nlTestSuite * inSuite, TLVReader & reader)
+static CHIP_ERROR ReadFuzzedEncoding1(TLVReader & reader)
{
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -4357,7 +4341,7 @@
static uint64_t sFuzzTestDurationMillis = 5000;
static uint8_t sFixedFuzzMask = 0;
-static void TLVReaderFuzzTest(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, TLVReaderFuzzTest)
{
uint64_t now, endTime;
uint8_t fuzzedData[sizeof(Encoding1)];
@@ -4421,8 +4405,8 @@
reader.Init(fuzzedData);
reader.ImplicitProfileId = TestProfile_2;
- CHIP_ERROR readRes = ReadFuzzedEncoding1(inSuite, reader);
- NL_TEST_ASSERT(inSuite, readRes != CHIP_NO_ERROR);
+ CHIP_ERROR readRes = ReadFuzzedEncoding1(reader);
+ EXPECT_NE(readRes, CHIP_NO_ERROR);
if (readRes == CHIP_NO_ERROR)
{
@@ -4443,23 +4427,23 @@
}
}
-static void AssertCanReadString(nlTestSuite * inSuite, ContiguousBufferTLVReader & reader, const char * expectedString)
+static void AssertCanReadString(ContiguousBufferTLVReader & reader, const char * expectedString)
{
Span<const char> str;
CHIP_ERROR err = reader.GetStringView(str);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, str.size() == strlen(expectedString));
- NL_TEST_ASSERT(inSuite, strncmp(str.data(), expectedString, str.size()) == 0);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ EXPECT_EQ(str.size(), strlen(expectedString));
+ EXPECT_EQ(strncmp(str.data(), expectedString, str.size()), 0);
}
-static void AssertCannotReadString(nlTestSuite * inSuite, ContiguousBufferTLVReader & reader)
+static void AssertCannotReadString(ContiguousBufferTLVReader & reader)
{
Span<const char> str;
CHIP_ERROR err = reader.GetStringView(str);
- NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
+ EXPECT_NE(err, CHIP_NO_ERROR);
}
-static void CheckGetStringView(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckGetStringView)
{
uint8_t buf[256];
static const char testString[] = "This is a test";
@@ -4467,25 +4451,25 @@
TLVWriter writer;
writer.Init(buf);
CHIP_ERROR err = writer.PutString(CommonTag(0), testString);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// First check that basic read from entire buffer works.
ContiguousBufferTLVReader reader;
reader.Init(buf);
reader.Next();
- AssertCanReadString(inSuite, reader, testString);
+ AssertCanReadString(reader, testString);
// Now check that read from a buffer bounded by the number of bytes
// written works.
reader.Init(buf, writer.GetLengthWritten());
reader.Next();
- AssertCanReadString(inSuite, reader, testString);
+ AssertCanReadString(reader, testString);
// Now check that read from a buffer bounded by fewer than the number of
// bytes written fails.
reader.Init(buf, writer.GetLengthWritten() - 1);
reader.Next();
- AssertCannotReadString(inSuite, reader);
+ AssertCannotReadString(reader);
}
{
@@ -4493,12 +4477,12 @@
TLVWriter writer;
writer.Init(buf);
CHIP_ERROR err = writer.Put(CommonTag(0), static_cast<uint8_t>(5));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
ContiguousBufferTLVReader reader;
reader.Init(buf);
reader.Next();
- AssertCannotReadString(inSuite, reader);
+ AssertCannotReadString(reader);
}
{
@@ -4507,12 +4491,12 @@
writer.Init(buf);
CHIP_ERROR err =
writer.PutBytes(CommonTag(0), reinterpret_cast<const uint8_t *>(testString), static_cast<uint32_t>(strlen(testString)));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
ContiguousBufferTLVReader reader;
reader.Init(buf);
reader.Next();
- AssertCannotReadString(inSuite, reader);
+ AssertCannotReadString(reader);
}
{
@@ -4521,7 +4505,7 @@
ContiguousBufferTLVReader reader;
reader.Init(shortString);
reader.Next();
- AssertCanReadString(inSuite, reader, "ab");
+ AssertCanReadString(reader, "ab");
}
{
@@ -4530,26 +4514,26 @@
ContiguousBufferTLVReader reader;
reader.Init(shortString);
reader.Next();
- AssertCannotReadString(inSuite, reader);
+ AssertCannotReadString(reader);
}
}
-static void AssertCanReadBytes(nlTestSuite * inSuite, ContiguousBufferTLVReader & reader, const ByteSpan & expectedBytes)
+static void AssertCanReadBytes(ContiguousBufferTLVReader & reader, const ByteSpan & expectedBytes)
{
ByteSpan bytes;
CHIP_ERROR err = reader.GetByteView(bytes);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, bytes.data_equal(expectedBytes));
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ EXPECT_TRUE(bytes.data_equal(expectedBytes));
}
-static void AssertCannotReadBytes(nlTestSuite * inSuite, ContiguousBufferTLVReader & reader)
+static void AssertCannotReadBytes(ContiguousBufferTLVReader & reader)
{
ByteSpan bytes;
CHIP_ERROR err = reader.GetByteView(bytes);
- NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
+ EXPECT_NE(err, CHIP_NO_ERROR);
}
-static void CheckGetByteView(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckGetByteView)
{
uint8_t buf[256];
const uint8_t testBytes[] = { 'T', 'h', 'i', 's', 'i', 's', 'a', 't', 'e', 's', 't', '\0' };
@@ -4557,25 +4541,25 @@
TLVWriter writer;
writer.Init(buf);
CHIP_ERROR err = writer.PutBytes(CommonTag(0), testBytes, sizeof(testBytes));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
// First check that basic read from entire buffer works.
ContiguousBufferTLVReader reader;
reader.Init(buf);
reader.Next();
- AssertCanReadBytes(inSuite, reader, ByteSpan(testBytes));
+ AssertCanReadBytes(reader, ByteSpan(testBytes));
// Now check that read from a buffer bounded by the number of bytes
// written works.
reader.Init(buf, writer.GetLengthWritten());
reader.Next();
- AssertCanReadBytes(inSuite, reader, ByteSpan(testBytes));
+ AssertCanReadBytes(reader, ByteSpan(testBytes));
// Now check that read from a buffer bounded by fewer than the number of
// bytes written fails.
reader.Init(buf, writer.GetLengthWritten() - 1);
reader.Next();
- AssertCannotReadBytes(inSuite, reader);
+ AssertCannotReadBytes(reader);
}
{
@@ -4583,12 +4567,12 @@
TLVWriter writer;
writer.Init(buf);
CHIP_ERROR err = writer.Put(CommonTag(0), static_cast<uint8_t>(5));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
ContiguousBufferTLVReader reader;
reader.Init(buf);
reader.Next();
- AssertCannotReadBytes(inSuite, reader);
+ AssertCannotReadBytes(reader);
}
{
@@ -4596,12 +4580,12 @@
TLVWriter writer;
writer.Init(buf);
CHIP_ERROR err = writer.PutString(CommonTag(0), reinterpret_cast<const char *>(testBytes));
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
ContiguousBufferTLVReader reader;
reader.Init(buf);
reader.Next();
- AssertCannotReadBytes(inSuite, reader);
+ AssertCannotReadBytes(reader);
}
{
@@ -4611,7 +4595,7 @@
reader.Init(shortBytes);
reader.Next();
const uint8_t expectedBytes[] = { 1, 2 };
- AssertCanReadBytes(inSuite, reader, ByteSpan(expectedBytes));
+ AssertCanReadBytes(reader, ByteSpan(expectedBytes));
}
{
@@ -4621,32 +4605,32 @@
ContiguousBufferTLVReader reader;
reader.Init(shortBytes);
reader.Next();
- AssertCannotReadBytes(inSuite, reader);
+ AssertCannotReadBytes(reader);
}
}
-static void CheckTLVScopedBuffer(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, CheckTLVScopedBuffer)
{
Platform::ScopedMemoryBuffer<uint8_t> buf;
CHIP_ERROR err;
buf.Calloc(64);
- NL_TEST_ASSERT(inSuite, buf.Get() != nullptr);
+ ASSERT_NE(buf.Get(), nullptr);
{
ScopedBufferTLVWriter writer(std::move(buf), 64);
- NL_TEST_ASSERT(inSuite, buf.Get() == nullptr); // // NOLINT(bugprone-use-after-move)
+ EXPECT_EQ(buf.Get(), nullptr); // // NOLINT(bugprone-use-after-move)
err = writer.Put(TLV::AnonymousTag(), (uint8_t) 33);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = writer.Finalize(buf);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, buf.Get() != nullptr);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ ASSERT_NE(buf.Get(), nullptr);
err = writer.Put(TLV::AnonymousTag(), (uint8_t) 33);
- NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
+ EXPECT_NE(err, CHIP_NO_ERROR);
}
{
@@ -4656,204 +4640,202 @@
reader.Init(std::move(buf), 64);
err = reader.Next();
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
err = reader.Get(val);
- NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, val == 33);
+ EXPECT_EQ(err, CHIP_NO_ERROR);
+ EXPECT_EQ(val, 33);
reader.TakeBuffer(buf);
- NL_TEST_ASSERT(inSuite, buf.Get() != nullptr);
+ ASSERT_NE(buf.Get(), nullptr);
err = reader.Get(val);
- NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
+ EXPECT_NE(err, CHIP_NO_ERROR);
}
}
-static void TestUninitializedWriter(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLV, TestUninitializedWriter)
{
{
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, !writer.IsInitialized());
+ EXPECT_FALSE(writer.IsInitialized());
}
{
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.Finalize() == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Finalize(), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.ReserveBuffer(123) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.ReserveBuffer(123), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.UnreserveBuffer(123) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.UnreserveBuffer(123), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
uint8_t v = 3;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
int8_t v = 3;
bool preserveSize = true;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v, preserveSize) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v, preserveSize), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
int16_t v = 3;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
int16_t v = 3;
bool preserveSize = true;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v, preserveSize) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v, preserveSize), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
int32_t v = 3;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
int32_t v = 3;
bool preserveSize = true;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v, preserveSize) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v, preserveSize), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
int64_t v = 3;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
int64_t v = 3;
bool preserveSize = true;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v, preserveSize) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v, preserveSize), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
uint8_t v = 3;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
uint8_t v = 3;
bool preserveSize = true;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v, preserveSize) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v, preserveSize), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
uint16_t v = 3;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
uint16_t v = 3;
bool preserveSize = true;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v, preserveSize) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v, preserveSize), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
uint32_t v = 3;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
uint32_t v = 3;
bool preserveSize = true;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v, preserveSize) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v, preserveSize), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
uint64_t v = 3;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
uint64_t v = 3;
bool preserveSize = true;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v, preserveSize) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v, preserveSize), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
double v = 1.23;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
float v = 1.23f;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
bool v = true;
- NL_TEST_ASSERT(inSuite, writer.PutBoolean(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.PutBoolean(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
bool v = true;
- NL_TEST_ASSERT(inSuite, writer.Put(ContextTag(1), v) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.Put(ContextTag(1), v), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
const uint8_t buf[] = { 1, 2, 3 };
- NL_TEST_ASSERT(inSuite,
- writer.PutBytes(ContextTag(1), buf, static_cast<uint32_t>(sizeof(buf))) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.PutBytes(ContextTag(1), buf, static_cast<uint32_t>(sizeof(buf))), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
const char * buf = "abc";
- NL_TEST_ASSERT(inSuite, writer.PutString(ContextTag(1), buf) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.PutString(ContextTag(1), buf), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
const char * buf = "abc";
- NL_TEST_ASSERT(inSuite,
- writer.PutString(ContextTag(1), buf, static_cast<uint32_t>(strlen(buf))) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.PutString(ContextTag(1), buf, static_cast<uint32_t>(strlen(buf))), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
CharSpan str = "abc"_span;
- NL_TEST_ASSERT(inSuite, writer.PutString(ContextTag(1), str) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.PutString(ContextTag(1), str), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.PutStringF(ContextTag(1), "%d", 1) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.PutStringF(ContextTag(1), "%d", 1), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.PutNull(ContextTag(1)) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.PutNull(ContextTag(1)), CHIP_ERROR_INCORRECT_STATE);
}
{
@@ -4862,7 +4844,7 @@
reader.Init(buf);
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.CopyElement(reader) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.CopyElement(reader), CHIP_ERROR_INCORRECT_STATE);
}
{
@@ -4871,51 +4853,49 @@
reader.Init(buf);
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.CopyElement(ContextTag(1), reader) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.CopyElement(ContextTag(1), reader), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
TLVType outerContainerType;
- NL_TEST_ASSERT(inSuite,
- writer.StartContainer(ContextTag(1), TLVType::kTLVType_Structure, outerContainerType) ==
- CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.StartContainer(ContextTag(1), TLVType::kTLVType_Structure, outerContainerType),
+ CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter writer;
TLVType outerContainerType = TLVType::kTLVType_Structure;
- NL_TEST_ASSERT(inSuite, writer.EndContainer(outerContainerType) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.EndContainer(outerContainerType), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter innerWriter;
uint8_t buf[]{ 0, 0, 0 };
innerWriter.Init(buf);
- NL_TEST_ASSERT(inSuite, innerWriter.IsInitialized());
+ EXPECT_TRUE(innerWriter.IsInitialized());
TLVWriter writer;
- NL_TEST_ASSERT(inSuite,
- writer.OpenContainer(ContextTag(1), TLVType::kTLVType_Structure, innerWriter) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.OpenContainer(ContextTag(1), TLVType::kTLVType_Structure, innerWriter), CHIP_ERROR_INCORRECT_STATE);
}
{
TLVWriter innerWriter;
uint8_t buf[]{ 0, 0, 0 };
innerWriter.Init(buf);
- NL_TEST_ASSERT(inSuite, innerWriter.IsInitialized());
+ EXPECT_TRUE(innerWriter.IsInitialized());
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.CloseContainer(innerWriter) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.CloseContainer(innerWriter), CHIP_ERROR_INCORRECT_STATE);
}
{
uint8_t buf[]{ 0, 0, 0 };
TLVWriter writer;
- NL_TEST_ASSERT(inSuite,
- writer.PutPreEncodedContainer(ContextTag(1), TLVType::kTLVType_Structure, buf,
- static_cast<uint32_t>(sizeof(buf))) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(
+ writer.PutPreEncodedContainer(ContextTag(1), TLVType::kTLVType_Structure, buf, static_cast<uint32_t>(sizeof(buf))),
+ CHIP_ERROR_INCORRECT_STATE);
}
{
@@ -4924,7 +4904,7 @@
reader.Init(buf);
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.CopyContainer(reader) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.CopyContainer(reader), CHIP_ERROR_INCORRECT_STATE);
}
{
@@ -4933,95 +4913,13 @@
reader.Init(buf);
TLVWriter writer;
- NL_TEST_ASSERT(inSuite, writer.CopyContainer(ContextTag(1), reader) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.CopyContainer(ContextTag(1), reader), CHIP_ERROR_INCORRECT_STATE);
}
{
uint8_t buf[]{ 0, 0, 0 };
TLVWriter writer;
- NL_TEST_ASSERT(inSuite,
- writer.CopyContainer(ContextTag(1), buf, static_cast<uint16_t>(sizeof(buf))) == CHIP_ERROR_INCORRECT_STATE);
+ EXPECT_EQ(writer.CopyContainer(ContextTag(1), buf, static_cast<uint16_t>(sizeof(buf))), CHIP_ERROR_INCORRECT_STATE);
}
}
-
-// Test Suite
-
-/**
- * Test Suite that lists all the test functions.
- */
-// clang-format off
-static const nlTest sTests[] =
-{
- NL_TEST_DEF("Simple Write Read Test", CheckSimpleWriteRead),
- NL_TEST_DEF("Inet Buffer Test", CheckPacketBuffer),
- NL_TEST_DEF("Buffer Overflow Test", CheckBufferOverflow),
- NL_TEST_DEF("Pretty Print Test", CheckPrettyPrinter),
- NL_TEST_DEF("Pretty Octet String Print Test", CheckOctetStringPrettyPrinter),
- NL_TEST_DEF("Data Macro Test", CheckDataMacro),
- NL_TEST_DEF("Strict Aliasing Test", CheckStrictAliasing),
- NL_TEST_DEF("CHIP TLV Basics", CheckTLVBasics),
- NL_TEST_DEF("CHIP TLV Writer", CheckTLVWriter),
- NL_TEST_DEF("CHIP TLV Reader", CheckTLVReader),
- NL_TEST_DEF("CHIP TLV Utilities", CheckTLVUtilities),
- NL_TEST_DEF("CHIP TLV Updater", CheckCHIPUpdater),
- NL_TEST_DEF("CHIP TLV Empty Find", CheckTLVEmptyFind),
- NL_TEST_DEF("CHIP Circular TLV buffer, simple", CheckCircularTLVBufferSimple),
- NL_TEST_DEF("CHIP Circular TLV buffer, mid-buffer start", CheckCircularTLVBufferStartMidway),
- NL_TEST_DEF("CHIP Circular TLV buffer, straddle", CheckCircularTLVBufferEvictStraddlingEvent),
- NL_TEST_DEF("CHIP Circular TLV buffer, edge", CheckCircularTLVBufferEdge),
- NL_TEST_DEF("CHIP TLV Printf", CheckTLVPutStringF),
- NL_TEST_DEF("CHIP TLV String Span", CheckTLVPutStringSpan),
- NL_TEST_DEF("CHIP TLV Printf, Circular TLV buf", CheckTLVPutStringFCircular),
- NL_TEST_DEF("CHIP TLV Skip non-contiguous", CheckTLVSkipCircular),
- NL_TEST_DEF("CHIP TLV ByteSpan", CheckTLVByteSpan),
- NL_TEST_DEF("CHIP TLV CharSpan", CheckTLVCharSpan),
- NL_TEST_DEF("CHIP TLV Get LocalizedStringIdentifier", CheckTLVGetLocalizedStringIdentifier),
- NL_TEST_DEF("CHIP TLV Scoped Buffer", CheckTLVScopedBuffer),
- NL_TEST_DEF("CHIP TLV Check reserve", CheckCloseContainerReserve),
- NL_TEST_DEF("CHIP TLV Reader Fuzz Test", TLVReaderFuzzTest),
- NL_TEST_DEF("CHIP TLV GetStringView Test", CheckGetStringView),
- NL_TEST_DEF("CHIP TLV GetByteView Test", CheckGetByteView),
- NL_TEST_DEF("Int Min/Max Test", TestIntMinMax),
- NL_TEST_DEF("Uninitialized Writer Test", TestUninitializedWriter),
-
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-/**
- * Set up the test suite.
- */
-int TestTLV_Setup(void * inContext)
-{
- CHIP_ERROR error = chip::Platform::MemoryInit();
- if (error != CHIP_NO_ERROR)
- return FAILURE;
- return SUCCESS;
-}
-
-/**
- * Tear down the test suite.
- */
-int TestTLV_Teardown(void * inContext)
-{
- chip::Platform::MemoryShutdown();
- return SUCCESS;
-}
-
-int TestTLV()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "chip-tlv",
- &sTests[0],
- TestTLV_Setup,
- TestTLV_Teardown
- };
- // clang-format on
-
- return chip::ExecuteTestsWithContext<TestTLVContext>(&theSuite, &theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestTLV)
diff --git a/src/lib/core/tests/TestTLVVectorWriter.cpp b/src/lib/core/tests/TestTLVVectorWriter.cpp
index c68211b..d2b604f 100644
--- a/src/lib/core/tests/TestTLVVectorWriter.cpp
+++ b/src/lib/core/tests/TestTLVVectorWriter.cpp
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+#include <gtest/gtest.h>
+
#include <lib/core/TLVVectorWriter.h>
#include <cstddef>
@@ -28,9 +30,6 @@
#include <lib/core/TLVCommon.h>
#include <lib/core/TLVTags.h>
#include <lib/support/Span.h>
-#include <lib/support/UnitTestContext.h>
-#include <lib/support/UnitTestExtendedAssertions.h>
-#include <lib/support/UnitTestRegistration.h>
#include <lib/support/UnitTestUtils.h>
using namespace chip;
@@ -42,42 +41,46 @@
struct TestTLVContext
{
- nlTestSuite * mSuite = nullptr;
int mEvictionCount = 0;
uint32_t mEvictedBytes = 0;
-
- TestTLVContext(nlTestSuite * suite) : mSuite(suite) {}
};
-void InitAndFinalizeWithNoData(nlTestSuite * inSuite, void * inContext)
+class TestTLVVectorWriter : public ::testing::Test
+{
+public:
+ static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
+ static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
+};
+
+TEST_F(TestTLVVectorWriter, InitAndFinalizeWithNoData)
{
std::vector<uint8_t> buffer;
TlvVectorWriter writer(buffer);
// Init and finalize but write not data.
- NL_TEST_ASSERT(inSuite, writer.Finalize() == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, buffer.empty());
+ EXPECT_EQ(writer.Finalize(), CHIP_NO_ERROR);
+ EXPECT_TRUE(buffer.empty());
}
-void SingleSmallDataFitsInOriginalBuffer(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLVVectorWriter, SingleSmallDataFitsInOriginalBuffer)
{
std::vector<uint8_t> buffer;
TlvVectorWriter writer(buffer);
TLVReader reader;
- NL_TEST_ASSERT(inSuite, writer.Put(AnonymousTag(), true) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, writer.Finalize() == CHIP_NO_ERROR);
+ EXPECT_EQ(writer.Put(AnonymousTag(), true), CHIP_NO_ERROR);
+ EXPECT_EQ(writer.Finalize(), CHIP_NO_ERROR);
reader.Init(buffer.data(), buffer.size());
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == AnonymousTag());
+ EXPECT_EQ(reader.Next(), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetTag(), AnonymousTag());
bool value = false;
- NL_TEST_ASSERT(inSuite, reader.Get(value) == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, value == true);
+ EXPECT_EQ(reader.Get(value), CHIP_NO_ERROR);
+ EXPECT_EQ(value, true);
}
-void SingleLargeDataRequiresNewBufferAllocation(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLVVectorWriter, SingleLargeDataRequiresNewBufferAllocation)
{
std::vector<uint8_t> buffer;
TlvVectorWriter writer(buffer);
@@ -86,20 +89,20 @@
const std::string bytes(kStringSize, 'a');
CHIP_ERROR error = writer.PutString(AnonymousTag(), bytes.data());
- NL_TEST_ASSERT(inSuite, error == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, writer.Finalize() == CHIP_NO_ERROR);
+ EXPECT_EQ(error, CHIP_NO_ERROR);
+ EXPECT_EQ(writer.Finalize(), CHIP_NO_ERROR);
reader.Init(buffer.data(), buffer.size());
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == AnonymousTag());
+ EXPECT_EQ(reader.Next(), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetTag(), AnonymousTag());
CharSpan span;
error = reader.Get(span);
- NL_TEST_ASSERT(inSuite, error == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, std::string(span.data(), span.size()) == bytes);
+ EXPECT_EQ(error, CHIP_NO_ERROR);
+ EXPECT_EQ(std::string(span.data(), span.size()), bytes);
}
-void ManySmallDataRequiresNewBufferAllocation(nlTestSuite * inSuite, void * inContext)
+TEST_F(TestTLVVectorWriter, ManySmallDataRequiresNewBufferAllocation)
{
std::vector<uint8_t> buffer;
TlvVectorWriter writer(buffer);
@@ -107,74 +110,21 @@
for (int i = 0; i < 10000; i++)
{
- NL_TEST_ASSERT(inSuite, writer.Put(AnonymousTag(), true) == CHIP_NO_ERROR);
+ EXPECT_EQ(writer.Put(AnonymousTag(), true), CHIP_NO_ERROR);
}
- NL_TEST_ASSERT(inSuite, writer.Finalize() == CHIP_NO_ERROR);
+ EXPECT_EQ(writer.Finalize(), CHIP_NO_ERROR);
reader.Init(buffer.data(), buffer.size());
for (int i = 0; i < 10000; i++)
{
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, reader.GetTag() == AnonymousTag());
+ EXPECT_EQ(reader.Next(), CHIP_NO_ERROR);
+ EXPECT_EQ(reader.GetTag(), AnonymousTag());
bool value = false;
CHIP_ERROR error = reader.Get(value);
- NL_TEST_ASSERT(inSuite, error == CHIP_NO_ERROR);
- NL_TEST_ASSERT(inSuite, value == true);
+ EXPECT_EQ(error, CHIP_NO_ERROR);
+ EXPECT_EQ(value, true);
}
- NL_TEST_ASSERT(inSuite, reader.Next() == CHIP_END_OF_TLV);
+ EXPECT_EQ(reader.Next(), CHIP_END_OF_TLV);
}
-
-// Test Suite
-
-/**
- * Test Suite that lists all the test functions.
- */
-// clang-format off
-static const nlTest sTests[] =
-{
- NL_TEST_DEF("Verify behavior on init and finalize without data manipulation", InitAndFinalizeWithNoData),
- NL_TEST_DEF("Ensure correct write/read operations within Inet buffer constraints", SingleSmallDataFitsInOriginalBuffer),
- NL_TEST_DEF("Handle cases where a single large data input exceeds buffer capacity", SingleLargeDataRequiresNewBufferAllocation),
- NL_TEST_DEF("Validate output formatting for multiple small data inputs requiring additional buffer space", ManySmallDataRequiresNewBufferAllocation),
- NL_TEST_SENTINEL()
-};
-// clang-format on
-
-/**
- * Set up the test suite.
- */
-int TestTLVVectorWriter_Setup(void * inContext)
-{
- CHIP_ERROR error = chip::Platform::MemoryInit();
- if (error != CHIP_NO_ERROR)
- return FAILURE;
- return SUCCESS;
-}
-
-/**
- * Tear down the test suite.
- */
-int TestTLVVectorWriter_Teardown(void * inContext)
-{
- chip::Platform::MemoryShutdown();
- return SUCCESS;
-}
-
-int TestTLVVectorWriter()
-{
- // clang-format off
- nlTestSuite theSuite =
- {
- "chip-tlv",
- &sTests[0],
- TestTLVVectorWriter_Setup,
- TestTLVVectorWriter_Teardown
- };
- // clang-format on
-
- return chip::ExecuteTestsWithContext<TestTLVContext>(&theSuite, &theSuite);
-}
-
-CHIP_REGISTER_TEST_SUITE(TestTLVVectorWriter)
diff --git a/src/test_driver/openiotsdk/unit-tests/test_components.txt b/src/test_driver/openiotsdk/unit-tests/test_components.txt
index 2da3c15..9cf879e 100644
--- a/src/test_driver/openiotsdk/unit-tests/test_components.txt
+++ b/src/test_driver/openiotsdk/unit-tests/test_components.txt
@@ -3,5 +3,6 @@
ASN1Tests
MinimalMdnsRecordsTests
MinimalMdnsRespondersTests
+CoreTests
PlatformTests
TestShell
diff --git a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt
index 848fd2f..7f86f26 100644
--- a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt
+++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt
@@ -1,7 +1,6 @@
AppTests
BDXTests
ChipCryptoTests
-CoreTests
CredentialsTest
DataModelTests
InetLayerTests