Adding unit test for updateRcOptions
This commit is contained in:
parent
5b3d86e966
commit
ca72890964
File diff suppressed because it is too large
Load Diff
|
@ -20,6 +20,7 @@
|
|||
#define PWM_RANGE_ZERO 0 // FIXME should all usages of this be changed to use PWM_RANGE_MIN?
|
||||
#define PWM_RANGE_MIN 1000
|
||||
#define PWM_RANGE_MAX 2000
|
||||
#define PWM_RANGE_MIDDLE ((PWM_RANGE_MAX - PWM_RANGE_MIN) / 2)
|
||||
|
||||
#define DEFAULT_SERVO_MIN 1020
|
||||
#define DEFAULT_SERVO_MIDDLE 1500
|
||||
|
|
|
@ -33,7 +33,7 @@ CXXFLAGS += -g -Wall -Wextra -pthread -ggdb -O0
|
|||
|
||||
# All tests produced by this Makefile. Remember to add new tests you
|
||||
# created to the list.
|
||||
TESTS = battery_unittest flight_imu_unittest gps_conversion_unittest telemetry_hott_unittest
|
||||
TESTS = battery_unittest flight_imu_unittest gps_conversion_unittest telemetry_hott_unittest rc_controls_unittest
|
||||
|
||||
# All Google Test headers. Usually you shouldn't change this
|
||||
# definition.
|
||||
|
@ -137,3 +137,19 @@ $(OBJECT_DIR)/telemetry_hott_unittest.o : $(TEST_DIR)/telemetry_hott_unittest.cc
|
|||
|
||||
telemetry_hott_unittest :$(OBJECT_DIR)/telemetry/hott.o $(OBJECT_DIR)/telemetry_hott_unittest.o $(OBJECT_DIR)/flight/gps_conversion.o $(OBJECT_DIR)/gtest_main.a
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $(OBJECT_DIR)/$@
|
||||
|
||||
|
||||
|
||||
$(OBJECT_DIR)/io/rc_controls.o : $(USER_DIR)/io/rc_controls.c $(USER_DIR)/io/rc_controls.h $(GTEST_HEADERS)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/io/rc_controls.c -o $@
|
||||
|
||||
$(OBJECT_DIR)/rc_controls_unittest.o : $(TEST_DIR)/rc_controls_unittest.cc \
|
||||
$(USER_DIR)/io/rc_controls.h $(GTEST_HEADERS)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/rc_controls_unittest.cc -o $@
|
||||
|
||||
rc_controls_unittest :$(OBJECT_DIR)/io/rc_controls.o $(OBJECT_DIR)/rc_controls_unittest.o $(OBJECT_DIR)/gtest_main.a
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $(OBJECT_DIR)/$@
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "common/axis.h"
|
||||
#include "flight/flight.h"
|
||||
|
||||
#include "rx/rx.h"
|
||||
#include "io/rc_controls.h"
|
||||
|
||||
#include "unittest_macros.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
#define NON_AUX_CHANNEL_COUNT 4
|
||||
|
||||
TEST(RcControlsTest, updateRcOptionsWithAllInputsAtMidde)
|
||||
{
|
||||
// given
|
||||
uint32_t activate[CHECKBOX_ITEM_COUNT];
|
||||
memset(&activate, 0, sizeof(activate));
|
||||
|
||||
uint8_t index;
|
||||
|
||||
for (index = 0; index < CHECKBOX_ITEM_COUNT; index++) {
|
||||
rcOptions[index] = 0;
|
||||
}
|
||||
|
||||
// and
|
||||
memset(&rxRuntimeConfig, 0, sizeof(rxRuntimeConfig_t));
|
||||
rxRuntimeConfig.auxChannelCount = MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT;
|
||||
|
||||
// and
|
||||
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT; index++) {
|
||||
rcData[index] = PWM_RANGE_MIDDLE;
|
||||
}
|
||||
|
||||
|
||||
// and
|
||||
uint32_t expectedRcOptions[CHECKBOX_ITEM_COUNT];
|
||||
memset(&expectedRcOptions, 0, sizeof(expectedRcOptions));
|
||||
|
||||
// when
|
||||
updateRcOptions(activate);
|
||||
|
||||
// then
|
||||
for (index = 0; index < CHECKBOX_ITEM_COUNT; index++) {
|
||||
printf("iteration: %d\n", index);
|
||||
EXPECT_EQ(expectedRcOptions[index], rcOptions[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void changeProfile(uint8_t profileIndex) {}
|
||||
void accSetCalibrationCycles(uint16_t) {}
|
||||
void gyroSetCalibrationCycles(uint16_t) {}
|
||||
void applyAndSaveAccelerometerTrimsDelta(rollAndPitchTrims_t*) {}
|
||||
void handleInflightCalibrationStickPosition(void) {}
|
||||
void mwArm(void) {}
|
||||
void feature(uint32_t) {}
|
||||
void sensors(uint32_t) {}
|
||||
void mwDisarm(void) {}
|
||||
|
||||
uint8_t armingFlags = 0;
|
||||
int16_t heading;
|
||||
uint8_t stateFlags = 0;
|
||||
int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT];
|
||||
rxRuntimeConfig_t rxRuntimeConfig;
|
Loading…
Reference in New Issue