tests: Adding unit tests.

The purpose of this commit is to start pushing unit test I am writing. I will add more unit tests in each patch

Refs: #1496

Change-Id: Ic132adddfa06a95780712eba63966d3bab4743af
This commit is contained in:
Ashlesh Gawande committed 2014-05-01 14:47:06 -05:00
1 parent c8a10f762b
commit eb582eb919
17 files changed
+727

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "adjacency-list.hpp"
#include "adjacent.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
using namespace std;
BOOST_AUTO_TEST_SUITE(TestAdjacenctList)
BOOST_AUTO_TEST_CASE(AdjacenctListBasic)
{
const string ADJ_NAME_1 = "testname";
const string ADJ_NAME_2 = "testname2";
//adjacent needed to test adjacency list.
Adjacent adjacent1(ADJ_NAME_1);
Adjacent adjacent2(ADJ_NAME_2);
adjacent1.setLinkCost(4);
adjacent2.setLinkCost(5);
AdjacencyList adjacentList1;
AdjacencyList adjacentList2;
adjacentList1.insert(adjacent1);
adjacentList2.insert(adjacent2);
BOOST_CHECK_EQUAL(adjacentList1.getSize(), 1);
BOOST_CHECK_EQUAL(adjacentList1.isEqual(adjacentList2), false);
BOOST_CHECK(adjacentList1.isNeighbor("testname"));
BOOST_CHECK_EQUAL(adjacentList1.isNeighbor("adjacent"), false);
string n1 = "testname";
BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), 0);
adjacentList1.setStatusOfNeighbor(n1, 1);
BOOST_CHECK_EQUAL(adjacentList1.getStatusOfNeighbor(n1), 1);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace tests
} //namespace nlsr
+36
View File
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "adjacent.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
using namespace std;
BOOST_AUTO_TEST_SUITE(TestAdjacenct)
BOOST_AUTO_TEST_CASE(AdjacenctBasic)
{
const string ADJ_NAME_1 = "testname";
const string ADJ_NAME_2 = "testname";
Adjacent adjacent1(ADJ_NAME_1);
Adjacent adjacent2(ADJ_NAME_2);
BOOST_CHECK(adjacent1.isEqual(adjacent2));
adjacent1.setLinkCost(10.5);
BOOST_CHECK_CLOSE(adjacent1.getLinkCost(), 10.5, 0.0001);
BOOST_CHECK_EQUAL(adjacent1.getName(), "testname");
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace tests
} //namespace nlsr
+59
View File
@@ -0,0 +1,59 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "conf-file-processor.hpp"
#include "nlsr.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestConfFileProcessor)
BOOST_AUTO_TEST_CASE(ConfFileProcessorSample)
{
Nlsr nlsr1;
const std::string CONFIG =
"network ndn\n"
"site-name memphis.edu\n"
"router-name cs/macbook\n\n"
"ndnneighbor /ndn/memphis.edu/cs/maia 7\n"
"link-cost /ndn/memphis.edu/cs/maia 30\n"
"ndnneighbor /ndn/memphis.edu/cs/pollux 10\n"
"link-cost /ndn/memphis.edu/cs/pollux 25\n\n"
"ndnname /ndn/memphis.edu/cs/macbook/name1\n"
"ndnname /ndn/memphis.edu/cs/macbook/name2\n\n\n"
;
ofstream config;
config.open("unit-test-nlsr.conf");
config << CONFIG;
config.close();
const string CONFIG_FILE = "unit-test-nlsr.conf";
ConfFileProcessor cfp1(nlsr1, CONFIG_FILE);
cfp1.processConfFile();
BOOST_CHECK(nlsr1.getAdjacencyList().isNeighbor("/ndn/memphis.edu/cs/maia"));
BOOST_CHECK_EQUAL(
nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/maia").getName(),
"/ndn/memphis.edu/cs/maia");
BOOST_CHECK_EQUAL(
nlsr1.getAdjacencyList().getAdjacent("/ndn/memphis.edu/cs/maia").getLinkCost(),
30);
BOOST_CHECK_EQUAL(nlsr1.getNamePrefixList().getSize(), 2);
remove("unit-test-nlsr.conf");
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+116
View File
@@ -0,0 +1,116 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "conf-parameter.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
using namespace std;
BOOST_AUTO_TEST_SUITE(TestConfParameter)
BOOST_AUTO_TEST_CASE(ConfParameterSettersAndGetters)
{
ConfParameter cp1;
const string NAME = "router1";
const string SITE = "memphis";
const string NETWORK = "ATT";
cp1.setRouterName(NAME);
cp1.setSiteName(SITE);
cp1.setNetwork(NETWORK);
cp1.setRootKeyPrefix("adminRootKey");
cp1.setInterestRetryNumber(2);
cp1.setInterestResendTime(1000);
cp1.setLsaRefreshTime(1500);
cp1.setRouterDeadInterval(10);
cp1.setMaxFacesPerPrefix(50);
cp1.setLogDir("log");
cp1.setCertDir("cert");
cp1.setSeqFileDir("ssfd");
cp1.setDetailedLogging(1);
cp1.setDebugging(1);
cp1.setIsHyperbolicCalc(1);
cp1.setCorR(2.5);
cp1.setCorTheta(102.5);
cp1.setTunnelType(2);
const string a = "csp";
cp1.setChronosyncSyncPrefix(a);
cp1.setChronosyncLsaPrefix("cla");
cp1.setInfoInterestInterval(3);
BOOST_CHECK_EQUAL(cp1.getRouterName(), "router1");
BOOST_CHECK_EQUAL(cp1.getSiteName(), "memphis");
BOOST_CHECK_EQUAL(cp1.getNetwork(), "ATT");
cp1.buildRouterPrefix();
BOOST_CHECK_EQUAL(cp1.getRouterPrefix(), "/ATT/memphis/router1");
BOOST_CHECK_EQUAL(cp1.getRootKeyPrefix(), "adminRootKey");
BOOST_CHECK_EQUAL(cp1.getInterestRetryNumber(), 2);
BOOST_CHECK_EQUAL(cp1.getInterestResendTime(), 1000);
BOOST_CHECK_EQUAL(cp1.getLsaRefreshTime(), 1500);
BOOST_CHECK_EQUAL(cp1.getRouterDeadInterval(), 10);
BOOST_CHECK_EQUAL(cp1.getMaxFacesPerPrefix(), 50);
BOOST_CHECK_EQUAL(cp1.getLogDir(), "log");
BOOST_CHECK_EQUAL(cp1.getCertDir(), "cert");
BOOST_CHECK_EQUAL(cp1.getSeqFileDir(), "ssfd");
BOOST_CHECK_EQUAL(cp1.getDetailedLogging(), 1);
BOOST_CHECK_EQUAL(cp1.getDebugging(), 1);
BOOST_CHECK_EQUAL(cp1.getIsHyperbolicCalc(), 1);
BOOST_CHECK_CLOSE(cp1.getCorTheta(), 102.5, 0.0001);
BOOST_CHECK_EQUAL(cp1.getTunnelType(), 2);
BOOST_CHECK_EQUAL(cp1.getChronosyncSyncPrefix(), "csp");
BOOST_CHECK_EQUAL(cp1.getChronosyncLsaPrefix(), "cla");
BOOST_CHECK_EQUAL(cp1.getInfoInterestInterval(), 3);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace test
} // namespace nlsr
+28
View File
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "route/fib-entry.hpp"
#include "route/nexthop-list.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestFibEntry)
BOOST_AUTO_TEST_CASE(FibEntryConstructorAndGetters)
{
FibEntry fe1("next1");
BOOST_CHECK_EQUAL(fe1.getName(), "next1");
BOOST_CHECK_EQUAL(fe1.getTimeToRefresh(), 0); //Default Time
BOOST_CHECK_EQUAL(fe1.getSeqNo(), 0); //Default Seq No.
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+80
View File
@@ -0,0 +1,80 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "lsa.hpp"
#include "name-prefix-list.hpp"
#include "adjacent.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestLsa)
BOOST_AUTO_TEST_CASE(NameLsaBasic)
{
NamePrefixList npl1;
std::string s1 = "name1";
std::string s2 = "name2";
npl1.insert(s1);
npl1.insert(s2);
//lsType is 1 for NameLsa, 3rd arg is seqNo. which will be a random number I just put in 12.
//1800 is default lsa refresh time.
NameLsa nlsa1("router1", 1, 12, 1800, npl1);
NameLsa nlsa2("router2", 1, 12, 1500, npl1);
BOOST_CHECK_EQUAL(nlsa1.getLsType(), 1);
BOOST_CHECK(nlsa1.getLifeTime() != nlsa2.getLifeTime());
BOOST_CHECK(nlsa1.getKey() != nlsa2.getKey());
}
BOOST_AUTO_TEST_CASE(AdjacentLsaConstructorAndGetters)
{
Adjacent adj1("adjacent");
Adjacent adj2("adjacent2");
AdjacencyList adjList;
adjList.insert(adj1);
//For AdjLsa, lsType is 2.
//1 is the number of adjacent in adjacent list.
AdjLsa alsa1("router1", 2, 12, 1800, 1, adjList);
AdjLsa alsa2("router1", 2, 12, 1800, 1, adjList);
BOOST_CHECK_EQUAL(alsa1.getLsType(), 2);
BOOST_CHECK_EQUAL(alsa1.getLsSeqNo(), 12);
BOOST_CHECK_EQUAL(alsa1.getLifeTime(), 1800);
BOOST_CHECK_EQUAL(alsa1.getNoLink(), 1);
BOOST_CHECK(alsa1.isEqual(alsa2));
alsa1.addAdjacent(adj2);
const std::string ADJACENT_1 = "adjacent2";
BOOST_CHECK(alsa1.getAdl().isNeighbor(ADJACENT_1));
}
BOOST_AUTO_TEST_CASE(CoordinateLsaConstructorAndGetters)
{
//For CoordinateLsa, lsType is 3.
CoordinateLsa clsa1("router1", 3, 12, 1800, 2.5, 30.0);
CoordinateLsa clsa2("router1", 3, 12, 1800, 2.5, 30.0);
BOOST_CHECK_CLOSE(clsa1.getCorRadius(), 2.5, 0.0001);
BOOST_CHECK_CLOSE(clsa1.getCorTheta(), 30.0, 0.0001);
BOOST_CHECK(clsa1.isEqual(clsa2));
BOOST_CHECK_EQUAL(clsa1.getData(), clsa2.getData());
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+50
View File
@@ -0,0 +1,50 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "lsdb.hpp"
#include "nlsr.hpp"
#include "lsa.hpp"
#include "name-prefix-list.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestLsdb)
BOOST_AUTO_TEST_CASE(LsdbRemoveAndExists)
{
Nlsr nlsr1;
NamePrefixList npl1;
string s1 = "name1";
string s2 = "name2";
string router1 = "router1/1";
npl1.insert(s1);
npl1.insert(s2);
//For NameLsa lsType is 1.
//12 is seqNo, randomly generated.
//1800 is the default life time.
NameLsa nlsa1("router1", 1, 12, 1800, npl1);
Lsdb lsdb1;
lsdb1.installNameLsa(nlsr1, nlsa1);
BOOST_CHECK(lsdb1.doesLsaExist("router1/1", 1));
lsdb1.removeNameLsa(nlsr1, router1);
BOOST_CHECK_EQUAL(lsdb1.doesLsaExist("router1/1", 1), false);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+29
View File
@@ -0,0 +1,29 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "route/map.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestMapEntry)
BOOST_AUTO_TEST_CASE(MapEntryConstructorAndGetters)
{
std::string rtr = "r0";
MapEntry me1(rtr, 1);
BOOST_CHECK_EQUAL(me1.getRouter(), "r0");
BOOST_CHECK_EQUAL(me1.getMappingNumber(), 1);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+31
View File
@@ -0,0 +1,31 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "route/map.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestMap)
BOOST_AUTO_TEST_CASE(MapAddElementAndSize)
{
Map map1;
std::string router1 = "r1";
std::string router2 = "r2";
map1.addElement(router1);
map1.addElement(router2);
BOOST_CHECK_EQUAL(map1.getMapSize(), 2);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+35
View File
@@ -0,0 +1,35 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "name-prefix-list.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestNpl)
BOOST_AUTO_TEST_CASE(NplSizeAndRemove)
{
NamePrefixList npl1;
std::string a = "testname";
std::string b = "name";
npl1.insert(a);
npl1.insert(b);
BOOST_CHECK_EQUAL(npl1.getSize(), 2);
npl1.remove(b);
BOOST_CHECK_EQUAL(npl1.getSize(), 1);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+25
View File
@@ -0,0 +1,25 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "route/name-prefix-table-entry.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestNpte)
BOOST_AUTO_TEST_CASE(NpteConstructorAndNamePrefix)
{
NamePrefixTableEntry npte1("/ndn/memphis.edu/cs");
BOOST_CHECK_EQUAL(npte1.getNamePrefix(), "/ndn/memphis.edu/cs");
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+32
View File
@@ -0,0 +1,32 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "route/nexthop-list.hpp"
#include "route/nexthop.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestNhl)
BOOST_AUTO_TEST_CASE(NhlAddNextHop)
{
NextHop np1;
NexthopList nhl1;
nhl1.addNextHop(np1);
BOOST_CHECK_EQUAL(nhl1.getSize(), 1);
nhl1.removeNextHop(np1);
BOOST_CHECK_EQUAL(nhl1.getSize(), 0);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+30
View File
@@ -0,0 +1,30 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "route/nexthop.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestNexthop)
BOOST_AUTO_TEST_CASE(NexthopSetAndGet)
{
NextHop np1;
np1.setConnectingFace(1);
np1.setRouteCost(10.5);
BOOST_CHECK_EQUAL(np1.getConnectingFace(), 1);
BOOST_CHECK_CLOSE(np1.getRouteCost(), 10.5, 0.0001);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+25
View File
@@ -0,0 +1,25 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "route/routing-table-entry.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestRoutingTableEntry)
BOOST_AUTO_TEST_CASE(RoutingTableEntryDestination)
{
RoutingTableEntry rte1("router1");
BOOST_CHECK_EQUAL(rte1.getDestination(), "router1");
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+34
View File
@@ -0,0 +1,34 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "route/routing-table.hpp"
#include "route/routing-table-entry.hpp"
#include "route/nexthop.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestRoutingTable)
BOOST_AUTO_TEST_CASE(RoutingTableAddNextHop)
{
RoutingTable rt1;
NextHop nh1;
const std::string DEST_ROUTER = "destRouter";
rt1.addNextHop("destRouter", nh1);
BOOST_CHECK_EQUAL(rt1.findRoutingTableEntry(DEST_ROUTER)->getDestination(),
"destRouter");
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+31
View File
@@ -0,0 +1,31 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "sequencing-manager.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestSequencingManager)
BOOST_AUTO_TEST_CASE(SequencingManagerBasic)
{
SequencingManager sm1(120, 121, 122);
SequencingManager sm2(sm1.getCombinedSeqNo());
BOOST_CHECK_EQUAL(sm2.getNameLsaSeq(), 120);
BOOST_CHECK_EQUAL(sm2.getAdjLsaSeq(), 121);
BOOST_CHECK_EQUAL(sm2.getCorLsaSeq(), 122);
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr
+34
View File
@@ -0,0 +1,34 @@
/**
* Copyright (C) 2014 Regents of the University of Memphis.
* See COPYING for copyright and distribution information.
*/
#include "utility/tokenizer.hpp"
#include <boost/test/unit_test.hpp>
namespace nlsr {
namespace test {
BOOST_AUTO_TEST_SUITE(TestTokenizer)
BOOST_AUTO_TEST_CASE(TokenizerBasic)
{
Tokenizer token1("/ndn/memphis.edu/cs", "/");
Tokenizer token2("/ndn/memphis.edu/cs", "/");
Tokenizer token3("/test/hello");
BOOST_CHECK(token1.getFirstToken() == token2.getFirstToken());
BOOST_CHECK_EQUAL(token1.getRestOfLine(), token2.getRestOfLine());
BOOST_CHECK(token1.getFirstToken() != token3.getFirstToken());
BOOST_CHECK(token1.getRestOfLine() != token3.getRestOfLine());
}
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
} //namespace nlsr