summaryrefslogtreecommitdiffstats
path: root/src/template_test.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-11 16:46:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-11 16:46:31 +0000
commite0d38508fc8b6bc3915b2235a85a068eacfb87bf (patch)
tree75de5a3a58d59b983ce82cde4f631a318cd6f13f /src/template_test.cc
parentReleasing progress-linux version 1.61.0-1~progress7.99u1. (diff)
downloadnghttp2-e0d38508fc8b6bc3915b2235a85a068eacfb87bf.tar.xz
nghttp2-e0d38508fc8b6bc3915b2235a85a068eacfb87bf.zip
Merging upstream version 1.62.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/template_test.cc')
-rw-r--r--src/template_test.cc35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/template_test.cc b/src/template_test.cc
index db212d1..99b193b 100644
--- a/src/template_test.cc
+++ b/src/template_test.cc
@@ -32,12 +32,15 @@
#include "template.h"
+using namespace std::literals;
+
namespace nghttp2 {
namespace {
const MunitTest tests[]{
munit_void_test(test_template_immutable_string),
munit_void_test(test_template_string_ref),
+ munit_void_test(test_template_as_uint8_span),
munit_test_end(),
};
} // namespace
@@ -147,7 +150,7 @@ void test_template_immutable_string(void) {
void test_template_string_ref(void) {
StringRef empty;
- assert_stdstring_equal("", empty.str());
+ assert_stdsv_equal(""sv, empty);
assert_size(0, ==, empty.size());
// from std::string
@@ -162,9 +165,9 @@ void test_template_string_ref(void) {
assert_size(5, ==, ref.size());
// from string literal
- auto from_lit = StringRef::from_lit("alpha");
+ auto from_lit = "alpha"_sr;
- assert_stdstring_equal("alpha", from_lit.str());
+ assert_stdsv_equal("alpha"sv, from_lit);
assert_size(5, ==, from_lit.size());
// from ImmutableString
@@ -172,19 +175,19 @@ void test_template_string_ref(void) {
StringRef imref(im);
- assert_stdstring_equal("bravo", imref.str());
+ assert_stdsv_equal("bravo"sv, imref);
assert_size(5, ==, imref.size());
// from C-string
StringRef cstrref("charlie");
- assert_stdstring_equal("charlie", cstrref.str());
+ assert_stdsv_equal("charlie"sv, cstrref);
assert_size(7, ==, cstrref.size());
// from C-string and its length
StringRef cstrnref("delta", 5);
- assert_stdstring_equal("delta", cstrnref.str());
+ assert_stdsv_equal("delta"sv, cstrnref);
assert_size(5, ==, cstrnref.size());
// operator[]
@@ -213,4 +216,24 @@ void test_template_string_ref(void) {
}
}
+void test_template_as_uint8_span(void) {
+ uint32_t a[2];
+
+ memcpy(&a, "\xc0\xc1\xc2\xc3\xf0\xf1\xf2\xf3", sizeof(a));
+
+ // dynamic extent
+ auto s = as_uint8_span(std::span{a, 2});
+
+ assert_size(sizeof(a), ==, s.size());
+ assert_size(std::dynamic_extent, ==, s.extent);
+ assert_memory_equal(s.size(), &a, s.data());
+
+ // non-dynamic extent
+ auto t = as_uint8_span(std::span<uint32_t, 2>{a, 2});
+
+ assert_size(sizeof(a), ==, t.size());
+ assert_size(sizeof(a), ==, t.extent);
+ assert_memory_equal(t.size(), &a, t.data());
+}
+
} // namespace nghttp2