mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-10-19 03:45:06 +00:00
- The `/system` FAT volume is removed. Its files are embedded in the firmware as generated C arrays. - Default-size fonts are generated at build time and used from flash. - The LVGL task and the Launcher run on PSRAM-preferred stacks. A new kernel `file_ops` API takes the file work off those threads. - `MainDispatcher` is reimplemented as an on-demand task. - More long-lived state is allocated with the PSRAM-preferring helpers. - Other fixes and improvements
91 lines
3.6 KiB
C++
91 lines
3.6 KiB
C++
#include "doctest.h"
|
|
|
|
#include <http/download.h>
|
|
|
|
TEST_CASE("http_download_start requires a subscribed subscription") {
|
|
HttpDownloadSubscription sub {};
|
|
CHECK_EQ(http_download_start("https://example.com/file", "not a certificate", "/target.bin", &sub), ERROR_INVALID_ARGUMENT);
|
|
}
|
|
|
|
TEST_CASE("http_download_poll times out before the download finishes") {
|
|
TaskEventGroup event_group {};
|
|
task_event_group_construct(&event_group);
|
|
|
|
HttpDownloadSubscription sub {};
|
|
CHECK_EQ(http_download_subscribe(&sub, &event_group), ERROR_NONE);
|
|
|
|
HttpDownloadEvent event {};
|
|
CHECK_EQ(http_download_poll(&sub, &event), ERROR_TIMEOUT);
|
|
|
|
http_download_unsubscribe(&sub);
|
|
task_event_group_destruct(&event_group);
|
|
}
|
|
|
|
TEST_CASE("http_download_start fails the download when the certificate can't be parsed") {
|
|
TaskEventGroup event_group {};
|
|
task_event_group_construct(&event_group);
|
|
|
|
HttpDownloadSubscription sub {};
|
|
CHECK_EQ(http_download_subscribe(&sub, &event_group), ERROR_NONE);
|
|
CHECK_EQ(http_download_start("https://example.com/file", "not a certificate", "/target.bin", &sub), ERROR_NONE);
|
|
|
|
CHECK_EQ(task_event_group_wait(&event_group, sub.bit, false, nullptr, pdMS_TO_TICKS(2000)), ERROR_NONE);
|
|
|
|
HttpDownloadEvent event {};
|
|
CHECK_EQ(http_download_poll(&sub, &event), ERROR_NONE);
|
|
CHECK_EQ(event.type, HTTP_DOWNLOAD_EVENT_ERROR);
|
|
|
|
http_download_unsubscribe(&sub);
|
|
task_event_group_destruct(&event_group);
|
|
}
|
|
|
|
TEST_CASE("http_download_unsubscribe reports ERROR_NOT_FOUND when not subscribed") {
|
|
HttpDownloadSubscription sub {};
|
|
CHECK_EQ(http_download_unsubscribe(&sub), ERROR_NOT_FOUND);
|
|
}
|
|
|
|
TEST_CASE("http_download_cancel reports ERROR_INVALID_STATE when not subscribed") {
|
|
HttpDownloadSubscription sub {};
|
|
CHECK_EQ(http_download_cancel(&sub), ERROR_INVALID_STATE);
|
|
}
|
|
|
|
TEST_CASE("http_download_unsubscribe is safe to call right after start, without waiting for the download to finish") {
|
|
TaskEventGroup event_group {};
|
|
task_event_group_construct(&event_group);
|
|
|
|
HttpDownloadSubscription sub {};
|
|
CHECK_EQ(http_download_subscribe(&sub, &event_group), ERROR_NONE);
|
|
CHECK_EQ(http_download_start("https://example.com/file", "not a certificate", "/target.bin", &sub), ERROR_NONE);
|
|
|
|
// No cancel, no poll for the terminal event - just unsubscribe and tear down immediately,
|
|
// racing whatever the download task is doing.
|
|
CHECK_EQ(http_download_unsubscribe(&sub), ERROR_NONE);
|
|
CHECK_EQ(http_download_unsubscribe(&sub), ERROR_NOT_FOUND);
|
|
|
|
// The bit is free again immediately, even though the download task may still be running.
|
|
uint32_t reclaimed_bit;
|
|
CHECK_EQ(task_event_group_claim_bit(&event_group, &reclaimed_bit), ERROR_NONE);
|
|
task_event_group_release_bit(&event_group, reclaimed_bit);
|
|
|
|
task_event_group_destruct(&event_group);
|
|
}
|
|
|
|
TEST_CASE("http_download_cancel before start makes the download finish as cancelled") {
|
|
TaskEventGroup event_group {};
|
|
task_event_group_construct(&event_group);
|
|
|
|
HttpDownloadSubscription sub {};
|
|
CHECK_EQ(http_download_subscribe(&sub, &event_group), ERROR_NONE);
|
|
CHECK_EQ(http_download_cancel(&sub), ERROR_NONE);
|
|
CHECK_EQ(http_download_start("https://example.com/file", "not a certificate", "/target.bin", &sub), ERROR_NONE);
|
|
|
|
CHECK_EQ(task_event_group_wait(&event_group, sub.bit, false, nullptr, pdMS_TO_TICKS(2000)), ERROR_NONE);
|
|
|
|
HttpDownloadEvent event {};
|
|
CHECK_EQ(http_download_poll(&sub, &event), ERROR_NONE);
|
|
CHECK_EQ(event.type, HTTP_DOWNLOAD_EVENT_CANCELLED);
|
|
|
|
http_download_unsubscribe(&sub);
|
|
task_event_group_destruct(&event_group);
|
|
}
|