1
0
mirror of https://github.com/yarrick/iodine.git synced 2024-11-25 06:26:05 +03:00

Convert fail_unless to ck_assert[_msg]

To work with check 0.15.0

Add == 0 to change fail_if to asserts as well.
This commit is contained in:
Erik Ekman 2020-07-23 22:31:53 +02:00
parent cde0b7632d
commit 13d081f5ed
9 changed files with 165 additions and 152 deletions

View File

@ -48,8 +48,8 @@ START_TEST(test_base32_encode)
len = sizeof(buf);
val = base32_ops.encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a));
fail_unless(val == strlen(testpairs[_i].b));
fail_unless(strcmp(buf, testpairs[_i].b) == 0,
ck_assert(val == strlen(testpairs[_i].b));
ck_assert_msg(strcmp(buf, testpairs[_i].b) == 0,
"'%s' != '%s'", buf, testpairs[_i].b);
}
END_TEST
@ -63,8 +63,8 @@ START_TEST(test_base32_decode)
len = sizeof(buf);
val = base32_ops.decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b));
fail_unless(val == strlen(testpairs[_i].a));
fail_unless(strcmp(buf, testpairs[_i].a) == 0,
ck_assert(val == strlen(testpairs[_i].a));
ck_assert_msg(strcmp(buf, testpairs[_i].a) == 0,
"'%s' != '%s'", buf, testpairs[_i].a);
}
END_TEST
@ -76,7 +76,7 @@ START_TEST(test_base32_5to8_8to5)
for (i = 0; i < 32; i++) {
c = b32_5to8(i);
fail_unless(b32_8to5(c) == i);
ck_assert(b32_8to5(c) == i);
}
}
END_TEST
@ -103,19 +103,19 @@ START_TEST(test_base32_blksize)
val = base32_ops.encode(encbuf, &enclen, rawbuf, rawlen);
fail_unless(rawlen == 5, "raw length was %d not 5", rawlen);
fail_unless(enclen == 5, "encoded %d bytes, not 5", enclen);
fail_unless(val == 8, "encoded string %s was length %d", encbuf, val);
ck_assert_msg(rawlen == 5, "raw length was %d not 5", rawlen);
ck_assert_msg(enclen == 5, "encoded %d bytes, not 5", enclen);
ck_assert_msg(val == 8, "encoded string %s was length %d", encbuf, val);
memset(rawbuf, 0, rawlen + 16);
enclen = val;
val = base32_ops.decode(rawbuf, &rawlen, encbuf, enclen);
fail_unless(rawlen == 5, "raw length was %d not 5", rawlen);
fail_unless(val == 5, "val was not 5 but %d", val);
ck_assert_msg(rawlen == 5, "raw length was %d not 5", rawlen);
ck_assert_msg(val == 5, "val was not 5 but %d", val);
for (i = 0; i < rawlen; i++) {
fail_unless(rawbuf[i] == 'A');
ck_assert(rawbuf[i] == 'A');
}
}
END_TEST

View File

