1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/test/provider/test_url.cc

93 lines
2.1 KiB
C++
Raw Normal View History

2019-02-23 14:57:57 +00:00
#include <gtest/gtest.h>
2019-03-26 22:04:53 +00:00
#include "webfuse/provider/impl/url.h"
2019-02-23 14:57:57 +00:00
TEST(url, ParseWs)
{
2019-03-26 22:04:53 +00:00
struct wfp_impl_url url;
bool result = wfp_impl_url_init(&url, "ws://localhost/");
2019-02-23 14:57:57 +00:00
ASSERT_TRUE(result);
ASSERT_EQ(80, url.port);
ASSERT_FALSE(url.use_tls);
2019-02-23 14:57:57 +00:00
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
2019-03-26 22:04:53 +00:00
wfp_impl_url_cleanup(&url);
2019-02-23 14:57:57 +00:00
}
TEST(url, ParswWss)
{
2019-03-26 22:04:53 +00:00
struct wfp_impl_url url;
bool result = wfp_impl_url_init(&url, "wss://localhost/");
2019-02-23 14:57:57 +00:00
ASSERT_TRUE(result);
ASSERT_EQ(443, url.port);
ASSERT_TRUE(url.use_tls);
2019-02-23 14:57:57 +00:00
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
2019-03-26 22:04:53 +00:00
wfp_impl_url_cleanup(&url);
2019-02-23 14:57:57 +00:00
}
TEST(url, ParseIPAdress)
{
2019-03-26 22:04:53 +00:00
struct wfp_impl_url url;
bool result = wfp_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);
2019-03-26 22:04:53 +00:00
wfp_impl_url_cleanup(&url);
2019-02-23 14:57:57 +00:00
}
TEST(url, ParsePort)
{
2019-03-26 22:04:53 +00:00
struct wfp_impl_url url;
bool result = wfp_impl_url_init(&url, "ws://localhost:54321/");
2019-02-23 14:57:57 +00:00
ASSERT_TRUE(result);
ASSERT_EQ(54321, url.port);
2019-03-26 22:04:53 +00:00
wfp_impl_url_cleanup(&url);
2019-02-23 14:57:57 +00:00
}
TEST(url, ParseNonEmptyPath)
{
2019-03-26 22:04:53 +00:00
struct wfp_impl_url url;
bool result = wfp_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);
2019-03-26 22:04:53 +00:00
wfp_impl_url_cleanup(&url);
2019-02-23 14:57:57 +00:00
}
TEST(url, FailToParseUnknownProtocol)
{
2019-03-26 22:04:53 +00:00
struct wfp_impl_url url;
bool result = wfp_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)
{
2019-03-26 22:04:53 +00:00
struct wfp_impl_url url;
bool result = wfp_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)
{
2019-03-26 22:04:53 +00:00
struct wfp_impl_url url;
bool result = wfp_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);
}