Skip to content

Commit

Permalink
backend: use parameterized tests in action_service_impl_test
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVautherin committed Mar 9, 2018
1 parent ab2605b commit af73e85
Showing 1 changed file with 38 additions and 200 deletions.
238 changes: 38 additions & 200 deletions backend/test/action_service_impl_test.cpp
Expand Up @@ -6,22 +6,28 @@
#include "action/action_service_impl.h"
#include "action/mocks/action_mock.h"

namespace {

using testing::NiceMock;
using testing::Return;

using MockAction = NiceMock<dronecore::testing::MockAction>;
using ActionServiceImpl = dronecore::backend::ActionServiceImpl<MockAction>;

using ActionResult = dronecore::rpc::action::ActionResult;
using InputPair = std::pair<std::string, dronecore::Action::Result>;

std::vector<InputPair> generateInputPairs();
std::string armAndGetTranslatedResult(dronecore::Action::Result arm_result);
std::string takeoffAndGetTranslatedResult(dronecore::Action::Result takeoff_result);
std::string landAndGetTranslatedResult(dronecore::Action::Result land_result);

TEST(ActionServiceImpl, armSuccessIsCorrectlyTranslated)
class ActionServiceImplTest : public ::testing::TestWithParam<InputPair> {};

TEST_P(ActionServiceImplTest, armResultIsTranslatedCorrectly)
{
const auto rpc_result = armAndGetTranslatedResult(dronecore::Action::Result::SUCCESS);
EXPECT_EQ(rpc_result, "SUCCESS");
const auto rpc_result = armAndGetTranslatedResult(GetParam().second);
EXPECT_EQ(rpc_result, GetParam().first);
}

std::string armAndGetTranslatedResult(const dronecore::Action::Result arm_result)
Expand All @@ -37,76 +43,10 @@ std::string armAndGetTranslatedResult(const dronecore::Action::Result arm_result
return ActionResult::Result_Name(response.action_result().result());
}

TEST(ActionServiceImpl, armNoDeviceIsCorrectlyTranslated)
{
const auto rpc_result = armAndGetTranslatedResult(dronecore::Action::Result::NO_DEVICE);
EXPECT_EQ(rpc_result, "NO_DEVICE");
}

TEST(ActionServiceImpl, armConnectionErrorIsCorrectlyTranslated)
{
const auto rpc_result = armAndGetTranslatedResult(
dronecore::Action::Result::CONNECTION_ERROR);
EXPECT_EQ(rpc_result, "CONNECTION_ERROR");
}

TEST(ActionServiceImpl, armBusyIsCorrectlyTranslated)
{
const auto rpc_result = armAndGetTranslatedResult(dronecore::Action::Result::BUSY);
EXPECT_EQ(rpc_result, "BUSY");
}

TEST(ActionServiceImpl, armCommandDeniedIsCorrectlyTranslated)
TEST_P(ActionServiceImplTest, takeoffResultIsTranslatedCorrectly)
{
const auto rpc_result = armAndGetTranslatedResult(
dronecore::Action::Result::COMMAND_DENIED);
EXPECT_EQ(rpc_result, "COMMAND_DENIED");
}

TEST(ActionServiceImpl, armCommandDeniedLandedStateUnknownIsCorrectlyTranslated)
{
const auto rpc_result = armAndGetTranslatedResult(
dronecore::Action::Result::COMMAND_DENIED_LANDED_STATE_UNKNOWN);
EXPECT_EQ(rpc_result, "COMMAND_DENIED_LANDED_STATE_UNKNOWN");
}

TEST(ActionServiceImpl, armCommandDeniedNotLandedIsCorrectlyTranslated)
{
const auto rpc_result = armAndGetTranslatedResult(
dronecore::Action::Result::COMMAND_DENIED_NOT_LANDED);
EXPECT_EQ(rpc_result, "COMMAND_DENIED_NOT_LANDED");
}

TEST(ActionServiceImpl, armTimeoutIsCorrectlyTranslated)
{
const auto rpc_result = armAndGetTranslatedResult(dronecore::Action::Result::TIMEOUT);
EXPECT_EQ(rpc_result, "TIMEOUT");
}

TEST(ActionServiceImpl, armVTOLTransitionSupportUnknownIsCorrectlyTranslated)
{
const auto rpc_result = armAndGetTranslatedResult(
dronecore::Action::Result::VTOL_TRANSITION_SUPPORT_UNKNOWN);
EXPECT_EQ(rpc_result, "VTOL_TRANSITION_SUPPORT_UNKNOWN");
}

TEST(ActionServiceImpl, armNoVTOLTransitionSupportIsCorrectlyTranslated)
{
const auto rpc_result = armAndGetTranslatedResult(
dronecore::Action::Result::NO_VTOL_TRANSITION_SUPPORT);
EXPECT_EQ(rpc_result, "NO_VTOL_TRANSITION_SUPPORT");
}

TEST(ActionServiceImpl, armUnknownIsCorrectlyTranslated)
{
const auto rpc_result = armAndGetTranslatedResult(dronecore::Action::Result::UNKNOWN);
EXPECT_EQ(rpc_result, "UNKNOWN");
}

TEST(ActionServiceImpl, takeoffSuccessIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(dronecore::Action::Result::SUCCESS);
EXPECT_EQ(rpc_result, "SUCCESS");
const auto rpc_result = takeoffAndGetTranslatedResult(GetParam().second);
EXPECT_EQ(rpc_result, GetParam().first);
}

std::string takeoffAndGetTranslatedResult(const dronecore::Action::Result takeoff_result)
Expand All @@ -122,76 +62,10 @@ std::string takeoffAndGetTranslatedResult(const dronecore::Action::Result takeof
return ActionResult::Result_Name(response.action_result().result());
}

TEST(ActionServiceImpl, takeoffNoDeviceIsCorrectlyTranslated)
TEST_P(ActionServiceImplTest, landResultIsTranslatedCorrectly)
{
const auto rpc_result = takeoffAndGetTranslatedResult(dronecore::Action::Result::NO_DEVICE);
EXPECT_EQ(rpc_result, "NO_DEVICE");
}

TEST(ActionServiceImpl, takeoffConnectionErrorIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(
dronecore::Action::Result::CONNECTION_ERROR);
EXPECT_EQ(rpc_result, "CONNECTION_ERROR");
}

TEST(ActionServiceImpl, takeoffBusyIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(dronecore::Action::Result::BUSY);
EXPECT_EQ(rpc_result, "BUSY");
}

TEST(ActionServiceImpl, takeoffCommandDeniedIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(
dronecore::Action::Result::COMMAND_DENIED);
EXPECT_EQ(rpc_result, "COMMAND_DENIED");
}

TEST(ActionServiceImpl, takeoffCommandDeniedLandedStateUnknownIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(
dronecore::Action::Result::COMMAND_DENIED_LANDED_STATE_UNKNOWN);
EXPECT_EQ(rpc_result, "COMMAND_DENIED_LANDED_STATE_UNKNOWN");
}

TEST(ActionServiceImpl, takeoffCommandDeniedNotLandedIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(
dronecore::Action::Result::COMMAND_DENIED_NOT_LANDED);
EXPECT_EQ(rpc_result, "COMMAND_DENIED_NOT_LANDED");
}

TEST(ActionServiceImpl, takeoffTimeoutIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(dronecore::Action::Result::TIMEOUT);
EXPECT_EQ(rpc_result, "TIMEOUT");
}

TEST(ActionServiceImpl, takeoffVTOLTransitionSupportUnknownIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(
dronecore::Action::Result::VTOL_TRANSITION_SUPPORT_UNKNOWN);
EXPECT_EQ(rpc_result, "VTOL_TRANSITION_SUPPORT_UNKNOWN");
}

TEST(ActionServiceImpl, takeoffNoVTOLTransitionSupportIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(
dronecore::Action::Result::NO_VTOL_TRANSITION_SUPPORT);
EXPECT_EQ(rpc_result, "NO_VTOL_TRANSITION_SUPPORT");
}

TEST(ActionServiceImpl, takeoffUnknownIsCorrectlyTranslated)
{
const auto rpc_result = takeoffAndGetTranslatedResult(dronecore::Action::Result::UNKNOWN);
EXPECT_EQ(rpc_result, "UNKNOWN");
}

TEST(ActionServiceImpl, landSuccessIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(dronecore::Action::Result::SUCCESS);
EXPECT_EQ(rpc_result, "SUCCESS");
const auto rpc_result = landAndGetTranslatedResult(GetParam().second);
EXPECT_EQ(rpc_result, GetParam().first);
}

std::string landAndGetTranslatedResult(const dronecore::Action::Result land_result)
Expand All @@ -207,68 +81,32 @@ std::string landAndGetTranslatedResult(const dronecore::Action::Result land_resu
return ActionResult::Result_Name(response.action_result().result());
}

TEST(ActionServiceImpl, landNoDeviceIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(dronecore::Action::Result::NO_DEVICE);
EXPECT_EQ(rpc_result, "NO_DEVICE");
}

TEST(ActionServiceImpl, landConnectionErrorIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(
dronecore::Action::Result::CONNECTION_ERROR);
EXPECT_EQ(rpc_result, "CONNECTION_ERROR");
}

TEST(ActionServiceImpl, landBusyIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(dronecore::Action::Result::BUSY);
EXPECT_EQ(rpc_result, "BUSY");
}
INSTANTIATE_TEST_CASE_P(ActionResultCorrespondences,
ActionServiceImplTest,
::testing::ValuesIn(generateInputPairs()));

TEST(ActionServiceImpl, landCommandDeniedIsCorrectlyTranslated)
std::vector<InputPair> generateInputPairs()
{
const auto rpc_result = landAndGetTranslatedResult(
dronecore::Action::Result::COMMAND_DENIED);
EXPECT_EQ(rpc_result, "COMMAND_DENIED");
}
std::vector<InputPair> input_pairs;
input_pairs.push_back(std::make_pair("SUCCESS", dronecore::Action::Result::SUCCESS));
input_pairs.push_back(std::make_pair("NO_DEVICE", dronecore::Action::Result::NO_DEVICE));
input_pairs.push_back(std::make_pair("CONNECTION_ERROR",
dronecore::Action::Result::CONNECTION_ERROR));
input_pairs.push_back(std::make_pair("BUSY", dronecore::Action::Result::BUSY));
input_pairs.push_back(std::make_pair("COMMAND_DENIED", dronecore::Action::Result::COMMAND_DENIED));
input_pairs.push_back(std::make_pair("COMMAND_DENIED_LANDED_STATE_UNKNOWN",
dronecore::Action::Result::COMMAND_DENIED_LANDED_STATE_UNKNOWN));
input_pairs.push_back(std::make_pair("COMMAND_DENIED_NOT_LANDED",
dronecore::Action::Result::COMMAND_DENIED_NOT_LANDED));
input_pairs.push_back(std::make_pair("TIMEOUT", dronecore::Action::Result::TIMEOUT));
input_pairs.push_back(std::make_pair("VTOL_TRANSITION_SUPPORT_UNKNOWN",
dronecore::Action::Result::VTOL_TRANSITION_SUPPORT_UNKNOWN));
input_pairs.push_back(std::make_pair("NO_VTOL_TRANSITION_SUPPORT",
dronecore::Action::Result::NO_VTOL_TRANSITION_SUPPORT));
input_pairs.push_back(std::make_pair("UNKNOWN", dronecore::Action::Result::UNKNOWN));

TEST(ActionServiceImpl, landCommandDeniedLandedStateUnknownIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(
dronecore::Action::Result::COMMAND_DENIED_LANDED_STATE_UNKNOWN);
EXPECT_EQ(rpc_result, "COMMAND_DENIED_LANDED_STATE_UNKNOWN");
return input_pairs;
}

TEST(ActionServiceImpl, landCommandDeniedNotLandedIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(
dronecore::Action::Result::COMMAND_DENIED_NOT_LANDED);
EXPECT_EQ(rpc_result, "COMMAND_DENIED_NOT_LANDED");
}

TEST(ActionServiceImpl, landTimeoutIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(dronecore::Action::Result::TIMEOUT);
EXPECT_EQ(rpc_result, "TIMEOUT");
}

TEST(ActionServiceImpl, landVTOLTransitionSupportUnknownIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(
dronecore::Action::Result::VTOL_TRANSITION_SUPPORT_UNKNOWN);
EXPECT_EQ(rpc_result, "VTOL_TRANSITION_SUPPORT_UNKNOWN");
}

TEST(ActionServiceImpl, landNoVTOLTransitionSupportIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(
dronecore::Action::Result::NO_VTOL_TRANSITION_SUPPORT);
EXPECT_EQ(rpc_result, "NO_VTOL_TRANSITION_SUPPORT");
}

TEST(ActionServiceImpl, landUnknownIsCorrectlyTranslated)
{
const auto rpc_result = landAndGetTranslatedResult(dronecore::Action::Result::UNKNOWN);
EXPECT_EQ(rpc_result, "UNKNOWN");
}
} // namespace

0 comments on commit af73e85

Please sign in to comment.