tlv: add LSDB dataset tlv abstractions
refs #2280
Change-Id: I2d0d238686e28d1c25a7821a47352fcd589df823
diff --git a/tests/tlv/test-name-lsa.cpp b/tests/tlv/test-name-lsa.cpp
new file mode 100644
index 0000000..318d282
--- /dev/null
+++ b/tests/tlv/test-name-lsa.cpp
@@ -0,0 +1,182 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, The University of Memphis,
+ * Regents of the University of California,
+ * Arizona Board of Regents.
+ *
+ * This file is part of NLSR (Named-data Link State Routing).
+ * See AUTHORS.md for complete list of NLSR authors and contributors.
+ *
+ * NLSR 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.
+ *
+ * NLSR 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
+ * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "tlv/name-lsa.hpp"
+
+#include "../boost-test.hpp"
+
+namespace nlsr {
+namespace tlv {
+namespace test {
+
+BOOST_AUTO_TEST_SUITE(TlvTestNameLsa)
+
+const uint8_t NameLsaWithNamesData[] =
+{
+ // Header
+ 0x89, 0x25,
+ // LsaInfo
+ 0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01,
+ 0x80, 0x8b, 0x02, 0x27, 0x10,
+ // Name
+ 0x07, 0x07, 0x08, 0x05, 0x74, 0x65, 0x73, 0x74, 0x31,
+ // Name
+ 0x07, 0x07, 0x08, 0x05, 0x74, 0x65, 0x73, 0x74, 0x32
+};
+
+const uint8_t NameLsaWithoutNamesData[] =
+{
+ // Header
+ 0x89, 0x13,
+ // LsaInfo
+ 0x80, 0x11, 0x81, 0x08, 0x07, 0x06, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x82, 0x01,
+ 0x80, 0x8b, 0x02, 0x27, 0x10,
+};
+
+BOOST_AUTO_TEST_CASE(NameLsaEncodeWithNames)
+{
+ NameLsa nameLsa;
+
+ LsaInfo lsaInfo;
+ lsaInfo.setOriginRouter("test");
+ lsaInfo.setSequenceNumber(128);
+ lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
+ nameLsa.setLsaInfo(lsaInfo);
+
+ nameLsa.addName("test1");
+ nameLsa.addName("test2");
+
+ const ndn::Block& wire = nameLsa.wireEncode();
+
+ BOOST_REQUIRE_EQUAL_COLLECTIONS(NameLsaWithNamesData,
+ NameLsaWithNamesData + sizeof(NameLsaWithNamesData),
+ wire.begin(), wire.end());
+}
+
+BOOST_AUTO_TEST_CASE(NameLsaDecodeWithNames)
+{
+ NameLsa nameLsa;
+
+ nameLsa.wireDecode(ndn::Block(NameLsaWithNamesData, sizeof(NameLsaWithNamesData)));
+
+ LsaInfo lsaInfo = nameLsa.getLsaInfo();
+ BOOST_CHECK_EQUAL(lsaInfo.getOriginRouter(), "test");
+ BOOST_CHECK_EQUAL(lsaInfo.getSequenceNumber(), 128);
+ BOOST_CHECK_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000));
+
+ BOOST_CHECK_EQUAL(nameLsa.hasNames(), true);
+ std::list<ndn::Name> names = nameLsa.getNames();
+ std::list<ndn::Name>::const_iterator it = names.begin();
+ BOOST_CHECK_EQUAL(*it, "test1");
+
+ it++;
+ BOOST_CHECK_EQUAL(*it, "test2");
+}
+
+BOOST_AUTO_TEST_CASE(NameLsaEncodeWithoutNames)
+{
+ NameLsa nameLsa;
+
+ LsaInfo lsaInfo;
+ lsaInfo.setOriginRouter("test");
+ lsaInfo.setSequenceNumber(128);
+ lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
+ nameLsa.setLsaInfo(lsaInfo);
+
+ const ndn::Block& wire = nameLsa.wireEncode();
+
+ BOOST_REQUIRE_EQUAL_COLLECTIONS(NameLsaWithoutNamesData,
+ NameLsaWithoutNamesData + sizeof(NameLsaWithoutNamesData),
+ wire.begin(), wire.end());
+}
+
+BOOST_AUTO_TEST_CASE(NameLsaDecodeWithoutNames)
+{
+ NameLsa nameLsa;
+
+ nameLsa.wireDecode(ndn::Block(NameLsaWithoutNamesData, sizeof(NameLsaWithoutNamesData)));
+
+ LsaInfo lsaInfo = nameLsa.getLsaInfo();
+ BOOST_CHECK_EQUAL(lsaInfo.getOriginRouter(), "test");
+ BOOST_CHECK_EQUAL(lsaInfo.getSequenceNumber(), 128);
+ BOOST_CHECK_EQUAL(lsaInfo.getExpirationPeriod(), ndn::time::milliseconds(10000));
+
+ BOOST_CHECK_EQUAL(nameLsa.hasNames(), false);
+}
+
+BOOST_AUTO_TEST_CASE(NameLsaClear)
+{
+ NameLsa nameLsa;
+
+ LsaInfo lsaInfo;
+ lsaInfo.setOriginRouter("test");
+ lsaInfo.setSequenceNumber(128);
+ lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
+ nameLsa.setLsaInfo(lsaInfo);
+
+ nameLsa.addName("test1");
+ BOOST_CHECK_EQUAL(nameLsa.getNames().size(), 1);
+
+ std::list<ndn::Name> names = nameLsa.getNames();
+ std::list<ndn::Name>::const_iterator it = names.begin();
+ BOOST_CHECK_EQUAL(*it, "test1");
+
+ nameLsa.clearNames();
+ BOOST_CHECK_EQUAL(nameLsa.getNames().size(), 0);
+
+ nameLsa.addName("test2");
+ BOOST_CHECK_EQUAL(nameLsa.getNames().size(), 1);
+
+ names = nameLsa.getNames();
+ it = names.begin();
+ BOOST_CHECK_EQUAL(*it, "test2");
+}
+
+BOOST_AUTO_TEST_CASE(AdjacencyLsaOutputStream)
+{
+ NameLsa nameLsa;
+
+ LsaInfo lsaInfo;
+ lsaInfo.setOriginRouter("test");
+ lsaInfo.setSequenceNumber(128);
+ lsaInfo.setExpirationPeriod(ndn::time::milliseconds(10000));
+ nameLsa.setLsaInfo(lsaInfo);
+
+ nameLsa.addName("test1");
+ nameLsa.addName("test2");
+
+ std::ostringstream os;
+ os << nameLsa;
+
+ BOOST_CHECK_EQUAL(os.str(), "NameLsa("
+ "LsaInfo("
+ "OriginRouter: /test, "
+ "SequenceNumber: 128, "
+ "ExpirationPeriod: 10000 milliseconds), "
+ "Name: /test1, "
+ "Name: /test2)");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace test
+} // namespace tlv
+} // namespace nlsr