Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
a3b4f2fe
Commit
a3b4f2fe
authored
Dec 06, 2016
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vehicle::sendMavCommand unit test
parent
b2835e7d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
220 additions
and
0 deletions
+220
-0
qgroundcontrol.pro
qgroundcontrol.pro
+2
-0
SendMavCommandTest.cc
src/Vehicle/SendMavCommandTest.cc
+151
-0
SendMavCommandTest.h
src/Vehicle/SendMavCommandTest.h
+31
-0
MockLink.cc
src/comm/MockLink.cc
+34
-0
UnitTestList.cc
src/qgcunittest/UnitTestList.cc
+2
-0
No files found.
qgroundcontrol.pro
View file @
a3b4f2fe
...
...
@@ -381,6 +381,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
src/qgcunittest/TCPLinkTest.h \
src/qgcunittest/TCPLoopBackServer.h \
src/qgcunittest/UnitTest.h \
src/Vehicle/SendMavCommandTest.h \
SOURCES += \
src/AnalyzeView/LogDownloadTest.cc \
...
...
@@ -409,6 +410,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
src/qgcunittest/TCPLoopBackServer.cc \
src/qgcunittest/UnitTest.cc \
src/qgcunittest/UnitTestList.cc \
src/Vehicle/SendMavCommandTest.cc \
} } } } } }
# Main QGC Headers and Source files
...
...
src/Vehicle/SendMavCommandTest.cc
0 → 100644
View file @
a3b4f2fe
/****************************************************************************
*
* (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.
*
****************************************************************************/
#include "SendMavCommandTest.h"
#include "MultiVehicleManager.h"
#include "QGCApplication.h"
void
SendMavCommandTest
::
_noFailure
(
void
)
{
_connectMockLink
();
MultiVehicleManager
*
vehicleMgr
=
qgcApp
()
->
toolbox
()
->
multiVehicleManager
();
Vehicle
*
vehicle
=
vehicleMgr
->
activeVehicle
();
QVERIFY
(
vehicle
);
vehicle
->
sendMavCommand
(
MAV_COMP_ID_ALL
,
MAV_CMD_USER_1
,
true
/* showError */
);
QSignalSpy
spyResult
(
vehicle
,
SIGNAL
(
mavCommandResult
(
int
,
int
,
int
,
int
,
bool
)));
QCOMPARE
(
spyResult
.
wait
(
10000
),
true
);
QList
<
QVariant
>
arguments
=
spyResult
.
takeFirst
();
QCOMPARE
(
arguments
.
count
(),
5
);
QCOMPARE
(
arguments
.
at
(
0
).
toInt
(),
vehicle
->
id
());
QCOMPARE
(
arguments
.
at
(
2
).
toInt
(),
(
int
)
MAV_CMD_USER_1
);
QCOMPARE
(
arguments
.
at
(
3
).
toInt
(),
(
int
)
MAV_RESULT_ACCEPTED
);
QCOMPARE
(
arguments
.
at
(
4
).
toBool
(),
false
);
}
void
SendMavCommandTest
::
_failureShowError
(
void
)
{
// Will pop error about request failure
setExpectedMessageBox
(
QMessageBox
::
Ok
);
_connectMockLink
();
MultiVehicleManager
*
vehicleMgr
=
qgcApp
()
->
toolbox
()
->
multiVehicleManager
();
Vehicle
*
vehicle
=
vehicleMgr
->
activeVehicle
();
QVERIFY
(
vehicle
);
vehicle
->
sendMavCommand
(
MAV_COMP_ID_ALL
,
MAV_CMD_USER_2
,
true
/* showError */
);
QSignalSpy
spyResult
(
vehicle
,
SIGNAL
(
mavCommandResult
(
int
,
int
,
int
,
int
,
bool
)));
QCOMPARE
(
spyResult
.
wait
(
10000
),
true
);
QList
<
QVariant
>
arguments
=
spyResult
.
takeFirst
();
QCOMPARE
(
arguments
.
count
(),
5
);
QCOMPARE
(
arguments
.
at
(
0
).
toInt
(),
vehicle
->
id
());
QCOMPARE
(
arguments
.
at
(
2
).
toInt
(),
(
int
)
MAV_CMD_USER_2
);
QCOMPARE
(
arguments
.
at
(
3
).
toInt
(),
(
int
)
MAV_RESULT_FAILED
);
QCOMPARE
(
arguments
.
at
(
4
).
toBool
(),
false
);
// User should have been notified
checkExpectedMessageBox
();
}
void
SendMavCommandTest
::
_failureNoShowError
(
void
)
{
_connectMockLink
();
MultiVehicleManager
*
vehicleMgr
=
qgcApp
()
->
toolbox
()
->
multiVehicleManager
();
Vehicle
*
vehicle
=
vehicleMgr
->
activeVehicle
();
QVERIFY
(
vehicle
);
vehicle
->
sendMavCommand
(
MAV_COMP_ID_ALL
,
MAV_CMD_USER_2
,
false
/* showError */
);
QSignalSpy
spyResult
(
vehicle
,
SIGNAL
(
mavCommandResult
(
int
,
int
,
int
,
int
,
bool
)));
QCOMPARE
(
spyResult
.
wait
(
10000
),
true
);
QList
<
QVariant
>
arguments
=
spyResult
.
takeFirst
();
QCOMPARE
(
arguments
.
count
(),
5
);
QCOMPARE
(
arguments
.
at
(
0
).
toInt
(),
vehicle
->
id
());
QCOMPARE
(
arguments
.
at
(
2
).
toInt
(),
(
int
)
MAV_CMD_USER_2
);
QCOMPARE
(
arguments
.
at
(
3
).
toInt
(),
(
int
)
MAV_RESULT_FAILED
);
QCOMPARE
(
arguments
.
at
(
4
).
toBool
(),
false
);
}
void
SendMavCommandTest
::
_noFailureAfterRetry
(
void
)
{
_connectMockLink
();
MultiVehicleManager
*
vehicleMgr
=
qgcApp
()
->
toolbox
()
->
multiVehicleManager
();
Vehicle
*
vehicle
=
vehicleMgr
->
activeVehicle
();
QVERIFY
(
vehicle
);
vehicle
->
sendMavCommand
(
MAV_COMP_ID_ALL
,
MAV_CMD_USER_3
,
true
/* showError */
);
QSignalSpy
spyResult
(
vehicle
,
SIGNAL
(
mavCommandResult
(
int
,
int
,
int
,
int
,
bool
)));
QCOMPARE
(
spyResult
.
wait
(
10000
),
true
);
QList
<
QVariant
>
arguments
=
spyResult
.
takeFirst
();
QCOMPARE
(
arguments
.
count
(),
5
);
QCOMPARE
(
arguments
.
at
(
0
).
toInt
(),
vehicle
->
id
());
QCOMPARE
(
arguments
.
at
(
2
).
toInt
(),
(
int
)
MAV_CMD_USER_3
);
QCOMPARE
(
arguments
.
at
(
3
).
toInt
(),
(
int
)
MAV_RESULT_ACCEPTED
);
QCOMPARE
(
arguments
.
at
(
4
).
toBool
(),
false
);
}
void
SendMavCommandTest
::
_failureAfterRetry
(
void
)
{
// Will pop error about request failure
setExpectedMessageBox
(
QMessageBox
::
Ok
);
_connectMockLink
();
MultiVehicleManager
*
vehicleMgr
=
qgcApp
()
->
toolbox
()
->
multiVehicleManager
();
Vehicle
*
vehicle
=
vehicleMgr
->
activeVehicle
();
QVERIFY
(
vehicle
);
vehicle
->
sendMavCommand
(
MAV_COMP_ID_ALL
,
MAV_CMD_USER_4
,
true
/* showError */
);
QSignalSpy
spyResult
(
vehicle
,
SIGNAL
(
mavCommandResult
(
int
,
int
,
int
,
int
,
bool
)));
QCOMPARE
(
spyResult
.
wait
(
10000
),
true
);
QList
<
QVariant
>
arguments
=
spyResult
.
takeFirst
();
QCOMPARE
(
arguments
.
count
(),
5
);
QCOMPARE
(
arguments
.
at
(
0
).
toInt
(),
vehicle
->
id
());
QCOMPARE
(
arguments
.
at
(
2
).
toInt
(),
(
int
)
MAV_CMD_USER_4
);
QCOMPARE
(
arguments
.
at
(
3
).
toInt
(),
(
int
)
MAV_RESULT_FAILED
);
QCOMPARE
(
arguments
.
at
(
4
).
toBool
(),
false
);
// User should have been notified
checkExpectedMessageBox
();
}
void
SendMavCommandTest
::
_failureAfterNoReponse
(
void
)
{
// Will pop error about request failure
setExpectedMessageBox
(
QMessageBox
::
Ok
);
_connectMockLink
();
MultiVehicleManager
*
vehicleMgr
=
qgcApp
()
->
toolbox
()
->
multiVehicleManager
();
Vehicle
*
vehicle
=
vehicleMgr
->
activeVehicle
();
QVERIFY
(
vehicle
);
vehicle
->
sendMavCommand
(
MAV_COMP_ID_ALL
,
MAV_CMD_USER_5
,
true
/* showError */
);
QSignalSpy
spyResult
(
vehicle
,
SIGNAL
(
mavCommandResult
(
int
,
int
,
int
,
int
,
bool
)));
QCOMPARE
(
spyResult
.
wait
(
10000
),
true
);
QList
<
QVariant
>
arguments
=
spyResult
.
takeFirst
();
QCOMPARE
(
arguments
.
count
(),
5
);
QCOMPARE
(
arguments
.
at
(
0
).
toInt
(),
vehicle
->
id
());
QCOMPARE
(
arguments
.
at
(
2
).
toInt
(),
(
int
)
MAV_CMD_USER_5
);
QCOMPARE
(
arguments
.
at
(
3
).
toInt
(),
(
int
)
MAV_RESULT_FAILED
);
QCOMPARE
(
arguments
.
at
(
4
).
toBool
(),
true
);
// User should have been notified
checkExpectedMessageBox
();
}
src/Vehicle/SendMavCommandTest.h
0 → 100644
View file @
a3b4f2fe
/****************************************************************************
*
* (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.
*
****************************************************************************/
#ifndef SendMavCommandTest_H
#define SendMavCommandTest_H
#include "UnitTest.h"
class
SendMavCommandTest
:
public
UnitTest
{
Q_OBJECT
private
slots
:
void
_noFailure
(
void
);
void
_failureShowError
(
void
);
void
_failureNoShowError
(
void
);
void
_noFailureAfterRetry
(
void
);
void
_failureAfterRetry
(
void
);
void
_failureAfterNoReponse
(
void
);
private:
};
#endif
src/comm/MockLink.cc
View file @
a3b4f2fe
...
...
@@ -807,6 +807,40 @@ void MockLink::_handleCommandLong(const mavlink_message_t& msg)
commandResult
=
MAV_RESULT_ACCEPTED
;
_respondWithAutopilotVersion
();
break
;
case
MAV_CMD_USER_1
:
// Test command which always returns MAV_RESULT_ACCEPTED
commandResult
=
MAV_RESULT_ACCEPTED
;
break
;
case
MAV_CMD_USER_2
:
// Test command which always returns MAV_RESULT_FAILED
commandResult
=
MAV_RESULT_FAILED
;
break
;
case
MAV_CMD_USER_3
:
// Test command which returns MAV_RESULT_ACCEPTED on second attempt
static
bool
firstCmdUser3
=
true
;
if
(
firstCmdUser3
)
{
firstCmdUser3
=
false
;
return
;
}
else
{
firstCmdUser3
=
true
;
commandResult
=
MAV_RESULT_ACCEPTED
;
}
break
;
case
MAV_CMD_USER_4
:
// Test command which returns MAV_RESULT_FAILED on second attempt
static
bool
firstCmdUser4
=
true
;
if
(
firstCmdUser4
)
{
firstCmdUser4
=
false
;
return
;
}
else
{
firstCmdUser4
=
true
;
commandResult
=
MAV_RESULT_FAILED
;
}
break
;
case
MAV_CMD_USER_5
:
// No response
return
;
break
;
}
mavlink_message_t
commandAck
;
...
...
src/qgcunittest/UnitTestList.cc
View file @
a3b4f2fe
...
...
@@ -31,6 +31,7 @@
#include "ParameterManagerTest.h"
#include "MissionCommandTreeTest.h"
#include "LogDownloadTest.h"
#include "SendMavCommandTest.h"
UT_REGISTER_TEST
(
FactSystemTestGeneric
)
UT_REGISTER_TEST
(
FactSystemTestPX4
)
...
...
@@ -50,6 +51,7 @@ UT_REGISTER_TEST(TCPLinkTest)
UT_REGISTER_TEST
(
ParameterManagerTest
)
UT_REGISTER_TEST
(
MissionCommandTreeTest
)
UT_REGISTER_TEST
(
LogDownloadTest
)
UT_REGISTER_TEST
(
SendMavCommandTest
)
// List of unit test which are currently disabled.
// If disabling a new test, include reason in comment.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment