EvgeniyGlazirin / oop

0 stars 0 forks source link

Замечания по HttpURL #10

Open alexey-malov opened 6 years ago

alexey-malov commented 6 years ago
BOOST_AUTO_TEST_CASE(create_exception_error)
{
    BOOST_CHECK_THROW(throw CUrlParsingError("error text"), std::invalid_argument);
}
alexey-malov commented 6 years ago
BOOST_AUTO_TEST_CASE(create_exception_error_if_url_is_empty)
{
    BOOST_CHECK_THROW(CHttpUrl(""), std::invalid_argument);
}
alexey-malov commented 6 years ago
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);
}
alexey-malov commented 6 years ago
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);
}
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
https://k:65537
bad lexical cast: source type value could not be interpreted as target
alexey-malov commented 6 years ago
http://google.com:80
Protocol: http
Domain: google.com
Port: 80
Document:
Url: http://google.com:80
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
            if ((port < MIN_PORT_VALUE) || (port > MAX_PORT_VALUE))
            {
                throw CUrlParsingError("Invalid port value");
            }
alexey-malov commented 6 years ago
    std::regex urlRegex(R"(^(\w+):\/\/([^\s:\/]+)(?::(\d+))?(?:\/(\S*))?$)");
alexey-malov commented 6 years ago
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");
    }
}
alexey-malov commented 6 years ago
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);
}
alexey-malov commented 6 years ago