Implement milliseconds ctor and tests for Geary.TimeoutManager.
This commit is contained in:
parent
b20b3cafad
commit
b1d4eaa32f
2 changed files with 29 additions and 0 deletions
|
|
@ -66,6 +66,18 @@ public class Geary.TimeoutManager : BaseObject {
|
|||
this.callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new timeout with an interval in milliseconds.
|
||||
*
|
||||
* The timeout will be by default not running, and hence needs to be
|
||||
* started by a call to {@link start}.
|
||||
*/
|
||||
public TimeoutManager.milliseconds(uint interval, TimeoutFunc callback) {
|
||||
this.use_seconds = false;
|
||||
this.interval = interval;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
~TimeoutManager() {
|
||||
reset();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,14 @@ class Geary.TimeoutManagerTest : Gee.TestCase {
|
|||
// add_seconds seems to vary wildly, so needs a large epsilon
|
||||
private const double SECONDS_EPSILON = 1.8;
|
||||
|
||||
private const double MILLISECONDS_EPSILON = 0.1;
|
||||
|
||||
public TimeoutManagerTest() {
|
||||
base("Geary.TimeoutManagerTest");
|
||||
add_test("start_reset", start_reset);
|
||||
if (Test.slow()) {
|
||||
add_test("test_seconds", test_seconds);
|
||||
add_test("test_milliseconds", test_milliseconds);
|
||||
add_test("test_repeat_forever", test_repeat_forever);
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +45,20 @@ class Geary.TimeoutManagerTest : Gee.TestCase {
|
|||
assert_epsilon(timer.elapsed(), 1.0, SECONDS_EPSILON);
|
||||
}
|
||||
|
||||
public void test_milliseconds() {
|
||||
Timer timer = new Timer();
|
||||
|
||||
TimeoutManager test = new TimeoutManager.milliseconds(100, () => { timer.stop(); });
|
||||
test.start();
|
||||
|
||||
timer.start();
|
||||
while (test.is_running && timer.elapsed() < 100 + MILLISECONDS_EPSILON) {
|
||||
Gtk.main_iteration();
|
||||
}
|
||||
|
||||
assert_epsilon(timer.elapsed(), 0.1, MILLISECONDS_EPSILON);
|
||||
}
|
||||
|
||||
public void test_repeat_forever() {
|
||||
Timer timer = new Timer();
|
||||
int count = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue