Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/Main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2026 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/

namespace Gala {
public int main (string[] args) {
TestCase[] test_cases = {
new SetupTest (),
new GestureControllerTest (),
new PropertyTargetTest (),
new SwipeTriggerTest (),
};

Test.init (ref args);
return Test.run ();
}
}
8 changes: 6 additions & 2 deletions tests/MutterTestCase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ public abstract class Gala.MutterTestCase : Gala.TestCase {
"--virtual-monitor", "1280x720@60"
};

protected Meta.Context context { get; private set; }
protected Clutter.Stage stage { get { return (Clutter.Stage) context.get_backend ().get_stage (); } }
protected static Meta.Context? context { get; private set; }
protected static Clutter.Stage? stage { get { return (Clutter.Stage) context?.get_backend ().get_stage (); } }

private MainLoop? main_loop;

construct {
if (context != null) {
Comment thread
lenemter marked this conversation as resolved.
return;
}

context = new Meta.Context ("");

unowned var unowned_args = MUTTER_ARGS;
Expand Down
8 changes: 2 additions & 6 deletions tests/TestCase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
public abstract class Gala.TestCase : Object {
public delegate void TestMethod ();

public string name { get; construct; }

private GLib.TestSuite suite;

construct {
suite = new GLib.TestSuite (name);
suite = new GLib.TestSuite (this.get_class ().get_type ().name ());
}

public int run (string[] args) {
Test.init (ref args);
public override void constructed () {
Comment thread
lenemter marked this conversation as resolved.
TestSuite.get_root ().add_suite ((owned) suite);
return Test.run ();
}

protected void add_test (string name, TestMethod test) {
Expand Down
22 changes: 11 additions & 11 deletions tests/lib/GestureControllerTest.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class Gala.MockTrigger : Object, GestureTrigger {
return true;
}

public override void enable_backends (GestureController controller) {
public void enable_backends (GestureController controller) {
controller.enable_backend (backend);
}
}
Expand Down Expand Up @@ -92,10 +92,7 @@ public class Gala.GestureControllerTest : MutterTestCase {
private MockBackend backend;
private GestureController controller;
private MockTarget target;

public GestureControllerTest () {
Object (name: "GestureControllerTest");
}
private Clutter.Actor actor;

construct {
add_test ("Test basic propagation", test_basic_propagation);
Expand All @@ -105,7 +102,7 @@ public class Gala.GestureControllerTest : MutterTestCase {
public override void set_up () {
base.set_up ();

var actor = new Clutter.Actor ();
actor = new Clutter.Actor ();
stage.add_child (actor);

backend = new MockBackend ();
Expand All @@ -125,11 +122,14 @@ public class Gala.GestureControllerTest : MutterTestCase {
}

public override void tear_down () {
stage.remove_child (target.actor);
if (actor != null) {
stage.remove_child (actor);
}

backend = null;
controller = null;
target = null;
actor = null;

base.tear_down ();
}
Expand Down Expand Up @@ -168,6 +168,10 @@ public class Gala.GestureControllerTest : MutterTestCase {
assert_finalize_object (ref target);
assert_finalize_object (ref controller);
assert_finalize_object (ref backend);

assert_nonnull (&actor);
stage.remove_child (actor);
assert_finalize_object (ref actor);
}

/**
Expand Down Expand Up @@ -201,7 +205,3 @@ public class Gala.GestureControllerTest : MutterTestCase {
run_main_loop ();
}
}

public int main (string[] args) {
return new Gala.GestureControllerTest ().run (args);
}
8 changes: 0 additions & 8 deletions tests/lib/PropertyTargetTest.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ public class Gala.PropertyTargetTest : TestCase {
private MockObject? target;
private PropertyTarget? default_int_prop_target;

public PropertyTargetTest () {
Object (name: "PropertyTarget");
}

construct {
add_test ("simple propagation", test_simple_propagation);
add_test ("double propagation", test_double_propagation);
Expand Down Expand Up @@ -151,7 +147,3 @@ public class Gala.PropertyTargetTest : TestCase {
assert_finalize_object<MockObject> (ref target);
}
}

public int main (string[] args) {
return new Gala.PropertyTargetTest ().run (args);
}
10 changes: 1 addition & 9 deletions tests/lib/SetupTest.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
* and allows us to interact with it, e.g. by creating a Clutter actor.
*/
public class Gala.SetupTest : MutterTestCase {
public SetupTest () {
Object (name: "SetupTest");
}

construct {
add_test ("Test setup successful", test_setup_successful);
add_test ("Test main loop", test_main_loop);
Expand All @@ -39,7 +35,7 @@ public class Gala.SetupTest : MutterTestCase {
var stage = backend.get_stage ();
assert_true (stage != null);
assert_true (stage is Clutter.Stage);
assert_true (this.stage == stage);
assert_true (MutterTestCase.stage == stage);

// Creating an actor requires clutter machinery to be set up, so check this
var actor = new Clutter.Actor ();
Expand Down Expand Up @@ -88,7 +84,3 @@ public class Gala.SetupTest : MutterTestCase {
assert_cmpint (frames, GT, 0);
}
}

public int main (string[] args) {
return new Gala.SetupTest ().run (args);
}
8 changes: 0 additions & 8 deletions tests/lib/SwipeTriggerTest.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ public class Gala.SwipeTriggerTest : MutterTestCase {
private Clutter.Actor? actor;
private SwipeTrigger? trigger;

public SwipeTriggerTest () {
Object (name: "SwipeTriggerTest");
}

construct {
add_test ("Test finalize trigger first", test_finalize_trigger_first);
add_test ("Test finalize actor first", test_finalize_actor_first);
Expand Down Expand Up @@ -56,7 +52,3 @@ public class Gala.SwipeTriggerTest : MutterTestCase {
assert_finalize_object (ref trigger);
}
}

public int main (string[] args) {
return new Gala.SwipeTriggerTest ().run (args);
}
19 changes: 0 additions & 19 deletions tests/lib/meson.build

This file was deleted.

26 changes: 25 additions & 1 deletion tests/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
common_test_sources = files(
'Main.vala',
'MutterTestCase.vala',
'TestCase.vala',
)

subdir('lib')
lib_tests = [
'GestureControllerTest',
'PropertyTargetTest',
'SetupTest',
'SwipeTriggerTest',
]

lib_test_sources = files()
foreach lib_test : lib_tests
lib_test_sources += 'lib' / '@0@.vala'.format(lib_test)
endforeach

test_executable = executable(
'io.elementary.gala.tests',
common_test_sources,
lib_test_sources,
gala_lib_sources,
dependencies: gala_base_dep,
install: false,
)

foreach lib_test : lib_tests
test(lib_test, test_executable, args: ['-p', '/Gala@0@'.format(lib_test)], suite: ['Gala', 'Gala/lib'], is_parallel: false)
endforeach