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> |
| 10 | |
| 11 | namespace nlsr { |
| 12 | namespace test { |
| 13 | BOOST_AUTO_TEST_SUITE(TestLsa) |
| 14 | |
| 15 | BOOST_AUTO_TEST_CASE(NameLsaBasic) |
| 16 | { |
| 17 | NamePrefixList npl1; |
| 18 | |
| 19 | std::string s1 = "name1"; |
| 20 | std::string s2 = "name2"; |
| 21 | |
| 22 | npl1.insert(s1); |
| 23 | npl1.insert(s2); |
| 24 | |
| 25 | //lsType is 1 for NameLsa, 3rd arg is seqNo. which will be a random number I just put in 12. |
| 26 | //1800 is default lsa refresh time. |
| 27 | NameLsa nlsa1("router1", 1, 12, 1800, npl1); |
| 28 | NameLsa nlsa2("router2", 1, 12, 1500, npl1); |
| 29 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame^] | 30 | BOOST_CHECK_EQUAL(nlsa1.getLsType(), (uint8_t)1); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 31 | |
| 32 | BOOST_CHECK(nlsa1.getLifeTime() != nlsa2.getLifeTime()); |
| 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); |
| 44 | |
| 45 | //For AdjLsa, lsType is 2. |
| 46 | //1 is the number of adjacent in adjacent list. |
| 47 | AdjLsa alsa1("router1", 2, 12, 1800, 1, adjList); |
| 48 | AdjLsa alsa2("router1", 2, 12, 1800, 1, adjList); |
| 49 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame^] | 50 | BOOST_CHECK_EQUAL(alsa1.getLsType(), (uint8_t)2); |
| 51 | BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), (uint32_t)12); |
| 52 | BOOST_CHECK_EQUAL(alsa1.getLifeTime(), (uint32_t)1800); |
| 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 | { |
| 65 | //For CoordinateLsa, lsType is 3. |
| 66 | CoordinateLsa clsa1("router1", 3, 12, 1800, 2.5, 30.0); |
| 67 | CoordinateLsa clsa2("router1", 3, 12, 1800, 2.5, 30.0); |
| 68 | |
| 69 | BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001); |
| 70 | BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001); |
| 71 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame^] | 72 | BOOST_CHECK(clsa1.isEqualContent(clsa2)); |
Ashlesh Gawande | eb582eb | 2014-05-01 14:25:20 -0500 | [diff] [blame] | 73 | |
| 74 | BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData()); |
| 75 | } |
| 76 | |
| 77 | BOOST_AUTO_TEST_SUITE_END() |
| 78 | |
| 79 | } //namespace test |
| 80 | } //namespace nlsr |