faces: Channel base class

refs #1261

Change-Id: If17037c4802cb6ccec0201c3bff7fc4b6db41c6a
diff --git a/tests/core/face-uri.cpp b/tests/core/face-uri.cpp
index 0b6a633..7eb9b62 100644
--- a/tests/core/face-uri.cpp
+++ b/tests/core/face-uri.cpp
@@ -24,32 +24,44 @@
   
   BOOST_CHECK(uri.parse("udp://hostname:80"));
   BOOST_CHECK_EQUAL(uri.getScheme(), "udp");
-  BOOST_CHECK_EQUAL(uri.getDomain(), "hostname");
+  BOOST_CHECK_EQUAL(uri.getHost(), "hostname");
   BOOST_CHECK_EQUAL(uri.getPort(), "80");
+  BOOST_CHECK_EQUAL(uri.getPath(), "");
 
   BOOST_CHECK(uri.parse("udp4://192.0.2.1:20"));
   BOOST_CHECK_EQUAL(uri.getScheme(), "udp4");
-  BOOST_CHECK_EQUAL(uri.getDomain(), "192.0.2.1");
+  BOOST_CHECK_EQUAL(uri.getHost(), "192.0.2.1");
   BOOST_CHECK_EQUAL(uri.getPort(), "20");
+  BOOST_CHECK_EQUAL(uri.getPath(), "");
 
   BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0::1]:6363"));
   BOOST_CHECK_EQUAL(uri.getScheme(), "udp6");
-  BOOST_CHECK_EQUAL(uri.getDomain(), "2001:db8:3f9:0::1");
+  BOOST_CHECK_EQUAL(uri.getHost(), "2001:db8:3f9:0::1");
   BOOST_CHECK_EQUAL(uri.getPort(), "6363");
+  BOOST_CHECK_EQUAL(uri.getPath(), "");
   
   BOOST_CHECK(uri.parse("udp6://[2001:db8:3f9:0:3025:ccc5:eeeb:86d3]:6363"));
   BOOST_CHECK_EQUAL(uri.getScheme(), "udp6");
-  BOOST_CHECK_EQUAL(uri.getDomain(), "2001:db8:3f9:0:3025:ccc5:eeeb:86d3");
+  BOOST_CHECK_EQUAL(uri.getHost(), "2001:db8:3f9:0:3025:ccc5:eeeb:86d3");
   BOOST_CHECK_EQUAL(uri.getPort(), "6363");
+  BOOST_CHECK_EQUAL(uri.getPath(), "");
 
   BOOST_CHECK(uri.parse("tcp://random.host.name"));
   BOOST_CHECK_EQUAL(uri.getScheme(), "tcp");
-  BOOST_CHECK_EQUAL(uri.getDomain(), "random.host.name");
+  BOOST_CHECK_EQUAL(uri.getHost(), "random.host.name");
   BOOST_CHECK_EQUAL(uri.getPort(), "");
+  BOOST_CHECK_EQUAL(uri.getPath(), "");
+
+  BOOST_CHECK(uri.parse("unix:///var/run/example.sock"));
+  BOOST_CHECK_EQUAL(uri.getScheme(), "unix");
+  BOOST_CHECK_EQUAL(uri.getHost(), "");
+  BOOST_CHECK_EQUAL(uri.getPort(), "");
+  BOOST_CHECK_EQUAL(uri.getPath(), "/var/run/example.sock");
 
   BOOST_CHECK_EQUAL(uri.parse("tcp://192.0.2.1:"), false);
   BOOST_CHECK_EQUAL(uri.parse("tcp://[::zzzz]"), false);
   BOOST_CHECK_EQUAL(uri.parse("udp6://[2001:db8:3f9:0:3025:ccc5:eeeb:86dg]:6363"), false);  
+  BOOST_CHECK_EQUAL(uri.getPath(), "");
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/face/tcp.cpp b/tests/face/tcp.cpp
index 2be6331..9223283 100644
--- a/tests/face/tcp.cpp
+++ b/tests/face/tcp.cpp
@@ -22,9 +22,14 @@
   shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
   shared_ptr<TcpChannel> channel1a = factory.createChannel("127.0.0.1", "20070");
   BOOST_CHECK_EQUAL(channel1, channel1a);
+  BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070");
 
   shared_ptr<TcpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
   BOOST_CHECK_NE(channel1, channel2);
+
+  shared_ptr<TcpChannel> channel3 = factory.createChannel("::1", "20071");
+  BOOST_CHECK_NE(channel2, channel3);
+  BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071");
 }
 
 class EndToEndFixture : protected BaseFixture
diff --git a/tests/face/udp.cpp b/tests/face/udp.cpp
index 12c9eb3..f877e2f 100644
--- a/tests/face/udp.cpp
+++ b/tests/face/udp.cpp
@@ -57,12 +57,17 @@
   shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
   shared_ptr<UdpChannel> channel1a = factory.createChannel("127.0.0.1", "20070");
   BOOST_CHECK_EQUAL(channel1, channel1a);
+  BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070");
 
   shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
   BOOST_CHECK_NE(channel1, channel2);
 
   shared_ptr<UdpChannel> channel3 = factory.createChannel(interfaceIp, "20070");
 
