HelenOS sources
This source file includes following definitions.
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
#include <errno.h>
#include <inet/addr.h>
#include <pcut/pcut.h>
PCUT_INIT;
PCUT_TEST_SUITE(addr);
PCUT_TEST(inet_addr_parse_full)
{
errno_t rc;
inet_addr_t addr;
char *endptr;
rc = inet_addr_parse("1122:3344:5566:7788:99aa:bbcc:ddee:ff00/", &addr,
&endptr);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS('/', *endptr);
PCUT_ASSERT_INT_EQUALS(ip_v6, addr.version);
PCUT_ASSERT_INT_EQUALS(0x11, addr.addr6[0]);
PCUT_ASSERT_INT_EQUALS(0x22, addr.addr6[1]);
PCUT_ASSERT_INT_EQUALS(0x33, addr.addr6[2]);
PCUT_ASSERT_INT_EQUALS(0x44, addr.addr6[3]);
PCUT_ASSERT_INT_EQUALS(0x55, addr.addr6[4]);
PCUT_ASSERT_INT_EQUALS(0x66, addr.addr6[5]);
PCUT_ASSERT_INT_EQUALS(0x77, addr.addr6[6]);
PCUT_ASSERT_INT_EQUALS(0x88, addr.addr6[7]);
PCUT_ASSERT_INT_EQUALS(0x99, addr.addr6[8]);
PCUT_ASSERT_INT_EQUALS(0xaa, addr.addr6[9]);
PCUT_ASSERT_INT_EQUALS(0xbb, addr.addr6[10]);
PCUT_ASSERT_INT_EQUALS(0xcc, addr.addr6[11]);
PCUT_ASSERT_INT_EQUALS(0xdd, addr.addr6[12]);
PCUT_ASSERT_INT_EQUALS(0xee, addr.addr6[13]);
PCUT_ASSERT_INT_EQUALS(0xff, addr.addr6[14]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[15]);
}
PCUT_TEST(inet_addr_parse_shortgr)
{
errno_t rc;
inet_addr_t addr;
char *endptr;
rc = inet_addr_parse("1:22:333:4444:5:66:777:8888/", &addr,
&endptr);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS('/', *endptr);
PCUT_ASSERT_INT_EQUALS(ip_v6, addr.version);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[0]);
PCUT_ASSERT_INT_EQUALS(0x01, addr.addr6[1]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[2]);
PCUT_ASSERT_INT_EQUALS(0x22, addr.addr6[3]);
PCUT_ASSERT_INT_EQUALS(0x03, addr.addr6[4]);
PCUT_ASSERT_INT_EQUALS(0x33, addr.addr6[5]);
PCUT_ASSERT_INT_EQUALS(0x44, addr.addr6[6]);
PCUT_ASSERT_INT_EQUALS(0x44, addr.addr6[7]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[8]);
PCUT_ASSERT_INT_EQUALS(0x05, addr.addr6[9]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[10]);
PCUT_ASSERT_INT_EQUALS(0x66, addr.addr6[11]);
PCUT_ASSERT_INT_EQUALS(0x07, addr.addr6[12]);
PCUT_ASSERT_INT_EQUALS(0x77, addr.addr6[13]);
PCUT_ASSERT_INT_EQUALS(0x88, addr.addr6[14]);
PCUT_ASSERT_INT_EQUALS(0x88, addr.addr6[15]);
}
PCUT_TEST(inet_addr_parse_wcbegin)
{
errno_t rc;
inet_addr_t addr;
char *endptr;
rc = inet_addr_parse("::1234/", &addr, &endptr);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS('/', *endptr);
PCUT_ASSERT_INT_EQUALS(ip_v6, addr.version);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[0]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[1]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[2]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[3]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[4]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[5]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[6]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[7]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[8]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[9]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[10]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[11]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[12]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[13]);
PCUT_ASSERT_INT_EQUALS(0x12, addr.addr6[14]);
PCUT_ASSERT_INT_EQUALS(0x34, addr.addr6[15]);
}
PCUT_TEST(inet_addr_parse_wcmiddle)
{
errno_t rc;
inet_addr_t addr;
char *endptr;
rc = inet_addr_parse("1122:3344::5566/", &addr, &endptr);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS('/', *endptr);
PCUT_ASSERT_INT_EQUALS(ip_v6, addr.version);
PCUT_ASSERT_INT_EQUALS(0x11, addr.addr6[0]);
PCUT_ASSERT_INT_EQUALS(0x22, addr.addr6[1]);
PCUT_ASSERT_INT_EQUALS(0x33, addr.addr6[2]);
PCUT_ASSERT_INT_EQUALS(0x44, addr.addr6[3]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[4]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[5]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[6]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[7]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[8]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[9]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[10]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[11]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[12]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[13]);
PCUT_ASSERT_INT_EQUALS(0x55, addr.addr6[14]);
PCUT_ASSERT_INT_EQUALS(0x66, addr.addr6[15]);
}
PCUT_TEST(inet_addr_parse_wcend)
{
errno_t rc;
inet_addr_t addr;
char *endptr;
rc = inet_addr_parse("1234:5678::/", &addr, &endptr);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS('/', *endptr);
PCUT_ASSERT_INT_EQUALS(ip_v6, addr.version);
PCUT_ASSERT_INT_EQUALS(0x12, addr.addr6[0]);
PCUT_ASSERT_INT_EQUALS(0x34, addr.addr6[1]);
PCUT_ASSERT_INT_EQUALS(0x56, addr.addr6[2]);
PCUT_ASSERT_INT_EQUALS(0x78, addr.addr6[3]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[4]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[5]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[6]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[7]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[8]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[9]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[10]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[11]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[12]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[13]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[14]);
PCUT_ASSERT_INT_EQUALS(0x00, addr.addr6[15]);
}
PCUT_EXPORT(addr);
HelenOS homepage, sources at GitHub