FileManagerTest.cc 20.8 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

24
#include "FileManagerTest.h"
Don Gagne's avatar
Don Gagne committed
25 26

/// @file
27
///     @brief FileManager unit test. Note: All code here assumes all work between
28 29
///             the unit test, mack mavlink file server and file manager is happening on
///             the same thread.
Don Gagne's avatar
Don Gagne committed
30 31 32
///
///     @author Don Gagne <don@thegagnes.com>

33
UT_REGISTER_TEST(FileManagerTest)
Don Gagne's avatar
Don Gagne committed
34

35
FileManagerTest::FileManagerTest(void) :
36
    _mockFileServer(_systemIdQGC, _systemIdServer),
Don Gagne's avatar
Don Gagne committed
37 38 39 40 41 42
    _fileManager(NULL),
    _multiSpy(NULL)
{
}

// Called once before all test cases are run
43
void FileManagerTest::initTestCase(void)
Don Gagne's avatar
Don Gagne committed
44
{
45 46 47 48 49 50 51
    _mockUAS = new MockUAS();
    Q_CHECK_PTR(_mockUAS);
    
    _mockUAS->setMockSystemId(_systemIdServer);
    _mockUAS->setMockMavlinkPlugin(&_mockFileServer);
}

52
void FileManagerTest::cleanupTestCase(void)
53 54
{
    delete _mockUAS;
Don Gagne's avatar
Don Gagne committed
55 56 57
}

// Called before every test case
58
void FileManagerTest::init(void)
Don Gagne's avatar
Don Gagne committed
59
{
Don Gagne's avatar
Don Gagne committed
60 61
    UnitTest::init();
    
Don Gagne's avatar
Don Gagne committed
62 63
    Q_ASSERT(_multiSpy == NULL);
    
64
    _fileManager = new FileManager(NULL, _mockUAS, _systemIdQGC);
Don Gagne's avatar
Don Gagne committed
65 66
    Q_CHECK_PTR(_fileManager);
    
67 68 69 70
    // Reset any internal state back to normal
    _mockFileServer.setErrorMode(MockMavlinkFileServer::errModeNone);
    _fileListReceived.clear();
    
71
    connect(&_mockFileServer, &MockMavlinkFileServer::messageReceived, _fileManager, &FileManager::receiveMessage);
Don Gagne's avatar
Don Gagne committed
72

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

75
    _rgSignals[listEntrySignalIndex] = SIGNAL(listEntry(const QString&));
76
    _rgSignals[listCompleteSignalIndex] = SIGNAL(listComplete(void));
77 78 79

    _rgSignals[downloadFileLengthSignalIndex] = SIGNAL(downloadFileLength(unsigned int));
    _rgSignals[downloadFileCompleteSignalIndex] = SIGNAL(downloadFileComplete(void));
Don Gagne's avatar
Don Gagne committed
80
    
81 82
    _rgSignals[errorMessageSignalIndex] = SIGNAL(errorMessage(const QString&));

Don Gagne's avatar
Don Gagne committed
83 84 85 86 87 88
    _multiSpy = new MultiSignalSpy();
    Q_CHECK_PTR(_multiSpy);
    QCOMPARE(_multiSpy->init(_fileManager, _rgSignals, _cSignals), true);
}

// Called after every test case
89
void FileManagerTest::cleanup(void)
Don Gagne's avatar
Don Gagne committed
90 91 92 93 94 95 96 97 98
{
    Q_ASSERT(_multiSpy);
    Q_ASSERT(_fileManager);
    
    delete _fileManager;
    delete _multiSpy;
    
    _fileManager = NULL;
    _multiSpy = NULL;
Don Gagne's avatar
Don Gagne committed
99 100
    
    UnitTest::cleanup();
Don Gagne's avatar
Don Gagne committed
101 102
}

103 104
/// @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
105 106
{
    // Keep a list of all names received so we can test it for correctness
107
    _fileListReceived += entry;
Don Gagne's avatar
Don Gagne committed
108 109 110
}


