Public Access
An Off screen turns on dimmed for the Toast's duration so the user can see what beeped. It isn't user activity: the timeouts aren't restarted, and a key pressed meanwhile reaches the App. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
103 lines
3.8 KiB
C++
103 lines
3.8 KiB
C++
#include <unity.h>
|
|
|
|
#include "power_policy.h"
|
|
|
|
using namespace roro;
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
void test_screen_dims_then_turns_off_after_inactivity() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(29999)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Dimmed), static_cast<int>(p.update(30000)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Off), static_cast<int>(p.update(60000)));
|
|
}
|
|
|
|
void test_key_on_dimmed_screen_wakes_and_still_acts() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.update(40000);
|
|
TEST_ASSERT_FALSE(p.activity(40000)); // not swallowed
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(40001)));
|
|
}
|
|
|
|
void test_key_on_off_screen_only_wakes() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.update(70000);
|
|
TEST_ASSERT_TRUE(p.activity(70000)); // swallowed
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(70001)));
|
|
}
|
|
|
|
void test_new_timeouts_apply_immediately() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.setTimeouts(10000, 20000);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Off), static_cast<int>(p.update(20000)));
|
|
}
|
|
|
|
void test_notification_lights_an_off_screen_dimmed_until_it_ends() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.update(70000); // off
|
|
p.notify(70000, 73000);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Dimmed), static_cast<int>(p.update(70001)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Dimmed), static_cast<int>(p.update(72999)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Off), static_cast<int>(p.update(73000)));
|
|
}
|
|
|
|
void test_notification_does_not_count_as_activity() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.notify(25000, 28000);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Dimmed), static_cast<int>(p.update(30000)));
|
|
}
|
|
|
|
void test_notification_never_brightens_or_dims_an_on_screen() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.notify(1000, 4000);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(2000)));
|
|
}
|
|
|
|
void test_key_on_a_notification_lit_screen_acts() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.update(70000);
|
|
p.notify(70000, 73000);
|
|
p.update(70001);
|
|
TEST_ASSERT_FALSE(p.activity(71000)); // the screen is visible: the key reaches the App
|
|
}
|
|
|
|
void test_short_press_reported_on_release() {
|
|
PowerButton b(2000);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::None), static_cast<int>(b.update(true, 0)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::None), static_cast<int>(b.update(true, 500)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::ShortPress), static_cast<int>(b.update(false, 600)));
|
|
}
|
|
|
|
void test_long_press_fires_once_while_still_held() {
|
|
PowerButton b(2000);
|
|
b.update(true, 0);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::LongPress), static_cast<int>(b.update(true, 2000)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::None), static_cast<int>(b.update(true, 3000)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::None), static_cast<int>(b.update(false, 3100)));
|
|
}
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_screen_dims_then_turns_off_after_inactivity);
|
|
RUN_TEST(test_key_on_dimmed_screen_wakes_and_still_acts);
|
|
RUN_TEST(test_key_on_off_screen_only_wakes);
|
|
RUN_TEST(test_new_timeouts_apply_immediately);
|
|
RUN_TEST(test_notification_lights_an_off_screen_dimmed_until_it_ends);
|
|
RUN_TEST(test_notification_does_not_count_as_activity);
|
|
RUN_TEST(test_notification_never_brightens_or_dims_an_on_screen);
|
|
RUN_TEST(test_key_on_a_notification_lit_screen_acts);
|
|
RUN_TEST(test_short_press_reported_on_release);
|
|
RUN_TEST(test_long_press_fires_once_while_still_held);
|
|
return UNITY_END();
|
|
}
|