encoding: Refactoring EncodingBuffer
Breaks: nfd:commit:c0273e3505ac2ccf843401be77a513d8eb663127
Breaks: ChronoSync:commit:e042f83a1df184a8e7a90ef00034d11026891cd1
Change-Id: I8275c6276c5ecfa280f87f584189907521febf5f
Refs: #2494, #2490
diff --git a/tests/unit-tests/encoding/encoder.t.cpp b/tests/unit-tests/encoding/encoder.t.cpp
new file mode 100644
index 0000000..b48569d
--- /dev/null
+++ b/tests/unit-tests/encoding/encoder.t.cpp
@@ -0,0 +1,171 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2015 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "encoding/encoder.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace encoding {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(EncodingEncoder)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+ Encoder e;
+ BOOST_CHECK_GT(e.capacity(), 100);
+
+ Encoder e1(100);
+ BOOST_CHECK_EQUAL(e1.capacity(), 100);
+
+ Encoder e2(100, 100);
+ BOOST_CHECK_EQUAL(e2.capacity(), 100);
+
+ BOOST_CHECK_EQUAL(e.prependByte(1), 1);
+ BOOST_CHECK_EQUAL(e.appendByte(1), 1);
+
+ uint8_t buf1[] = {'t', 'e', 's', 't', '1'};
+ BOOST_CHECK_EQUAL(e1.prependByteArray(buf1, sizeof(buf1)), 5);
+ BOOST_CHECK_EQUAL(e1.appendByteArray(buf1, sizeof(buf1)), 5);
+
+ std::vector<uint8_t> buf2 = {'t', 'e', 's', 't', '2'};
+ BOOST_CHECK_EQUAL(e1.prependRange(buf2.begin(), buf2.end()), 5);
+ BOOST_CHECK_EQUAL(e1.appendRange(buf2.begin(), buf2.end()), 5);
+
+ std::list<uint8_t> buf3 = {'t', 'e', 's', 't', '2'};
+ BOOST_CHECK_EQUAL(e2.prependRange(buf3.begin(), buf3.end()), 5);
+ BOOST_CHECK_EQUAL(e2.appendRange(buf3.begin(), buf3.end()), 5);
+
+ uint8_t expected1[] = {1, 1};
+ BOOST_CHECK_EQUAL_COLLECTIONS(e.buf(), e.buf() + e.size(),
+ expected1, expected1 + sizeof(expected1));
+
+ const Encoder& constE = e;
+ BOOST_CHECK_EQUAL_COLLECTIONS(constE.buf(), constE.buf() + constE.size(),
+ expected1, expected1 + sizeof(expected1));
+
+ uint8_t expected2[] = {'t', 'e', 's', 't', '2',
+ 't', 'e', 's', 't', '1', 't', 'e', 's', 't', '1',
+ 't', 'e', 's', 't', '2'};
+ BOOST_CHECK_EQUAL_COLLECTIONS(e1.begin(), e1.end(),
+ expected2, expected2 + sizeof(expected2));
+ const Encoder& constE1 = e1;
+ BOOST_CHECK_EQUAL_COLLECTIONS(constE1.begin(), constE1.end(),
+ expected2, expected2 + sizeof(expected2));
+
+ BOOST_CHECK_THROW(e1.block(), tlv::Error);
+ BOOST_CHECK_NO_THROW(e1.block(false));
+
+ e1.prependVarNumber(20);
+ e1.prependVarNumber(100);
+
+ BOOST_CHECK_NO_THROW(e1.block());
+}
+
+BOOST_AUTO_TEST_CASE(Tlv)
+{
+ Encoder e;
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(1), 1);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(1), 1);
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(252), 1);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(252), 1);
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(253), 3);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(253), 3);
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(65536), 5);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(65536), 5);
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(4294967296LL), 9);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(4294967296LL), 9);
+
+ //
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(1), 1);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(1), 1);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(252), 1);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(252), 1);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(253), 1);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(253), 1);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(255), 1);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(255), 1);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(256), 2);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(256), 2);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(65535), 2);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(65535), 2);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(65536), 4);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(65536), 4);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(4294967296LL), 8);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(4294967296LL), 8);
+
+ //
+
+ uint8_t buf[] = {0x01, 0x03, 0x00, 0x00, 0x00};
+ Block block1(buf, sizeof(buf));
+
+ BOOST_CHECK_EQUAL(e.prependByteArrayBlock(100, buf, sizeof(buf)), 7);
+ BOOST_CHECK_EQUAL(e.appendByteArrayBlock(100, buf, sizeof(buf)), 7);
+
+ BOOST_CHECK_EQUAL(e.prependBlock(block1), 5);
+ BOOST_CHECK_EQUAL(e.appendBlock(block1), 5);
+
+ Block block2(100, block1);
+
+ BOOST_CHECK_EQUAL(e.prependBlock(block2), 7);
+ BOOST_CHECK_EQUAL(e.appendBlock(block2), 7);
+}
+
+BOOST_AUTO_TEST_CASE(Reserve)
+{
+ Encoder e(100, 0);
+ BOOST_CHECK_EQUAL(e.capacity(), 100);
+
+ e.reserve(100, true);
+ BOOST_CHECK_EQUAL(e.capacity(), 100);
+
+ e.reserve(200, true);
+ BOOST_CHECK_EQUAL(e.capacity(), 200);
+
+ e.reserve(100, false);
+ BOOST_CHECK_EQUAL(e.capacity(), 200);
+
+ e.reserveFront(1000);
+ BOOST_CHECK_GT(e.capacity(), 1000);
+
+ e.reserveBack(1000);
+ BOOST_CHECK_GT(e.capacity(), 2000);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // EncodingEncoder
+
+} // namespace tests
+} // namespace encoding
+} // namespace ndn
diff --git a/tests/unit-tests/encoding/estimator.t.cpp b/tests/unit-tests/encoding/estimator.t.cpp
new file mode 100644
index 0000000..b759489
--- /dev/null
+++ b/tests/unit-tests/encoding/estimator.t.cpp
@@ -0,0 +1,120 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2015 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "encoding/estimator.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace encoding {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(EncodingEstimator)
+
+BOOST_AUTO_TEST_CASE(Basic)
+{
+ Estimator e;
+ Estimator e1(100);
+ Estimator e2(100, 100);
+
+ BOOST_CHECK_EQUAL(e.prependByte(1), 1);
+ BOOST_CHECK_EQUAL(e.appendByte(1), 1);
+
+ uint8_t buf1[] = {'t', 'e', 's', 't', '1'};
+ BOOST_CHECK_EQUAL(e1.prependByteArray(buf1, sizeof(buf1)), 5);
+ BOOST_CHECK_EQUAL(e1.appendByteArray(buf1, sizeof(buf1)), 5);
+
+ std::vector<uint8_t> buf2 = {'t', 'e', 's', 't', '2'};
+ BOOST_CHECK_EQUAL(e1.prependRange(buf2.begin(), buf2.end()), 5);
+ BOOST_CHECK_EQUAL(e1.appendRange(buf2.begin(), buf2.end()), 5);
+
+ std::list<uint8_t> buf3 = {'t', 'e', 's', 't', '2'};
+ BOOST_CHECK_EQUAL(e2.prependRange(buf3.begin(), buf3.end()), 5);
+ BOOST_CHECK_EQUAL(e2.appendRange(buf3.begin(), buf3.end()), 5);
+}
+
+BOOST_AUTO_TEST_CASE(Tlv)
+{
+ Estimator e;
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(1), 1);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(1), 1);
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(252), 1);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(252), 1);
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(253), 3);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(253), 3);
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(65536), 5);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(65536), 5);
+
+ BOOST_CHECK_EQUAL(e.prependVarNumber(4294967296LL), 9);
+ BOOST_CHECK_EQUAL(e.appendVarNumber(4294967296LL), 9);
+
+ //
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(1), 1);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(1), 1);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(252), 1);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(252), 1);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(253), 1);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(253), 1);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(255), 1);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(255), 1);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(256), 2);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(256), 2);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(65535), 2);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(65535), 2);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(65536), 4);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(65536), 4);
+
+ BOOST_CHECK_EQUAL(e.prependNonNegativeInteger(4294967296LL), 8);
+ BOOST_CHECK_EQUAL(e.appendNonNegativeInteger(4294967296LL), 8);
+
+ //
+
+ uint8_t buf[] = {0x01, 0x03, 0x00, 0x00, 0x00};
+ Block block1(buf, sizeof(buf));
+
+ BOOST_CHECK_EQUAL(e.prependByteArrayBlock(100, buf, sizeof(buf)), 7);
+ BOOST_CHECK_EQUAL(e.appendByteArrayBlock(100, buf, sizeof(buf)), 7);
+
+ BOOST_CHECK_EQUAL(e.prependBlock(block1), 5);
+ BOOST_CHECK_EQUAL(e.appendBlock(block1), 5);
+
+ Block block2(100, block1);
+
+ BOOST_CHECK_EQUAL(e.prependBlock(block2), 7);
+ BOOST_CHECK_EQUAL(e.appendBlock(block2), 7);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // EncodingEstimator
+
+} // namespace tests
+} // namespace encoding
+} // namespace ndn
diff --git a/tests/unit-tests/test-block.cpp b/tests/unit-tests/test-block.cpp
index a8c104b..959b612 100644
--- a/tests/unit-tests/test-block.cpp
+++ b/tests/unit-tests/test-block.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2014 Regents of the University of California.
+ * Copyright (c) 2013-2015 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -19,126 +19,153 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
-
#include "encoding/encoding-buffer.hpp"
#include "encoding/buffer-stream.hpp"
#include "boost-test.hpp"
-using namespace std;
namespace ndn {
+namespace tests {
BOOST_AUTO_TEST_SUITE(TestBlock)
-BOOST_AUTO_TEST_CASE(BlockBasic)
+class BasicBlockFixture
{
+public:
EncodingBuffer buffer;
EncodingEstimator estimator;
- size_t s1, s2;
+};
- // VarNumber checks
+BOOST_FIXTURE_TEST_SUITE(Basic, BasicBlockFixture)
- s1 = buffer.prependVarNumber(252);
- s2 = estimator.prependVarNumber(252);
+BOOST_AUTO_TEST_CASE(VarNumberOneByte1)
+{
+ size_t s1 = buffer.prependVarNumber(252);
+ size_t s2 = estimator.prependVarNumber(252);
BOOST_CHECK_EQUAL(buffer.size(), 1);
BOOST_CHECK_EQUAL(s1, 1);
BOOST_CHECK_EQUAL(s2, 1);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependVarNumber(253);
- s2 = estimator.prependVarNumber(253);
+BOOST_AUTO_TEST_CASE(VarNumberOneByte2)
+{
+ size_t s1 = buffer.prependVarNumber(253);
+ size_t s2 = estimator.prependVarNumber(253);
BOOST_CHECK_EQUAL(buffer.size(), 3);
BOOST_CHECK_EQUAL(s1, 3);
BOOST_CHECK_EQUAL(s2, 3);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependVarNumber(255);
- s2 = estimator.prependVarNumber(255);
+BOOST_AUTO_TEST_CASE(VarNumberThreeBytes1)
+{
+ size_t s1 = buffer.prependVarNumber(255);
+ size_t s2 = estimator.prependVarNumber(255);
BOOST_CHECK_EQUAL(buffer.size(), 3);
BOOST_CHECK_EQUAL(s1, 3);
BOOST_CHECK_EQUAL(s2, 3);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependVarNumber(65535);
- s2 = estimator.prependVarNumber(65535);
+BOOST_AUTO_TEST_CASE(VarNumberThreeBytes2)
+{
+ size_t s1 = buffer.prependVarNumber(65535);
+ size_t s2 = estimator.prependVarNumber(65535);
BOOST_CHECK_EQUAL(buffer.size(), 3);
BOOST_CHECK_EQUAL(s1, 3);
BOOST_CHECK_EQUAL(s2, 3);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependVarNumber(65536);
- s2 = estimator.prependVarNumber(65536);
+BOOST_AUTO_TEST_CASE(VarNumberFiveBytes1)
+{
+ size_t s1 = buffer.prependVarNumber(65536);
+ size_t s2 = estimator.prependVarNumber(65536);
BOOST_CHECK_EQUAL(buffer.size(), 5);
BOOST_CHECK_EQUAL(s1, 5);
BOOST_CHECK_EQUAL(s2, 5);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependVarNumber(4294967295LL);
- s2 = estimator.prependVarNumber(4294967295LL);
+BOOST_AUTO_TEST_CASE(VarNumberFiveBytes2)
+{
+ size_t s1 = buffer.prependVarNumber(4294967295LL);
+ size_t s2 = estimator.prependVarNumber(4294967295LL);
BOOST_CHECK_EQUAL(buffer.size(), 5);
BOOST_CHECK_EQUAL(s1, 5);
BOOST_CHECK_EQUAL(s2, 5);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependVarNumber(4294967296LL);
- s2 = estimator.prependVarNumber(4294967296LL);
+BOOST_AUTO_TEST_CASE(VarNumberNineBytes)
+{
+ size_t s1 = buffer.prependVarNumber(4294967296LL);
+ size_t s2 = estimator.prependVarNumber(4294967296LL);
BOOST_CHECK_EQUAL(buffer.size(), 9);
BOOST_CHECK_EQUAL(s1, 9);
BOOST_CHECK_EQUAL(s2, 9);
- buffer = EncodingBuffer();
+}
- // nonNegativeInteger checks
-
- s1 = buffer.prependNonNegativeInteger(252);
- s2 = estimator.prependNonNegativeInteger(252);
+BOOST_AUTO_TEST_CASE(NonNegativeNumberOneByte1)
+{
+ size_t s1 = buffer.prependNonNegativeInteger(252);
+ size_t s2 = estimator.prependNonNegativeInteger(252);
BOOST_CHECK_EQUAL(buffer.size(), 1);
BOOST_CHECK_EQUAL(s1, 1);
BOOST_CHECK_EQUAL(s2, 1);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependNonNegativeInteger(255);
- s2 = estimator.prependNonNegativeInteger(255);
+BOOST_AUTO_TEST_CASE(NonNegativeNumberOneByte2)
+{
+ size_t s1 = buffer.prependNonNegativeInteger(255);
+ size_t s2 = estimator.prependNonNegativeInteger(255);
BOOST_CHECK_EQUAL(buffer.size(), 1);
BOOST_CHECK_EQUAL(s1, 1);
BOOST_CHECK_EQUAL(s2, 1);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependNonNegativeInteger(256);
- s2 = estimator.prependNonNegativeInteger(256);
+BOOST_AUTO_TEST_CASE(NonNegativeNumberTwoBytes1)
+{
+ size_t s1 = buffer.prependNonNegativeInteger(256);
+ size_t s2 = estimator.prependNonNegativeInteger(256);
BOOST_CHECK_EQUAL(buffer.size(), 2);
BOOST_CHECK_EQUAL(s1, 2);
BOOST_CHECK_EQUAL(s2, 2);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependNonNegativeInteger(65535);
- s2 = estimator.prependNonNegativeInteger(65535);
+BOOST_AUTO_TEST_CASE(NonNegativeNumberTwoBytes2)
+{
+ size_t s1 = buffer.prependNonNegativeInteger(65535);
+ size_t s2 = estimator.prependNonNegativeInteger(65535);
BOOST_CHECK_EQUAL(buffer.size(), 2);
BOOST_CHECK_EQUAL(s1, 2);
BOOST_CHECK_EQUAL(s2, 2);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependNonNegativeInteger(65536);
- s2 = estimator.prependNonNegativeInteger(65536);
+BOOST_AUTO_TEST_CASE(NonNegativeNumberFourBytes1)
+{
+ size_t s1 = buffer.prependNonNegativeInteger(65536);
+ size_t s2 = estimator.prependNonNegativeInteger(65536);
BOOST_CHECK_EQUAL(buffer.size(), 4);
BOOST_CHECK_EQUAL(s1, 4);
BOOST_CHECK_EQUAL(s2, 4);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependNonNegativeInteger(4294967295LL);
- s2 = estimator.prependNonNegativeInteger(4294967295LL);
+BOOST_AUTO_TEST_CASE(NonNegativeNumberFourBytes2)
+{
+ size_t s1 = buffer.prependNonNegativeInteger(4294967295LL);
+ size_t s2 = estimator.prependNonNegativeInteger(4294967295LL);
BOOST_CHECK_EQUAL(buffer.size(), 4);
BOOST_CHECK_EQUAL(s1, 4);
BOOST_CHECK_EQUAL(s2, 4);
- buffer = EncodingBuffer();
+}
- s1 = buffer.prependNonNegativeInteger(4294967296LL);
- s2 = estimator.prependNonNegativeInteger(4294967296LL);
+BOOST_AUTO_TEST_CASE(NonNegativeNumberEightBytes)
+{
+ size_t s1 = buffer.prependNonNegativeInteger(4294967296LL);
+ size_t s2 = estimator.prependNonNegativeInteger(4294967296LL);
BOOST_CHECK_EQUAL(buffer.size(), 8);
BOOST_CHECK_EQUAL(s1, 8);
BOOST_CHECK_EQUAL(s2, 8);
- buffer = EncodingBuffer();
}
+BOOST_AUTO_TEST_SUITE_END() // Basic
+
BOOST_AUTO_TEST_CASE(EncodingBufferToBlock)
{
uint8_t value[4];
@@ -166,19 +193,24 @@
Block block(0xab, buf);
block.encode();
- EncodingBuffer buffer(0,0);
- BOOST_REQUIRE_NO_THROW(buffer = EncodingBuffer(block));
- BOOST_CHECK_EQUAL(buffer.size(), 12);
- BOOST_CHECK_EQUAL(buffer.capacity(), 12);
+ {
+ BOOST_REQUIRE_NO_THROW(EncodingBuffer(block));
+ EncodingBuffer buffer(block);
+ BOOST_CHECK_EQUAL(buffer.size(), 12);
+ BOOST_CHECK_EQUAL(buffer.capacity(), 12);
+ }
(*buf)[1] = 0xe0;
(*buf)[2] = 2;
BOOST_REQUIRE_NO_THROW(block = Block(buf, buf->begin() + 1, buf->begin() + 5));
BOOST_CHECK_EQUAL(block.type(), 0xe0);
- BOOST_REQUIRE_NO_THROW(buffer = EncodingBuffer(block));
- BOOST_CHECK_EQUAL(buffer.size(), 4);
- BOOST_CHECK_EQUAL(buffer.capacity(), 10);
+ {
+ BOOST_REQUIRE_NO_THROW(EncodingBuffer(block));
+ EncodingBuffer buffer(block);
+ BOOST_CHECK_EQUAL(buffer.size(), 4);
+ BOOST_CHECK_EQUAL(buffer.capacity(), 10);
+ }
}
BOOST_AUTO_TEST_CASE(FromBuffer)
@@ -280,4 +312,5 @@
BOOST_AUTO_TEST_SUITE_END()
+} // namespace tests
} // namespace ndn
diff --git a/tests/unit-tests/test-name.cpp b/tests/unit-tests/test-name.cpp
index e2f45ab..0eef98b 100644
--- a/tests/unit-tests/test-name.cpp
+++ b/tests/unit-tests/test-name.cpp
@@ -459,6 +459,37 @@
BOOST_CHECK_GE(name::Component("A"), comp0);
}
+BOOST_AUTO_TEST_CASE(CreateComponentWithIterators) // Bug #2490
+{
+ {
+ std::vector<uint8_t> bytes = {1};
+ name::Component c(bytes.begin(), bytes.end());
+ BOOST_CHECK_EQUAL(c.value_size(), 1);
+ BOOST_CHECK_EQUAL(c.size(), 3);
+ }
+
+ {
+ std::list<uint8_t> bytes = {1, 2, 3, 4};
+ name::Component c(bytes.begin(), bytes.end());
+ BOOST_CHECK_EQUAL(c.value_size(), 4);
+ BOOST_CHECK_EQUAL(c.size(), 6);
+ }
+
+ {
+ std::vector<int8_t> bytes = {1};
+ name::Component c(bytes.begin(), bytes.end());
+ BOOST_CHECK_EQUAL(c.value_size(), 1);
+ BOOST_CHECK_EQUAL(c.size(), 3);
+ }
+
+ {
+ std::list<int8_t> bytes = {1, 2, 3, 4};
+ name::Component c(bytes.begin(), bytes.end());
+ BOOST_CHECK_EQUAL(c.value_size(), 4);
+ BOOST_CHECK_EQUAL(c.size(), 6);
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace ndn
diff --git a/tests/unit-tests/util/simple-notification.hpp b/tests/unit-tests/util/simple-notification.hpp
index e90e374..1d22a2a 100644
--- a/tests/unit-tests/util/simple-notification.hpp
+++ b/tests/unit-tests/util/simple-notification.hpp
@@ -1,6 +1,12 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2014 Regents of the University of California.
+ * Copyright (c) 2014-2015, 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,
+ * The University of Memphis.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -19,32 +25,6 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
-/**
- * Original copyright notice from NFD:
- *
- * 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,
- * The University of Memphis
- *
- * 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/>.
- */
-
#ifndef NDN_UNIT_TESTS_UTIL_SIMPLE_NOTIFICATION_HPP
#define NDN_UNIT_TESTS_UTIL_SIMPLE_NOTIFICATION_HPP
@@ -83,10 +63,9 @@
wireEncode() const
{
ndn::EncodingBuffer buffer;
- prependByteArrayBlock(buffer,
- 0x8888,
- reinterpret_cast<const uint8_t*>(m_message.c_str()),
- m_message.size());
+ buffer.prependByteArrayBlock(0x8888,
+ reinterpret_cast<const uint8_t*>(m_message.c_str()),
+ m_message.size());
return buffer.block();
}