Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2014 Regents of the University of Memphis. |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include "lsa.hpp" |
| 7 | #include "name-prefix-list.hpp" |
| 8 | #include "adjacent.hpp" |
| 9 | #include <boost/test/unit_test.hpp> |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame^] | 10 | #include <ndn-cxx/util/time.hpp> |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 11 | |
| 12 | namespace nlsr { |
| 13 | namespace test { |
| 14 | BOOST_AUTO_TEST_SUITE(TestLsa) |
| 15 | |
| 16 | BOOST_AUTO_TEST_CASE(NameLsaBasic) |
| 17 | { |
| 18 | NamePrefixList npl1; |
| 19 | |
| 20 | std::string s1 = "name1"; |
| 21 | std::string s2 = "name2"; |
| 22 | |
| 23 | npl1.insert(s1); |
| 24 | npl1.insert(s2); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame^] | 25 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 26 | //lsType is 1 for NameLsa, 3rd arg is seqNo. which will be a random number I just put in 12. |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame^] | 27 | NameLsa nlsa1("router1", std::string("name"), 12, testTimePoint, npl1); |
| 28 | NameLsa nlsa2("router2", std::string("name"), 12, testTimePoint, npl1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 29 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 30 | BOOST_CHECK_EQUAL(nlsa1.getLsType(), "name"); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 31 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame^] | 32 | BOOST_CHECK(nlsa1.getExpirationTimePoint() == nlsa2.getExpirationTimePoint()); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 33 | |
| 34 | BOOST_CHECK(nlsa1.getKey() != nlsa2.getKey()); |
| 35 | } |
| 36 | |
| 37 | BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters) |
| 38 | { |
| 39 | Adjacent adj1("adjacent"); |
| 40 | Adjacent adj2("adjacent2"); |
| 41 | |
| 42 | AdjacencyList adjList; |
| 43 | adjList.insert(adj1); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame^] | 44 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 45 | //For AdjLsa, lsType is 2. |
| 46 | //1 is the number of adjacent in adjacent list. |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame^] | 47 | AdjLsa alsa1("router1", std::string("adjacency"), 12, testTimePoint, 1, adjList); |
| 48 | AdjLsa alsa2("router1", std::string("adjacency"), 12, testTimePoint, 1, adjList); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 49 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 50 | BOOST_CHECK_EQUAL(alsa1.getLsType(), "adjacency"); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 51 | BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame^] | 52 | BOOST_CHECK_EQUAL(alsa1.getExpirationTimePoint(), testTimePoint); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 53 | BOOST_CHECK_EQUAL(alsa1.getNoLink(), (uint32_t)1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 54 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 55 | BOOST_CHECK(alsa1.isEqualContent(alsa2)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 56 | |
| 57 | alsa1.addAdjacent(adj2); |
| 58 | |
| 59 | const std::string ADJACENT_1 = "adjacent2"; |
| 60 | BOOST_CHECK(alsa1.getAdl().isNeighbor(ADJACENT_1)); |
| 61 | } |
| 62 | |
| 63 | BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters) |
| 64 | { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame^] | 65 | ndn::time::system_clock::TimePoint testTimePoint = ndn::time::system_clock::now(); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 66 | //For CoordinateLsa, lsType is 3. |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame^] | 67 | CoordinateLsa clsa1("router1", std::string("coordinate"), 12, testTimePoint, 2.5, 30.0); |
| 68 | CoordinateLsa clsa2("router1", std::string("coordinate"), 12, testTimePoint, 2.5, 30.0); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 69 | |
| 70 | BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001); |
| 71 | BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001); |
| 72 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 73 | BOOST_CHECK(clsa1.isEqualContent(clsa2)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 74 | |
| 75 | BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData()); |
| 76 | } |
| 77 | |
| 78 | BOOST_AUTO_TEST_SUITE_END() |
| 79 | |
| 80 | } //namespace test |
| 81 | } //namespace nlsr |