npl: npls more conveniently instantiable

NPLs can now be instantiated using brace-init lists, as well as by passing
any iterator-capable container.

refs: #4345

Change-Id: Ib43373d5899d0ac14861027c34431fa928eec191
diff --git a/tests/test-lsa.cpp b/tests/test-lsa.cpp
index f15507d..f3eff5c 100644
--- a/tests/test-lsa.cpp
+++ b/tests/test-lsa.cpp
@@ -34,13 +34,10 @@
 
 BOOST_AUTO_TEST_CASE(NameLsaBasic)
 {
-  NamePrefixList npl1;
+  ndn::Name s1{"name1"};
+  ndn::Name s2{"name2"};
+  NamePrefixList npl1{s1, s2};
 
-  std::string s1 = "name1";
-  std::string s2 = "name2";
-
-  npl1.insert(s1);
-  npl1.insert(s2);
   ndn::time::system_clock::TimePoint testTimePoint =  ndn::time::system_clock::now();
 
   //3rd arg is seqNo. which will be a random number I just put in 12.
@@ -184,13 +181,9 @@
   BOOST_CHECK(adjlsa1.isEqualContent(adjlsa2));
 
   //Name LSA
-  NamePrefixList npl1;
-
-  std::string s1 = "name1";
-  std::string s2 = "name2";
-
-  npl1.insert(s1);
-  npl1.insert(s2);
+  ndn::Name s1{"name1"};
+  ndn::Name s2{"name2"};
+  NamePrefixList npl1{s1, s2};
 
   NameLsa nlsa1("router1", 1, testTimePoint, npl1);
   NameLsa nlsa2;
diff --git a/tests/test-name-prefix-list.cpp b/tests/test-name-prefix-list.cpp
index 080b259..f8bf855 100644
--- a/tests/test-name-prefix-list.cpp
+++ b/tests/test-name-prefix-list.cpp
@@ -31,13 +31,10 @@
  */
 BOOST_AUTO_TEST_CASE(NplSizeAndRemove)
 {
-  NamePrefixList npl1;
+  ndn::Name a{"testname"};
+  ndn::Name b{"name"};
 
-  std::string a = "testname";
-  std::string b = "name";
-
-  npl1.insert(a);
-  npl1.insert(b);
+  NamePrefixList npl1{a, b};
 
   BOOST_CHECK_EQUAL(npl1.size(), 2);
 
@@ -52,19 +49,11 @@
  */
 BOOST_AUTO_TEST_CASE(OperatorEquals)
 {
-  NamePrefixList list1;
-  NamePrefixList list2;
   ndn::Name name1("/ndn/test/name1");
   ndn::Name name2("/ndn/test/name2");
   ndn::Name name3("/ndn/some/other/name1");
-
-  list1.insert(name1);
-  list1.insert(name2);
-  list1.insert(name3);
-
-  list2.insert(name1);
-  list2.insert(name2);
-  list2.insert(name3);
+  NamePrefixList list1{name1, name2, name3};
+  NamePrefixList list2{name1, name2, name3};
 
   BOOST_CHECK_EQUAL(list1, list2);
 }
@@ -75,13 +64,10 @@
  */
 BOOST_AUTO_TEST_CASE(GetNames)
 {
-  NamePrefixList list;
   const ndn::Name name1{"/ndn/test/prefix1"};
   const ndn::Name name2{"/ndn/test/prefix2"};
   const ndn::Name name3{"/ndn/test/prefix3"};
-  list.insert(name1);
-  list.insert(name2);
-  list.insert(name3);
+  NamePrefixList list{name1, name2, name3};
 
   std::vector<ndn::Name> referenceNames{name1, name2, name3};
 
@@ -103,9 +89,9 @@
  */
 BOOST_AUTO_TEST_CASE(countSources)
 {
-  NamePrefixList list;
   const ndn::Name name1{"/ndn/test/prefix1"};
   const ndn::Name invalidName{"/not/a/prefix"};
+  NamePrefixList list;
   list.insert(name1, "nlsr.conf");
   list.insert(name1, "readvertise");
   list.insert(name1, "prefix-update");
@@ -169,6 +155,40 @@
   }
 }
 
+BOOST_AUTO_TEST_CASE(BraceInitializerCtors)
+{
+  const ndn::Name name1{"/ndn/test/prefix1"};
+  const ndn::Name name2{"/ndn/test/prefix2"};
+  const ndn::Name name3{"/ndn/test/prefix3"};
+  std::list<ndn::Name> testList{name1, name2, name3};
+
+  const std::vector<std::string> sources1{"static", "readvertise"};
+  const std::vector<std::string> sources2{"static", "nlsrc"};
+  const std::vector<std::string> sources3{"static"};
+
+  NamePrefixList list1{name1, name2, name3};
+  auto list = list1.getNames();
+  BOOST_CHECK_EQUAL(list1.size(), 3);
+  BOOST_CHECK(testList == list);
+
+  NamePrefixList list2{ NamePrefixList::NamePair{name1, sources1},
+      NamePrefixList::NamePair{name2, sources2}, NamePrefixList::NamePair{name3, sources3} };
+  auto name1Sources = list2.getSources(name1);
+  BOOST_CHECK(sources1 == name1Sources);
+  auto name2Sources = list2.getSources(name2);
+  BOOST_CHECK(sources2 == name2Sources);
+  auto name3Sources = list2.getSources(name3);
+  BOOST_CHECK(sources3 == name3Sources);
+
+  const std::vector<ndn::Name> namesVector{name1, name2, name3};
+  NamePrefixList list3(namesVector);
+  BOOST_CHECK(list1 == list3);
+
+  const std::list<ndn::Name> namesList{name1, name2, name3};
+  NamePrefixList list4(namesList);
+  BOOST_CHECK(list1 == list4);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace test
diff --git a/tests/test-name-prefix-table.cpp b/tests/test-name-prefix-table.cpp
index 474585c..5322cb7 100644
--- a/tests/test-name-prefix-table.cpp
+++ b/tests/test-name-prefix-table.cpp
@@ -89,8 +89,7 @@
   // BUPT Name LSA
   ndn::Name buptAdvertisedName("/ndn/cn/edu/bupt");
 
-  NamePrefixList buptNames;
-  buptNames.insert(buptAdvertisedName);
+  NamePrefixList buptNames{buptAdvertisedName};
 
   NameLsa buptNameLsa(buptRouterName, 1, ndn::time::system_clock::now(),
                       buptNames);
diff --git a/tests/test-statistics.cpp b/tests/test-statistics.cpp
index bc029e1..b148cb2 100644
--- a/tests/test-statistics.cpp
+++ b/tests/test-statistics.cpp
@@ -248,8 +248,7 @@
                                    Statistics::PacketType::SENT_ADJ_LSA_DATA);
 
   // Name LSA
-  NamePrefixList prefixes;
-  prefixes.insert("/ndn/name");
+  NamePrefixList prefixes{ndn::Name{"/ndn/name"}};
 
   NameLsa nameLsa(routerName, seqNo, MAX_TIME, prefixes);
   lsdb.installNameLsa(nameLsa);