address_ut.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include "address.h"
  3. using namespace NAddr;
  4. Y_UNIT_TEST_SUITE(IRemoteAddr_ToString) {
  5. Y_UNIT_TEST(Raw) {
  6. THolder<TOpaqueAddr> opaque(new TOpaqueAddr);
  7. IRemoteAddr* addr = opaque.Get();
  8. TString s = ToString(*addr);
  9. UNIT_ASSERT_VALUES_EQUAL("(raw all zeros)", s);
  10. opaque->MutableAddr()->sa_data[10] = 17;
  11. TString t = ToString(*addr);
  12. UNIT_ASSERT_C(t.StartsWith("(raw 0 0"), t);
  13. UNIT_ASSERT_C(t.EndsWith(')'), t);
  14. }
  15. Y_UNIT_TEST(Ipv6) {
  16. TNetworkAddress address("::1", 22);
  17. TNetworkAddress::TIterator it = address.Begin();
  18. UNIT_ASSERT(it != address.End());
  19. UNIT_ASSERT(it->ai_family == AF_INET6);
  20. TString toString = ToString((const IRemoteAddr&)TAddrInfo(&*it));
  21. UNIT_ASSERT_VALUES_EQUAL(TString("[::1]:22"), toString);
  22. }
  23. Y_UNIT_TEST(Loopback) {
  24. TNetworkAddress localAddress("127.70.0.1", 22);
  25. UNIT_ASSERT_VALUES_EQUAL(NAddr::IsLoopback(TAddrInfo(&*localAddress.Begin())), true);
  26. TNetworkAddress localAddress2("127.0.0.1", 22);
  27. UNIT_ASSERT_VALUES_EQUAL(NAddr::IsLoopback(TAddrInfo(&*localAddress2.Begin())), true);
  28. }
  29. } // Y_UNIT_TEST_SUITE(IRemoteAddr_ToString)