Skip to content

Commit

Permalink
tests: fix sync prefix test if SVS support is disabled
Browse files Browse the repository at this point in the history
Amends a2599da

Change-Id: I21b4379ad83f2241ad6749759ac3a95d98929a17
  • Loading branch information
Pesa committed Aug 3, 2023
1 parent 7543f59 commit 907675b
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions tests/test-conf-file-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ using std::shared_ptr;
const std::string SECTION_GENERAL =
"general\n"
"{\n"
" network /ndn/\n"
" site /memphis.edu/\n"
" router /cs/pollux/\n"
" network /ndn\n"
" site /memphis.edu\n"
" router /cs/pollux\n"
" lsa-refresh-time 1800\n"
" lsa-interest-lifetime 3\n"
" router-dead-interval 86400\n"
Expand All @@ -51,10 +51,11 @@ const std::string SECTION_GENERAL =
const std::string SECTION_GENERAL_SVS =
"general\n"
"{\n"
" network /ndn/\n"
" site /memphis.edu/\n"
" router /cs/pollux/\n"
" network /ndn\n"
" site /memphis.edu\n"
" router /cs/pollux\n"
" sync-protocol svs\n"
" state-dir /tmp\n"
"}\n\n";

const std::string SECTION_NEIGHBORS =
Expand Down Expand Up @@ -145,7 +146,7 @@ class ConfFileProcessorFixture : public IoKeyChainFixture
}

bool
processConfigurationString(std::string confString)
processConfigurationString(std::string_view confString)
{
std::ofstream config;
config.open("unit-test-nlsr.conf");
Expand All @@ -171,14 +172,14 @@ BOOST_FIXTURE_TEST_SUITE(TestConfFileProcessor, ConfFileProcessorFixture)

BOOST_AUTO_TEST_CASE(LinkState)
{
processConfigurationString(CONFIG_LINK_STATE);
BOOST_REQUIRE(processConfigurationString(CONFIG_LINK_STATE));
conf.buildRouterAndSyncUserPrefix();

// General
BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/");
BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu/");
BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux/");
BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux/");
BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn");
BOOST_CHECK_EQUAL(conf.getSiteName(), "/memphis.edu");
BOOST_CHECK_EQUAL(conf.getRouterName(), "/cs/pollux");
BOOST_CHECK_EQUAL(conf.getRouterPrefix(), "/ndn/memphis.edu/cs/pollux");
BOOST_CHECK_EQUAL(conf.getSyncPrefix(), ndn::Name("/localhop/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION));
BOOST_CHECK_EQUAL(conf.getLsaPrefix(), "/localhop/ndn/nlsr/LSA");
BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), 1800);
Expand Down Expand Up @@ -220,14 +221,18 @@ BOOST_AUTO_TEST_CASE(LinkState)
BOOST_CHECK_EQUAL(conf.getNamePrefixList().size(), 2);
}

BOOST_AUTO_TEST_CASE(SVSPrefix)
BOOST_AUTO_TEST_CASE(SvsPrefix)
{
processConfigurationString(CONFIG_SVS);
#ifdef HAVE_SVS
BOOST_REQUIRE(processConfigurationString(CONFIG_SVS));
conf.buildRouterAndSyncUserPrefix();

// SVS does not use localhop
BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn/");
BOOST_CHECK_EQUAL(conf.getNetwork(), "/ndn");
BOOST_CHECK_EQUAL(conf.getSyncPrefix(), ndn::Name("/ndn/nlsr/sync").appendVersion(ConfParameter::SYNC_VERSION));
#else
BOOST_CHECK_EQUAL(processConfigurationString(CONFIG_SVS), false);
#endif
}

BOOST_AUTO_TEST_CASE(MalformedUri)
Expand All @@ -252,24 +257,21 @@ BOOST_AUTO_TEST_CASE(MalformedUri)

BOOST_AUTO_TEST_CASE(Hyperbolic)
{
processConfigurationString(CONFIG_HYPERBOLIC);
BOOST_REQUIRE(processConfigurationString(CONFIG_HYPERBOLIC));

BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1);
BOOST_CHECK_EQUAL(conf.getCorR(), 123.456);
std::vector<double> angles;
angles.push_back(1.45);
std::vector<double> angles{1.45};
BOOST_CHECK(conf.getCorTheta() == angles);
}

BOOST_AUTO_TEST_CASE(Hyperbolic2)
{
processConfigurationString(CONFIG_HYPERBOLIC_ANGLES);
BOOST_REQUIRE(processConfigurationString(CONFIG_HYPERBOLIC_ANGLES));

BOOST_CHECK_EQUAL(conf.getHyperbolicState(), 1);
BOOST_CHECK_EQUAL(conf.getCorR(), 123.456);
std::vector<double> angles;
angles.push_back(1.45);
angles.push_back(2.25);
std::vector<double> angles{1.45, 2.25};
BOOST_CHECK(conf.getCorTheta() == angles);
}

