forked from cawka/ndn.cxx
diff --git a/test/event-scheduler-tests.cc b/test/event-scheduler-tests.cc
new file mode 100644
index 0000000..fab5b76
--- /dev/null
+++ b/test/event-scheduler-tests.cc
@@ -0,0 +1,177 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ *                     Zhenkai Zhu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "scheduler/scheduler-all.h"
+
+#include <boost/test/unit_test.hpp>
+#include <boost/make_shared.hpp>
+#include <map>
+#include <unistd.h>
+
+using namespace boost;
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(SchedulerTests)
+
+map<string, int> table;
+
+void func(string str)
+{
+  map<string, int>::iterator it = table.find(str);
+  if (it == table.end())
+  {
+    table.insert(make_pair(str, 1));
+  }
+  else
+  {
+    int count = it->second;
+    count++;
+    table.erase(it);
+    table.insert(make_pair(str, count));
+  }
+}
+
+bool
+matcher(const TaskPtr &task)
+{
+  return task->tag() == "period" || task->tag() == "world";
+}
+
+BOOST_AUTO_TEST_CASE(SchedulerTest)
+{
+  SchedulerPtr scheduler(new Scheduler());
+  IntervalGeneratorPtr generator(new SimpleIntervalGenerator(0.2));
+
+  string tag1 = "hello";
+  string tag2 = "world";
+  string tag3 = "period";
+
+  TaskPtr task1(new OneTimeTask(boost::bind(func, tag1), tag1, scheduler, 0.5));
+  TaskPtr task2(new OneTimeTask(boost::bind(func, tag2), tag2, scheduler, 0.5));
+  TaskPtr task3(new PeriodicTask(boost::bind(func, tag3), tag3, scheduler, generator));
+
+  scheduler->start();
+  scheduler->addTask(task1);
+  scheduler->addTask(task2);
+  scheduler->addTask(task3);
+  BOOST_CHECK_EQUAL(scheduler->size(), 3);
+  usleep(600000);
+  BOOST_CHECK_EQUAL(scheduler->size(), 1);
+  scheduler->addTask(task1);
+  BOOST_CHECK_EQUAL(scheduler->size(), 2);
+  usleep(600000);
+  scheduler->addTask(task1);
+  BOOST_CHECK_EQUAL(scheduler->size(), 2);
+  usleep(400000);
+  scheduler->deleteTask(task1->tag());
+  BOOST_CHECK_EQUAL(scheduler->size(), 1);
+  usleep(200000);
+
+  scheduler->addTask(task1);
+  scheduler->addTask(task2);
+  BOOST_CHECK_EQUAL(scheduler->size(), 3);
+  usleep(100000);
+  scheduler->deleteTask(bind(matcher, _1));
+  BOOST_CHECK_EQUAL(scheduler->size(), 1);
+  usleep(1000000);
+
+  BOOST_CHECK_EQUAL(scheduler->size(), 0);
+  scheduler->addTask(task1);
+  usleep(400000);
+  BOOST_CHECK_EQUAL(scheduler->size(), 1);
+  scheduler->rescheduleTask(task1);
+  usleep(400000);
+  BOOST_CHECK_EQUAL(scheduler->size(), 1);
+  usleep(110000);
+  BOOST_CHECK_EQUAL(scheduler->size(), 0);
+
+
+  int hello = 0, world = 0, period = 0;
+
+  map<string, int>::iterator it;
+  it = table.find(tag1);
+  if (it != table.end())
+  {
+    hello = it->second;
+  }
+  it = table.find(tag2);
+  if (it != table.end())
+  {
+    world = it->second;
+  }
+  it = table.find(tag3);
+  if (it != table.end())
+  {
+    period = it->second;
+  }
+
+  // added five times, canceled once before invoking callback
+  BOOST_CHECK_EQUAL(hello, 4);
+  // added two times, canceled once by matcher before invoking callback
+  BOOST_CHECK_EQUAL(world, 1);
+  // invoked every 0.2 seconds before deleted by matcher
+  BOOST_CHECK_EQUAL(period, static_cast<int>((0.6 + 0.6 + 0.4 + 0.2 + 0.1) / 0.2));
+
+  scheduler->shutdown();
+}
+
+void reschedule();
+SchedulerPtr schd0(new Scheduler());
+int resCount;
+TaskPtr task0(new PeriodicTask(boost::bind(reschedule), "testtest", schd0, boost::make_shared<SimpleIntervalGenerator>(0.5)));
+void reschedule()
+{
+  schd0->rescheduleTask(task0);
+  resCount++;
+}
+
+BOOST_AUTO_TEST_CASE(RescheduleTest)
+{
+  resCount = 0;
+  schd0->start();
+  schd0->addTask(task0);
+  usleep(5100000);
+  BOOST_CHECK_EQUAL(resCount, 10);
+  schd0->shutdown();
+}
+
+BOOST_AUTO_TEST_CASE(GeneratorTest)
+{
+  double interval = 10;
+  double percent = 0.5;
+  int times = 10000;
+  IntervalGeneratorPtr generator(new RandomIntervalGenerator(interval, percent));
+  double sum = 0.0;
+  double min = 2 * interval;
+  double max = -1;
+  for (int i = 0; i < times; i++)
+  {
+    double next = generator->nextInterval();
+    sum += next;
+    if (next > max)
+    {
+      max = next;
+    }
+    if (next < min)
+    {
+      min = next;
+    }
+  }
+
+  BOOST_CHECK( abs(1.0 - (sum / static_cast<double>(times)) / interval) < 0.05);
+  BOOST_CHECK( min > interval * (1 - percent / 2.0));
+  BOOST_CHECK( max < interval * (1 + percent / 2.0));
+  BOOST_CHECK( abs(1.0 - ((max - min) / interval) / percent) < 0.05);
+
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/exclude-tests.cc b/test/exclude-tests.cc
new file mode 100644
index 0000000..882f5a6
--- /dev/null
+++ b/test/exclude-tests.cc
@@ -0,0 +1,104 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndn-cpp/fields/exclude.h"
+#include "ndn-cpp/error.h"
+
+#include <boost/test/unit_test.hpp>
+
+#include <boost/lexical_cast.hpp>
+
+using namespace ndn;
+using namespace std;
+using namespace boost;
+
+BOOST_AUTO_TEST_SUITE(ExcludeTests)
+
+BOOST_AUTO_TEST_CASE (Basic)
+{
+  Exclude e;
+  e.excludeOne (string ("b"));
+  BOOST_CHECK_EQUAL (e.size (), 1);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), "b ");
+
+  e.excludeOne (string ("d"));
+  BOOST_CHECK_EQUAL (e.size (), 2);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), "b d ");
+
+  e.excludeOne (string ("a"));
+  BOOST_CHECK_EQUAL (e.size (), 3);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), "a b d ");
+
+  e.excludeOne (string ("aa"));
+  BOOST_CHECK_EQUAL (e.size (), 4);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), "a b d aa ");
+
+  e.excludeOne (string ("cc"));
+  BOOST_CHECK_EQUAL (e.size (), 5);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), "a b d aa cc ");
+
+  e.excludeOne (string ("c"));
+  BOOST_CHECK_EQUAL (e.size (), 6);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), "a b c d aa cc ");
+}
+
+BOOST_AUTO_TEST_CASE (Ranges)
+{
+// example: ANY /b /d ANY /f
+
+  Exclude e;
+  e.excludeOne (string ("b0"));
+  BOOST_CHECK_EQUAL (e.size (), 1);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), "b0 ");
+
+  e.excludeRange (name::Component (), string ("b1"));
+  BOOST_CHECK_EQUAL (e.size (), 2);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> b1 ");
+
+  e.excludeRange (name::Component (), string ("c0"));
+  BOOST_CHECK_EQUAL (e.size (), 2);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> c0 ");
+
+  e.excludeRange (string ("a0"), string ("c0"));
+  BOOST_CHECK_EQUAL (e.size (), 2);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> c0 ");
+
+  e.excludeRange (string ("d0"), string ("e0"));
+  BOOST_CHECK_EQUAL (e.size (), 4);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> c0 d0 ----> e0 ");
+
+  e.excludeRange (string ("c1"), string ("d1"));
+  BOOST_CHECK_EQUAL (e.size (), 4);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> c0 c1 ----> e0 ");
+
+  e.excludeRange (string ("a1"), string ("d1"));
+  BOOST_CHECK_EQUAL (e.size (), 2);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> e0 ");
+
+  e.excludeBefore (string ("e2"));
+  BOOST_CHECK_EQUAL (e.size (), 2);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> e2 ");
+
+  e.excludeAfter (string ("f0"));
+  BOOST_CHECK_EQUAL (e.size (), 3);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> e2 f0 ----> ");
+
+  e.excludeAfter (string ("e5"));
+  BOOST_CHECK_EQUAL (e.size (), 3);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> e2 e5 ----> ");
+
+  e.excludeAfter (string ("b2"));
+  BOOST_CHECK_EQUAL (e.size (), 1);
+  BOOST_CHECK_EQUAL (lexical_cast<string> (e), " ----> ");
+
+  BOOST_REQUIRE_THROW (e.excludeRange (string ("d0"), string ("a0")), error::Exclude);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/executor-tests.cc b/test/executor-tests.cc
new file mode 100644
index 0000000..273f0c2
--- /dev/null
+++ b/test/executor-tests.cc
@@ -0,0 +1,72 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ *                     Zhenkai Zhu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include <boost/test/unit_test.hpp>
+#include "executor/executor.h"
+
+#include "logging.h"
+
+INIT_LOGGER ("Test.Executor");
+
+using namespace boost;
+using namespace std;
+
+void timeConsumingJob ()
+{
+  _LOG_DEBUG ("Start sleep");
+  sleep(1);
+  _LOG_DEBUG ("Finish sleep");
+}
+
+BOOST_AUTO_TEST_CASE(TestExecutor)
+{
+  INIT_LOGGERS ();
+
+  {
+    Executor executor (3);
+    executor.start ();
+    Executor::Job job = bind(timeConsumingJob);
+
+    executor.execute(job);
+    executor.execute(job);
+
+    usleep(2000);
+    // both jobs should have been taken care of
+    BOOST_CHECK_EQUAL(executor.jobQueueSize(), 0);
+
+    usleep(500000);
+
+    // add four jobs while only one thread is idle
+    executor.execute(job);
+    executor.execute(job);
+    executor.execute(job);
+    executor.execute(job);
+
+    usleep(1000);
+    // three jobs should remain in queue
+    BOOST_CHECK_EQUAL(executor.jobQueueSize(), 3);
+
+    usleep(500000);
+    // two threads should have finished and
+    // take care of two queued jobs
+    BOOST_CHECK_EQUAL(executor.jobQueueSize(), 1);
+
+    // all jobs should have been fetched
+    usleep(501000);
+    BOOST_CHECK_EQUAL(executor.jobQueueSize(), 0);
+
+    executor.shutdown ();
+  } //separate scope to ensure that destructor is called
+
+
+  sleep(1);
+}
diff --git a/test/interest-tests.cc b/test/interest-tests.cc
new file mode 100644
index 0000000..7e56fd1
--- /dev/null
+++ b/test/interest-tests.cc
@@ -0,0 +1,95 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndn-cpp/wire/ccnb.h"
+#include "ndn-cpp/interest.h"
+
+#include <unistd.h>
+#include <fstream>
+
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/make_shared.hpp>
+
+#include "logging.h"
+
+using namespace ndn;
+using namespace std;
+using namespace boost;
+
+BOOST_AUTO_TEST_SUITE(InterestTests)
+
+static const string Interest1 ("\x01\xD2\xF2\x00\x05\x9A\x8E\x32\x00\x05\xA2\x8E\x32\x00\x05\xAA\x8E\x31\x00\x02"
+                               "\xFA\x8E\x34\x00\x02\xD2\x8E\x30\x00\x03\x82\x95\xA0\x00\x00\x00",
+                               36);
+
+static const string Interest2 ("\x01\xD2\xF2\x00\x05\x9A\x8E\x32\x00\x05\xA2\x8E\x32\x00\x03\x82\x95\xA0\x00\x00"
+                               "\x00",
+                               21);
+
+static const string Interest3 ("\x01\xD2\xF2\x00\x05\x9A\x8E\x32\x00\x05\xA2\x8E\x32\x00\x02\xDA\xFA\xA5\x61\x6C" \
+                               "\x65\x78\x00\xFA\xC5\x7A\x68\x65\x6E\x6B\x61\x69\x30\x00\xEA\x00\xFA\xC5\x7A\x68" \
+                               "\x65\x6E\x6B\x61\x69\x31\x00\xFA\x01\x8D\x6C\x6F\x6F\x6F\x6F\x6F\x6F\x6F\x6F\x6F" \
+                               "\x6F\x6F\x6F\x6F\x6F\x6E\x67\x00\xEA\x00\x00\x05\xAA\x8E\x31\x00\x02\xFA\x8E\x34" \
+                               "\x00\x02\xD2\x8E\x30\x00\x03\x82\x95\xA0\x00\x00\x00", 93);
+
+BOOST_AUTO_TEST_CASE (Basic)
+{
+  INIT_LOGGERS ();
+  
+  Interest i;
+  i.setName (Name ("/test"));
+  i.setMinSuffixComponents (2);
+  i.setMaxSuffixComponents (2);
+  i.setInterestLifetime (posix_time::seconds (10));
+  i.setScope (Interest::SCOPE_LOCAL_CCND);
+  i.setAnswerOriginKind (Interest::AOK_STALE);
+  i.setChildSelector (Interest::CHILD_RIGHT);
+  // i.setPublisherPublicKeyDigest (?);
+
+  ostringstream os;
+  wire::Ccnb::appendInterest (os, i);
+  string Interest0 = os.str ();
+  BOOST_CHECK_EQUAL_COLLECTIONS (Interest0.begin (), Interest0.end (),
+                                 Interest1.begin (), Interest1.end ());
+
+  i.getExclude ().excludeOne (name::Component ("alex"));
+  i.getExclude ().excludeRange (name::Component ("zhenkai0"), name::Component("zhenkai1"));
+  i.getExclude ().excludeAfter (name::Component ("loooooooooooooong"));
+
+  BOOST_CHECK_EQUAL (boost::lexical_cast<string> (i.getExclude ()), "alex zhenkai0 ----> zhenkai1 loooooooooooooong ----> ");
+
+  os.str (""); os.clear ();
+  wire::Ccnb::appendInterest (os, i);
+  Interest0 = os.str ();
+  BOOST_CHECK_EQUAL_COLLECTIONS (Interest0.begin (), Interest0.end (),
+                                 Interest3.begin (), Interest3.end ());
+}
+
+// BOOST_AUTO_TEST_CASE (Charbuf)
+// {
+//   INIT_LOGGERS ();
+
+//   Interest i;
+//   i.setName (Name ("/test"));
+//   i.setMinSuffixComponents (2);
+//   i.setMaxSuffixComponents (2);
+//   i.setInterestLifetime (posix_time::seconds (10));
+
+//   charbuf_stream stream;
+//   wire::Ccnb::appendInterest (stream, i);
+
+//   BOOST_CHECK_EQUAL_COLLECTIONS (reinterpret_cast<char*> (stream.buf ().getBuf ()->buf),
+//                                  reinterpret_cast<char*> (stream.buf ().getBuf ()->buf+stream.buf ().getBuf ()->length),
+//                                  Interest2.begin (), Interest2.end ());
+  
+// }
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/name-tests.cc b/test/name-tests.cc
new file mode 100644
index 0000000..1431f79
--- /dev/null
+++ b/test/name-tests.cc
@@ -0,0 +1,162 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ *                     Zhenkai Zhu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include <sstream>
+#include "ndn-cpp/fields/name.h"
+#include "ndn-cpp/fields/name-component.h"
+#include "ndn-cpp/error.h"
+#include "ndn-cpp/wire/ccnb.h"
+
+#define BOOST_TEST_MAIN 1
+
+#include <boost/test/unit_test.hpp>
+
+using namespace ndn;
+using namespace std;
+using namespace boost;
+
+BOOST_AUTO_TEST_SUITE(NameTests)
+
+BOOST_AUTO_TEST_CASE (Component)
+{
+  name::Component x;
+  BOOST_CHECK_EQUAL (x.size (), 0);
+
+  x = name::Component ("test");
+  BOOST_CHECK_EQUAL (x.size (), 4);
+
+  x = name::Component ("%21test");
+  BOOST_CHECK_EQUAL (x.size (), 5);
+
+  BOOST_CHECK_EQUAL (x.toUri (), "!test");
+
+  x = name::Component ("%20test");
+  BOOST_CHECK_EQUAL (x.size (), 5);
+
+  BOOST_CHECK_EQUAL (x.toUri (), "%20test");
+}
+
+BOOST_AUTO_TEST_CASE (Basic)
+{
+  Name empty = Name ();
+  Name root = Name ("/");
+  BOOST_CHECK_EQUAL (empty, root);
+  BOOST_CHECK_EQUAL (empty, Name ("/"));
+  BOOST_CHECK_EQUAL (root.size(), 0);
+
+  empty.append ("hello");
+  empty.append ("world");
+  BOOST_CHECK_EQUAL (empty.size(), 2);
+  BOOST_CHECK_EQUAL (empty.toUri(), "/hello/world");
+  empty = empty + root;
+  BOOST_CHECK_EQUAL (empty.toUri(), "/hello/world");
+  BOOST_CHECK_EQUAL (empty.get (0).toUri (), "hello");
+  BOOST_CHECK_EQUAL (empty.getSubName(1, 1), Name("/world"));
+  Name name("/hello/world");
+  BOOST_CHECK_EQUAL (empty, name);
+  BOOST_CHECK_EQUAL (name, Name("/hello") + Name("/world"));
+
+  name.appendSeqNum (1);
+  name.appendSeqNum (255);
+  name.appendSeqNum (256);
+  name.appendSeqNum (1234567890);
+
+  BOOST_CHECK_EQUAL (name.toUri (), "/hello/world/%00%01/%00%FF/%00%01%00/%00I%96%02%D2");
+
+  BOOST_CHECK_EQUAL (name.get (5).toSeqNum (), 1234567890);
+  BOOST_CHECK_EQUAL (name.get (4).toSeqNum (), 256);
+  BOOST_CHECK_EQUAL (name.get (3).toSeqNum (), 255);
+  BOOST_CHECK_EQUAL (name.get (2).toSeqNum (), 1);
+
+  BOOST_CHECK_EQUAL (name.get (-1).toUri (), "%00I%96%02%D2");
+
+  BOOST_CHECK_EQUAL (Name ("/%00").get (0).toSeqNum (), 0);
+
+  const char tmp [] = {0, 1, 2, 3, 0x50};
+  BOOST_CHECK_EQUAL (Name ().append (tmp, sizeof(tmp)).toUri (), "/%00%01%02%03P");
+
+  string entree("entr\u00E9e");
+  BOOST_CHECK_EQUAL (Name ().append (entree.c_str(), entree.size()).toUri (), "/entr%C3%A9e");
+  Name entreeName("/entr%C3%A9e");
+  BOOST_CHECK_EQUAL_COLLECTIONS (entreeName.get(0).begin(), entreeName.get(0).end(), entree.begin(), entree.end() );
+
+  Name appendName ("/hello/you");
+  appendName.append (Name ("/hello/you/too"));
+  BOOST_CHECK_EQUAL (appendName.toUri (), "/hello/you/hello/you/too");
+
+  Name appendSelf ("/hello/you");
+  appendSelf.append (appendSelf);
+  BOOST_CHECK_EQUAL (appendSelf.toUri (), "/hello/you/hello/you");
+
+  Name withVersion ("/hello.txt/%FD%95-%25U1%DE%04/%00%01");
+  BOOST_REQUIRE_NO_THROW (withVersion.get (1).toVersion ());
+  BOOST_CHECK_EQUAL (withVersion.get (1).toVersion (), 1370203370106261);
+  
+  BOOST_CHECK_EQUAL (Name("/!").toUri(), "/%21");
+}
+
+BOOST_AUTO_TEST_CASE (Advanced)
+{
+  BOOST_REQUIRE_THROW (Name (""),       error::Name);
+  BOOST_REQUIRE_THROW (Name ("//"), error::Name);
+  BOOST_REQUIRE_THROW (Name ("ndn://"), error::Name);
+  BOOST_REQUIRE_THROW (Name ("bla"),    error::Name);
+  BOOST_REQUIRE_THROW (Name ("bla/"),   error::Name);
+  BOOST_REQUIRE_THROW (Name ("http:/test"), error::Name);
+
+  BOOST_CHECK_EQUAL (Name ("ndn:///").toUri (), "/");
+  BOOST_CHECK_EQUAL (Name ("ccnx:///").toUri (), "/");
+  BOOST_CHECK_EQUAL (Name ("/").toUri (), "/");
+  BOOST_CHECK_EQUAL (Name ("///").toUri (), "/");
+  BOOST_CHECK_EQUAL (Name ("////////////////////////////////////////////////").toUri (), "/");
+  BOOST_CHECK_EQUAL (Name ("ndn://bla:random@something-else:0000/actual/name").toUri (), "/actual/name");
+  BOOST_CHECK_EQUAL (Name ("/slash/").toUri (), "/slash");
+  
+  BOOST_CHECK_EQUAL (Name ().append (".", 1).toUri (), "/...");
+  BOOST_CHECK_EQUAL (Name ("/.").get(0).size(), 0);
+  BOOST_CHECK_EQUAL (Name ("/..").get(0).size(), 0);
+  BOOST_CHECK_EQUAL (Name ("/...").get(0).size(), 0);
+  BOOST_CHECK_EQUAL (Name ("/....").get(0).size(), 1);
+  
+  BOOST_CHECK_EQUAL (Name ().append ("", 0).toUri (), "/...");
+  const char tmp [] = {'.'};
+  BOOST_CHECK_EQUAL (Name ().append (tmp, sizeof(tmp)).toUri (), "/....");
+}
+
+BOOST_AUTO_TEST_CASE (Ordering)
+{
+  // check "canonical" ordering
+  BOOST_CHECK_EQUAL (Name ("/test"), Name ("/test"));
+  BOOST_CHECK_GE (Name ("/test"), Name ("/aaaa"));
+  BOOST_CHECK_GT (Name ("/test"), Name ("/aaaa"));
+  BOOST_CHECK_GT (Name ("/test/test/test"), Name ("/test/test"));
+  BOOST_CHECK_GE (Name ("/test/test/test"), Name ("/test/test"));
+  BOOST_CHECK_GE (Name ("/test/test/test"), Name ("/test/test/test"));
+
+  BOOST_CHECK_LE (Name ("/test"), Name ("/aaaaa"));
+  BOOST_CHECK_LT (Name ("/test"), Name ("/aaaaa"));
+  BOOST_CHECK_LT (Name ("/test/test"), Name ("/test/test/test"));
+  BOOST_CHECK_LE (Name ("/test/test"), Name ("/test/test/test"));
+  BOOST_CHECK_LE (Name ("/test/test/test"), Name ("/test/test/test"));
+}
+
+BOOST_AUTO_TEST_CASE (Encoding)
+{
+  std::stringbuf buffer;
+  std::ostream output (&buffer);
+
+  Name root = Name ("/");
+  wire::Ccnb::appendName(output, root);
+  BOOST_CHECK_EQUAL (buffer.str().size(), 2);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/security-tests.cc b/test/security-tests.cc
new file mode 100644
index 0000000..ec8415c
--- /dev/null
+++ b/test/security-tests.cc
@@ -0,0 +1,40 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ *                     Zhenkai Zhu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+// #include "platforms/osx/keychain-osx.h"
+#include "ndn-cpp/error.h"
+
+#include <boost/test/unit_test.hpp>
+
+#include <fstream>
+
+using namespace ndn;
+using namespace std;
+using namespace boost;
+
+BOOST_AUTO_TEST_SUITE(SecurityTests)
+
+BOOST_AUTO_TEST_CASE (Basic)
+{
+  // Ptr<Keychain> keychain;
+  // BOOST_CHECK_NO_THROW (keychain = Ptr<keychain::OSX>::Create ());
+
+  // Name keyName ("/my/private/key1");
+  // keychain->generateKeyPair (keyName);
+  // // keychain->deleteKeyPair (keyName);
+
+  // Ptr<Blob> key = keychain->getPublicKey (keyName);
+  // ofstream f ("out.pub");
+  // f.write (key->buf (), key->size ());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/test-boost-header-only.cpp b/test/test-boost-header-only.cpp
new file mode 100644
index 0000000..ebc8553
--- /dev/null
+++ b/test/test-boost-header-only.cpp
@@ -0,0 +1,36 @@
+/* 
+ * File:   test-no-boost.cpp
+ * Author: jefft0
+ *
+ * Created on June 10, 2013, 4:21 PM
+ */
+
+#include <cstdlib>
+#include <sstream>
+#include "ndn-cpp/fields/name.h"
+#include "ndn-cpp/fields/name-component.h"
+#include "ndn-cpp/interest.h"
+#include "ndn-cpp/wire/ccnb.h"
+
+using namespace std;
+using namespace ndn;
+
+/*
+ * 
+ */
+int main(int argc, char** argv) {
+  Interest interest;
+  interest.setName(Name("/test"));
+  interest.setMinSuffixComponents(2);
+  interest.setMaxSuffixComponents(2);
+  interest.setInterestLifetime(boost::posix_time::seconds(10));
+  interest.setScope(Interest::SCOPE_LOCAL_CCND);
+  interest.setAnswerOriginKind(Interest::AOK_STALE);
+  interest.setChildSelector(Interest::CHILD_RIGHT);
+  // i.setPublisherPublicKeyDigest(?);
+  ostringstream binary;
+  wire::Ccnb::appendInterest(binary, interest);
+  cout << binary.str().size();
+    
+  return 0;
+}