cs-smoketest: data.wireEncode() before CS insert

refs #2217

Change-Id: Id93d8ab5df4228cf156c53f21891c9b9efb64698
diff --git a/tests/other/cs-smoketest.cpp b/tests/other/cs-smoketest.cpp
index 57c92ef..1fc97c9 100644
--- a/tests/other/cs-smoketest.cpp
+++ b/tests/other/cs-smoketest.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014,  Regents of the University of California,
+ *                      Arizona Board of Regents,
+ *                      Colorado State University,
+ *                      University Pierre & Marie Curie, Sorbonne University,
+ *                      Washington University in St. Louis,
+ *                      Beijing Institute of Technology,
+ *                      The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,15 +21,14 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- *
- * \author Ilya Moiseenko <iliamo@ucla.edu>
- **/
+ */
 
 #include "table/cs.hpp"
 #include "table/cs-entry.hpp"
 #include <ndn-cxx/security/key-chain.hpp>
 
 namespace nfd {
+namespace cs_smoketest {
 
 static void
 runStressTest()
@@ -41,70 +41,71 @@
                                         reinterpret_cast<const uint8_t*>(0), 0));
 
   // 182 MB in memory
-  for (int i = 0; i < 70000; i++)
-    {
-      Name name("/stress/test");
-      name.appendNumber(i % 4);
-      name.appendNumber(i);
+  for (int i = 0; i < 70000; i++) {
+    Name name("/stress/test");
+    name.appendNumber(i % 4);
+    name.appendNumber(i);
 
-      shared_ptr<Interest> interest = make_shared<Interest>(name);
-      interestWorkload[i] = interest;
+    shared_ptr<Interest> interest = make_shared<Interest>(name);
+    interestWorkload[i] = interest;
 
-      shared_ptr<Data> data = make_shared<Data>(name);
-      data->setSignature(fakeSignature);
-      dataWorkload[i] = data;
-    }
+    shared_ptr<Data> data = make_shared<Data>(name);
+    data->setSignature(fakeSignature);
+    dataWorkload[i] = data;
+  }
 
   time::duration<double, boost::nano> previousResult(0);
 
-  for (size_t nInsertions = 1000; nInsertions < 10000000; nInsertions *= 2)
-    {
-      Cs cs;
-      srand(time::toUnixTimestamp(time::system_clock::now()).count());
+  for (size_t nInsertions = 1000; nInsertions < 10000000; nInsertions *= 2) {
+    Cs cs;
+    srand(time::toUnixTimestamp(time::system_clock::now()).count());
 
-      time::steady_clock::TimePoint startTime = time::steady_clock::now();
+    time::steady_clock::TimePoint startTime = time::steady_clock::now();
 
-      size_t workloadCounter = 0;
-      for (size_t i = 0; i < nInsertions; i++)
-        {
-          if (workloadCounter > 69999)
-            workloadCounter = 0;
+    size_t workloadCounter = 0;
+    for (size_t i = 0; i < nInsertions; i++) {
+      if (workloadCounter > 69999)
+        workloadCounter = 0;
 
-          cs.find(*interestWorkload[workloadCounter]);
-          cs.insert(*dataWorkload[workloadCounter]);
+      cs.find(*interestWorkload[workloadCounter]);
+      Data& data = *dataWorkload[workloadCounter];
+      data.setName(data.getName()); // reset data.m_fullName
+      data.wireEncode();
+      cs.insert(data);
 
-          workloadCounter++;
-        }
-
-      time::steady_clock::TimePoint endTime = time::steady_clock::now();
-
-      time::duration<double, boost::nano> runDuration = endTime - startTime;
-      time::duration<double, boost::nano> perOperationTime = runDuration / nInsertions;
-
-      std::cout << "nItem = " << nInsertions << std::endl;
-      std::cout << "Total running time = "
-                << time::duration_cast<time::duration<double> >(runDuration)
-                << std::endl;
-      std::cout << "Average per-operation time = "
-                << time::duration_cast<time::duration<double, boost::micro> >(perOperationTime)
-                << std::endl;
-
-      if (previousResult > time::nanoseconds(1))
-        std::cout << "Change compared to the previous: "
-                  << (100.0 * perOperationTime / previousResult) << "%" << std::endl;
-
-      std::cout << "\n=================================\n" << std::endl;
-
-      previousResult = perOperationTime;
+      workloadCounter++;
     }
+
+    time::steady_clock::TimePoint endTime = time::steady_clock::now();
+
+    time::duration<double, boost::nano> runDuration = endTime - startTime;
+    time::duration<double, boost::nano> perOperationTime = runDuration / nInsertions;
+
+    std::cout << "nItem = " << nInsertions << std::endl;
+    std::cout << "Total running time = "
+              << time::duration_cast<time::duration<double> >(runDuration)
+              << std::endl;
+    std::cout << "Average per-operation time = "
+              << time::duration_cast<time::duration<double, boost::micro> >(perOperationTime)
+              << std::endl;
+
+    if (previousResult > time::nanoseconds(1))
+      std::cout << "Change compared to the previous: "
+                << (100.0 * perOperationTime / previousResult) << "%" << std::endl;
+
+    std::cout << "\n=================================\n" << std::endl;
+
+    previousResult = perOperationTime;
+  }
 }
 
+} // namespace cs_smoketest
 } // namespace nfd
 
 int
 main(int argc, char** argv)
 {
-  nfd::runStressTest();
+  nfd::cs_smoketest::runStressTest();
 
   return 0;
 }