@ -73,8 +73,8 @@ START_TEST(test_base64_encode)
len = sizeof(buf);
val = base64_ops.encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a));
fail_unless(val == strlen(testpairs[_i].b));
fail_unless(strcmp(buf, testpairs[_i].b) == 0,
ck_assert(val == strlen(testpairs[_i].b));
ck_assert_msg(strcmp(buf, testpairs[_i].b) == 0,
"'%s' != '%s'", buf, testpairs[_i].b);
}
END_TEST
@ -88,8 +88,8 @@ START_TEST(test_base64_decode)
len = sizeof(buf);
val = base64_ops.decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b));
fail_unless(val == strlen(testpairs[_i].a));
fail_unless(strcmp(buf, testpairs[_i].a) == 0,
ck_assert(val == strlen(testpairs[_i].a));
ck_assert_msg(strcmp(buf, testpairs[_i].a) == 0,
"'%s' != '%s'", buf, testpairs[_i].a);
}
END_TEST
@ -116,19 +116,19 @@ START_TEST(test_base64_blksize)
val = base64_ops.encode(encbuf, &enclen, rawbuf, rawlen);
fail_unless(rawlen == 3, "raw length was %d not 3", rawlen);
fail_unless(enclen == 3, "encoded %d bytes, not 3", enclen);
fail_unless(val == 4, "encoded string %s was length %d", encbuf, val);
ck_assert_msg(rawlen == 3, "raw length was %d not 3", rawlen);
ck_assert_msg(enclen == 3, "encoded %d bytes, not 3", enclen);
ck_assert_msg(val == 4, "encoded string %s was length %d", encbuf, val);
memset(rawbuf, 0, rawlen + 16);
enclen = val;
val = base64_ops.decode(rawbuf, &rawlen, encbuf, enclen);
fail_unless(rawlen == 3, "raw length was %d not 3", rawlen);
fail_unless(val == 3);
ck_assert_msg(rawlen == 3, "raw length was %d not 3", rawlen);
ck_assert(val == 3);
for (i = 0; i < rawlen; i++) {
fail_unless(rawbuf[i] == 'A');
ck_assert(rawbuf[i] == 'A');
}
}
END_TEST

View File

