Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 72 additions & 61 deletions tests/bstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ test0_0(const char *s, const char *res)
int ret = 0;
bstring b0 = bfromcstr(s);
if (s) {
if (b0 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
if (res == NULL) {
if (b0 == NULL || res == NULL) {
ck_abort();
return; /* Just a safeguard */
}
Expand All @@ -80,11 +76,7 @@ test0_1(const char *s, int len, const char *res)
int ret = 0;
bstring b0 = bfromcstralloc(len, s);
if (s) {
if (b0 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
if (res == NULL) {
if (b0 == NULL || res == NULL) {
ck_abort();
return; /* Just a safeguard */
}
Expand Down Expand Up @@ -137,11 +129,7 @@ test1_0(const void *blk, int len, const char *res)
{
int ret = 0;
bstring b0 = blk2bstr(blk, len);
if (res) {
if (b0 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
if (res && b0) {
ck_assert_int_eq(b0->slen, len);
ret = memcmp(res, b0->data, len);
ck_assert_int_eq(ret, 0);
Expand Down Expand Up @@ -173,11 +161,7 @@ test2_0(const bstring b, char z, const unsigned char *res)
{
int ret = 0;
char *s = bstr2cstr(b, z);
if (res) {
if (s == NULL) {
ck_abort();
return; /* Just a safeguard */
}
if (res && s) {
ret = strlen(s);
ck_assert_int_eq(b->slen, ret);
ret = memcmp(res, b->data, b->slen);
Expand Down Expand Up @@ -235,11 +219,9 @@ test3_0(const bstring b)
bstring b0 = bstrcpy(b);
if (!b || !b->data || b->slen < 0) {
ck_assert(b0 == NULL);
} else if (b0 == NULL) {
ck_abort();
} else {
if (b0 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
ck_assert_int_eq(b0->slen, b->slen);
ret = memcmp(b->data, b0->data, b->slen);
ck_assert_int_eq(ret, 0);
Expand Down Expand Up @@ -270,11 +252,7 @@ test4_0(const bstring b, int left, int len, const char *res)
if (b0 == NULL) {
ck_assert(!b || !b->data || b->slen < 0 || len < 0);
} else {
if (b == NULL) {
ck_abort();
return; /* Just a safeguard */
}
if (res == NULL) {
if (b == NULL || res == NULL) {
ck_abort();
return; /* Just a safeguard */
}
Expand Down Expand Up @@ -504,18 +482,18 @@ test7x8(int (* fnptr)(const bstring, const bstring),
bstring b = bstrcpy(&shortBstring);
if (b == NULL) {
ck_abort();
return; /* Just a safeguard */
}
b->data[1]++;
test7x8_0(fnptr, b, &shortBstring, retGT);
int ret = bdestroy(b);
ck_assert_int_eq(ret, BSTR_OK);
if (fnptr == biseq) {
test7x8_0(fnptr, &shortBstring, &longBstring, retGT);
test7x8_0(fnptr, &longBstring, &shortBstring, retLT);
} else {
test7x8_0(fnptr, &shortBstring, &longBstring, 'b' - 'T');
test7x8_0(fnptr, &longBstring, &shortBstring, 'T' - 'b');
b->data[1]++;
test7x8_0(fnptr, b, &shortBstring, retGT);
int ret = bdestroy(b);
ck_assert_int_eq(ret, BSTR_OK);
if (fnptr == biseq) {
test7x8_0(fnptr, &shortBstring, &longBstring, retGT);
test7x8_0(fnptr, &longBstring, &shortBstring, retLT);
} else {
test7x8_0(fnptr, &shortBstring, &longBstring, 'b' - 'T');
test7x8_0(fnptr, &longBstring, &shortBstring, 'T' - 'b');
}
}
}

Expand Down Expand Up @@ -1029,7 +1007,10 @@ test17_0(bstring s1, int pos, int len, char * res)
int ret = 0;
if (s1 && s1->data && s1->slen >= 0) {
b2 = bstrcpy(s1);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = bdelete(b2, pos, len);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -1147,7 +1128,10 @@ test19_0(bstring b, int len, const char *res, int erv)
bstring b1 = NULL;
if (b && b->data && b->slen >= 0) {
b1 = bstrcpy(b);
ck_assert(b1 != NULL);
if (b1 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b1);
ret = bpattern(b1, len);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -1326,17 +1310,17 @@ test21_1(bstring b, const bstring sc, int ns)
l = bsplitstr (b, sc);
if (l == NULL) {
ck_abort();
return; /* Just a safeguard */
} else {
ck_assert_int_eq(ns, l->qty);
c = bjoin(l, sc);
ck_assert(c != NULL);
ret = biseq (c, b);
ck_assert_int_eq(ret, 1);
ret = bdestroy(c);
ck_assert_int_eq(ret, BSTR_OK);
ret = bstrListDestroy(l);
ck_assert_int_eq(ret, BSTR_OK);
}
ck_assert_int_eq(ns, l->qty);
c = bjoin(l, sc);
ck_assert(c != NULL);
ret = biseq (c, b);
ck_assert_int_eq(ret, 1);
ret = bdestroy(c);
ck_assert_int_eq(ret, BSTR_OK);
ret = bstrListDestroy(l);
ck_assert_int_eq(ret, BSTR_OK);
} else {
l = bsplitstr(b, sc);
ck_assert(l == NULL);
Expand Down Expand Up @@ -1822,7 +1806,10 @@ test26_0(bstring b0, int pos, int len, const bstring b1,
if (b0 && b0->data && b0->slen >= 0 &&
b1 && b1->data && b1->slen >= 0) {
b2 = bstrcpy(b0);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = breplace(b2, pos, len, b1, fill);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -1882,7 +1869,10 @@ test27_0(bstring b0, const bstring b1, const char *res)
if (b0 && b0->data && b0->slen >= 0 &&
b1 && b1->data && b1->slen >= 0) {
b2 = bstrcpy(b0);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = bassign(b2, b1);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -2014,7 +2004,10 @@ test29_0(bstring b0, char *s, const char *res)
int ret = 0;
if (b0 && b0->data && b0->slen >= 0) {
b2 = bstrcpy(b0);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = bcatcstr(b2, s);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -2063,7 +2056,10 @@ test30_0(bstring b0, const unsigned char *s, int len, const char *res)
int ret = 0;
if (b0 && b0->data && b0->slen >= 0) {
b2 = bstrcpy(b0);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = bcatblk(b2, s, len);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -2126,7 +2122,10 @@ test31_0(bstring b0, const bstring find, const bstring replace,
find && find->data && find->slen >= 0 &&
replace && replace->data && replace->slen >= 0) {
b2 = bstrcpy(b0);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = bfindreplace(b2, find, replace, pos);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -2158,7 +2157,10 @@ test31_1(bstring b0, const bstring find, const bstring replace,
find && find->data && find->slen >= 0 &&
replace && replace->data && replace->slen >= 0) {
b2 = bstrcpy(b0);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = bfindreplacecaseless(b2, find, replace, pos);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -2321,7 +2323,10 @@ test33_0(bstring b0, const char *res)
int ret = 0;
if (b0 && b0->data && b0->slen >= 0) {
b2 = bstrcpy(b0);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = btoupper(b2);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -2367,7 +2372,10 @@ test34_0(bstring b0, const char *res)
int ret = 0;
if (b0 != NULL && b0->data != NULL && b0->slen >= 0) {
b2 = bstrcpy(b0);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = btolower(b2);
ck_assert_int_eq(ret, BSTR_ERR);
Expand Down Expand Up @@ -2700,7 +2708,10 @@ test40_0(bstring b0, const bstring b1, int left, int len, const char *res)
if (b0 != NULL && b0->data != NULL && b0->slen >= 0 &&
b1 != NULL && b1->data != NULL && b1->slen >= 0) {
b2 = bstrcpy(b0);
ck_assert(b2 != NULL);
if (b2 == NULL) {
ck_abort();
return; /* Just a safeguard */
}
bwriteprotect(*b2);
ret = bassignmidstr(b2, b1, left, len);
ck_assert_int_ne(ret, 0);
Expand Down