Test that DynamicJsonBuffer returns a different pointer after each alloc()

This commit is contained in:
Benoit Blanchon
2014-12-13 10:03:01 +01:00
parent 0d57fe5a7e
commit ada588c112
2 changed files with 11 additions and 1 deletions

View File

@ -21,10 +21,14 @@ class DynamicJsonBuffer : public JsonBuffer {
protected:
virtual void* alloc(size_t bytes) {
void* p = _buffer + _size;
_size += bytes;
return NULL;
return p;
}
static const size_t BLOCK_CAPACITY = 32;
size_t _size;
uint8_t _buffer[BLOCK_CAPACITY];
};
}

View File

@ -26,3 +26,9 @@ TEST_F(DynamicJsonBuffer_Basic_Tests, GrowsAfterAlloc) {
buffer.alloc(100);
ASSERT_EQ(200, buffer.size());
}
TEST_F(DynamicJsonBuffer_Basic_Tests, ReturnDifferentPointer) {
void* p1 = buffer.alloc(100);
void* p2 = buffer.alloc(200);
ASSERT_NE(p1, p2);
}