fb2c083551
Validate / build-test (macos-latest) (push) Failing after 3s
Validate / build-test (windows-latest) (push) Failing after 15s
Validate / build-test (ubuntu-latest) (push) Successful in 17s
Validate / reports (push) Successful in 50s
Release / release (push) Successful in 50s
Phase 2 of the English translation: Word documents (filled, EPB-specific): - 8 plans (PID, PM, QA, SWE, Test, Project Manual, CM, RM) - 6 safety docs (HARA, Safety Case, FMEDA, MISRA Compliance, Verification Report, Tool Qualification Cppcheck) - 2 manuals (User, Service) - 3 audit artefacts (Review minutes, NC-001, MISRA-REC-001) - All regenerated via pandoc from English markdown sources Code, tests, headers: - All file headers, struct comments, function docstrings in English - All test names (TEST_BEGIN strings) translated - Inline comments translated - 46 tests still green after translation CI workflows: - All step names in English - Step descriptions, comments, release notes template in English README.md fully rewritten in English with proper guided tour. Phase 3 (still pending): dev-process repo templates + toolstack/setup docs.
92 lines
2.4 KiB
C
92 lines
2.4 KiB
C
/**
|
|
* @file test_switch_debouncer.c
|
|
* @brief Unit tests for the Switch Debouncer.
|
|
*
|
|
* @reqs SWE-025
|
|
* @arch SWA-006
|
|
*/
|
|
#include "../unit_test_framework.h"
|
|
#include "../../src/switch_debouncer.h"
|
|
|
|
TestStats g_test_stats = {0, 0};
|
|
|
|
static SwitchRaw mk(bool apply, bool release)
|
|
{
|
|
SwitchRaw r = {0};
|
|
r.apply_raw = apply ? 1U : 0U;
|
|
r.release_raw = release ? 1U : 0U;
|
|
return r;
|
|
}
|
|
|
|
static void test_init_state_is_neutral(void)
|
|
{
|
|
TEST_BEGIN("init -> neutral");
|
|
(void)switch_init();
|
|
ASSERT_EQ(switch_get_state(), SWITCH_NEUTRAL);
|
|
TEST_END();
|
|
}
|
|
|
|
static void test_debounce_apply_takes_5_samples(void)
|
|
{
|
|
TEST_BEGIN("apply needs 5 stable samples (50 ms)");
|
|
(void)switch_init();
|
|
for (int i = 0; i < 4; ++i) {
|
|
switch_step_10ms(mk(true, false));
|
|
ASSERT_EQ(switch_get_state(), SWITCH_NEUTRAL);
|
|
}
|
|
switch_step_10ms(mk(true, false));
|
|
ASSERT_EQ(switch_get_state(), SWITCH_APPLY);
|
|
TEST_END();
|
|
}
|
|
|
|
static void test_debounce_release_takes_5_samples(void)
|
|
{
|
|
TEST_BEGIN("release needs 5 stable samples (50 ms)");
|
|
(void)switch_init();
|
|
for (int i = 0; i < 5; ++i) {
|
|
switch_step_10ms(mk(false, true));
|
|
}
|
|
ASSERT_EQ(switch_get_state(), SWITCH_RELEASE);
|
|
TEST_END();
|
|
}
|
|
|
|
static void test_bounce_does_not_change_state(void)
|
|
{
|
|
TEST_BEGIN("bouncing input keeps current state");
|
|
(void)switch_init();
|
|
for (int i = 0; i < 5; ++i) {
|
|
switch_step_10ms(mk(true, false));
|
|
}
|
|
ASSERT_EQ(switch_get_state(), SWITCH_APPLY);
|
|
/* Bounce: 1 sample apply, 1 sample neutral, 1 sample release ... */
|
|
switch_step_10ms(mk(true, false));
|
|
switch_step_10ms(mk(false, false));
|
|
switch_step_10ms(mk(false, true));
|
|
switch_step_10ms(mk(true, false));
|
|
switch_step_10ms(mk(false, false));
|
|
ASSERT_EQ(switch_get_state(), SWITCH_APPLY);
|
|
TEST_END();
|
|
}
|
|
|
|
static void test_both_pressed_is_neutral(void)
|
|
{
|
|
TEST_BEGIN("both apply+release pressed -> neutral");
|
|
(void)switch_init();
|
|
for (int i = 0; i < 5; ++i) {
|
|
switch_step_10ms(mk(true, true));
|
|
}
|
|
ASSERT_EQ(switch_get_state(), SWITCH_NEUTRAL);
|
|
TEST_END();
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
printf("== test_switch_debouncer ==\n");
|
|
test_init_state_is_neutral();
|
|
test_debounce_apply_takes_5_samples();
|
|
test_debounce_release_takes_5_samples();
|
|
test_bounce_does_not_change_state();
|
|
test_both_pressed_is_neutral();
|
|
TEST_SUMMARY();
|
|
}
|