forked from mavlink/qgroundcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitialConnectTest.cc
61 lines (51 loc) · 2.72 KB
/
InitialConnectTest.cc
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
26
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
60
61
/****************************************************************************
*
* (c) 2009-2020 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 "InitialConnectTest.h"
#include "MultiVehicleManager.h"
#include "QGCApplication.h"
#include "LinkManager.h"
#include "MockLink.h"
void InitialConnectTest::_performTestCases(void)
{
static const struct TestCase_s {
MockConfiguration::FailureMode_t failureMode;
const char* failureModeStr;
} rgTestCases[] = {
{ MockConfiguration::FailNone, "No failures" },
{ MockConfiguration::FailInitialConnectRequestMessageAutopilotVersionFailure, "REQUEST_MESSAGE:AUTOPILOT_VERSION returns failure" },
{ MockConfiguration::FailInitialConnectRequestMessageAutopilotVersionLost, "REQUEST_MESSAGE:AUTOPILOT_VERSION success, AUTOPILOT_VERSION never sent" },
{ MockConfiguration::FailInitialConnectRequestMessageProtocolVersionFailure, "REQUEST_MESSAGE:PROTOCOL_VERSION returns failure" },
{ MockConfiguration::FailInitialConnectRequestMessageProtocolVersionLost, "REQUEST_MESSAGE:PROTOCOL_VERSION success, PROTOCOL_VERSION never sent" },
};
for (const struct TestCase_s& testCase: rgTestCases) {
qDebug() << "Testing case failure mode:" << testCase.failureModeStr;
_connectMockLink(MAV_AUTOPILOT_PX4, testCase.failureMode);
_disconnectMockLink();
}
}
void InitialConnectTest::_boardVendorProductId(void)
{
auto *mvm = qgcApp()->toolbox()->multiVehicleManager();
QSignalSpy activeVehicleSpy{mvm, &MultiVehicleManager::activeVehicleChanged};
auto mockConfig = std::make_shared<MockConfiguration>(QString{"MockLink"});
const uint16_t mockVendor = 1234;
const uint16_t mockProduct = 5678;
mockConfig->setBoardVendorProduct(mockVendor, mockProduct);
SharedLinkConfigurationPtr linkConfig = mockConfig;
_linkManager->createConnectedLink(linkConfig);
QVERIFY(activeVehicleSpy.wait());
auto *vehicle = mvm->activeVehicle();
QSignalSpy initialConnectCompleteSpy{vehicle, &Vehicle::initialConnectComplete};
// Both ends of mocklink (and the initial connect state machine?) operate on
// a different thread. The initial connection may already be complete.
QVERIFY(initialConnectCompleteSpy.wait() || vehicle->isInitialConnectComplete());
QCOMPARE(vehicle->firmwareBoardVendorId(), mockVendor);
QCOMPARE(vehicle->firmwareBoardProductId(), mockProduct);
_linkManager->disconnectAll();
}