FileManagerTest.cc 16.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

Don Gagne's avatar
Don Gagne committed
10 11 12 13

/// @file
///     @author Don Gagne <don@thegagnes.com>

14
#include "FileManagerTest.h"
15
#include "MultiVehicleManager.h"
16
#include "UAS.h"
17
#include "QGCApplication.h"
18

19 20 21 22
FileManagerTest::FileManagerTest(void)
    : _fileServer(NULL)
    , _fileManager(NULL)
    , _multiSpy(NULL)
Don Gagne's avatar
Don Gagne committed
23
{
24

Don Gagne's avatar
Don Gagne committed
25 26 27
}

// Called before every test case
28
void FileManagerTest::init(void)
Don Gagne's avatar
Don Gagne committed
29
{
Don Gagne's avatar
Don Gagne committed
30 31
    UnitTest::init();
    
32
    _connectMockLink();
33 34 35

    _fileServer = _mockLink->getFileServer();
    QVERIFY(_fileServer != NULL);
Don Gagne's avatar
Don Gagne committed
36
    
37
    _fileManager = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->uas()->getFileManager();
38 39 40
    QVERIFY(_fileManager != NULL);
    
    Q_ASSERT(_multiSpy == NULL);
Don Gagne's avatar
Don Gagne committed
41
    
42
    // Reset any internal state back to normal
43
    _fileServer->setErrorMode(MockLinkFileServer::errModeNone);
44
    _fileListReceived.clear();
Don Gagne's avatar
Don Gagne committed
45

46
    connect(_fileManager, &FileManager::listEntry, this, &FileManagerTest::listEntry);
Don Gagne's avatar
Don Gagne committed
47

48
    _rgSignals[listEntrySignalIndex] = SIGNAL(listEntry(const QString&));
49 50
    _rgSignals[commandCompleteSignalIndex] = SIGNAL(commandComplete(void));
    _rgSignals[commandErrorSignalIndex] = SIGNAL(commandError(const QString&));
51

Don Gagne's avatar
Don Gagne committed
52 53 54 55 56 57
    _multiSpy = new MultiSignalSpy();
    Q_CHECK_PTR(_multiSpy);
    QCOMPARE(_multiSpy->init(_fileManager, _rgSignals, _cSignals), true);
}

// Called after every test case
58
void FileManagerTest::cleanup(void)
Don Gagne's avatar
Don Gagne committed
59 60 61 62
{
    Q_ASSERT(_multiSpy);
    Q_ASSERT(_fileManager);
    
63 64
    // Disconnecting the link will prompt for log file save
    setExpectedFileDialog(getSaveFileName, QStringList());
65 66
    _disconnectMockLink();

67 68 69
    _fileServer = NULL;
    _fileManager = NULL;
    
Don Gagne's avatar
Don Gagne committed
70 71 72
    delete _multiSpy;
    
    _multiSpy = NULL;
Don Gagne's avatar
Don Gagne committed
73 74
    
    UnitTest::cleanup();
Don Gagne's avatar
Don Gagne committed
75 76
}

77 78
/// @brief Connected to FileManager listEntry signal in order to catch list entries
void FileManagerTest::listEntry(const QString& entry)
Don Gagne's avatar
Don Gagne committed
79 80
{
    // Keep a list of all names received so we can test it for correctness
81
    _fileListReceived += entry;
Don Gagne's avatar
Don Gagne committed
82 83 84
}


85
void FileManagerTest::_ackTest(void)
Don Gagne's avatar
Don Gagne committed
86 87 88 89 90 91 92
{
    Q_ASSERT(_fileManager);
    Q_ASSERT(_multiSpy);
    Q_ASSERT(_multiSpy->checkNoSignals() == true);
    
    // If