Skip to content

Commit 09df543

Browse files
committed
Adding tests
1 parent ce1bb56 commit 09df543

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/http_utils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ std::string get_ip_str(
243243
socklen_t maxlen
244244
)
245245
{
246-
if (!sa) throw new std::invalid_argument("socket pointer is null");
246+
if (!sa) throw std::invalid_argument("socket pointer is null");
247247

248248
char to_ret[NI_MAXHOST];
249249
if (AF_INET6 == sa->sa_family)
@@ -258,13 +258,13 @@ std::string get_ip_str(
258258
}
259259
else
260260
{
261-
throw new std::invalid_argument("IP family must be either AF_INET or AF_INET6");
261+
throw std::invalid_argument("IP family must be either AF_INET or AF_INET6");
262262
}
263263
}
264264

265265
unsigned short get_port(const struct sockaddr* sa)
266266
{
267-
if (!sa) throw new std::invalid_argument("socket pointer is null");
267+
if (!sa) throw std::invalid_argument("socket pointer is null");
268268

269269
if (sa->sa_family == AF_INET)
270270
{
@@ -276,7 +276,7 @@ unsigned short get_port(const struct sockaddr* sa)
276276
}
277277
else
278278
{
279-
throw new std::invalid_argument("IP family must be either AF_INET or AF_INET6");
279+
throw std::invalid_argument("IP family must be either AF_INET or AF_INET6");
280280
}
281281
}
282282

test/unit/http_utils_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, unescape)
5858
LT_CHECK_EQ(expected_size, 3);
5959
LT_END_AUTO_TEST(unescape)
6060

61+
LT_BEGIN_AUTO_TEST(http_utils_suite, unescape_plus)
62+
char* string_with_plus = (char*) malloc(6 * sizeof(char));
63+
sprintf(string_with_plus, "%s", "A+B");
64+
int expected_size = http::http_unescape(string_with_plus);
65+
66+
char* expected = (char*) malloc(4 * sizeof(char));
67+
sprintf(expected, "%s", "A B");
68+
69+
LT_CHECK_EQ(string(string_with_plus), string(expected));
70+
LT_CHECK_EQ(expected_size, 3);
71+
LT_END_AUTO_TEST(unescape_plus)
72+
6173
LT_BEGIN_AUTO_TEST(http_utils_suite, standardize_url)
6274
string url = "/", result;
6375
result = http::http_utils::standardize_url(url);

0 commit comments

Comments
 (0)