LogDownloadTest.cc 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "LogDownloadTest.h"
#include "LogDownloadController.h"
#include "MockLink.h"

#include <QDir>

LogDownloadTest::LogDownloadTest(void)
{

}

void LogDownloadTest::downloadTest(void)
{

    _connectMockLink(MAV_AUTOPILOT_PX4);

26
    LogDownloadController* controller = new LogDownloadController();
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

    _rgLogDownloadControllerSignals[requestingListChangedSignalIndex] =     SIGNAL(requestingListChanged());
    _rgLogDownloadControllerSignals[downloadingLogsChangedSignalIndex] =    SIGNAL(downloadingLogsChanged());
    _rgLogDownloadControllerSignals[modelChangedSignalIndex] =              SIGNAL(modelChanged());

    _multiSpyLogDownloadController = new MultiSignalSpy();
    QVERIFY(_multiSpyLogDownloadController->init(controller, _rgLogDownloadControllerSignals, _cLogDownloadControllerSignals));

    controller->refresh();
    QVERIFY(_multiSpyLogDownloadController->waitForSignalByIndex(requestingListChangedSignalIndex, 10000));
    _multiSpyLogDownloadController->clearAllSignals();
    if (controller->requestingList()) {
        QVERIFY(_multiSpyLogDownloadController->waitForSignalByIndex(requestingListChangedSignalIndex, 10000));
        QCOMPARE(controller->requestingList(), false);
    }
    _multiSpyLogDownloadController->clearAllSignals();

    QGCLogModel* model = controller->model();
    QVERIFY(model);
    qDebug() << model->count();
    (*model)[0]->setSelected(true);

    QString downloadTo = QDir::currentPath();
    qDebug() << "download to:" << downloadTo;
    controller->downloadToDirectory(downloadTo);
    QVERIFY(_multiSpyLogDownloadController->waitForSignalByIndex(downloadingLogsChangedSignalIndex, 10000));
    _multiSpyLogDownloadController->clearAllSignals();
    if (controller->downloadingLogs()) {
        QVERIFY(_multiSpyLogDownloadController->waitForSignalByIndex(downloadingLogsChangedSignalIndex, 10000));
        QCOMPARE(controller->downloadingLogs(), false);
    }
    _multiSpyLogDownloadController->clearAllSignals();

60
    QString downloadFile = QDir(downloadTo).filePath("log_0_UnknownDate.ulg");
61 62 63 64 65 66
    QVERIFY(UnitTest::fileCompare(downloadFile, _mockLink->logDownloadFile()));

    QFile::remove(downloadFile);

    delete controller;
}