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