111 112
#if 0
void FileManagerTest::_ackTest(void)
Don Gagne's avatar
Don Gagne committed
113 114 115 116 117 118 119 120
{
    Q_ASSERT(_fileManager);
    Q_ASSERT(_multiSpy);
    Q_ASSERT(_multiSpy->checkNoSignals() == true);
    
    // If the file manager doesn't receive an ack it will timeout and emit an error. So make sure
    // we don't get any error signals.
    QVERIFY(_fileManager->_sendCmdTestAck());
121
    QTest::qWait(_ackTimerTimeoutMsecs); // Let the file manager timeout
Don Gagne's avatar
Don Gagne committed
122
    QVERIFY(_multiSpy->checkNoSignals());
123
    
124
    // Setup for no response from ack. This should cause a timeout error
125 126 127 128
    _mockFileServer.setErrorMode(MockMavlinkFileServer::errModeNoResponse);
    QVERIFY(_fileManager->_sendCmdTestAck());
    QTest::qWait(_ackTimerTimeoutMsecs); // Let the file manager timeout
    QCOMPARE(_multiSpy->checkOnlySignalByMask(errorMessageSignalMask), true);
129 130 131 132 133 134 135
    _multiSpy->clearAllSignals();

    // Setup for a bad sequence number in the ack. This should cause an error;
    _mockFileServer.setErrorMode(MockMavlinkFileServer::errModeBadSequence);
    QVERIFY(_fileManager->_sendCmdTestAck());
    QCOMPARE(_multiSpy->checkOnlySignalByMask(errorMessageSignalMask), true);
    _multiSpy->clearAllSignals();
Don Gagne's avatar
Don Gagne committed
136 137
}

138
void FileManagerTest::_noAckTest(void)
Don Gagne's avatar
Don Gagne committed
139 140 141 142 143 144 145
{
    Q_ASSERT(_fileManager);
    Q_ASSERT(_multiSpy);
    Q_ASSERT(_multiSpy->checkNoSignals() == true);
    
    // This should not get the ack back and timeout.
    QVERIFY(_fileManager->_sendCmdTestNoAck());
146
    QTest::qWait(_ackTimerTimeoutMsecs); // Let the file manager timeout
Don Gagne's avatar
Don Gagne committed
147 148 149
    QCOMPARE(_multiSpy->checkOnlySignalByMask(errorMessageSignalMask), true);
}

150
void FileManagerTest::_resetTest(void)
Don Gagne's avatar
Don Gagne committed
151 152 153 154 155 156 157 158 159 160 161
{
    Q_ASSERT(_fileManager);
    Q_ASSERT(_multiSpy);
    Q_ASSERT(_multiSpy->checkNoSignals() == true);
    
    // Send a reset command
    //  We should not get any signals back from this
    QVERIFY(_fileManager->_sendCmdReset());
    QVERIFY(_multiSpy->checkNoSignals());
}

