Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include <boost/test/unit_test.hpp> |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 7 | #include "face.hpp" |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 8 | |
| 9 | using namespace std; |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 10 | namespace ndn { |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 11 | |
| 12 | BOOST_AUTO_TEST_SUITE(TestFaces) |
| 13 | |
| 14 | struct FacesFixture |
| 15 | { |
| 16 | FacesFixture() |
| 17 | : dataCount(0) |
| 18 | , timeoutCount(0) |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | void |
| 23 | onData() |
| 24 | { |
| 25 | ++dataCount; |
| 26 | } |
| 27 | |
| 28 | void |
| 29 | onTimeout() |
| 30 | { |
| 31 | ++timeoutCount; |
| 32 | } |
| 33 | |
| 34 | void |
| 35 | onInterest() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | onRegFailed() |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | uint32_t dataCount; |
| 45 | uint32_t timeoutCount; |
| 46 | }; |
| 47 | |
| 48 | BOOST_FIXTURE_TEST_CASE (Unix, FacesFixture) |
| 49 | { |
| 50 | Face face; |
| 51 | |
| 52 | face.expressInterest(Interest("/%C1.M.S.localhost/%C1.M.SRV/ndnd/KEY", 1000), |
| 53 | ptr_lib::bind(&FacesFixture::onData, this), |
| 54 | ptr_lib::bind(&FacesFixture::onTimeout, this)); |
| 55 | |
| 56 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 57 | |
| 58 | BOOST_CHECK_EQUAL(dataCount, 1); |
| 59 | BOOST_CHECK_EQUAL(timeoutCount, 0); |
| 60 | |
| 61 | face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere", 50), |
| 62 | ptr_lib::bind(&FacesFixture::onData, this), |
| 63 | ptr_lib::bind(&FacesFixture::onTimeout, this)); |
| 64 | |
| 65 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 66 | |
| 67 | BOOST_CHECK_EQUAL(dataCount, 1); |
| 68 | BOOST_CHECK_EQUAL(timeoutCount, 1); |
| 69 | } |
| 70 | |
| 71 | BOOST_FIXTURE_TEST_CASE (Tcp, FacesFixture) |
| 72 | { |
| 73 | Face face("localhost"); |
| 74 | |
| 75 | face.expressInterest(Interest("/%C1.M.S.localhost/%C1.M.SRV/ndnd/KEY", 1000), |
| 76 | ptr_lib::bind(&FacesFixture::onData, this), |
| 77 | ptr_lib::bind(&FacesFixture::onTimeout, this)); |
| 78 | |
| 79 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 80 | |
| 81 | BOOST_CHECK_EQUAL(dataCount, 1); |
| 82 | BOOST_CHECK_EQUAL(timeoutCount, 0); |
| 83 | |
| 84 | face.expressInterest(Interest("/localhost/non-existing/data/should/not/exist/anywhere", 50), |
| 85 | ptr_lib::bind(&FacesFixture::onData, this), |
| 86 | ptr_lib::bind(&FacesFixture::onTimeout, this)); |
| 87 | |
| 88 | BOOST_REQUIRE_NO_THROW(face.processEvents()); |
| 89 | |
| 90 | BOOST_CHECK_EQUAL(dataCount, 1); |
| 91 | BOOST_CHECK_EQUAL(timeoutCount, 1); |
| 92 | } |
| 93 | |
| 94 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 95 | |
| 96 | } // namespace ndn |