Skip to content

Commit fa7e247

Browse files
committed
Added tests for dumping methods
1 parent a36f803 commit fa7e247

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

test/unit/http_utils_test.cpp

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ LT_END_AUTO_TEST(get_port_null)
150150

151151
LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_str)
152152
http::ip_representation test_ip("192.168.5.5");
153-
153+
154154
LT_CHECK_EQ(test_ip.ip_version, http::http_utils::IPV4);
155155

156156
for (int i = 0; i < 12; i++) {
@@ -167,7 +167,7 @@ LT_END_AUTO_TEST(ip_representation4_str)
167167

168168
LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_str_mask)
169169
http::ip_representation test_ip("192.168.*.*");
170-
170+
171171
LT_CHECK_EQ(test_ip.ip_version, http::http_utils::IPV4);
172172

173173
for (int i = 0; i < 12; i++) {
@@ -192,7 +192,7 @@ LT_END_AUTO_TEST(ip_representation4_str_beyond255)
192192

193193
LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str)
194194
http::ip_representation test_ip("2001:db8:8714:3a90::12");
195-
195+
196196
LT_CHECK_EQ(test_ip.ip_version, http::http_utils::IPV6);
197197

198198
LT_CHECK_EQ(test_ip.pieces[0], 32);
@@ -217,7 +217,7 @@ LT_END_AUTO_TEST(ip_representation6_str)
217217

218218
LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str_mask)
219219
http::ip_representation test_ip("2001:db8:8714:3a90:*:*");
220-
220+
221221
LT_CHECK_EQ(test_ip.ip_version, http::http_utils::IPV6);
222222

223223
LT_CHECK_EQ(test_ip.pieces[0], 32);
@@ -422,7 +422,7 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_sockaddr)
422422
ip4addr.sin_addr.s_addr = inet_addr("127.0.0.1");
423423

424424
http::ip_representation test_ip((sockaddr*) &ip4addr);
425-
425+
426426
LT_CHECK_EQ(test_ip.ip_version, http::http_utils::IPV4);
427427

428428
for (int i = 0; i < 12; i++) {
@@ -434,7 +434,7 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_sockaddr)
434434
LT_CHECK_EQ(test_ip.pieces[14], 0);
435435
LT_CHECK_EQ(test_ip.pieces[15], 1);
436436

437-
LT_CHECK_EQ(test_ip.mask, 0xFFFF);
437+
LT_CHECK_EQ(test_ip.mask, 0xFFFF);
438438
LT_END_AUTO_TEST(ip_representation4_sockaddr)
439439

440440
LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_sockaddr)
@@ -445,7 +445,7 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_sockaddr)
445445
inet_pton(AF_INET6, "2001:db8:8714:3a90::12", &(ip6addr.sin6_addr));
446446

447447
http::ip_representation test_ip((sockaddr*) &ip6addr);
448-
448+
449449
LT_CHECK_EQ(test_ip.ip_version, http::http_utils::IPV6);
450450

451451
LT_CHECK_EQ(test_ip.pieces[0], 32);
@@ -516,6 +516,50 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation_less_than_with_masks)
516516
LT_CHECK_EQ(http::ip_representation("2001:db8::ff00:42:8329") < http::ip_representation("2001:db8::ff00:42:*"), false);
517517
LT_END_AUTO_TEST(ip_representation_less_than_with_masks)
518518

519+
LT_BEGIN_AUTO_TEST(http_utils_suite, dump_header_map)
520+
std::map<std::string, std::string, http::header_comparator> header_map;
521+
header_map["HEADER_ONE"] = "VALUE_ONE";
522+
header_map["HEADER_TWO"] = "VALUE_TWO";
523+
header_map["HEADER_THREE"] = "VALUE_THREE";
524+
525+
std::stringstream ss;
526+
http::dump_header_map(ss, "prefix", header_map);
527+
LT_CHECK_EQ(ss.str(), " prefix [HEADER_ONE:\"VALUE_ONE\" HEADER_TWO:\"VALUE_TWO\" HEADER_THREE:\"VALUE_THREE\" ]\n");
528+
LT_END_AUTO_TEST(dump_header_map)
529+
530+
LT_BEGIN_AUTO_TEST(http_utils_suite, dump_header_map_no_prefix)
531+
std::map<std::string, std::string, http::header_comparator> header_map;
532+
header_map["HEADER_ONE"] = "VALUE_ONE";
533+
header_map["HEADER_TWO"] = "VALUE_TWO";
534+
header_map["HEADER_THREE"] = "VALUE_THREE";
535+
536+
std::stringstream ss;
537+
http::dump_header_map(ss, "", header_map);
538+
LT_CHECK_EQ(ss.str(), " [HEADER_ONE:\"VALUE_ONE\" HEADER_TWO:\"VALUE_TWO\" HEADER_THREE:\"VALUE_THREE\" ]\n");
539+
LT_END_AUTO_TEST(dump_header_map_no_prefix)
540+
541+
LT_BEGIN_AUTO_TEST(http_utils_suite, dump_arg_map)
542+
std::map<std::string, std::string, http::arg_comparator> arg_map;
543+
arg_map["ARG_ONE"] = "VALUE_ONE";
544+
arg_map["ARG_TWO"] = "VALUE_TWO";
545+
arg_map["ARG_THREE"] = "VALUE_THREE";
546+
547+
std::stringstream ss;
548+
http::dump_arg_map(ss, "prefix", arg_map);
549+
LT_CHECK_EQ(ss.str(), " prefix [ARG_ONE:\"VALUE_ONE\" ARG_TWO:\"VALUE_TWO\" ARG_THREE:\"VALUE_THREE\" ]\n");
550+
LT_END_AUTO_TEST(dump_arg_map)
551+
552+
LT_BEGIN_AUTO_TEST(http_utils_suite, dump_arg_map_no_prefix)
553+
std::map<std::string, std::string, http::arg_comparator> arg_map;
554+
arg_map["ARG_ONE"] = "VALUE_ONE";
555+
arg_map["ARG_TWO"] = "VALUE_TWO";
556+
arg_map["ARG_THREE"] = "VALUE_THREE";
557+
558+
std::stringstream ss;
559+
http::dump_arg_map(ss, "", arg_map);
560+
LT_CHECK_EQ(ss.str(), " [ARG_ONE:\"VALUE_ONE\" ARG_TWO:\"VALUE_TWO\" ARG_THREE:\"VALUE_THREE\" ]\n");
561+
LT_END_AUTO_TEST(dump_arg_map_no_prefix)
562+
519563
LT_BEGIN_AUTO_TEST_ENV()
520564
AUTORUN_TESTS()
521565
LT_END_AUTO_TEST_ENV()

0 commit comments

Comments
 (0)