Open alexey-malov opened 6 years ago
BOOST_AUTO_TEST_CASE(create_exception_error_if_url_is_empty)
{
BOOST_CHECK_THROW(CHttpUrl(""), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(create_exception_if_port_is_incorrect)
{
BOOST_CHECK_THROW(CHttpUrl("http://ab.ru:as6"), std::invalid_argument);
BOOST_CHECK_THROW(CHttpUrl("http://ab.ru:0"), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(create_exception_error_if_url_has_wrong_protocol)
{
BOOST_CHECK_THROW(CHttpUrl("httd://last.fm"), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(create_exception_error_if_url_has_wrong_parameters)
{
BOOST_CHECK_THROW(CHttpUrl("httd://last.fm/image.jpeg/image2.jpeg"), std::invalid_argument);
}
https://k:65537
bad lexical cast: source type value could not be interpreted as target
http://google.com:80
Protocol: http
Domain: google.com
Port: 80
Document:
Url: http://google.com:80
if ((port < MIN_PORT_VALUE) || (port > MAX_PORT_VALUE))
{
throw CUrlParsingError("Invalid port value");
}
std::regex urlRegex(R"(^(\w+):\/\/([^\s:\/]+)(?::(\d+))?(?:\/(\S*))?$)");
[ ] Разобраться и уметь объяснить, для чего стоит буква R перед строковым литералом
[ ] Разобраться и уметь объяснить, что означает каждый символ в этом регулярном выражении. Для экспериментов рекомендую сайт https://regexr.com/
CHttpUrl::CHttpUrl(std::string const& domain, std::string const& document, Protocol protocol)
: m_protocol(protocol)
, m_document(document)
{
if (!domain.empty())
{
m_domain = domain;
}
else
{
throw CUrlParsingError("Empty domain");
}
}
CHttpUrl::CHttpUrl(std::string const& domain, std::string const& document, Protocol protocol, unsigned short port)
: m_protocol(protocol)
, m_document(document)
{
if (!domain.empty())
{
m_domain = domain;
}
else
{
throw CUrlParsingError("Empty domain");
}
m_port = ParsePort(std::to_string(port), m_protocol);
}