Skip to content

Commit

Permalink
backend: add pause mission test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sushma7785 authored and JonasVautherin committed May 22, 2018
1 parent d6cb241 commit 1ae7eb1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions backend/test/mission_service_impl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ using RPCCameraAction = dc::rpc::mission::MissionItem::CameraAction;
using StartMissionRequest = dc::rpc::mission::StartMissionRequest;
using StartMissionResponse = dc::rpc::mission::StartMissionResponse;

using PauseMissionRequest = dc::rpc::mission::PauseMissionRequest;
using PauseMissionResponse = dc::rpc::mission::PauseMissionResponse;

static constexpr auto ARBITRARY_RESULT = dc::Mission::Result::UNKNOWN;

std::vector<InputPair> generateInputPairs();
Expand Down Expand Up @@ -386,6 +389,47 @@ TEST_F(MissionServiceImplIsFinishedTest, isMissionFinishedDoesNotCrashWithNullRe
_mission_service.IsMissionFinished(nullptr, nullptr, nullptr);
}

class MissionServiceImplPauseTest : public MissionServiceImplTestBase
{
protected:
std::future<void> pauseMissionAndSaveParams(std::shared_ptr<PauseMissionResponse> response);
};

INSTANTIATE_TEST_CASE_P(MissionResultCorrespondences,
MissionServiceImplPauseTest,
::testing::ValuesIn(generateInputPairs()));

TEST_F(MissionServiceImplPauseTest, doesNotFailWhenArgsAreNull)
{
auto start_handle = pauseMissionAndSaveParams(nullptr);
_result_callback(ARBITRARY_RESULT);
}

std::future<void> MissionServiceImplPauseTest::pauseMissionAndSaveParams(
std::shared_ptr<PauseMissionResponse> response)
{
EXPECT_CALL(_mission, pause_mission_async(_))
.WillOnce(SaveResult(&_result_callback, &_callback_saved_promise));

auto start_handle = std::async(std::launch::async, [this, response]() {
_mission_service.PauseMission(nullptr, nullptr, response.get());
});

_callback_saved_future.wait();
return start_handle;
}

TEST_P(MissionServiceImplPauseTest, pauseResultIsTranslatedCorrectly)
{
auto response = std::make_shared<PauseMissionResponse>();
auto pause_handle = pauseMissionAndSaveParams(response);

_result_callback(GetParam().second);
pause_handle.wait();

EXPECT_EQ(GetParam().first, rpc::MissionResult::Result_Name(response->mission_result().result()));
}

std::vector<InputPair> generateInputPairs()
{
std::vector<InputPair> input_pairs;
Expand Down

0 comments on commit 1ae7eb1

Please sign in to comment.