Property 2.1: Mode-specific operation validity.
Tests that operations succeed only if valid for the pin's configured mode.
79{
81
82
83 const struct {
85 const char* mode_name;
86 bool should_set_succeed;
87 bool should_get_succeed;
88 bool should_toggle_succeed;
89 } test_cases[] = {
96 };
97
98 for (size_t i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
99 uint8_t test_pin = i;
100
101
102 test_state.pin_modes[test_pin] = test_cases[i].mode;
105
107 test_cases[i].mode_name, test_pin);
108
109
111 if (test_cases[i].should_set_succeed) {
114 "FAIL: set_level should succeed for %s mode, got error: %d",
115 test_cases[i].mode_name, set_result);
117 }
118 } else {
121 "FAIL: set_level should fail with MESHX_ERR_GPIO_INVALID_MODE for %s mode, got: %d",
122 test_cases[i].mode_name, set_result);
124 }
125 }
126
127
128 uint8_t level;
130 if (test_cases[i].should_get_succeed) {
133 "FAIL: get_level should succeed for %s mode, got error: %d",
134 test_cases[i].mode_name, get_result);
136 }
137 } else {
140 "FAIL: get_level should fail with MESHX_ERR_GPIO_INVALID_MODE for %s mode, got: %d",
141 test_cases[i].mode_name, get_result);
143 }
144 }
145
146
148 if (test_cases[i].should_toggle_succeed) {
151 "FAIL: toggle should succeed for %s mode, got error: %d",
152 test_cases[i].mode_name, toggle_result);
154 }
155 } else {
158 "FAIL: toggle should fail with MESHX_ERR_GPIO_INVALID_MODE for %s mode, got: %d",
159 test_cases[i].mode_name, toggle_result);
161 }
162 }
163 }
164
167}
meshx_err_t meshx_gpio_get_level(uint8_t logical_pin, uint8_t *level)
Get GPIO pin level.
Definition meshx_gpio.c:392
meshx_err_t meshx_gpio_toggle(uint8_t logical_pin)
Toggle GPIO pin level.
Definition meshx_gpio.c:453
meshx_gpio_mode_t
GPIO Pin Modes.
Definition meshx_gpio.h:28
@ MESHX_GPIO_MODE_INPUT_OUTPUT
Definition meshx_gpio.h:31
@ MESHX_GPIO_MODE_OPEN_DRAIN_INPUT_OUTPUT
Definition meshx_gpio.h:33
@ MESHX_GPIO_MODE_PWM_OUTPUT
Definition meshx_gpio.h:34
@ MESHX_GPIO_MODE_OPEN_DRAIN
Definition meshx_gpio.h:32