#include #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(); }