END_TEST START_TEST (test_StringBuffer_accessWithNULL) { StringBuffer_append(NULL, NULL); StringBuffer_appendChar(NULL, ' '); StringBuffer_appendExp(NULL, 0.0); StringBuffer_appendInt(NULL, 0); StringBuffer_appendNumber(NULL, NULL); StringBuffer_appendReal(NULL, 0.0); fail_unless (StringBuffer_capacity(NULL) == 0); StringBuffer_ensureCapacity(NULL, 0); StringBuffer_free(NULL); fail_unless (StringBuffer_getBuffer(NULL) == NULL); StringBuffer_grow(NULL, 0); fail_unless (StringBuffer_length(NULL) == 0); StringBuffer_reset(NULL); fail_unless (StringBuffer_toString(NULL) == NULL); }
/** * Doubles the capacity of this StringBuffer (if nescessary) until it can * hold at least n additional characters. * * Use this function only if you want fine-grained control of the * StringBuffer. By default, the StringBuffer will automatically double * its capacity (as many times as needed) to accomodate an append * operation. */ LIBSBML_EXTERN void StringBuffer_ensureCapacity (StringBuffer_t *sb, unsigned long n) { unsigned long wanted = sb->length + n; unsigned long c; if (wanted > sb->capacity) { /** * Double the total new capacity (c) until it is greater-than wanted. * Grow StringBuffer by this amount minus the current capacity. */ for (c = 2 * sb->capacity; c < wanted; c *= 2) ; StringBuffer_grow(sb, c - sb->capacity); } }
END_TEST START_TEST (test_StringBuffer_grow) { char *s; StringBuffer_append(SB, "foobar"); fail_unless( StringBuffer_length(SB) == 6 ); fail_unless( StringBuffer_capacity(SB) == 10 ); StringBuffer_grow(SB, 10); fail_unless( StringBuffer_length(SB) == 6 ); fail_unless( StringBuffer_capacity(SB) == 20 ); s = StringBuffer_toString(SB); fail_unless( !strcmp(s, "foobar") ); safe_free(s); }