@ -25,14 +25,14 @@ START_TEST(test_topdomain_ok)
{
char *error;
fail_if(check_topdomain("foo.0123456789.qwertyuiop.asdfghjkl.zxcvbnm.com", &error));
ck_assert(check_topdomain("foo.0123456789.qwertyuiop.asdfghjkl.zxcvbnm.com", &error) == 0);
/* Not allowed to start with dot */
fail_unless(check_topdomain(".foo.0123456789.qwertyuiop.asdfghjkl.zxcvbnm.com", &error));
fail_if(strcmp("Starts with a dot", error));
ck_assert(check_topdomain(".foo.0123456789.qwertyuiop.asdfghjkl.zxcvbnm.com", &error));
ck_assert(strcmp("Starts with a dot", error) == 0);
/* Test missing error msg ptr */
fail_unless(check_topdomain(".foo", NULL));
ck_assert(check_topdomain(".foo", NULL));
}
END_TEST
@ -41,29 +41,29 @@ START_TEST(test_topdomain_length)
char *error;
/* Test empty and too short */
fail_unless(check_topdomain("", &error));
fail_if(strcmp("Too short (< 3)", error));
fail_unless(check_topdomain("a", &error));
fail_if(strcmp("Too short (< 3)", error));
fail_unless(check_topdomain(".a", &error));
fail_if(strcmp("Too short (< 3)", error));
fail_unless(check_topdomain("a.", &error));
fail_if(strcmp("Too short (< 3)", error));
fail_unless(check_topdomain("ab", &error));
fail_if(strcmp("Too short (< 3)", error));
fail_if(check_topdomain("a.b", &error));
fail_if(strcmp("Too short (< 3)", error));
ck_assert(check_topdomain("", &error));
ck_assert(strcmp("Too short (< 3)", error) == 0);
ck_assert(check_topdomain("a", &error));
ck_assert(strcmp("Too short (< 3)", error) == 0);
ck_assert(check_topdomain(".a", &error));
ck_assert(strcmp("Too short (< 3)", error) == 0);
ck_assert(check_topdomain("a.", &error));
ck_assert(strcmp("Too short (< 3)", error) == 0);
ck_assert(check_topdomain("ab", &error));
ck_assert(strcmp("Too short (< 3)", error) == 0);
ck_assert(check_topdomain("a.b", &error) == 0);
ck_assert(strcmp("Too short (< 3)", error) == 0);
/* Test too long (over 128, need rest of space for data) */
fail_unless(check_topdomain(
ck_assert(check_topdomain(
"abcd12345.abcd12345.abcd12345.abcd12345.abcd12345."
"abcd12345.abcd12345.abcd12345.abcd12345.abcd12345."
"abcd12345.abcd12345.foo129xxx", &error));
fail_if(strcmp("Too long (> 128)", error));
fail_if(check_topdomain(
ck_assert(strcmp("Too long (> 128)", error) == 0);
ck_assert(check_topdomain(
"abcd12345.abcd12345.abcd12345.abcd12345.abcd12345."
"abcd12345.abcd12345.abcd12345.abcd12345.abcd12345."
"abcd12345.abcd12345.foo128xx", &error));
"abcd12345.abcd12345.foo128xx", &error) == 0);
}
END_TEST
@ -72,36 +72,36 @@ START_TEST(test_topdomain_chunks)
char *error;
/* Must have at least one dot */
fail_if(check_topdomain("abcde.gh", &error));
fail_unless(check_topdomain("abcdefgh", &error));
fail_if(strcmp("No dots", error));
ck_assert(check_topdomain("abcde.gh", &error) == 0);
ck_assert(check_topdomain("abcdefgh", &error));
ck_assert(strcmp("No dots", error) == 0);
/* Not two consecutive dots */
fail_unless(check_topdomain("abc..defgh", &error));
fail_if(strcmp("Consecutive dots", error));
ck_assert(check_topdomain("abc..defgh", &error));
ck_assert(strcmp("Consecutive dots", error) == 0);
/* Not end with a dots */
fail_unless(check_topdomain("abc.defgh.", &error));
fail_if(strcmp("Ends with a dot", error));
ck_assert(check_topdomain("abc.defgh.", &error));
ck_assert(strcmp("Ends with a dot", error) == 0);
/* No chunk longer than 63 chars */
fail_if(check_topdomain("123456789012345678901234567890"
"123456789012345678901234567890333.com", &error));
fail_unless(check_topdomain("123456789012345678901234567890"
ck_assert(check_topdomain("123456789012345678901234567890"
"123456789012345678901234567890333.com", &error) == 0);
ck_assert(check_topdomain("123456789012345678901234567890"
"1234567890123456789012345678904444.com", &error));
fail_if(strcmp("Too long domain part (> 63)", error));
ck_assert(strcmp("Too long domain part (> 63)", error) == 0);
fail_if(check_topdomain("abc.123456789012345678901234567890"
"123456789012345678901234567890333.com", &error));
fail_unless(check_topdomain("abc.123456789012345678901234567890"
ck_assert(check_topdomain("abc.123456789012345678901234567890"
"123456789012345678901234567890333.com", &error) == 0);
ck_assert(check_topdomain("abc.123456789012345678901234567890"
"1234567890123456789012345678904444.com", &error));
fail_if(strcmp("Too long domain part (> 63)", error));
ck_assert(strcmp("Too long domain part (> 63)", error) == 0);
fail_if(check_topdomain("abc.123456789012345678901234567890"
"123456789012345678901234567890333", &error));
fail_unless(check_topdomain("abc.123456789012345678901234567890"
ck_assert(check_topdomain("abc.123456789012345678901234567890"
"123456789012345678901234567890333", &error) == 0);
ck_assert(check_topdomain("abc.123456789012345678901234567890"
"1234567890123456789012345678904444", &error));
fail_if(strcmp("Too long domain part (> 63)", error));
ck_assert(strcmp("Too long domain part (> 63)", error) == 0);
}
END_TEST
@ -114,14 +114,14 @@ START_TEST(test_parse_format_ipv4)
int addr_len;
addr_len = get_addr(host, 53, AF_INET, 0, &addr);
fail_unless(addr_len == sizeof(struct sockaddr_in));
ck_assert(addr_len == sizeof(struct sockaddr_in));
v4addr = (struct sockaddr_in *) &addr;
fail_unless(v4addr->sin_addr.s_addr == htonl(0xc0a8020a));
fail_unless(v4addr->sin_port == htons(53));
ck_assert(v4addr->sin_addr.s_addr == htonl(0xc0a8020a));
ck_assert(v4addr->sin_port == htons(53));
formatted = format_addr(&addr, addr_len);
fail_if(strcmp(host, formatted));
ck_assert(strcmp(host, formatted) == 0);
}
END_TEST
@ -134,14 +134,14 @@ START_TEST(test_parse_format_ipv4_listen_all)
int addr_len;
addr_len = get_addr(NULL, 53, AF_INET, AI_PASSIVE, &addr);
fail_unless(addr_len == sizeof(struct sockaddr_in));
ck_assert(addr_len == sizeof(struct sockaddr_in));
v4addr = (struct sockaddr_in *) &addr;
fail_unless(v4addr->sin_addr.s_addr == htonl(0x00000000));
fail_unless(v4addr->sin_port == htons(53));
ck_assert(v4addr->sin_addr.s_addr == htonl(0x00000000));
ck_assert(v4addr->sin_port == htons(53));
formatted = format_addr(&addr, addr_len);
fail_if(strcmp(host, formatted));
ck_assert(strcmp(host, formatted) == 0);
}
END_TEST
@ -159,14 +159,14 @@ START_TEST(test_parse_format_ipv6)
int addr_len;
addr_len = get_addr(host, 53, AF_UNSPEC, 0, &addr);
fail_unless(addr_len == sizeof(struct sockaddr_in6));
ck_assert(addr_len == sizeof(struct sockaddr_in6));
v6addr = (struct sockaddr_in6 *) &addr;
fail_if(memcmp(&v6addr->sin6_addr, v6_bits, sizeof(v6_bits)));
fail_unless(v6addr->sin6_port == htons(53));
ck_assert(memcmp(&v6addr->sin6_addr, v6_bits, sizeof(v6_bits)) == 0);
ck_assert(v6addr->sin6_port == htons(53));
formatted = format_addr(&addr, addr_len);
fail_if(strcmp(compact, formatted));
ck_assert(strcmp(compact, formatted) == 0);
}
END_TEST
@ -184,15 +184,15 @@ START_TEST(test_parse_format_ipv4_mapped_ipv6)
int addr_len;
addr_len = get_addr(v4mapped, 53, AF_INET6, 0, &addr);
fail_unless(addr_len == sizeof(struct sockaddr_in6));
ck_assert(addr_len == sizeof(struct sockaddr_in6));
v6addr = (struct sockaddr_in6 *) &addr;
fail_if(memcmp(&v6addr->sin6_addr, v6_bits, sizeof(v6_bits)));
fail_unless(v6addr->sin6_port == htons(53));
ck_assert(memcmp(&v6addr->sin6_addr, v6_bits, sizeof(v6_bits)) == 0);
ck_assert(v6addr->sin6_port == htons(53));
/* Format as IPv4 address */
formatted = format_addr(&addr, addr_len);
fail_if(strcmp(host, formatted));
ck_assert(strcmp(host, formatted) == 0);
}
END_TEST

View File

@ -100,8 +100,10 @@ START_TEST(test_encode_query)
dump_packet(query_packet, len);
dump_packet(buf, ret);
}
fail_unless(strncmp(query_packet, buf, sizeof(query_packet)) == 0, "Did not compile expected packet");
fail_unless(ret == len, "Bad packet length: %d, expected %d", ret, len);
ck_assert_msg(strncmp(query_packet, buf, sizeof(query_packet)) == 0,
"Did not compile expected packet");
ck_assert_msg(ret == len,
"Bad packet length: %d, expected %d", ret, len);
}
END_TEST
@ -124,8 +126,11 @@ START_TEST(test_decode_query)
len = sizeof(buf);
unpack_data(buf, len, &(q.name[1]), (int) (domain - q.name) - 1, enc);
fail_unless(strncmp(buf, innerData, strlen(innerData)) == 0, "Did not extract expected host: '%s'", buf);
fail_unless(strlen(buf) == strlen(innerData), "Bad host length: %d, expected %d: '%s'", strlen(buf), strlen(innerData), buf);
ck_assert_msg(strncmp(buf, innerData, strlen(innerData)) == 0,
"Did not extract expected host: '%s'", buf);
ck_assert_msg(strlen(buf) == strlen(innerData),
"Bad host length: %d, expected %d: '%s'",
strlen(buf), strlen(innerData), buf);
}
END_TEST
@ -147,8 +152,10 @@ START_TEST(test_encode_response)
ret = dns_encode(buf, len, &q, QR_ANSWER, msgData, strlen(msgData));
len = sizeof(answer_packet) - 1; /* Skip extra null character */
fail_unless(strncmp(answer_packet, buf, sizeof(answer_packet)) == 0, "Did not compile expected packet");
fail_unless(ret == len, "Bad packet length: %d, expected %d", ret, len);
ck_assert_msg(strncmp(answer_packet, buf, sizeof(answer_packet)) == 0,
"Did not compile expected packet");
ck_assert_msg(ret == len,
"Bad packet length: %d, expected %d", ret, len);
}
END_TEST
@ -163,9 +170,11 @@ START_TEST(test_decode_response)
memset(&buf, 0, sizeof(buf));
ret = dns_decode(buf, len, &q, QR_ANSWER, answer_packet, sizeof(answer_packet)-1);
fail_unless(ret == strlen(msgData), "Bad data length: %d, expected %d", ret, strlen(msgData));
fail_unless(strncmp(msgData, buf, strlen(msgData)) == 0, "Did not extract expected data");
fail_unless(q.id == 0x0539);
ck_assert_msg(ret == strlen(msgData),
"Bad data length: %d, expected %d", ret, strlen(msgData));
ck_assert_msg(strncmp(msgData, buf, strlen(msgData)) == 0,
"Did not extract expected data");
ck_assert(q.id == 0x0539);
}
END_TEST
@ -180,9 +189,12 @@ START_TEST(test_decode_response_with_high_trans_id)
memset(&buf, 0, sizeof(buf));
ret = dns_decode(buf, len, &q, QR_ANSWER, answer_packet_high_trans_id, sizeof(answer_packet_high_trans_id)-1);
fail_unless(ret == strlen(msgData), "Bad data length: %d, expected %d", ret, strlen(msgData));
fail_unless(strncmp(msgData, buf, strlen(msgData)) == 0, "Did not extract expected data");
fail_unless(q.id == 0x8539, "q.id was %08X instead of %08X!", q.id, 0x8539);
ck_assert_msg(ret == strlen(msgData),
"Bad data length: %d, expected %d", ret, strlen(msgData));
ck_assert_msg(strncmp(msgData, buf, strlen(msgData)) == 0,
"Did not extract expected data");
ck_assert_msg(q.id == 0x8539,
"q.id was %08X instead of %08X!", q.id, 0x8539);
}
END_TEST
@ -196,7 +208,7 @@ START_TEST(test_get_id_short_packet)
memset(&buf, 5, sizeof(buf));
id = dns_get_id(buf, len);
fail_unless(id == 0);
ck_assert(id == 0);
}
END_TEST
@ -205,7 +217,7 @@ START_TEST(test_get_id_low)
unsigned short id;
id = dns_get_id(answer_packet, sizeof(answer_packet));
fail_unless(id == 1337);
ck_assert(id == 1337);
}
END_TEST
@ -214,7 +226,7 @@ START_TEST(test_get_id_high)
unsigned short id;
id = dns_get_id(answer_packet_high_trans_id, sizeof(answer_packet_high_trans_id));
fail_unless(id == 0x8539);
ck_assert(id == 0x8539);
}
END_TEST

