add htbuffer_clear and some more tests

This commit is contained in:
whottgen 2005-03-31 14:04:55 +00:00
parent 725228882d
commit 780bdb30ce
2 changed files with 46 additions and 1 deletions

View File

@ -93,6 +93,11 @@ htbuffer_t *htbuffer_memcpy_w_offset(htbuffer_t *dest, unsigned int offset, cons
return dest;
}
htbuffer_t *htbuffer_clear(htbuffer_t *dest) {
memset(dest->buf, 0, dest->current_buf_size);
return dest;
}
htbuffer_t *htbuffer_memcpy(htbuffer_t *dest, const char *src, unsigned int src_size) {
return htbuffer_memcpy_w_offset(dest, 0, src, src_size);
}

View File

@ -163,8 +163,48 @@ int main(int argc, char **args) {
printf("11. OK\n");
htbuffer_free(b);
/* ------------------------------------------------------------------------------------------- */
#define TEXT12 "aaa"
#define TEXT13 "bbb"
b = htbuffer_init(512);
htbuffer_strcpy(b, TEXT12);
htbuffer_strcpy(b, TEXT13);
if (strcmp(TEXT13, b->buf))
printf("12. FAULURE: unexpected content {%s}\n", b->buf);
else
printf("12. OK\n");
htbuffer_free(b);
/* ------------------------------------------------------------------------------------------- */
#define TEXT14 "aaa"
#define TEXT15 "bbb"
b = htbuffer_init(512);
htbuffer_strcpy(b, TEXT14);
htbuffer_strcpy(b, "");
htbuffer_strcat(b, TEXT15);
if (strcmp(TEXT15, b->buf))
printf("13. FAULURE: unexpected content {%s}\n", b->buf);
else
printf("13. OK\n");
htbuffer_free(b);
/* ------------------------------------------------------------------------------------------- */
#define TEXT16 "aaa"
#define TEXT17 "bbb"
#define TEXT17_1 "b"
b = htbuffer_init(512);
htbuffer_strcpy(b, TEXT16);
htbuffer_clear(b);
htbuffer_strncat(b, TEXT15, 1);
htbuffer_strncat(b, "\0", 1);
if (strcmp(TEXT17_1, b->buf))
printf("13. FAULURE: unexpected content {%s}\n", b->buf);
else
printf("13. OK\n");
htbuffer_free(b);