Add upper boundary checks for tilt sensitivity settings
The tilt sensitivity values were passed to the NVS module without the boundaries being checked, even though the maximum percent value is 100. This commit fixes this issue. Also test cases are added to cover the upper boundary checks for the tilt sensitivity settings. Fixes #1086
This commit is contained in:
@@ -322,6 +322,35 @@ TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivi
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(expect, vals, CONFIG_RELAY_CHN_COUNT);
|
||||
}
|
||||
|
||||
// Test sensitivity upper boundary for all set functions
|
||||
TEST_CASE("relay_chn_tilt_set_sensitivity functions handle upper boundary", "[relay_chn][tilt][sensitivity]")
|
||||
{
|
||||
// 1. Test relay_chn_tilt_set_sensitivity() for each channel
|
||||
for (uint8_t ch = 0; ch < CONFIG_RELAY_CHN_COUNT; ch++) {
|
||||
relay_chn_tilt_set_sensitivity(ch, 101);
|
||||
TEST_ASSERT_EQUAL_UINT8(100, relay_chn_tilt_get_sensitivity(ch));
|
||||
|
||||
relay_chn_tilt_set_sensitivity(ch, 255);
|
||||
TEST_ASSERT_EQUAL_UINT8(100, relay_chn_tilt_get_sensitivity(ch));
|
||||
}
|
||||
|
||||
// 2. Test relay_chn_tilt_set_sensitivity_all_with()
|
||||
relay_chn_tilt_set_sensitivity_all_with(150);
|
||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
TEST_ASSERT_EQUAL_UINT8(100, relay_chn_tilt_get_sensitivity(i));
|
||||
}
|
||||
|
||||
// 3. Test relay_chn_tilt_set_sensitivity_all()
|
||||
uint8_t sensitivities[CONFIG_RELAY_CHN_COUNT];
|
||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
sensitivities[i] = 100 + i * 10; // Values like 100, 110, 120...
|
||||
}
|
||||
TEST_ESP_OK(relay_chn_tilt_set_sensitivity_all(sensitivities));
|
||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
TEST_ASSERT_EQUAL_UINT8(100, relay_chn_tilt_get_sensitivity(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Test tilt counter logic: forward x3, reverse x3, extra reverse fails
|
||||
TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][tilt][counter]")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user