void URLTestCase::CopyAndAssignment() { wxURL url1("http://www.example.org/"); wxURL url2; wxURI *puri = &url2; // downcast { // Copy constructor wxURL url3(url1); CPPUNIT_ASSERT(url1 == url3); } { // Constructor for string wxURL url3(url1.GetURL()); CPPUNIT_ASSERT(url1 == url3); } { // 'Copy' constructor for uri wxURL url3(*puri); CPPUNIT_ASSERT(url2 == url3); } // assignment for uri *puri = url1; CPPUNIT_ASSERT(url1 == url2); // assignment to self through base pointer *puri = url2; // Assignment of string url1 = wxS("http://www.example2.org/index.html"); *puri = wxS("http://www.example2.org/index.html"); CPPUNIT_ASSERT(url1 == url2); // Assignment url1 = wxS(""); url2 = url1; CPPUNIT_ASSERT(url1 == url2); // assignment to self wxCLANG_WARNING_SUPPRESS(self-assign-overloaded) url2 = url2; wxCLANG_WARNING_RESTORE(self-assign-overloaded) // check for destructor (with base pointer!) puri = new wxURL(); delete puri; }
bool CVFSEntry::Rename(const CURL& url, const CURL& url2) { if (!Initialized()) return false; CVFSURLWrapper url3(url); CVFSURLWrapper url4(url2); return m_pStruct->Rename(&url3.url, &url4.url); }
bool CVFSEntry::Rename(const CURL& url, const CURL& url2) { if (!m_struct.toAddon.rename) return false; CVFSURLWrapper url3(url); CVFSURLWrapper url4(url2); return m_struct.toAddon.rename(&m_struct, &url3.url, &url4.url); }
TEST(NetworkAccessManager, Get) { CustomNetworkAccessManagerFactory factory; QObjectPtr<QNetworkAccessManager> nam (factory.create(nullptr)); // Non-localhost:8080 Url QObjectPtr<QNetworkReply> reply1 (nam->get(QNetworkRequest(QUrl("http://www.google.com")))); while (!reply1->isFinished()) { QTest::qWait(100); } EXPECT_EQ(reply1->url(), QUrl()); EXPECT_NE(reply1->error(), QNetworkReply::NoError); // localhost:8080 Url QUrl url2 ("http://localhost:8080/ipfs/hash/test.png"); QObjectPtr<QNetworkReply> reply2 (nam->get(QNetworkRequest(url2))); EXPECT_EQ(reply2->url(), url2); QUrl url3 ("http://127.0.0.1:8080/ipfs/hash/test.png"); QObjectPtr<QNetworkReply> reply3 (nam->get(QNetworkRequest(url3))); EXPECT_EQ(reply3->url(), url3); }
// Ensure all functions compile correctly. void url_compile_test() { // Constructors urdl::url url1; urdl::url url2("http://foo/bar"); urdl::url url3(std::string("http://foo/bar")); urdl::url url4(url1); urdl::url url5 = url1; // operator= url5 = url2; // protocol() const urdl::url& const_url1 = url1; want<std::string>(const_url1.protocol()); // user_info() want<std::string>(const_url1.user_info()); // host() want<std::string>(const_url1.host()); // port() want<unsigned short>(const_url1.port()); // path() want<std::string>(const_url1.path()); // query() want<std::string>(const_url1.query()); // fragment() want<std::string>(const_url1.fragment()); // to_string() want<std::string>(const_url1.to_string()); want<std::string>(const_url1.to_string(urdl::url::protocol_component)); want<std::string>(const_url1.to_string(urdl::url::user_info_component)); want<std::string>(const_url1.to_string(urdl::url::host_component)); want<std::string>(const_url1.to_string(urdl::url::port_component)); want<std::string>(const_url1.to_string(urdl::url::path_component)); want<std::string>(const_url1.to_string(urdl::url::query_component)); want<std::string>(const_url1.to_string(urdl::url::fragment_component)); want<std::string>(const_url1.to_string(urdl::url::all_components)); // from_string() asio::error_code ec; want<urdl::url>(urdl::url::from_string("http://foo/bar")); want<urdl::url>(urdl::url::from_string("http://foo/bar", ec)); want<urdl::url>(urdl::url::from_string(std::string("http://foo/bar"))); want<urdl::url>(urdl::url::from_string(std::string("http://foo/bar"), ec)); // operator== const urdl::url& const_url2 = url2; want<bool>(const_url1 == const_url2); // operator!= want<bool>(const_url1 != const_url2); // operator< want<bool>(const_url1 < const_url2); }
QString AFormatter::formatHyperlinks (const QString& text) { QString result = text; QRegExp url1("\\[url\\](.+)\\[/url\\]", Qt::CaseInsensitive, QRegExp::RegExp); QRegExp url2("\\[url=(\\S+)\\](.+)\\[/url\\]", Qt::CaseInsensitive, QRegExp::RegExp); url1.setMinimal(true); url2.setMinimal(true); int index = 0; while ((index = url1.indexIn(result, index)) != -1) { QString html; QString lstr = url1.cap(1); int lval = AParser::isURL(lstr); if (lval == 1) html = QString::fromUtf8("<a href='") + lstr + "'>" + lstr + "</a>"; else if (lval == 2) // опасная ссылка html = "<span class='alert'>" + lstr + "</span>"; else // невалидная ссылка html = lstr; result.replace(url1.cap(0), html); index += std::min(url1.matchedLength(), html.length()); } index = 0; while ((index = url2.indexIn(result, index)) != -1) { QString html; QString lstr = url2.cap(1); QString rstr = url2.cap(2); int lval = AParser::isURL(lstr); int rval = AParser::isURL(rstr); if (lval == 1) html = "<a href='" + lstr + "'>" + rstr + "</a>"; else if (rval == 1) html = "<a href='" + rstr + "'>" + lstr + "</a>"; else if (lval == 2) html = "<span class='alert'>" + rstr + "</span>"; else if (rval == 2) html = "<span class='alert'>" + lstr + "</span>"; else // невалидная ссылка html = rstr + " (" + lstr + ")"; result.replace(url2.cap(0), html); index += std::min(url2.matchedLength(), html.length()); } // ссылки без тэгов QRegExp url3("[^'>]((http://|https://|ftp://|[^/]www\\.)[^<\\s]+)", Qt::CaseInsensitive, QRegExp::RegExp); index = 0; while ((index = url3.indexIn(result, index)) != -1) { QString html; QString lstr = url3.cap(1); int lval = AParser::isURL(lstr); if (lval == 1) { html = QString::fromUtf8("<a href='") + lstr + "'>" + QUrl::fromPercentEncoding(lstr.toUtf8()) + "</a>"; result.replace(lstr, html); index += std::min(url3.matchedLength(), html.length()); } else // невалидная или опасная ссылка index += url3.matchedLength(); } // email url QRegExp email("\\[email\\](\\S+)\\[/email\\]", Qt::CaseInsensitive, QRegExp::RegExp); email.setMinimal(true); index = 0; while ((index = email.indexIn(result, index)) != -1) { QString html; QString lstr = email.cap(1); int lval = AParser::isURL(lstr); if (lval == 1) html = QString::fromUtf8("<a href='mailto:") + lstr + "'>" + lstr + "</a>"; else if (lval == 2) html = lstr; else // невалидная ссылка html = lstr; result.replace(email.cap(0), html); index += std::min(email.matchedLength(), html.length()); } // msdn url QRegExp msdn("\\[msdn\\](\\S+)\\[/msdn\\]", Qt::CaseInsensitive, QRegExp::RegExp); msdn.setMinimal(true); result.replace(msdn, "<a href='http://search.msdn.microsoft.com/Default.aspx?brand=Msdn&query=\\1'>\\1</a>"); return result; }
void Test_NetCore::TestSettingUrl () { string reason; std::cout<<"TestSettingUrl\n"; NetCore _nc (ptr_callback.get(), &journal, ptr_log.get()); //former _nc.Init (ptr_log.get()); string url ("ftp://downloads1.kaspersky-labs.com/index.htm"); string url2 ("ftp://downloads2.kaspersky-labs.com/index.html"); string url3 ("ftp://downloads1.kaspersky-labs.com:23/index.html"); string url4 ("ftp://downloads1.kaspersky-labs.com/"); string url5 ("ftp://downloads1.kaspersky-labs.com:21/rel1/rel2/"); string url6 ("ftp://downloads1.kaspersky-labs.com:22/rel1/rel2/rel3/index.htm"); string url7 ("ftp://downloads1.kaspersky-labs.com"); string url8 ("\\\\avp_server\\common\\file.txt"); string url9 ("http://10.64.0.5/common:8088/file.txt"); //case 1 TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url.c_str(), false) == NET_NO_ERROR, "Setting URL"); TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::ftpPassive, url.c_str(), "downloads1.kaspersky-labs.com", DOWNLOADS1_IP, "/index.htm/", 0 ) == _nc.m_addressInformation, "Checking NetUrlInfo" ); //case 2 TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url2.c_str(), false) == NET_NO_ERROR, "Setting URL"); TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::ftpPassive, url2.c_str(), "downloads2.kaspersky-labs.com", DOWNLOADS2_IP, "/index.html/", 0 ) == _nc.m_addressInformation, "Checking NetUrlInfo" ); //case 2a TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url2.c_str(), true) == NET_NO_ERROR, "Setting URL"); TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::ftpActive, url2.c_str(), "downloads2.kaspersky-labs.com", DOWNLOADS2_IP, "/index.html/", 0 ) == _nc.m_addressInformation, "Checking NetUrlInfo" ); //case 3 TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url3.c_str(), true) == NET_NO_ERROR, "Setting URL"); TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::ftpActive, url3.c_str(), "downloads1.kaspersky-labs.com", DOWNLOADS1_IP, "/index.html/", 23 ) == _nc.m_addressInformation, "Checking NetUrlInfo" ); //case 4 TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url4.c_str(), true) == NET_NO_ERROR, "Setting URL"); TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::ftpActive, url4.c_str(), "downloads1.kaspersky-labs.com", DOWNLOADS1_IP, "/", 0 ) == _nc.m_addressInformation, "Checking NetUrlInfo" ); //case 5 TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url5.c_str(), true) == NET_NO_ERROR, "Setting URL"); TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::ftpActive, url5.c_str(), "downloads1.kaspersky-labs.com", DOWNLOADS1_IP, "/rel1/rel2/", 21 ) == _nc.m_addressInformation, "Checking NetUrlInfo" ); //case 6 TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url6.c_str(), true) == NET_NO_ERROR, "Setting URL"); TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::ftpActive, url6.c_str(), "downloads1.kaspersky-labs.com", DOWNLOADS1_IP, "/rel1/rel2/rel3/index.htm/", 22 ) == _nc.m_addressInformation, "Checking NetUrlInfo" ); //case 7 TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url7.c_str(), true) == NET_NO_ERROR, "Setting URL"); TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::ftpActive, url7.c_str(), "downloads1.kaspersky-labs.com", DOWNLOADS1_IP, "/", 0 ) == _nc.m_addressInformation, "Checking NetUrlInfo" ); //case 8 TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url8.c_str(), true) == NET_NO_ERROR, "Setting URL"); TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::fileProtocol, "", "", "", url8.c_str(), 0 ) == _nc.m_addressInformation, "Checking NetUrlInfo" ); //case 9 TD_BOOST_CHECK_MESSAGE (_nc.SetUrl (url9.c_str(), true) == NET_WRONG_USAGE, "Setting URL"); /*TD_BOOST_CHECK_MESSAGE ( AddressInformation_Unit (AddressInformation::Protocol::notDefined, url9.c_str(), "10.64.0.5", "10.64.0.5", "common", 8088 ) == _nc.m_addressInformation, "Checking NetUrlInfo" );*/ Step ("TestSettingUrl", reason); };