summaryrefslogtreecommitdiffstats
path: root/src/util_test.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 08:52:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 08:52:01 +0000
commit42f47327da6a208ac3cd1f9bca07fc506ed51a63 (patch)
treee06c5e993e0d0b618f616280b372506b1f0f8419 /src/util_test.cc
parentAdding debian version 1.59.0-1. (diff)
downloadnghttp2-42f47327da6a208ac3cd1f9bca07fc506ed51a63.tar.xz
nghttp2-42f47327da6a208ac3cd1f9bca07fc506ed51a63.zip
Merging upstream version 1.60.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/util_test.cc841
1 files changed, 468 insertions, 373 deletions
diff --git a/src/util_test.cc b/src/util_test.cc
index 0ac0f1d..2e01e9d 100644
--- a/src/util_test.cc
+++ b/src/util_test.cc
@@ -28,7 +28,7 @@
#include <iostream>
#include <random>
-#include <CUnit/CUnit.h>
+#include "munitxx.h"
#include <nghttp2/nghttp2.h>
@@ -39,166 +39,233 @@ using namespace nghttp2;
namespace shrpx {
+namespace {
+const MunitTest tests[]{
+ munit_void_test(test_util_streq),
+ munit_void_test(test_util_strieq),
+ munit_void_test(test_util_inp_strlower),
+ munit_void_test(test_util_to_base64),
+ munit_void_test(test_util_to_token68),
+ munit_void_test(test_util_percent_encode_token),
+ munit_void_test(test_util_percent_decode),
+ munit_void_test(test_util_quote_string),
+ munit_void_test(test_util_utox),
+ munit_void_test(test_util_http_date),
+ munit_void_test(test_util_select_h2),
+ munit_void_test(test_util_ipv6_numeric_addr),
+ munit_void_test(test_util_utos),
+ munit_void_test(test_util_make_string_ref_uint),
+ munit_void_test(test_util_utos_unit),
+ munit_void_test(test_util_utos_funit),
+ munit_void_test(test_util_parse_uint_with_unit),
+ munit_void_test(test_util_parse_uint),
+ munit_void_test(test_util_parse_duration_with_unit),
+ munit_void_test(test_util_duration_str),
+ munit_void_test(test_util_format_duration),
+ munit_void_test(test_util_starts_with),
+ munit_void_test(test_util_ends_with),
+ munit_void_test(test_util_parse_http_date),
+ munit_void_test(test_util_localtime_date),
+ munit_void_test(test_util_get_uint64),
+ munit_void_test(test_util_parse_config_str_list),
+ munit_void_test(test_util_make_http_hostport),
+ munit_void_test(test_util_make_hostport),
+ munit_void_test(test_util_strifind),
+ munit_void_test(test_util_random_alpha_digit),
+ munit_void_test(test_util_format_hex),
+ munit_void_test(test_util_is_hex_string),
+ munit_void_test(test_util_decode_hex),
+ munit_void_test(test_util_extract_host),
+ munit_void_test(test_util_split_hostport),
+ munit_void_test(test_util_split_str),
+ munit_void_test(test_util_rstrip),
+ munit_test_end(),
+};
+} // namespace
+
+const MunitSuite util_suite{
+ "/util", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE,
+};
+
void test_util_streq(void) {
- CU_ASSERT(
+ assert_true(
util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alpha")));
- CU_ASSERT(!util::streq(StringRef::from_lit("alpha"),
- StringRef::from_lit("alphabravo")));
- CU_ASSERT(!util::streq(StringRef::from_lit("alphabravo"),
- StringRef::from_lit("alpha")));
- CU_ASSERT(
- !util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA")));
- CU_ASSERT(!util::streq(StringRef{}, StringRef::from_lit("a")));
- CU_ASSERT(util::streq(StringRef{}, StringRef{}));
- CU_ASSERT(!util::streq(StringRef::from_lit("alpha"), StringRef{}));
-
- CU_ASSERT(
- !util::streq(StringRef::from_lit("alph"), StringRef::from_lit("alpha")));
- CU_ASSERT(
- !util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alph")));
- CU_ASSERT(
- !util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA")));
-
- CU_ASSERT(util::streq_l("alpha", "alpha", 5));
- CU_ASSERT(util::streq_l("alpha", "alphabravo", 5));
- CU_ASSERT(!util::streq_l("alpha", "alphabravo", 6));
- CU_ASSERT(!util::streq_l("alphabravo", "alpha", 5));
- CU_ASSERT(!util::streq_l("alpha", "alphA", 5));
- CU_ASSERT(!util::streq_l("", "a", 1));
- CU_ASSERT(util::streq_l("", "", 0));
- CU_ASSERT(!util::streq_l("alpha", "", 0));
+ assert_false(util::streq(StringRef::from_lit("alpha"),
+ StringRef::from_lit("alphabravo")));
+ assert_false(util::streq(StringRef::from_lit("alphabravo"),
+ StringRef::from_lit("alpha")));
+ assert_false(
+ util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA")));
+ assert_false(util::streq(StringRef{}, StringRef::from_lit("a")));
+ assert_true(util::streq(StringRef{}, StringRef{}));
+ assert_false(util::streq(StringRef::from_lit("alpha"), StringRef{}));
+
+ assert_false(
+ util::streq(StringRef::from_lit("alph"), StringRef::from_lit("alpha")));
+ assert_false(
+ util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alph")));
+ assert_false(
+ util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA")));
+
+ assert_true(util::streq_l("alpha", "alpha", 5));
+ assert_true(util::streq_l("alpha", "alphabravo", 5));
+ assert_false(util::streq_l("alpha", "alphabravo", 6));
+ assert_false(util::streq_l("alphabravo", "alpha", 5));
+ assert_false(util::streq_l("alpha", "alphA", 5));
+ assert_false(util::streq_l("", "a", 1));
+ assert_true(util::streq_l("", "", 0));
+ assert_false(util::streq_l("alpha", "", 0));
}
void test_util_strieq(void) {
- CU_ASSERT(util::strieq(std::string("alpha"), std::string("alpha")));
- CU_ASSERT(util::strieq(std::string("alpha"), std::string("AlPhA")));
- CU_ASSERT(util::strieq(std::string(), std::string()));
- CU_ASSERT(!util::strieq(std::string("alpha"), std::string("AlPhA ")));
- CU_ASSERT(!util::strieq(std::string(), std::string("AlPhA ")));
+ assert_true(util::strieq(std::string("alpha"), std::string("alpha")));
+ assert_true(util::strieq(std::string("alpha"), std::string("AlPhA")));
+ assert_true(util::strieq(std::string(), std::string()));
+ assert_false(util::strieq(std::string("alpha"), std::string("AlPhA ")));
+ assert_false(util::strieq(std::string(), std::string("AlPhA ")));
- CU_ASSERT(
+ assert_true(
util::strieq(StringRef::from_lit("alpha"), StringRef::from_lit("alpha")));
- CU_ASSERT(
+ assert_true(
util::strieq(StringRef::from_lit("alpha"), StringRef::from_lit("AlPhA")));
- CU_ASSERT(util::strieq(StringRef{}, StringRef{}));
- CU_ASSERT(!util::strieq(StringRef::from_lit("alpha"),
- StringRef::from_lit("AlPhA ")));
- CU_ASSERT(
- !util::strieq(StringRef::from_lit(""), StringRef::from_lit("AlPhA ")));
+ assert_true(util::strieq(StringRef{}, StringRef{}));
+ assert_false(util::strieq(StringRef::from_lit("alpha"),
+ StringRef::from_lit("AlPhA ")));
+ assert_false(
+ util::strieq(StringRef::from_lit(""), StringRef::from_lit("AlPhA ")));
- CU_ASSERT(util::strieq_l("alpha", "alpha", 5));
- CU_ASSERT(util::strieq_l("alpha", "AlPhA", 5));
- CU_ASSERT(util::strieq_l("", static_cast<const char *>(nullptr), 0));
- CU_ASSERT(!util::strieq_l("alpha", "AlPhA ", 6));
- CU_ASSERT(!util::strieq_l("", "AlPhA ", 6));
+ assert_true(util::strieq_l("alpha", "alpha", 5));
+ assert_true(util::strieq_l("alpha", "AlPhA", 5));
+ assert_true(util::strieq_l("", static_cast<const char *>(nullptr), 0));
+ assert_false(util::strieq_l("alpha", "AlPhA ", 6));
+ assert_false(util::strieq_l("", "AlPhA ", 6));
- CU_ASSERT(util::strieq_l("alpha", StringRef::from_lit("alpha")));
- CU_ASSERT(util::strieq_l("alpha", StringRef::from_lit("AlPhA")));
- CU_ASSERT(util::strieq_l("", StringRef{}));
- CU_ASSERT(!util::strieq_l("alpha", StringRef::from_lit("AlPhA ")));
- CU_ASSERT(!util::strieq_l("", StringRef::from_lit("AlPhA ")));
+ assert_true(util::strieq_l("alpha", StringRef::from_lit("alpha")));
+ assert_true(util::strieq_l("alpha", StringRef::from_lit("AlPhA")));
+ assert_true(util::strieq_l("", StringRef{}));
+ assert_false(util::strieq_l("alpha", StringRef::from_lit("AlPhA ")));
+ assert_false(util::strieq_l("", StringRef::from_lit("AlPhA ")));
}
void test_util_inp_strlower(void) {
std::string a("alPha");
util::inp_strlower(a);
- CU_ASSERT("alpha" == a);
+ assert_stdstring_equal("alpha", a);
a = "ALPHA123BRAVO";
util::inp_strlower(a);
- CU_ASSERT("alpha123bravo" == a);
+ assert_stdstring_equal("alpha123bravo", a);
a = "";
util::inp_strlower(a);
- CU_ASSERT("" == a);
+ assert_stdstring_equal("", a);
}
void test_util_to_base64(void) {
BlockAllocator balloc(4096, 4096);
- CU_ASSERT("AAA++B/=" ==
- util::to_base64(balloc, StringRef::from_lit("AAA--B_")));
- CU_ASSERT("AAA++B/B" ==
- util::to_base64(balloc, StringRef::from_lit("AAA--B_B")));
+ assert_stdstring_equal(
+ "AAA++B/=",
+ util::to_base64(balloc, StringRef::from_lit("AAA--B_")).str());
+ assert_stdstring_equal(
+ "AAA++B/B",
+ util::to_base64(balloc, StringRef::from_lit("AAA--B_B")).str());
}
void test_util_to_token68(void) {
std::string x = "AAA++B/=";
util::to_token68(x);
- CU_ASSERT("AAA--B_" == x);
+ assert_stdstring_equal("AAA--B_", x);
x = "AAA++B/B";
util::to_token68(x);
- CU_ASSERT("AAA--B_B" == x);
+ assert_stdstring_equal("AAA--B_B", x);
}
void test_util_percent_encode_token(void) {
BlockAllocator balloc(4096, 4096);
- CU_ASSERT("h2" ==
- util::percent_encode_token(balloc, StringRef::from_lit("h2")));
- CU_ASSERT("h3~" ==
- util::percent_encode_token(balloc, StringRef::from_lit("h3~")));
- CU_ASSERT("100%25" ==
- util::percent_encode_token(balloc, StringRef::from_lit("100%")));
- CU_ASSERT("http%202" ==
- util::percent_encode_token(balloc, StringRef::from_lit("http 2")));
+ assert_stdstring_equal(
+ "h2",
+ util::percent_encode_token(balloc, StringRef::from_lit("h2")).str());
+ assert_stdstring_equal(
+ "h3~",
+ util::percent_encode_token(balloc, StringRef::from_lit("h3~")).str());
+ assert_stdstring_equal(
+ "100%25",
+ util::percent_encode_token(balloc, StringRef::from_lit("100%")).str());
+ assert_stdstring_equal(
+ "http%202",
+ util::percent_encode_token(balloc, StringRef::from_lit("http 2")).str());
}
void test_util_percent_decode(void) {
{
std::string s = "%66%6F%6f%62%61%72";
- CU_ASSERT("foobar" == util::percent_decode(std::begin(s), std::end(s)));
+ assert_stdstring_equal("foobar",
+ util::percent_decode(std::begin(s), std::end(s)));
}
{
std::string s = "%66%6";
- CU_ASSERT("f%6" == util::percent_decode(std::begin(s), std::end(s)));
+ assert_stdstring_equal("f%6",
+ util::percent_decode(std::begin(s), std::end(s)));
}
{
std::string s = "%66%";
- CU_ASSERT("f%" == util::percent_decode(std::begin(s), std::end(s)));
+ assert_stdstring_equal("f%",
+ util::percent_decode(std::begin(s), std::end(s)));
}
BlockAllocator balloc(1024, 1024);
- CU_ASSERT("foobar" == util::percent_decode(
- balloc, StringRef::from_lit("%66%6F%6f%62%61%72")));
+ assert_stdstring_equal(
+ "foobar",
+ util::percent_decode(balloc, StringRef::from_lit("%66%6F%6f%62%61%72"))
+ .str());
- CU_ASSERT("f%6" ==
- util::percent_decode(balloc, StringRef::from_lit("%66%6")));
+ assert_stdstring_equal(
+ "f%6", util::percent_decode(balloc, StringRef::from_lit("%66%6")).str());
- CU_ASSERT("f%" == util::percent_decode(balloc, StringRef::from_lit("%66%")));
+ assert_stdstring_equal(
+ "f%", util::percent_decode(balloc, StringRef::from_lit("%66%")).str());
}
void test_util_quote_string(void) {
BlockAllocator balloc(4096, 4096);
- CU_ASSERT("alpha" ==
- util::quote_string(balloc, StringRef::from_lit("alpha")));
- CU_ASSERT("" == util::quote_string(balloc, StringRef::from_lit("")));
- CU_ASSERT("\\\"alpha\\\"" ==
- util::quote_string(balloc, StringRef::from_lit("\"alpha\"")));
+ assert_stdstring_equal(
+ "alpha", util::quote_string(balloc, StringRef::from_lit("alpha")).str());
+ assert_stdstring_equal(
+ "", util::quote_string(balloc, StringRef::from_lit("")).str());
+ assert_stdstring_equal(
+ "\\\"alpha\\\"",
+ util::quote_string(balloc, StringRef::from_lit("\"alpha\"")).str());
}
void test_util_utox(void) {
- CU_ASSERT("0" == util::utox(0));
- CU_ASSERT("1" == util::utox(1));
- CU_ASSERT("F" == util::utox(15));
- CU_ASSERT("10" == util::utox(16));
- CU_ASSERT("3B9ACA07" == util::utox(1000000007));
- CU_ASSERT("100000000" == util::utox(1LL << 32));
+ assert_stdstring_equal("0", util::utox(0));
+ assert_stdstring_equal("1", util::utox(1));
+ assert_stdstring_equal("F", util::utox(15));
+ assert_stdstring_equal("10", util::utox(16));
+ assert_stdstring_equal("3B9ACA07", util::utox(1000000007));
+ assert_stdstring_equal("100000000", util::utox(1LL << 32));
}
void test_util_http_date(void) {
- CU_ASSERT("Thu, 01 Jan 1970 00:00:00 GMT" == util::http_date(0));
- CU_ASSERT("Wed, 29 Feb 2012 09:15:16 GMT" == util::http_date(1330506916));
+ assert_stdstring_equal("Thu, 01 Jan 1970 00:00:00 GMT", util::http_date(0));
+ assert_stdstring_equal("Wed, 29 Feb 2012 09:15:16 GMT",
+ util::http_date(1330506916));
std::array<char, 30> http_buf;
- CU_ASSERT("Thu, 01 Jan 1970 00:00:00 GMT" ==
- util::format_http_date(http_buf.data(),
- std::chrono::system_clock::time_point()));
- CU_ASSERT("Wed, 29 Feb 2012 09:15:16 GMT" ==
- util::format_http_date(http_buf.data(),
- std::chrono::system_clock::time_point(
- std::chrono::seconds(1330506916))));
+ assert_stdstring_equal(
+ "Thu, 01 Jan 1970 00:00:00 GMT",
+ util::format_http_date(http_buf.data(),
+ std::chrono::system_clock::time_point())
+ .str());
+ assert_stdstring_equal(
+ "Wed, 29 Feb 2012 09:15:16 GMT",
+ util::format_http_date(http_buf.data(),
+ std::chrono::system_clock::time_point(
+ std::chrono::seconds(1330506916)))
+ .str());
}
void test_util_select_h2(void) {
@@ -207,10 +274,10 @@ void test_util_select_h2(void) {
// Check single entry and select it.
const unsigned char t1[] = "\x2h2";
- CU_ASSERT(util::select_h2(&out, &outlen, t1, sizeof(t1) - 1));
- CU_ASSERT(
- memcmp(NGHTTP2_PROTO_VERSION_ID, out, NGHTTP2_PROTO_VERSION_ID_LEN) == 0);
- CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen);
+ assert_true(util::select_h2(&out, &outlen, t1, sizeof(t1) - 1));
+ assert_memory_equal(NGHTTP2_PROTO_VERSION_ID_LEN, NGHTTP2_PROTO_VERSION_ID,
+ out);
+ assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen);
out = nullptr;
outlen = 0;
@@ -218,224 +285,235 @@ void test_util_select_h2(void) {
// Check the case where id is correct but length is invalid and too
// long.
const unsigned char t2[] = "\x6h2-14";
- CU_ASSERT(!util::select_h2(&out, &outlen, t2, sizeof(t2) - 1));
+ assert_false(util::select_h2(&out, &outlen, t2, sizeof(t2) - 1));
// Check the case where h2 is located after bogus ID.
const unsigned char t3[] = "\x2h3\x2h2";
- CU_ASSERT(util::select_h2(&out, &outlen, t3, sizeof(t3) - 1));
+ assert_true(util::select_h2(&out, &outlen, t3, sizeof(t3) - 1));
- CU_ASSERT(
- memcmp(NGHTTP2_PROTO_VERSION_ID, out, NGHTTP2_PROTO_VERSION_ID_LEN) == 0);
- CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen);
+ assert_memory_equal(NGHTTP2_PROTO_VERSION_ID_LEN, NGHTTP2_PROTO_VERSION_ID,
+ out);
+ assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen);
out = nullptr;
outlen = 0;
// Check the case that last entry's length is invalid and too long.
const unsigned char t4[] = "\x2h3\x6h2-14";
- CU_ASSERT(!util::select_h2(&out, &outlen, t4, sizeof(t4) - 1));
+ assert_false(util::select_h2(&out, &outlen, t4, sizeof(t4) - 1));
// Check the case that all entries are not supported.
const unsigned char t5[] = "\x2h3\x2h4";
- CU_ASSERT(!util::select_h2(&out, &outlen, t5, sizeof(t5) - 1));
+ assert_false(util::select_h2(&out, &outlen, t5, sizeof(t5) - 1));
// Check the case where 2 values are eligible, but last one is
// picked up because it has precedence over the other.
const unsigned char t6[] = "\x5h2-14\x5h2-16";
- CU_ASSERT(util::select_h2(&out, &outlen, t6, sizeof(t6) - 1));
- CU_ASSERT(util::streq(NGHTTP2_H2_16, StringRef{out, outlen}));
+ assert_true(util::select_h2(&out, &outlen, t6, sizeof(t6) - 1));
+ assert_true(util::streq(NGHTTP2_H2_16, StringRef{out, outlen}));
}
void test_util_ipv6_numeric_addr(void) {
- CU_ASSERT(util::ipv6_numeric_addr("::1"));
- CU_ASSERT(util::ipv6_numeric_addr("2001:0db8:85a3:0042:1000:8a2e:0370:7334"));
+ assert_true(util::ipv6_numeric_addr("::1"));
+ assert_true(
+ util::ipv6_numeric_addr("2001:0db8:85a3:0042:1000:8a2e:0370:7334"));
// IPv4
- CU_ASSERT(!util::ipv6_numeric_addr("127.0.0.1"));
+ assert_false(util::ipv6_numeric_addr("127.0.0.1"));
// not numeric address
- CU_ASSERT(!util::ipv6_numeric_addr("localhost"));
+ assert_false(util::ipv6_numeric_addr("localhost"));
}
void test_util_utos(void) {
uint8_t buf[32];
- CU_ASSERT(("0" == StringRef{buf, util::utos(buf, 0)}));
- CU_ASSERT(("123" == StringRef{buf, util::utos(buf, 123)}));
- CU_ASSERT(("18446744073709551615" ==
- StringRef{buf, util::utos(buf, 18446744073709551615ULL)}));
+ assert_stdstring_equal("0", (std::string{buf, util::utos(buf, 0)}));
+ assert_stdstring_equal("123", (std::string{buf, util::utos(buf, 123)}));
+ assert_stdstring_equal(
+ "18446744073709551615",
+ (std::string{buf, util::utos(buf, 18446744073709551615ULL)}));
}
void test_util_make_string_ref_uint(void) {
BlockAllocator balloc(1024, 1024);
- CU_ASSERT("0" == util::make_string_ref_uint(balloc, 0));
- CU_ASSERT("123" == util::make_string_ref_uint(balloc, 123));
- CU_ASSERT("18446744073709551615" ==
- util::make_string_ref_uint(balloc, 18446744073709551615ULL));
+ assert_stdstring_equal("0", util::make_string_ref_uint(balloc, 0).str());
+ assert_stdstring_equal("123", util::make_string_ref_uint(balloc, 123).str());
+ assert_stdstring_equal(
+ "18446744073709551615",
+ util::make_string_ref_uint(balloc, 18446744073709551615ULL).str());
}
void test_util_utos_unit(void) {
- CU_ASSERT("0" == util::utos_unit(0));
- CU_ASSERT("1023" == util::utos_unit(1023));
- CU_ASSERT("1K" == util::utos_unit(1024));
- CU_ASSERT("1K" == util::utos_unit(1025));
- CU_ASSERT("1M" == util::utos_unit(1 << 20));
- CU_ASSERT("1G" == util::utos_unit(1 << 30));
- CU_ASSERT("1024G" == util::utos_unit(1LL << 40));
+ assert_stdstring_equal("0", util::utos_unit(0));
+ assert_stdstring_equal("1023", util::utos_unit(1023));
+ assert_stdstring_equal("1K", util::utos_unit(1024));
+ assert_stdstring_equal("1K", util::utos_unit(1025));
+ assert_stdstring_equal("1M", util::utos_unit(1 << 20));
+ assert_stdstring_equal("1G", util::utos_unit(1 << 30));
+ assert_stdstring_equal("1024G", util::utos_unit(1LL << 40));
}
void test_util_utos_funit(void) {
- CU_ASSERT("0" == util::utos_funit(0));
- CU_ASSERT("1023" == util::utos_funit(1023));
- CU_ASSERT("1.00K" == util::utos_funit(1024));
- CU_ASSERT("1.00K" == util::utos_funit(1025));
- CU_ASSERT("1.09K" == util::utos_funit(1119));
- CU_ASSERT("1.27K" == util::utos_funit(1300));
- CU_ASSERT("1.00M" == util::utos_funit(1 << 20));
- CU_ASSERT("1.18M" == util::utos_funit(1234567));
- CU_ASSERT("1.00G" == util::utos_funit(1 << 30));
- CU_ASSERT("4492450797.23G" == util::utos_funit(4823732313248234343LL));
- CU_ASSERT("1024.00G" == util::utos_funit(1LL << 40));
+ assert_stdstring_equal("0", util::utos_funit(0));
+ assert_stdstring_equal("1023", util::utos_funit(1023));
+ assert_stdstring_equal("1.00K", util::utos_funit(1024));
+ assert_stdstring_equal("1.00K", util::utos_funit(1025));
+ assert_stdstring_equal("1.09K", util::utos_funit(1119));
+ assert_stdstring_equal("1.27K", util::utos_funit(1300));
+ assert_stdstring_equal("1.00M", util::utos_funit(1 << 20));
+ assert_stdstring_equal("1.18M", util::utos_funit(1234567));
+ assert_stdstring_equal("1.00G", util::utos_funit(1 << 30));
+ assert_stdstring_equal("4492450797.23G",
+ util::utos_funit(4823732313248234343LL));
+ assert_stdstring_equal("1024.00G", util::utos_funit(1LL << 40));
}
void test_util_parse_uint_with_unit(void) {
- CU_ASSERT(0 == util::parse_uint_with_unit("0"));
- CU_ASSERT(1023 == util::parse_uint_with_unit("1023"));
- CU_ASSERT(1024 == util::parse_uint_with_unit("1k"));
- CU_ASSERT(2048 == util::parse_uint_with_unit("2K"));
- CU_ASSERT(1 << 20 == util::parse_uint_with_unit("1m"));
- CU_ASSERT(1 << 21 == util::parse_uint_with_unit("2M"));
- CU_ASSERT(1 << 30 == util::parse_uint_with_unit("1g"));
- CU_ASSERT(1LL << 31 == util::parse_uint_with_unit("2G"));
- CU_ASSERT(9223372036854775807LL ==
- util::parse_uint_with_unit("9223372036854775807"));
+ assert_int64(0, ==, util::parse_uint_with_unit("0"));
+ assert_int64(1023, ==, util::parse_uint_with_unit("1023"));
+ assert_int64(1024, ==, util::parse_uint_with_unit("1k"));
+ assert_int64(2048, ==, util::parse_uint_with_unit("2K"));
+ assert_int64(1 << 20, ==, util::parse_uint_with_unit("1m"));
+ assert_int64(1 << 21, ==, util::parse_uint_with_unit("2M"));
+ assert_int64(1 << 30, ==, util::parse_uint_with_unit("1g"));
+ assert_int64(1LL << 31, ==, util::parse_uint_with_unit("2G"));
+ assert_int64(9223372036854775807LL, ==,
+ util::parse_uint_with_unit("9223372036854775807"));
// check overflow case
- CU_ASSERT(-1 == util::parse_uint_with_unit("9223372036854775808"));
- CU_ASSERT(-1 == util::parse_uint_with_unit("10000000000000000000"));
- CU_ASSERT(-1 == util::parse_uint_with_unit("9223372036854775807G"));
+ assert_int64(-1, ==, util::parse_uint_with_unit("9223372036854775808"));
+ assert_int64(-1, ==, util::parse_uint_with_unit("10000000000000000000"));
+ assert_int64(-1, ==, util::parse_uint_with_unit("9223372036854775807G"));
// bad characters
- CU_ASSERT(-1 == util::parse_uint_with_unit("1.1"));
- CU_ASSERT(-1 == util::parse_uint_with_unit("1a"));
- CU_ASSERT(-1 == util::parse_uint_with_unit("a1"));
- CU_ASSERT(-1 == util::parse_uint_with_unit("1T"));
- CU_ASSERT(-1 == util::parse_uint_with_unit(""));
+ assert_int64(-1, ==, util::parse_uint_with_unit("1.1"));
+ assert_int64(-1, ==, util::parse_uint_with_unit("1a"));
+ assert_int64(-1, ==, util::parse_uint_with_unit("a1"));
+ assert_int64(-1, ==, util::parse_uint_with_unit("1T"));
+ assert_int64(-1, ==, util::parse_uint_with_unit(""));
}
void test_util_parse_uint(void) {
- CU_ASSERT(0 == util::parse_uint("0"));
- CU_ASSERT(1023 == util::parse_uint("1023"));
- CU_ASSERT(-1 == util::parse_uint("1k"));
- CU_ASSERT(9223372036854775807LL == util::parse_uint("9223372036854775807"));
+ assert_int64(0, ==, util::parse_uint("0"));
+ assert_int64(1023, ==, util::parse_uint("1023"));
+ assert_int64(-1, ==, util::parse_uint("1k"));
+ assert_int64(9223372036854775807LL, ==,
+ util::parse_uint("9223372036854775807"));
// check overflow case
- CU_ASSERT(-1 == util::parse_uint("9223372036854775808"));
- CU_ASSERT(-1 == util::parse_uint("10000000000000000000"));
+ assert_int64(-1, ==, util::parse_uint("9223372036854775808"));
+ assert_int64(-1, ==, util::parse_uint("10000000000000000000"));
// bad characters
- CU_ASSERT(-1 == util::parse_uint("1.1"));
- CU_ASSERT(-1 == util::parse_uint("1a"));
- CU_ASSERT(-1 == util::parse_uint("a1"));
- CU_ASSERT(-1 == util::parse_uint("1T"));
- CU_ASSERT(-1 == util::parse_uint(""));
+ assert_int64(-1, ==, util::parse_uint("1.1"));
+ assert_int64(-1, ==, util::parse_uint("1a"));
+ assert_int64(-1, ==, util::parse_uint("a1"));
+ assert_int64(-1, ==, util::parse_uint("1T"));
+ assert_int64(-1, ==, util::parse_uint(""));
}
void test_util_parse_duration_with_unit(void) {
- CU_ASSERT(0. == util::parse_duration_with_unit("0"));
- CU_ASSERT(123. == util::parse_duration_with_unit("123"));
- CU_ASSERT(123. == util::parse_duration_with_unit("123s"));
- CU_ASSERT(0.500 == util::parse_duration_with_unit("500ms"));
- CU_ASSERT(123. == util::parse_duration_with_unit("123S"));
- CU_ASSERT(0.500 == util::parse_duration_with_unit("500MS"));
- CU_ASSERT(180 == util::parse_duration_with_unit("3m"));
- CU_ASSERT(3600 * 5 == util::parse_duration_with_unit("5h"));
+ assert_double(0., ==, util::parse_duration_with_unit("0"));
+ assert_double(123., ==, util::parse_duration_with_unit("123"));
+ assert_double(123., ==, util::parse_duration_with_unit("123s"));
+ assert_double(0.500, ==, util::parse_duration_with_unit("500ms"));
+ assert_double(123., ==, util::parse_duration_with_unit("123S"));
+ assert_double(0.500, ==, util::parse_duration_with_unit("500MS"));
+ assert_double(180, ==, util::parse_duration_with_unit("3m"));
+ assert_double(3600 * 5, ==, util::parse_duration_with_unit("5h"));
auto err = std::numeric_limits<double>::infinity();
// check overflow case
- CU_ASSERT(err == util::parse_duration_with_unit("9223372036854775808"));
+ assert_double(err, ==, util::parse_duration_with_unit("9223372036854775808"));
// bad characters
- CU_ASSERT(err == util::parse_duration_with_unit("0u"));
- CU_ASSERT(err == util::parse_duration_with_unit("0xs"));
- CU_ASSERT(err == util::parse_duration_with_unit("0mt"));
- CU_ASSERT(err == util::parse_duration_with_unit("0mss"));
- CU_ASSERT(err == util::parse_duration_with_unit("s"));
- CU_ASSERT(err == util::parse_duration_with_unit("ms"));
+ assert_double(err, ==, util::parse_duration_with_unit("0u"));
+ assert_double(err, ==, util::parse_duration_with_unit("0xs"));
+ assert_double(err, ==, util::parse_duration_with_unit("0mt"));
+ assert_double(err, ==, util::parse_duration_with_unit("0mss"));
+ assert_double(err, ==, util::parse_duration_with_unit("s"));
+ assert_double(err, ==, util::parse_duration_with_unit("ms"));
}
void test_util_duration_str(void) {
- CU_ASSERT("0" == util::duration_str(0.));
- CU_ASSERT("1s" == util::duration_str(1.));
- CU_ASSERT("500ms" == util::duration_str(0.5));
- CU_ASSERT("1500ms" == util::duration_str(1.5));
- CU_ASSERT("2m" == util::duration_str(120.));
- CU_ASSERT("121s" == util::duration_str(121.));
- CU_ASSERT("1h" == util::duration_str(3600.));
+ assert_stdstring_equal("0", util::duration_str(0.));
+ assert_stdstring_equal("1s", util::duration_str(1.));
+ assert_stdstring_equal("500ms", util::duration_str(0.5));
+ assert_stdstring_equal("1500ms", util::duration_str(1.5));
+ assert_stdstring_equal("2m", util::duration_str(120.));
+ assert_stdstring_equal("121s", util::duration_str(121.));
+ assert_stdstring_equal("1h", util::duration_str(3600.));
}
void test_util_format_duration(void) {
- CU_ASSERT("0us" == util::format_duration(std::chrono::microseconds(0)));
- CU_ASSERT("999us" == util::format_duration(std::chrono::microseconds(999)));
- CU_ASSERT("1.00ms" == util::format_duration(std::chrono::microseconds(1000)));
- CU_ASSERT("1.09ms" == util::format_duration(std::chrono::microseconds(1090)));
- CU_ASSERT("1.01ms" == util::format_duration(std::chrono::microseconds(1009)));
- CU_ASSERT("999.99ms" ==
- util::format_duration(std::chrono::microseconds(999990)));
- CU_ASSERT("1.00s" ==
- util::format_duration(std::chrono::microseconds(1000000)));
- CU_ASSERT("1.05s" ==
- util::format_duration(std::chrono::microseconds(1050000)));
-
- CU_ASSERT("0us" == util::format_duration(0.));
- CU_ASSERT("999us" == util::format_duration(0.000999));
- CU_ASSERT("1.00ms" == util::format_duration(0.001));
- CU_ASSERT("1.09ms" == util::format_duration(0.00109));
- CU_ASSERT("1.01ms" == util::format_duration(0.001009));
- CU_ASSERT("999.99ms" == util::format_duration(0.99999));
- CU_ASSERT("1.00s" == util::format_duration(1.));
- CU_ASSERT("1.05s" == util::format_duration(1.05));
+ assert_stdstring_equal("0us",
+ util::format_duration(std::chrono::microseconds(0)));
+ assert_stdstring_equal("999us",
+ util::format_duration(std::chrono::microseconds(999)));
+ assert_stdstring_equal(
+ "1.00ms", util::format_duration(std::chrono::microseconds(1000)));
+ assert_stdstring_equal(
+ "1.09ms", util::format_duration(std::chrono::microseconds(1090)));
+ assert_stdstring_equal(
+ "1.01ms", util::format_duration(std::chrono::microseconds(1009)));
+ assert_stdstring_equal(
+ "999.99ms", util::format_duration(std::chrono::microseconds(999990)));
+ assert_stdstring_equal(
+ "1.00s", util::format_duration(std::chrono::microseconds(1000000)));
+ assert_stdstring_equal(
+ "1.05s", util::format_duration(std::chrono::microseconds(1050000)));
+
+ assert_stdstring_equal("0us", util::format_duration(0.));
+ assert_stdstring_equal("999us", util::format_duration(0.000999));
+ assert_stdstring_equal("1.00ms", util::format_duration(0.001));
+ assert_stdstring_equal("1.09ms", util::format_duration(0.00109));
+ assert_stdstring_equal("1.01ms", util::format_duration(0.001009));
+ assert_stdstring_equal("999.99ms", util::format_duration(0.99999));
+ assert_stdstring_equal("1.00s", util::format_duration(1.));
+ assert_stdstring_equal("1.05s", util::format_duration(1.05));
}
void test_util_starts_with(void) {
- CU_ASSERT(util::starts_with(StringRef::from_lit("foo"),
- StringRef::from_lit("foo")));
- CU_ASSERT(util::starts_with(StringRef::from_lit("fooo"),
- StringRef::from_lit("foo")));
- CU_ASSERT(util::starts_with(StringRef::from_lit("ofoo"), StringRef{}));
- CU_ASSERT(!util::starts_with(StringRef::from_lit("ofoo"),
- StringRef::from_lit("foo")));
-
- CU_ASSERT(util::istarts_with(StringRef::from_lit("FOO"),
- StringRef::from_lit("fOO")));
- CU_ASSERT(util::istarts_with(StringRef::from_lit("ofoo"), StringRef{}));
- CU_ASSERT(util::istarts_with(StringRef::from_lit("fOOo"),
- StringRef::from_lit("Foo")));
- CU_ASSERT(!util::istarts_with(StringRef::from_lit("ofoo"),
+ assert_true(util::starts_with(StringRef::from_lit("foo"),
+ StringRef::from_lit("foo")));
+ assert_true(util::starts_with(StringRef::from_lit("fooo"),
StringRef::from_lit("foo")));
+ assert_true(util::starts_with(StringRef::from_lit("ofoo"), StringRef{}));
+ assert_false(util::starts_with(StringRef::from_lit("ofoo"),
+ StringRef::from_lit("foo")));
- CU_ASSERT(util::istarts_with_l(StringRef::from_lit("fOOo"), "Foo"));
- CU_ASSERT(!util::istarts_with_l(StringRef::from_lit("ofoo"), "foo"));
+ assert_true(util::istarts_with(StringRef::from_lit("FOO"),
+ StringRef::from_lit("fOO")));
+ assert_true(util::istarts_with(StringRef::from_lit("ofoo"), StringRef{}));
+ assert_true(util::istarts_with(StringRef::from_lit("fOOo"),
+ StringRef::from_lit("Foo")));
+ assert_false(util::istarts_with(StringRef::from_lit("ofoo"),
+ StringRef::from_lit("foo")));
+
+ assert_true(util::istarts_with_l(StringRef::from_lit("fOOo"), "Foo"));
+ assert_false(util::istarts_with_l(StringRef::from_lit("ofoo"), "foo"));
}
void test_util_ends_with(void) {
- CU_ASSERT(
+ assert_true(
util::ends_with(StringRef::from_lit("foo"), StringRef::from_lit("foo")));
- CU_ASSERT(util::ends_with(StringRef::from_lit("foo"), StringRef{}));
- CU_ASSERT(
+ assert_true(util::ends_with(StringRef::from_lit("foo"), StringRef{}));
+ assert_true(
util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("foo")));
- CU_ASSERT(
- !util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo")));
+ assert_false(
+ util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo")));
- CU_ASSERT(
+ assert_true(
util::iends_with(StringRef::from_lit("fOo"), StringRef::from_lit("Foo")));
- CU_ASSERT(util::iends_with(StringRef::from_lit("foo"), StringRef{}));
- CU_ASSERT(util::iends_with(StringRef::from_lit("oFoo"),
- StringRef::from_lit("fOO")));
- CU_ASSERT(!util::iends_with(StringRef::from_lit("ofoo"),
- StringRef::from_lit("fo")));
+ assert_true(util::iends_with(StringRef::from_lit("foo"), StringRef{}));
+ assert_true(util::iends_with(StringRef::from_lit("oFoo"),
+ StringRef::from_lit("fOO")));
+ assert_false(
+ util::iends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo")));
- CU_ASSERT(util::iends_with_l(StringRef::from_lit("oFoo"), "fOO"));
- CU_ASSERT(!util::iends_with_l(StringRef::from_lit("ofoo"), "fo"));
+ assert_true(util::iends_with_l(StringRef::from_lit("oFoo"), "fOO"));
+ assert_false(util::iends_with_l(StringRef::from_lit("ofoo"), "fo"));
}
void test_util_parse_http_date(void) {
- CU_ASSERT(1001939696 == util::parse_http_date(StringRef::from_lit(
- "Mon, 1 Oct 2001 12:34:56 GMT")));
+ assert_int64(1001939696, ==,
+ util::parse_http_date(
+ StringRef::from_lit("Mon, 1 Oct 2001 12:34:56 GMT")));
}
void test_util_localtime_date(void) {
@@ -450,25 +528,28 @@ void test_util_localtime_date(void) {
#endif // !__linux__
tzset();
- CU_ASSERT_STRING_EQUAL("02/Oct/2001:00:34:56 +1200",
- util::common_log_date(1001939696).c_str());
- CU_ASSERT_STRING_EQUAL("2001-10-02T00:34:56.123+12:00",
- util::iso8601_date(1001939696000LL + 123).c_str());
+ assert_stdstring_equal("02/Oct/2001:00:34:56 +1200",
+ util::common_log_date(1001939696));
+ assert_stdstring_equal("2001-10-02T00:34:56.123+12:00",
+ util::iso8601_date(1001939696000LL + 123));
std::array<char, 27> common_buf;
- CU_ASSERT("02/Oct/2001:00:34:56 +1200" ==
- util::format_common_log(common_buf.data(),
- std::chrono::system_clock::time_point(
- std::chrono::seconds(1001939696))));
+ assert_stdstring_equal(
+ "02/Oct/2001:00:34:56 +1200",
+ util::format_common_log(common_buf.data(),
+ std::chrono::system_clock::time_point(
+ std::chrono::seconds(1001939696)))
+ .str());
std::array<char, 30> iso8601_buf;
- CU_ASSERT(
- "2001-10-02T00:34:56.123+12:00" ==
+ assert_stdstring_equal(
+ "2001-10-02T00:34:56.123+12:00",
util::format_iso8601(iso8601_buf.data(),
std::chrono::system_clock::time_point(
- std::chrono::milliseconds(1001939696123LL))));
+ std::chrono::milliseconds(1001939696123LL)))
+ .str());
if (tz) {
setenv("TZ", tz, 1);
@@ -486,7 +567,7 @@ void test_util_get_uint64(void) {
auto n = util::get_uint64(v.data());
- CU_ASSERT(0x01123456ff9aabbcULL == n);
+ assert_uint64(0x01123456ff9aabbcULL, ==, n);
}
{
auto v = std::array<unsigned char, 8>{
@@ -494,83 +575,91 @@ void test_util_get_uint64(void) {
auto n = util::get_uint64(v.data());
- CU_ASSERT(0xffffffffffffffffULL == n);
+ assert_uint64(0xffffffffffffffffULL, ==, n);
}
}
void test_util_parse_config_str_list(void) {
auto res = util::parse_config_str_list(StringRef::from_lit("a"));
- CU_ASSERT(1 == res.size());
- CU_ASSERT("a" == res[0]);
+ assert_size(1, ==, res.size());
+ assert_stdstring_equal("a", res[0]);
res = util::parse_config_str_list(StringRef::from_lit("a,"));
- CU_ASSERT(2 == res.size());
- CU_ASSERT("a" == res[0]);
- CU_ASSERT("" == res[1]);
+ assert_size(2, ==, res.size());
+ assert_stdstring_equal("a", res[0]);
+ assert_stdstring_equal("", res[1]);
res = util::parse_config_str_list(StringRef::from_lit(":a::"), ':');
- CU_ASSERT(4 == res.size());
- CU_ASSERT("" == res[0]);
- CU_ASSERT("a" == res[1]);
- CU_ASSERT("" == res[2]);
- CU_ASSERT("" == res[3]);
+ assert_size(4, ==, res.size());
+ assert_stdstring_equal("", res[0]);
+ assert_stdstring_equal("a", res[1]);
+ assert_stdstring_equal("", res[2]);
+ assert_stdstring_equal("", res[3]);
res = util::parse_config_str_list(StringRef{});
- CU_ASSERT(1 == res.size());
- CU_ASSERT("" == res[0]);
+ assert_size(1, ==, res.size());
+ assert_stdstring_equal("", res[0]);
res = util::parse_config_str_list(StringRef::from_lit("alpha,bravo,charlie"));
- CU_ASSERT(3 == res.size());
- CU_ASSERT("alpha" == res[0]);
- CU_ASSERT("bravo" == res[1]);
- CU_ASSERT("charlie" == res[2]);
+ assert_size(3, ==, res.size());
+ assert_stdstring_equal("alpha", res[0]);
+ assert_stdstring_equal("bravo", res[1]);
+ assert_stdstring_equal("charlie", res[2]);
}
void test_util_make_http_hostport(void) {
BlockAllocator balloc(4096, 4096);
- CU_ASSERT("localhost" == util::make_http_hostport(
- balloc, StringRef::from_lit("localhost"), 80));
- CU_ASSERT("[::1]" ==
- util::make_http_hostport(balloc, StringRef::from_lit("::1"), 443));
- CU_ASSERT(
- "localhost:3000" ==
- util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 3000));
+ assert_stdstring_equal(
+ "localhost",
+ util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 80)
+ .str());
+ assert_stdstring_equal(
+ "[::1]",
+ util::make_http_hostport(balloc, StringRef::from_lit("::1"), 443).str());
+ assert_stdstring_equal(
+ "localhost:3000",
+ util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 3000)
+ .str());
}
void test_util_make_hostport(void) {
std::array<char, util::max_hostport> hostport_buf;
- CU_ASSERT("localhost:80" ==
- util::make_hostport(std::begin(hostport_buf),
- StringRef::from_lit("localhost"), 80));
- CU_ASSERT("[::1]:443" == util::make_hostport(std::begin(hostport_buf),
- StringRef::from_lit("::1"),
- 443));
+ assert_stdstring_equal(
+ "localhost:80", util::make_hostport(std::begin(hostport_buf),
+ StringRef::from_lit("localhost"), 80)
+ .str());
+ assert_stdstring_equal("[::1]:443",
+ util::make_hostport(std::begin(hostport_buf),
+ StringRef::from_lit("::1"), 443)
+ .str());
BlockAllocator balloc(4096, 4096);
- CU_ASSERT("localhost:80" ==
- util::make_hostport(balloc, StringRef::from_lit("localhost"), 80));
- CU_ASSERT("[::1]:443" ==
- util::make_hostport(balloc, StringRef::from_lit("::1"), 443));
+ assert_stdstring_equal(
+ "localhost:80",
+ util::make_hostport(balloc, StringRef::from_lit("localhost"), 80).str());
+ assert_stdstring_equal(
+ "[::1]:443",
+ util::make_hostport(balloc, StringRef::from_lit("::1"), 443).str());
}
void test_util_strifind(void) {
- CU_ASSERT(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"),
- StringRef::from_lit("gzip")));
+ assert_true(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"),
+ StringRef::from_lit("gzip")));
- CU_ASSERT(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"),
- StringRef::from_lit("dEflate")));
+ assert_true(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"),
+ StringRef::from_lit("dEflate")));
- CU_ASSERT(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"),
- StringRef::from_lit("BZIP2")));
+ assert_true(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"),
+ StringRef::from_lit("BZIP2")));
- CU_ASSERT(util::strifind(StringRef::from_lit("nghttp2"), StringRef{}));
+ assert_true(util::strifind(StringRef::from_lit("nghttp2"), StringRef{}));
// Be aware this fact
- CU_ASSERT(!util::strifind(StringRef{}, StringRef{}));
+ assert_false(util::strifind(StringRef{}, StringRef{}));
- CU_ASSERT(!util::strifind(StringRef::from_lit("nghttp2"),
- StringRef::from_lit("http1")));
+ assert_false(util::strifind(StringRef::from_lit("nghttp2"),
+ StringRef::from_lit("http1")));
}
void test_util_random_alpha_digit(void) {
@@ -580,116 +669,117 @@ void test_util_random_alpha_digit(void) {
auto p = util::random_alpha_digit(std::begin(data), std::end(data), gen);
- CU_ASSERT(std::end(data) == p);
+ assert_true(std::end(data) == p);
for (auto b : data) {
- CU_ASSERT(('A' <= b && b <= 'Z') || ('a' <= b && b <= 'z') ||
- ('0' <= b && b <= '9'));
+ assert_true(('A' <= b && b <= 'Z') || ('a' <= b && b <= 'z') ||
+ ('0' <= b && b <= '9'));
}
}
void test_util_format_hex(void) {
BlockAllocator balloc(4096, 4096);
- CU_ASSERT("0ff0" ==
- util::format_hex(balloc, StringRef::from_lit("\x0f\xf0")));
- CU_ASSERT("" == util::format_hex(balloc, StringRef::from_lit("")));
+ assert_stdstring_equal(
+ "0ff0", util::format_hex(balloc, StringRef::from_lit("\x0f\xf0")).str());
+ assert_stdstring_equal(
+ "", util::format_hex(balloc, StringRef::from_lit("")).str());
}
void test_util_is_hex_string(void) {
- CU_ASSERT(util::is_hex_string(StringRef{}));
- CU_ASSERT(util::is_hex_string(StringRef::from_lit("0123456789abcdef")));
- CU_ASSERT(util::is_hex_string(StringRef::from_lit("0123456789ABCDEF")));
- CU_ASSERT(!util::is_hex_string(StringRef::from_lit("000")));
- CU_ASSERT(!util::is_hex_string(StringRef::from_lit("XX")));
+ assert_true(util::is_hex_string(StringRef{}));
+ assert_true(util::is_hex_string(StringRef::from_lit("0123456789abcdef")));
+ assert_true(util::is_hex_string(StringRef::from_lit("0123456789ABCDEF")));
+ assert_false(util::is_hex_string(StringRef::from_lit("000")));
+ assert_false(util::is_hex_string(StringRef::from_lit("XX")));
}
void test_util_decode_hex(void) {
BlockAllocator balloc(4096, 4096);
- CU_ASSERT("\x0f\xf0" ==
- util::decode_hex(balloc, StringRef::from_lit("0ff0")));
- CU_ASSERT("" == util::decode_hex(balloc, StringRef{}));
+ assert_stdstring_equal(
+ "\x0f\xf0", util::decode_hex(balloc, StringRef::from_lit("0ff0")).str());
+ assert_stdstring_equal("", util::decode_hex(balloc, StringRef{}).str());
}
void test_util_extract_host(void) {
- CU_ASSERT(StringRef::from_lit("foo") ==
- util::extract_host(StringRef::from_lit("foo")));
- CU_ASSERT(StringRef::from_lit("foo") ==
- util::extract_host(StringRef::from_lit("foo:")));
- CU_ASSERT(StringRef::from_lit("foo") ==
- util::extract_host(StringRef::from_lit("foo:0")));
- CU_ASSERT(StringRef::from_lit("[::1]") ==
- util::extract_host(StringRef::from_lit("[::1]")));
- CU_ASSERT(StringRef::from_lit("[::1]") ==
- util::extract_host(StringRef::from_lit("[::1]:")));
-
- CU_ASSERT(util::extract_host(StringRef::from_lit(":foo")).empty());
- CU_ASSERT(util::extract_host(StringRef::from_lit("[::1")).empty());
- CU_ASSERT(util::extract_host(StringRef::from_lit("[::1]0")).empty());
- CU_ASSERT(util::extract_host(StringRef{}).empty());
+ assert_stdstring_equal("foo",
+ util::extract_host(StringRef::from_lit("foo")).str());
+ assert_stdstring_equal("foo",
+ util::extract_host(StringRef::from_lit("foo:")).str());
+ assert_stdstring_equal(
+ "foo", util::extract_host(StringRef::from_lit("foo:0")).str());
+ assert_stdstring_equal(
+ "[::1]", util::extract_host(StringRef::from_lit("[::1]")).str());
+ assert_stdstring_equal(
+ "[::1]", util::extract_host(StringRef::from_lit("[::1]:")).str());
+
+ assert_true(util::extract_host(StringRef::from_lit(":foo")).empty());
+ assert_true(util::extract_host(StringRef::from_lit("[::1")).empty());
+ assert_true(util::extract_host(StringRef::from_lit("[::1]0")).empty());
+ assert_true(util::extract_host(StringRef{}).empty());
}
void test_util_split_hostport(void) {
- CU_ASSERT(std::make_pair(StringRef::from_lit("foo"), StringRef{}) ==
- util::split_hostport(StringRef::from_lit("foo")));
- CU_ASSERT(
+ assert_true(std::make_pair(StringRef::from_lit("foo"), StringRef{}) ==
+ util::split_hostport(StringRef::from_lit("foo")));
+ assert_true(
std::make_pair(StringRef::from_lit("foo"), StringRef::from_lit("80")) ==
util::split_hostport(StringRef::from_lit("foo:80")));
- CU_ASSERT(
+ assert_true(
std::make_pair(StringRef::from_lit("::1"), StringRef::from_lit("80")) ==
util::split_hostport(StringRef::from_lit("[::1]:80")));
- CU_ASSERT(std::make_pair(StringRef::from_lit("::1"), StringRef{}) ==
- util::split_hostport(StringRef::from_lit("[::1]")));
+ assert_true(std::make_pair(StringRef::from_lit("::1"), StringRef{}) ==
+ util::split_hostport(StringRef::from_lit("[::1]")));
- CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) ==
- util::split_hostport(StringRef{}));
- CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) ==
- util::split_hostport(StringRef::from_lit("[::1]:")));
- CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) ==
- util::split_hostport(StringRef::from_lit("foo:")));
- CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) ==
- util::split_hostport(StringRef::from_lit("[::1:")));
- CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) ==
- util::split_hostport(StringRef::from_lit("[::1]80")));
+ assert_true(std::make_pair(StringRef{}, StringRef{}) ==
+ util::split_hostport(StringRef{}));
+ assert_true(std::make_pair(StringRef{}, StringRef{}) ==
+ util::split_hostport(StringRef::from_lit("[::1]:")));
+ assert_true(std::make_pair(StringRef{}, StringRef{}) ==
+ util::split_hostport(StringRef::from_lit("foo:")));
+ assert_true(std::make_pair(StringRef{}, StringRef{}) ==
+ util::split_hostport(StringRef::from_lit("[::1:")));
+ assert_true(std::make_pair(StringRef{}, StringRef{}) ==
+ util::split_hostport(StringRef::from_lit("[::1]80")));
}
void test_util_split_str(void) {
- CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("")} ==
- util::split_str(StringRef::from_lit(""), ','));
- CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("alpha")} ==
- util::split_str(StringRef::from_lit("alpha"), ','));
- CU_ASSERT((std::vector<StringRef>{StringRef::from_lit("alpha"),
- StringRef::from_lit("")}) ==
- util::split_str(StringRef::from_lit("alpha,"), ','));
- CU_ASSERT((std::vector<StringRef>{StringRef::from_lit("alpha"),
- StringRef::from_lit("bravo")}) ==
- util::split_str(StringRef::from_lit("alpha,bravo"), ','));
- CU_ASSERT((std::vector<StringRef>{StringRef::from_lit("alpha"),
- StringRef::from_lit("bravo"),
- StringRef::from_lit("charlie")}) ==
- util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ','));
- CU_ASSERT(
+ assert_true(std::vector<StringRef>{StringRef::from_lit("")} ==
+ util::split_str(StringRef::from_lit(""), ','));
+ assert_true(std::vector<StringRef>{StringRef::from_lit("alpha")} ==
+ util::split_str(StringRef::from_lit("alpha"), ','));
+ assert_true((std::vector<StringRef>{StringRef::from_lit("alpha"),
+ StringRef::from_lit("")}) ==
+ util::split_str(StringRef::from_lit("alpha,"), ','));
+ assert_true((std::vector<StringRef>{StringRef::from_lit("alpha"),
+ StringRef::from_lit("bravo")}) ==
+ util::split_str(StringRef::from_lit("alpha,bravo"), ','));
+ assert_true((std::vector<StringRef>{StringRef::from_lit("alpha"),
+ StringRef::from_lit("bravo"),
+ StringRef::from_lit("charlie")}) ==
+ util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ','));
+ assert_true(
(std::vector<StringRef>{StringRef::from_lit("alpha"),
StringRef::from_lit("bravo"),
StringRef::from_lit("charlie")}) ==
util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',', 0));
- CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("")} ==
- util::split_str(StringRef::from_lit(""), ',', 1));
- CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("")} ==
- util::split_str(StringRef::from_lit(""), ',', 2));
- CU_ASSERT(
+ assert_true(std::vector<StringRef>{StringRef::from_lit("")} ==
+ util::split_str(StringRef::from_lit(""), ',', 1));
+ assert_true(std::vector<StringRef>{StringRef::from_lit("")} ==
+ util::split_str(StringRef::from_lit(""), ',', 2));
+ assert_true(
(std::vector<StringRef>{StringRef::from_lit("alpha"),
StringRef::from_lit("bravo,charlie")}) ==
util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',', 2));
- CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("alpha")} ==
- util::split_str(StringRef::from_lit("alpha"), ',', 2));
- CU_ASSERT((std::vector<StringRef>{StringRef::from_lit("alpha"),
- StringRef::from_lit("")}) ==
- util::split_str(StringRef::from_lit("alpha,"), ',', 2));
- CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("alpha")} ==
- util::split_str(StringRef::from_lit("alpha"), ',', 0));
- CU_ASSERT(
+ assert_true(std::vector<StringRef>{StringRef::from_lit("alpha")} ==
+ util::split_str(StringRef::from_lit("alpha"), ',', 2));
+ assert_true((std::vector<StringRef>{StringRef::from_lit("alpha"),
+ StringRef::from_lit("")}) ==
+ util::split_str(StringRef::from_lit("alpha,"), ',', 2));
+ assert_true(std::vector<StringRef>{StringRef::from_lit("alpha")} ==
+ util::split_str(StringRef::from_lit("alpha"), ',', 0));
+ assert_true(
std::vector<StringRef>{StringRef::from_lit("alpha,bravo,charlie")} ==
util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',', 1));
}
@@ -697,11 +787,16 @@ void test_util_split_str(void) {
void test_util_rstrip(void) {
BlockAllocator balloc(4096, 4096);
- CU_ASSERT("alpha" == util::rstrip(balloc, StringRef::from_lit("alpha")));
- CU_ASSERT("alpha" == util::rstrip(balloc, StringRef::from_lit("alpha ")));
- CU_ASSERT("alpha" == util::rstrip(balloc, StringRef::from_lit("alpha \t")));
- CU_ASSERT("" == util::rstrip(balloc, StringRef::from_lit("")));
- CU_ASSERT("" == util::rstrip(balloc, StringRef::from_lit("\t\t\t ")));
+ assert_stdstring_equal(
+ "alpha", util::rstrip(balloc, StringRef::from_lit("alpha")).str());
+ assert_stdstring_equal(
+ "alpha", util::rstrip(balloc, StringRef::from_lit("alpha ")).str());
+ assert_stdstring_equal(
+ "alpha", util::rstrip(balloc, StringRef::from_lit("alpha \t")).str());
+ assert_stdstring_equal("",
+ util::rstrip(balloc, StringRef::from_lit("")).str());
+ assert_stdstring_equal(
+ "", util::rstrip(balloc, StringRef::from_lit("\t\t\t ")).str());
}
} // namespace shrpx