feat(sacn): Endpunkt zum Einstellen und Statusfeld in system/info

This commit is contained in:
Michael Sauer
2026-09-20 00:24:09 +02:00
parent 882cb55297
commit e892b441ce
3 changed files with 161 additions and 0 deletions
+115
View File
@@ -346,6 +346,113 @@ static void test_settings_name_token_auth(void)
TEST_ASSERT_EQUAL_INT(500, resp.status);
}
/* --- system/settings: sacn --- */
static const cJSON *sacn_field(const char *name)
{
const cJSON *s = cJSON_GetObjectItemCaseSensitive(doc, "sacn");
return cJSON_GetObjectItemCaseSensitive(s, name);
}
static void test_settings_exposes_sacn_block(void)
{
call(NL_HTTP_GET, "/api/v1/system/settings", TOKEN, NULL);
TEST_ASSERT_EQUAL_INT(200, resp.status);
TEST_ASSERT_TRUE(cJSON_IsTrue(sacn_field("enabled")));
TEST_ASSERT_EQUAL_INT(1, (int)cJSON_GetNumberValue(sacn_field("universe")));
TEST_ASSERT_EQUAL_INT(1, (int)cJSON_GetNumberValue(sacn_field("start_slot")));
TEST_ASSERT_EQUAL_STRING("release", cJSON_GetStringValue(sacn_field("on_timeout")));
TEST_ASSERT_EQUAL_INT(6, (int)cJSON_GetNumberValue(sacn_field("slots")));
}
static void test_settings_sacn_block_reflects_stored_values(void)
{
fake_settings.sacn_enabled = 0;
fake_settings.sacn_universe = 12;
fake_settings.sacn_start_slot = 7;
fake_settings.sacn_hold = 1;
call(NL_HTTP_GET, "/api/v1/system/settings", TOKEN, NULL);
TEST_ASSERT_FALSE(cJSON_IsTrue(sacn_field("enabled")));
TEST_ASSERT_EQUAL_INT(12, (int)cJSON_GetNumberValue(sacn_field("universe")));
TEST_ASSERT_EQUAL_INT(7, (int)cJSON_GetNumberValue(sacn_field("start_slot")));
TEST_ASSERT_EQUAL_STRING("hold", cJSON_GetStringValue(sacn_field("on_timeout")));
}
static void test_put_sacn_all_fields(void)
{
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN,
"{\"type\":\"sacn\",\"enabled\":false,\"universe\":300,"
"\"start_slot\":100,\"on_timeout\":\"hold\"}");
TEST_ASSERT_EQUAL_INT(200, resp.status);
TEST_ASSERT_EQUAL_INT(1, fake_save_calls);
TEST_ASSERT_EQUAL_UINT8(0, fake_settings.sacn_enabled);
TEST_ASSERT_EQUAL_UINT16(300, fake_settings.sacn_universe);
TEST_ASSERT_EQUAL_UINT16(100, fake_settings.sacn_start_slot);
TEST_ASSERT_EQUAL_UINT8(1, fake_settings.sacn_hold);
}
static void test_put_sacn_single_field_leaves_rest(void)
{
fake_settings.sacn_universe = 9;
fake_settings.sacn_hold = 1;
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN,
"{\"type\":\"sacn\",\"start_slot\":50}");
TEST_ASSERT_EQUAL_INT(200, resp.status);
TEST_ASSERT_EQUAL_UINT16(50, fake_settings.sacn_start_slot);
TEST_ASSERT_EQUAL_UINT16(9, fake_settings.sacn_universe);
TEST_ASSERT_EQUAL_UINT8(1, fake_settings.sacn_hold);
}
static void test_put_sacn_rejects_bad_values(void)
{
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"sacn\",\"enabled\":\"ja\"}");
TEST_ASSERT_EQUAL_INT(400, resp.status);
TEST_ASSERT_EQUAL_STRING("invalid enabled", error_text());
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"sacn\",\"universe\":0}");
TEST_ASSERT_EQUAL_INT(400, resp.status);
TEST_ASSERT_EQUAL_STRING("invalid universe", error_text());
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"sacn\",\"universe\":64000}");
TEST_ASSERT_EQUAL_STRING("invalid universe", error_text());
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"sacn\",\"start_slot\":0}");
TEST_ASSERT_EQUAL_STRING("invalid start_slot", error_text());
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"sacn\",\"on_timeout\":\"halten\"}");
TEST_ASSERT_EQUAL_STRING("invalid on_timeout", error_text());
TEST_ASSERT_EQUAL_INT(0, fake_save_calls); /* nichts davon darf gespeichert werden */
}
/* Ein Board mit RGB braucht 6 Slots: ab 508 passt der Satz nicht mehr ins Universe. */
static void test_put_sacn_start_slot_must_leave_room_for_all_slots(void)
{
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"sacn\",\"start_slot\":507}");
TEST_ASSERT_EQUAL_INT(200, resp.status);
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"sacn\",\"start_slot\":508}");
TEST_ASSERT_EQUAL_INT(400, resp.status);
TEST_ASSERT_EQUAL_STRING("invalid start_slot", error_text());
}
static void test_put_sacn_start_slot_limit_follows_the_board(void)
{
fake_api_reset("g95_cw"); /* drei Slots: 510 passt noch */
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"sacn\",\"start_slot\":510}");
TEST_ASSERT_EQUAL_INT(200, resp.status);
call(NL_HTTP_PUT, "/api/v1/system/settings", TOKEN, "{\"type\":\"sacn\",\"start_slot\":511}");
TEST_ASSERT_EQUAL_INT(400, resp.status);
}
static void test_info_exposes_sacn_state(void)
{
fake_info.sacn_active = true;
fake_settings.sacn_universe = 5;
call(NL_HTTP_GET, "/api/v1/system/info", NULL, NULL);
TEST_ASSERT_EQUAL_INT(200, resp.status);
TEST_ASSERT_TRUE(cJSON_IsTrue(sacn_field("active")));
TEST_ASSERT_EQUAL_INT(5, (int)cJSON_GetNumberValue(sacn_field("universe")));
}
/* --- system/command --- */
static void test_commands(void)
{
@@ -406,6 +513,14 @@ int main(void)
RUN_TEST(test_settings_wifi_source_reflects_compiled_fallback);
RUN_TEST(test_settings_wifi);
RUN_TEST(test_settings_name_token_auth);
RUN_TEST(test_settings_exposes_sacn_block);
RUN_TEST(test_settings_sacn_block_reflects_stored_values);
RUN_TEST(test_put_sacn_all_fields);
RUN_TEST(test_put_sacn_single_field_leaves_rest);
RUN_TEST(test_put_sacn_rejects_bad_values);
RUN_TEST(test_put_sacn_start_slot_must_leave_room_for_all_slots);
RUN_TEST(test_put_sacn_start_slot_limit_follows_the_board);
RUN_TEST(test_info_exposes_sacn_state);
RUN_TEST(test_commands);
return UNITY_END();
}