blob: 4129cbc3048f4092410f518f3c3ca8d31cb00f4c [file] [log] [blame]
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -07001/* -*- 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 Afanasyev241df872015-08-13 17:26:15 -070030#include "NFD/daemon/face/null-face.hpp"
31
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070032#include "../tests-common.hpp"
33
34namespace ns3 {
35namespace ndn {
36
37BOOST_FIXTURE_TEST_SUITE(HelperNdnFaceContainer, CleanupFixture)
38
Alexander Afanasyev241df872015-08-13 17:26:15 -070039BOOST_AUTO_TEST_CASE(Basic)
40{
41 FaceContainer c1;
42 BOOST_CHECK_EQUAL(c1.GetN(), 0);
43
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -070044 c1.Add(nfd::face::makeNullFace(FaceUri("null://1")));
Alexander Afanasyev241df872015-08-13 17:26:15 -070045 BOOST_CHECK_EQUAL(c1.GetN(), 1);
46
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -070047 c1.Add(nfd::face::makeNullFace(FaceUri("null://2")));
Alexander Afanasyev241df872015-08-13 17:26:15 -070048 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 Gaodd516fe2015-04-23 04:18:24 -070071BOOST_AUTO_TEST_CASE(AddAll)
72{
Alexander Afanasyev241df872015-08-13 17:26:15 -070073 FaceContainer c1;
Alexander Afanasyevca3c67e2016-09-08 15:48:23 -070074 c1.Add(nfd::face::makeNullFace(FaceUri("null://1")));
75 c1.Add(nfd::face::makeNullFace(FaceUri("null://2")));
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070076
Alexander Afanasyev241df872015-08-13 17:26:15 -070077 FaceContainer c2(c1);
78 c2.AddAll(c1);
79 BOOST_CHECK_EQUAL(c2.GetN(), 4);
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070080
Alexander Afanasyev241df872015-08-13 17:26:15 -070081 FaceContainer c3(c1);
82 c3.AddAll(c3);
83 BOOST_CHECK_EQUAL(c3.GetN(), 4);
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070084
Alexander Afanasyev241df872015-08-13 17:26:15 -070085 Ptr<FaceContainer> c4 = Create<FaceContainer>(c1);
86 c4->AddAll(c4);
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070087
Alexander Afanasyev241df872015-08-13 17:26:15 -070088 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 Gaodd516fe2015-04-23 04:18:24 -070096}
97
98BOOST_AUTO_TEST_SUITE_END()
99
100} // namespace ndn
101} // namespace ns3