|
23 | 23 | *
|
24 | 24 | */
|
25 | 25 |
|
26 |
| -#include <nlbyteorder.h> |
27 | 26 | #include <gtest/gtest.h>
|
| 27 | +#include <nlbyteorder.h> |
28 | 28 |
|
29 | 29 | #include <lib/core/CHIPCore.h>
|
30 | 30 | #include <lib/core/TLV.h>
|
@@ -143,26 +143,25 @@ void TestEndAndExitContainer(T & t, TLVType outerContainerType)
|
143 | 143 | EXPECT_EQ(t.GetContainerType(), outerContainerType);
|
144 | 144 | }
|
145 | 145 |
|
146 |
| -#define TEST_GET(s, type, tag, expectedVal, expectedErr) \ |
| 146 | +#define TEST_GET(s, type, tag, expectedVal, expectedErr) \ |
147 | 147 | do \
|
148 | 148 | { \
|
149 |
| - EXPECT_EQ(s.GetType(), type); \ |
150 |
| - EXPECT_EQ(s.GetTag(), tag); \ |
151 |
| - EXPECT_EQ(s.GetLength(), 0u); \ |
| 149 | + EXPECT_EQ(s.GetType(), type); \ |
| 150 | + EXPECT_EQ(s.GetTag(), tag); \ |
| 151 | + EXPECT_EQ(s.GetLength(), 0u); \ |
152 | 152 | \
|
153 | 153 | decltype(expectedVal) __val; \
|
154 | 154 | CHIP_ERROR __err = s.Get(__val); \
|
155 |
| - EXPECT_EQ(__err, expectedErr); \ |
| 155 | + EXPECT_EQ(__err, expectedErr); \ |
156 | 156 | if (__err == CHIP_NO_ERROR) \
|
157 | 157 | { \
|
158 |
| - EXPECT_EQ(__val, expectedVal); \ |
| 158 | + EXPECT_EQ(__val, expectedVal); \ |
159 | 159 | } \
|
160 | 160 | } while (false)
|
161 | 161 |
|
162 | 162 | #define TEST_GET_NOERROR(s, type, tag, expectedVal) TEST_GET(s, type, tag, expectedVal, CHIP_NO_ERROR)
|
163 | 163 |
|
164 |
| -void ForEachElement(TLVReader & reader, void * context, |
165 |
| - void (*cb)(TLVReader & reader, void * context)) |
| 164 | +void ForEachElement(TLVReader & reader, void * context, void (*cb)(TLVReader & reader, void * context)) |
166 | 165 | {
|
167 | 166 | CHIP_ERROR err;
|
168 | 167 |
|
@@ -276,8 +275,7 @@ void TestDupBytes(TLVReader & reader, Tag tag, const uint8_t * expectedVal, uint
|
276 | 275 | chip::Platform::MemoryFree(val);
|
277 | 276 | }
|
278 | 277 |
|
279 |
| -void TestBufferContents(const System::PacketBufferHandle & buffer, const uint8_t * expectedVal, |
280 |
| - uint32_t expectedLen) |
| 278 | +void TestBufferContents(const System::PacketBufferHandle & buffer, const uint8_t * expectedVal, uint32_t expectedLen) |
281 | 279 | {
|
282 | 280 | System::PacketBufferHandle buf = buffer.Retain();
|
283 | 281 | while (!buf.IsNull())
|
@@ -727,21 +725,17 @@ void ReadEncoding1(TLVReader & reader)
|
727 | 725 | TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(42));
|
728 | 726 | TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(42));
|
729 | 727 | TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint8_t>(42), CHIP_ERROR_WRONG_TLV_TYPE);
|
730 |
| - TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(42), |
731 |
| - CHIP_ERROR_WRONG_TLV_TYPE); |
732 |
| - TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(42), |
733 |
| - CHIP_ERROR_WRONG_TLV_TYPE); |
734 |
| - TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(42), |
735 |
| - CHIP_ERROR_WRONG_TLV_TYPE); |
| 728 | + TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint16_t>(42), CHIP_ERROR_WRONG_TLV_TYPE); |
| 729 | + TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(42), CHIP_ERROR_WRONG_TLV_TYPE); |
| 730 | + TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(42), CHIP_ERROR_WRONG_TLV_TYPE); |
736 | 731 |
|
737 | 732 | TestNext<TLVReader>(reader3);
|
738 | 733 |
|
739 | 734 | TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int8_t>(-17));
|
740 | 735 | TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(-17));
|
741 | 736 | TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(-17));
|
742 | 737 | TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(-17));
|
743 |
| - TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(-17), |
744 |
| - CHIP_ERROR_WRONG_TLV_TYPE); |
| 738 | + TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(-17), CHIP_ERROR_WRONG_TLV_TYPE); |
745 | 739 |
|
746 | 740 | TestNext<TLVReader>(reader3);
|
747 | 741 |
|
@@ -811,8 +805,7 @@ void ReadEncoding1(TLVReader & reader)
|
811 | 805 | TestNext<TLVReader>(reader2);
|
812 | 806 |
|
813 | 807 | TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), 17.9f);
|
814 |
| - TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), |
815 |
| - static_cast<double>(17.9f)); |
| 808 | + TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), static_cast<double>(17.9f)); |
816 | 809 |
|
817 | 810 | TestNext<TLVReader>(reader2);
|
818 | 811 |
|
@@ -1131,8 +1124,7 @@ void AppendEncoding2(uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t
|
1131 | 1124 | * <TestProfile_1, 1, kTLVType_Structure, <TestProfile_1, 2, true> <TestProfile_2, 2, false> >,
|
1132 | 1125 | * <TestProfile_2, 1, kTLVType_Structure, <TestProfile_2, 2, false> <TestProfile_1, 2, true> >
|
1133 | 1126 | */
|
1134 |
| -void FindAppendEncoding2(uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen, |
1135 |
| - bool findContainer) |
| 1127 | +void FindAppendEncoding2(uint8_t * buf, uint32_t dataLen, uint32_t maxLen, uint32_t & updatedLen, bool findContainer) |
1136 | 1128 | {
|
1137 | 1129 | CHIP_ERROR err;
|
1138 | 1130 |
|
@@ -2443,7 +2435,8 @@ TEST_F(TestTLV, CheckCircularTLVBufferEvictStraddlingEvent)
|
2443 | 2435 |
|
2444 | 2436 | WriteEncoding3(writer);
|
2445 | 2437 |
|
2446 |
| - EXPECT_EQ(writer.GetLengthWritten(), (8u * 11 + 7)); // 8 writes of Encoding3 (11 bytes each) and 7 bytes for the initial boolean. |
| 2438 | + EXPECT_EQ(writer.GetLengthWritten(), |
| 2439 | + (8u * 11 + 7)); // 8 writes of Encoding3 (11 bytes each) and 7 bytes for the initial boolean. |
2447 | 2440 | EXPECT_EQ(buffer.DataLength(), 22u);
|
2448 | 2441 | EXPECT_EQ((buffer.DataLength() + context->mEvictedBytes), writer.GetLengthWritten());
|
2449 | 2442 | EXPECT_EQ(context->mEvictionCount, 7);
|
@@ -3471,10 +3464,8 @@ void TestTLVReaderDup()
|
3471 | 3464 | TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int16_t>(42));
|
3472 | 3465 | TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int32_t>(42));
|
3473 | 3466 | TEST_GET_NOERROR(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<int64_t>(42));
|
3474 |
| - TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(42), |
3475 |
| - CHIP_ERROR_WRONG_TLV_TYPE); |
3476 |
| - TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(42), |
3477 |
| - CHIP_ERROR_WRONG_TLV_TYPE); |
| 3467 | + TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint32_t>(42), CHIP_ERROR_WRONG_TLV_TYPE); |
| 3468 | + TEST_GET(reader3, kTLVType_SignedInteger, AnonymousTag(), static_cast<uint64_t>(42), CHIP_ERROR_WRONG_TLV_TYPE); |
3478 | 3469 |
|
3479 | 3470 | TestNext<TLVReader>(reader3);
|
3480 | 3471 |
|
@@ -3551,8 +3542,7 @@ void TestTLVReaderDup()
|
3551 | 3542 | TestNext<TLVReader>(reader2);
|
3552 | 3543 |
|
3553 | 3544 | TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), 17.9f);
|
3554 |
| - TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), |
3555 |
| - static_cast<double>(17.9f)); |
| 3545 | + TEST_GET_NOERROR(reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), static_cast<double>(17.9f)); |
3556 | 3546 |
|
3557 | 3547 | TestNext<TLVReader>(reader2);
|
3558 | 3548 |
|
@@ -3739,13 +3729,11 @@ void TestTLVReaderInPractice()
|
3739 | 3729 |
|
3740 | 3730 | TestNext<TLVReader>(reader);
|
3741 | 3731 |
|
3742 |
| - TEST_GET_NOERROR(reader, kTLVType_SignedInteger, ProfileTag(TestProfile_1, 4000000000ULL), |
3743 |
| - static_cast<int64_t>(12345)); |
| 3732 | + TEST_GET_NOERROR(reader, kTLVType_SignedInteger, ProfileTag(TestProfile_1, 4000000000ULL), static_cast<int64_t>(12345)); |
3744 | 3733 |
|
3745 | 3734 | TestNext<TLVReader>(reader);
|
3746 | 3735 |
|
3747 |
| - TEST_GET_NOERROR(reader, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_1, 4000000000ULL), |
3748 |
| - static_cast<float>(1.0)); |
| 3736 | + TEST_GET_NOERROR(reader, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_1, 4000000000ULL), static_cast<float>(1.0)); |
3749 | 3737 | }
|
3750 | 3738 |
|
3751 | 3739 | void TestTLVReader_NextOverContainer_ProcessElement(TLVReader & reader, void * context)
|
@@ -4879,7 +4867,8 @@ TEST_F(TestTLV, TestUninitializedWriter)
|
4879 | 4867 | TLVWriter writer;
|
4880 | 4868 | TLVType outerContainerType;
|
4881 | 4869 |
|
4882 |
| - EXPECT_EQ(writer.StartContainer(ContextTag(1), TLVType::kTLVType_Structure, outerContainerType), CHIP_ERROR_INCORRECT_STATE); |
| 4870 | + EXPECT_EQ(writer.StartContainer(ContextTag(1), TLVType::kTLVType_Structure, outerContainerType), |
| 4871 | + CHIP_ERROR_INCORRECT_STATE); |
4883 | 4872 | }
|
4884 | 4873 |
|
4885 | 4874 | {
|
@@ -4911,8 +4900,9 @@ TEST_F(TestTLV, TestUninitializedWriter)
|
4911 | 4900 | {
|
4912 | 4901 | uint8_t buf[]{ 0, 0, 0 };
|
4913 | 4902 | TLVWriter writer;
|
4914 |
| - EXPECT_EQ(writer.PutPreEncodedContainer(ContextTag(1), TLVType::kTLVType_Structure, buf, |
4915 |
| - static_cast<uint32_t>(sizeof(buf))), CHIP_ERROR_INCORRECT_STATE); |
| 4903 | + EXPECT_EQ( |
| 4904 | + writer.PutPreEncodedContainer(ContextTag(1), TLVType::kTLVType_Structure, buf, static_cast<uint32_t>(sizeof(buf))), |
| 4905 | + CHIP_ERROR_INCORRECT_STATE); |
4916 | 4906 | }
|
4917 | 4907 |
|
4918 | 4908 | {
|
|
0 commit comments