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