encoding: Fixing bugs in EncodingBlock and Block
Several Block constructors incorrectly initialized value boundaries.
Change-Id: I0d8a4fe73cc24530245862e0428e617437078bf0
refs: #1256, #1257
diff --git a/src/common.hpp b/src/common.hpp
index bed6c3c..647e306 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -30,6 +30,7 @@
#include <boost/lexical_cast.hpp>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/utility.hpp>
#include <boost/iostreams/detail/ios.hpp>
#include <boost/iostreams/categories.hpp>
@@ -49,8 +50,6 @@
namespace ptr_lib = std;
namespace func_lib = std;
-using std::noncopyable;
-
using std::shared_ptr;
using std::make_shared;
using std::enable_shared_from_this;
@@ -76,8 +75,6 @@
namespace ptr_lib = boost;
namespace func_lib = boost;
-using boost::noncopyable;
-
using boost::shared_ptr;
using boost::make_shared;
using boost::enable_shared_from_this;
@@ -91,6 +88,7 @@
namespace ndn {
+using boost::noncopyable;
/**
* A time interval represented as the number of milliseconds.
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index 9c8ba1e..5409879 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -39,8 +39,8 @@
, m_end(m_buffer->end())
, m_size(m_end - m_begin)
{
- m_value_begin = m_buffer->begin();
- m_value_end = m_buffer->end();
+ m_value_begin = m_begin;
+ m_value_end = m_end;
m_type = Tlv::readType(m_value_begin, m_value_end);
@@ -58,8 +58,8 @@
, m_end(end)
, m_size(m_end - m_begin)
{
- m_value_begin = m_buffer->begin();
- m_value_end = m_buffer->end();
+ m_value_begin = m_begin;
+ m_value_end = m_end;
m_type = Tlv::readType(m_value_begin, m_value_end);
uint64_t length = Tlv::readVarNumber(m_value_begin, m_value_end);
diff --git a/src/encoding/block.hpp b/src/encoding/block.hpp
index 2afd154..a2f19be 100644
--- a/src/encoding/block.hpp
+++ b/src/encoding/block.hpp
@@ -17,6 +17,9 @@
namespace ndn {
+template<bool> class EncodingImpl;
+typedef EncodingImpl<true> EncodingBuffer;
+
/**
* @brief Class representing wire element of the NDN packet
*/
@@ -223,6 +226,7 @@
Buffer::const_iterator m_value_end;
mutable element_container m_subBlocks;
+ friend class EncodingImpl<true>;
};
////////////////////////////////////////////////////////////////////////////////
diff --git a/src/encoding/encoding-buffer.hpp b/src/encoding/encoding-buffer.hpp
index 62d6a12..b4c9018 100644
--- a/src/encoding/encoding-buffer.hpp
+++ b/src/encoding/encoding-buffer.hpp
@@ -18,6 +18,7 @@
#include "buffer.hpp"
#include "tlv.hpp"
+#include "block.hpp"
#include <boost/lexical_cast.hpp>
diff --git a/tests/test-block.cpp b/tests/test-block.cpp
new file mode 100644
index 0000000..c2fab26
--- /dev/null
+++ b/tests/test-block.cpp
@@ -0,0 +1,32 @@
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <boost/test/unit_test.hpp>
+
+#include "encoding/encoding-buffer.hpp"
+
+using namespace std;
+namespace ndn {
+
+BOOST_AUTO_TEST_SUITE(TestBlock)
+
+BOOST_AUTO_TEST_CASE (Decode)
+{
+ uint8_t value[4];
+
+ ndn::EncodingBuffer buffer;
+ size_t length = buffer.prependByteArray(value, sizeof(value));
+ buffer.prependVarNumber(length);
+ buffer.prependVarNumber(0xe0);
+
+ Block block;
+ BOOST_REQUIRE_NO_THROW(block = buffer.block());
+ BOOST_CHECK_EQUAL(block.type(), 0xe0);
+ BOOST_CHECK_EQUAL(block.value_size(), sizeof(value));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn