2019-02-23 14:57:57 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
#include "webfuse/impl/util/url.h"
|
2019-02-23 14:57:57 +00:00
|
|
|
|
|
|
|
TEST(url, ParseWs)
|
|
|
|
{
|
2020-06-11 17:12:07 +00:00
|
|
|
struct wf_url url;
|
2020-06-28 17:43:08 +00:00
|
|
|
bool result = wf_impl_url_init(&url, "ws://localhost/");
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_TRUE(result);
|
|
|
|
ASSERT_EQ(80, url.port);
|
2019-02-23 15:19:00 +00:00
|
|
|
ASSERT_FALSE(url.use_tls);
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_STREQ("localhost", url.host);
|
|
|
|
ASSERT_STREQ("/", url.path);
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_url_cleanup(&url);
|
2019-02-23 14:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(url, ParswWss)
|
|
|
|
{
|
2020-06-11 17:12:07 +00:00
|
|
|
struct wf_url url;
|
2020-06-28 17:43:08 +00:00
|
|
|
bool result = wf_impl_url_init(&url, "wss://localhost/");
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_TRUE(result);
|
|
|
|
ASSERT_EQ(443, url.port);
|
2019-02-23 15:19:00 +00:00
|
|
|
ASSERT_TRUE(url.use_tls);
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_STREQ("localhost", url.host);
|
|
|
|
ASSERT_STREQ("/", url.path);
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_url_cleanup(&url);
|
2019-02-23 14:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(url, ParseIPAdress)
|
|
|
|
{
|
2020-06-11 17:12:07 +00:00
|
|
|
struct wf_url url;
|
2020-06-28 17:43:08 +00:00
|
|
|
bool result = wf_impl_url_init(&url, "ws://127.0.0.1/");
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_TRUE(result);
|
|
|
|
ASSERT_EQ(80, url.port);
|
|
|
|
ASSERT_STREQ("127.0.0.1", url.host);
|
|
|
|
ASSERT_STREQ("/", url.path);
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_url_cleanup(&url);
|
2019-02-23 14:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(url, ParsePort)
|
|
|
|
{
|
2020-06-11 17:12:07 +00:00
|
|
|
struct wf_url url;
|
2020-06-28 17:43:08 +00:00
|
|
|
bool result = wf_impl_url_init(&url, "ws://localhost:54321/");
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_TRUE(result);
|
|
|
|
ASSERT_EQ(54321, url.port);
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_url_cleanup(&url);
|
2019-02-23 14:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(url, ParseNonEmptyPath)
|
|
|
|
{
|
2020-06-11 17:12:07 +00:00
|
|
|
struct wf_url url;
|
2020-06-28 17:43:08 +00:00
|
|
|
bool result = wf_impl_url_init(&url, "ws://localhost/some_path?query");
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_TRUE(result);
|
|
|
|
ASSERT_STREQ("/some_path?query", url.path);
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_url_cleanup(&url);
|
2019-02-23 14:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(url, FailToParseUnknownProtocol)
|
|
|
|
{
|
2020-06-11 17:12:07 +00:00
|
|
|
struct wf_url url;
|
2020-06-28 17:43:08 +00:00
|
|
|
bool result = wf_impl_url_init(&url, "unknown://localhost/");
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_FALSE(result);
|
|
|
|
ASSERT_EQ(0, url.port);
|
|
|
|
ASSERT_EQ(nullptr, url.path);
|
|
|
|
ASSERT_EQ(nullptr, url.host);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(url, FailToParseMissingProtocol)
|
|
|
|
{
|
2020-06-11 17:12:07 +00:00
|
|
|
struct wf_url url;
|
2020-06-28 17:43:08 +00:00
|
|
|
bool result = wf_impl_url_init(&url, "unknown");
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_FALSE(result);
|
|
|
|
ASSERT_EQ(0, url.port);
|
|
|
|
ASSERT_EQ(nullptr, url.path);
|
|
|
|
ASSERT_EQ(nullptr, url.host);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(url, FailToParseMissingPath)
|
|
|
|
{
|
2020-06-11 17:12:07 +00:00
|
|
|
struct wf_url url;
|
2020-06-28 17:43:08 +00:00
|
|
|
bool result = wf_impl_url_init(&url, "ws://localhost");
|
2019-02-23 14:57:57 +00:00
|
|
|
ASSERT_FALSE(result);
|
|
|
|
ASSERT_EQ(0, url.port);
|
|
|
|
ASSERT_EQ(nullptr, url.path);
|
|
|
|
ASSERT_EQ(nullptr, url.host);
|
|
|
|
}
|
|
|
|
|