face: move packet encoding to Impl class
Practical limit of packet size is now enforced on encoded
NDNLPv2 packets instead of network-layer packets.
If a packet exceeds size limit, the face throws a
Face::OversizedPacketError exception. Since packet encoding may
be asynchronous, this exception could be thrown by
Face::processEvents instead of Face::expressInterest and
Face::put.
refs #4228
Change-Id: Ib68cf80b3b8967fdd0ba040bd8ee595a0eff740e
diff --git a/tests/integrated/face.cpp b/tests/integrated/face.cpp
index 038b499..cf7c872 100644
--- a/tests/integrated/face.cpp
+++ b/tests/integrated/face.cpp
@@ -150,9 +150,7 @@
bind(&FacesFixture::onData, this),
bind(&FacesFixture::onNack, this),
bind(&FacesFixture::onTimeout, this));
-
- BOOST_REQUIRE_NO_THROW(face.processEvents());
-
+ face.processEvents();
BOOST_CHECK_EQUAL(nData, 1);
BOOST_CHECK_EQUAL(nNacks, 0);
BOOST_CHECK_EQUAL(nTimeouts, 0);
@@ -162,25 +160,29 @@
bind(&FacesFixture::onData, this),
bind(&FacesFixture::onNack, this),
bind(&FacesFixture::onTimeout, this));
+ face.processEvents();
+ BOOST_CHECK_EQUAL(nData, 1);
+ BOOST_CHECK_EQUAL(nNacks, 0);
+ BOOST_CHECK_EQUAL(nTimeouts, 1);
Name veryLongName;
for (size_t i = 0; i <= MAX_NDN_PACKET_SIZE / 10; i++) {
veryLongName.append("0123456789");
}
- BOOST_CHECK_THROW(face.expressInterest(Interest(veryLongName), nullptr, nullptr, nullptr),
- Face::Error);
+ BOOST_CHECK_THROW(do {
+ face.expressInterest(Interest(veryLongName), nullptr, nullptr, nullptr);
+ face.processEvents();
+ } while (false), Face::OversizedPacketError);
shared_ptr<Data> data = make_shared<Data>(veryLongName);
data->setContent(reinterpret_cast<const uint8_t*>("01234567890"), 10);
m_keyChain.sign(*data);
- BOOST_CHECK_THROW(face.put(*data), Face::Error);
+ BOOST_CHECK_THROW(do {
+ face.put(*data);
+ face.processEvents();
+ } while (false), Face::OversizedPacketError);
- BOOST_REQUIRE_NO_THROW(face.processEvents());
-
- BOOST_CHECK_EQUAL(nData, 1);
- BOOST_CHECK_EQUAL(nNacks, 0);
- BOOST_CHECK_EQUAL(nTimeouts, 1);
}
BOOST_AUTO_TEST_CASE(Tcp)
diff --git a/tests/unit-tests/lp/packet.t.cpp b/tests/unit-tests/lp/packet.t.cpp
index c173ed2..8d4e78d 100644
--- a/tests/unit-tests/lp/packet.t.cpp
+++ b/tests/unit-tests/lp/packet.t.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -34,24 +34,30 @@
{
Packet packet;
+ BOOST_CHECK(packet.empty());
BOOST_CHECK(!packet.has<FragIndexField>());
BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
- BOOST_CHECK_NO_THROW(packet.set<FragIndexField>(1234));
+
+ packet.set<FragIndexField>(1234);
+ BOOST_CHECK(!packet.empty());
BOOST_CHECK(packet.has<FragIndexField>());
BOOST_CHECK_THROW(packet.add<FragIndexField>(5678), std::length_error);
BOOST_CHECK_EQUAL(1, packet.count<FragIndexField>());
BOOST_CHECK_EQUAL(1234, packet.get<FragIndexField>(0));
BOOST_CHECK_THROW(packet.get<FragIndexField>(1), std::out_of_range);
BOOST_CHECK_THROW(packet.remove<FragIndexField>(1), std::out_of_range);
- BOOST_CHECK_NO_THROW(packet.remove<FragIndexField>(0));
+
+ packet.remove<FragIndexField>(0);
BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
- BOOST_CHECK_NO_THROW(packet.add<FragIndexField>(832));
- std::vector<uint64_t> fragIndexes;
- BOOST_REQUIRE_NO_THROW(fragIndexes = packet.list<FragIndexField>());
+
+ packet.add<FragIndexField>(832);
+ std::vector<uint64_t> fragIndexes = packet.list<FragIndexField>();
BOOST_CHECK_EQUAL(1, fragIndexes.size());
BOOST_CHECK_EQUAL(832, fragIndexes.at(0));
- BOOST_CHECK_NO_THROW(packet.clear<FragIndexField>());
+
+ packet.clear<FragIndexField>();
BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
+ BOOST_CHECK(packet.empty());
}
/// \todo test field access methods with a REPEATABLE field