all repos — tint2 @ 82d7fdc8f9fb61fd8eee565e0a34f5f94b0585db

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Timer: more tests
o9000 mrovi9000@gmail.com
commit

82d7fdc8f9fb61fd8eee565e0a34f5f94b0585db

parent

e046cb88abc85eef218d1912297db92e7cbf3204

1 files changed, 74 insertions(+), 0 deletions(-)

jump to
M src/util/timer.csrc/util/timer.c

@@ -544,6 +544,11 @@ int change_interval_ms;

bool add; int add_value_ms; int add_interval_ms; + bool stop_other; + bool change_other; + int change_other_value_ms; + int change_other_interval_ms; + timeout *other; } TimeoutContainer; void container_callback(void *arg) {

@@ -556,6 +561,12 @@ change_timeout(&container->timeout, container->change_value_ms, container->change_interval_ms, container_callback, arg);

if (container->add) { add_timeout(container->add_value_ms, container->add_interval_ms, container_callback, arg, NULL); container->add = false; + } + if (container->stop_other) + stop_timeout(container->other); + else if (container->change_other) { + change_timeout(&container->other, container->change_other_value_ms, container->change_other_interval_ms, container_callback, arg); + container->change_other = false; } }

@@ -800,6 +811,37 @@ handle_expired_timers();

ASSERT_EQUAL(container.triggered, 1); } +TEST(stop_timeout_simple_other_inside_callback) { + u_int64_t origin = 2134523; + TimeoutContainer container; + bzero(&container, sizeof(container)); + int triggered_other = 0; + + set_mock_time_ms(origin + 0); + + container.stop_other = true; + container.timeout = add_timeout(100, 0, container_callback, &container, NULL); + container.other = add_timeout(200, 0, trigger_callback, &triggered_other, NULL); + handle_expired_timers(); + ASSERT_EQUAL(container.triggered, 0); + ASSERT_EQUAL(triggered_other, 0); + + set_mock_time_ms(origin + 100); + handle_expired_timers(); + ASSERT_EQUAL(container.triggered, 1); + ASSERT_EQUAL(triggered_other, 0); + + set_mock_time_ms(origin + 200); + handle_expired_timers(); + ASSERT_EQUAL(container.triggered, 1); + ASSERT_EQUAL(triggered_other, 0); + + set_mock_time_ms(origin + 300); + handle_expired_timers(); + ASSERT_EQUAL(container.triggered, 1); + ASSERT_EQUAL(triggered_other, 0); +} + TEST(change_timeout_simple) { u_int64_t origin = 2134523; int triggered = 0;

@@ -901,6 +943,38 @@

set_mock_time_ms(origin + 400); handle_expired_timers(); ASSERT_EQUAL(container.triggered, 3); +} + +TEST(change_timeout_simple_other_inside_callback) { + u_int64_t origin = 2134523; + TimeoutContainer container; + bzero(&container, sizeof(container)); + int triggered_other = 0; + + set_mock_time_ms(origin + 0); + + container.change_other = true; + container.change_other_value_ms = 100; + container.timeout = add_timeout(100, 0, container_callback, &container, NULL); + container.other = add_timeout(1000, 0, trigger_callback, &triggered_other, NULL); + handle_expired_timers(); + ASSERT_EQUAL(container.triggered, 0); + ASSERT_EQUAL(triggered_other, 0); + + set_mock_time_ms(origin + 100); + handle_expired_timers(); + ASSERT_EQUAL(container.triggered, 1); + ASSERT_EQUAL(triggered_other, 0); + + set_mock_time_ms(origin + 200); + handle_expired_timers(); + ASSERT_EQUAL(container.triggered, 2); + ASSERT_EQUAL(triggered_other, 0); + + set_mock_time_ms(origin + 200); + handle_expired_timers(); + ASSERT_EQUAL(container.triggered, 2); + ASSERT_EQUAL(triggered_other, 0); } TEST(add_change_two_timeout_simple_inside_callback) {