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/security/transform/hex-encode.t.cpp b/tests/unit/security/transform/hex-encode.t.cpp
index 791fdd7..8025c37 100644
--- a/tests/unit/security/transform/hex-encode.t.cpp
+++ b/tests/unit/security/transform/hex-encode.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).
*
@@ -38,7 +38,7 @@
BOOST_AUTO_TEST_CASE(Basic)
{
- uint8_t in[128] = {
+ const uint8_t in[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -56,15 +56,14 @@
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
-
- std::string out =
+ const std::string out =
"000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"
"000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"
"000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"
"000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f";
OBufferStream os;
- bufferSource(in, sizeof(in)) >> hexEncode() >> streamSink(os);
+ bufferSource(in) >> hexEncode() >> streamSink(os);
ConstBufferPtr buf1 = os.buf();
BOOST_CHECK_EQUAL_COLLECTIONS(out.begin(), out.end(), buf1->begin(), buf1->end());
@@ -72,7 +71,7 @@
BOOST_AUTO_TEST_CASE(UpperCase)
{
- uint8_t in[128] = {
+ const uint8_t in[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -90,15 +89,14 @@
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
-
- std::string out =
+ const std::string out =
"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F"
"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F"
"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F"
"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F";
OBufferStream os;
- bufferSource(in, sizeof(in)) >> hexEncode(true) >> streamSink(os);
+ bufferSource(in) >> hexEncode(true) >> streamSink(os);
ConstBufferPtr buf1 = os.buf();
BOOST_CHECK_EQUAL_COLLECTIONS(out.begin(), out.end(), buf1->begin(), buf1->end());
@@ -106,7 +104,7 @@
BOOST_AUTO_TEST_CASE(StepByStep)
{
- uint8_t in[] = {
+ const uint8_t in[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
@@ -132,8 +130,7 @@
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
-
- std::string out =
+ const std::string out =
"000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"
"000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"
"000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f"
@@ -150,15 +147,15 @@
OBufferStream os;
StepSource source;
source >> hexEncode() >> streamSink(os);
- source.write(in, 64); // complete chunk
- source.write(in + 64, 32); // first half of a chunk
- source.write(in + 96, 32); // second half of a chunk
- source.write(in + 128, 20); // front of a chunk
- source.write(in + 148, 20); // middle of a chunk
- source.write(in + 168, 24); // end of a chunk
- source.write(in + 192, 63); // odd number of bytes
- source.write(in + 255, 85); // one and half chunk
- source.write(in + 340, 44); // remaining part
+ source.write({in, 64}); // complete chunk
+ source.write({in + 64, 32}); // first half of a chunk
+ source.write({in + 96, 32}); // second half of a chunk
+ source.write({in + 128, 20}); // front of a chunk
+ source.write({in + 148, 20}); // middle of a chunk
+ source.write({in + 168, 24}); // end of a chunk
+ source.write({in + 192, 63}); // odd number of bytes
+ source.write({in + 255, 85}); // one and half chunk
+ source.write({in + 340, 44}); // remaining part
source.end();
ConstBufferPtr buf1 = os.buf();
@@ -171,6 +168,7 @@
StepSource source;
source >> hexEncode() >> streamSink(os);
source.end();
+
BOOST_CHECK_EQUAL(os.buf()->size(), 0);
}