Browse Source

[core] perf: simpler buffer_string_space() (tests)

personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
aba45f68d8
  1. 2
      src/buffer.h
  2. 19
      src/t/test_buffer.c

2
src/buffer.h

@ -194,7 +194,7 @@ static inline size_t buffer_string_length(const buffer *b) {
}
static inline size_t buffer_string_space(const buffer *b) {
return NULL != b ? b->size - b->used - (0 == b->used) : 0;
return NULL != b && b->size ? b->size - b->used - (0 == b->used) : 0;
}
static inline void buffer_append_string_buffer(buffer *b, const buffer *src) {

19
src/t/test_buffer.c

@ -101,9 +101,28 @@ static void test_buffer_to_lower_upper(void) {
buffer_free(psrc);
}
static void test_buffer_string_space(void) {
buffer *b = buffer_init();
size_t space;
space = buffer_string_space(b);
assert(0 == space);
buffer_copy_string_len(b, CONST_STR_LEN(""));
space = buffer_string_space(b);
assert(space > 0);
assert(space + buffer_string_length(b) == b->size - 1);
buffer_commit(b, b->size - 1);
assert(b->used == b->size);
space = buffer_string_space(b);
assert(0 == space);
buffer_free(b);
}
int main() {
test_buffer_path_simplify();
test_buffer_to_lower_upper();
test_buffer_string_space();
return 0;
}

Loading…
Cancel
Save