View File

@ -50,7 +50,7 @@ START_TEST(test_inline_dotify)
b = temp;
inline_dotify(b, sizeof(temp));
fail_unless(strcmp(dottests[_i].b, temp) == 0,
ck_assert_msg(strcmp(dottests[_i].b, temp) == 0,
"'%s' != '%s'", temp, dottests[_i].b);
}
END_TEST
@ -65,7 +65,7 @@ START_TEST(test_inline_undotify)
b = temp;
inline_undotify(b, sizeof(temp));
fail_unless(strcmp(dottests[_i].a, temp) == 0,
ck_assert_msg(strcmp(dottests[_i].a, temp) == 0,
"'%s' != '%s'", temp, dottests[_i].a);
}
END_TEST
@ -87,8 +87,9 @@ START_TEST(test_build_hostname)
for (i = 1; i < sizeof(data); i++) {
int len = build_hostname(buf, buflen, data, i, topdomain, &base32_ops, sizeof(buf));
fail_if(len > i);
fail_if(strstr(buf, ".."), "Found double dots when encoding data len %d! buf: %s", i, buf);
ck_assert(len <= i);
ck_assert_msg(strstr(buf, "..") == NULL,
"Found double dots when encoding data len %d! buf: %s", i, buf);
}
}
END_TEST

View File

@ -31,14 +31,14 @@ START_TEST(test_fw_query_simple)
/* Test empty cache */
fw_query_get(0x848A, &qp);
fail_unless(qp == NULL);
ck_assert(qp == NULL);
fw_query_put(&q);
/* Test cache with one entry */
fw_query_get(0x848A, &qp);
fail_unless(qp->addrlen == q.addrlen);
fail_unless(qp->id == q.id);
ck_assert(qp->addrlen == q.addrlen);
ck_assert(qp->id == q.id);
}
END_TEST
@ -62,8 +62,8 @@ START_TEST(test_fw_query_edge)
/* The query should still be cached */
fw_query_get(0x848A, &qp);
fail_unless(qp->addrlen == 33);
fail_unless(qp->id == 0x848A);
ck_assert(qp->addrlen == 33);
ck_assert(qp->id == 0x848A);
q.addrlen++;
q.id++;
@ -71,7 +71,7 @@ START_TEST(test_fw_query_edge)
/* but now it is overwritten */
fw_query_get(0x848A, &qp);
fail_unless(qp == NULL);
ck_assert(qp == NULL);
}
END_TEST

View File

@ -34,7 +34,7 @@ START_TEST(test_login_hash)
memset(ans, 0, sizeof(ans));
login_calculate(ans, len, pass, seed);
fail_unless(strncmp(ans, good, len) == 0, NULL);
ck_assert(strncmp(ans, good, len) == 0);
}
END_TEST
@ -54,7 +54,7 @@ START_TEST(test_login_hash_short)
/* If len < 16, it should do nothing */
login_calculate(ans, len, pass, seed);
fail_if(memcmp(ans, check, sizeof(ans)));
ck_assert(memcmp(ans, check, sizeof(ans)) == 0);
}
END_TEST

View File

@ -46,13 +46,13 @@ START_TEST(test_read_putshort)
for (i = 0; i < 65536; i++) {
p = (char*)&k;
putshort(&p, i);
fail_unless(ntohs(k) == i,
ck_assert_msg(ntohs(k) == i,
"Bad value on putshort for %d: %d != %d",
i, ntohs(k), i);
p = (char*)&k;
readshort(NULL, &p, &l);
fail_unless(l == i,
ck_assert_msg(l == i,
"Bad value on readshort for %d: %d != %d",
i, l, i);
}
@ -73,13 +73,13 @@ START_TEST(test_read_putlong)
putlong(&p, j);
fail_unless(ntohl(k) == j,
ck_assert_msg(ntohl(k) == j,
"Bad value on putlong for %d: %d != %d", i, ntohl(j), j);
p = (char*)&k;
readlong(NULL, &p, &l);
fail_unless(l == j,
ck_assert_msg(l == j,
"Bad value on readlong for %d: %d != %d", i, l, j);
}
}
@ -98,8 +98,8 @@ START_TEST(test_read_name_empty_loop)
data = (char*) emptyloop + sizeof(HEADER);
buf[1023] = 'A';
rv = readname((char *) emptyloop, sizeof(emptyloop), &data, buf, 1023);
fail_unless(rv == 0);
fail_unless(buf[1023] == 'A');
ck_assert(rv == 0);
ck_assert(buf[1023] == 'A');
}
END_TEST
@ -116,8 +116,8 @@ START_TEST(test_read_name_inf_loop)
data = (char*) infloop + sizeof(HEADER);
buf[4] = '\a';
rv = readname((char*) infloop, sizeof(infloop), &data, buf, 4);
fail_unless(rv == 3);
fail_unless(buf[4] == '\a');
ck_assert(rv == 3);
ck_assert(buf[4] == '\a');
}
END_TEST
@ -140,8 +140,8 @@ START_TEST(test_read_name_longname)
data = (char*) longname + sizeof(HEADER);
buf[256] = '\a';
rv = readname((char*) longname, sizeof(longname), &data, buf, 256);
fail_unless(rv == 256);
fail_unless(buf[256] == '\a');
ck_assert(rv == 256);
ck_assert(buf[256] == '\a');
}
END_TEST
@ -157,7 +157,7 @@ START_TEST(test_read_name_onejump)
memset(buf, 0, sizeof(buf));
data = (char*) onejump + sizeof(HEADER);
rv = readname((char*) onejump, sizeof(onejump), &data, buf, 256);
fail_unless(rv == 9);
ck_assert(rv == 9);
}
END_TEST
@ -179,8 +179,8 @@ START_TEST(test_read_name_badjump_start)
data = (char*) jumper + sizeof(HEADER);
rv = readname((char*) jumper, sizeof(badjump), &data, buf, 256);
fail_unless(rv == 0);
fail_unless(buf[0] == 0);
ck_assert(rv == 0);
ck_assert(buf[0] == 0);
}
free(jumper);
}
@ -204,8 +204,8 @@ START_TEST(test_read_name_badjump_second)
data = (char*) jumper + sizeof(HEADER);
rv = readname((char*) jumper, sizeof(badjump2), &data, buf, 256);
fail_unless(rv == 4);
fail_unless(strcmp("BA.", buf) == 0,
ck_assert(rv == 4);
ck_assert_msg(strcmp("BA.", buf) == 0,
"buf is not BA: %s", buf);
}
free(jumper);
@ -224,8 +224,8 @@ START_TEST(test_putname)
b = buf;
ret = putname(&b, 256, domain);
fail_unless(ret == strlen(domain) + 1);
fail_unless(strncmp(buf, out, ret) == 0, "Happy flow failed");
ck_assert(ret == strlen(domain) + 1);
ck_assert_msg(strncmp(buf, out, ret) == 0, "Happy flow failed");
}
END_TEST
@ -242,8 +242,8 @@ START_TEST(test_putname_nodot)
b = buf;
ret = putname(&b, 256, nodot);
fail_unless(ret == -1);
fail_unless(b == buf);
ck_assert(ret == -1);
ck_assert(b == buf);
}
END_TEST
@ -264,8 +264,8 @@ START_TEST(test_putname_toolong)
b = buf;
ret = putname(&b, 256, toolong);
fail_unless(ret == -1);
fail_unless(b == buf);
ck_assert(ret == -1);
ck_assert(b == buf);
}
END_TEST

View File

@ -38,12 +38,12 @@ START_TEST(test_init_users)
ip = inet_addr("127.0.0.1");
count = init_users(ip, 27);
for (i = 0; i < count; i++) {
fail_unless(users[i].id == i);
fail_unless(users[i].q.id == 0);
fail_unless(users[i].inpacket.len == 0);
fail_unless(users[i].outpacket.len == 0);
ck_assert(users[i].id == i);
ck_assert(users[i].q.id == 0);
ck_assert(users[i].inpacket.len == 0);
ck_assert(users[i].outpacket.len == 0);
snprintf(givenip, sizeof(givenip), "127.0.0.%d", i + 2);
fail_unless(users[i].tun_ip == inet_addr(givenip));
ck_assert(users[i].tun_ip == inet_addr(givenip));
}
}
END_TEST
@ -58,25 +58,25 @@ START_TEST(test_find_user_by_ip)
users[0].conn = CONN_DNS_NULL;
testip = (unsigned int) inet_addr("10.0.0.1");
fail_unless(find_user_by_ip(testip) == -1);
ck_assert(find_user_by_ip(testip) == -1);
testip = (unsigned int) inet_addr("127.0.0.2");
fail_unless(find_user_by_ip(testip) == -1);
ck_assert(find_user_by_ip(testip) == -1);
users[0].active = 1;
testip = (unsigned int) inet_addr("127.0.0.2");
fail_unless(find_user_by_ip(testip) == -1);
ck_assert(find_user_by_ip(testip) == -1);
users[0].last_pkt = time(NULL);
testip = (unsigned int) inet_addr("127.0.0.2");
fail_unless(find_user_by_ip(testip) == -1);
ck_assert(find_user_by_ip(testip) == -1);
users[0].authenticated = 1;
testip = (unsigned int) inet_addr("127.0.0.2");
fail_unless(find_user_by_ip(testip) == 0);
ck_assert(find_user_by_ip(testip) == 0);
}
END_TEST
@ -87,17 +87,17 @@ START_TEST(test_all_users_waiting_to_send)
ip = inet_addr("127.0.0.1");
init_users(ip, 27);
fail_unless(all_users_waiting_to_send() == 1);
ck_assert(all_users_waiting_to_send() == 1);
users[0].conn = CONN_DNS_NULL;
users[0].active = 1;
fail_unless(all_users_waiting_to_send() == 1);
ck_assert(all_users_waiting_to_send() == 1);
users[0].last_pkt = time(NULL);
users[0].outpacket.len = 0;
fail_unless(all_users_waiting_to_send() == 0);
ck_assert(all_users_waiting_to_send() == 0);
#ifdef OUTPACKETQ_LEN
users[0].outpacketq_filled = 1;
@ -105,7 +105,7 @@ START_TEST(test_all_users_waiting_to_send)
users[0].outpacket.len = 44;
#endif
fail_unless(all_users_waiting_to_send() == 1);
ck_assert(all_users_waiting_to_send() == 1);
}
END_TEST
@ -120,24 +120,24 @@ START_TEST(test_find_available_user)
for (i = 0; i < USERS; i++) {
users[i].authenticated = 1;
users[i].authenticated_raw = 1;
fail_unless(find_available_user() == i);
fail_if(users[i].authenticated);
fail_if(users[i].authenticated_raw);
ck_assert(find_available_user() == i);
ck_assert(users[i].authenticated == 0);
ck_assert(users[i].authenticated_raw == 0);
}
for (i = 0; i < USERS; i++) {
fail_unless(find_available_user() == -1);
ck_assert(find_available_user() == -1);
}
users[3].active = 0;
fail_unless(find_available_user() == 3);
fail_unless(find_available_user() == -1);
ck_assert(find_available_user() == 3);
ck_assert(find_available_user() == -1);
users[3].last_pkt = 55;
fail_unless(find_available_user() == 3);
fail_unless(find_available_user() == -1);
ck_assert(find_available_user() == 3);
ck_assert(find_available_user() == -1);
}
END_TEST
@ -150,22 +150,22 @@ START_TEST(test_find_available_user_small_net)
init_users(ip, 29); /* this should result in 5 enabled users */
for (i = 0; i < 5; i++) {
fail_unless(find_available_user() == i);
ck_assert(find_available_user() == i);
}
for (i = 0; i < USERS; i++) {
fail_unless(find_available_user() == -1);
ck_assert(find_available_user() == -1);
}
users[3].active = 0;
fail_unless(find_available_user() == 3);
fail_unless(find_available_user() == -1);
ck_assert(find_available_user() == 3);
ck_assert(find_available_user() == -1);
users[3].last_pkt = 55;
fail_unless(find_available_user() == 3);
fail_unless(find_available_user() == -1);
ck_assert(find_available_user() == 3);
ck_assert(find_available_user() == -1);
}
END_TEST