Expand All @@ -281,17 +283,17 @@ BOOST_AUTO_TEST_CASE(DefaultValuesGeneral)
commentOut("lsa-interest-lifetime", config);
commentOut("router-dead-interval", config);

BOOST_CHECK(processConfigurationString(config));
BOOST_REQUIRE(processConfigurationString(config));

BOOST_CHECK_EQUAL(conf.getLsaRefreshTime(), static_cast<uint32_t>(LSA_REFRESH_TIME_DEFAULT));
BOOST_CHECK_EQUAL(conf.getLsaInterestLifetime(),
static_cast<ndn::time::seconds>(LSA_INTEREST_LIFETIME_DEFAULT));
BOOST_CHECK_EQUAL(conf.getRouterDeadInterval(), (2 * conf.getLsaRefreshTime()));

BOOST_CHECK(conf.m_confFileName != conf.getConfFileNameDynamic());
BOOST_CHECK_NE(conf.m_confFileName, conf.getConfFileNameDynamic());
conf.m_confFileName = "/tmp/nlsr.conf";
BOOST_CHECK(conf.m_confFileName == conf.getConfFileNameDynamic());
BOOST_CHECK(!processConfigurationString(config));
BOOST_CHECK_EQUAL(conf.m_confFileName, conf.getConfFileNameDynamic());
BOOST_CHECK_EQUAL(processConfigurationString(config), false);
}

BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors)
Expand All @@ -304,7 +306,7 @@ BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors)
commentOut("first-hello-interval", config);
commentOut("adj-lsa-build-interval", config);

BOOST_CHECK_EQUAL(processConfigurationString(config), true);
BOOST_REQUIRE(processConfigurationString(config));

BOOST_CHECK_EQUAL(conf.getInterestRetryNumber(), static_cast<uint32_t>(HELLO_RETRIES_DEFAULT));
BOOST_CHECK_EQUAL(conf.getInterestResendTime(), static_cast<uint32_t>(HELLO_TIMEOUT_DEFAULT));
Expand All @@ -315,7 +317,7 @@ BOOST_AUTO_TEST_CASE(DefaultValuesNeighbors)

BOOST_AUTO_TEST_CASE(CanonizeNeighbors)
{
std::string config = std::string(R"INFO(neighbors
std::string config{R"INFO(neighbors
{
neighbor
{
Expand All @@ -329,9 +331,9 @@ BOOST_AUTO_TEST_CASE(CanonizeNeighbors)
face-uri udp4://michigan.testbed.named-data.net
link-cost 30
}
})INFO");
})INFO"};

BOOST_CHECK_EQUAL(processConfigurationString(config), true);
BOOST_REQUIRE(processConfigurationString(config));

BOOST_CHECK_EQUAL(conf.m_adjl.getAdjacent("/ndn/edu/arizona/%C1.Router/hobo").getFaceUri().toString(),
"udp4://128.196.203.36:6363");
Expand All @@ -346,7 +348,7 @@ BOOST_AUTO_TEST_CASE(DefaultValuesFib)
commentOut("max-faces-per-prefix", config);
commentOut("routing-calc-interval", config);

BOOST_CHECK_EQUAL(processConfigurationString(config), true);
BOOST_REQUIRE(processConfigurationString(config));

BOOST_CHECK_EQUAL(conf.getMaxFacesPerPrefix(),
static_cast<uint32_t>(MAX_FACES_PER_PREFIX_DEFAULT));
Expand All @@ -360,7 +362,7 @@ BOOST_AUTO_TEST_CASE(DefaultValuesHyperbolic)

commentOut("state", config);

BOOST_CHECK_EQUAL(processConfigurationString(config), true);
BOOST_REQUIRE(processConfigurationString(config));

BOOST_CHECK_EQUAL(conf.getHyperbolicState(), static_cast<int32_t>(HYPERBOLIC_STATE_DEFAULT));
}
Expand Down Expand Up @@ -421,8 +423,7 @@ BOOST_AUTO_TEST_CASE(LoadCertToPublish)
}
)CONF";

BOOST_CHECK(processConfigurationString(SECTION_SECURITY));

BOOST_REQUIRE(processConfigurationString(SECTION_SECURITY));
}

BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814
Expand All @@ -440,7 +441,7 @@ BOOST_AUTO_TEST_CASE(PrefixUpdateValidatorOptional) // Bug #2814
}
)CONF";

BOOST_CHECK(processConfigurationString(SECTION_SECURITY));
BOOST_REQUIRE(processConfigurationString(SECTION_SECURITY));
}

BOOST_AUTO_TEST_SUITE_END()
Expand Down

0 comments on commit 907675b

Please sign in to comment.