fix coding style
This commit is contained in:
1 parent
b615a5880c
commit
30c4e8edaa
60 files changed
+1275
-1275
No files matched your search
+155
-155
@@ -32,7 +32,7 @@ uint32_t Buffer::m_maxTotalAddStart = 0;
|
||||
uint32_t Buffer::m_maxTotalAddEnd = 0;
|
||||
|
||||
struct Buffer::BufferData *
|
||||
Buffer::allocate (uint32_t reqSize, uint32_t reqStart)
|
||||
Buffer::Allocate (uint32_t reqSize, uint32_t reqStart)
|
||||
{
|
||||
if (reqSize == 0) {
|
||||
reqSize = 1;
|
||||
@@ -50,31 +50,31 @@ Buffer::allocate (uint32_t reqSize, uint32_t reqStart)
|
||||
}
|
||||
|
||||
void
|
||||
Buffer::deallocate (struct Buffer::BufferData *data)
|
||||
Buffer::Deallocate (struct Buffer::BufferData *data)
|
||||
{
|
||||
uint8_t *buf = reinterpret_cast<uint8_t *> (data);
|
||||
delete [] buf;
|
||||
}
|
||||
#ifdef USE_FREE_LIST
|
||||
void
|
||||
Buffer::recycle (struct Buffer::BufferData *data)
|
||||
Buffer::Recycle (struct Buffer::BufferData *data)
|
||||
{
|
||||
assert (data->m_count == 0);
|
||||
/* get rid of it if it is too small for later reuse. */
|
||||
if (data->m_size < (Buffer::m_maxTotalAddStart + Buffer::m_maxTotalAddEnd)) {
|
||||
Buffer::deallocate (data);
|
||||
Buffer::Deallocate (data);
|
||||
return;
|
||||
}
|
||||
/* feed into free list */
|
||||
if (Buffer::m_freeList.size () > 1000) {
|
||||
Buffer::deallocate (data);
|
||||
Buffer::Deallocate (data);
|
||||
} else {
|
||||
Buffer::m_freeList.push_back (data);
|
||||
}
|
||||
}
|
||||
|
||||
Buffer::BufferData *
|
||||
Buffer::create (void)
|
||||
Buffer::Create (void)
|
||||
{
|
||||
/* try to find a buffer correctly sized. */
|
||||
while (!Buffer::m_freeList.empty ()) {
|
||||
@@ -87,25 +87,25 @@ Buffer::create (void)
|
||||
data->m_count = 1;
|
||||
return data;
|
||||
}
|
||||
Buffer::deallocate (data);
|
||||
Buffer::Deallocate (data);
|
||||
}
|
||||
struct Buffer::BufferData *data = Buffer::allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
|
||||
struct Buffer::BufferData *data = Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
|
||||
m_maxTotalAddStart);
|
||||
assert (data->m_count == 1);
|
||||
return data;
|
||||
}
|
||||
#else
|
||||
void
|
||||
Buffer::recycle (struct Buffer::BufferData *data)
|
||||
Buffer::Recycle (struct Buffer::BufferData *data)
|
||||
{
|
||||
Buffer::deallocate (data);
|
||||
Buffer::Deallocate (data);
|
||||
}
|
||||
|
||||
Buffer::BufferData *
|
||||
Buffer::create (void)
|
||||
Buffer::Create (void)
|
||||
{
|
||||
return Buffer::allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
|
||||
m_maxTotalAddStart);
|
||||
return Buffer::Allocate (m_maxTotalAddStart+m_maxTotalAddEnd,
|
||||
m_maxTotalAddStart);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace ns3 {
|
||||
|
||||
|
||||
void
|
||||
Buffer::addAtStart (uint32_t start)
|
||||
Buffer::AddAtStart (uint32_t start)
|
||||
{
|
||||
assert (m_start <= m_data->m_initialStart);
|
||||
bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
|
||||
@@ -128,20 +128,20 @@ Buffer::addAtStart (uint32_t start)
|
||||
m_size += start;
|
||||
} else if (m_size + start <= m_data->m_size && !isDirty) {
|
||||
/* enough space but need to move data around to fit new data */
|
||||
memmove (m_data->m_data + start, getStart (), m_size);
|
||||
memmove (m_data->m_data + start, GetStart (), m_size);
|
||||
assert (start > m_start);
|
||||
m_data->m_initialStart += start;
|
||||
m_start = 0;
|
||||
m_size += start;
|
||||
m_start = 0;
|
||||
m_size += start;
|
||||
} else if (m_start < start) {
|
||||
/* not enough space in buffer */
|
||||
uint32_t newSize = m_size + start;
|
||||
struct Buffer::BufferData *newData = Buffer::allocate (newSize, 0);
|
||||
memcpy (newData->m_data + start, getStart (), m_size);
|
||||
struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
|
||||
memcpy (newData->m_data + start, GetStart (), m_size);
|
||||
newData->m_initialStart = m_data->m_initialStart + start;
|
||||
m_data->m_count--;
|
||||
if (m_data->m_count == 0) {
|
||||
Buffer::deallocate (m_data);
|
||||
Buffer::Deallocate (m_data);
|
||||
}
|
||||
m_data = newData;
|
||||
m_start = 0;
|
||||
@@ -149,12 +149,12 @@ Buffer::addAtStart (uint32_t start)
|
||||
} else {
|
||||
/* enough space in the buffer but it is dirty ! */
|
||||
assert (isDirty);
|
||||
struct Buffer::BufferData *newData = Buffer::create ();
|
||||
memcpy (newData->m_data + m_start, getStart (), m_size);
|
||||
struct Buffer::BufferData *newData = Buffer::Create ();
|
||||
memcpy (newData->m_data + m_start, GetStart (), m_size);
|
||||
newData->m_initialStart = m_data->m_initialStart;
|
||||
m_data->m_count--;
|
||||
if (m_data->m_count == 0) {
|
||||
recycle (m_data);
|
||||
Recycle (m_data);
|
||||
}
|
||||
m_data = newData;
|
||||
m_start -= start;
|
||||
@@ -178,7 +178,7 @@ Buffer::addAtStart (uint32_t start)
|
||||
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
|
||||
}
|
||||
void
|
||||
Buffer::addAtEnd (uint32_t end)
|
||||
Buffer::AddAtEnd (uint32_t end)
|
||||
{
|
||||
assert (m_start <= m_data->m_initialStart);
|
||||
bool isDirty = m_data->m_count > 1 &&
|
||||
@@ -188,21 +188,21 @@ Buffer::addAtEnd (uint32_t end)
|
||||
m_size += end;
|
||||
} else if (m_size + end <= m_data->m_size && !isDirty) {
|
||||
/* enough space but need to move data around to fit the extra data */
|
||||
uint32_t newStart = m_data->m_size - (m_size + end);
|
||||
memmove (m_data->m_data + newStart, getStart (), m_size);
|
||||
uint32_t newStart = m_data->m_size - (m_size + end);
|
||||
memmove (m_data->m_data + newStart, GetStart (), m_size);
|
||||
assert (newStart < m_start);
|
||||
m_data->m_initialStart -= m_start - newStart;
|
||||
m_start = newStart;
|
||||
m_size += end;
|
||||
m_start = newStart;
|
||||
m_size += end;
|
||||
} else if (m_start + m_size + end > m_data->m_size) {
|
||||
/* not enough space in buffer */
|
||||
uint32_t newSize = m_size + end;
|
||||
struct Buffer::BufferData *newData = Buffer::allocate (newSize, 0);
|
||||
memcpy (newData->m_data, getStart (), m_size);
|
||||
struct Buffer::BufferData *newData = Buffer::Allocate (newSize, 0);
|
||||
memcpy (newData->m_data, GetStart (), m_size);
|
||||
newData->m_initialStart = m_data->m_initialStart;
|
||||
m_data->m_count--;
|
||||
if (m_data->m_count == 0) {
|
||||
Buffer::deallocate (m_data);
|
||||
Buffer::Deallocate (m_data);
|
||||
}
|
||||
m_data = newData;
|
||||
m_size = newSize;
|
||||
@@ -210,12 +210,12 @@ Buffer::addAtEnd (uint32_t end)
|
||||
} else {
|
||||
/* enough space in the buffer but it is dirty ! */
|
||||
assert (isDirty);
|
||||
struct Buffer::BufferData *newData = Buffer::create ();
|
||||
memcpy (newData->m_data + m_start, getStart (), m_size);
|
||||
struct Buffer::BufferData *newData = Buffer::Create ();
|
||||
memcpy (newData->m_data + m_start, GetStart (), m_size);
|
||||
newData->m_initialStart = m_data->m_initialStart;
|
||||
m_data->m_count--;
|
||||
if (m_data->m_count == 0) {
|
||||
recycle (m_data);
|
||||
Recycle (m_data);
|
||||
}
|
||||
m_data = newData;
|
||||
m_size += end;
|
||||
@@ -240,7 +240,7 @@ Buffer::addAtEnd (uint32_t end)
|
||||
}
|
||||
|
||||
void
|
||||
Buffer::removeAtStart (uint32_t start)
|
||||
Buffer::RemoveAtStart (uint32_t start)
|
||||
{
|
||||
if (m_zeroAreaSize == 0) {
|
||||
if (m_size <= start) {
|
||||
@@ -284,7 +284,7 @@ Buffer::removeAtStart (uint32_t start)
|
||||
", dirty start="<<m_data->m_dirtyStart<<", dirty size="<<m_data->m_dirtySize);
|
||||
}
|
||||
void
|
||||
Buffer::removeAtEnd (uint32_t end)
|
||||
Buffer::RemoveAtEnd (uint32_t end)
|
||||
{
|
||||
if (m_zeroAreaSize == 0) {
|
||||
if (m_size <= end) {
|
||||
@@ -325,47 +325,47 @@ Buffer::removeAtEnd (uint32_t end)
|
||||
}
|
||||
|
||||
Buffer
|
||||
Buffer::createFragment (uint32_t start, uint32_t length) const
|
||||
Buffer::CreateFragment (uint32_t start, uint32_t length) const
|
||||
{
|
||||
uint32_t zeroStart = m_data->m_initialStart - m_start;
|
||||
uint32_t zeroEnd = zeroStart + m_zeroAreaSize;
|
||||
if (m_zeroAreaSize != 0 &&
|
||||
start + length > zeroStart &&
|
||||
start <= zeroEnd) {
|
||||
transformIntoRealBuffer ();
|
||||
TransformIntoRealBuffer ();
|
||||
}
|
||||
Buffer tmp = *this;
|
||||
tmp.removeAtStart (start);
|
||||
tmp.removeAtEnd (getSize () - (start + length));
|
||||
tmp.RemoveAtStart (start);
|
||||
tmp.RemoveAtEnd (GetSize () - (start + length));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void
|
||||
Buffer::transformIntoRealBuffer (void) const
|
||||
Buffer::TransformIntoRealBuffer (void) const
|
||||
{
|
||||
if (m_zeroAreaSize != 0) {
|
||||
assert (m_data->m_initialStart >= m_start);
|
||||
assert (m_size >= (m_data->m_initialStart - m_start));
|
||||
Buffer tmp;
|
||||
tmp.addAtStart (m_zeroAreaSize);
|
||||
tmp.begin ().writeU8 (0, m_zeroAreaSize);
|
||||
tmp.AddAtStart (m_zeroAreaSize);
|
||||
tmp.Begin ().WriteU8 (0, m_zeroAreaSize);
|
||||
uint32_t dataStart = m_data->m_initialStart - m_start;
|
||||
tmp.addAtStart (dataStart);
|
||||
tmp.begin ().write (m_data->m_data+m_start, dataStart);
|
||||
tmp.AddAtStart (dataStart);
|
||||
tmp.Begin ().Write (m_data->m_data+m_start, dataStart);
|
||||
uint32_t dataEnd = m_size - (m_data->m_initialStart - m_start);
|
||||
tmp.addAtEnd (dataEnd);
|
||||
Buffer::Iterator i = tmp.end ();
|
||||
i.prev (dataEnd);
|
||||
i.write (m_data->m_data+m_data->m_initialStart,dataEnd);
|
||||
tmp.AddAtEnd (dataEnd);
|
||||
Buffer::Iterator i = tmp.End ();
|
||||
i.Prev (dataEnd);
|
||||
i.Write (m_data->m_data+m_data->m_initialStart,dataEnd);
|
||||
*const_cast<Buffer *> (this) = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t const*
|
||||
Buffer::peekData (void) const
|
||||
Buffer::PeekData (void) const
|
||||
{
|
||||
transformIntoRealBuffer ();
|
||||
TransformIntoRealBuffer ();
|
||||
return m_data->m_data + m_start;
|
||||
}
|
||||
|
||||
@@ -384,10 +384,10 @@ namespace ns3 {
|
||||
|
||||
class BufferTest: public Test {
|
||||
private:
|
||||
bool ensureWrittenBytes (Buffer b, uint32_t n, uint8_t array[]);
|
||||
bool EnsureWrittenBytes (Buffer b, uint32_t n, uint8_t array[]);
|
||||
public:
|
||||
virtual bool runTests (void);
|
||||
BufferTest ();
|
||||
virtual bool RunTests (void);
|
||||
BufferTest ();
|
||||
};
|
||||
|
||||
|
||||
@@ -395,32 +395,32 @@ BufferTest::BufferTest ()
|
||||
: Test ("Buffer") {}
|
||||
|
||||
bool
|
||||
BufferTest::ensureWrittenBytes (Buffer b, uint32_t n, uint8_t array[])
|
||||
BufferTest::EnsureWrittenBytes (Buffer b, uint32_t n, uint8_t array[])
|
||||
{
|
||||
bool success = true;
|
||||
uint8_t *expected = array;
|
||||
uint8_t const*got;
|
||||
got = b.peekData ();
|
||||
got = b.PeekData ();
|
||||
for (uint32_t j = 0; j < n; j++) {
|
||||
if (got[j] != expected[j]) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
failure () << "Buffer -- ";
|
||||
failure () << "expected: n=";
|
||||
failure () << n << ", ";
|
||||
failure ().setf (std::ios::hex, std::ios::basefield);
|
||||
Failure () << "Buffer -- ";
|
||||
Failure () << "expected: n=";
|
||||
Failure () << n << ", ";
|
||||
Failure ().setf (std::ios::hex, std::ios::basefield);
|
||||
for (uint32_t j = 0; j < n; j++) {
|
||||
failure () << (uint16_t)expected[j] << " ";
|
||||
Failure () << (uint16_t)expected[j] << " ";
|
||||
}
|
||||
failure ().setf (std::ios::dec, std::ios::basefield);
|
||||
failure () << "got: ";
|
||||
failure ().setf (std::ios::hex, std::ios::basefield);
|
||||
Failure ().setf (std::ios::dec, std::ios::basefield);
|
||||
Failure () << "got: ";
|
||||
Failure ().setf (std::ios::hex, std::ios::basefield);
|
||||
for (uint32_t j = 0; j < n; j++) {
|
||||
failure () << (uint16_t)got[j] << " ";
|
||||
Failure () << (uint16_t)got[j] << " ";
|
||||
}
|
||||
failure () << std::endl;
|
||||
Failure () << std::endl;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -432,75 +432,75 @@ BufferTest::ensureWrittenBytes (Buffer b, uint32_t n, uint8_t array[])
|
||||
#define ENSURE_WRITTEN_BYTES(buffer, n, ...) \
|
||||
{ \
|
||||
uint8_t bytes[] = {__VA_ARGS__}; \
|
||||
if (!ensureWrittenBytes (buffer, n , bytes)) { \
|
||||
if (!EnsureWrittenBytes (buffer, n , bytes)) { \
|
||||
ok = false; \
|
||||
} \
|
||||
}
|
||||
|
||||
bool
|
||||
BufferTest::runTests (void)
|
||||
BufferTest::RunTests (void)
|
||||
{
|
||||
bool ok = true;
|
||||
Buffer buffer;
|
||||
Buffer::Iterator i;
|
||||
buffer.addAtStart (6);
|
||||
i = buffer.begin ();
|
||||
i.writeU8 (0x66);
|
||||
buffer.AddAtStart (6);
|
||||
i = buffer.Begin ();
|
||||
i.WriteU8 (0x66);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 1, 0x66);
|
||||
i = buffer.begin ();
|
||||
i.writeU8 (0x67);
|
||||
i = buffer.Begin ();
|
||||
i.WriteU8 (0x67);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 1, 0x67);
|
||||
i.writeHtonU16 (0x6568);
|
||||
i = buffer.begin ();
|
||||
i.WriteHtonU16 (0x6568);
|
||||
i = buffer.Begin ();
|
||||
ENSURE_WRITTEN_BYTES (buffer, 3, 0x67, 0x65, 0x68);
|
||||
i.writeHtonU16 (0x6369);
|
||||
i.WriteHtonU16 (0x6369);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 3, 0x63, 0x69, 0x68);
|
||||
i.writeHtonU32 (0xdeadbeaf);
|
||||
i.WriteHtonU32 (0xdeadbeaf);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 6, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
|
||||
buffer.addAtStart (2);
|
||||
i = buffer.begin ();
|
||||
i.writeU16 (0);
|
||||
buffer.AddAtStart (2);
|
||||
i = buffer.Begin ();
|
||||
i.WriteU16 (0);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 8, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf);
|
||||
buffer.addAtEnd (2);
|
||||
i = buffer.begin ();
|
||||
i.next (8);
|
||||
i.writeU16 (0);
|
||||
buffer.AddAtEnd (2);
|
||||
i = buffer.Begin ();
|
||||
i.Next (8);
|
||||
i.WriteU16 (0);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 10, 0, 0, 0x63, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
|
||||
buffer.removeAtStart (3);
|
||||
i = buffer.begin ();
|
||||
buffer.RemoveAtStart (3);
|
||||
i = buffer.Begin ();
|
||||
ENSURE_WRITTEN_BYTES (buffer, 7, 0x69, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
|
||||
buffer.removeAtEnd (4);
|
||||
i = buffer.begin ();
|
||||
buffer.RemoveAtEnd (4);
|
||||
i = buffer.Begin ();
|
||||
ENSURE_WRITTEN_BYTES (buffer, 3, 0x69, 0xde, 0xad);
|
||||
buffer.addAtStart (1);
|
||||
i = buffer.begin ();
|
||||
i.writeU8 (0xff);
|
||||
buffer.AddAtStart (1);
|
||||
i = buffer.Begin ();
|
||||
i.WriteU8 (0xff);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 4, 0xff, 0x69, 0xde, 0xad);
|
||||
buffer.addAtEnd (1);
|
||||
i = buffer.begin ();
|
||||
i.next (4);
|
||||
i.writeU8 (0xff);
|
||||
i.prev (2);
|
||||
uint16_t saved = i.readU16 ();
|
||||
i.prev (2);
|
||||
i.writeHtonU16 (0xff00);
|
||||
i.prev (2);
|
||||
if (i.readNtohU16 () != 0xff00) {
|
||||
buffer.AddAtEnd (1);
|
||||
i = buffer.Begin ();
|
||||
i.Next (4);
|
||||
i.WriteU8 (0xff);
|
||||
i.Prev (2);
|
||||
uint16_t saved = i.ReadU16 ();
|
||||
i.Prev (2);
|
||||
i.WriteHtonU16 (0xff00);
|
||||
i.Prev (2);
|
||||
if (i.ReadNtohU16 () != 0xff00) {
|
||||
ok = false;
|
||||
}
|
||||
i.prev (2);
|
||||
i.writeU16 (saved);
|
||||
i.Prev (2);
|
||||
i.WriteU16 (saved);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0x69, 0xde, 0xad, 0xff);
|
||||
Buffer o = buffer;
|
||||
ENSURE_WRITTEN_BYTES (o, 5, 0xff, 0x69, 0xde, 0xad, 0xff);
|
||||
o.addAtStart (1);
|
||||
i = o.begin ();
|
||||
i.writeU8 (0xfe);
|
||||
o.AddAtStart (1);
|
||||
i = o.Begin ();
|
||||
i.WriteU8 (0xfe);
|
||||
ENSURE_WRITTEN_BYTES (o, 6, 0xfe, 0xff, 0x69, 0xde, 0xad, 0xff);
|
||||
buffer.addAtStart (2);
|
||||
i = buffer.begin ();
|
||||
i.writeU8 (0xfd);
|
||||
i.writeU8 (0xfd);
|
||||
buffer.AddAtStart (2);
|
||||
i = buffer.Begin ();
|
||||
i.WriteU8 (0xfd);
|
||||
i.WriteU8 (0xfd);
|
||||
ENSURE_WRITTEN_BYTES (o, 6, 0xfe, 0xff, 0x69, 0xde, 0xad, 0xff);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 7, 0xfd, 0xfd, 0xff, 0x69, 0xde, 0xad, 0xff);
|
||||
|
||||
@@ -510,71 +510,71 @@ BufferTest::runTests (void)
|
||||
a = a;
|
||||
}
|
||||
|
||||
// test remove start.
|
||||
// test Remove start.
|
||||
buffer = Buffer (5);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
|
||||
buffer.removeAtStart (1);
|
||||
buffer.RemoveAtStart (1);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
|
||||
buffer.addAtStart (1);
|
||||
buffer.begin ().writeU8 (0xff);
|
||||
buffer.AddAtStart (1);
|
||||
buffer.Begin ().WriteU8 (0xff);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 5, 0xff, 0, 0, 0, 0);
|
||||
buffer.removeAtStart(3);
|
||||
buffer.RemoveAtStart(3);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
|
||||
buffer.addAtStart (4);
|
||||
buffer.begin ().writeHtonU32 (0xdeadbeaf);
|
||||
buffer.AddAtStart (4);
|
||||
buffer.Begin ().WriteHtonU32 (0xdeadbeaf);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 6, 0xde, 0xad, 0xbe, 0xaf, 0, 0);
|
||||
buffer.removeAtStart (2);
|
||||
buffer.RemoveAtStart (2);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 4, 0xbe, 0xaf, 0, 0);
|
||||
buffer.addAtEnd (4);
|
||||
i = buffer.begin ();
|
||||
i.next (4);
|
||||
i.writeHtonU32 (0xdeadbeaf);
|
||||
buffer.AddAtEnd (4);
|
||||
i = buffer.Begin ();
|
||||
i.Next (4);
|
||||
i.WriteHtonU32 (0xdeadbeaf);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 8, 0xbe, 0xaf, 0, 0, 0xde, 0xad, 0xbe, 0xaf);
|
||||
buffer.removeAtStart (5);
|
||||
buffer.RemoveAtStart (5);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 3, 0xad, 0xbe, 0xaf);
|
||||
// test remove end
|
||||
// test Remove end
|
||||
buffer = Buffer (5);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0);
|
||||
buffer.removeAtEnd (1);
|
||||
buffer.RemoveAtEnd (1);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 4, 0, 0, 0, 0);
|
||||
buffer.addAtEnd (2);
|
||||
i = buffer.begin ();
|
||||
i.next (4);
|
||||
i.writeU8 (0xab);
|
||||
i.writeU8 (0xac);
|
||||
buffer.AddAtEnd (2);
|
||||
i = buffer.Begin ();
|
||||
i.Next (4);
|
||||
i.WriteU8 (0xab);
|
||||
i.WriteU8 (0xac);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 6, 0, 0, 0, 0, 0xab, 0xac);
|
||||
buffer.removeAtEnd (1);
|
||||
buffer.RemoveAtEnd (1);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 5, 0, 0, 0, 0, 0xab);
|
||||
buffer.removeAtEnd (3);
|
||||
buffer.RemoveAtEnd (3);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 2, 0, 0);
|
||||
buffer.addAtEnd (6);
|
||||
i = buffer.begin ();
|
||||
i.next (2);
|
||||
i.writeU8 (0xac);
|
||||
i.writeU8 (0xad);
|
||||
i.writeU8 (0xae);
|
||||
i.writeU8 (0xaf);
|
||||
i.writeU8 (0xba);
|
||||
i.writeU8 (0xbb);
|
||||
buffer.AddAtEnd (6);
|
||||
i = buffer.Begin ();
|
||||
i.Next (2);
|
||||
i.WriteU8 (0xac);
|
||||
i.WriteU8 (0xad);
|
||||
i.WriteU8 (0xae);
|
||||
i.WriteU8 (0xaf);
|
||||
i.WriteU8 (0xba);
|
||||
i.WriteU8 (0xbb);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 8, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
|
||||
buffer.addAtStart (3);
|
||||
i = buffer.begin ();
|
||||
i.writeU8 (0x30);
|
||||
i.writeU8 (0x31);
|
||||
i.writeU8 (0x32);
|
||||
buffer.AddAtStart (3);
|
||||
i = buffer.Begin ();
|
||||
i.WriteU8 (0x30);
|
||||
i.WriteU8 (0x31);
|
||||
i.WriteU8 (0x32);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 11, 0x30, 0x31, 0x32, 0, 0, 0xac, 0xad, 0xae, 0xaf, 0xba, 0xbb);
|
||||
buffer.removeAtEnd (9);
|
||||
buffer.RemoveAtEnd (9);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 2, 0x30, 0x31);
|
||||
buffer = Buffer (3);
|
||||
buffer.addAtEnd (2);
|
||||
i = buffer.begin ();
|
||||
i.next (3);
|
||||
i.writeHtonU16 (0xabcd);
|
||||
buffer.addAtStart (1);
|
||||
buffer.begin ().writeU8 (0x21);
|
||||
buffer.AddAtEnd (2);
|
||||
i = buffer.Begin ();
|
||||
i.Next (3);
|
||||
i.WriteHtonU16 (0xabcd);
|
||||
buffer.AddAtStart (1);
|
||||
buffer.Begin ().WriteU8 (0x21);
|
||||
ENSURE_WRITTEN_BYTES (buffer, 6, 0x21, 0, 0, 0, 0xab, 0xcd);
|
||||
buffer.removeAtEnd (8);
|
||||
if (buffer.getSize () != 0) {
|
||||
buffer.RemoveAtEnd (8);
|
||||
if (buffer.GetSize () != 0) {
|
||||
ok = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user