+  shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20071");
+  BOOST_CHECK_NE(channel2, channel4);
+  BOOST_CHECK_EQUAL(channel4->getUri().toString(), "udp6://[::1]:20071");
+
   //same endpoint of a unicast channel
   BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp,
                                                     "224.0.0.1",
@@ -162,7 +167,7 @@
 {
 public:
   void
-  channel1_onFaceCreated(const shared_ptr<UdpFace>& newFace)
+  channel1_onFaceCreated(const shared_ptr<Face>& newFace)
   {
     BOOST_CHECK(!static_cast<bool>(m_face1));
     m_face1 = newFace;
@@ -271,7 +276,7 @@
 
 
   void
-  channel_onFaceCreated(const shared_ptr<UdpFace>& newFace)
+  channel_onFaceCreated(const shared_ptr<Face>& newFace)
   {
     m_faces.push_back(newFace);
     m_limitedIo.afterOp();
diff --git a/tests/face/unix-stream.cpp b/tests/face/unix-stream.cpp
index d143251..921c1ff 100644
--- a/tests/face/unix-stream.cpp
+++ b/tests/face/unix-stream.cpp
@@ -15,17 +15,24 @@
 
 using namespace boost::asio::local;
 
+#define CHANNEL_PATH1 "unix-stream-test.1.sock"
+#define CHANNEL_PATH2 "unix-stream-test.2.sock"
+
 BOOST_FIXTURE_TEST_SUITE(FaceUnixStream, BaseFixture)
 
 BOOST_AUTO_TEST_CASE(ChannelMap)
 {
   UnixStreamFactory factory;
 
-  shared_ptr<UnixStreamChannel> channel1 = factory.createChannel("foo");
-  shared_ptr<UnixStreamChannel> channel1a = factory.createChannel("foo");
+  shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
+  shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1);
   BOOST_CHECK_EQUAL(channel1, channel1a);
+  std::string channel1uri = channel1->getUri().toString();
+  BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator
+  BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1),
+                    channel1uri.size() - std::string(CHANNEL_PATH1).size());
 
-  shared_ptr<UnixStreamChannel> channel2 = factory.createChannel("bar");
+  shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2);
   BOOST_CHECK_NE(channel1, channel2);
 }
 
@@ -41,10 +48,10 @@
   }
 
   void
-  channel1_onFaceCreated(const shared_ptr<UnixStreamFace>& newFace)
+  channel1_onFaceCreated(const shared_ptr<Face>& newFace)
   {
     BOOST_CHECK(!static_cast<bool>(m_face1));
-    m_face1 = newFace;
+    m_face1 = static_pointer_cast<UnixStreamFace>(newFace);
     m_face1->onReceiveInterest +=
       bind(&EndToEndFixture::face1_onReceiveInterest, this, _1);
     m_face1->onReceiveData +=
@@ -94,9 +101,9 @@
   }
 
   void
-  channel_onFaceCreated(const shared_ptr<UnixStreamFace>& newFace)
+  channel_onFaceCreated(const shared_ptr<Face>& newFace)
   {
-    m_faces.push_back(newFace);
+    m_faces.push_back(static_pointer_cast<UnixStreamFace>(newFace));
 
     m_limitedIo.afterOp();
   }
@@ -127,13 +134,13 @@
 {
   UnixStreamFactory factory;
 
-  shared_ptr<UnixStreamChannel> channel1 = factory.createChannel("foo");
+  shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
   channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated,   this, _1),
                    bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
 
   shared_ptr<stream_protocol::socket> client =
       make_shared<stream_protocol::socket>(boost::ref(g_io));
-  client->async_connect(stream_protocol::endpoint("foo"),
+  client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
                         bind(&EndToEndFixture::client_onConnect, this, _1));
 
   BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
@@ -184,13 +191,13 @@
 {
   UnixStreamFactory factory;
 
-  shared_ptr<UnixStreamChannel> channel = factory.createChannel("foo");
+  shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1);
   channel->listen(bind(&EndToEndFixture::channel_onFaceCreated,   this, _1),
                   bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
 
   shared_ptr<stream_protocol::socket> client1 =
       make_shared<stream_protocol::socket>(boost::ref(g_io));
-  client1->async_connect(stream_protocol::endpoint("foo"),
+  client1->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
                          bind(&EndToEndFixture::client_onConnect, this, _1));
 
   BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
@@ -200,7 +207,7 @@
 
   shared_ptr<stream_protocol::socket> client2 =
       make_shared<stream_protocol::socket>(boost::ref(g_io));
-  client2->async_connect(stream_protocol::endpoint("foo"),
+  client2->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
                          bind(&EndToEndFixture::client_onConnect, this, _1));
 
   BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
@@ -266,13 +273,13 @@
 {
   UnixStreamFactory factory;
 
-  shared_ptr<UnixStreamChannel> channel1 = factory.createChannel("foo");
+  shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
   channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated,   this, _1),
                    bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
 
   shared_ptr<stream_protocol::socket> client =
       make_shared<stream_protocol::socket>(boost::ref(g_io));
-  client->async_connect(stream_protocol::endpoint("foo"),
+  client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
                         bind(&EndToEndFixture::client_onConnect, this, _1));
 
   BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,