protasov-ilja / OOP

labs on C++
0 stars 0 forks source link

Замечания по ParseUrl #9

Open AniSkyWorker opened 6 years ago

AniSkyWorker commented 6 years ago

k = 0.8

alexey-malov commented 6 years ago
alexey-malov commented 6 years ago
    catch (const std::invalid_argument& isError)
    {
        std::cout << isError.what() << "\n";
        return false;
    }
    catch (const std::out_of_range& isError)
    {
        std::cout << isError.what() << "\n";
        return false;
    }
alexey-malov commented 6 years ago

image

alexey-malov commented 6 years ago
Protocol CheckProtocol(const std::string& protocolString)
{
    auto ConvertCharTolower = [](char ch) {
        return static_cast<char>(tolower(ch));
    };

    std::string protocolStringInLowerCase;
    std::transform(protocolString.begin(), protocolString.end(), std::back_inserter(protocolStringInLowerCase), ConvertCharTolower);
    if (protocolStringInLowerCase == "http")
    {
        return Protocol::HTTP;
    }
    else if (protocolStringInLowerCase == "https")
    {
        return Protocol::HTTPS;
    }
    else if (protocolStringInLowerCase == "ftp")
    {
        return Protocol::FTP;
    }

    return Protocol::NotValid;
}
alexey-malov commented 6 years ago
bool CheckPortNumber(const std::string& portString, int& portNumber)
{
    try
    {
        portNumber = std::stoi(portString);
        if ((portNumber < 1) || (portNumber > 65535))
        {
            return false;
        }
    }
    catch (const std::exception&)
    {
        return false;
    }

    return true;
}
alexey-malov commented 6 years ago
    // берет неверный url и возвращает false
    BOOST_AUTO_TEST_CASE(takes_invalid_url_and_returns_false)
    {
        CheckUrlParsing("http:/www.mysite.com/docs", 0, "", "", false);
        CheckUrlParsing("https//www.mysite.com/docs", 0, "", "", false);
        CheckUrlParsing("ftpwww.mysite.com/docs", 0, "", "", false);
    }
ExpectUrlParsingFailure("InvalidProtocol://google.com");