Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame^] | 3 | * 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 25 | |
| 26 | #include "face/face.hpp" |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 27 | #include "face/local-face.hpp" |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 28 | #include "dummy-face.hpp" |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 29 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 30 | #include "tests/test-common.hpp" |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 32 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | namespace tests { |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 35 | BOOST_FIXTURE_TEST_SUITE(FaceFace, BaseFixture) |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 36 | |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 37 | BOOST_AUTO_TEST_CASE(Description) |
| 38 | { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 39 | DummyFace face; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 40 | face.setDescription("3pFsKrvWr"); |
| 41 | BOOST_CHECK_EQUAL(face.getDescription(), "3pFsKrvWr"); |
| 42 | } |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 43 | |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 44 | BOOST_AUTO_TEST_CASE(LocalControlHeaderEnabled) |
| 45 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 46 | DummyLocalFace face; |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 47 | |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(), false); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 49 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 50 | face.setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID, true); |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(), true); |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID), true); |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled( |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 54 | LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID), false); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 55 | |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 56 | face.setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID, false); |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 57 | BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled(), false); |
| 58 | BOOST_CHECK_EQUAL(face.isLocalControlHeaderEnabled( |
Steve DiBenedetto | 7564d97 | 2014-03-24 14:28:46 -0600 | [diff] [blame] | 59 | LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID), false); |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Junxiao Shi | 7860d48 | 2014-02-21 23:57:20 -0700 | [diff] [blame] | 62 | BOOST_AUTO_TEST_CASE(Counters) |
| 63 | { |
| 64 | DummyFace face; |
| 65 | const FaceCounters& counters = face.getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 66 | BOOST_CHECK_EQUAL(counters.getNInInterests() , 0); |
| 67 | BOOST_CHECK_EQUAL(counters.getNInDatas() , 0); |
| 68 | BOOST_CHECK_EQUAL(counters.getNOutInterests(), 0); |
| 69 | BOOST_CHECK_EQUAL(counters.getNOutDatas() , 0); |
Junxiao Shi | 7860d48 | 2014-02-21 23:57:20 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame^] | 72 | class FaceFailTestFace : public DummyFace |
| 73 | { |
| 74 | public: |
| 75 | FaceFailTestFace() |
| 76 | : failCount(0) |
| 77 | { |
| 78 | this->onFail += bind(&FaceFailTestFace::failHandler, this, _1); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | failOnce() |
| 83 | { |
| 84 | this->fail("reason"); |
| 85 | } |
| 86 | |
| 87 | private: |
| 88 | void |
| 89 | failHandler(const std::string& reason) |
| 90 | { |
| 91 | BOOST_CHECK_EQUAL(reason, "reason"); |
| 92 | ++this->failCount; |
| 93 | } |
| 94 | |
| 95 | public: |
| 96 | int failCount; |
| 97 | }; |
| 98 | |
| 99 | BOOST_AUTO_TEST_CASE(FailTwice) |
| 100 | { |
| 101 | FaceFailTestFace face; |
| 102 | BOOST_CHECK_EQUAL(face.failCount, 0); |
| 103 | face.failOnce(); |
| 104 | BOOST_CHECK_EQUAL(face.failCount, 1); |
| 105 | face.failOnce(); |
| 106 | BOOST_CHECK_EQUAL(face.failCount, 1); |
| 107 | } |
| 108 | |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 109 | BOOST_AUTO_TEST_SUITE_END() |
| 110 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 111 | } // namespace tests |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 112 | } // namespace nfd |