summaryrefslogtreecommitdiffstats
path: root/src/ByteBuffer.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-01-26 17:48:09 +0100
committermadmaxoft <github@xoft.cz>2014-01-26 17:56:12 +0100
commitab4672be40f0576ab90418e11043d686de6c5855 (patch)
treebc79b1f32589a917ed76b828388d238470a6d87c /src/ByteBuffer.cpp
parentItem-loading now checks for weird bytes. (diff)
downloadcuberite-ab4672be40f0576ab90418e11043d686de6c5855.tar
cuberite-ab4672be40f0576ab90418e11043d686de6c5855.tar.gz
cuberite-ab4672be40f0576ab90418e11043d686de6c5855.tar.bz2
cuberite-ab4672be40f0576ab90418e11043d686de6c5855.tar.lz
cuberite-ab4672be40f0576ab90418e11043d686de6c5855.tar.xz
cuberite-ab4672be40f0576ab90418e11043d686de6c5855.tar.zst
cuberite-ab4672be40f0576ab90418e11043d686de6c5855.zip
Diffstat (limited to 'src/ByteBuffer.cpp')
-rw-r--r--src/ByteBuffer.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index e06f63a0e..d2d3beb97 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -54,6 +54,7 @@ public:
{
TestRead();
TestWrite();
+ TestWrap();
}
void TestRead(void)
@@ -61,11 +62,11 @@ public:
cByteBuffer buf(50);
buf.Write("\x05\xac\x02\x00", 4);
UInt32 v1;
- ASSERT(buf.ReadVarInt(v1) && (v1 == 5));
+ assert(buf.ReadVarInt(v1) && (v1 == 5));
UInt32 v2;
- ASSERT(buf.ReadVarInt(v2) && (v2 == 300));
+ assert(buf.ReadVarInt(v2) && (v2 == 300));
UInt32 v3;
- ASSERT(buf.ReadVarInt(v3) && (v3 == 0));
+ assert(buf.ReadVarInt(v3) && (v3 == 0));
}
void TestWrite(void)
@@ -76,9 +77,30 @@ public:
buf.WriteVarInt(0);
AString All;
buf.ReadAll(All);
- ASSERT(All.size() == 4);
- ASSERT(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0);
+ assert(All.size() == 4);
+ assert(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0);
}
+
+ void TestWrap(void)
+ {
+ cByteBuffer buf(3);
+ for (int i = 0; i < 1000; i++)
+ {
+ int FreeSpace = buf.GetFreeSpace();
+ assert(buf.GetReadableSpace() == 0);
+ assert(FreeSpace > 0);
+ assert(buf.Write("a", 1));
+ assert(buf.CanReadBytes(1));
+ assert(buf.GetReadableSpace() == 1);
+ unsigned char v = 0;
+ assert(buf.ReadByte(v));
+ assert(v == 'a');
+ assert(buf.GetReadableSpace() == 0);
+ buf.CommitRead();
+ assert(buf.GetFreeSpace() == FreeSpace); // We're back to normal
+ }
+ }
+
} g_ByteBufferTest;
#endif
@@ -159,7 +181,7 @@ bool cByteBuffer::Write(const char * a_Bytes, int a_Count)
int CurReadableSpace = GetReadableSpace();
int WrittenBytes = 0;
- if (GetFreeSpace() < a_Count)
+ if (CurFreeSpace < a_Count)
{
return false;
}
@@ -864,3 +886,4 @@ void cByteBuffer::CheckValid(void) const
+