File indexing completed on 2025-01-05 03:58:15

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2021-01-05
0007  * Description : an unit test to download version online.
0008  *
0009  * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 // Qt includes
0016 
0017 #include <QCoreApplication>
0018 #include <QTest>
0019 #include <QObject>
0020 
0021 // Local includes
0022 
0023 #include "digikam_debug.h"
0024 #include "onlineversiondwnl.h"
0025 #include "onlineversionchecker.h"
0026 
0027 using namespace Digikam;
0028 
0029 int main(int argc, char* argv[])
0030 {
0031     QCoreApplication app(argc, argv);
0032 
0033     if (argc < 3)
0034     {
0035         qCDebug(DIGIKAM_TESTS_LOG) << "onlinecheck <bool> <bool> - Check if new version is online";
0036         qCDebug(DIGIKAM_TESTS_LOG) << "Usage: <bool> 0 for stable release only, 1 for pre-release.";
0037         qCDebug(DIGIKAM_TESTS_LOG) << "       <bool> 0 without debug symbols, 1 with debug symbols.";
0038         return -1;
0039     }
0040 
0041     bool preRelease = QString::fromLatin1(argv[1]).toInt();
0042     bool withDebug  = QString::fromLatin1(argv[2]).toInt();
0043     QString version;
0044 
0045     qCDebug(DIGIKAM_TESTS_LOG) << "Check for pre-release     :" << preRelease;
0046     qCDebug(DIGIKAM_TESTS_LOG) << "Version with debug symbols:" << withDebug;
0047 
0048     if (preRelease)
0049     {
0050         OnlineVersionChecker* const check = new OnlineVersionChecker(nullptr, preRelease);
0051         check->setCurrentBuildDate(QDateTime::fromString(QLatin1String("2021-01-01T00:00:00"), Qt::ISODate));
0052         check->checkForNewVersion();
0053 
0054         QTest::qWait(3000);
0055 
0056         version = check->preReleaseFileName();
0057 
0058         if (version.isEmpty())
0059         {
0060             qCWarning(DIGIKAM_TESTS_LOG) << "Cannot get pre-release version!";
0061             return (-1);
0062         }
0063     }
0064     else
0065     {
0066         version = QLatin1String("7.3.0");
0067     }
0068 
0069     OnlineVersionDwnl* const dwnl = new OnlineVersionDwnl(nullptr, preRelease, withDebug);
0070     dwnl->startDownload(version);
0071 
0072     QObject::connect(dwnl, &Digikam::OnlineVersionDwnl::signalDownloadProgress,
0073                      [=](qint64 brecv, qint64 btotal)
0074         {
0075             if (btotal)
0076             {
0077                 qCDebug(DIGIKAM_TESTS_LOG) << "Downloaded" << brecv << "/" << btotal << "bytes" << "(" << brecv*100/btotal << "% )";
0078             }
0079         }
0080     );
0081 
0082     app.exec();
0083 
0084     return 0;
0085 }