Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and tennessee-google committed Jul 5, 2023
1 parent 1d4ebec commit 4d1f6b0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/lib/support/BufferReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#include <lib/core/CHIPEncoding.h>

#include <type_traits>
#include <string.h>
#include <type_traits>

namespace chip {
namespace Encoding {
Expand All @@ -33,10 +33,10 @@ namespace {
// thing being read.
void ReadHelper(const uint8_t * p, bool * dest)
{
*dest = (*p != 0);
*dest = (*p != 0);
}

template<typename T>
template <typename T>
void ReadHelper(const uint8_t * p, T * dest)
{
std::make_unsigned_t<T> result;
Expand Down
4 changes: 1 addition & 3 deletions src/lib/support/BufferReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ class Reader
/**
* @return false if the reader is in error, true if the reader is OK.
*/
bool IsSuccess() const {
return StatusCode() == CHIP_NO_ERROR;
}
bool IsSuccess() const { return StatusCode() == CHIP_NO_ERROR; }

/**
* Read a bool, assuming single byte storage.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/support/BufferWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class BufferWriter : public EndianBufferWriterBase<BufferWriter>
public:
BufferWriter(uint8_t * buf, size_t len) : EndianBufferWriterBase<BufferWriter>(buf, len)
{
static_assert((-1 & 3) == 3, "LittleEndian::BufferWriter only works with 2's complement architectures.");
static_assert((-1 & 3) == 3, "LittleEndian::BufferWriter only works with 2's complement architectures.");
}
BufferWriter(MutableByteSpan buf) : EndianBufferWriterBase<BufferWriter>(buf) {}
BufferWriter(const BufferWriter & other) = default;
Expand All @@ -148,7 +148,7 @@ class BufferWriter : public EndianBufferWriterBase<BufferWriter>
public:
BufferWriter(uint8_t * buf, size_t len) : EndianBufferWriterBase<BufferWriter>(buf, len)
{
static_assert((-1 & 3) == 3, "BigEndian::BufferWriter only works with 2's complement architectures.");
static_assert((-1 & 3) == 3, "BigEndian::BufferWriter only works with 2's complement architectures.");
}
BufferWriter(MutableByteSpan buf) : EndianBufferWriterBase<BufferWriter>(buf) {}
BufferWriter(const BufferWriter & other) = default;
Expand Down
36 changes: 19 additions & 17 deletions src/lib/support/tests/TestBufferReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ static void TestBufferReader_Skip(nlTestSuite * inSuite, void * inContext)

static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * inContext)
{
const uint8_t test_buf1[10] = {0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01};
const uint8_t test_buf1[10] = { 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01 };

// Unsigned 8 bits reads
{
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf1}};
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf1 } };
uint8_t val1 = 0;
uint8_t val2 = 0;
NL_TEST_ASSERT(inSuite, reader.Read8(&val1).Read8(&val2).IsSuccess());
Expand All @@ -149,7 +149,7 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Unsigned 16 bits reads
{
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf1}};
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf1 } };
uint16_t val1 = 0;
uint16_t val2 = 0;
NL_TEST_ASSERT(inSuite, reader.Read16(&val1).Read16(&val2).IsSuccess());
Expand All @@ -159,7 +159,7 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Unsigned 32 bits reads
{
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf1}};
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf1 } };
uint32_t val1 = 0;
uint32_t val2 = 0;
NL_TEST_ASSERT(inSuite, reader.Read32(&val1).Read32(&val2).IsSuccess());
Expand All @@ -169,8 +169,8 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Unsigned 32 bits reads, unaligned
{
uint8_t test_buf2[10] = {0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01};
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf2}};
uint8_t test_buf2[10] = { 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01 };
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf2 } };

uint32_t val1 = 0;
uint32_t val2 = 0;
Expand All @@ -182,7 +182,7 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Unsigned 64 bits read
{
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf1}};
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf1 } };
uint64_t val = 0;
NL_TEST_ASSERT(inSuite, reader.Read64(&val).IsSuccess());
NL_TEST_ASSERT(inSuite, reader.Remaining() == 2);
Expand All @@ -191,7 +191,7 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Signed 8 bits reads
{
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf1}};
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf1 } };
int8_t val1 = 0;
int8_t val2 = 0;
NL_TEST_ASSERT(inSuite, reader.ReadSigned8(&val1).ReadSigned8(&val2).IsSuccess());
Expand All @@ -201,7 +201,7 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Signed 16 bits reads
{
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf1}};
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf1 } };
int16_t val1 = 0;
int16_t val2 = 0;
NL_TEST_ASSERT(inSuite, reader.ReadSigned16(&val1).ReadSigned16(&val2).IsSuccess());
Expand All @@ -211,7 +211,7 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Signed 32 bits reads
{
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf1}};
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf1 } };
int32_t val1 = 0;
int32_t val2 = 0;
NL_TEST_ASSERT(inSuite, reader.ReadSigned32(&val1).ReadSigned32(&val2).IsSuccess());
Expand All @@ -221,8 +221,8 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Signed 32 bits reads, unaligned
{
uint8_t test_buf2[10] = {0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01};
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf2}};
uint8_t test_buf2[10] = { 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01 };
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf2 } };

int32_t val1 = 0;
int32_t val2 = 0;
Expand All @@ -234,7 +234,7 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Signed 64 bits read
{
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf1}};
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf1 } };
int64_t val = 0;
NL_TEST_ASSERT(inSuite, reader.ReadSigned64(&val).IsSuccess());
NL_TEST_ASSERT(inSuite, reader.Remaining() == 2);
Expand All @@ -243,8 +243,8 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i

// Bools
{
uint8_t test_buf2[5] = {0x00, 0xff, 0x01, 0x04, 0x07};
chip::Encoding::LittleEndian::Reader reader{ByteSpan{test_buf2}};
uint8_t test_buf2[5] = { 0x00, 0xff, 0x01, 0x04, 0x07 };
chip::Encoding::LittleEndian::Reader reader{ ByteSpan{ test_buf2 } };
bool val1 = true;
bool val2 = false;
bool val3 = false;
Expand All @@ -261,8 +261,10 @@ static void TestBufferReader_LittleEndianScalars(nlTestSuite * inSuite, void * i
/**
* Test Suite. It lists all the test functions.
*/
static const nlTest sTests[] = { NL_TEST_DEF_FN(TestBufferReader_Basic), NL_TEST_DEF_FN(TestBufferReader_BasicSpan),
NL_TEST_DEF_FN(TestBufferReader_Saturation), NL_TEST_DEF_FN(TestBufferReader_Skip),
static const nlTest sTests[] = { NL_TEST_DEF_FN(TestBufferReader_Basic),
NL_TEST_DEF_FN(TestBufferReader_BasicSpan),
NL_TEST_DEF_FN(TestBufferReader_Saturation),
NL_TEST_DEF_FN(TestBufferReader_Skip),
NL_TEST_DEF("Test Little-endian buffer Reader scalar reads", TestBufferReader_LittleEndianScalars),
NL_TEST_SENTINEL() };

Expand Down
2 changes: 0 additions & 2 deletions src/lib/support/tests/TestBufferWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ void TestPutBigEndian(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, bb.expect("\x06\x07\x08", 3, 0));
}


{
BWTest<BigEndian::BufferWriter> bb(4);
bb.PutSigned8(static_cast<int8_t>(-6));
Expand Down Expand Up @@ -296,7 +295,6 @@ void TestPutBigEndian(nlTestSuite * inSuite, void * inContext)
bb.PutSigned64(static_cast<int64_t>(9223372036854775807LL));
NL_TEST_ASSERT(inSuite, bb.expect("\x7f\xff\xff\xff\xff\xff\xff\xff", 8, 1));
}

}

const nlTest sTests[] = {
Expand Down

0 comments on commit 4d1f6b0

Please sign in to comment.