Commit 17360776 authored by Pekka Pessi's avatar Pekka Pessi

su tests: using TEST_P() and TEST_SIZE().

darcs-hash:20061121185719-65a35-2fab31d458a013d437ef7ff469971fb0bce2043a.gz
parent 1d26f947
......@@ -155,7 +155,7 @@ void zap(context_t *c, entry_t *e)
su_free(c->c_home, e);
}
static int count(context_t *c, hash_value_t h)
static unsigned long count(context_t *c, hash_value_t h)
{
entry_t *e, **ee;
unsigned long n;
......
......@@ -58,10 +58,6 @@ static int test_flags = 0;
char const name[] = "test_memmem";
#ifdef _MSC_VER
#pragma warning(disable:4295) /* disable C4295: array is too small to include a terminating null character*/
#endif
void usage(void)
{
fprintf(stderr, "usage: %s [-v]\n", name);
......@@ -74,20 +70,21 @@ char const *null = NULL;
static int test_notfound(void)
{
char const haystack[12] = "abcabcabcabc";
char const needle[3] = "cab";
char const haystack[] = "abcabcabcabc";
char const needle[] = "cab";
char const *a;
BEGIN();
TEST(memmem(haystack, sizeof haystack, needle, sizeof needle), haystack + 2);
TEST(memmem(needle, sizeof needle, haystack, sizeof haystack), NULL);
TEST(memmem(haystack, sizeof haystack, "", 0), haystack);
TEST(memmem(haystack, sizeof haystack, null, 0), haystack);
TEST(memmem(haystack, 0, "", 0), haystack);
TEST(memmem(haystack, 0, null, 0), haystack);
TEST_P(memmem(haystack, 12, needle, 3), haystack + 2);
TEST_P(memmem(needle, 3, haystack, 12), NULL);
TEST_P(memmem(haystack, 12, "", 0), haystack);
TEST_P(memmem(haystack, 12, null, 0), haystack);
TEST_P(memmem(haystack, 0, "", 0), haystack);
TEST_P(memmem(haystack, 0, null, 0), haystack);
TEST(memmem(haystack + 2, 3, needle, 3), haystack + 2);
TEST(memmem(a = "a\0bc", 4, "a\0bc", 4), a);
TEST_P(memmem(haystack + 2, 3, needle, 3), haystack + 2);
TEST_P(memmem(haystack + 2, 2, needle, 3), NULL);
TEST_P(memmem(a = "a\0bc", 4, "a\0bc", 4), a);
END();
}
......
This diff is collapsed.
......@@ -234,7 +234,7 @@ int test_sendrecv(void)
TEST(su_wait(w, 1, 500), 0);
TEST(su_wait_events(w, s), SU_WAIT_IN);
TEST(su_getmsgsize(s), 8 + 8 + 6);
TEST_SIZE(su_getmsgsize(s), 8 + 8 + 6);
n = su_vrecv(s, rv, 3, 0, NULL, NULL); TEST(n, 8 + 8 + 6);
TEST(su_wait(w, 1, 100), SU_WAIT_TIMEOUT);
......
......@@ -138,19 +138,19 @@ static int test_alloc(void)
su_home_preload(home, 1, 1024 + 2 * 8);
TEST_1(c = su_zalloc(home, 64)); p0 = c; p1 = c + 1024;
TEST(c = su_realloc(home, c0 = c, 127), c0);
TEST_P(c = su_realloc(home, c0 = c, 127), c0);
TEST_1(c = c0 = su_zalloc(home, 1024 - 128));
TEST_1(p0 <= c); TEST_1(c < p1);
TEST(c = su_realloc(home, c, 128), c0);
TEST(c = su_realloc(home, c, 1023 - 128), c0);
TEST(c = su_realloc(home, c, 1024 - 128), c0);
TEST_P(c = su_realloc(home, c, 128), c0);
TEST_P(c = su_realloc(home, c, 1023 - 128), c0);
TEST_P(c = su_realloc(home, c, 1024 - 128), c0);
TEST_1(c = su_realloc(home, c, 1024));
TEST_1(c = su_realloc(home, c, 2 * 1024));
TEST(c = su_realloc(home, p0, 126), p0);
TEST_P(c = su_realloc(home, p0, 126), p0);
TEST_1(c = su_realloc(home, p0, 1024));
TEST(c = su_realloc(home, c, 0), NULL);
TEST_P(c = su_realloc(home, c, 0), NULL);
su_home_check(home);
su_home_deinit(home);
......@@ -260,7 +260,7 @@ static int test_strlst(void)
TEST_S(su_strlst_item(l1, 0), "aaa");
TEST_VOID(su_strlst_destroy(l1));
TEST(su_strlst_len(NULL), 0);
TEST_SIZE(su_strlst_len(NULL), 0);
TEST_1(!su_strlst_get_array(NULL));
TEST_VOID(su_strlst_free_array(NULL, NULL));
......@@ -284,8 +284,8 @@ static int test_strlst(void)
TEST_S(su_strlst_item(l, 0), foo);
TEST_S(su_strlst_item(l, 1), bar);
TEST_S(su_strlst_item(l, 2), baz);
TEST(su_strlst_item(l, 3), NULL);
TEST(su_strlst_item(l, (unsigned)-1), NULL);
TEST_P(su_strlst_item(l, 3), NULL);
TEST_P(su_strlst_item(l, (unsigned)-1), NULL);
TEST_1(l1 = su_strlst_copy(su_strlst_home(l), l));
TEST_1(l2 = su_strlst_dup(su_strlst_home(l), l));
......@@ -303,9 +303,9 @@ static int test_strlst(void)
su_home_get_stats(su_strlst_home(l), 0, kids, sizeof kids);
TEST(kids->hs_clones, 2);
TEST(kids->hs_allocs.hsa_number, 3);
TEST(kids->hs_frees.hsf_number, 1);
TEST_SIZE(kids->hs_clones, 2);
TEST64(kids->hs_allocs.hsa_number, 3);
TEST64(kids->hs_frees.hsf_number, 1);
su_strlst_destroy(l);
......@@ -356,7 +356,7 @@ static int test_strlst(void)
{
char s[] = "foo\nfaa\n";
TEST_1((l = su_strlst_split(home, s, "\n")));
TEST(su_strlst_len(l), 3);
TEST_SIZE(su_strlst_len(l), 3);
TEST_1(su_strlst_append(l, "bar"));
TEST_S(su_strlst_join(l, home, "\n"), "foo\nfaa\n\nbar");
}
......@@ -364,19 +364,19 @@ static int test_strlst(void)
{
char s[] = "foo";
TEST_1((l = su_strlst_split(home, s, "\n")));
TEST(su_strlst_len(l), 1);
TEST_SIZE(su_strlst_len(l), 1);
}
{
char s[] = "\n\n";
TEST_1((l = su_strlst_split(home, s, "\n")));
TEST(su_strlst_len(l), 3);
TEST_SIZE(su_strlst_len(l), 3);
}
{
char s[] = "";
TEST_1((l = su_strlst_split(home, s, "\n")));
TEST(su_strlst_len(l), 1);
TEST_SIZE(su_strlst_len(l), 1);
}
{
......@@ -391,7 +391,7 @@ static int test_strlst(void)
char s[] = S;
TEST_1((l = su_strlst_split(home, s, "\n")));
TEST(su_strlst_len(l), 53);
TEST_SIZE(su_strlst_len(l), 53);
TEST_1(su_strlst_append(l, "bar"));
TEST_S(su_strlst_join(l, home, "\n"), S "\nbar");
......@@ -400,11 +400,11 @@ static int test_strlst(void)
for (i = 0; i < 54; i++) {
TEST_1(su_strlst_remove(l, 0));
TEST_1(!su_strlst_remove(l, 53 - i));
TEST(su_strlst_len(l), 53 - i);
TEST_SIZE(su_strlst_len(l), 53 - i);
}
TEST_1(!su_strlst_remove(l, 0));
TEST(su_strlst_len(l), 0);
TEST_SIZE(su_strlst_len(l), 0);
}
{
......@@ -482,11 +482,11 @@ static int test_vectors(void)
TEST(su_vector_append(v, bar), 0);
TEST(su_vector_insert(v, 0, baz), 0);
TEST(su_vector_item(v, 0), baz);
TEST(su_vector_item(v, 1), foo);
TEST(su_vector_item(v, 2), bar);
TEST(su_vector_item(v, 3), NULL);
TEST(su_vector_item(v, (unsigned)-1), NULL);
TEST_P(su_vector_item(v, 0), baz);
TEST_P(su_vector_item(v, 1), foo);
TEST_P(su_vector_item(v, 2), bar);
TEST_P(su_vector_item(v, 3), NULL);
TEST_P(su_vector_item(v, (unsigned)-1), NULL);
TEST_1(!su_vector_is_empty(v));
su_vector_destroy(v);
......@@ -503,15 +503,15 @@ static int test_vectors(void)
TEST(su_vector_insert(v, 0, "b"), 0);
TEST(su_vector_insert(v, 0, "a"), 0);
TEST(su_vector_len(v), 10);
TEST_SIZE(su_vector_len(v), 10);
TEST_1(a = su_vector_get_array(v));
for (i = 0; i < 10; i++) {
TEST_S(su_vector_item(v, i), a[i]);
}
TEST(su_vector_item(v, 10), NULL);
TEST(a[10], NULL);
TEST_P(su_vector_item(v, 10), NULL);
TEST_P(a[10], NULL);
TEST_1(w = su_vector_create(home, NULL));
TEST(su_vector_append(w, "a"), 0);
......@@ -525,7 +525,7 @@ static int test_vectors(void)
TEST(su_vector_append(w, "i"), 0);
TEST(su_vector_append(w, "j"), 0);
TEST(su_vector_len(w), 10);
TEST_SIZE(su_vector_len(w), 10);
for (i = 0; i < 10; i++) {
TEST_S(su_vector_item(v, i), a[i]);
......@@ -555,12 +555,12 @@ static int test_vectors(void)
TEST(su_vector_append(v, data3), 0);
TEST(su_vector_append(v, data4), 0);
TEST(su_vector_len(v), 4);
TEST_SIZE(su_vector_len(v), 4);
TEST(su_vector_item(v, 0), data1);
TEST(su_vector_item(v, 1), data2);
TEST(su_vector_item(v, 2), data3);
TEST(su_vector_item(v, 3), data4);
TEST_P(su_vector_item(v, 0), data1);
TEST_P(su_vector_item(v, 1), data2);
TEST_P(su_vector_item(v, 2), data3);
TEST_P(su_vector_item(v, 3), data4);
TEST(data1->data, 1);
TEST(data2->data, 2);
......@@ -569,11 +569,11 @@ static int test_vectors(void)
TEST(su_vector_remove(v, 2), 0);
TEST(su_vector_len(v), 3);
TEST_SIZE(su_vector_len(v), 3);
TEST(su_vector_item(v, 0), data1);
TEST(su_vector_item(v, 1), data2);
TEST(su_vector_item(v, 2), data4);
TEST_P(su_vector_item(v, 0), data1);
TEST_P(su_vector_item(v, 1), data2);
TEST_P(su_vector_item(v, 2), data4);
TEST(data1->data, 1);
TEST(data2->data, 2);
......@@ -621,8 +621,10 @@ static int test_auto(void)
su_home_get_stats(tmphome, 0, hs, sizeof *hs);
TEST(hs->hs_allocs.hsa_preload + hs->hs_allocs.hsa_number, 8191 + 8191 / 32);
TEST(hs->hs_frees.hsf_preload + hs->hs_frees.hsf_number, 8191 + 8191 / 32 - 1);
TEST64(hs->hs_allocs.hsa_preload + hs->hs_allocs.hsa_number,
8191 + 8191 / 32);
TEST64(hs->hs_frees.hsf_preload + hs->hs_frees.hsf_number,
8191 + 8191 / 32 - 1);
/*
This test depends on macro SU_HOME_AUTO_SIZE() calculating
offsetof(su_block_t, sub_nodes[7]) correctly with
......
......@@ -108,7 +108,7 @@ static int callback(su_root_magic_t *magic,
su_wait_t *w,
su_wakeup_arg_t *arg)
{
int i = (int)arg;
intptr_t i = (intptr_t)arg;
assert(magic);
......@@ -158,7 +158,7 @@ int test_register(void)
{
su_port_t *port;
su_sockaddr_t su[1];
int i;
intptr_t i;
int sockets[256] = { 0 };
int reg[256] = { 0 };
int wakeups[256] = { 0 };
......
......@@ -208,8 +208,9 @@ static int register_test(root_test_t *rt)
for (i = 0; i < 5; i++) {
test_ep_t *ep = rt->rt_ep[i];
TEST(sendto(s, msg, sizeof(msg), 0, &ep->addr->su_sa, ep->addrlen),
sizeof(msg));
TEST_SIZE(su_sendto(s, msg, sizeof(msg), 0,
&ep->addr->su_sa, ep->addrlen),
sizeof(msg));
test_run(rt);
TEST(rt->rt_received, i);
TEST(rt->rt_wakeup, i);
......@@ -231,8 +232,9 @@ static int register_test(root_test_t *rt)
for (i = 0; i < 5; i++) {
test_ep_t *ep = rt->rt_ep[i];
TEST(sendto(s, msg, sizeof(msg), 0, &ep->addr->su_sa, ep->addrlen),
sizeof(msg));
TEST_SIZE(su_sendto(s, msg, sizeof(msg), 0,
&ep->addr->su_sa, ep->addrlen),
sizeof(msg));
test_run(rt);
TEST(rt->rt_received, i);
TEST(rt->rt_wakeup, i);
......@@ -254,8 +256,9 @@ static int register_test(root_test_t *rt)
for (i = 0; i < 5; i++) {
test_ep_t *ep = rt->rt_ep[i];
TEST(sendto(s, msg, sizeof(msg), 0, &ep->addr->su_sa, ep->addrlen),
sizeof(msg));
TEST_SIZE(su_sendto(s, msg, sizeof(msg), 0,
&ep->addr->su_sa, ep->addrlen),
sizeof(msg));
test_run(rt);
TEST(rt->rt_received, i);
TEST(rt->rt_wakeup, i);
......
......@@ -182,9 +182,9 @@ static int test_assumptions(void)
/* First some pointer arithmetics - this is always true, right? */
tagi = tags;
TEST(tagi + 1, tags + 1);
TEST_P(tagi + 1, tags + 1);
tagi = (tagi_t *)(sizeof(tagi_t) + (char *)tagi);
TEST(tagi, tags + 1);
TEST_P(tagi, tags + 1);
END();
}
......@@ -286,45 +286,45 @@ static int test_dup(void)
TAG_SKIP(2),
TAG_NEXT(rest));
TEST(lst[0].t_tag, tag_a);
TEST(lst[1].t_tag, tag_a);
TEST(lst[2].t_tag, tag_i);
TEST(lst[3].t_tag, tag_skip);
TEST(lst[4].t_tag, tag_next);
TEST_P(lst[0].t_tag, tag_a);
TEST_P(lst[1].t_tag, tag_a);
TEST_P(lst[2].t_tag, tag_i);
TEST_P(lst[3].t_tag, tag_skip);
TEST_P(lst[4].t_tag, tag_next);
TEST(tl_len(lst), 5 * sizeof(tagi_t));
TEST(tl_xtra(lst, 0), strlen("Moro" "Vaan" "Foo") + 3);
TEST_SIZE(tl_len(lst), 5 * sizeof(tagi_t));
TEST_SIZE(tl_xtra(lst, 0), strlen("Moro" "Vaan" "Foo") + 3);
dup = tl_adup(NULL, lst);
TEST0(dup != NULL);
TEST(tl_len(dup), 5 * sizeof(tagi_t));
TEST(tl_xtra(dup, 0), strlen("Moro" "Vaan" "Foo") + 3);
TEST_1(dup != NULL);
TEST_SIZE(tl_len(dup), 5 * sizeof(tagi_t));
TEST_SIZE(tl_xtra(dup, 0), strlen("Moro" "Vaan" "Foo") + 3);
su_free(NULL, dup);
dup = tl_llist(TAG_B("Moi"), TAG_NEXT(lst));
TEST(dup[0].t_tag, tag_b);
TEST(dup[1].t_tag, tag_a);
TEST(dup[2].t_tag, tag_a);
TEST(dup[3].t_tag, tag_i);
TEST(dup[4].t_tag, tag_a);
TEST(dup[5].t_tag, NULL);
TEST_P(dup[0].t_tag, tag_b);
TEST_P(dup[1].t_tag, tag_a);
TEST_P(dup[2].t_tag, tag_a);
TEST_P(dup[3].t_tag, tag_i);
TEST_P(dup[4].t_tag, tag_a);
TEST_P(dup[5].t_tag, NULL);
su_free(NULL, dup);
dup = tl_llist(TAG_NEXT(NULL));
TEST(dup[0].t_tag, 0);
TEST_P(dup[0].t_tag, 0);
su_free(NULL, dup);
dup = tl_llist(TAG_END());
TEST(dup[0].t_tag, 0);
TEST_P(dup[0].t_tag, 0);
su_free(NULL, dup);
dup = tl_llist(TAG_SKIP(1), TAG_NEXT(lst + 4));
TEST(dup[0].t_tag, tag_a);
TEST(dup[1].t_tag, 0);
TEST_P(dup[0].t_tag, tag_a);
TEST_P(dup[1].t_tag, 0);
su_free(NULL, dup);
tl_vfree(lst);
......@@ -392,43 +392,43 @@ static int test_filters(void)
b1 = tl_afilter(NULL, filter1, lst);
TEST(tl_len(b1), 3 * sizeof(tagi_t));
TEST(tl_xtra(b1, 0), strlen("Moro" "vaan") + 2);
TEST_SIZE(tl_len(b1), 3 * sizeof(tagi_t));
TEST_SIZE(tl_xtra(b1, 0), strlen("Moro" "vaan") + 2);
b2 = tl_afilter(NULL, filter2, lst);
TEST(tl_len(b2), 3 * sizeof(tagi_t));
TEST(tl_xtra(b2, 0), 0);
TEST_SIZE(tl_len(b2), 3 * sizeof(tagi_t));
TEST_SIZE(tl_xtra(b2, 0), 0);
b3 = tl_afilter(NULL, filter3, lst);
TEST(tl_len(b3), 5 * sizeof(tagi_t));
TEST(tl_xtra(b3, 0), strlen("Moro" "vaan") + 2);
TEST_SIZE(tl_len(b3), 5 * sizeof(tagi_t));
TEST_SIZE(tl_xtra(b3, 0), strlen("Moro" "vaan") + 2);
b4 = tl_afilter(NULL, filter4, lst);
TEST(tl_len(b4), 7 * sizeof(tagi_t));
TEST(tl_xtra(b4, 0), strlen("Moro" "vaan") + 2);
TEST_SIZE(tl_len(b4), 7 * sizeof(tagi_t));
TEST_SIZE(tl_xtra(b4, 0), strlen("Moro" "vaan") + 2);
su_free(NULL, b1); su_free(NULL, b2); su_free(NULL, b3); su_free(NULL, b4);
nsfilter = tl_list(TAG_ANY_PQ(), TAG_END());
b5 = tl_afilter(NULL, nsfilter, lst);
TEST(tl_len(b5), 3 * sizeof(tagi_t));
TEST(tl_xtra(b5, 0), 0);
TEST_SIZE(tl_len(b5), 3 * sizeof(tagi_t));
TEST_SIZE(tl_xtra(b5, 0), 0);
TEST(b5[0].t_tag, tag_q);
TEST(b5[1].t_tag, tag_p);
TEST_P(b5[0].t_tag, tag_q);
TEST_P(b5[1].t_tag, tag_p);
b = tl_afilter(home, filter5, lst); TEST_1(b);
TEST(b[0].t_tag, tag_a);
TEST(b[1].t_tag, tag_i);
TEST(b[2].t_tag, tag_q);
TEST(b[3].t_tag, 0);
TEST_P(b[0].t_tag, tag_a);
TEST_P(b[1].t_tag, tag_i);
TEST_P(b[2].t_tag, tag_q);
TEST_P(b[3].t_tag, 0);
b = tl_afilter(home, filter6, lst); TEST_1(b);
TEST(b[0].t_tag, 0);
TEST_P(b[0].t_tag, 0);
tl_vfree(filter1); tl_vfree(filter2); tl_vfree(filter3);
tl_vfree(filter4); tl_vfree(filter5); tl_vfree(filter6);
......@@ -483,11 +483,11 @@ static int test_tagargs2(tag_type_t tag, tag_value_t value, ...)
ta_start(ta, tag, value);
t = ta_args(ta);
TEST(t->t_tag, tag_a);
TEST_P(t->t_tag, tag_a);
TEST_S((char *)t->t_value, "a");
t = tl_next(t);
TEST(t->t_tag, tag_b);
TEST_P(t->t_tag, tag_b);
TEST_S((char *)t->t_value, "b");
ta_end(ta);
......
......@@ -167,7 +167,7 @@ int test2(int flags)
TEST(g1->s.clock_seq_hi_and_reserved & 0xc0, 0x80);
TEST(i = su_guid_sprintf(buf, sizeof(buf), g1), su_guid_strlen);
TEST(strlen(buf), i);
TEST_SIZE(strlen(buf), i);
tv0.tv_usec++;
su_guid_generate(g1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment