mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-23 02:01:55 +00:00
Birdtest: Add IP addr funcs Tests (not complete)
This commit is contained in:
parent
89ee134e2f
commit
9a49b70d1b
79
lib/ip_test.c
Normal file
79
lib/ip_test.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* BIRD Library -- IP address functions Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "test/birdtest_support.h" /* REMOVE ME */
|
||||
|
||||
#include "lib/ip.h"
|
||||
|
||||
static u32
|
||||
build_ip4(u8 a, u8 b, u8 c, u8 d)
|
||||
{
|
||||
return ((u32)a << 24) + ((u32)b << 16) + ((u32)c << 8) + (u32)d;
|
||||
}
|
||||
|
||||
static u32
|
||||
ip4_pton_(char* s)
|
||||
{
|
||||
ip4_addr ip;
|
||||
ip4_pton(s,&ip);
|
||||
return ip.addr;
|
||||
}
|
||||
|
||||
static int
|
||||
t_ip4_pton(void)
|
||||
{
|
||||
struct in_out_data_ {
|
||||
char *in;
|
||||
u32 out;
|
||||
} in_out_data[] = {
|
||||
{
|
||||
.in = "192.168.1.128",
|
||||
.out = build_ip4(192, 168, 1, 128),
|
||||
},
|
||||
{
|
||||
.in = "255.255.255.255",
|
||||
.out = build_ip4(255, 255, 255, 255),
|
||||
},
|
||||
{
|
||||
.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_check(ip4_pton_, in_out_data, "%s", "0x%08X");
|
||||
|
||||
return BT_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_case(t_ip4_pton, "Converting IPv4 string to IPv4 ip4_addr struct");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user