[gnome-break-timer] Bring back the test suite
- From: Dylan McCall <dylanmccall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-break-timer] Bring back the test suite
- Date: Fri, 20 Nov 2020 04:19:34 +0000 (UTC)
commit 004de1de09c55cffa9b5cd697c11ddf4d529a574
Author: Dylan McCall <dylan dylanmccall ca>
Date: Thu Nov 19 15:46:06 2020 -0800
Bring back the test suite
To support this, separate pieces of the application into helper
libraries (again), but this time tidier because Meson is excellent.
meson.build | 1 +
org.gnome.BreakTimer.json | 4 +
src/common/meson.build | 8 +-
src/daemon/meson.build | 47 ++++-
src/meson.build | 35 ----
src/settings/meson.build | 51 +++++-
tests/activity-monitor/test_ActivityMonitor.vala | 193 --------------------
tests/common/common_runner.vala | 4 +
tests/common/meson.build | 15 ++
tests/common/test_NaturalTime.vala | 8 +-
.../daemon_activity_runner.vala} | 4 +
tests/daemon-activity/meson.build | 15 ++
tests/daemon-activity/test_ActivityMonitor.vala | 200 +++++++++++++++++++++
.../daemon_timerbreak_runner.vala} | 4 +
tests/daemon-timerbreak/meson.build | 15 ++
.../test_TimerBreakController.vala | 55 +++---
tests/daemon-util/daemon_util_runner.vala | 4 +
tests/daemon-util/meson.build | 16 ++
tests/daemon-util/test_Countdown.vala | 8 +-
tests/daemon-util/test_StatefulTimer.vala | 8 +-
tests/meson.build | 30 ++++
tests/tests.vala | 116 +++++-------
22 files changed, 500 insertions(+), 341 deletions(-)
---
diff --git a/meson.build b/meson.build
index 887301b..9af55da 100644
--- a/meson.build
+++ b/meson.build
@@ -65,5 +65,6 @@ run_script_conf.set('BINDIR', bindir)
subdir('po')
subdir('data')
subdir('src')
+subdir('tests')
meson.add_install_script('build-aux/meson/postinstall.py')
diff --git a/org.gnome.BreakTimer.json b/org.gnome.BreakTimer.json
index 5d34d68..4684854 100644
--- a/org.gnome.BreakTimer.json
+++ b/org.gnome.BreakTimer.json
@@ -75,6 +75,10 @@
"name" : "gnome-break-timer",
"buildsystem" : "meson",
"builddir" : true,
+ "run-tests": true,
+ "build-options": {
+ "test-args": ["--share=network"]
+ },
"sources" : [
{
"type" : "git",
diff --git a/src/common/meson.build b/src/common/meson.build
index 6a9cfa9..aa0eeea 100644
--- a/src/common/meson.build
+++ b/src/common/meson.build
@@ -1,4 +1,4 @@
-common_sources = files(
+common_lib_sources = files(
'IBreakTimer_TimerBreak.vala',
'IBreakTimer.vala',
'IFreedesktopApplication.vala',
@@ -10,15 +10,15 @@ common_sources = files(
'NaturalTime.vala'
)
-common_dependencies = [
+common_lib_dependencies = [
gio_dep,
config_lib_dep
]
common_lib = static_library(
'common',
- sources: common_sources,
- dependencies: common_dependencies,
+ sources: common_lib_sources,
+ dependencies: common_lib_dependencies,
include_directories: include_directories('.')
)
diff --git a/src/daemon/meson.build b/src/daemon/meson.build
index ed7db03..1dcaee9 100644
--- a/src/daemon/meson.build
+++ b/src/daemon/meson.build
@@ -1,4 +1,4 @@
-daemon_sources = files(
+daemon_lib_sources = files(
'activity/ActivityMonitorBackend.vala',
'activity/ActivityMonitor.vala',
'activity/MutterActivityMonitorBackend.vala',
@@ -9,7 +9,6 @@ daemon_sources = files(
'break/BreakView.vala',
'BreakManagerDBusObject.vala',
'BreakManager.vala',
- 'main.vala',
'microbreak/MicroBreakController.vala',
'microbreak/MicroBreakType.vala',
'microbreak/MicroBreakView.vala',
@@ -29,3 +28,47 @@ daemon_sources = files(
'util/StatefulTimer.vala',
'util/TimeUnit.vala'
)
+
+daemon_lib_dependencies = [
+ cairo_dep,
+ config_lib_dep,
+ gio_dep,
+ gio_unix_dep,
+ gtk_dep,
+ json_glib_dep,
+ gsound_dep,
+ libnotify_dep,
+ m_dep,
+ posix_dep,
+ common_lib_dep
+]
+
+daemon_lib = static_library(
+ 'daemon',
+ sources: daemon_lib_sources,
+ dependencies: daemon_lib_dependencies,
+ include_directories: include_directories('.')
+)
+
+daemon_lib_dep = declare_dependency(
+ link_with: daemon_lib,
+ dependencies: daemon_lib_dependencies,
+ include_directories: include_directories('.')
+)
+
+daemon_exe_sources = files(
+ 'main.vala'
+)
+
+executable(
+ 'gnome-break-timer-daemon',
+ sources : [
+ daemon_exe_sources
+ ],
+ dependencies : [
+ daemon_lib_dep,
+ break_timer_resources_dep
+ ],
+ install: true,
+ install_dir: bindir
+)
diff --git a/src/meson.build b/src/meson.build
index e81aeaf..c04b944 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -17,38 +17,3 @@ config_lib_dep = declare_dependency(
subdir('common')
subdir('settings')
subdir('daemon')
-
-common_dependencies = [
- cairo_dep,
- config_lib_dep,
- gio_dep,
- gio_unix_dep,
- gtk_dep,
- json_glib_dep,
- gsound_dep,
- libnotify_dep,
- m_dep,
- posix_dep,
- common_lib_dep,
- break_timer_resources_dep
-]
-
-executable(
- 'gnome-break-timer-settings',
- sources : [
- settings_sources
- ],
- dependencies : common_dependencies,
- install: true,
- install_dir: bindir
-)
-
-executable(
- 'gnome-break-timer-daemon',
- sources : [
- daemon_sources
- ],
- dependencies : common_dependencies,
- install: true,
- install_dir: bindir
-)
diff --git a/src/settings/meson.build b/src/settings/meson.build
index 7808c12..38debc1 100644
--- a/src/settings/meson.build
+++ b/src/settings/meson.build
@@ -1,8 +1,4 @@
-# TODO: BUILD IN DATA FILES
-# $(top_srcdir)/settings/resources.c: $(top_srcdir)/data/gnome-break-timer.gresource.xml $(shell
$(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(top_srcdir)/data/
$(top_srcdir)/data/gnome-break-timer.gresource.xml)
-# $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(top_srcdir)/data/ --generate-source $<
-
-settings_sources = files(
+settings_lib_sources = files(
'Application.vala',
'break/BreakInfoWidget.vala',
'break/BreakSettingsWidget.vala',
@@ -10,7 +6,6 @@ settings_sources = files(
'break/BreakType.vala',
'BreakManager.vala',
'BreakSettingsDialog.vala',
- 'main.vala',
'MainWindow.vala',
'microbreak/MicroBreakInfoWidget.vala',
'microbreak/MicroBreakSettingsWidget.vala',
@@ -31,3 +26,47 @@ settings_sources = files(
'widgets/OverlayArrow.vala',
'widgets/TimeChooser.vala'
)
+
+settings_lib_dependencies = [
+ cairo_dep,
+ config_lib_dep,
+ gio_dep,
+ gio_unix_dep,
+ gtk_dep,
+ json_glib_dep,
+ gsound_dep,
+ libnotify_dep,
+ m_dep,
+ posix_dep,
+ common_lib_dep
+]
+
+settings_lib = static_library(
+ 'settings',
+ sources: settings_lib_sources,
+ dependencies: settings_lib_dependencies,
+ include_directories: include_directories('.')
+)
+
+settings_lib_dep = declare_dependency(
+ link_with: settings_lib,
+ dependencies: settings_lib_dependencies,
+ include_directories: include_directories('.')
+)
+
+settings_exe_sources = files(
+ 'main.vala'
+)
+
+executable(
+ 'gnome-break-timer-settings',
+ sources : [
+ settings_exe_sources
+ ],
+ dependencies : [
+ settings_lib_dep,
+ break_timer_resources_dep
+ ],
+ install: true,
+ install_dir: bindir
+)
diff --git a/tests/common/common_runner.vala b/tests/common/common_runner.vala
index fa338d2..8136498 100644
--- a/tests/common/common_runner.vala
+++ b/tests/common/common_runner.vala
@@ -15,8 +15,12 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+namespace BreakTimer.Tests.Common {
+
public static int main (string[] args) {
var runner = new TestRunner (ref args);
runner.add (new test_NaturalTime ());
return runner.run ();
}
+
+}
diff --git a/tests/common/meson.build b/tests/common/meson.build
new file mode 100644
index 0000000..0075952
--- /dev/null
+++ b/tests/common/meson.build
@@ -0,0 +1,15 @@
+common_test_runner = executable(
+ 'tests-common',
+ sources : [
+ 'common_runner.vala',
+ 'test_NaturalTime.vala'
+ ],
+ dependencies : [
+ tests_lib_dep
+ ]
+)
+
+test(
+ 'Run common tests',
+ common_test_runner
+)
diff --git a/tests/common/test_NaturalTime.vala b/tests/common/test_NaturalTime.vala
index 15c8da0..e22612b 100644
--- a/tests/common/test_NaturalTime.vala
+++ b/tests/common/test_NaturalTime.vala
@@ -15,6 +15,10 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Common;
+
+namespace BreakTimer.Tests.Common {
+
public class test_NaturalTime : SimpleTestSuite {
public NaturalTime natural_time;
@@ -109,4 +113,6 @@ public class test_NaturalTime : SimpleTestSuite {
assert (value_51 == 55);
}
}
-}
\ No newline at end of file
+}
+
+}
diff --git a/tests/activity-monitor/activity-monitor_runner.vala
b/tests/daemon-activity/daemon_activity_runner.vala
similarity index 94%
rename from tests/activity-monitor/activity-monitor_runner.vala
rename to tests/daemon-activity/daemon_activity_runner.vala
index b6017d0..ba60fec 100644
--- a/tests/activity-monitor/activity-monitor_runner.vala
+++ b/tests/daemon-activity/daemon_activity_runner.vala
@@ -15,8 +15,12 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+namespace BreakTimer.Tests.Daemon.Activity {
+
public static int main (string[] args) {
var runner = new TestRunner (ref args);
runner.add (new test_ActivityMonitor ());
return runner.run ();
}
+
+}
diff --git a/tests/daemon-activity/meson.build b/tests/daemon-activity/meson.build
new file mode 100644
index 0000000..366b593
--- /dev/null
+++ b/tests/daemon-activity/meson.build
@@ -0,0 +1,15 @@
+daemon_activity_test_runner = executable(
+ 'tests-daemon-activity',
+ sources : [
+ 'daemon_activity_runner.vala',
+ 'test_ActivityMonitor.vala'
+ ],
+ dependencies : [
+ tests_lib_dep
+ ]
+)
+
+test(
+ 'Run daemon-activity tests',
+ daemon_activity_test_runner
+)
diff --git a/tests/daemon-activity/test_ActivityMonitor.vala b/tests/daemon-activity/test_ActivityMonitor.vala
new file mode 100644
index 0000000..caf4906
--- /dev/null
+++ b/tests/daemon-activity/test_ActivityMonitor.vala
@@ -0,0 +1,200 @@
+/*
+ * This file is part of GNOME Break Timer.
+ *
+ * GNOME Break Timer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNOME Break Timer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using BreakTimer.Daemon.Activity;
+
+namespace BreakTimer.Tests.Daemon.Activity {
+
+public class test_ActivityMonitor : TestSuiteWithActivityMonitor {
+ public test_ActivityMonitor () {
+ new test_simple_idle ().add_to (this);
+ new test_simple_active ().add_to (this);
+ new test_lock_idle ().add_to (this);
+ new test_active_then_idle ().add_to (this);
+ new test_sleep_and_unlock ().add_to (this);
+ new test_unlock_signal_activity ().add_to (this);
+ }
+
+ class test_simple_idle : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = false;
+ context.time_step (false, 0, 0);
+ context.time_step (false, 1, 1);
+
+ assert (context.activity_log.length () == 2);
+
+ assert (context.activity_log.nth_data (0).type == ActivityType.NONE);
+ assert (context.activity_log.nth_data (0).is_active () == false);
+ stdout.printf("IDLE TIME: %d\n", (int) context.activity_log.nth_data (0).idle_time);
+ assert (context.activity_log.nth_data (0).idle_time == 10);
+
+ assert (context.activity_log.nth_data (1).type == ActivityType.NONE);
+ assert (context.activity_log.nth_data (1).is_active () == false);
+ assert (context.activity_log.nth_data (1).idle_time == context.activity_log.nth_data
(0).idle_time + 1);
+ }
+ }
+
+ class test_simple_active : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = false;
+ context.time_step (true, 1, 1);
+
+ context.time_step (true, 1, 1);
+
+ context.time_step (true, 1, 1);
+
+ assert (context.activity_log.length () == 3);
+
+ assert (context.activity_log.nth_data (0).type == ActivityType.INPUT);
+ assert (context.activity_log.nth_data (0).is_active () == true);
+ assert (context.activity_log.nth_data (0).idle_time == 0);
+
+ assert (context.activity_log.nth_data (1).type == ActivityType.INPUT);
+ assert (context.activity_log.nth_data (1).is_active () == true);
+ assert (context.activity_log.nth_data (1).idle_time == 0);
+
+ assert (context.activity_log.nth_data (2).type == ActivityType.INPUT);
+ assert (context.activity_log.nth_data (2).is_active () == true);
+ assert (context.activity_log.nth_data (2).idle_time == 0);
+ }
+ }
+
+ class test_active_then_idle : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = false;
+ context.time_step (true, 1, 1);
+
+ context.time_step (false, 1, 1);
+
+ context.time_step (false, 1, 1);
+
+ context.time_step (true, 1, 1);
+
+ context.time_step (true, 1, 1);
+
+ assert (context.activity_log.length () == 5);
+
+ assert (context.activity_log.nth_data (0).type == ActivityType.INPUT);
+ assert (context.activity_log.nth_data (0).is_active () == true);
+ assert (context.activity_log.nth_data (0).idle_time == 0);
+
+ assert (context.activity_log.nth_data (1).type == ActivityType.NONE);
+ assert (context.activity_log.nth_data (1).is_active () == false);
+ assert (context.activity_log.nth_data (1).idle_time == 1);
+ assert (context.activity_log.nth_data (1).time_since_active == 1);
+
+ assert (context.activity_log.nth_data (2).type == ActivityType.NONE);
+ assert (context.activity_log.nth_data (2).is_active () == false);
+ assert (context.activity_log.nth_data (2).idle_time == 2);
+ assert (context.activity_log.nth_data (2).time_since_active == 2);
+
+ assert (context.activity_log.nth_data (3).type == ActivityType.INPUT);
+ assert (context.activity_log.nth_data (3).is_active () == true);
+ assert (context.activity_log.nth_data (3).idle_time == 0);
+ assert (context.activity_log.nth_data (3).time_since_active == 3);
+
+ assert (context.activity_log.nth_data (4).type == ActivityType.INPUT);
+ assert (context.activity_log.nth_data (4).is_active () == true);
+ assert (context.activity_log.nth_data (4).idle_time == 0);
+ assert (context.activity_log.nth_data (4).time_since_active == 1);
+ }
+ }
+
+ class test_lock_idle : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = true;
+ context.time_step (true, 1, 1);
+
+ context.time_step (true, 1, 1);
+
+ context.time_step (false, 1, 1);
+
+ assert (context.activity_log.length () == 3);
+
+ assert (context.activity_log.nth_data (0).type == ActivityType.LOCKED);
+ assert (context.activity_log.nth_data (0).is_active () == false);
+ assert (context.activity_log.nth_data (0).idle_time == 0);
+
+ assert (context.activity_log.nth_data (1).type == ActivityType.LOCKED);
+ assert (context.activity_log.nth_data (1).is_active () == false);
+ assert (context.activity_log.nth_data (1).idle_time == 0);
+
+ assert (context.activity_log.nth_data (2).type == ActivityType.LOCKED);
+ assert (context.activity_log.nth_data (2).is_active () == false);
+ assert (context.activity_log.nth_data (2).idle_time == 1);
+ }
+ }
+
+ class test_sleep_and_unlock : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = false;
+ context.time_step (true, 1, 1);
+
+ context.session_status.virt_is_locked = true;
+ context.time_step (true, 120, 2);
+
+ context.time_step (true, 1, 1);
+
+ context.session_status.virt_is_locked = false;
+ context.time_step (true, 1, 1);
+
+ assert (context.activity_log.length () == 4);
+
+ assert (context.activity_log.nth_data (0).type == ActivityType.INPUT);
+ assert (context.activity_log.nth_data (0).is_active () == true);
+ assert (context.activity_log.nth_data (0).idle_time == 0);
+ assert (context.activity_log.nth_data (0).time_correction == 0);
+
+ assert (context.activity_log.nth_data (1).type == ActivityType.SLEEP);
+ assert (context.activity_log.nth_data (1).is_active () == false);
+ assert (context.activity_log.nth_data (1).time_since_active == 120);
+ assert (context.activity_log.nth_data (1).idle_time == 0);
+ assert (context.activity_log.nth_data (1).time_correction == 120-2);
+
+ assert (context.activity_log.nth_data (2).type == ActivityType.LOCKED);
+ assert (context.activity_log.nth_data (2).is_active () == false);
+ assert (context.activity_log.nth_data (2).idle_time == 0);
+ assert (context.activity_log.nth_data (2).time_correction == 0);
+
+ assert (context.activity_log.nth_data (3).type == ActivityType.INPUT);
+ assert (context.activity_log.nth_data (3).is_active () == true);
+ assert (context.activity_log.nth_data (3).idle_time == 0);
+ assert (context.activity_log.nth_data (3).time_correction == 0);
+ }
+ }
+
+ class test_unlock_signal_activity : Object, SimpleTestCase<test_ActivityMonitor> {
+ public void run (test_ActivityMonitor context) {
+ context.session_status.virt_is_locked = true;
+ context.time_step (true, 1, 1);
+
+ context.session_status.do_unlock ();
+
+ assert (context.activity_log.length () == 2);
+
+ assert (context.activity_log.nth_data (0).type == ActivityType.LOCKED);
+ assert (context.activity_log.nth_data (0).is_active () == false);
+ assert (context.activity_log.nth_data (0).idle_time == 0);
+
+ assert (context.activity_log.nth_data (1).type == ActivityType.UNLOCK);
+ assert (context.activity_log.nth_data (1).is_active () == true);
+ assert (context.activity_log.nth_data (1).idle_time == 0);
+ }
+ }
+}
+
+}
diff --git a/tests/breaks/breaks_runner.vala b/tests/daemon-timerbreak/daemon_timerbreak_runner.vala
similarity index 94%
rename from tests/breaks/breaks_runner.vala
rename to tests/daemon-timerbreak/daemon_timerbreak_runner.vala
index 84b3213..b45fa80 100644
--- a/tests/breaks/breaks_runner.vala
+++ b/tests/daemon-timerbreak/daemon_timerbreak_runner.vala
@@ -15,8 +15,12 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+namespace BreakTimer.Tests.Daemon.TimerBreak {
+
public static int main (string[] args) {
var runner = new TestRunner (ref args);
runner.add (new test_TimerBreakController ());
return runner.run ();
}
+
+}
diff --git a/tests/daemon-timerbreak/meson.build b/tests/daemon-timerbreak/meson.build
new file mode 100644
index 0000000..5843f4b
--- /dev/null
+++ b/tests/daemon-timerbreak/meson.build
@@ -0,0 +1,15 @@
+daemon_timerbreak_test_runner = executable(
+ 'tests-daemon-timerbreak',
+ sources : [
+ 'daemon_timerbreak_runner.vala',
+ 'test_TimerBreakController.vala'
+ ],
+ dependencies : [
+ tests_lib_dep
+ ]
+)
+
+test(
+ 'Run daemon-timerbreak tests',
+ daemon_timerbreak_test_runner
+)
diff --git a/tests/breaks/test_TimerBreakController.vala
b/tests/daemon-timerbreak/test_TimerBreakController.vala
similarity index 89%
rename from tests/breaks/test_TimerBreakController.vala
rename to tests/daemon-timerbreak/test_TimerBreakController.vala
index 2138880..99f00ec 100644
--- a/tests/breaks/test_TimerBreakController.vala
+++ b/tests/daemon-timerbreak/test_TimerBreakController.vala
@@ -15,13 +15,18 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Daemon.Activity;
+using BreakTimer.Daemon.TimerBreak;
+
+namespace BreakTimer.Tests.Daemon.TimerBreak {
+
public class test_TimerBreakController : TestSuiteWithActivityMonitor {
public const int DEFAULT_INTERVAL = 360;
public const int DEFAULT_DURATION = 30;
public testable_TimerBreakController break_controller;
- public Gee.List<string> break_log;
- public Gee.List<string> break_timestep_log;
+ public GLib.List<string> break_log;
+ public GLib.List<string> break_timestep_log;
public test_TimerBreakController () {
new test_start_disabled ().add_to (this);
@@ -33,15 +38,15 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
}
public override void setup () {
- this.break_log = new Gee.ArrayList<string> ();
- this.break_timestep_log = new Gee.ArrayList<string> ();
+ this.break_log = new GLib.List<string> ();
+ this.break_timestep_log = new GLib.List<string> ();
base.setup ();
}
private void log_break_message (string message) {
- this.break_log.add (message);
- this.break_timestep_log.add (message);
+ this.break_log.append (message);
+ this.break_timestep_log.append (message);
}
public Json.Object save_state () {
@@ -70,8 +75,8 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
public override void refresh_environment () {
base.refresh_environment ();
- this.break_log.clear ();
- this.break_timestep_log.clear ();
+ this.break_log = new GLib.List<string> ();
+ this.break_timestep_log = new GLib.List<string> ();
this.break_controller = new testable_TimerBreakController (this.activity_monitor);
this.break_controller.interval = DEFAULT_INTERVAL;
@@ -90,7 +95,7 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
}
public override void time_step (bool is_active, int real_seconds, int monotonic_seconds) {
- this.break_timestep_log.clear ();
+ this.break_timestep_log = new GLib.List<string> ();
base.time_step (is_active, real_seconds, monotonic_seconds);
this.break_controller.time_step (real_seconds, monotonic_seconds);
}
@@ -122,7 +127,7 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
context.break_controller.activate ();
assert (context.break_controller.is_enabled () == false);
- assert (context.break_log.last () == "disabled");
+ assert (context.break_log.last ().data == "disabled");
}
}
@@ -140,9 +145,9 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
for (int step = 0; step <= test_TimerBreakController.DEFAULT_DURATION; step++) {
context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
+ assert (context.break_timestep_log.nth_data (0) == "counting");
if (step == test_TimerBreakController.DEFAULT_DURATION) {
- assert (context.break_timestep_log[1] == "finished");
+ assert (context.break_timestep_log.nth_data (1) == "finished");
}
}
expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
@@ -151,7 +156,7 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
for (int step = 0; step < test_TimerBreakController.DEFAULT_INTERVAL; step++) {
context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
+ assert (context.break_timestep_log.nth_data (0) == "counting");
}
context.break_controller.assert_timers (expected_starts_in, expected_remaining);
}
@@ -165,7 +170,7 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
var active_time_1 = 20;
for (int step = 0; step < active_time_1; step++) {
context.time_step (true, 1, 1);
- assert (context.break_timestep_log[0] == "delayed");
+ assert (context.break_timestep_log.nth_data (0) == "delayed");
}
expected_starts_in -= active_time_1;
context.break_controller.assert_timers (expected_starts_in, expected_remaining);
@@ -173,7 +178,7 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
var idle_time_1 = 10;
for (int step = 0; step <= idle_time_1; step++) {
context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
+ assert (context.break_timestep_log.nth_data (0) == "counting");
}
expected_starts_in -= 1;
expected_remaining -= idle_time_1;
@@ -183,11 +188,11 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
var warn_step = active_time_2 - test_TimerBreakController.DEFAULT_DURATION - 1;
for (int step = 0; step < active_time_2; step++) {
context.time_step (true, 1, 1);
- assert (context.break_timestep_log[0] == "delayed");
+ assert (context.break_timestep_log.nth_data (0) == "delayed");
if (step == warn_step) {
- assert (context.break_timestep_log[1] == "warned");
+ assert (context.break_timestep_log.nth_data (1) == "warned");
} else if (step == active_time_2-1) {
- assert (context.break_timestep_log[1] == "activated");
+ assert (context.break_timestep_log.nth_data (1) == "activated");
}
}
expected_starts_in = 0;
@@ -196,16 +201,16 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
for (int step = 0; step < 5; step++) {
context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
+ assert (context.break_timestep_log.nth_data (0) == "counting");
}
expected_remaining -= 5;
context.break_controller.assert_timers (expected_starts_in, expected_remaining);
for (int step = 0; step < expected_remaining; step++) {
context.time_step (false, 1, 1);
- assert (context.break_timestep_log[0] == "counting");
+ assert (context.break_timestep_log.nth_data (0) == "counting");
if (step == expected_remaining-1) {
- assert (context.break_timestep_log[1] == "finished");
+ assert (context.break_timestep_log.nth_data (1) == "finished");
}
}
expected_starts_in = test_TimerBreakController.DEFAULT_INTERVAL;
@@ -219,7 +224,7 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
int expected_remaining = test_TimerBreakController.DEFAULT_DURATION;
context.break_controller.activate ();
- assert (context.break_log.last () == "activated");
+ assert (context.break_log.last ().data == "activated");
assert (context.break_controller.get_seconds_since_start () == 0);
context.break_controller.assert_timers (null, expected_remaining);
@@ -254,7 +259,7 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
for (int step = 0; step < expected_starts_in; step++) {
context.time_step (true, 1, 1);
if (step == expected_starts_in-1) {
- assert (context.break_timestep_log[1] == "activated");
+ assert (context.break_timestep_log.nth_data (1) == "activated");
}
}
expected_starts_in = 0;
@@ -317,4 +322,6 @@ public class test_TimerBreakController : TestSuiteWithActivityMonitor {
context.break_controller.assert_timers (0, test_TimerBreakController.DEFAULT_DURATION-20);
}
}
-}
\ No newline at end of file
+}
+
+}
diff --git a/tests/daemon-util/daemon_util_runner.vala b/tests/daemon-util/daemon_util_runner.vala
index 175e246..4cd53c6 100644
--- a/tests/daemon-util/daemon_util_runner.vala
+++ b/tests/daemon-util/daemon_util_runner.vala
@@ -15,9 +15,13 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+namespace BreakTimer.Tests.Daemon.Util {
+
public static int main (string[] args) {
var runner = new TestRunner (ref args);
runner.add (new test_Countdown ());
runner.add (new test_StatefulTimer ());
return runner.run ();
}
+
+}
diff --git a/tests/daemon-util/meson.build b/tests/daemon-util/meson.build
new file mode 100644
index 0000000..583bd53
--- /dev/null
+++ b/tests/daemon-util/meson.build
@@ -0,0 +1,16 @@
+daemon_util_test_runner = executable(
+ 'tests-daemon-util',
+ sources : [
+ 'daemon_util_runner.vala',
+ 'test_Countdown.vala',
+ 'test_StatefulTimer.vala'
+ ],
+ dependencies : [
+ tests_lib_dep
+ ]
+)
+
+test(
+ 'Run daemon-util tests',
+ daemon_util_test_runner
+)
diff --git a/tests/daemon-util/test_Countdown.vala b/tests/daemon-util/test_Countdown.vala
index d271be5..90de583 100644
--- a/tests/daemon-util/test_Countdown.vala
+++ b/tests/daemon-util/test_Countdown.vala
@@ -15,6 +15,10 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Daemon.Util;
+
+namespace BreakTimer.Tests.Daemon.Util {
+
public class test_Countdown : TestSuiteWithActivityMonitor {
public test_Countdown () {
new test_construct ().add_to (this);
@@ -320,4 +324,6 @@ public class test_Countdown : TestSuiteWithActivityMonitor {
assert (countdown.get_time_remaining () == time_remaining);
}
}
-}
\ No newline at end of file
+}
+
+}
diff --git a/tests/daemon-util/test_StatefulTimer.vala b/tests/daemon-util/test_StatefulTimer.vala
index 5a30bc2..6632759 100644
--- a/tests/daemon-util/test_StatefulTimer.vala
+++ b/tests/daemon-util/test_StatefulTimer.vala
@@ -15,6 +15,10 @@
* along with GNOME Break Timer. If not, see <http://www.gnu.org/licenses/>.
*/
+using BreakTimer.Daemon.Util;
+
+namespace BreakTimer.Tests.Daemon.Util {
+
public class test_StatefulTimer : TestSuiteWithActivityMonitor {
/* We won't be able to test the timer mechanics in much detail because,
* internally, it uses GTimer and the (real) system clock. Still, we can
@@ -101,4 +105,6 @@ public class test_StatefulTimer : TestSuiteWithActivityMonitor {
// assert ((int)timer.lap_time () == 5);
}
}
-}
\ No newline at end of file
+}
+
+}
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..2630578
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,30 @@
+# Uses common_dependencies from "src"
+
+tests_lib_sources = [
+ 'tests.vala'
+]
+
+tests_lib_dependencies = [
+ common_lib_dep,
+ daemon_lib_dep,
+ settings_lib_dep
+]
+
+tests_lib = static_library(
+ 'tests',
+ sources: tests_lib_sources,
+ dependencies: tests_lib_dependencies,
+ include_directories: include_directories('.')
+)
+
+tests_lib_dep = declare_dependency(
+ link_with: tests_lib,
+ dependencies: tests_lib_dependencies,
+ include_directories: include_directories('.')
+)
+
+subdir('common')
+subdir('daemon-activity')
+subdir('daemon-timerbreak')
+subdir('daemon-util')
+
diff --git a/tests/tests.vala b/tests/tests.vala
index d0c35f5..1ec2d51 100644
--- a/tests/tests.vala
+++ b/tests/tests.vala
@@ -18,7 +18,13 @@
// GLib's TestSuite and TestCase are compact classes, so we wrap them in real GLib.Objects for convenience
// This base code is partly borrowed from libgee's test suite, at https://git.gnome.org/browse/libgee
-public abstract class SimpleTestSuite : Object {
+using BreakTimer.Common;
+using BreakTimer.Daemon.Activity;
+using BreakTimer.Daemon.Util;
+
+namespace BreakTimer.Tests {
+
+public abstract class SimpleTestSuite : GLib.Object {
private GLib.TestSuite g_test_suite;
private Adaptor[] adaptors = new Adaptor[0];
@@ -63,7 +69,7 @@ public abstract class SimpleTestSuite : Object {
}
}
- public SimpleTestSuite () {
+ protected SimpleTestSuite () {
var name = this.get_name ();
this.g_test_suite = new GLib.TestSuite (name);
}
@@ -93,7 +99,7 @@ public abstract class SimpleTestSuite : Object {
}
}
-public interface SimpleTestCase<T> : Object {
+public interface SimpleTestCase<T> : GLib.Object {
public abstract void run (T context);
public void add_to (SimpleTestSuite test_suite) {
@@ -106,10 +112,10 @@ public interface SimpleTestCase<T> : Object {
}
-class TestRunner : Object {
+public class TestRunner : GLib.Object {
private GLib.TestSuite root_suite;
- private File tmp_dir;
+ private GLib.File tmp_dir;
const string SCHEMA_FILE_NAME = "org.gnome.BreakTimer.gschema.xml";
public TestRunner (ref unowned string[] args, GLib.TestSuite? root_suite = null) {
@@ -126,48 +132,14 @@ class TestRunner : Object {
}
public virtual void global_setup () {
- Environment.set_variable ("LANGUAGE", "C", true);
+ GLib.Environment.set_variable ("LANGUAGE", "C", true);
try {
- var tmp_path = DirUtils.make_tmp ("gnome-break-timer-test-XXXXXX");
- tmp_dir = File.new_for_path (tmp_path);
+ var tmp_path = GLib.DirUtils.make_tmp ("gnome-break-timer-test-XXXXXX");
+ tmp_dir = GLib.File.new_for_path (tmp_path);
} catch (Error e) {
GLib.warning ("Error creating temporary directory for test files: %s".printf (e.message));
}
-
- string target_data_path = Path.build_filename (tmp_dir.get_path (), "share");
- string target_schema_path = Path.build_filename (tmp_dir.get_path (), "share", "glib-2.0",
"schemas");
-
- Environment.set_variable ("GSETTINGS_BACKEND", "memory", true);
-
- var original_data_dirs = Environment.get_variable ("XDG_DATA_DIRS");
- Environment.set_variable ("XDG_DATA_DIRS", "%s:%s".printf (target_data_path, original_data_dirs),
true);
-
- File source_schema_file = File.new_for_path (
- Path.build_filename (get_top_builddir (), "data", SCHEMA_FILE_NAME)
- );
-
- File target_schema_dir = File.new_for_path (target_schema_path);
- try {
- target_schema_dir.make_directory_with_parents ();
- } catch (Error e) {
- GLib.warning ("Error creating directory for schema files: %s", e.message);
- }
-
- File target_schema_file = File.new_for_path (
- Path.build_filename (target_schema_dir.get_path (), SCHEMA_FILE_NAME)
- );
-
- try {
- source_schema_file.copy (target_schema_file, FileCopyFlags.OVERWRITE);
- } catch (Error e) {
- GLib.warning ("Error copying schema file: %s", e.message);
- }
-
- int compile_schemas_result = Posix.system ("glib-compile-schemas %s".printf (target_schema_path));
- if (compile_schemas_result != 0) {
- GLib.warning ("Could not compile schemas in %s", target_schema_path);
- }
}
public virtual void global_teardown () {
@@ -186,12 +158,6 @@ class TestRunner : Object {
this.global_teardown ();
return 0;
}
-
- private static string get_top_builddir () {
- var builddir = Environment.get_variable ("top_builddir");
- if (builddir == null) builddir = "..";
- return builddir;
- }
}
@@ -201,33 +167,33 @@ public class TestSuiteWithActivityMonitor : SimpleTestSuite {
public testable_ActivityMonitorBackend activity_monitor_backend;
public testable_SessionStatus session_status;
public ActivityMonitor activity_monitor;
- public Gee.List<ActivityMonitor.UserActivity?> activity_log;
+ public GLib.List<UserActivity?> activity_log;
- public const int64 START_REAL_TIME = 100000 * Util.MICROSECONDS_IN_SECONDS;
- public const int64 START_MONOTONIC_TIME = 50 * Util.MICROSECONDS_IN_SECONDS;
+ public const int64 START_REAL_TIME = 100000 * TimeUnit.MICROSECONDS_IN_SECONDS;
+ public const int64 START_MONOTONIC_TIME = 50 * TimeUnit.MICROSECONDS_IN_SECONDS;
public override void setup () {
base.setup ();
- Util._do_override_time = true;
- Util._override_real_time = START_REAL_TIME;
- Util._override_monotonic_time = START_MONOTONIC_TIME;
+ TimeUnit._do_override_time = true;
+ TimeUnit._override_real_time = START_REAL_TIME;
+ TimeUnit._override_monotonic_time = START_MONOTONIC_TIME;
- this.activity_log = new Gee.ArrayList<ActivityMonitor.UserActivity?> ();
+ this.activity_log = new GLib.List<UserActivity?> ();
this.refresh_environment ();
}
public override void teardown () {
- Util._do_override_time = false;
- Util._override_real_time = 0;
- Util._override_monotonic_time = 0;
+ TimeUnit._do_override_time = false;
+ TimeUnit._override_real_time = 0;
+ TimeUnit._override_monotonic_time = 0;
}
public virtual void refresh_environment () {
// We keep _override_real_time as it is, because time never goes backward within a test case
- Util._override_monotonic_time = START_MONOTONIC_TIME;
+ TimeUnit._override_monotonic_time = START_MONOTONIC_TIME;
- this.activity_log.clear ();
+ this.activity_log = new GLib.List<UserActivity?> ();
this.activity_monitor_backend = new testable_ActivityMonitorBackend ();
this.session_status = new testable_SessionStatus ();
this.activity_monitor = new ActivityMonitor (session_status, activity_monitor_backend);
@@ -237,14 +203,14 @@ public class TestSuiteWithActivityMonitor : SimpleTestSuite {
}
public virtual void time_step (bool is_active, int real_seconds, int monotonic_seconds) {
- Util._override_real_time += real_seconds * Util.MICROSECONDS_IN_SECONDS;
- Util._override_monotonic_time += monotonic_seconds * Util.MICROSECONDS_IN_SECONDS;
+ TimeUnit._override_real_time += real_seconds * TimeUnit.MICROSECONDS_IN_SECONDS;
+ TimeUnit._override_monotonic_time += monotonic_seconds * TimeUnit.MICROSECONDS_IN_SECONDS;
if (is_active) this.activity_monitor_backend.push_activity ();
this.activity_monitor.poll_activity ();
}
- private void log_activity (ActivityMonitor.UserActivity activity) {
- this.activity_log.add (activity);
+ private void log_activity (UserActivity activity) {
+ this.activity_log.append (activity);
}
}
@@ -252,26 +218,26 @@ public class TestSuiteWithActivityMonitor : SimpleTestSuite {
// We also need special testable implementations of certain classes and interfaces
public class testable_ActivityMonitorBackend : ActivityMonitorBackend {
- public int64 last_event_time = 0;
- public int64 start_time = 0;
+ private int64 start_time_ms = 0;
+ private int64 last_event_time_ms = 0;
public testable_ActivityMonitorBackend () {
- this.start_time = Util.get_monotonic_time_seconds () - 10;
+ this.start_time_ms = TimeUnit.get_monotonic_time_ms () - 10000;
}
public void push_activity () {
- this.last_event_time = Util.get_monotonic_time_seconds ();
+ this.last_event_time_ms = TimeUnit.get_monotonic_time_ms ();
}
- protected override int time_since_last_event () {
- int64 now_monotonic = Util.get_monotonic_time_seconds ();
- int64 event_time = this.last_event_time;
- if (event_time == 0) event_time = this.start_time;
- return (int) (now_monotonic - event_time);
+ protected override uint64 time_since_last_event_ms () {
+ int64 now_monotonic_ms = TimeUnit.get_monotonic_time_ms ();
+ int64 event_time_ms = this.last_event_time_ms;
+ if (event_time_ms == 0) event_time_ms = this.start_time_ms;
+ return now_monotonic_ms - event_time_ms;
}
}
-public class testable_SessionStatus : Object, ISessionStatus {
+public class testable_SessionStatus : GLib.Object, ISessionStatus {
public bool virt_is_locked = false;
public void do_lock () {
@@ -296,3 +262,5 @@ public class testable_SessionStatus : Object, ISessionStatus {
public void unblank_screen () {}
}
+
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]