blob: 498ca7335ab1fcbed22c9718928eeb56c624b219 [file] [log] [blame]
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08003 * See COPYING for copyright and distribution information.
4 */
5
6#include <boost/test/unit_test.hpp>
Alexander Afanasyev09c613f2014-01-29 00:23:58 -08007#include "face.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08008
9using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080010namespace ndn {
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080011
12BOOST_AUTO_TEST_SUITE(TestFaces)
13
14struct 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
48BOOST_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
71BOOST_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
94BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080095
96} // namespace ndn