[geary/bug/728002-webkit2: 92/140] Implement milliseconds ctor and tests for Geary.TimeoutManager.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/bug/728002-webkit2: 92/140] Implement milliseconds ctor and tests for Geary.TimeoutManager.
- Date: Tue, 31 Jan 2017 23:06:16 +0000 (UTC)
commit b1d4eaa32f0415756e55cf72558a2cb70cfb85bd
Author: Michael James Gratton <mike vee net>
Date: Tue Jan 17 16:27:42 2017 +1100
Implement milliseconds ctor and tests for Geary.TimeoutManager.
src/engine/util/util-timeout-manager.vala | 12 ++++++++++++
test/engine/util-timeout-manager-test.vala | 17 +++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/src/engine/util/util-timeout-manager.vala b/src/engine/util/util-timeout-manager.vala
index d8c9322..8f493ad 100644
--- a/src/engine/util/util-timeout-manager.vala
+++ b/src/engine/util/util-timeout-manager.vala
@@ -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();
}
diff --git a/test/engine/util-timeout-manager-test.vala b/test/engine/util-timeout-manager-test.vala
index a087162..ae439e9 100644
--- a/test/engine/util-timeout-manager-test.vala
+++ b/test/engine/util-timeout-manager-test.vala
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]