162
void FileManagerTest::_listTest(void)
Don Gagne's avatar
Don Gagne committed
163 164 165 166 167
{
    Q_ASSERT(_fileManager);
    Q_ASSERT(_multiSpy);
    Q_ASSERT(_multiSpy->checkNoSignals() == true);
    
168
    // FileManager::listDirectory signalling as follows:
169
    //  Emits a listEntry signal for each list entry
170 171 172 173 174
    //  Emits an errorMessage signal if:
    //      It gets a Nak back
    //      Sequence number is incorrrect on any response
    //      CRC is incorrect on any responses
    //      List entry is formatted incorrectly
175
    //  It is possible to get a number of good listEntry signals, followed by an errorMessage signal
176 177 178
    //  Emits listComplete after it receives the final list entry
    //      If an errorMessage signal is signalled no listComplete is signalled
    
Don Gagne's avatar
Don Gagne committed
179 180 181
    // Send a bogus path
    //  We should get a single resetStatusMessages signal
    //  We should get a single errorMessage signal
182
    _fileManager->listDirectory("/bogus");
183
    QCOMPARE(_multiSpy->checkOnlySignalByMask(errorMessageSignalMask), true);
Don Gagne's avatar
Don Gagne committed
184 185
    _multiSpy->clearAllSignals();

186
    // Setup the mock file server with a valid directory list
Don Gagne's avatar
Don Gagne committed
187 188 189 190
    QStringList fileList;
    fileList << "Ddir" << "Ffoo" << "Fbar";
    _mockFileServer.setFileList(fileList);
    
191 192 193 194 195 196 197 198 199 200 201 202 203
    // Run through the various server side failure modes
    for (size_t i=0; i<MockMavlinkFileServer::cFailureModes; i++) {
        MockMavlinkFileServer::ErrorMode_t errMode = MockMavlinkFileServer::rgFailureModes[i];
        qDebug() << "Testing failure mode:" << errMode;
        _mockFileServer.setErrorMode(errMode);
        
        _fileManager->listDirectory("/");
        QTest::qWait(_ackTimerTimeoutMsecs); // Let the file manager timeout
        
        if (errMode == MockMavlinkFileServer::errModeNoSecondResponse || errMode == MockMavlinkFileServer::errModeNakSecondResponse) {
            // For simulated server errors on subsequent Acks, the first Ack will go through. This means we should have gotten some
            // partial results. In the case of the directory list test set, all entries fit into the first ack, so we should have
            // gotten back all of them.
204 205
            QCOMPARE(_multiSpy->getSpyByIndex(listEntrySignalIndex)->count(), fileList.count());
            _multiSpy->clearSignalByIndex(listEntrySignalIndex);
206 207
            
            // And then it should have errored out because the next list Request would have failed.
208
            QCOMPARE(_multiSpy->checkOnlySignalByMask(errorMessageSignalMask), true);
209 210 211
        } else {
            // For the simulated errors which failed the intial response we should not have gotten any results back at all.
            // Just an error.
212
            QCOMPARE(_multiSpy->checkOnlySignalByMask(errorMessageSignalMask), true);
213 214 215 216 217 218 219 220
        }

        // Set everything back to initial state
        _fileListReceived.clear();
        _multiSpy->clearAllSignals();
        _mockFileServer.setErrorMode(MockMavlinkFileServer::errModeNone);
    }

221
    // Send a list command at the root of the directory tree which should succeed    
222
    _fileManager->listDirectory("/");
223
    QCOMPARE(_multiSpy->checkSignalByMask(listCompleteSignalMask), true);
224
    QCOMPARE(_multiSpy->checkNoSignalByMask(errorMessageSignalMask), true);
225
    QCOMPARE(_multiSpy->getSpyByIndex(listEntrySignalIndex)->count(), fileList.count());
226
    QVERIFY(_fileListReceived == fileList);
Don Gagne's avatar
Don Gagne committed
227
}
228

