tests: Change to updated naming conventions
Change-Id: I9351c669282c3c02fd533237489beeb10fe7d15e
Refs: #2497
diff --git a/tests/rib/rib.t.cpp b/tests/rib/rib.t.cpp
new file mode 100644
index 0000000..12b6208
--- /dev/null
+++ b/tests/rib/rib.t.cpp
@@ -0,0 +1,335 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "rib/rib.hpp"
+
+#include "tests/test-common.hpp"
+
+namespace nfd {
+namespace rib {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(TestRib, nfd::tests::BaseFixture)
+
+BOOST_AUTO_TEST_CASE(RibEntry)
+{
+ rib::RibEntry entry;
+
+ rib::Route route1;
+ route1.faceId = 1;
+ route1.origin = 0;
+
+ entry.insertRoute(route1);
+ BOOST_CHECK_EQUAL(entry.getRoutes().size(), 1);
+
+ Route route2;
+ route2.faceId = 1;
+ route2.origin = 128;
+
+ entry.insertRoute(route2);
+ BOOST_CHECK_EQUAL(entry.getRoutes().size(), 2);
+
+ entry.eraseRoute(route1);
+ BOOST_CHECK_EQUAL(entry.getRoutes().size(), 1);
+
+ BOOST_CHECK(entry.findRoute(route1) == entry.getRoutes().end());
+ BOOST_CHECK(entry.findRoute(route2) != entry.getRoutes().end());
+
+ entry.insertRoute(route2);
+ BOOST_CHECK_EQUAL(entry.getRoutes().size(), 1);
+
+ entry.eraseRoute(route1);
+ BOOST_CHECK_EQUAL(entry.getRoutes().size(), 1);
+ BOOST_CHECK(entry.findRoute(route2) != entry.getRoutes().end());
+}
+
+BOOST_AUTO_TEST_CASE(Parent)
+{
+ rib::Rib rib;
+
+ Route root;
+ Name name1("/");
+ root.faceId = 1;
+ root.origin = 20;
+ rib.insert(name1, root);
+
+ Route route1;
+ Name name2("/hello");
+ route1.faceId = 2;
+ route1.origin = 20;
+ rib.insert(name2, route1);
+
+ Route route2;
+ Name name3("/hello/world");
+ route2.faceId = 3;
+ route2.origin = 20;
+ rib.insert(name3, route2);
+
+ shared_ptr<rib::RibEntry> ribEntry = rib.findParent(name3);
+ BOOST_REQUIRE(static_cast<bool>(ribEntry));
+ BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 2);
+
+ ribEntry = rib.findParent(name2);
+ BOOST_REQUIRE(static_cast<bool>(ribEntry));
+ BOOST_CHECK_EQUAL(ribEntry->getRoutes().front().faceId, 1);
+
+ Route route3;
+ Name name4("/hello/test/foo/bar");
+ route2.faceId = 3;
+ route2.origin = 20;
+ rib.insert(name4, route3);
+
+ ribEntry = rib.findParent(name4);
+ BOOST_CHECK(ribEntry != shared_ptr<rib::RibEntry>());
+ BOOST_CHECK(ribEntry->getRoutes().front().faceId == 2);
+}
+
+BOOST_AUTO_TEST_CASE(Children)
+{
+ rib::Rib rib;
+
+ Route route1;
+ Name name1("/");
+ route1.faceId = 1;
+ route1.origin = 20;
+ rib.insert(name1, route1);
+
+ Route route2;
+ Name name2("/hello/world");
+ route2.faceId = 2;
+ route2.origin = 20;
+ rib.insert(name2, route2);
+
+ Route route3;
+ Name name3("/hello/test/foo/bar");
+ route3.faceId = 3;
+ route3.origin = 20;
+ rib.insert(name3, route3);
+
+ BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 2);
+ BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0);
+ BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0);
+
+ Route entry4;
+ Name name4("/hello");
+ entry4.faceId = 4;
+ entry4.origin = 20;
+ rib.insert(name4, entry4);
+
+ BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().size(), 1);
+ BOOST_CHECK_EQUAL((rib.find(name2)->second)->getChildren().size(), 0);
+ BOOST_CHECK_EQUAL((rib.find(name3)->second)->getChildren().size(), 0);
+ BOOST_CHECK_EQUAL((rib.find(name4)->second)->getChildren().size(), 2);
+
+ BOOST_CHECK_EQUAL((rib.find(name1)->second)->getChildren().front()->getName(), "/hello");
+ BOOST_CHECK_EQUAL((rib.find(name4)->second)->getParent()->getName(), "/");
+
+ BOOST_REQUIRE(static_cast<bool>((rib.find(name2)->second)->getParent()));
+ BOOST_CHECK_EQUAL((rib.find(name2)->second)->getParent()->getName(), name4);
+ BOOST_REQUIRE(static_cast<bool>((rib.find(name3)->second)->getParent()));
+ BOOST_CHECK_EQUAL((rib.find(name3)->second)->getParent()->getName(), name4);
+}
+
+BOOST_AUTO_TEST_CASE(EraseFace)
+{
+ rib::Rib rib;
+
+ Route route1;
+ Name name1("/");
+ route1.faceId = 1;
+ route1.origin = 20;
+ rib.insert(name1, route1);
+
+ Route route2;
+ Name name2("/hello/world");
+ route2.faceId = 2;
+ route2.origin = 20;
+ rib.insert(name2, route2);
+
+ Route route3;
+ Name name3("/hello/world");
+ route3.faceId = 1;
+ route3.origin = 20;
+ rib.insert(name3, route3);
+
+ Route entry4;
+ Name name4("/not/inserted");
+ entry4.faceId = 1;
+ entry4.origin = 20;
+
+ rib.erase(name4, entry4);
+ rib.erase(name1, route1);
+
+ BOOST_CHECK(rib.find(name1) == rib.end());
+ BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 2);
+
+ rib.erase(name2, route2);
+
+ BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 1);
+ BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().front().faceId, 1);
+
+ rib.erase(name3, route3);
+
+ BOOST_CHECK(rib.find(name2) == rib.end());
+
+ rib.erase(name4, entry4);
+}
+
+BOOST_AUTO_TEST_CASE(EraseRibEntry)
+{
+ rib::Rib rib;
+
+ Route route1;
+ Name name1("/");
+ route1.faceId = 1;
+ route1.origin = 20;
+ rib.insert(name1, route1);
+
+ Route route2;
+ Name name2("/hello");
+ route2.faceId = 2;
+ route2.origin = 20;
+ rib.insert(name2, route2);
+
+ Route route3;
+ Name name3("/hello/world");
+ route3.faceId = 1;
+ route3.origin = 20;
+ rib.insert(name3, route3);
+
+ shared_ptr<rib::RibEntry> ribEntry1 = rib.find(name1)->second;
+ shared_ptr<rib::RibEntry> ribEntry2 = rib.find(name2)->second;
+ shared_ptr<rib::RibEntry> ribEntry3 = rib.find(name3)->second;
+
+ BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry2);
+ BOOST_CHECK(ribEntry3->getParent() == ribEntry2);
+
+ rib.erase(name2, route2);
+ BOOST_CHECK(ribEntry1->getChildren().front() == ribEntry3);
+ BOOST_CHECK(ribEntry3->getParent() == ribEntry1);
+}
+
+BOOST_AUTO_TEST_CASE(EraseByFaceId)
+{
+ rib::Rib rib;
+
+ Route route1;
+ Name name1("/");
+ route1.faceId = 1;
+ route1.origin = 20;
+ rib.insert(name1, route1);
+
+ Route route2;
+ Name name2("/hello/world");
+ route2.faceId = 2;
+ route2.origin = 20;
+ rib.insert(name2, route2);
+
+ Route route3;
+ Name name3("/hello/world");
+ route3.faceId = 1;
+ route3.origin = 20;
+ rib.insert(name3, route3);
+
+ rib.erase(1);
+ BOOST_CHECK(rib.find(name1) == rib.end());
+ BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 1);
+
+ rib.erase(3);
+ BOOST_CHECK_EQUAL((rib.find(name2)->second)->getRoutes().size(), 1);
+
+ rib.erase(2);
+ BOOST_CHECK(rib.find(name2) == rib.end());
+
+ rib.erase(3);
+}
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+ rib::Rib rib;
+
+ Route route1;
+ Name name1("/hello/world");
+ route1.faceId = 1;
+ route1.origin = 20;
+ route1.cost = 10;
+ route1.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE;
+ route1.expires = time::steady_clock::now() + time::milliseconds(1500);
+
+ rib.insert(name1, route1);
+ BOOST_CHECK_EQUAL(rib.size(), 1);
+
+ rib.insert(name1, route1);
+ BOOST_CHECK_EQUAL(rib.size(), 1);
+
+ Route route2;
+ Name name2("/hello/world");
+ route2.faceId = 1;
+ route2.origin = 20;
+ route2.cost = 100;
+ route2.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
+ route2.expires = time::steady_clock::now() + time::seconds(0);
+
+ rib.insert(name2, route2);
+ BOOST_CHECK_EQUAL(rib.size(), 1);
+
+ route2.faceId = 2;
+ rib.insert(name2, route2);
+ BOOST_CHECK_EQUAL(rib.size(), 2);
+
+ BOOST_CHECK(rib.find(name1)->second->hasFaceId(route1.faceId));
+ BOOST_CHECK(rib.find(name1)->second->hasFaceId(route2.faceId));
+
+ Name name3("/foo/bar");
+ rib.insert(name3, route2);
+ BOOST_CHECK_EQUAL(rib.size(), 3);
+
+ route2.origin = 1;
+ rib.insert(name3, route2);
+ BOOST_CHECK_EQUAL(rib.size(), 4);
+
+ rib.erase(name3, route2);
+ BOOST_CHECK_EQUAL(rib.size(), 3);
+
+ Name name4("/hello/world");
+ rib.erase(name4, route2);
+ BOOST_CHECK_EQUAL(rib.size(), 3);
+
+ route2.origin = 20;
+ rib.erase(name4, route2);
+ BOOST_CHECK_EQUAL(rib.size(), 2);
+
+ BOOST_CHECK_EQUAL(rib.find(name2, route2), static_cast<Route*>(0));
+ BOOST_CHECK_NE(rib.find(name1, route1), static_cast<Route*>(0));
+
+ rib.erase(name1, route1);
+ BOOST_CHECK_EQUAL(rib.size(), 1);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace rib
+} // namespace nfd