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
57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
#include <unity.h>
|
|
|
|
#include "dialog_model.h"
|
|
|
|
using namespace roro;
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
void test_starts_on_the_safe_first_button_and_undecided() {
|
|
DialogModel d({"Cancel", "Format"});
|
|
TEST_ASSERT_EQUAL(0, d.selected());
|
|
TEST_ASSERT_EQUAL(DialogModel::kPending, d.result());
|
|
}
|
|
|
|
void test_left_right_and_tab_move_between_buttons() {
|
|
DialogModel d({"Cancel", "Format"});
|
|
d.onKey(KeyEvent::of(Key::Right));
|
|
TEST_ASSERT_EQUAL(1, d.selected());
|
|
d.onKey(KeyEvent::of(Key::Right));
|
|
TEST_ASSERT_EQUAL(1, d.selected());
|
|
d.onKey(KeyEvent::of(Key::Tab));
|
|
TEST_ASSERT_EQUAL(0, d.selected());
|
|
d.onKey(KeyEvent::of(Key::Left));
|
|
TEST_ASSERT_EQUAL(0, d.selected());
|
|
}
|
|
|
|
void test_select_confirms_the_highlighted_button() {
|
|
DialogModel d({"Cancel", "Format"});
|
|
d.onKey(KeyEvent::of(Key::Right));
|
|
d.onKey(KeyEvent::of(Key::Select));
|
|
TEST_ASSERT_EQUAL(1, d.result());
|
|
}
|
|
|
|
void test_back_cancels() {
|
|
DialogModel d({"Cancel", "Format"});
|
|
d.onKey(KeyEvent::of(Key::Right));
|
|
d.onKey(KeyEvent::of(Key::Back));
|
|
TEST_ASSERT_EQUAL(DialogModel::kCancelled, d.result());
|
|
}
|
|
|
|
void test_dialog_consumes_every_key_while_open() {
|
|
DialogModel d({"OK"});
|
|
TEST_ASSERT_TRUE(d.onKey(KeyEvent::character('x')));
|
|
TEST_ASSERT_TRUE(d.onKey(KeyEvent::of(Key::Back)));
|
|
}
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_starts_on_the_safe_first_button_and_undecided);
|
|
RUN_TEST(test_left_right_and_tab_move_between_buttons);
|
|
RUN_TEST(test_select_confirms_the_highlighted_button);
|
|
RUN_TEST(test_back_cancels);
|
|
RUN_TEST(test_dialog_consumes_every_key_while_open);
|
|
return UNITY_END();
|
|
}
|