More unit tests and unified target for all tests (#6661)

* added general settings tests

* fixed pre-219 switchUnlockState (CPN)

* X7 radio settings tests

* updated X10 model

* patched TESTS_PATH to point directly at the complete tests path

* fixed horus general settings switch conversion

* cpn x10 general settings tests

* fixed horus cpn import

* use x10 model from otx file to ease editing with companion

* added make targets "gtests" and "tests"

gtests builds all the tests (radio & companion)
tests builds and executes all the tests (radio & companion)

* fixed companion tests cmake

* fixed gtests-radio target

* fixed commit tests

* fixed converting LS & RS on X10

* fixed converting global functions on X10

* fixed source conversion on X10

* fixed throttle source on X10

* fixed throttle source on radio and companion

* more checks and re-enabled Horus screenData copy

* more tests (X10)

* [X10] restore correct direction for RS & LS

* [horus] convert "Value" widget source

* fixed conversion of ModelHeader::bitmap length

* added missing X10 radio tests to companion tests

* fixed conversion of telemetry sources in logical switches

* [horus] fixed potential crash

* fixed "AND switch" conversion in logical switches
This commit is contained in:
Raphael Coeffic
2019-08-26 08:36:31 +02:00
committed by Bertrand Songis
parent 274528ee1d
commit 5db30ea7bc
19 changed files with 340 additions and 105 deletions
+34 -15
View File
@@ -40,7 +40,13 @@ inline int MAX_SWITCHES(Board::Type board, int version)
return Boards::getCapability(board, Board::Switches);
}
#define MAX_KNOBS(board, version) (IS_HORUS(board) ? 8 : 4)
inline int MAX_KNOBS(Board::Type board, int version)
{
if (version >= 219 && IS_HORUS(board))
return 8;
return 4;
}
inline int MAX_POTS(Board::Type board, int version)
{
@@ -56,6 +62,14 @@ inline int MAX_POTS_STORAGE(Board::Type board, int version)
return Boards::getCapability(board, Board::PotsStorage);
}
inline int MAX_SLIDERS_SLOTS(Board::Type board, int version)
{
if (version >= 219 && IS_HORUS(board))
return 8;
return 4;
}
// bitsize of swconfig_t / 2 (see radio/src/datastructs.h)
inline int MAX_SWITCH_SLOTS(Board::Type board, int version)
{
@@ -254,8 +268,13 @@ class SourcesConversionTable: public ConversionTable {
}
}
for (int i=0; i<CPN_MAX_STICKS+MAX_POTS(board,version)+Boards::getCapability(board, Board::SlidersStorage)+Boards::getCapability(board, Board::MouseAnalogs)+MAX_GYRO_ANALOGS(board, version); i++) {
addConversion(RawSource(SOURCE_TYPE_STICK, i), val++);
for (int i=0; i<CPN_MAX_STICKS+MAX_POTS_STORAGE(board, version)+Boards::getCapability(board, Board::SlidersStorage)+Boards::getCapability(board, Board::MouseAnalogs)+MAX_GYRO_ANALOGS(board, version); i++) {
int offset = 0;
if (version <= 218 && IS_HORUS(board) && i>=CPN_MAX_STICKS+MAX_POTS_STORAGE(board, version))
offset += 2;
addConversion(RawSource(SOURCE_TYPE_STICK, i + offset), val++);
}
for (int i=0; i<MAX_ROTARY_ENCODERS(board); i++) {
@@ -2475,6 +2494,9 @@ void OpenTxModelData::afterImport()
}
modelData.switchWarningStates = newSwitchWarningStates;
}
if (version <= 218 && IS_HORUS_X10(board) && modelData.thrTraceSrc > 3)
modelData.thrTraceSrc += 2;
}
OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type board, unsigned int version, unsigned int variant):
@@ -2639,7 +2661,7 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type
if (IS_STM32(board)) {
if (version >= 218) {
internalField.Append(new UnsignedField<4>(this, generalData.hw_uartMode));
if (!IS_HORUS(board)) {
if (!IS_HORUS(board) || version < 219) {
for (uint8_t i=0; i<4; i++) {
internalField.Append(new UnsignedField<1>(this, generalData.sliderConfig[i]));
}
@@ -2669,17 +2691,18 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type
}
for (int i=0; i<MAX_KNOBS(board, version); i++) {
int offset = 0;
// 2 new pots for Horus from 219 on
if (version <= 218 && IS_HORUS(board) && (i == 3))
i += 2;
if (version <= 218 && IS_HORUS(board) && (i >= 3))
offset += 2;
if (i < Boards::getCapability(board, Board::PotsStorage))
internalField.Append(new UnsignedField<2>(this, generalData.potConfig[i]));
internalField.Append(new UnsignedField<2>(this, generalData.potConfig[i+offset]));
else
internalField.Append(new SpareBitsField<2>(this));
}
if (IS_HORUS(board)) {
for (int i=0; i<8; i++) {
if (IS_HORUS(board) && version >= 219) {
for (int i=0; i<MAX_SLIDERS_SLOTS(board,version); i++) {
if (i < Boards::getCapability(board, Board::SlidersStorage))
internalField.Append(new UnsignedField<1>(this, generalData.sliderConfig[i]));
else
@@ -2703,7 +2726,7 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type
if (IS_TARANIS_X9E(board))
internalField.Append(new SpareBitsField<64>(this)); // switchUnlockStates
else if (IS_TARANIS_X9D(board))
else if (version >= 219 && IS_TARANIS_X9D(board))
internalField.Append(new SpareBitsField<32>(this)); // switchUnlockStates
else if (IS_TARANIS(board))
internalField.Append(new SpareBitsField<16>(this)); // switchUnlockStates
@@ -2721,11 +2744,7 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type
for (int i=0; i<CPN_MAX_STICKS; ++i) {
internalField.Append(new ZCharField<3>(this, generalData.stickName[i], "Stick name"));
}
for (int i=0; i<Boards::getCapability(board, Board::PotsStorage); ++i) {
if (version <= 218 && IS_HORUS(board) && (i == 3)) {
// skip not yet existing pots (EXT1 / EXT2 for X10)
i += 2;
}
for (int i=0; i<MAX_POTS_STORAGE(board, version); ++i) {
internalField.Append(new ZCharField<3>(this, generalData.potName[i], "Pot name"));
}
for (int i=0; i<Boards::getCapability(board, Board::SlidersStorage); ++i) {
+13 -7
View File
@@ -1184,7 +1184,7 @@ void SetupPanel::on_trimIncrement_currentIndexChanged(int index)
void SetupPanel::on_throttleSource_currentIndexChanged(int index)
{
if (!lock) {
model->thrTraceSrc = index;
model->thrTraceSrc = ui->throttleSource->currentData().toUInt();
emit modified();
}
}
@@ -1244,14 +1244,20 @@ void SetupPanel::populateThrottleSourceCB()
Board::Type board = firmware->getBoard();
lock = true;
ui->throttleSource->clear();
ui->throttleSource->addItem(tr("THR"));
for (int i=0; i<getBoardCapability(board, Board::Pots)+getBoardCapability(board, Board::Sliders); i++) {
ui->throttleSource->addItem(firmware->getAnalogInputName(4+i), i);
ui->throttleSource->addItem(tr("THR"), 0);
int idx=1;
for (int i=0; i<getBoardCapability(board, Board::Pots)+getBoardCapability(board, Board::Sliders); i++, idx++) {
if (RawSource(SOURCE_TYPE_STICK,4+i).isAvailable(model,&generalSettings,board)) {
ui->throttleSource->addItem(firmware->getAnalogInputName(4+i), idx);
}
}
for (int i=0; i<firmware->getCapability(Outputs); i++) {
ui->throttleSource->addItem(RawSource(SOURCE_TYPE_CH, i).toString(model, &generalSettings));
for (int i=0; i<firmware->getCapability(Outputs); i++, idx++) {
ui->throttleSource->addItem(RawSource(SOURCE_TYPE_CH, i).toString(model, &generalSettings), idx);
}
ui->throttleSource->setCurrentIndex(model->thrTraceSrc);
int thrTraceSrcIdx = ui->throttleSource->findData(model->thrTraceSrc);
ui->throttleSource->setCurrentIndex(thrTraceSrcIdx);
lock = false;
}
+8 -8
View File
@@ -4,8 +4,8 @@ find_path(GTEST_INCDIR gtest/gtest.h HINTS "${GTEST_ROOT}/include" DOC "Path to
find_path(GTEST_SRCDIR src/gtest-all.cc HINTS "${GTEST_ROOT}" "${GTEST_ROOT}/src/gtest" DOC "Path of Google Test 'src' folder.")
if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
add_library(gtests-cpn-lib STATIC EXCLUDE_FROM_ALL ${GTEST_SRCDIR}/src/gtest-all.cc )
target_include_directories(gtests-cpn-lib PUBLIC ${GTEST_INCDIR} ${GTEST_INCDIR}/gtest ${GTEST_SRCDIR})
add_library(gtests-companion-lib STATIC EXCLUDE_FROM_ALL ${GTEST_SRCDIR}/src/gtest-all.cc )
target_include_directories(gtests-companion-lib PUBLIC ${GTEST_INCDIR} ${GTEST_INCDIR}/gtest ${GTEST_SRCDIR})
add_definitions(-DGTESTS)
set(TESTS_PATH ${COMPANION_SRC_DIRECTORY}/tests)
set(RADIO_TESTS_PATH ${RADIO_SRC_DIRECTORY}/tests)
@@ -14,8 +14,8 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(WIN32)
target_include_directories(gtests-cpn-lib PUBLIC ${WIN_INCLUDE_DIRS})
target_link_libraries(gtests-cpn-lib PRIVATE ${WIN_LINK_LIBRARIES})
target_include_directories(gtests-companion-lib PUBLIC ${WIN_INCLUDE_DIRS})
target_link_libraries(gtests-companion-lib PRIVATE ${WIN_LINK_LIBRARIES})
endif(WIN32)
file(GLOB TEST_SRC_FILES ${TESTS_PATH}/*.cpp)
@@ -25,10 +25,10 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND)
use_cxx11() # ensure gnu++11 in CXX_FLAGS with CMake < 3.1
add_executable(gtests-cpn EXCLUDE_FROM_ALL ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h)
add_dependencies(gtests-cpn gtests-cpn-lib)
target_link_libraries(gtests-cpn gtests-cpn-lib pthread Qt5::Core Qt5::Widgets ${CPN_COMMON_LIB})
message(STATUS "Added optional gtests-cpn target")
add_executable(gtests-companion EXCLUDE_FROM_ALL ${TEST_SRC_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/location.h)
add_dependencies(gtests-companion gtests-companion-lib)
target_link_libraries(gtests-companion gtests-companion-lib simulation firmwares storage common)
message(STATUS "Added optional gtests-companion target")
else()
message(WARNING "WARNING: gtests target will not be available (check that GTEST_INCDIR, GTEST_SRCDIR, and Qt5Widgets are configured).")
endif()
+82 -7
View File
@@ -1,7 +1,9 @@
#include "gtests.h"
#include "location.h"
#include "storage/otx.h"
#include "storage/storage.h"
#include "firmwares/opentx/opentxinterface.h"
#include "firmwares/customfunctiondata.h"
TEST(Conversions, ConversionX9DPFrom22)
{
@@ -10,6 +12,16 @@ TEST(Conversions, ConversionX9DPFrom22)
ASSERT_EQ(true, store.load(radioData));
ASSERT_EQ(true, store.load(radioData));
const GeneralSettings& settings = radioData.generalSettings;
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), settings.customFn[0].swtch);
EXPECT_EQ(FuncLogs, settings.customFn[0].func);
EXPECT_EQ(20, settings.customFn[0].param);
EXPECT_STREQ("Tes", settings.switchName[0]);
EXPECT_EQ(Board::SWITCH_3POS, settings.switchConfig[0]);
const ModelData& model = radioData.models[0];
EXPECT_STREQ("Test", model.name);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_SWITCH,SWITCH_SA0), model.timers[0].mode);
@@ -37,6 +49,14 @@ TEST(Conversions, ConversionX7From22)
ASSERT_EQ(true, store.load(radioData));
const GeneralSettings& settings = radioData.generalSettings;
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), settings.customFn[0].swtch);
EXPECT_EQ(FuncLogs, settings.customFn[0].func);
EXPECT_EQ(20, settings.customFn[0].param);
EXPECT_STREQ("Tes", settings.switchName[0]);
EXPECT_EQ(Board::SWITCH_3POS, settings.switchConfig[0]);
const ModelData& model = radioData.models[0];
EXPECT_STREQ("Test", model.name);
EXPECT_EQ(PULSES_PXX_R9M, model.moduleData[1].protocol);
@@ -83,23 +103,77 @@ bool loadFile(QByteArray & filedata, const QString & filename)
return true;
}
TEST(Conversions, ConversionHorusFrom22)
TEST(Conversions, ConversionX10From22)
{
QByteArray modelByteArray;
ASSERT_EQ(true, loadFile(modelByteArray, RADIO_TESTS_PATH "/MODELS/model_22_horus.bin"));
QByteArray byteBuffer;
#define USE_OTX
#if defined(USE_OTX)
OtxFormat otx(RADIO_TESTS_PATH "/model_22_x10.otx");
RadioData radio;
EXPECT_EQ(true, otx.load(radio));
const GeneralSettings& settings = radio.generalSettings;
const ModelData& model = radio.models[0];
#else
ASSERT_EQ(true, loadFile(byteBuffer, RADIO_TESTS_PATH "/model_22_x10/RADIO/radio.bin"));
GeneralSettings settings;
EXPECT_NE(nullptr, loadRadioSettingsFromByteArray(settings, byteBuffer));
#endif
EXPECT_EQ(100, settings.calibSpanNeg[9]);
EXPECT_EQ(500, settings.calibMid[9]);
EXPECT_EQ(900, settings.calibSpanPos[9]);
EXPECT_EQ(200, settings.calibSpanNeg[10]);
EXPECT_EQ(400, settings.calibMid[10]);
EXPECT_EQ(600, settings.calibSpanPos[10]);
EXPECT_EQ(-23, settings.vBatMin);
EXPECT_EQ(20, settings.speakerVolume);
EXPECT_STREQ("en", settings.ttsLanguage);
EXPECT_STREQ("model1.bin", settings.currModelFilename);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), settings.customFn[0].swtch);
EXPECT_EQ(FuncLogs, settings.customFn[0].func);
EXPECT_EQ(20, settings.customFn[0].param);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_ON), settings.customFn[1].swtch);
EXPECT_EQ(FuncVolume, settings.customFn[1].func);
EXPECT_EQ(RawSource(SOURCE_TYPE_STICK,4+5+1).toValue(), settings.customFn[1].param); // RS
EXPECT_STREQ("Tes", settings.switchName[0]);
EXPECT_EQ(Board::SWITCH_3POS, settings.switchConfig[0]);
EXPECT_STREQ("BT_X10", settings.bluetoothName);
EXPECT_STREQ("Default", settings.themeName);
#if !defined(USE_OTX)
byteBuffer.clear();
ASSERT_EQ(true, loadFile(byteBuffer, RADIO_TESTS_PATH "/model_22_x10/MODELS/model1.bin"));
ModelData model;
ASSERT_NE(nullptr, loadModelFromByteArray(model, modelByteArray));
ASSERT_NE(nullptr, loadModelFromByteArray(model, byteBuffer));
#endif
EXPECT_STREQ("Test", model.name);
EXPECT_EQ(0, model.noGlobalFunctions);
EXPECT_EQ(0, model.beepANACenter);
EXPECT_EQ(80, model.mixData[0].weight);
EXPECT_EQ(RawSource(SOURCE_TYPE_PPM,0), model.mixData[4].srcRaw);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), model.mixData[4].swtch);
EXPECT_EQ(RawSource(SOURCE_TYPE_MAX), model.mixData[2].srcRaw); // MAX
EXPECT_EQ(RawSource(SOURCE_TYPE_STICK,4+5), model.mixData[3].srcRaw); // LS
EXPECT_EQ(RawSource(SOURCE_TYPE_PPM,0), model.mixData[5].srcRaw);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_TELEMETRY,1), model.mixData[5].swtch);
EXPECT_EQ(900, model.limitData[0].max); // -100
EXPECT_EQ(80, model.expoData[0].weight);
EXPECT_EQ(LS_FN_VPOS, model.logicalSw[0].func);
EXPECT_EQ(RawSource(SOURCE_TYPE_PPM,0).toValue(), model.logicalSw[0].val1);
EXPECT_EQ(RawSource(SOURCE_TYPE_PPM,0).toValue(), model.logicalSw[0].val1); // TR1
EXPECT_EQ(0, model.logicalSw[0].val2);
EXPECT_EQ(RawSource(SOURCE_TYPE_TELEMETRY,19*3).toValue(), model.logicalSw[1].val1); // TELE:20
EXPECT_EQ(20, model.logicalSw[1].val2);
EXPECT_EQ(RawSwitch(SWITCH_TYPE_VIRTUAL,1).toValue(), model.logicalSw[1].andsw);
EXPECT_EQ(HELI_SWASH_TYPE_120X, model.swashRingData.type);
EXPECT_STREQ("Tes", model.flightModeData[0].name);
EXPECT_EQ(10, model.flightModeData[0].gvars[0]);
@@ -110,4 +184,5 @@ TEST(Conversions, ConversionHorusFrom22)
EXPECT_STREQ("Tes", model.sensorData[0].label);
EXPECT_EQ(10, model.sensorData[0].id);
EXPECT_EQ(9, model.sensorData[0].instance);
EXPECT_EQ(5 + 2 + 3, model.thrTraceSrc); // CH3
}