You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1009 B

#include "../minunit.h"
#include <lcthw/bstrlib.h>
char *test_bfromcstr()
{
bstring b = bfromcstr("oh hai");
mu_assert(b != NULL, "bstring is NULL.");
return NULL;
}
char *test_blk2bstr()
{
bstring b = blk2bstr("hats", 5);
mu_assert(b != NULL, "bstring is NULL.");
b = blk2bstr(NULL, 42);
mu_assert(b == NULL, "bstring is not NULL.");
b = blk2bstr("bats", -17);
mu_assert(b == NULL, "bstring is not NULL.");
return NULL;
}
char *test_bstrcpy()
{
bstring b = bfromcstr("mats");
mu_assert(bstrcpy(b) != NULL, "bstring is NULL.");
mu_assert(bstrcpy(NULL) == NULL, "bstring is not NULL.");
int orig_len = b->slen;
b->slen = -1;
mu_assert(bstrcpy(b) == NULL, "bstring is not NULL.");
b->slen = orig_len;
b->data = NULL;
mu_assert(bstrcpy(b) == NULL, "bstring is not NULL.");
return NULL;
}
char *all_tests()
{
mu_suite_start();
mu_run_test(test_bfromcstr);
mu_run_test(test_blk2bstr);
mu_run_test(test_bstrcpy);
return NULL;
}
RUN_TESTS(all_tests);