From 2c6e339d598647334192672d61e581b91c8ece60 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 8 Dec 2023 19:54:32 +0000 Subject: [PATCH] Restyled by clang-format --- src/lib/core/TLVWriter.h | 9 +- src/lib/core/tests/TestTLV.cpp | 537 +++++++++++++++++---------------- 2 files changed, 279 insertions(+), 267 deletions(-) diff --git a/src/lib/core/TLVWriter.h b/src/lib/core/TLVWriter.h index e6bba3ea821fff..eb38d5a28d9932 100644 --- a/src/lib/core/TLVWriter.h +++ b/src/lib/core/TLVWriter.h @@ -972,7 +972,8 @@ class DLL_EXPORT TLVWriter * * @retval #CHIP_NO_ERROR If the method succeeded. * @retval #CHIP_ERROR_INCORRECT_STATE - * If the supplied container writer is not in the correct state or if the TLVWriter is not initialized. + * If the supplied container writer is not in the correct state or if the TLVWriter is not + * initialized. * @retval #CHIP_ERROR_TLV_CONTAINER_OPEN * If another container writer has been opened on the supplied * container writer and not yet closed. @@ -1051,7 +1052,8 @@ class DLL_EXPORT TLVWriter * @retval #CHIP_ERROR_INVALID_ARGUMENT * If the supplied reader uses a TLVBackingStore rather than a simple buffer. * @retval #CHIP_ERROR_INCORRECT_STATE - * If the supplied reader is not positioned on a container element or if the TLVWriter was not initialized. + * If the supplied reader is not positioned on a container element or if the TLVWriter was not + * initialized. * @retval #CHIP_ERROR_TLV_CONTAINER_OPEN * If a container writer has been opened on the current writer and not * yet closed. @@ -1103,7 +1105,8 @@ class DLL_EXPORT TLVWriter * @retval #CHIP_ERROR_INVALID_ARGUMENT * If the supplied reader uses a TLVBackingStore rather than a simple buffer. * @retval #CHIP_ERROR_INCORRECT_STATE - * If the supplied reader is not positioned on a container element or of the TLVWriter was not initialized. + * If the supplied reader is not positioned on a container element or of the TLVWriter was not + * initialized. * @retval #CHIP_ERROR_TLV_CONTAINER_OPEN * If a container writer has been opened on the current writer and not * yet closed. diff --git a/src/lib/core/tests/TestTLV.cpp b/src/lib/core/tests/TestTLV.cpp index 5431bc20a12ad7..fce0a5d17ae484 100644 --- a/src/lib/core/tests/TestTLV.cpp +++ b/src/lib/core/tests/TestTLV.cpp @@ -4647,270 +4647,279 @@ static void CheckTLVScopedBuffer(nlTestSuite * inSuite, void * inContext) } } -static void TestUninitializedWriter(nlTestSuite * inSuite, void * inContext) { - { - TLVWriter writer; - NL_TEST_ASSERT(inSuite, !writer.IsInitialized()); - } - - { - TLVWriter writer; - NL_TEST_ASSERT(inSuite, writer.Finalize() == CHIP_ERROR_INCORRECT_STATE); - } - - { - TLVWriter writer; - NL_TEST_ASSERT(inSuite, writer.ReserveBuffer(123) == CHIP_ERROR_INCORRECT_STATE); - } - - { - TLVWriter writer; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - int8_t v = 3; - bool preserveSize = true; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - int16_t v = 3; - bool preserveSize = true; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - int32_t v = 3; - bool preserveSize = true; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - int64_t v = 3; - bool preserveSize = true; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - uint8_t v = 3; - bool preserveSize = true; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - uint16_t v = 3; - bool preserveSize = true; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - uint32_t v = 3; - bool preserveSize = true; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - uint64_t v = 3; - bool preserveSize = true; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - float v = 1.23f; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - bool v = true; - NL_TEST_ASSERT(inSuite, 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(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); - } - - { - TLVWriter writer; - const char* buf = "abc"; - NL_TEST_ASSERT(inSuite, writer.PutString(ContextTag(1), buf, static_cast(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); - } - - { - TLVWriter writer; - NL_TEST_ASSERT(inSuite, writer.PutStringF(ContextTag(1), "%d", 1) == CHIP_ERROR_INCORRECT_STATE); - } - - { - TLVWriter writer; - NL_TEST_ASSERT(inSuite, writer.PutNull(ContextTag(1)) == CHIP_ERROR_INCORRECT_STATE); - } - - { - const uint8_t buf[] {0, 0, 0}; - TLVReader reader; - reader.Init(buf); - - TLVWriter writer; - NL_TEST_ASSERT(inSuite, writer.CopyElement(reader) == CHIP_ERROR_INCORRECT_STATE); - } - - { - const uint8_t buf[] {0, 0, 0}; - TLVReader reader; - reader.Init(buf); - - TLVWriter writer; - NL_TEST_ASSERT(inSuite, 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); - } - - { - TLVWriter writer; - TLVType outerContainerType = TLVType::kTLVType_Structure; - NL_TEST_ASSERT(inSuite, writer.EndContainer(outerContainerType) == CHIP_ERROR_INCORRECT_STATE); - } - - { - TLVWriter innerWriter; - uint8_t buf[] {0, 0, 0}; - innerWriter.Init(buf); - NL_TEST_ASSERT(inSuite, innerWriter.IsInitialized()); - - TLVWriter writer; - NL_TEST_ASSERT(inSuite, 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()); - - TLVWriter writer; - NL_TEST_ASSERT(inSuite, 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(sizeof(buf))) == CHIP_ERROR_INCORRECT_STATE); - } - - { - const uint8_t buf[] {0, 0, 0}; - TLVReader reader; - reader.Init(buf); - - TLVWriter writer; - NL_TEST_ASSERT(inSuite, writer.CopyContainer(reader) == CHIP_ERROR_INCORRECT_STATE); - } - - { - const uint8_t buf[] {0, 0, 0}; - TLVReader reader; - reader.Init(buf); - - TLVWriter writer; - NL_TEST_ASSERT(inSuite, 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(sizeof(buf))) == CHIP_ERROR_INCORRECT_STATE); - } +static void TestUninitializedWriter(nlTestSuite * inSuite, void * inContext) +{ + { + TLVWriter writer; + NL_TEST_ASSERT(inSuite, !writer.IsInitialized()); + } + + { + TLVWriter writer; + NL_TEST_ASSERT(inSuite, writer.Finalize() == CHIP_ERROR_INCORRECT_STATE); + } + + { + TLVWriter writer; + NL_TEST_ASSERT(inSuite, writer.ReserveBuffer(123) == CHIP_ERROR_INCORRECT_STATE); + } + + { + TLVWriter writer; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + int8_t v = 3; + bool preserveSize = true; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + int16_t v = 3; + bool preserveSize = true; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + int32_t v = 3; + bool preserveSize = true; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + int64_t v = 3; + bool preserveSize = true; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + uint8_t v = 3; + bool preserveSize = true; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + uint16_t v = 3; + bool preserveSize = true; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + uint32_t v = 3; + bool preserveSize = true; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + uint64_t v = 3; + bool preserveSize = true; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + float v = 1.23f; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + bool v = true; + NL_TEST_ASSERT(inSuite, 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(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); + } + + { + TLVWriter writer; + const char * buf = "abc"; + NL_TEST_ASSERT(inSuite, + writer.PutString(ContextTag(1), buf, static_cast(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); + } + + { + TLVWriter writer; + NL_TEST_ASSERT(inSuite, writer.PutStringF(ContextTag(1), "%d", 1) == CHIP_ERROR_INCORRECT_STATE); + } + + { + TLVWriter writer; + NL_TEST_ASSERT(inSuite, writer.PutNull(ContextTag(1)) == CHIP_ERROR_INCORRECT_STATE); + } + + { + const uint8_t buf[]{ 0, 0, 0 }; + TLVReader reader; + reader.Init(buf); + + TLVWriter writer; + NL_TEST_ASSERT(inSuite, writer.CopyElement(reader) == CHIP_ERROR_INCORRECT_STATE); + } + + { + const uint8_t buf[]{ 0, 0, 0 }; + TLVReader reader; + reader.Init(buf); + + TLVWriter writer; + NL_TEST_ASSERT(inSuite, 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); + } + + { + TLVWriter writer; + TLVType outerContainerType = TLVType::kTLVType_Structure; + NL_TEST_ASSERT(inSuite, writer.EndContainer(outerContainerType) == CHIP_ERROR_INCORRECT_STATE); + } + + { + TLVWriter innerWriter; + uint8_t buf[]{ 0, 0, 0 }; + innerWriter.Init(buf); + NL_TEST_ASSERT(inSuite, innerWriter.IsInitialized()); + + TLVWriter writer; + NL_TEST_ASSERT(inSuite, + 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()); + + TLVWriter writer; + NL_TEST_ASSERT(inSuite, 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(sizeof(buf))) == CHIP_ERROR_INCORRECT_STATE); + } + + { + const uint8_t buf[]{ 0, 0, 0 }; + TLVReader reader; + reader.Init(buf); + + TLVWriter writer; + NL_TEST_ASSERT(inSuite, writer.CopyContainer(reader) == CHIP_ERROR_INCORRECT_STATE); + } + + { + const uint8_t buf[]{ 0, 0, 0 }; + TLVReader reader; + reader.Init(buf); + + TLVWriter writer; + NL_TEST_ASSERT(inSuite, 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(sizeof(buf))) == CHIP_ERROR_INCORRECT_STATE); + } } // Test Suite