blob: f236d77dcec7a01ee95f134b056127dadbfbf848 [file] [log] [blame]
/* -*- 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
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NFD 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 General Public License for more details.
*
* 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 "tests/test-common.hpp"
#include <ndn-cpp-dev/security/key-chain.hpp>
namespace nfd {
namespace tests {
class CsAccessor : public Cs
{
public:
bool
evictItem_accessor()
{
return evictItem();
}
};
BOOST_FIXTURE_TEST_SUITE(TableCs, BaseFixture)
BOOST_AUTO_TEST_CASE(Insertion)
{
Cs cs;
shared_ptr<Data> data = make_shared<Data>("/insertion");
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
data->setSignature(fakeSignature);
BOOST_CHECK_EQUAL(cs.insert(*data), true);
}
BOOST_AUTO_TEST_CASE(Insertion2)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/a");
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/b");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data3 = make_shared<Data>("/c");
data3->setSignature(fakeSignature);
cs.insert(*data3);
shared_ptr<Data> data4 = make_shared<Data>("/d");
data4->setSignature(fakeSignature);
cs.insert(*data4);
BOOST_CHECK_EQUAL(cs.size(), 4);
}
BOOST_AUTO_TEST_CASE(DuplicateInsertion)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data0 = make_shared<Data>("/insert/smth");
data0->setSignature(fakeSignature);
BOOST_CHECK_EQUAL(cs.insert(*data0), true);
shared_ptr<Data> data = make_shared<Data>("/insert/duplicate");
data->setSignature(fakeSignature);
BOOST_CHECK_EQUAL(cs.insert(*data), true);
cs.insert(*data);
BOOST_CHECK_EQUAL(cs.size(), 2);
}
BOOST_AUTO_TEST_CASE(DuplicateInsertion2)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/insert/duplicate");
data->setSignature(fakeSignature);
BOOST_CHECK_EQUAL(cs.insert(*data), true);
cs.insert(*data);
BOOST_CHECK_EQUAL(cs.size(), 1);
shared_ptr<Data> data2 = make_shared<Data>("/insert/original");
data2->setSignature(fakeSignature);
BOOST_CHECK_EQUAL(cs.insert(*data2), true);
BOOST_CHECK_EQUAL(cs.size(), 2);
}
BOOST_AUTO_TEST_CASE(InsertAndFind)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
Name name("/insert/and/find");
shared_ptr<Data> data = make_shared<Data>(name);
data->setSignature(fakeSignature);
BOOST_CHECK_EQUAL(cs.insert(*data), true);
shared_ptr<Interest> interest = make_shared<Interest>(name);
const Data* found = cs.find(*interest);
BOOST_REQUIRE(found != 0);
BOOST_CHECK_EQUAL(data->getName(), found->getName());
}
BOOST_AUTO_TEST_CASE(InsertAndNotFind)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
Name name("/insert/and/find");
shared_ptr<Data> data = make_shared<Data>(name);
data->setSignature(fakeSignature);
BOOST_CHECK_EQUAL(cs.insert(*data), true);
Name name2("/not/find");
shared_ptr<Interest> interest = make_shared<Interest>(name2);
const Data* found = cs.find(*interest);
BOOST_CHECK_EQUAL(found, static_cast<const Data*>(0));
}
BOOST_AUTO_TEST_CASE(InsertAndErase)
{
CsAccessor cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/insertandelete");
data->setSignature(fakeSignature);
cs.insert(*data);
BOOST_CHECK_EQUAL(cs.size(), 1);
cs.evictItem_accessor();
BOOST_CHECK_EQUAL(cs.size(), 0);
}
BOOST_AUTO_TEST_CASE(StalenessQueue)
{
CsAccessor cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
Name name2("/insert/fresh");
shared_ptr<Data> data2 = make_shared<Data>(name2);
data2->setFreshnessPeriod(time::milliseconds(5000));
data2->setSignature(fakeSignature);
cs.insert(*data2);
Name name("/insert/expire");
shared_ptr<Data> data = make_shared<Data>(name);
data->setFreshnessPeriod(time::milliseconds(500));
data->setSignature(fakeSignature);
cs.insert(*data);
BOOST_CHECK_EQUAL(cs.size(), 2);
sleep(1);
cs.evictItem_accessor();
BOOST_CHECK_EQUAL(cs.size(), 1);
shared_ptr<Interest> interest = make_shared<Interest>(name2);
const Data* found = cs.find(*interest);
BOOST_REQUIRE(found != 0);
BOOST_CHECK_EQUAL(found->getName(), name2);
}
//even max size
BOOST_AUTO_TEST_CASE(ReplacementEvenSize)
{
Cs cs(4);
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/a");
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/b");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data3 = make_shared<Data>("/c");
data3->setSignature(fakeSignature);
cs.insert(*data3);
shared_ptr<Data> data4 = make_shared<Data>("/d");
data4->setSignature(fakeSignature);
cs.insert(*data4);
shared_ptr<Data> data5 = make_shared<Data>("/e");
data5->setSignature(fakeSignature);
cs.insert(*data5);
BOOST_CHECK_EQUAL(cs.size(), 4);
}
//odd max size
BOOST_AUTO_TEST_CASE(Replacement2)
{
Cs cs(3);
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/a");
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/b");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data3 = make_shared<Data>("/c");
data3->setSignature(fakeSignature);
cs.insert(*data3);
shared_ptr<Data> data4 = make_shared<Data>("/d");
data4->setSignature(fakeSignature);
cs.insert(*data4);
BOOST_CHECK_EQUAL(cs.size(), 3);
}
BOOST_AUTO_TEST_CASE(InsertAndEraseByName)
{
CsAccessor cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
Name name("/insertandremovebyname");
shared_ptr<Data> data = make_shared<Data>(name);
data->setSignature(fakeSignature);
cs.insert(*data);
uint8_t digest1[32];
ndn::ndn_digestSha256(data->wireEncode().wire(), data->wireEncode().size(), digest1);
shared_ptr<Data> data2 = make_shared<Data>("/a");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data3 = make_shared<Data>("/z");
data3->setSignature(fakeSignature);
cs.insert(*data3);
BOOST_CHECK_EQUAL(cs.size(), 3);
name.append(digest1, 32);
cs.erase(name);
BOOST_CHECK_EQUAL(cs.size(), 2);
}
BOOST_AUTO_TEST_CASE(DigestCalculation)
{
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/digest/compute");
data->setSignature(fakeSignature);
uint8_t digest1[32];
ndn::ndn_digestSha256(data->wireEncode().wire(), data->wireEncode().size(), digest1);
cs::Entry* entry = new cs::Entry(*data, false);
BOOST_CHECK_EQUAL_COLLECTIONS(digest1, digest1+32,
entry->getDigest()->buf(), entry->getDigest()->buf()+32);
}
BOOST_AUTO_TEST_CASE(InsertCanonical)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/a");
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/b");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data3 = make_shared<Data>("/c");
data3->setSignature(fakeSignature);
cs.insert(*data3);
shared_ptr<Data> data4 = make_shared<Data>("/d");
data4->setSignature(fakeSignature);
cs.insert(*data4);
shared_ptr<Data> data5 = make_shared<Data>("/c/c/1/2/3/4/5/6");
data5->setSignature(fakeSignature);
cs.insert(*data5);
shared_ptr<Data> data6 = make_shared<Data>("/c/c/1/2/3");
data6->setSignature(fakeSignature);
cs.insert(*data6);
shared_ptr<Data> data7 = make_shared<Data>("/c/c/1");
data7->setSignature(fakeSignature);
cs.insert(*data7);
}
BOOST_AUTO_TEST_CASE(EraseCanonical)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/a");
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/b");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data3 = make_shared<Data>("/c");
data3->setSignature(fakeSignature);
cs.insert(*data3);
shared_ptr<Data> data4 = make_shared<Data>("/d");
data4->setSignature(fakeSignature);
cs.insert(*data4);
uint8_t digest1[32];
ndn::ndn_digestSha256(data->wireEncode().wire(), data->wireEncode().size(), digest1);
shared_ptr<Data> data5 = make_shared<Data>("/c/c/1/2/3/4/5/6");
data5->setSignature(fakeSignature);
cs.insert(*data5);
shared_ptr<Data> data6 = make_shared<Data>("/c/c/1/2/3");
data6->setSignature(fakeSignature);
cs.insert(*data6);
shared_ptr<Data> data7 = make_shared<Data>("/c/c/1");
data7->setSignature(fakeSignature);
cs.insert(*data7);
Name name("/a");
name.append(digest1,32);
cs.erase(name);
BOOST_CHECK_EQUAL(cs.size(), 6);
}
BOOST_AUTO_TEST_CASE(ImplicitDigestSelector)
{
CsAccessor cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
Name name("/digest/works");
shared_ptr<Data> data = make_shared<Data>(name);
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/a");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data3 = make_shared<Data>("/z/z/z");
data3->setSignature(fakeSignature);
cs.insert(*data3);
uint8_t digest1[32];
ndn::ndn_digestSha256(data->wireEncode().wire(), data->wireEncode().size(), digest1);
uint8_t digest2[32] = {0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1};
shared_ptr<Interest> interest = make_shared<Interest>(boost::cref(Name(name).append(digest1, 32)));
interest->setMinSuffixComponents(0);
interest->setMaxSuffixComponents(0);
const Data* found = cs.find(*interest);
BOOST_CHECK_NE(found, static_cast<const Data*>(0));
BOOST_CHECK_EQUAL(found->getName(), name);
shared_ptr<Interest> interest2 = make_shared<Interest>(boost::cref(Name(name).append(digest2, 32)));
interest2->setMinSuffixComponents(0);
interest2->setMaxSuffixComponents(0);
const Data* notfound = cs.find(*interest2);
BOOST_CHECK_EQUAL(notfound, static_cast<const Data*>(0));
}
BOOST_AUTO_TEST_CASE(ChildSelector)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/a");
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/b");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data4 = make_shared<Data>("/d");
data4->setSignature(fakeSignature);
cs.insert(*data4);
shared_ptr<Data> data5 = make_shared<Data>("/c/c");
data5->setSignature(fakeSignature);
cs.insert(*data5);
shared_ptr<Data> data6 = make_shared<Data>("/c/f");
data6->setSignature(fakeSignature);
cs.insert(*data6);
shared_ptr<Data> data7 = make_shared<Data>("/c/n");
data7->setSignature(fakeSignature);
cs.insert(*data7);
shared_ptr<Interest> interest = make_shared<Interest>("/c");
interest->setChildSelector(1);
const Data* found = cs.find(*interest);
BOOST_CHECK_EQUAL(found->getName(), "/c/n");
shared_ptr<Interest> interest2 = make_shared<Interest>("/c");
interest2->setChildSelector(0);
const Data* found2 = cs.find(*interest2);
BOOST_CHECK_EQUAL(found2->getName(), "/c/c");
}
BOOST_AUTO_TEST_CASE(ChildSelector2)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/a/b/1");
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/a/b/2");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data3 = make_shared<Data>("/a/z/1");
data3->setSignature(fakeSignature);
cs.insert(*data3);
shared_ptr<Data> data4 = make_shared<Data>("/a/z/2");
data4->setSignature(fakeSignature);
cs.insert(*data4);
shared_ptr<Interest> interest = make_shared<Interest>("/a");
interest->setChildSelector(1);
const Data* found = cs.find(*interest);
BOOST_CHECK_EQUAL(found->getName(), "/a/z/1");
}
BOOST_AUTO_TEST_CASE(MustBeFreshSelector)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
Name name("/insert/nonfresh");
shared_ptr<Data> data = make_shared<Data>(name);
data->setFreshnessPeriod(time::milliseconds(500));
data->setSignature(fakeSignature);
cs.insert(*data);
sleep(1);
shared_ptr<Interest> interest = make_shared<Interest>(name);
interest->setMustBeFresh(true);
const Data* found = cs.find(*interest);
BOOST_CHECK_EQUAL(found, static_cast<const Data*>(0));
}
BOOST_AUTO_TEST_CASE(MinMaxComponentsSelector)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/a");
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/b");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data4 = make_shared<Data>("/d");
data4->setSignature(fakeSignature);
cs.insert(*data4);
shared_ptr<Data> data5 = make_shared<Data>("/c/c/1/2/3/4/5/6");
data5->setSignature(fakeSignature);
cs.insert(*data5);
shared_ptr<Data> data6 = make_shared<Data>("/c/c/6/7/8/9");
data6->setSignature(fakeSignature);
cs.insert(*data6);
shared_ptr<Data> data7 = make_shared<Data>("/c/c/1/2/3");
data7->setSignature(fakeSignature);
cs.insert(*data7);
shared_ptr<Data> data8 = make_shared<Data>("/c/c/1");
data8->setSignature(fakeSignature);
cs.insert(*data8);
shared_ptr<Interest> interest = make_shared<Interest>("/c/c");
interest->setMinSuffixComponents(3);
interest->setChildSelector(0);
const Data* found = cs.find(*interest);
BOOST_CHECK_EQUAL(found->getName(), "/c/c/1/2/3/4/5/6");
shared_ptr<Interest> interest2 = make_shared<Interest>("/c/c");
interest2->setMinSuffixComponents(4);
interest2->setChildSelector(1);
const Data* found2 = cs.find(*interest2);
BOOST_CHECK_EQUAL(found2->getName(), "/c/c/6/7/8/9");
shared_ptr<Interest> interest3 = make_shared<Interest>("/c/c");
interest3->setMaxSuffixComponents(2);
interest3->setChildSelector(1);
const Data* found3 = cs.find(*interest3);
BOOST_CHECK_EQUAL(found3->getName(), "/c/c/1");
}
BOOST_AUTO_TEST_CASE(ExcludeSelector)
{
Cs cs;
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
shared_ptr<Data> data = make_shared<Data>("/a");
data->setSignature(fakeSignature);
cs.insert(*data);
shared_ptr<Data> data2 = make_shared<Data>("/b");
data2->setSignature(fakeSignature);
cs.insert(*data2);
shared_ptr<Data> data3 = make_shared<Data>("/c/a");
data3->setSignature(fakeSignature);
cs.insert(*data3);
shared_ptr<Data> data4 = make_shared<Data>("/d");
data4->setSignature(fakeSignature);
cs.insert(*data4);
shared_ptr<Data> data5 = make_shared<Data>("/c/c");
data5->setSignature(fakeSignature);
cs.insert(*data5);
shared_ptr<Data> data6 = make_shared<Data>("/c/f");
data6->setSignature(fakeSignature);
cs.insert(*data6);
shared_ptr<Data> data7 = make_shared<Data>("/c/n");
data7->setSignature(fakeSignature);
cs.insert(*data7);
shared_ptr<Interest> interest = make_shared<Interest>("/c");
interest->setChildSelector(1);
Exclude e;
e.excludeOne (Name::Component("n"));
interest->setExclude(e);
const Data* found = cs.find(*interest);
BOOST_CHECK_EQUAL(found->getName(), "/c/f");
shared_ptr<Interest> interest2 = make_shared<Interest>("/c");
interest2->setChildSelector(0);
Exclude e2;
e2.excludeOne (Name::Component("a"));
interest2->setExclude(e2);
const Data* found2 = cs.find(*interest2);
BOOST_CHECK_EQUAL(found2->getName(), "/c/c");
shared_ptr<Interest> interest3 = make_shared<Interest>("/c");
interest3->setChildSelector(0);
Exclude e3;
e3.excludeOne (Name::Component("c"));
interest3->setExclude(e3);
const Data* found3 = cs.find(*interest3);
BOOST_CHECK_EQUAL(found3->getName(), "/c/a");
}
//
class FindFixture : protected BaseFixture
{
protected:
void
insert(uint32_t id, const Name& name)
{
shared_ptr<Data> data = make_shared<Data>(name);
data->setFreshnessPeriod(time::milliseconds(99999));
data->setContent(reinterpret_cast<const uint8_t*>(&id), sizeof(id));
ndn::SignatureSha256WithRsa fakeSignature;
fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
data->setSignature(fakeSignature);
m_cs.insert(*data);
}
Interest&
startInterest(const Name& name)
{
m_interest = make_shared<Interest>(name);
return *m_interest;
}
uint32_t
find()
{
const Data* found = m_cs.find(*m_interest);
if (found == 0) {
return 0;
}
const Block& content = found->getContent();
if (content.value_size() != sizeof(uint32_t)) {
return 0;
}
return *reinterpret_cast<const uint32_t*>(content.value());
}
protected:
Cs m_cs;
shared_ptr<Interest> m_interest;
};
BOOST_FIXTURE_TEST_SUITE(Find, FindFixture)
BOOST_AUTO_TEST_CASE(EmptyDataName)
{
insert(1, "ndn:/");
startInterest("ndn:/");
BOOST_CHECK_EQUAL(find(), 1);
}
BOOST_AUTO_TEST_CASE(EmptyInterestName)
{
insert(1, "ndn:/A");
startInterest("ndn:/");
BOOST_CHECK_EQUAL(find(), 1);
}
BOOST_AUTO_TEST_CASE(Leftmost)
{
insert(1, "ndn:/A");
insert(2, "ndn:/B/p/1");
insert(3, "ndn:/B/p/2");
insert(4, "ndn:/B/q/1");
insert(5, "ndn:/B/q/2");
insert(6, "ndn:/C");
startInterest("ndn:/B");
BOOST_CHECK_EQUAL(find(), 2);
}
BOOST_AUTO_TEST_CASE(Rightmost)
{
insert(1, "ndn:/A");
insert(2, "ndn:/B/p/1");
insert(3, "ndn:/B/p/2");
insert(4, "ndn:/B/q/1");
insert(5, "ndn:/B/q/2");
insert(6, "ndn:/C");
startInterest("ndn:/B")
.setChildSelector(1);
BOOST_CHECK_EQUAL(find(), 4);
}
BOOST_AUTO_TEST_CASE(Leftmost_ExactName1)
{
insert(1, "ndn:/");
insert(2, "ndn:/A/B");
insert(3, "ndn:/A/C");
insert(4, "ndn:/A");
insert(5, "ndn:/D");
// Intuitively you would think Data 4 should be between Data 1 and 2,
// but Data 4 has full Name ndn:/A/<32-octet hash>.
startInterest("ndn:/A");
BOOST_CHECK_EQUAL(find(), 2);
}
BOOST_AUTO_TEST_CASE(Leftmost_ExactName33)
{
insert(1, "ndn:/");
insert(2, "ndn:/A");
insert(3, "ndn:/A/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"); // 33 'B's
insert(4, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's
insert(5, "ndn:/D");
// Data 2 is returned, because <32-octet hash> is less than Data 3.
startInterest("ndn:/A");
BOOST_CHECK_EQUAL(find(), 2);
}
BOOST_AUTO_TEST_CASE(MinSuffixComponents)
{
insert(1, "ndn:/A/1/2/3/4");
insert(2, "ndn:/B/1/2/3");
insert(3, "ndn:/C/1/2");
insert(4, "ndn:/D/1");
insert(5, "ndn:/E");
insert(6, "ndn:/");
startInterest("ndn:/")
.setChildSelector(1)
.setMinSuffixComponents(0);
BOOST_CHECK_EQUAL(find(), 6);
startInterest("ndn:/")
.setChildSelector(1)
.setMinSuffixComponents(1);
BOOST_CHECK_EQUAL(find(), 6);
startInterest("ndn:/")
.setChildSelector(1)
.setMinSuffixComponents(2);
BOOST_CHECK_EQUAL(find(), 5);
startInterest("ndn:/")
.setChildSelector(1)
.setMinSuffixComponents(3);
BOOST_CHECK_EQUAL(find(), 4);
startInterest("ndn:/")
.setChildSelector(1)
.setMinSuffixComponents(4);
BOOST_CHECK_EQUAL(find(), 3);
startInterest("ndn:/")
.setChildSelector(1)
.setMinSuffixComponents(5);
BOOST_CHECK_EQUAL(find(), 2);
startInterest("ndn:/")
.setChildSelector(1)
.setMinSuffixComponents(6);
BOOST_CHECK_EQUAL(find(), 1);
startInterest("ndn:/")
.setChildSelector(1)
.setMinSuffixComponents(7);
BOOST_CHECK_EQUAL(find(), 0);
}
BOOST_AUTO_TEST_CASE(MaxSuffixComponents)
{
insert(1, "ndn:/");
insert(2, "ndn:/A");
insert(3, "ndn:/A/B");
insert(4, "ndn:/A/B/C");
insert(5, "ndn:/A/B/C/D");
insert(6, "ndn:/A/B/C/D/E");
// Order is 6,5,4,3,2,1, because <32-octet hash> is greater than a 1-octet component.
startInterest("ndn:/")
.setMaxSuffixComponents(0);
BOOST_CHECK_EQUAL(find(), 0);
startInterest("ndn:/")
.setMaxSuffixComponents(1);
BOOST_CHECK_EQUAL(find(), 1);
startInterest("ndn:/")
.setMaxSuffixComponents(2);
BOOST_CHECK_EQUAL(find(), 2);
startInterest("ndn:/")
.setMaxSuffixComponents(3);
BOOST_CHECK_EQUAL(find(), 3);
startInterest("ndn:/")
.setMaxSuffixComponents(4);
BOOST_CHECK_EQUAL(find(), 4);
startInterest("ndn:/")
.setMaxSuffixComponents(5);
BOOST_CHECK_EQUAL(find(), 5);
startInterest("ndn:/")
.setMaxSuffixComponents(6);
BOOST_CHECK_EQUAL(find(), 6);
}
BOOST_AUTO_TEST_CASE(DigestOrder)
{
insert(1, "ndn:/A");
insert(2, "ndn:/A");
// We don't know which comes first, but there must be some order
startInterest("ndn:/A")
.setChildSelector(0);
uint32_t leftmost = find();
startInterest("ndn:/A")
.setChildSelector(1);
uint32_t rightmost = find();
BOOST_CHECK_NE(leftmost, rightmost);
}
BOOST_AUTO_TEST_CASE(DigestExclude)
{
insert(1, "ndn:/A/B");
insert(2, "ndn:/A");
insert(3, "ndn:/A/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"); // 33 'C's
startInterest("ndn:/A")
.setExclude(Exclude().excludeBefore(ndn::name::Component(reinterpret_cast<const uint8_t*>(
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"), 31))); // 31 0xFF's
BOOST_CHECK_EQUAL(find(), 2);
startInterest("ndn:/A")
.setChildSelector(1)
.setExclude(Exclude().excludeAfter(ndn::name::Component(reinterpret_cast<const uint8_t*>(
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00"), 33))); // 33 0x00's
BOOST_CHECK_EQUAL(find(), 2);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests
} // namespace nfd