Public Access
Steps 5 and 6 of M0. - lib/ui (host-tested): ListModel, LineEditor (UTF-8, byte-limited), wrapText, ToastQueue, DialogModel - lib/input (host-tested): KeyMapper turns keyboard state into logical keys (Fn arrows, ` Back, Fn+` Home) and composes accents with opt - src/ui: off-screen 16-bit frame pushed in one transfer (fixes the flicker), Status Bar, list, text, line editor, dialog, Toast widgets, Notifier (Toast + beep + LED), vendored public-domain Latin-1 fonts - Apps: minimal Launcher, Widget demo, Diagnostics (SD erase now behind a confirmation dialog) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
78 lines
2.5 KiB
C++
78 lines
2.5 KiB
C++
#include <unity.h>
|
|
|
|
#include "toast_queue.h"
|
|
|
|
using namespace roro;
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
void test_nothing_shown_when_empty() {
|
|
ToastQueue q(3000);
|
|
TEST_ASSERT_NULL(q.current(0));
|
|
}
|
|
|
|
void test_toast_is_shown_for_its_duration() {
|
|
ToastQueue q(3000);
|
|
q.push("hello", NotificationLevel::Info, 1000);
|
|
TEST_ASSERT_NOT_NULL(q.current(1000));
|
|
TEST_ASSERT_EQUAL_STRING("hello", q.current(3999)->text.c_str());
|
|
TEST_ASSERT_NULL(q.current(4000));
|
|
}
|
|
|
|
void test_queued_toasts_follow_each_other() {
|
|
ToastQueue q(3000);
|
|
q.push("one", NotificationLevel::Info, 0);
|
|
q.push("two", NotificationLevel::Info, 100);
|
|
TEST_ASSERT_EQUAL_STRING("one", q.current(2999)->text.c_str());
|
|
TEST_ASSERT_EQUAL_STRING("two", q.current(3000)->text.c_str());
|
|
TEST_ASSERT_EQUAL_STRING("two", q.current(5999)->text.c_str());
|
|
TEST_ASSERT_NULL(q.current(6000));
|
|
}
|
|
|
|
void test_a_toast_queued_later_gets_its_full_duration() {
|
|
ToastQueue q(3000);
|
|
q.push("one", NotificationLevel::Info, 0);
|
|
TEST_ASSERT_NULL(q.current(10000));
|
|
q.push("two", NotificationLevel::Info, 20000);
|
|
TEST_ASSERT_NOT_NULL(q.current(22999));
|
|
}
|
|
|
|
void test_flood_keeps_the_visible_toast_and_drops_the_oldest_waiting() {
|
|
ToastQueue q(3000, 2);
|
|
q.push("a", NotificationLevel::Info, 0);
|
|
q.push("b", NotificationLevel::Info, 0);
|
|
q.push("c", NotificationLevel::Info, 0);
|
|
TEST_ASSERT_EQUAL_STRING("a", q.current(0)->text.c_str());
|
|
TEST_ASSERT_EQUAL_STRING("c", q.current(3000)->text.c_str());
|
|
}
|
|
|
|
void test_dismiss_shows_the_next_one_immediately() {
|
|
ToastQueue q(3000);
|
|
q.push("one", NotificationLevel::Info, 0);
|
|
q.push("two", NotificationLevel::Info, 0);
|
|
q.dismiss(500);
|
|
TEST_ASSERT_EQUAL_STRING("two", q.current(500)->text.c_str());
|
|
}
|
|
|
|
void test_reports_when_a_new_toast_appears() {
|
|
ToastQueue q(3000);
|
|
q.push("one", NotificationLevel::Info, 0);
|
|
TEST_ASSERT_TRUE(q.takeChanged());
|
|
TEST_ASSERT_FALSE(q.takeChanged());
|
|
q.current(3000); // expires
|
|
TEST_ASSERT_TRUE(q.takeChanged());
|
|
}
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_nothing_shown_when_empty);
|
|
RUN_TEST(test_toast_is_shown_for_its_duration);
|
|
RUN_TEST(test_queued_toasts_follow_each_other);
|
|
RUN_TEST(test_a_toast_queued_later_gets_its_full_duration);
|
|
RUN_TEST(test_flood_keeps_the_visible_toast_and_drops_the_oldest_waiting);
|
|
RUN_TEST(test_dismiss_shows_the_next_one_immediately);
|
|
RUN_TEST(test_reports_when_a_new_toast_appears);
|
|
return UNITY_END();
|
|
}
|