#include <gtest/gtest.h>
#include <iostream>
using std::cout;
using std::endl;
TEST(inetaddr_test, Bad_addr)
{
InetAddr sa;
ASSERT_ANY_THROW(sa.host("deadbeef"));
}
TEST(inetaddr_test, init_addr)
{
InetAddr sa;
cout << sa << endl;
ASSERT_EQ(sa.host(), "::");
ASSERT_EQ(sa.port(), 0);
ASSERT_EQ(sa.scope_id(), 0);
}
TEST(inetaddr_test, any_addrs)
{
InetAddr sa;
sa.host("::ffff:0.0.0.0");
cout << sa << endl;
ASSERT_EQ(sa.host(), "::ffff:0.0.0.0");
sa = InetAddr();
sa.host("::");
cout << sa << endl;
ASSERT_EQ(sa.host(), "::");
}
TEST(inetaddr_test, loop_addrs)
{
InetAddr sa;
sa.host("::ffff:127.0.0.1");
cout << sa << endl;
ASSERT_EQ(sa.host(), "::ffff:127.0.0.1");
sa = InetAddr();
sa.host("::1");
cout << sa << endl;
ASSERT_EQ(sa.host(), "::1");
}
TEST(inetaddr_test, unicast_global)
{
InetAddr sa;
sa.host("::ffff:192.168.12.24");
cout << sa << endl;
ASSERT_EQ(sa.host(), "::ffff:192.168.12.24");
sa = InetAddr();
sa.host("dead::beef:feed");
cout << sa << endl;
ASSERT_EQ(sa.host(), "dead::beef:feed");
}
TEST(inetaddr_test, unicast_link)
{
InetAddr sa;
sa.host("fe80::dead:beef");
cout << sa << endl;
ASSERT_EQ(sa.host(),"fe80::dead:beef");
}
TEST(inetaddr_test, unicast_site)
{
InetAddr sa;
sa.host("fd00::dead:beef");
cout << sa << endl;
ASSERT_EQ(sa.host(),"fd00::dead:beef");
}
TEST(inetaddr_test, multicast_ipv4)
{
InetAddr sa;
sa.host("::ffff:224.1.2.3");
cout << sa << endl;
sa = InetAddr();
sa.host("::ffff:239.1.2.3");
cout << sa << endl;
sa = InetAddr();
sa.host("::ffff:223.1.2.3");
cout << sa << endl;
sa = InetAddr();
sa.host("::ffff:240.1.2.3");
cout << sa << endl;
}
TEST(inetaddr_test, multicast_ipv6)
{
InetAddr sa;
sa.host("ff01::1");
cout << sa << endl;
sa = InetAddr();
sa.host("ff02::1");
cout << sa << endl;
sa = InetAddr();
sa.host("ff01::2");
cout << sa << endl;
sa = InetAddr();
sa.host("ff02::2");
cout << sa << endl;
sa = InetAddr();
sa.host("ff05::2");
cout << sa << endl;
sa = InetAddr();
sa.host("ff18::dead:beef");
cout << sa << endl;
sa.host("ff03::dead:beef");
cout << sa << endl;
}
InetAddrFlag
Internet address flags.
@ unicast
Unicast address.
@ link_local
Traffic is restricted to the local link.
@ realm_local
Traffic is restricted to the local realm.
@ mcast_all_nodes
Reaches all nodes in the scope, e.g. ff0X::1.
@ global
Global traffic is allowed.
@ org_local
Traffic is restricted to the local organization.
@ mcast_all_routers
Reaches all routers in the scope, e.g. ff0X::2.
@ loopback
Loopback address.
@ if_local
Traffic is restricted to the local interface.
@ mcast_dynamic
Dynamic (temporary) address, otherwise permanent (assigned).
@ site_local
Traffic is restricted to the local site.
@ multicast
Multicast address.
@ unique_local_address
Address which can be used freely within a site: e.g. fd00::/8.
Internet tcp and udp networking.
TEST(inet_example, client_server_stream_test)
[Inet client server]