229
void FileManagerTest::_readDownloadTest(void)
230 231 232 233 234
{
    Q_ASSERT(_fileManager);
    Q_ASSERT(_multiSpy);
    Q_ASSERT(_multiSpy->checkNoSignals() == true);
    
235
    // FileManager::downloadPath works as follows:
236 237 238
    //  Sends an Open Command to the server
    //      Expects an Ack Response back from the server with the correct sequence numner
    //          Emits an errorMessage signal if it gets a Nak back
239
    //      Emits an downloadFileLength signal with the file length if it gets back a good Ack
240
    //  Sends subsequent Read commands to the server until it gets the full file contents back
241
    //      Emits a downloadFileProgress for each read command ack it gets back
242 243
    //  Sends Terminate command to server when download is complete to close Open command
    //      Mock file server will signal terminateCommandReceived when it gets a Terminate command
244
    //  Sends downloadFileComplete signal to indicate the download is complete
245 246 247 248
    //  Emits an errorMessage signal if sequence number is incorrrect on any response
    //  Emits an errorMessage signal if CRC is incorrect on any responses
    
    // Expected signals if the Open command fails for any reason
249
    quint16 signalMaskOpenFailure = errorMessageSignalMask;
250 251

    // Expected signals if the Read command fails for any reason
252
    quint16 signalMaskReadFailure = downloadFileLengthSignalMask | errorMessageSignalMask;
253 254
    
    // Expected signals if the downloadPath command succeeds
255
    quint16 signalMaskDownloadSuccess = downloadFileLengthSignalMask | downloadFileCompleteSignalMask;
256

257 258 259 260
    // Send a bogus path
    //  We should get a single resetStatusMessages signal
    //  We should get a single errorMessage signal
    _fileManager->downloadPath("bogus", QDir::temp());
261
    QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskOpenFailure), true);
262 263 264
    _multiSpy->clearAllSignals();
    
    // Clean previous downloads
265 266 267 268 269
    for (size_t i=0; i<MockMavlinkFileServer::cFileTestCases; i++) {
        QString filePath = QDir::temp().absoluteFilePath(MockMavlinkFileServer::rgFileTestCases[i].filename);
        if (QFile::exists(filePath)) {
            Q_ASSERT(QFile::remove(filePath));
        }
270
    }
271
    
272 273
    // We setup a spy on the Terminate command signal of the mock file server so that we can determine that a
    // Terminate command was correctly sent after the Open/Read commands complete.
274 275
    QSignalSpy terminateSpy(&_mockFileServer, SIGNAL(terminateCommandReceived()));
    
276
    // Run through the set of file test cases
277
    for (size_t i=0; i<MockMavlinkFileServer::cFileTestCases; i++) {
278
        const MockMavlinkFileServer::FileTestCase* testCase = &MockMavlinkFileServer::rgFileTestCases[i];
279 280 281
        
        // Run through the various failure modes for this test case
        for (size_t j=0; j<MockMavlinkFileServer::cFailureModes; j++) {
282
			
283 284 285 286
            MockMavlinkFileServer::ErrorMode_t errMode = MockMavlinkFileServer::rgFailureModes[j];
            qDebug() << "Testing failure mode:" << errMode;
            _mockFileServer.setErrorMode(errMode);
            
287
            _fileManager->downloadPath(testCase->filename, QDir::temp());
288 289 290 291 292
            QTest::qWait(_ackTimerTimeoutMsecs); // Let the file manager timeout
            
            if (errMode == MockMavlinkFileServer::errModeNoSecondResponse || errMode == MockMavlinkFileServer::errModeNakSecondResponse) {
                // For simulated server errors on subsequent Acks, the first Ack will go through. We must handle things differently depending
                // on whether the downloaded file requires multiple packets to complete the download.
293
                if (testCase->fMultiPacketResponse) {
294 295
                    // The downloaded file requires multiple Acks to complete. Hence first Read should have succeeded and sent one downloadFileComplete.
                    // Second Read should have failed.
296
                    QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskReadFailure), true);
297 298 299 300 301 302

                    // Open command succeeded, so we should get a Terminate for the open
                    QCOMPARE(terminateSpy.count(), 1);
                } else {
                    // The downloaded file fits within a single Ack response, hence there is no second Read issued.
                    // This should result in a successful download.
303
                    QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskDownloadSuccess), true);
304 305 306 307 308
                    
                    // We should get a single Terminate command to close the Open session
                    QCOMPARE(terminateSpy.count(), 1);
                    
                    // Validate file contents
309 310
                    QString filePath = QDir::temp().absoluteFilePath(testCase->filename);
                    _validateFileContents(filePath, testCase->length);
311 312 313 314
                }
            } else {
                // For all the other simulated server errors the Open command should have failed. Since the Open failed
                // there is no session to terminate, hence no Terminate in this case.
315
                QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskOpenFailure), true);
