You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2013/07/09 21:36:45 UTC

git commit: Add initial ink_inet regression tests

Updated Branches:
  refs/heads/master 181e224f7 -> 6cdbf78f3


Add initial ink_inet regression tests


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/6cdbf78f
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/6cdbf78f
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/6cdbf78f

Branch: refs/heads/master
Commit: 6cdbf78f30b7cf5e44fce518a92c3279376dc1f5
Parents: 181e224
Author: James Peach <jp...@apache.org>
Authored: Tue Jul 9 13:31:56 2013 -0600
Committer: James Peach <jp...@apache.org>
Committed: Tue Jul 9 13:36:31 2013 -0600

----------------------------------------------------------------------
 lib/ts/ink_inet.cc | 24 ++++++++++++++++++++++++
 lib/ts/ink_inet.h  |  3 +++
 2 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6cdbf78f/lib/ts/ink_inet.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_inet.cc b/lib/ts/ink_inet.cc
index dffe53f..8948b91 100644
--- a/lib/ts/ink_inet.cc
+++ b/lib/ts/ink_inet.cc
@@ -22,6 +22,7 @@
  */
 
 #include "libts.h"
+#include "ts/TestBox.h"
 
 #if defined(darwin)
 extern "C"
@@ -469,3 +470,26 @@ ats_ip_check_characters(ts::ConstBuffer text) {
     : AF_INET
     ;
 }
+
+REGRESSION_TEST(Ink_Inet) (RegressionTest * t, int /* atype */, int * pstatus) {
+  TestBox box(t, pstatus);
+  IpEndpoint  ep;
+  IpAddr      addr;
+
+  box = REGRESSION_TEST_PASSED;
+
+  box.check(ats_ip_pton("76.14.64.156", &ep.sa) == 0, "ats_ip_pton()");
+  box.check(addr.load("76.14.64.156") == 0, "IpAddr::load()");
+  box.check(addr.family() == ep.family(), "mismatched address family");
+
+  switch (addr.family()) {
+  case AF_INET:
+    box.check(ep.sin.sin_addr.s_addr == addr._addr._ip4, "IPv4 address mismatch");
+    break;
+  case AF_INET6:
+    box.check(memcmp(&ep.sin6.sin6_addr, &addr._addr._ip6, sizeof(in6_addr)) == 0, "IPv6 address mismatch");
+    break;
+  default:
+    ;
+  }
+}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6cdbf78f/lib/ts/ink_inet.h
----------------------------------------------------------------------
diff --git a/lib/ts/ink_inet.h b/lib/ts/ink_inet.h
index 52c64f1..760c89c 100644
--- a/lib/ts/ink_inet.h
+++ b/lib/ts/ink_inet.h
@@ -85,6 +85,8 @@ union IpEndpoint {
   /// Test for IPv6.
   bool isIp6() const;
 
+  uint16_t family() const;
+
   /// Set to be any address for family @a family.
   /// @a family must be @c AF_INET or @c AF_INET6.
   /// @return This object.
@@ -1210,6 +1212,7 @@ IpEndpoint::isValid() const {
 
 inline bool IpEndpoint::isIp4() const { return AF_INET == sa.sa_family; }
 inline bool IpEndpoint::isIp6() const { return AF_INET6 == sa.sa_family; }
+inline uint16_t IpEndpoint::family() const { return sa.sa_family; }
 
 inline IpEndpoint&
 IpEndpoint::setToAnyAddr(int family) {