diff --git a/src/Utilities/QGCCachedFileDownload.cc b/src/Utilities/QGCCachedFileDownload.cc index 381584bf10f..e894a87607a 100644 --- a/src/Utilities/QGCCachedFileDownload.cc +++ b/src/Utilities/QGCCachedFileDownload.cc @@ -7,57 +7,58 @@ * ****************************************************************************/ - #include "QGCCachedFileDownload.h" #include "QGCFileDownload.h" +#include #include -QGCCachedFileDownload::QGCCachedFileDownload(QObject* parent, const QString& cacheDirectory) - : QObject(parent), _fileDownload(new QGCFileDownload(this)), _diskCache(new QNetworkDiskCache(this)) +QGCCachedFileDownload::QGCCachedFileDownload(const QString &cacheDirectory, QObject *parent) + : QObject(parent) + , _fileDownload(new QGCFileDownload(this)) + , _diskCache(new QNetworkDiskCache(this)) { _diskCache->setCacheDirectory(cacheDirectory); _fileDownload->setCache(_diskCache); - connect(_fileDownload, &QGCFileDownload::downloadProgress, this, &QGCCachedFileDownload::downloadProgress); - connect(_fileDownload, &QGCFileDownload::downloadComplete, this, &QGCCachedFileDownload::onDownloadCompleted); + (void) connect(_fileDownload, &QGCFileDownload::downloadProgress, this, &QGCCachedFileDownload::downloadProgress); + (void) connect(_fileDownload, &QGCFileDownload::downloadComplete, this, &QGCCachedFileDownload::_onDownloadCompleted); } -bool QGCCachedFileDownload::download(const QString& url, int maxCacheAgeSec) +bool QGCCachedFileDownload::download(const QString &url, int maxCacheAgeSec) { _downloadFromNetwork = false; - // Check cache - QNetworkCacheMetaData metadata = _diskCache->metaData(url); - if (metadata.isValid() && metadata.attributes().contains(QNetworkRequest::Attribute::User)) { + const QNetworkCacheMetaData metadata = _diskCache->metaData(url); + if (metadata.isValid() && metadata.attributes().contains(QNetworkRequest::Attribute::User)) { // We want the following behavior: // - Use the cached file if not older than maxCacheAgeSec // - Otherwise try to download the file, but still use the cached file if there's no connection - QDateTime creationTime = metadata.attributes().find(QNetworkRequest::Attribute::User)->toDateTime(); - bool expired = creationTime.addSecs(maxCacheAgeSec) < QDateTime::currentDateTime(); + const auto &metaDataAttributes = metadata.attributes(); + const QDateTime creationTime = metaDataAttributes.find(QNetworkRequest::Attribute::User)->toDateTime(); + const bool expired = creationTime.addSecs(maxCacheAgeSec) < QDateTime::currentDateTime(); if (expired) { // Force network download, as Qt would still use the cache otherwise (w/o checking the remote) - auto attributes = QVector>{qMakePair(QNetworkRequest::CacheLoadControlAttribute, QVariant{QNetworkRequest::AlwaysNetwork})}; + const auto attributes = QList>{qMakePair(QNetworkRequest::CacheLoadControlAttribute, QVariant{QNetworkRequest::AlwaysNetwork})}; _downloadFromNetwork = true; return _fileDownload->download(url, attributes); } - auto attributes = QVector>{qMakePair(QNetworkRequest::CacheLoadControlAttribute, QVariant{QNetworkRequest::PreferCache})}; + const auto attributes = QList>{qMakePair(QNetworkRequest::CacheLoadControlAttribute, QVariant{QNetworkRequest::PreferCache})}; return _fileDownload->download(url, attributes); - - } else { - return _fileDownload->download(url); } + + return _fileDownload->download(url); } -void QGCCachedFileDownload::onDownloadCompleted(QString remoteFile, QString localFile, QString errorMsg) +void QGCCachedFileDownload::_onDownloadCompleted(const QString &remoteFile, const QString &localFile, const QString &errorMsg) { // Set cache creation time if not set already (the Qt docs mention there's a creation time, but I could not find any API) QNetworkCacheMetaData metadata = _diskCache->metaData(remoteFile); if (metadata.isValid() && !metadata.attributes().contains(QNetworkRequest::Attribute::User)) { QNetworkCacheMetaData::AttributesMap attributes = metadata.attributes(); - attributes.insert(QNetworkRequest::Attribute::User, QDateTime::currentDateTime()); + (void) attributes.insert(QNetworkRequest::Attribute::User, QDateTime::currentDateTime()); metadata.setAttributes(attributes); _diskCache->updateMetaData(metadata); } diff --git a/src/Utilities/QGCCachedFileDownload.h b/src/Utilities/QGCCachedFileDownload.h index 83b13e01e4b..ca98fc0a0bb 100644 --- a/src/Utilities/QGCCachedFileDownload.h +++ b/src/Utilities/QGCCachedFileDownload.h @@ -9,8 +9,8 @@ #pragma once -#include #include +#include class QGCFileDownload; class QNetworkDiskCache; @@ -18,24 +18,25 @@ class QNetworkDiskCache; class QGCCachedFileDownload : public QObject { Q_OBJECT - + public: - QGCCachedFileDownload(QObject* parent, const QString& cacheDirectory); + QGCCachedFileDownload(const QString &cacheDirectory, QObject *parent = nullptr); /// Download the specified remote file. /// @param url File to download /// @param maxCacheAgeSec Maximum age of cached item in seconds /// @return true: Asynchronous download has started, false: Download initialization failed - bool download(const QString& url, int maxCacheAgeSec); + bool download(const QString &url, int maxCacheAgeSec); signals: void downloadProgress(qint64 curr, qint64 total); - void downloadComplete(QString remoteFile, QString localFile, QString errorMsg); + void downloadComplete(const QString &remoteFile, const QString &localFile, const QString &errorMsg); -private: - void onDownloadCompleted(QString remoteFile, QString localFile, QString errorMsg); +private slots: + void _onDownloadCompleted(const QString &remoteFile, const QString &localFile, const QString &errorMsg); - QGCFileDownload* _fileDownload; - QNetworkDiskCache* _diskCache; - bool _downloadFromNetwork{false}; +private: + QGCFileDownload* _fileDownload = nullptr; + QNetworkDiskCache* _diskCache = nullptr; + bool _downloadFromNetwork = false; }; diff --git a/src/Utilities/QGCFileDownload.cc b/src/Utilities/QGCFileDownload.cc index 10903e232b3..41b0842dfec 100644 --- a/src/Utilities/QGCFileDownload.cc +++ b/src/Utilities/QGCFileDownload.cc @@ -7,20 +7,45 @@ * ****************************************************************************/ - #include "QGCFileDownload.h" +#include "QGCLoggingCategory.h" #include #include #include -QGCFileDownload::QGCFileDownload(QObject* parent) - : QNetworkAccessManager(parent) +QGC_LOGGING_CATEGORY(QGCFileDownloadLog, "qgc.utilities.qgcfiledownload"); + +QGCFileDownload::QGCFileDownload(QObject *parent) + : QObject(parent) + , _networkManager(new QNetworkAccessManager(this)) +{ + // qCDebug(QGCFileDownloadLog) << Q_FUNC_INFO << this; +} + +QGCFileDownload::~QGCFileDownload() { + // qCDebug(QGCFileDownloadLog) << Q_FUNC_INFO << this; +} +void QGCFileDownload::setCache(QAbstractNetworkCache *cache) +{ + _networkManager->setCache(cache); +} + +void QGCFileDownload::setIgnoreSSLErrorsIfNeeded(QNetworkReply &networkReply) +{ + const bool sslLibraryBuildIs1x = ((QSslSocket::sslLibraryBuildVersionNumber() & 0xf0000000) == 0x10000000); + const bool sslLibraryIs3x = ((QSslSocket::sslLibraryVersionNumber() & 0xf0000000) == 0x30000000); + if (sslLibraryBuildIs1x && sslLibraryIs3x) { + qCWarning(QGCFileDownloadLog) << "Ignoring ssl certificates due to OpenSSL version mismatch"; + QList errorsThatCanBeIgnored; + errorsThatCanBeIgnored << QSslError(QSslError::NoPeerCertificate); + networkReply.ignoreSslErrors(errorsThatCanBeIgnored); + } } -bool QGCFileDownload::download(const QString& remoteFile, const QVector>& requestAttributes, bool redirect) +bool QGCFileDownload::download(const QString &remoteFile, const QList> &requestAttributes, bool redirect) { if (!redirect) { _requestAttributes = requestAttributes; @@ -28,10 +53,9 @@ bool QGCFileDownload::download(const QString& remoteFile, const QVector &attribute : requestAttributes) { networkRequest.setAttribute(attribute.first, attribute.second); } - QNetworkProxy tProxy; +#if !defined(Q_OS_IOS) && !defined(Q_OS_ANDROID) + QNetworkProxy tProxy = _networkManager->proxy(); tProxy.setType(QNetworkProxy::DefaultProxy); - setProxy(tProxy); - - QNetworkReply* networkReply = get(networkRequest); + _networkManager->setProxy(tProxy); +#endif + + QNetworkReply *const networkReply = _networkManager->get(networkRequest); if (!networkReply) { - qWarning() << "QNetworkAccessManager::get failed"; + qCWarning(QGCFileDownloadLog) << "QNetworkAccessManager::get failed"; return false; } setIgnoreSSLErrorsIfNeeded(*networkReply); - connect(networkReply, &QNetworkReply::downloadProgress, this, &QGCFileDownload::downloadProgress); - connect(networkReply, &QNetworkReply::finished, this, &QGCFileDownload::_downloadFinished); - connect(networkReply, &QNetworkReply::errorOccurred, this, &QGCFileDownload::_downloadError); + (void) connect(networkReply, &QNetworkReply::downloadProgress, this, &QGCFileDownload::downloadProgress); + (void) connect(networkReply, &QNetworkReply::finished, this, &QGCFileDownload::_downloadFinished); + (void) connect(networkReply, &QNetworkReply::errorOccurred, this, &QGCFileDownload::_downloadError); + return true; } -void QGCFileDownload::_downloadFinished(void) +void QGCFileDownload::_downloadFinished() { - QNetworkReply* reply = qobject_cast(QObject::sender()); + QNetworkReply *const reply = qobject_cast(QObject::sender()); + if (!reply) { + return; + } + reply->deleteLater(); - // When an error occurs or the user cancels the download, we still end up here. So bail out in - // those cases. if (reply->error() != QNetworkReply::NoError) { - reply->deleteLater(); return; } - // Check for redirection + if (!reply->isOpen()) { + return; + } + + const int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + if ((statusCode < HTTP_Response::SUCCESS_OK) || (statusCode >= HTTP_Response::REDIRECTION_MULTIPLE_CHOICES)) { + return; + } + QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (!redirectionTarget.isNull()) { - QUrl redirectUrl = reply->url().resolved(redirectionTarget.toUrl()); - download(redirectUrl.toString(), _requestAttributes, true /* redirect */); - reply->deleteLater(); + const QUrl redirectUrl = reply->url().resolved(redirectionTarget.toUrl()); + (void) download(redirectUrl.toString(), _requestAttributes, true); return; } // Split out filename from path QString remoteFileName = QFileInfo(reply->url().toString()).fileName(); if (remoteFileName.isEmpty()) { - qWarning() << "Unabled to parse filename from remote url" << reply->url().toString(); + qCWarning(QGCFileDownloadLog) << "Unabled to parse filename from remote url" << reply->url().toString(); remoteFileName = "DownloadedFile"; } // Strip out http parameters from remote filename - int parameterIndex = remoteFileName.indexOf("?"); + const int parameterIndex = remoteFileName.indexOf("?"); if (parameterIndex != -1) { - remoteFileName = remoteFileName.left(parameterIndex); + remoteFileName = remoteFileName.left(parameterIndex); } - // Determine location to download file to QString downloadFilename = QStandardPaths::writableLocation(QStandardPaths::TempLocation); if (downloadFilename.isEmpty()) { downloadFilename = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); @@ -110,13 +144,13 @@ void QGCFileDownload::_downloadFinished(void) return; } } - downloadFilename += "/" + remoteFileName; + downloadFilename += "/" + remoteFileName; if (!downloadFilename.isEmpty()) { // Store downloaded file in download location QFile file(downloadFilename); if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - emit downloadComplete(_originalRemoteFile, downloadFilename, tr("Could not save downloaded file to %1. Error: %2").arg(downloadFilename).arg(file.errorString())); + emit downloadComplete(_originalRemoteFile, downloadFilename, tr("Could not save downloaded file to %1. Error: %2").arg(downloadFilename, file.errorString())); return; } @@ -125,44 +159,27 @@ void QGCFileDownload::_downloadFinished(void) emit downloadComplete(_originalRemoteFile, downloadFilename, QString()); } else { - QString errorMsg = "Internal error"; - qWarning() << errorMsg; + const QString errorMsg = "Internal error"; + qCWarning(QGCFileDownloadLog) << errorMsg; emit downloadComplete(_originalRemoteFile, downloadFilename, errorMsg); } - - reply->deleteLater(); } -/// @brief Called when an error occurs during download void QGCFileDownload::_downloadError(QNetworkReply::NetworkError code) { QString errorMsg; - - if (code == QNetworkReply::OperationCanceledError) { - errorMsg = tr("Download cancelled"); - } else if (code == QNetworkReply::ContentNotFoundError) { + switch (code) { + case QNetworkReply::OperationCanceledError: + errorMsg = tr("Download cancelled"); + break; + case QNetworkReply::ContentNotFoundError: errorMsg = tr("Error: File Not Found"); - - } else { + break; + default: errorMsg = tr("Error during download. Error: %1").arg(code); + break; } emit downloadComplete(_originalRemoteFile, QString(), errorMsg); } - -void QGCFileDownload::setIgnoreSSLErrorsIfNeeded(QNetworkReply& networkReply) -{ - // Some systems (like Ubuntu 22.04) only ship with OpenSSL 3.x, however Qt 5.15.2 links against OpenSSL 1.x. - // This results in unresolved symbols for EVP_PKEY_base_id and SSL_get_peer_certificate. - // To still get a connection we have to ignore certificate verification (connection is still encrypted but open to MITM attacks) - // See https://bugreports.qt.io/browse/QTBUG-115146 - const bool sslLibraryBuildIs1x = (QSslSocket::sslLibraryBuildVersionNumber() & 0xf0000000) == 0x10000000; - const bool sslLibraryIs3x = (QSslSocket::sslLibraryVersionNumber() & 0xf0000000) == 0x30000000; - if (sslLibraryBuildIs1x && sslLibraryIs3x) { - qWarning() << "Ignoring ssl certificates due to OpenSSL version mismatch"; - QList errorsThatCanBeIgnored; - errorsThatCanBeIgnored << QSslError(QSslError::NoPeerCertificate); - networkReply.ignoreSslErrors(errorsThatCanBeIgnored); - } -} diff --git a/src/Utilities/QGCFileDownload.h b/src/Utilities/QGCFileDownload.h index 984a36117c0..0013cce250f 100644 --- a/src/Utilities/QGCFileDownload.h +++ b/src/Utilities/QGCFileDownload.h @@ -9,33 +9,52 @@ #pragma once +#include +#include #include #include -class QGCFileDownload : public QNetworkAccessManager +class QNetworkAccessManager; +class QAbstractNetworkCache; + +Q_DECLARE_LOGGING_CATEGORY(QGCFileDownloadLog) + +class QGCFileDownload : public QObject { Q_OBJECT - + + enum HTTP_Response { + SUCCESS_OK = 200, + REDIRECTION_MULTIPLE_CHOICES = 300 + }; + public: - QGCFileDownload(QObject* parent = nullptr); - + QGCFileDownload(QObject *parent = nullptr); + ~QGCFileDownload(); + /// Download the specified remote file. - /// @param remoteFile File to download. Can be http address or file system path. - /// @param requestAttributes Optional request attributes to set - /// @param redirect true: call is internal due to redirect - /// @return true: Asynchronous download has started, false: Download initialization failed - bool download(const QString& remoteFile, const QVector>& requestAttributes={}, bool redirect = false); + /// @param remoteFile File to download. Can be http address or file system path. + /// @param requestAttributes Optional request attributes to set + /// @param redirect true: call is internal due to redirect + /// @return true: Asynchronous download has started, false: Download initialization failed + bool download(const QString& remoteFile, const QList> &requestAttributes = {}, bool redirect = false); - static void setIgnoreSSLErrorsIfNeeded(QNetworkReply& networkReply); + void setCache(QAbstractNetworkCache *cache); + + static void setIgnoreSSLErrorsIfNeeded(QNetworkReply &networkReply); signals: void downloadProgress(qint64 curr, qint64 total); - void downloadComplete(QString remoteFile, QString localFile, QString errorMsg); + void downloadComplete(const QString &remoteFile, const QString &localFile, const QString &errorMsg); -private: - void _downloadFinished(void); +private slots: + void _downloadFinished(); + + /// Called when an error occurs during download void _downloadError(QNetworkReply::NetworkError code); +private: + QNetworkAccessManager *_networkManager = nullptr; QString _originalRemoteFile; - QVector> _requestAttributes; + QList> _requestAttributes; }; diff --git a/src/Vehicle/Components/ComponentInformationManager.cc b/src/Vehicle/Components/ComponentInformationManager.cc index 40999d782c9..86a416c2ab6 100644 --- a/src/Vehicle/Components/ComponentInformationManager.cc +++ b/src/Vehicle/Components/ComponentInformationManager.cc @@ -28,7 +28,7 @@ QGC_LOGGING_CATEGORY(ComponentInformationManagerLog, "ComponentInformationManage ComponentInformationManager::ComponentInformationManager(Vehicle* vehicle) : _vehicle (vehicle) , _requestTypeStateMachine (this) - , _cachedFileDownload(new QGCCachedFileDownload(this, QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/QGCCompInfoFileDownloadCache"))) + , _cachedFileDownload(new QGCCachedFileDownload(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/QGCCompInfoFileDownloadCache"), this)) , _fileCache(ComponentInformationCache::defaultInstance()) , _translation(new ComponentInformationTranslation(this, _cachedFileDownload)) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ef75ce1f526..b363c2f0a23 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -98,6 +98,7 @@ add_subdirectory(UI) add_subdirectory(Utilities) # Compression add_qgc_test(DecompressionTest) +add_qgc_test(UtilitiesTest) add_subdirectory(Vehicle) # Components diff --git a/test/UnitTestList.cc b/test/UnitTestList.cc index 7a408f67211..7b487a7adca 100644 --- a/test/UnitTestList.cc +++ b/test/UnitTestList.cc @@ -9,7 +9,6 @@ #include "UnitTestList.h" #include "UnitTest.h" -#include "QGCApplication.h" #include "QGCLoggingCategory.h" // ADSB @@ -88,6 +87,7 @@ // Utilities // Compression #include "DecompressionTest.h" +#include "QGCFileDownloadTest.h" // Vehicle // Components @@ -109,98 +109,99 @@ QGC_LOGGING_CATEGORY(UnitTestsLog, "qgc.test.unittestlist") int runTests(bool stress, QStringView unitTestOptions) { - // ADSB - UT_REGISTER_TEST(ADSBTest) + // ADSB + UT_REGISTER_TEST(ADSBTest) - // AnalyzeView - UT_REGISTER_TEST(ExifParserTest) - UT_REGISTER_TEST(GeoTagControllerTest) - // UT_REGISTER_TEST(MavlinkLogTest) - // UT_REGISTER_TEST(LogDownloadTest) - UT_REGISTER_TEST(PX4LogParserTest) - UT_REGISTER_TEST(ULogParserTest) + // AnalyzeView + UT_REGISTER_TEST(ExifParserTest) + UT_REGISTER_TEST(GeoTagControllerTest) + // UT_REGISTER_TEST(MavlinkLogTest) + // UT_REGISTER_TEST(LogDownloadTest) + UT_REGISTER_TEST(PX4LogParserTest) + UT_REGISTER_TEST(ULogParserTest) - // Audio - UT_REGISTER_TEST(AudioOutputTest) + // Audio + UT_REGISTER_TEST(AudioOutputTest) - // AutoPilotPlugins - // UT_REGISTER_TEST(RadioConfigTest) + // AutoPilotPlugins + // UT_REGISTER_TEST(RadioConfigTest) - // Comms - UT_REGISTER_TEST(QGCSerialPortInfoTest) + // Comms + UT_REGISTER_TEST(QGCSerialPortInfoTest) - // FactSystem - UT_REGISTER_TEST(FactSystemTestGeneric) - UT_REGISTER_TEST(FactSystemTestPX4) - UT_REGISTER_TEST(ParameterManagerTest) + // FactSystem + UT_REGISTER_TEST(FactSystemTestGeneric) + UT_REGISTER_TEST(FactSystemTestPX4) + UT_REGISTER_TEST(ParameterManagerTest) - // FollowMe - UT_REGISTER_TEST(FollowMeTest) + // FollowMe + UT_REGISTER_TEST(FollowMeTest) - // Geo + // Geo UT_REGISTER_TEST(GeoTest) // MAVLink UT_REGISTER_TEST(StatusTextHandlerTest) UT_REGISTER_TEST(SigningTest) - // MissionManager - UT_REGISTER_TEST(CameraCalcTest) - UT_REGISTER_TEST(CameraSectionTest) - UT_REGISTER_TEST(CorridorScanComplexItemTest) - // UT_REGISTER_TEST(FWLandingPatternTest) - // UT_REGISTER_TEST(LandingComplexItemTest) - // UT_REGISTER_TEST_STANDALONE(MissionCommandTreeEditorTest) - UT_REGISTER_TEST(MissionCommandTreeTest) - UT_REGISTER_TEST(MissionControllerManagerTest) - UT_REGISTER_TEST(MissionControllerTest) - UT_REGISTER_TEST(MissionItemTest) - UT_REGISTER_TEST(MissionManagerTest) - UT_REGISTER_TEST(MissionSettingsTest) - UT_REGISTER_TEST(PlanMasterControllerTest) - UT_REGISTER_TEST(QGCMapPolygonTest) - UT_REGISTER_TEST(QGCMapPolylineTest) - // UT_REGISTER_TEST(SectionTest) - UT_REGISTER_TEST(SimpleMissionItemTest) - UT_REGISTER_TEST(SpeedSectionTest) - UT_REGISTER_TEST(StructureScanComplexItemTest) - UT_REGISTER_TEST(SurveyComplexItemTest) - UT_REGISTER_TEST(TransectStyleComplexItemTest) - // UT_REGISTER_TEST(VisualMissionItemTest) - - // qgcunittest - // UT_REGISTER_TEST(FileDialogTest) - // UT_REGISTER_TEST(MainWindowTest) - // UT_REGISTER_TEST(MessageBoxTest) - - // QmlControls - - // Terrain - UT_REGISTER_TEST(TerrainQueryTest) - - // UI - - // Utilities - // Compression - UT_REGISTER_TEST(DecompressionTest) - - // Vehicle - // Components - UT_REGISTER_TEST(ComponentInformationCacheTest) - UT_REGISTER_TEST(ComponentInformationTranslationTest) - UT_REGISTER_TEST(FTPManagerTest) - // UT_REGISTER_TEST(InitialConnectTest) - // UT_REGISTER_TEST(RequestMessageTest) - // UT_REGISTER_TEST(SendMavCommandWithHandlerTest) - // UT_REGISTER_TEST(SendMavCommandWithSignalingTest) - - // Missing - // UT_REGISTER_TEST(FlightGearUnitTest) - // UT_REGISTER_TEST(LinkManagerTest) - // UT_REGISTER_TEST(SendMavCommandTest) - // UT_REGISTER_TEST(TCPLinkTest) - - int result = 0; + // MissionManager + UT_REGISTER_TEST(CameraCalcTest) + UT_REGISTER_TEST(CameraSectionTest) + UT_REGISTER_TEST(CorridorScanComplexItemTest) + // UT_REGISTER_TEST(FWLandingPatternTest) + // UT_REGISTER_TEST(LandingComplexItemTest) + // UT_REGISTER_TEST_STANDALONE(MissionCommandTreeEditorTest) + UT_REGISTER_TEST(MissionCommandTreeTest) + UT_REGISTER_TEST(MissionControllerManagerTest) + UT_REGISTER_TEST(MissionControllerTest) + UT_REGISTER_TEST(MissionItemTest) + UT_REGISTER_TEST(MissionManagerTest) + UT_REGISTER_TEST(MissionSettingsTest) + UT_REGISTER_TEST(PlanMasterControllerTest) + UT_REGISTER_TEST(QGCMapPolygonTest) + UT_REGISTER_TEST(QGCMapPolylineTest) + // UT_REGISTER_TEST(SectionTest) + UT_REGISTER_TEST(SimpleMissionItemTest) + UT_REGISTER_TEST(SpeedSectionTest) + UT_REGISTER_TEST(StructureScanComplexItemTest) + UT_REGISTER_TEST(SurveyComplexItemTest) + UT_REGISTER_TEST(TransectStyleComplexItemTest) + // UT_REGISTER_TEST(VisualMissionItemTest) + + // qgcunittest + // UT_REGISTER_TEST(FileDialogTest) + // UT_REGISTER_TEST(MainWindowTest) + // UT_REGISTER_TEST(MessageBoxTest) + + // QmlControls + + // Terrain + UT_REGISTER_TEST(TerrainQueryTest) + + // UI + + // Utilities + // Compression + UT_REGISTER_TEST(DecompressionTest) + // UT_REGISTER_TEST(QGCFileDownloadTest) + + // Vehicle + // Components + UT_REGISTER_TEST(ComponentInformationCacheTest) + UT_REGISTER_TEST(ComponentInformationTranslationTest) + UT_REGISTER_TEST(FTPManagerTest) + // UT_REGISTER_TEST(InitialConnectTest) + // UT_REGISTER_TEST(RequestMessageTest) + // UT_REGISTER_TEST(SendMavCommandWithHandlerTest) + // UT_REGISTER_TEST(SendMavCommandWithSignalingTest) + + // Missing + // UT_REGISTER_TEST(FlightGearUnitTest) + // UT_REGISTER_TEST(LinkManagerTest) + // UT_REGISTER_TEST(SendMavCommandTest) + // UT_REGISTER_TEST(TCPLinkTest) + + int result = 0; for (int i=0; i < (stress ? 20 : 1); i++) { // Run the test diff --git a/test/Utilities/CMakeLists.txt b/test/Utilities/CMakeLists.txt index ff0354538b4..22b813e255b 100644 --- a/test/Utilities/CMakeLists.txt +++ b/test/Utilities/CMakeLists.txt @@ -3,6 +3,8 @@ add_subdirectory(Compression) find_package(Qt6 REQUIRED COMPONENTS Core) qt_add_library(UtilitiesTest STATIC + QGCFileDownloadTest.cc + QGCFileDownloadTest.h ) target_link_libraries(UtilitiesTest diff --git a/test/Utilities/QGCFileDownloadTest.cc b/test/Utilities/QGCFileDownloadTest.cc new file mode 100644 index 00000000000..5a10ab2c2e8 --- /dev/null +++ b/test/Utilities/QGCFileDownloadTest.cc @@ -0,0 +1,15 @@ +#include "QGCFileDownloadTest.h" +#include "QGCCachedFileDownload.h" +#include "QGCFileDownload.h" + +#include + +void QGCFileDownloadTest::_testFileDownload() +{ + QGCFileDownload file; +} + +void QGCFileDownloadTest::_testCachedFileDownload() +{ + QGCCachedFileDownload file(""); +} diff --git a/test/Utilities/QGCFileDownloadTest.h b/test/Utilities/QGCFileDownloadTest.h new file mode 100644 index 00000000000..d294e6bcf67 --- /dev/null +++ b/test/Utilities/QGCFileDownloadTest.h @@ -0,0 +1,12 @@ +#pragma once + +#include "UnitTest.h" + +class QGCFileDownloadTest : public UnitTest +{ + Q_OBJECT + +private slots: + void _testFileDownload(); + void _testCachedFileDownload(); +}; diff --git a/test/Vehicle/Components/ComponentInformationTranslationTest.cc b/test/Vehicle/Components/ComponentInformationTranslationTest.cc index a462718044e..b5e78a23788 100644 --- a/test/Vehicle/Components/ComponentInformationTranslationTest.cc +++ b/test/Vehicle/Components/ComponentInformationTranslationTest.cc @@ -18,7 +18,7 @@ void ComponentInformationTranslationTest::_basic_test() { QString translationJson = ":/unittest/TranslationTest.json"; QString translationTs = ":/unittest/TranslationTest_de_DE.ts"; - ComponentInformationTranslation* translation = new ComponentInformationTranslation(this, new QGCCachedFileDownload(this, "")); + ComponentInformationTranslation* translation = new ComponentInformationTranslation(this, new QGCCachedFileDownload("", this)); QString tempFilename = translation->translateJsonUsingTS(translationJson, translationTs); QVERIFY(!tempFilename.isEmpty());