blob: 474a75644841aad1c747fc6ca9d06786108c0e0d [file] [log] [blame]
Junxiao Shia4f2be82014-03-02 22:56:41 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "fw/face-table.hpp"
8#include "fw/forwarder.hpp"
9
10#include "tests/test-common.hpp"
11#include "tests/face/dummy-face.hpp"
12
13namespace nfd {
14namespace tests {
15
16BOOST_FIXTURE_TEST_SUITE(FwFaceTable, BaseFixture)
17
18BOOST_AUTO_TEST_CASE(AddRemove)
19{
20 Forwarder forwarder;
21
22 shared_ptr<Face> face1 = make_shared<DummyFace>();
23 shared_ptr<Face> face2 = make_shared<DummyFace>();
24
25 BOOST_CHECK_EQUAL(face1->getId(), INVALID_FACEID);
26 BOOST_CHECK_EQUAL(face2->getId(), INVALID_FACEID);
27
28 forwarder.addFace(face1);
29 forwarder.addFace(face2);
30
31 BOOST_CHECK_NE(face1->getId(), INVALID_FACEID);
32 BOOST_CHECK_NE(face2->getId(), INVALID_FACEID);
33 BOOST_CHECK_NE(face1->getId(), face2->getId());
34
35 forwarder.removeFace(face1);
36 forwarder.removeFace(face2);
37
38 BOOST_CHECK_EQUAL(face1->getId(), INVALID_FACEID);
39 BOOST_CHECK_EQUAL(face2->getId(), INVALID_FACEID);
40}
41
42BOOST_AUTO_TEST_CASE(Enumerate)
43{
44 Forwarder forwarder;
45 FaceTable& faceTable = forwarder.getFaceTable();
46
47 shared_ptr<Face> face1 = make_shared<DummyFace>();
48 shared_ptr<Face> face2 = make_shared<DummyFace>();
49 bool hasFace1 = false, hasFace2 = false;
50
51 BOOST_CHECK_EQUAL(faceTable.size(), 0);
52 BOOST_CHECK_EQUAL(std::distance(faceTable.begin(), faceTable.end()), faceTable.size());
53
54 faceTable.add(face1);
55 BOOST_CHECK_EQUAL(faceTable.size(), 1);
56 BOOST_CHECK_EQUAL(std::distance(faceTable.begin(), faceTable.end()), faceTable.size());
57 hasFace1 = hasFace2 = false;
58 for (FaceTable::const_iterator it = faceTable.begin(); it != faceTable.end(); ++it) {
59 if (*it == face1) {
60 hasFace1 = true;
61 }
62 }
63 BOOST_CHECK(hasFace1);
64
65 faceTable.add(face2);
66 BOOST_CHECK_EQUAL(faceTable.size(), 2);
67 BOOST_CHECK_EQUAL(std::distance(faceTable.begin(), faceTable.end()), faceTable.size());
68 hasFace1 = hasFace2 = false;
69 for (FaceTable::const_iterator it = faceTable.begin(); it != faceTable.end(); ++it) {
70 if (*it == face1) {
71 hasFace1 = true;
72 }
73 if (*it == face2) {
74 hasFace2 = true;
75 }
76 }
77 BOOST_CHECK(hasFace1);
78 BOOST_CHECK(hasFace2);
79
80 faceTable.remove(face1);
81 BOOST_CHECK_EQUAL(faceTable.size(), 1);
82 BOOST_CHECK_EQUAL(std::distance(faceTable.begin(), faceTable.end()), faceTable.size());
83 hasFace1 = hasFace2 = false;
84 for (FaceTable::const_iterator it = faceTable.begin(); it != faceTable.end(); ++it) {
85 if (*it == face1) {
86 hasFace1 = true;
87 }
88 if (*it == face2) {
89 hasFace2 = true;
90 }
91 }
92 BOOST_CHECK(!hasFace1);
93 BOOST_CHECK(hasFace2);
94}
95
96BOOST_AUTO_TEST_SUITE_END()
97
98} // namespace tests
99} // namespace nfd