Add test for gbuf

This commit is contained in:
Nils O. Selåsdal
2012-11-18 13:45:52 +01:00
parent 9547730c9e
commit 65a6c67277
4 changed files with 59 additions and 4 deletions
+42
View File
@@ -0,0 +1,42 @@
#include <check.h>
#include <string.h>
#include <ucore/ucore_buffer.h>
START_TEST (test_new_gbuf)
GBuf *buf = uc_new_gbuf(11);
fail_if(buf == NULL);
fail_if(buf->len != 11);
fail_if(buf->ref_cnt != 1);
fail_if(buf->buf == NULL);
fail_if(buf->used != 0);
END_TEST
START_TEST (test_gbuf_append1)
const char *data = "lorum_ ipson 1234567890";
int rc;
GBuf *buf = uc_new_gbuf(11);
fail_if(buf == NULL);
rc = uc_gbuf_append(buf, data, strlen(data) + 1);
fail_if(rc != 0);
fail_if(buf->used != strlen(data) + 1);
fail_if(strcmp(data, buf->buf) != 0);
END_TEST
Suite *buffer_suite(void)
{
Suite *s = suite_create("buffer");
TCase *tc = tcase_create("buffer (GBuf) tests");
tcase_add_test(tc, test_new_gbuf);
tcase_add_test(tc, test_gbuf_append1);
suite_add_tcase(s, tc);
return s;
}