[libcalamares] Add urls only if valid, add tests to check that
This commit is contained in:
parent
1452b74740
commit
c79fc2e6d9
@ -20,6 +20,8 @@
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
namespace Network
|
||||
@ -205,21 +207,29 @@ Manager::setCheckHasInternetUrl( const QUrl& url )
|
||||
{
|
||||
d->m_lastCheckedUrlIndex = -1;
|
||||
d->m_hasInternetUrls.clear();
|
||||
if ( url.isValid() )
|
||||
{
|
||||
d->m_hasInternetUrls.append( url );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Manager::setCheckHasInternetUrl( const QVector< QUrl >& urls )
|
||||
{
|
||||
d->m_lastCheckedUrlIndex = -1;
|
||||
d->m_hasInternetUrls = urls;
|
||||
std::remove_if(
|
||||
d->m_hasInternetUrls.begin(), d->m_hasInternetUrls.end(), []( const QUrl& u ) { return u.isValid(); } );
|
||||
}
|
||||
|
||||
void
|
||||
Manager::addCheckHasInternetUrl( const QUrl& url )
|
||||
{
|
||||
if ( url.isValid() )
|
||||
{
|
||||
d->m_hasInternetUrls.append( url );
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Does a request asynchronously, returns the (pending) reply
|
||||
*
|
||||
|
@ -60,3 +60,58 @@ NetworkTests::testPing()
|
||||
QVERIFY( canPing_www_kde_org );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NetworkTests::testCheckUrl()
|
||||
{
|
||||
using namespace CalamaresUtils::Network;
|
||||
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
||||
auto& nam = Manager::instance();
|
||||
|
||||
{
|
||||
QUrl u( "http://example.com" );
|
||||
QVERIFY( u.isValid() );
|
||||
nam.setCheckHasInternetUrl( u );
|
||||
QVERIFY( nam.checkHasInternet() );
|
||||
}
|
||||
{
|
||||
QUrl u( "http://nonexistent.example.com" );
|
||||
QVERIFY( u.isValid() );
|
||||
nam.setCheckHasInternetUrl( u );
|
||||
QVERIFY( !nam.checkHasInternet() );
|
||||
}
|
||||
{
|
||||
QUrl u;
|
||||
QVERIFY( !u.isValid() );
|
||||
nam.setCheckHasInternetUrl( u );
|
||||
QVERIFY( !nam.checkHasInternet() );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NetworkTests::testCheckMultiUrl()
|
||||
{
|
||||
using namespace CalamaresUtils::Network;
|
||||
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
||||
auto& nam = Manager::instance();
|
||||
|
||||
{
|
||||
QUrl u0( "http://example.com" );
|
||||
QUrl u1( "https://kde.org" );
|
||||
QVERIFY( u0.isValid() );
|
||||
QVERIFY( u1.isValid() );
|
||||
nam.setCheckHasInternetUrl( { u0, u1 } );
|
||||
QVERIFY( nam.checkHasInternet() );
|
||||
}
|
||||
{
|
||||
QUrl u0( "http://nonexistent.example.com" );
|
||||
QUrl u1( "http://bogus.example.com" );
|
||||
QVERIFY( u0.isValid() );
|
||||
QVERIFY( u1.isValid() );
|
||||
nam.setCheckHasInternetUrl( { u0, u1 } );
|
||||
QVERIFY( !nam.checkHasInternet() );
|
||||
QVERIFY( !nam.checkHasInternet() );
|
||||
nam.addCheckHasInternetUrl( QUrl( "http://example.com" ) );
|
||||
QVERIFY( nam.checkHasInternet() );
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ private Q_SLOTS:
|
||||
|
||||
void testInstance();
|
||||
void testPing();
|
||||
|
||||
void testCheckUrl();
|
||||
void testCheckMultiUrl();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user