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/base64-encode.t.cpp b/tests/unit/security/transform/base64-encode.t.cpp
index 228f214..7b4aa47 100644
--- a/tests/unit/security/transform/base64-encode.t.cpp
+++ b/tests/unit/security/transform/base64-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).
*
@@ -39,7 +39,7 @@
BOOST_AUTO_TEST_CASE(Basic)
{
- 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,
@@ -57,14 +57,13 @@
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
-
- std::string out =
+ const std::string out =
"AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4P\n"
"AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4P\n"
"AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8=\n";
OBufferStream os;
- bufferSource(in, sizeof(in)) >> base64Encode() >> streamSink(os);
+ bufferSource(in) >> base64Encode() >> 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(NoNewLine)
{
- 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,
@@ -90,14 +89,13 @@
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
-
- std::string out =
+ const std::string out =
"AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4P"
"AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4P"
"AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8=";
OBufferStream os;
- BufferSource(in, sizeof(in)) >> base64Encode(false) >> streamSink(os);
+ BufferSource(in) >> base64Encode(false) >> streamSink(os);
ConstBufferPtr buf1 = os.buf();
BOOST_CHECK_EQUAL_COLLECTIONS(out.begin(), out.end(), buf1->begin(), buf1->end());
@@ -105,7 +103,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,
@@ -131,8 +129,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 =
"AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4P\n"
"AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4P\n"
"AAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4P\n"
@@ -145,15 +142,15 @@
OBufferStream os;
StepSource source;
source >> base64Encode() >> 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, 24); // front of a chunk
- source.write(in + 152, 20); // middle of a chunk
- source.write(in + 172, 20); // 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, 24}); // front of a chunk
+ source.write({in + 152, 20}); // middle of a chunk
+ source.write({in + 172, 20}); // 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();
@@ -166,6 +163,7 @@
StepSource source;
source >> base64Encode() >> streamSink(os);
source.end();
+
BOOST_CHECK_EQUAL(os.buf()->size(), 0);
}