API change for closure. Return ParsedContentObject, not just content
Fixed bug in test/test-sync-core.cc: there should have been two independent schedulers
diff --git a/test/test-ccnx-tunnel.cc b/test/test-ccnx-tunnel.cc
deleted file mode 100644
index 724d6e5..0000000
--- a/test/test-ccnx-tunnel.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-#include "ccnx-tunnel.h"
-#include "ccnx-closure.h"
-#include "ccnx-name.h"
-#include "ccnx-pco.h"
-#include <unistd.h>
-
-#include <boost/test/unit_test.hpp>
-
-
-using namespace Ccnx;
-using namespace std;
-using namespace boost;
-
-BOOST_AUTO_TEST_SUITE(CcnxTunnelTests)
-
-class DummyTunnel : public CcnxTunnel
-{
-public:
- DummyTunnel();
- virtual ~DummyTunnel() {}
-
- virtual Name
- queryRoutableName(const Name &name);
-
- void
- overridePrefix();
-
-};
-
-DummyTunnel::DummyTunnel() : CcnxTunnel()
-{
- m_localPrefix = Name("/local");
-}
-
-void
-DummyTunnel::overridePrefix()
-{
- CcnxWrapper::setInterestFilter(m_localPrefix, bind(&DummyTunnel::handleTunneledInterest, this, _1));
-}
-
-Name
-DummyTunnel::queryRoutableName (const Name &name)
-{
- return Name("/local") + name;
-}
-
-CcnxWrapperPtr t1(new DummyTunnel());
-CcnxWrapperPtr t2(new DummyTunnel());
-CcnxWrapperPtr c1(new CcnxWrapper());
-
-DummyTunnel t3;
-
-// global data callback counter;
-int g_dc_i = 0;
-int g_dc_o = 0;
-int g_ic = 0;
-
-void innerCallback(const Name &name, const Bytes &content)
-{
- g_dc_i ++;
- string str((const char *)&content[0], content.size());
- BOOST_CHECK_EQUAL(name, str);
-}
-
-void outerCallback(const Name &name, const Bytes &content)
-{
- g_dc_o ++;
-}
-
-void interestCallback(const Name &name)
-{
- string strName = name.toString();
- t3.publishData(name, (const unsigned char *)strName.c_str(), strName.size(), 5);
- g_ic++;
-}
-
-BOOST_AUTO_TEST_CASE (CcnxTunnelTest)
-{
- // test publish
- string inner = "/hello";
-
- g_dc_o = 0;
- t1->publishData(Name(inner), (const unsigned char *)inner.c_str(), inner.size(), 5);
- usleep(100000);
-
- c1->sendInterest(Name("/local/hello"), Closure(bind(outerCallback, _1, _2)));
- usleep(100000);
- // it is indeed published as /local/hello
- BOOST_CHECK_EQUAL(g_dc_o, 1);
-
- g_dc_i = 0;
- t2->sendInterest(Name(inner), Closure(bind(innerCallback, _1, _2)));
- usleep(100000);
- BOOST_CHECK_EQUAL(g_dc_i, 1);
-}
-
-BOOST_AUTO_TEST_CASE (CcnxTunnelRegister)
-{
-
- g_ic = 0;
- g_dc_i = 0;
- t3.overridePrefix();
- t3.setInterestFilter(Name("/t3"), bind(interestCallback, _1));
- usleep(100000);
- Closure innerClosure (bind(innerCallback, _1, _2));
- t1->sendInterest(Name("/t3/hello"), innerClosure);
- usleep(100000);
- BOOST_CHECK_EQUAL(g_dc_i, 1);
- BOOST_CHECK_EQUAL(g_ic, 1);
-
- t3.clearInterestFilter(Name("/t3"));
- usleep(100000);
- t1->sendInterest(Name("/t3/hello-there"), innerClosure);
- usleep(100000);
- BOOST_CHECK_EQUAL(g_dc_i, 1);
- BOOST_CHECK_EQUAL(g_ic, 1);
-
-}
-
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/test-ccnx-wrapper.cc b/test/test-ccnx-wrapper.cc
index b64f513..d5188de 100644
--- a/test/test-ccnx-wrapper.cc
+++ b/test/test-ccnx-wrapper.cc
@@ -31,9 +31,10 @@
c2->publishData(name, (const unsigned char*)content.c_str(), content.size(), 5);
}
-void dataCallback(const Name &name, const Bytes &content)
+void dataCallback(const Name &name, Ccnx::PcoPtr pco)
{
- string msg((const char*)&content[0], content.size());
+ BytesPtr content = pco->contentPtr ();
+ string msg(reinterpret_cast<const char *> (head (*content)), content->size());
g_dataCallback_counter ++;
BOOST_CHECK_EQUAL(name, msg);
}
diff --git a/test/test-fetch-manager.cc b/test/test-fetch-manager.cc
index 55c85df..276fe0c 100644
--- a/test/test-fetch-manager.cc
+++ b/test/test-fetch-manager.cc
@@ -50,15 +50,17 @@
void
onData (Fetcher &fetcher, uint32_t seqno, const Ccnx::Name &basename,
- const Ccnx::Name &name, const Ccnx::Bytes &data)
+ const Ccnx::Name &name, Ccnx::PcoPtr pco)
{
recvData.insert (seqno);
differentNames.insert (basename);
segmentNames.insert (name);
- if (data.size () == sizeof(int))
+ BytesPtr data = pco->contentPtr ();
+
+ if (data->size () == sizeof(int))
{
- recvContent.insert (*reinterpret_cast<const int*> (head(data)));
+ recvContent.insert (*reinterpret_cast<const int*> (head(*data)));
}
// cout << "<<< " << basename << ", " << name << ", " << seqno << endl;
diff --git a/test/test-sync-core.cc b/test/test-sync-core.cc
index 2caa99b..b8316c1 100644
--- a/test/test-sync-core.cc
+++ b/test/test-sync-core.cc
@@ -3,9 +3,11 @@
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
+#include <boost/make_shared.hpp>
using namespace std;
using namespace Ccnx;
+using namespace boost;
using namespace boost::filesystem;
BOOST_AUTO_TEST_SUITE(SyncCoreTests)
@@ -55,16 +57,17 @@
SyncLogPtr log1(new SyncLog(dir1, user1.toString()));
SyncLogPtr log2(new SyncLog(dir2, user2.toString()));
- SchedulerPtr scheduler(new Scheduler());
+ // should not have used the same scheduler...
+ SchedulerPtr scheduler1 = make_shared<Scheduler> ();
+ SchedulerPtr scheduler2 = make_shared<Scheduler> ();
-
- SyncCore *core1 = new SyncCore(log1, user1, loc1, syncPrefix, bind(callback, _1), c1, scheduler);
+ SyncCore *core1 = new SyncCore(log1, user1, loc1, syncPrefix, bind(callback, _1), c1, scheduler1);
usleep(10000);
- SyncCore *core2 = new SyncCore(log2, user2, loc2, syncPrefix, bind(callback, _1), c2, scheduler);
+ SyncCore *core2 = new SyncCore(log2, user2, loc2, syncPrefix, bind(callback, _1), c2, scheduler2);
usleep(1000000);
checkRoots(core1->root(), core2->root());
- cout << "\n\n\n\n\n\n----------\n";
+ // cout << "\n\n\n\n\n\n----------\n";
core1->updateLocalState(1);
usleep(100000);
checkRoots(core1->root(), core2->root());
@@ -84,11 +87,11 @@
BOOST_CHECK_EQUAL(log1->LookupLocator (user2), loc2);
// simple simultaneous data generation
- cout << "\n\n\n\n\n\n----------Simultaneous\n";
+ // cout << "\n\n\n\n\n\n----------Simultaneous\n";
core1->updateLocalState(11);
usleep(100);
core2->updateLocalState(15);
- usleep(1000000);
+ usleep(2000000);
checkRoots(core1->root(), core2->root());
BOOST_CHECK_EQUAL(core1->seq(user2), 15);
BOOST_CHECK_EQUAL(core2->seq(user1), 11);