Commit 0df22f80 authored by Dominic Clifton's avatar Dominic Clifton
Browse files

Remove some test duplication in RcControls unit rest by using test

fixture classes.
parent dcc54a9a
......@@ -48,13 +48,18 @@ extern "C" {
extern void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions, escAndServoConfig_t *escAndServoConfig, pidProfile_t *pidProfile);
}
TEST(RcControlsTest, updateActivatedModesWithAllInputsAtMidde)
{
// given
class RcControlsModesTest : public ::testing::Test {
protected:
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
memset(&modeActivationConditions, 0, sizeof(modeActivationConditions));
// and
virtual void SetUp() {
memset(&modeActivationConditions, 0, sizeof(modeActivationConditions));
}
};
TEST_F(RcControlsModesTest, updateActivatedModesWithAllInputsAtMidde)
{
// given
rcModeActivationMask = 0;
// and
......@@ -79,12 +84,9 @@ TEST(RcControlsTest, updateActivatedModesWithAllInputsAtMidde)
}
}
TEST(RcControlsTest, updateActivatedModesUsingValidAuxConfigurationAndRXValues)
TEST_F(RcControlsModesTest, updateActivatedModesUsingValidAuxConfigurationAndRXValues)
{
// given
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
memset(&modeActivationConditions, 0, sizeof(modeActivationConditions));
modeActivationConditions[0].modeId = (boxId_e)0;
modeActivationConditions[0].auxChannelIndex = AUX1 - NON_AUX_CHANNEL_COUNT;
modeActivationConditions[0].range.startStep = CHANNEL_VALUE_TO_STEP(1700);
......@@ -232,7 +234,20 @@ static const adjustmentConfig_t rateAdjustmentConfig = {
.data = { { 1 } }
};
TEST(RcControlsTest, processRcAdjustmentsSticksInMiddle)
class RcControlsAdjustmentsTest : public ::testing::Test {
protected:
virtual void SetUp() {
adjustmentStateMask = 0;
memset(&adjustmentStates, 0, sizeof(adjustmentStates));
memset(&rxConfig, 0, sizeof (rxConfig));
rxConfig.mincheck = DEFAULT_MIN_CHECK;
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
rxConfig.midrc = 1500;
}
};
TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsSticksInMiddle)
{
// given
controlRateConfig_t controlRateConfig = {
......@@ -246,13 +261,6 @@ TEST(RcControlsTest, processRcAdjustmentsSticksInMiddle)
};
// and
memset(&rxConfig, 0, sizeof (rxConfig));
rxConfig.mincheck = DEFAULT_MIN_CHECK;
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
rxConfig.midrc = 1500;
adjustmentStateMask = 0;
memset(&adjustmentStates, 0, sizeof(adjustmentStates));
configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &rateAdjustmentConfig);
// and
......@@ -275,7 +283,7 @@ TEST(RcControlsTest, processRcAdjustmentsSticksInMiddle)
EXPECT_EQ(adjustmentStateMask, 0);
}
TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
TEST_F(RcControlsAdjustmentsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
{
// given
controlRateConfig_t controlRateConfig = {
......@@ -289,14 +297,6 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
};
// and
memset(&rxConfig, 0, sizeof (rxConfig));
rxConfig.mincheck = DEFAULT_MIN_CHECK;
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
rxConfig.midrc = 1500;
// and
adjustmentStateMask = 0;
memset(&adjustmentStates, 0, sizeof(adjustmentStates));
configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &rateAdjustmentConfig);
// and
......@@ -441,7 +441,7 @@ static const adjustmentConfig_t rateProfileAdjustmentConfig = {
.data = { { 3 } }
};
TEST(RcControlsTest, processRcRateProfileAdjustments)
TEST_F(RcControlsAdjustmentsTest, processRcRateProfileAdjustments)
{
// given
controlRateConfig_t controlRateConfig = {
......@@ -454,15 +454,6 @@ TEST(RcControlsTest, processRcRateProfileAdjustments)
.tpa_breakpoint = 0
};
// and
memset(&rxConfig, 0, sizeof (rxConfig));
rxConfig.mincheck = DEFAULT_MIN_CHECK;
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
rxConfig.midrc = 1500;
adjustmentStateMask = 0;
memset(&adjustmentStates, 0, sizeof(adjustmentStates));
int adjustmentIndex = 3;
configureAdjustment(adjustmentIndex, AUX4 - NON_AUX_CHANNEL_COUNT, &rateProfileAdjustmentConfig);
......@@ -528,7 +519,7 @@ static const adjustmentConfig_t pidYawDAdjustmentConfig = {
.data = { { 1 } }
};
TEST(RcControlsTest, processPIDIncreasePidController0)
TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController0)
{
// given
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
......@@ -554,15 +545,6 @@ TEST(RcControlsTest, processPIDIncreasePidController0)
controlRateConfig_t controlRateConfig;
memset(&controlRateConfig, 0, sizeof (controlRateConfig));
// and
memset(&rxConfig, 0, sizeof (rxConfig));
rxConfig.mincheck = DEFAULT_MIN_CHECK;
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
rxConfig.midrc = 1500;
adjustmentStateMask = 0;
memset(&adjustmentStates, 0, sizeof(adjustmentStates));
configureAdjustment(0, AUX1 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollPAdjustmentConfig);
configureAdjustment(1, AUX2 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollIAdjustmentConfig);
configureAdjustment(2, AUX3 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollDAdjustmentConfig);
......@@ -614,7 +596,7 @@ TEST(RcControlsTest, processPIDIncreasePidController0)
EXPECT_EQ(28, pidProfile.D8[YAW]);
}
TEST(RcControlsTest, processPIDIncreasePidController2)
TEST_F(RcControlsAdjustmentsTest, processPIDIncreasePidController2)
{
// given
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
......@@ -640,15 +622,6 @@ TEST(RcControlsTest, processPIDIncreasePidController2)
controlRateConfig_t controlRateConfig;
memset(&controlRateConfig, 0, sizeof (controlRateConfig));
// and
memset(&rxConfig, 0, sizeof (rxConfig));
rxConfig.mincheck = DEFAULT_MIN_CHECK;
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
rxConfig.midrc = 1500;
adjustmentStateMask = 0;
memset(&adjustmentStates, 0, sizeof(adjustmentStates));
configureAdjustment(0, AUX1 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollPAdjustmentConfig);
configureAdjustment(1, AUX2 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollIAdjustmentConfig);
configureAdjustment(2, AUX3 - NON_AUX_CHANNEL_COUNT, &pidPitchAndRollDAdjustmentConfig);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment