Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
| 7 | * |
| 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
| 19 | |
| 20 | #include "helper/ndn-face-container.hpp" |
| 21 | |
| 22 | #include "ns3/node-container.h" |
| 23 | #include "ns3/point-to-point-net-device.h" |
| 24 | #include "ns3/node.h" |
| 25 | #include "ns3/core-module.h" |
| 26 | #include "ns3/network-module.h" |
| 27 | #include "ns3/point-to-point-module.h" |
| 28 | #include "ns3/ndnSIM-module.h" |
| 29 | |
Alexander Afanasyev | 241df87 | 2015-08-13 17:26:15 -0700 | [diff] [blame] | 30 | #include "NFD/daemon/face/null-face.hpp" |
| 31 | |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 32 | #include "../tests-common.hpp" |
| 33 | |
| 34 | namespace ns3 { |
| 35 | namespace ndn { |
| 36 | |
| 37 | BOOST_FIXTURE_TEST_SUITE(HelperNdnFaceContainer, CleanupFixture) |
| 38 | |
Alexander Afanasyev | 241df87 | 2015-08-13 17:26:15 -0700 | [diff] [blame] | 39 | BOOST_AUTO_TEST_CASE(Basic) |
| 40 | { |
| 41 | FaceContainer c1; |
| 42 | BOOST_CHECK_EQUAL(c1.GetN(), 0); |
| 43 | |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 44 | c1.Add(nfd::face::makeNullFace(FaceUri("null://1"))); |
Alexander Afanasyev | 241df87 | 2015-08-13 17:26:15 -0700 | [diff] [blame] | 45 | BOOST_CHECK_EQUAL(c1.GetN(), 1); |
| 46 | |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 47 | c1.Add(nfd::face::makeNullFace(FaceUri("null://2"))); |
Alexander Afanasyev | 241df87 | 2015-08-13 17:26:15 -0700 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(c1.GetN(), 2); |
| 49 | |
| 50 | FaceContainer c2(c1); |
| 51 | BOOST_CHECK_EQUAL(c2.GetN(), c1.GetN()); |
| 52 | |
| 53 | FaceContainer c3; |
| 54 | BOOST_CHECK_EQUAL(c3.GetN(), 0); |
| 55 | |
| 56 | c3 = c1; |
| 57 | BOOST_CHECK_EQUAL(c3.GetN(), c1.GetN()); |
| 58 | |
| 59 | for (size_t i = 0; i < c1.GetN(); ++i) { |
| 60 | BOOST_CHECK_EQUAL(c1.Get(i)->getLocalUri(), c2.Get(i)->getLocalUri()); |
| 61 | BOOST_CHECK_EQUAL(c1.Get(i)->getLocalUri(), c3.Get(i)->getLocalUri()); |
| 62 | } |
| 63 | |
| 64 | size_t pos = 0; |
| 65 | for (FaceContainer::Iterator i = c1.Begin(); i != c1.End(); ++i, ++pos) { |
| 66 | BOOST_CHECK_EQUAL((*i)->getLocalUri(), c2.Get(pos)->getLocalUri()); |
| 67 | BOOST_CHECK_EQUAL((*i)->getLocalUri(), c3.Get(pos)->getLocalUri()); |
| 68 | } |
| 69 | } |
| 70 | |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 71 | BOOST_AUTO_TEST_CASE(AddAll) |
| 72 | { |
Alexander Afanasyev | 241df87 | 2015-08-13 17:26:15 -0700 | [diff] [blame] | 73 | FaceContainer c1; |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 74 | c1.Add(nfd::face::makeNullFace(FaceUri("null://1"))); |
| 75 | c1.Add(nfd::face::makeNullFace(FaceUri("null://2"))); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 76 | |
Alexander Afanasyev | 241df87 | 2015-08-13 17:26:15 -0700 | [diff] [blame] | 77 | FaceContainer c2(c1); |
| 78 | c2.AddAll(c1); |
| 79 | BOOST_CHECK_EQUAL(c2.GetN(), 4); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 80 | |
Alexander Afanasyev | 241df87 | 2015-08-13 17:26:15 -0700 | [diff] [blame] | 81 | FaceContainer c3(c1); |
| 82 | c3.AddAll(c3); |
| 83 | BOOST_CHECK_EQUAL(c3.GetN(), 4); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 241df87 | 2015-08-13 17:26:15 -0700 | [diff] [blame] | 85 | Ptr<FaceContainer> c4 = Create<FaceContainer>(c1); |
| 86 | c4->AddAll(c4); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 241df87 | 2015-08-13 17:26:15 -0700 | [diff] [blame] | 88 | BOOST_CHECK_EQUAL_COLLECTIONS(c2.Begin(), c2.Begin() + c1.GetN(), |
| 89 | c1.Begin(), c1.End()); |
| 90 | |
| 91 | BOOST_CHECK_EQUAL_COLLECTIONS(c2.Begin() + c1.GetN(), c2.End(), |
| 92 | c1.Begin(), c1.End()); |
| 93 | |
| 94 | BOOST_CHECK_EQUAL_COLLECTIONS(c2.Begin(), c2.End(), c3.Begin(), c3.End()); |
| 95 | BOOST_CHECK_EQUAL_COLLECTIONS(c2.Begin(), c2.End(), c4->Begin(), c4->End()); |
Yuanzhi Gao | dd516fe | 2015-04-23 04:18:24 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | BOOST_AUTO_TEST_SUITE_END() |
| 99 | |
| 100 | } // namespace ndn |
| 101 | } // namespace ns3 |