blob: 67c5add12fc09aff630fe9328a989bec74de9e9e [file] [log] [blame]
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08001/**
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 Afanasyev09c613f2014-01-29 00:23:58 -08008#include "face.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08009
10using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080011namespace ndn {
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080012
13BOOST_AUTO_TEST_SUITE(TestFaces)
14
15struct 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
49BOOST_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
72BOOST_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
95BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080096
97} // namespace ndn