fix/134-testing-issues #27
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"relay_chn.h": "c"
|
||||
}
|
||||
},
|
||||
"idf.port": "/dev/ttyUSB0"
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
# Create a component for test component
|
||||
idf_component_register(SRCS_DIRS "."
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES unity relay_chn)
|
||||
REQUIRES unity relay_chn)
|
||||
|
||||
# Mark this as a test component
|
||||
# 'relay_chn' is the name of the main component.
|
||||
idf_build_set_property(TEST_COMPONENTS "relay_chn" APPEND)
|
||||
@@ -8,14 +8,30 @@ const gpio_num_t gpio_map[] = {GPIO_NUM_4, GPIO_NUM_5, GPIO_NUM_18, GPIO_NUM_19}
|
||||
const uint8_t gpio_count = sizeof(gpio_map) / sizeof(gpio_map[0]);
|
||||
const uint8_t relay_chn_count = gpio_count / 2;
|
||||
|
||||
TEST_CASE("relay chn inits correctly", "[relay_chn]")
|
||||
{
|
||||
|
||||
void setUp(void) {
|
||||
// Her testten önce çalışacak kod
|
||||
// relay_chn_create'i burada çağırarak her testin temiz bir başlangıç yapmasını sağlayalım.
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
// Tüm röleleri başlangıçta durdur (temiz bir durum için)
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
relay_chn_stop(i);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); // Rölelerin stabilize olması için kısa bir gecikme
|
||||
}
|
||||
|
||||
void tearDown(void) {
|
||||
// Her testten sonra çalışacak kod (isteğe bağlı, genellikle cleanup için)
|
||||
// Örneğin, GPIO'ları de-initialize edebilirsin, ama relay_chn'in buna ihtiyacı yoksa boş bırakabilirsin.
|
||||
// Ancak her test sonunda tüm rölelerin kapalı olduğundan emin olmak iyi bir pratik.
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
relay_chn_stop(i);
|
||||
}
|
||||
vTaskDelay(pdMS_to_TICKS(100));
|
||||
}
|
||||
|
||||
TEST_CASE("Relay channels run forward and update state", "[relay_chn][forward]")
|
||||
{
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
// Test forward run on all channels
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state(i));
|
||||
@@ -35,7 +51,6 @@ TEST_CASE("Relay channels run forward and update state", "[relay_chn][forward]")
|
||||
|
||||
TEST_CASE("Relay channels run reverse and update state", "[relay_chn][reverse]")
|
||||
{
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
// Test reverse run on all channels
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state(i));
|
||||
@@ -63,15 +78,16 @@ static void check_channels_state_unchanged(void)
|
||||
|
||||
TEST_CASE("Relay channels do not change state for invalid channel", "[relay_chn][invalid]")
|
||||
{
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
// Test invalid channel run
|
||||
relay_chn_run_forward(relay_chn_count + 1); // Run the channel forward
|
||||
// Test invalid channel run
|
||||
relay_chn_run_forward(relay_chn_count); // İlk geçersiz kanal (index out of bounds)
|
||||
check_channels_state_unchanged(); // Tüm geçerli kanalların durumu değişmemeli
|
||||
|
||||
relay_chn_run_reverse(relay_chn_count);
|
||||
check_channels_state_unchanged();
|
||||
relay_chn_run_reverse(relay_chn_count + 1); // Run the channel reverse
|
||||
|
||||
relay_chn_stop(relay_chn_count);
|
||||
check_channels_state_unchanged();
|
||||
relay_chn_stop(relay_chn_count + 1); // Stop the channel
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state(relay_chn_count + 1));
|
||||
check_channels_state_unchanged();
|
||||
relay_chn_flip_direction(relay_chn_count + 1); // Flip the direction
|
||||
|
||||
relay_chn_flip_direction(relay_chn_count);
|
||||
check_channels_state_unchanged();
|
||||
}
|
||||
Reference in New Issue
Block a user