blob: 143dfe6843ae36ad098bca9f3d7316ce1b5e5bc0 [file] [log] [blame]
Junxiao Shi2c29f3a2014-01-24 19:59:00 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi08d07a72014-06-09 23:17:57 -07003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 **/
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070025
26#include "face/face.hpp"
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080027#include "face/local-face.hpp"
Junxiao Shicbba04c2014-01-26 14:21:22 -070028#include "dummy-face.hpp"
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070029
Junxiao Shid9ee45c2014-02-27 15:38:11 -070030#include "tests/test-common.hpp"
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070031
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080032namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033namespace tests {
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070034
Junxiao Shid9ee45c2014-02-27 15:38:11 -070035BOOST_FIXTURE_TEST_SUITE(FaceFace, BaseFixture)
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070036
Junxiao Shi32bfeb32014-01-25 18:22:02 -070037BOOST_AUTO_TEST_CASE(Description)
38{
Junxiao Shi8c8d2182014-01-30 22:33:00 -070039 DummyFace face;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070040 face.setDescription("3pFsKrvWr");
41 BOOST_CHECK_EQUAL(face.getDescription(), "3pFsKrvWr");
42}
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070043
Junxiao Shi16b8bc92014-02-17 22:24:55 -070044BOOST_AUTO_TEST_CASE(LocalControlHeaderEnabled)
45{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080046 DummyLocalFace face;
Junxiao Shi6e694322014-04-03 10:27:13 -070047
Junxiao Shi16b8bc92014-02-17 22:24:55 -070048 BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(), false);
Junxiao Shi6e694322014-04-03 10:27:13 -070049
Steve DiBenedetto7564d972014-03-24 14:28:46 -060050 face.setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID, true);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070051 BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(), true);
Steve DiBenedetto7564d972014-03-24 14:28:46 -060052 BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID), true);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070053 BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(
Steve DiBenedetto7564d972014-03-24 14:28:46 -060054 LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID), false);
Junxiao Shi6e694322014-04-03 10:27:13 -070055
Steve DiBenedetto7564d972014-03-24 14:28:46 -060056 face.setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID, false);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070057 BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(), false);
58 BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(
Steve DiBenedetto7564d972014-03-24 14:28:46 -060059 LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID), false);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070060}
61
Junxiao Shi08d07a72014-06-09 23:17:57 -070062class FaceFailTestFace : public DummyFace
63{
64public:
65 FaceFailTestFace()
66 : failCount(0)
67 {
68 this->onFail += bind(&FaceFailTestFace::failHandler, this, _1);
69 }
70
71 void
72 failOnce()
73 {
74 this->fail("reason");
75 }
76
77private:
78 void
79 failHandler(const std::string& reason)
80 {
81 BOOST_CHECK_EQUAL(reason, "reason");
82 ++this->failCount;
83 }
84
85public:
86 int failCount;
87};
88
89BOOST_AUTO_TEST_CASE(FailTwice)
90{
91 FaceFailTestFace face;
92 BOOST_CHECK_EQUAL(face.failCount, 0);
93 face.failOnce();
94 BOOST_CHECK_EQUAL(face.failCount, 1);
95 face.failOnce();
96 BOOST_CHECK_EQUAL(face.failCount, 1);
97}
98
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070099BOOST_AUTO_TEST_SUITE_END()
100
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700101} // namespace tests
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800102} // namespace nfd