FileManagerTest.h 2.08 KB
Newer Older
1 2
/****************************************************************************
 *
3
 *   (c) 2009-2018 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * 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
#pragma once
Don Gagne's avatar
Don Gagne committed
12 13 14 15

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

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

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

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

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

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

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

    MultiSignalSpy*     _multiSpy;
    static const size_t _cSignals = maxSignalIndex;
    const char*         _rgSignals[_cSignals];
    
72 73
    /// @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.
74
    static const int _ackTimerTimeoutMsecs = FileManager::ackTimerMaxRetries * FileManager::ackTimerTimeoutMsecs * 2;
75
    
Don Gagne's avatar
Don Gagne committed
76 77 78
    QStringList _fileListReceived;
};