build: add PCHs for ndnsec and unit tests, fine-tune the existing ones

A full debug+tests build now takes 10% less time with gcc-9 and 21% less
with clang-10. Release builds (without tests) are only marginally faster
with gcc and 7% faster with clang.

Change-Id: I494778fe44cecc6209819a49f48a03f4d16c36af
diff --git a/tests/make-interest-data.cpp b/tests/make-interest-data.cpp
index 4031507..09d879b 100644
--- a/tests/make-interest-data.cpp
+++ b/tests/make-interest-data.cpp
@@ -30,7 +30,7 @@
 makeInterest(const Name& name, bool canBePrefix, time::milliseconds lifetime,
              optional<Interest::Nonce> nonce)
 {
-  auto interest = make_shared<Interest>(name, lifetime);
+  auto interest = std::make_shared<Interest>(name, lifetime);
   interest->setCanBePrefix(canBePrefix);
   interest->setNonce(nonce);
   return interest;
@@ -39,7 +39,7 @@
 shared_ptr<Data>
 makeData(const Name& name)
 {
-  auto data = make_shared<Data>(name);
+  auto data = std::make_shared<Data>(name);
   return signData(data);
 }
 
diff --git a/tests/test-home-fixture.hpp b/tests/test-home-fixture.hpp
index 38fd3f1..63d5d88 100644
--- a/tests/test-home-fixture.hpp
+++ b/tests/test-home-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2020 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -28,7 +28,7 @@
 #include <fstream>
 #include <initializer_list>
 
-#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/replace.hpp>
 #include <boost/filesystem.hpp>
 
 namespace ndn {
diff --git a/tests/tests-pch.hpp b/tests/tests-pch.hpp
new file mode 100644
index 0000000..a81f7bf
--- /dev/null
+++ b/tests/tests-pch.hpp
@@ -0,0 +1,37 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2020 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#ifndef NDN_TESTS_TESTS_PCH_HPP
+#define NDN_TESTS_TESTS_PCH_HPP
+
+#include "ndn-cxx/impl/common-pch.hpp"
+
+#include "ndn-cxx/data.hpp"
+#include "ndn-cxx/interest.hpp"
+#include "ndn-cxx/lp/nack.hpp"
+#include "ndn-cxx/security/v2/key-chain.hpp"
+
+#include "tests/boost-test.hpp"
+
+#include <fstream>
+#include <boost/filesystem.hpp>
+
+#endif // NDN_TESTS_TESTS_PCH_HPP
diff --git a/tests/unit/unit-tests-pch.hpp b/tests/unit/unit-tests-pch.hpp
new file mode 100644
index 0000000..54e15f9
--- /dev/null
+++ b/tests/unit/unit-tests-pch.hpp
@@ -0,0 +1,35 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2020 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#ifndef NDN_TESTS_UNIT_UNIT_TESTS_PCH_HPP
+#define NDN_TESTS_UNIT_UNIT_TESTS_PCH_HPP
+
+#include "tests/tests-pch.hpp"
+
+#include "ndn-cxx/face.hpp"
+#include "ndn-cxx/ims/in-memory-storage.hpp"
+#include "ndn-cxx/security/transform.hpp"
+#include "ndn-cxx/security/v2/validator.hpp"
+#include "ndn-cxx/util/config-file.hpp"
+
+#include "tests/identity-management-fixture.hpp"
+
+#endif // NDN_TESTS_UNIT_UNIT_TESTS_PCH_HPP
diff --git a/tests/unit/util/backports.t.cpp b/tests/unit/util/backports.t.cpp
index b73465b..2404d03 100644
--- a/tests/unit/util/backports.t.cpp
+++ b/tests/unit/util/backports.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2020 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -20,18 +20,9 @@
  */
 
 #include "ndn-cxx/util/backports.hpp"
-#include "ndn-cxx/util/ostream-joiner.hpp"
 
 #include "tests/boost-test.hpp"
 
-#include <numeric>
-
-#if BOOST_VERSION >= 105900
-#include <boost/test/tools/output_test_stream.hpp>
-#else
-#include <boost/test/output_test_stream.hpp>
-#endif
-
 namespace ndn {
 namespace tests {
 
@@ -59,40 +50,6 @@
   BOOST_CHECK_EQUAL(x, 10);
 }
 
-BOOST_AUTO_TEST_CASE(OstreamJoiner)
-{
-  boost::test_tools::output_test_stream os;
-
-  auto joiner1 = ostream_joiner<char>(os, ' ');
-  auto joiner2 = make_ostream_joiner(os, ' ');
-  static_assert(std::is_same<decltype(joiner1), decltype(joiner2)>::value, "");
-
-  std::vector<int> v(5);
-  std::iota(v.begin(), v.end(), 1);
-  std::copy(v.begin(), v.end(), joiner2);
-  BOOST_CHECK(os.is_equal("1 2 3 4 5"));
-
-  auto joiner3 = make_ostream_joiner(os, "...");
-  std::copy(v.begin(), v.end(), joiner3);
-  BOOST_CHECK(os.is_equal("1...2...3...4...5"));
-
-  joiner3 = "one";
-  BOOST_CHECK(os.is_equal("one"));
-  joiner3 = "two";
-  BOOST_CHECK(os.is_equal("...two"));
-  ++joiner3 = "three";
-  BOOST_CHECK(os.is_equal("...three"));
-  joiner3++ = "four";
-  BOOST_CHECK(os.is_equal("...four"));
-
-  std::copy(v.begin(), v.end(), make_ostream_joiner(os, ""));
-  BOOST_CHECK(os.is_equal("12345"));
-
-  std::string delimiter("_");
-  std::copy(v.begin(), v.end(), make_ostream_joiner(os, delimiter));
-  BOOST_CHECK(os.is_equal("1_2_3_4_5"));
-}
-
 BOOST_AUTO_TEST_SUITE_END() // TestBackports
 BOOST_AUTO_TEST_SUITE_END() // Util
 
diff --git a/tests/unit/util/ostream-joiner.t.cpp b/tests/unit/util/ostream-joiner.t.cpp
new file mode 100644
index 0000000..2eaf2f9
--- /dev/null
+++ b/tests/unit/util/ostream-joiner.t.cpp
@@ -0,0 +1,78 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2020 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "ndn-cxx/util/ostream-joiner.hpp"
+
+#include "tests/boost-test.hpp"
+
+#include <numeric>
+
+#if BOOST_VERSION >= 105900
+#include <boost/test/tools/output_test_stream.hpp>
+#else
+#include <boost/test/output_test_stream.hpp>
+#endif
+
+namespace ndn {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(Util)
+BOOST_AUTO_TEST_SUITE(TestOstreamJoiner)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+  boost::test_tools::output_test_stream os;
+
+  auto joiner1 = ostream_joiner<char>(os, ' ');
+  auto joiner2 = make_ostream_joiner(os, ' ');
+  static_assert(std::is_same<decltype(joiner1), decltype(joiner2)>::value, "");
+
+  std::vector<int> v(5);
+  std::iota(v.begin(), v.end(), 1);
+  std::copy(v.begin(), v.end(), joiner2);
+  BOOST_CHECK(os.is_equal("1 2 3 4 5"));
+
+  auto joiner3 = make_ostream_joiner(os, "...");
+  std::copy(v.begin(), v.end(), joiner3);
+  BOOST_CHECK(os.is_equal("1...2...3...4...5"));
+
+  joiner3 = "one";
+  BOOST_CHECK(os.is_equal("one"));
+  joiner3 = "two";
+  BOOST_CHECK(os.is_equal("...two"));
+  ++joiner3 = "three";
+  BOOST_CHECK(os.is_equal("...three"));
+  joiner3++ = "four";
+  BOOST_CHECK(os.is_equal("...four"));
+
+  std::copy(v.begin(), v.end(), make_ostream_joiner(os, ""));
+  BOOST_CHECK(os.is_equal("12345"));
+
+  std::string delimiter("_");
+  std::copy(v.begin(), v.end(), make_ostream_joiner(os, delimiter));
+  BOOST_CHECK(os.is_equal("1_2_3_4_5"));
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestOstreamJoiner
+BOOST_AUTO_TEST_SUITE_END() // Util
+
+} // namespace tests
+} // namespace ndn
diff --git a/tests/unit/wscript b/tests/unit/wscript
index bc7ce0f..e91ac7f 100644
--- a/tests/unit/wscript
+++ b/tests/unit/wscript
@@ -1,6 +1,6 @@
 # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
 
-top = '../..'
+top = '../../'
 
 def build(bld):
     configPath = 'UNIT_TEST_CONFIG_PATH="%s"' % bld.bldnode.make_node('tmp-files')
@@ -18,11 +18,13 @@
 
     bld.objects(target='unit-tests-objects',
                 source=srcFiles,
+                features='pch',
+                headers='unit-tests-pch.hpp',
                 use='tests-common',
                 defines=[configPath])
 
     # unit test binary
-    bld.program(target='../../unit-tests',
+    bld.program(target=top + 'unit-tests',
                 name='unit-tests',
                 source=['main.cpp'],
                 use='unit-tests-objects',
diff --git a/tests/wscript b/tests/wscript
index d343b1a..d7401ca 100644
--- a/tests/wscript
+++ b/tests/wscript
@@ -1,13 +1,13 @@
 # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
 
-top = '..'
+top = '../'
 
 def build(bld):
     # common objects that can be shared among all tests
     bld.objects(target='tests-common',
-                features='pch',
                 source=bld.path.ant_glob('*.cpp'),
-                headers=['../ndn-cxx/impl/common-pch.hpp', 'boost-test.hpp'],
+                features='pch',
+                headers='tests-pch.hpp',
                 use='ndn-cxx BOOST')
 
     bld.recurse('benchmarks')