Skip to content

Commit

Permalink
fix: allow controller setting integer to have a native range
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Sep 15, 2024
1 parent 4cd65ab commit cb4059c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/controllers/legacycontrollersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,16 @@ class LegacyControllerNumberSetting
/// and a strictly positive step, strictly less than max..
/// @return true if valid
bool valid() const override {
static constexpr bool typeSize = sizeof(long) == sizeof(int);
return AbstractLegacyControllerSetting::valid() &&
m_defaultValue >= m_minValue && m_savedValue >= m_minValue &&
m_editedValue >= m_minValue && m_defaultValue <= m_maxValue &&
m_savedValue <= m_maxValue && m_editedValue <= m_maxValue &&
m_stepValue > 0 && m_stepValue < m_maxValue;
m_stepValue > 0 &&
(typeSize ||
static_cast<long>(m_stepValue) <
static_cast<long>(m_maxValue) -
static_cast<long>(m_minValue));
}

static AbstractLegacyControllerSetting* createFrom(const QDomElement& element) {
Expand Down
35 changes: 35 additions & 0 deletions src/test/controller_mapping_settings_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,38 @@ TEST_F(LegacyControllerMappingSettingsTest, discardDuplicateSettings) {
ASSERT_EQ(settings.at(1)->value().toNumber(), 50);
ASSERT_EQ(settings.at(2)->value().toString(), "myOptionValue1");
}

TEST_F(LegacyControllerMappingSettingsTest, handleNumberWithNegativeRange) {
QDomDocument doc;
QString dom;
QTextStream(&dom)
<< QString(kValidInteger).arg("0", "-500", "0", "1");
doc.setContent(
QString("<?xml version=\"1.0\" "
"encoding=\"utf-8\"?><MixxxControllerPreset><settings>%1</"
"settings></MixxxControllerPreset>")
.arg(dom));

auto pMapping = LegacyDummyMappingFileHandler::loadDummyMapping(
doc.documentElement(), "/fake/path");

ASSERT_EQ(pMapping->getSettings().size(), 1);
ASSERT_EQ(pMapping->getSettings().at(0)->variableName(), "myInteger1");
ASSERT_EQ(pMapping->getSettings().at(0)->value().toNumber(), 0);

dom.clear();
QTextStream(&dom)
<< QString(kValidInteger).arg("20", "-100", "100", "50");
doc.setContent(
QString("<?xml version=\"1.0\" "
"encoding=\"utf-8\"?><MixxxControllerPreset><settings>%1</"
"settings></MixxxControllerPreset>")
.arg(dom));

pMapping = LegacyDummyMappingFileHandler::loadDummyMapping(
doc.documentElement(), "/fake/path");

ASSERT_EQ(pMapping->getSettings().size(), 1);
ASSERT_EQ(pMapping->getSettings().at(0)->variableName(), "myInteger1");
ASSERT_EQ(pMapping->getSettings().at(0)->value().toNumber(), 20);
}

0 comments on commit cb4059c

Please sign in to comment.