mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-12 12:01:54 +00:00
Birdtest: Refactore some tests
lib/bitops_test.c lib/ip_test.c lib/lists_test.c lib/md5_test.c
This commit is contained in:
parent
81b2e266fb
commit
979dc9e65e
@ -120,7 +120,7 @@ t_log2(void)
|
||||
in_out_data[i].in = pow2(i+1);
|
||||
in_out_data[i].out = i+1;
|
||||
}
|
||||
bt_assert_fn_in(u32_log2, in_out_data, "%u", "%u");
|
||||
bt_assert_out_fn_in(u32_log2, in_out_data, "%u", "%u");
|
||||
|
||||
u32_log2(0);
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include "lib/ip.h"
|
||||
|
||||
#define IP4_MAX_LEN 16
|
||||
|
||||
static u32
|
||||
build_ip4(u8 a, u8 b, u8 c, u8 d)
|
||||
{
|
||||
@ -28,10 +30,10 @@ ip4_pton_(char *s)
|
||||
static int
|
||||
t_ip4_pton(void)
|
||||
{
|
||||
struct in_out_data_ {
|
||||
char *in;
|
||||
struct in_out {
|
||||
char in[IP4_MAX_LEN];
|
||||
u32 out;
|
||||
} in_out_data[] = {
|
||||
} in_out[] = {
|
||||
{
|
||||
.in = "192.168.1.128",
|
||||
.out = build_ip4(192, 168, 1, 128),
|
||||
@ -44,27 +46,11 @@ t_ip4_pton(void)
|
||||
.in = "0.0.0.0",
|
||||
.out = build_ip4(0, 0, 0, 0),
|
||||
},
|
||||
{
|
||||
.in = "00.000.0000.00000",
|
||||
.out = build_ip4(0, 0, 0, 0),
|
||||
},
|
||||
{
|
||||
.in = "00.000.0000.00000",
|
||||
.out = build_ip4(0, 0, 0, 0),
|
||||
},
|
||||
{
|
||||
.in = "-1",
|
||||
.out = build_ip4(0, 0, 0, 0),
|
||||
},
|
||||
{
|
||||
.in = "",
|
||||
.out = build_ip4(0, 0, 0, 0),
|
||||
},
|
||||
};
|
||||
|
||||
bt_assert_fn_in(ip4_pton_, in_out_data, "%s", "0x%08X");
|
||||
bt_assert_out_fn_in(ip4_pton_, in_out, "'%s'", NULL);
|
||||
|
||||
return bt_test_case_success;
|
||||
return bt_test_suite_success;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -80,11 +66,10 @@ ip6_pton_(char *s, u32 (*addr)[4])
|
||||
static int
|
||||
t_ip6_pton(void)
|
||||
{
|
||||
struct in_out_data_ {
|
||||
struct in_out {
|
||||
char *in;
|
||||
u32 out[4];
|
||||
u32 fn_out[4];
|
||||
} in_out_data[] = {
|
||||
} in_out[] = {
|
||||
{
|
||||
.in = "2001:0db8:0000:0000:0000:0000:1428:57ab",
|
||||
.out = {0x20010DB8, 0x00000000, 0x00000000, 0x142857AB},
|
||||
@ -111,13 +96,11 @@ t_ip6_pton(void)
|
||||
},
|
||||
};
|
||||
|
||||
bt_assert_fn_in_out_struct(ip6_pton_, in_out_data, "%s");
|
||||
bt_assert_fn_in_out(ip6_pton_, in_out, "'%s'", NULL);
|
||||
|
||||
return bt_test_case_success;
|
||||
return bt_test_suite_success;
|
||||
}
|
||||
|
||||
#define IP4_MAX_LEN 16
|
||||
|
||||
char *
|
||||
ip4_ntop_(ip4_addr a, char (*b)[IP4_MAX_LEN])
|
||||
{
|
||||
@ -127,11 +110,10 @@ ip4_ntop_(ip4_addr a, char (*b)[IP4_MAX_LEN])
|
||||
static int
|
||||
t_ip4_ntop(void)
|
||||
{
|
||||
struct in_out_data_ {
|
||||
struct in_out {
|
||||
ip4_addr in;
|
||||
char out[IP4_MAX_LEN];
|
||||
char fn_out[IP4_MAX_LEN];
|
||||
} in_out_data[] = {
|
||||
} in_out[] = {
|
||||
{
|
||||
.in = { .addr = build_ip4(192, 168, 1, 128) },
|
||||
.out = "192.168.1.128",
|
||||
@ -147,9 +129,37 @@ t_ip4_ntop(void)
|
||||
|
||||
};
|
||||
|
||||
bt_assert_fn_in_out(ip4_ntop_, in_out_data, "0x%08X", "\"%s\"");
|
||||
bt_assert_fn_in_out(ip4_ntop_, in_out, NULL, "'%s'");
|
||||
|
||||
return bt_test_case_success;
|
||||
return bt_test_suite_success;
|
||||
}
|
||||
|
||||
char *
|
||||
ip6_ntop_(ip6_addr a, char (*b)[INET6_ADDRSTRLEN])
|
||||
{
|
||||
return ip6_ntop(a, (char *) b);
|
||||
}
|
||||
|
||||
static int
|
||||
t_ip6_ntop(void)
|
||||
{
|
||||
struct in_out {
|
||||
ip6_addr in;
|
||||
char out[INET6_ADDRSTRLEN];
|
||||
} in_out[] = {
|
||||
{
|
||||
.in = { .addr = {0x20010DB8, 0x00000000, 0x00000000, 0x142857AB}},
|
||||
.out = "2001:db8::1428:57ab",
|
||||
},
|
||||
{
|
||||
.in = { .addr = {0x26052700, 0x00000003, 0x00000000, 0x471393E3}},
|
||||
.out = "2605:2700:0:3::4713:93e3",
|
||||
},
|
||||
};
|
||||
|
||||
bt_assert_fn_in_out(ip6_ntop_, in_out, NULL, "'%s'");
|
||||
|
||||
return bt_test_suite_success;
|
||||
}
|
||||
|
||||
int
|
||||
@ -159,7 +169,8 @@ main(int argc, char *argv[])
|
||||
|
||||
bt_test_suite(t_ip4_pton, "Converting IPv4 string to ip4_addr struct");
|
||||
bt_test_suite(t_ip6_pton, "Converting IPv6 string to ip6_addr struct");
|
||||
bt_test_suite(t_ip4_ntop, "t_ip4_ntop");
|
||||
bt_test_suite(t_ip4_ntop, "Converting ip4_addr struct to IPv4 string");
|
||||
bt_test_suite(t_ip6_ntop, "Converting ip6_addr struct to IPv6 string");
|
||||
|
||||
return bt_end();
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ is_empty_list_well_unlinked(void)
|
||||
|
||||
bt_assert(l.head == NODE &l.null);
|
||||
bt_assert(l.tail == NODE &l.head);
|
||||
bt_assert(EMPTY_LIST(l));
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
{
|
||||
|
@ -40,15 +40,11 @@ compute_md5(const char *str, char (*out_hash)[MD5_CHARS+1])
|
||||
static int
|
||||
t_md5(void)
|
||||
{
|
||||
struct in_out_data_ {
|
||||
struct in_out {
|
||||
char *in;
|
||||
char out[MD5_CHARS+1];
|
||||
char fn_out[MD5_CHARS+1];
|
||||
} in_out_data[] = {
|
||||
{
|
||||
.in = "",
|
||||
.out = "d41d8cd98f00b204e9800998ecf8427e",
|
||||
},
|
||||
} in_out[] = {
|
||||
{
|
||||
.in = "",
|
||||
.out = "d41d8cd98f00b204e9800998ecf8427e",
|
||||
@ -79,7 +75,7 @@ t_md5(void)
|
||||
},
|
||||
};
|
||||
|
||||
bt_assert_fn_in_out(compute_md5, in_out_data, "\"%s\"", "\"%s\"");
|
||||
bt_assert_fn_in_out(compute_md5, in_out, "'%s'", "'%s'");
|
||||
|
||||
return BT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user