FileManagerTest.h 2.09 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
#ifndef FileManagerTEST_H
#define FileManagerTEST_H
Don Gagne's avatar
Don Gagne committed
13 14 15 16

#include <QObject>
#include <QtTest/QtTest>

Don Gagne's avatar
Don Gagne committed
17
#include "UnitTest.h"
18
#include "FileManager.h"
19
#include "MockLink.h"
Don Gagne's avatar
Don Gagne committed
20 21 22
#include "MultiSignalSpy.h"

/// @file
23
///     @brief FileManager unit test
Don Gagne's avatar
Don Gagne committed
24 25 26
///
///     @author Don Gagne <don@thegagnes.com>

27
class FileManagerTest : public UnitTest
Don Gagne's avatar
Don Gagne committed
28 29 30 31
{
    Q_OBJECT
    
public:
32
    FileManagerTest(void);
Don Gagne's avatar
Don Gagne committed
33 34 35 36 37 38 39 40 41 42
    
private slots:
    // Test case initialization
    void init(void);
    void cleanup(void);
    
    // Test cases
    void _ackTest(void);
    void _noAckTest(void);
    void _listTest(void);
43 44
	
    // Connected to FileManager listEntry signal
45
    void listEntry(const QString& entry);
Don Gagne's avatar
Don Gagne committed
46 47
    
private:
48 49
    void _validateFileContents(const QString& filePath, uint8_t length);

Don Gagne's avatar
Don Gagne committed
50
    enum {
51
        listEntrySignalIndex = 0,
Don Gagne's avatar
Don Gagne committed
52 53
        commandCompleteSignalIndex,
        commandErrorSignalIndex,
Don Gagne's avatar
Don Gagne committed
54 55 56 57
        maxSignalIndex
    };
    
    enum {
Don Gagne's avatar
Don Gagne committed
58 59
        listEntrySignalMask =       1 << listEntrySignalIndex,
        commandCompleteSignalMask = 1 << commandCompleteSignalIndex,
60
        commandErrorSignalMask =    1 << commandErrorSignalIndex,
Don Gagne's avatar
Don Gagne committed
61
    };
62 63 64 65

    static const uint8_t    _systemIdQGC = 255;
    static const uint8_t    _systemIdServer = 128;

66 67
    MockLinkFileServer* _fileServer;
    FileManager*        _fileManager;
Don Gagne's avatar
Don Gagne committed
68 69 70 71 72

    MultiSignalSpy*     _multiSpy;
    static const size_t _cSignals = maxSignalIndex;
    const char*         _rgSignals[_cSignals];
    
73 74
    /// @brief This is the amount of time to wait to allow the FileManager enough time to timeout waiting for an Ack.
    /// As such it must be larger than the Ack Timeout used by the FileManager.
75
    static const int _ackTimerTimeoutMsecs = FileManager::ackTimerTimeoutMsecs * 2;
76
    
Don Gagne's avatar
Don Gagne committed
77 78 79 80
    QStringList _fileListReceived;
};

#endif