예제 #1
0
CDataBuffer::CDataBuffer(const CDataBuffer& Buffer)
    : m_BufferSize(Buffer.GetDataSize()), m_AllocPercentage(Buffer.m_AllocPercentage),
      m_DataEnd(0)
{
    m_Buffer = (BYTE*)malloc(m_BufferSize);
    Append(Buffer.GetData(), Buffer.GetDataSize());
}
예제 #2
0
void TestDataBuffer()
{
    CDataBuffer DataBuffer;
    char* String = "SimpleString";
    int StringLength = 12;
    int NumberOfRepetitions = 1000;
    for(int i = 0; i < NumberOfRepetitions; ++i)
        DataBuffer.Append((BYTE*)String, StringLength);
    Assert(DataBuffer.GetDataSize() == StringLength * NumberOfRepetitions);
    const BYTE* Data = DataBuffer.GetData();
    for(int j = 0; j < NumberOfRepetitions; ++j)
    {
        bool Equal = (0 == memcmp(String, Data, StringLength));
        Assert(Equal);
        Data += StringLength;
    }

    CDataBuffer AnotherBuffer(DataBuffer);
    char* UpdateString = "UpdateString";
    int UpdateStringLen = (int)strlen(UpdateString);
    int UpdatePosition = 10;
    Assert(AnotherBuffer.UpdateData(UpdatePosition, (BYTE*)UpdateString,
                                    UpdateStringLen) == true);
    Data = AnotherBuffer.GetData();
    Assert(memcmp(Data + UpdatePosition, UpdateString, UpdateStringLen) == 0);

    TestStruct TestType;
    AnotherBuffer.AppendType(TestType);

    CDataBuffer AssignedBuffer = AnotherBuffer;
    Assert(AssignedBuffer.GetDataSize() == AnotherBuffer.GetDataSize());
    Assert(memcmp(AssignedBuffer.GetData(), AnotherBuffer.GetData(), AnotherBuffer.GetDataSize()) == 0);
}