316 317 318 319 320 321 322 323 324 325
                QCOMPARE(terminateSpy.count(), 0);
            }

            // Cleanup for next iteration
            _multiSpy->clearAllSignals();
            terminateSpy.clear();
            _mockFileServer.setErrorMode(MockMavlinkFileServer::errModeNone);
        }

        // Run what should be a successful file download test case. No servers errors are being simulated.
326
		_mockFileServer.setErrorMode(MockMavlinkFileServer::errModeNone);
327 328 329 330 331 332
        _fileManager->downloadPath(testCase->filename, QDir::temp());

        // This should be a succesful download
        QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskDownloadSuccess), true);
        
        // Make sure the file length coming back through the openFileLength signal is correct
333
        QVERIFY(_multiSpy->getSpyByIndex(downloadFileLengthSignalIndex)->takeFirst().at(0).toInt() == testCase->length);
334 335 336

        _multiSpy->clearAllSignals();
        
337
        // We should get a single Terminate command to close the session
338 339 340
        QCOMPARE(terminateSpy.count(), 1);
        terminateSpy.clear();
        
341
        // Validate file contents
342 343 344
        QString filePath = QDir::temp().absoluteFilePath(MockMavlinkFileServer::rgFileTestCases[i].filename);
        _validateFileContents(filePath, MockMavlinkFileServer::rgFileTestCases[i].length);
    }
345
}
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
#endif

void FileManagerTest::_streamDownloadTest(void)
{
	Q_ASSERT(_fileManager);
	Q_ASSERT(_multiSpy);
	Q_ASSERT(_multiSpy->checkNoSignals() == true);
	
	// FileManager::streamPath works as follows:
	//  Sends an Open Command to the server
	//      Expects an Ack Response back from the server with the correct sequence numner
	//          Emits an errorMessage signal if it gets a Nak back
	//      Emits an downloadFileLength signal with the file length if it gets back a good Ack
	//  Sends a single Stream command to the server
	//		Expects continuous Ack responses back with file contents
	//      Emits a downloadFileProgress for each ack it gets back
	//  Sends Terminate command to server when download is complete to close Open command
	//      Mock file server will signal terminateCommandReceived when it gets a Terminate command
	//  Sends downloadFileComplete signal to indicate the download is complete
	//  Emits an errorMessage signal if sequence number is incorrrect on any response
	//  Emits an errorMessage signal if CRC is incorrect on any responses
	
	// Expected signals if the Open command fails for any reason
	quint16 signalMaskOpenFailure = errorMessageSignalMask;
	
	// Expected signals if the Read command fails for any reason
	quint16 signalMaskReadFailure = downloadFileLengthSignalMask | errorMessageSignalMask;
	
	// Expected signals if the downloadPath command succeeds
	quint16 signalMaskDownloadSuccess = downloadFileLengthSignalMask | downloadFileCompleteSignalMask;
	
	// Send a bogus path
	//  We should get a single resetStatusMessages signal
	//  We should get a single errorMessage signal
	_fileManager->streamPath("bogus", QDir::temp());
	QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskOpenFailure), true);
	_multiSpy->clearAllSignals();
	
	// Clean previous downloads
	for (size_t i=0; i<MockMavlinkFileServer::cFileTestCases; i++) {
		QString filePath = QDir::temp().absoluteFilePath(MockMavlinkFileServer::rgFileTestCases[i].filename);
		if (QFile::exists(filePath)) {
			Q_ASSERT(QFile::remove(filePath));
		}
	}
	
	// We setup a spy on the Terminate command signal of the mock file server so that we can determine that a
	// Terminate command was correctly sent after the Open/Read commands complete.
	QSignalSpy terminateSpy(&_mockFileServer, SIGNAL(terminateCommandReceived()));
	
	// Run through the set of file test cases
	for (size_t i=0; i<MockMavlinkFileServer::cFileTestCases; i++) {
		const MockMavlinkFileServer::FileTestCase* testCase = &MockMavlinkFileServer::rgFileTestCases[i];
		
		// Run through the various failure modes for this test case
		for (size_t j=0; j<MockMavlinkFileServer::cFailureModes; j++) {
			
			MockMavlinkFileServer::ErrorMode_t errMode = MockMavlinkFileServer::rgFailureModes[j];
			qDebug() << "Testing failure mode:" << errMode;
			_mockFileServer.setErrorMode(errMode);
			
			_fileManager->streamPath(testCase->filename, QDir::temp());
			QTest::qWait(_ackTimerTimeoutMsecs); // Let the file manager timeout
			
			if (errMode == MockMavlinkFileServer::errModeNoSecondResponse || errMode == MockMavlinkFileServer::errModeNakSecondResponse) {
				// For simulated server errors on subsequent Acks, the first Ack will go through. We must handle things differently depending
				// on whether the downloaded file requires multiple packets to complete the download.
				if (testCase->packetCount != 1) {
					// The downloaded file requires multiple Acks to complete. Second Ack should have failed.
					QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskReadFailure), true);
					
					// Open command succeeded, so we should get a Terminate for the open
					QCOMPARE(terminateSpy.count(), 1);
				} else {
					// The downloaded file fits within a single Ack response, hence there is no second Read issued.
					// This should result in a successful download.
					QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskDownloadSuccess), true);
					
					// We should get a single Terminate command to close the Open session
					QCOMPARE(terminateSpy.count(), 1);
					
					// Validate file contents
					QString filePath = QDir::temp().absoluteFilePath(testCase->filename);
					_validateFileContents(filePath, testCase->length);
				}
			} else {
				// For all the other simulated server errors the Open command should have failed. Since the Open failed
				// there is no session to terminate, hence no Terminate in this case.
				QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskOpenFailure), true);
				QCOMPARE(terminateSpy.count(), 0);
			}
			
			// Cleanup for next iteration
			_multiSpy->clearAllSignals();
			terminateSpy.clear();
			_mockFileServer.setErrorMode(MockMavlinkFileServer::errModeNone);
		}
		
		// Run what should be a successful file download test case. No servers errors are being simulated.
		_mockFileServer.setErrorMode(MockMavlinkFileServer::errModeNone);
		_fileManager->streamPath(testCase->filename, QDir::temp());
		
		// This should be a succesful download
		QCOMPARE(_multiSpy->checkOnlySignalByMask(signalMaskDownloadSuccess), true);
		
		// Make sure the file length coming back through the openFileLength signal is correct
		QVERIFY(_multiSpy->getSpyByIndex(downloadFileLengthSignalIndex)->takeFirst().at(0).toInt() == testCase->length);
		
		_multiSpy->clearAllSignals();
		
		// We should get a single Terminate command to close the session
		QCOMPARE(terminateSpy.count(), 1);
		terminateSpy.clear();
		
		// Validate file contents
		QString filePath = QDir::temp().absoluteFilePath(MockMavlinkFileServer::rgFileTestCases[i].filename);
		_validateFileContents(filePath, MockMavlinkFileServer::rgFileTestCases[i].length);
	}
}

void FileManagerTest::_validateFileContents(const QString& filePath, uint8_t length)
{
	QFile file(filePath);
	
	// Make sure file size is correct
	QCOMPARE(file.size(), (qint64)length);
	
	// Read data
	QVERIFY(file.open(QIODevice::ReadOnly));
	QByteArray bytes = file.readAll();
	file.close();
	
	// Validate file contents:
	//      Repeating 0x00, 0x01 .. 0xFF until file is full
	for (uint8_t i=0; i<bytes.length(); i++) {
		QCOMPARE((uint8_t)bytes[i], (uint8_t)(i & 0xFF));
	}
}