I am writing a dynamically growing string buffer. I have the following in a .c
file.
#ifndef STRBUF_GROWTH_SIZE
#define STRBUF_GROWTH_SIZE 4096
#endif
My code uses this constant to do the reallocation of the buffer. Now in the tests, I need to set this value to a small one so that I can check the reallocation. I tried defining this in the tests.cpp
(All tests are in C++ using UnitTest++).
#define STRBUF_GROWTH_SIZE 10
TEST(StringBuffer)
{
struct strbuf *string = strbuf_init();
strbuf_add(string, "first");
CHECK_EQUAL("first", string->buffer);
CHECK_EQUAL(5, string->length);
CHECK_EQUAL(10, string->allocated); /* this fails */
strbuf_add(string, " second");
CHECK_EQUAL("first second", string->buffer);
CHECK_EQUAL(12, string->length);
CHECK_EQUAL(20, string->allocated); /* this fails */
strbuf_destroy(string);
}
I am wondering why the value didn't change to 10? How can I workaround this problem?
Any thoughts?