@@ -402,14 +402,16 @@ TEST_IMPL(sendReaction)
402402 return false ;
403403}
404404
405+ static constexpr auto fileContent = " Test" ;
406+
405407TEST_IMPL (sendFile)
406408{
407409 auto * tf = new QTemporaryFile;
408410 if (!tf->open ()) {
409411 clog << " Failed to create a temporary file" << endl;
410412 FAIL_TEST ();
411413 }
412- tf->write (" Test " );
414+ tf->write (fileContent );
413415 tf->close ();
414416 QFileInfo tfi { *tf };
415417 // QFileInfo::fileName brings only the file name; QFile::fileName brings
@@ -454,9 +456,11 @@ TEST_IMPL(sendFile)
454456struct DownloadRunner {
455457 QUrl url;
456458
457- using result_type = QNetworkReply::NetworkError;
459+ using result_type = std::pair<QNetworkReply::NetworkError, bool >;
460+
461+ static constexpr result_type Success { QNetworkReply::NoError, true };
458462
459- QNetworkReply::NetworkError operator ()(int ) const
463+ result_type operator ()(int ) const
460464 {
461465 QEventLoop el;
462466 QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply {
@@ -466,10 +470,10 @@ struct DownloadRunner {
466470 reply.data (), &QNetworkReply::finished, &el, [&el] { el.exit (); },
467471 Qt::QueuedConnection);
468472 el.exec ();
469- return reply->error ();
473+ return { reply->error (), reply-> readAll () == fileContent } ;
470474 }
471475
472- static QVector<QNetworkReply::NetworkError > run (const QUrl& url, int threads)
476+ static QVector<result_type > run (const QUrl& url, int threads)
473477 {
474478 return QtConcurrent::blockingMapped (QVector<int >(threads),
475479 DownloadRunner{ url });
@@ -481,15 +485,15 @@ bool TestSuite::testDownload(const TestToken& thisTest, const QUrl& mxcUrl)
481485 // Testing direct media requests needs explicit allowance
482486 NetworkAccessManager::allowDirectMediaRequests (true );
483487 if (const auto result = DownloadRunner::run (mxcUrl, 1 );
484- result.back () != QNetworkReply::NoError ) {
488+ result.back () != DownloadRunner::Success ) {
485489 clog << " Direct media request to "
486490 << mxcUrl.toDisplayString ().toStdString ()
487491 << " was allowed but failed" << endl;
488492 FAIL_TEST ();
489493 }
490494 NetworkAccessManager::allowDirectMediaRequests (false );
491495 if (const auto result = DownloadRunner::run (mxcUrl, 1 );
492- result.back () == QNetworkReply::NoError ) {
496+ result.back () == DownloadRunner::Success ) {
493497 clog << " Direct media request to "
494498 << mxcUrl.toDisplayString ().toStdString ()
495499 << " was disallowed but succeeded" << endl;
@@ -500,8 +504,8 @@ bool TestSuite::testDownload(const TestToken& thisTest, const QUrl& mxcUrl)
500504 const auto results = DownloadRunner::run (httpUrl, 3 );
501505 // Move out actual test from the multithreaded code to help debugging
502506 FINISH_TEST (std::all_of (results.begin (), results.end (),
503- [](QNetworkReply::NetworkError ne ) {
504- return ne == QNetworkReply::NoError ;
507+ [](DownloadRunner::result_type result ) {
508+ return result == DownloadRunner::Success ;
505509 }));
506510}
507511
0 commit comments