util: backport C++20 std::span and use it in various APIs
Implementation taken from span-lite by Martin Moene,
commit 337af6e23f6d3264136c16565546244da23159ba
Change-Id: Icfd0ba6841cbf6ef7870c31c881df940da9faf7e
diff --git a/tests/unit/encoding/block-helpers.t.cpp b/tests/unit/encoding/block-helpers.t.cpp
index c44be84..4b26109 100644
--- a/tests/unit/encoding/block-helpers.t.cpp
+++ b/tests/unit/encoding/block-helpers.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -101,19 +101,22 @@
BOOST_CHECK_THROW(readDouble("64043E800000"_block), tlv::Error);
}
-BOOST_AUTO_TEST_CASE(Data)
+BOOST_AUTO_TEST_CASE(Binary)
{
std::string buf1{1, 1, 1, 1};
const uint8_t buf2[]{1, 1, 1, 1};
std::list<uint8_t> buf3{1, 1, 1, 1};
- Block b1 = makeBinaryBlock(100, buf1.data(), buf1.size());
- Block b2 = makeBinaryBlock(100, buf2, sizeof(buf2));
- Block b3 = makeBinaryBlock(100, buf1.begin(), buf1.end()); // fast encoding (random access iterator)
- Block b4 = makeBinaryBlock(100, buf3.begin(), buf3.end()); // slow encoding (general iterator)
+ Block b1 = makeBinaryBlock(100, buf1.data(), buf1.size()); // char* overload
+ Block b2 = makeBinaryBlock(100, buf2, sizeof(buf2)); // uint8_t* overload
+ Block b3 = makeBinaryBlock(100, buf2); // span overload
+ Block b4 = makeBinaryBlock(100, buf1.begin(), buf1.end()); // fast encoding (random access iterator)
+ Block b5 = makeBinaryBlock(100, buf3.begin(), buf3.end()); // slow encoding (general iterator)
BOOST_CHECK_EQUAL(b1, b2);
BOOST_CHECK_EQUAL(b1, b3);
+ BOOST_CHECK_EQUAL(b1, b4);
+ BOOST_CHECK_EQUAL(b1, b5);
BOOST_CHECK_EQUAL(b1.type(), 100);
BOOST_CHECK_EQUAL(b1.value_size(), buf1.size());
BOOST_CHECK_EQUAL_COLLECTIONS(b1.value_begin(), b1.value_end(), buf2, buf2 + sizeof(buf2));