Skip to content

Commit

Permalink
backend: add SetReturnToLaunchAfterMission to Mission
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVautherin committed Aug 31, 2018
1 parent 23083a0 commit cdcd324
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/src/plugins/mission/mission_service_impl.h
Expand Up @@ -203,6 +203,18 @@ class MissionServiceImpl final : public dronecode_sdk::rpc::mission::MissionServ
return grpc::Status::OK;
}

grpc::Status SetReturnToLaunchAfterMission(
grpc::ServerContext * /* context */,
const rpc::mission::SetReturnToLaunchAfterMissionRequest *request,
rpc::mission::SetReturnToLaunchAfterMissionResponse * /* response */) override
{
if (request != nullptr) {
_mission.set_return_to_launch_after_mission(request->enable());
}

return grpc::Status::OK;
}

static void translateMissionItem(const std::shared_ptr<MissionItem> mission_item,
rpc::mission::MissionItem *rpc_mission_item)
{
Expand Down
26 changes: 26 additions & 0 deletions backend/test/mission_service_impl_test.cpp
Expand Up @@ -679,6 +679,32 @@ void MissionServiceImplGetRTLAfterMissionTest::checkGetRTLAfterMissionReturns(
EXPECT_EQ(expected_value, response.enable());
}

class MissionServiceImplSetRTLAfterMissionTest : public MissionServiceImplTestBase {
protected:
void checkSetRTLAfterMissionSets(const bool expected_value);
};

TEST_F(MissionServiceImplSetRTLAfterMissionTest, setRTLAfterMissionDoesNotCrashWithNullRequest)
{
_mission_service.SetReturnToLaunchAfterMission(nullptr, nullptr, nullptr);
}

TEST_F(MissionServiceImplSetRTLAfterMissionTest, setRTLAfterMissionSetsRightValue)
{
checkSetRTLAfterMissionSets(false);
checkSetRTLAfterMissionSets(true);
}

void MissionServiceImplSetRTLAfterMissionTest::checkSetRTLAfterMissionSets(
const bool expected_value)
{
EXPECT_CALL(_mission, set_return_to_launch_after_mission(expected_value));
dronecode_sdk::rpc::mission::SetReturnToLaunchAfterMissionRequest request;
request.set_enable(expected_value);

_mission_service.SetReturnToLaunchAfterMission(nullptr, &request, nullptr);
}

std::vector<InputPair> generateInputPairs()
{
std::vector<InputPair> input_pairs;
Expand Down
1 change: 1 addition & 0 deletions plugins/mission/mocks/mission_mock.h
Expand Up @@ -23,6 +23,7 @@ class MockMission {
MOCK_CONST_METHOD0(mission_finished, bool());
MOCK_CONST_METHOD1(subscribe_progress, void(Mission::progress_callback_t));
MOCK_CONST_METHOD0(get_return_to_launch_after_mission, bool());
MOCK_CONST_METHOD1(set_return_to_launch_after_mission, void(bool));
};

} // namespace testing
Expand Down

0 comments on commit cdcd324

Please sign in to comment.