Пример #1
0
void DataBufferTF::testExpand()
{
    DataBuffer buffer;
    buffer.expand(0);
    CPPUNIT_ASSERT(buffer._pstart);
    int64_t content = 0x12345678;
    buffer.writeInt64(content);
    int oldDataLen = buffer.getDataLen();
    buffer.expand(MAX_BUFFER_SIZE);
    CPPUNIT_ASSERT_EQUAL(oldDataLen, buffer.getDataLen());
    CPPUNIT_ASSERT(buffer.getFreeLen() >= MAX_BUFFER_SIZE);
    CPPUNIT_ASSERT_EQUAL(content, buffer.readInt64());
}
Пример #2
0
void DataBufferTF::testShrink()
{
    DataBuffer buffer;
    buffer.shrink();
    CPPUNIT_ASSERT(!buffer._pstart);
    buffer.expand(1);
    void *old_pstart = buffer._pstart;
    if (buffer._pend - buffer._pstart <= MAX_BUFFER_SIZE) {
        buffer.shrink();
        CPPUNIT_ASSERT_EQUAL(old_pstart, (void *)buffer._pstart);
    }
    const char *content = "just for test";
    int len  = 14;
    buffer.writeBytes(content, len);
    buffer.expand(MAX_BUFFER_SIZE);
    old_pstart = buffer._pstart;
    int datalen = buffer._pstart - buffer._pfree;
    buffer.shrink();
    CPPUNIT_ASSERT(old_pstart != buffer._pstart);
    CPPUNIT_ASSERT(buffer.findBytes((const char *)content, len) >= 0);
    CPPUNIT_ASSERT(old_pstart != buffer._pstart);
    CPPUNIT_ASSERT_EQUAL(datalen,(int)(buffer._pstart - buffer._pfree));
    CPPUNIT_ASSERT_EQUAL((int)(buffer._pend - buffer._pstart), MAX_BUFFER_SIZE);
}