-
-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathTestCase.vala
More file actions
48 lines (39 loc) · 1.27 KB
/
TestCase.vala
File metadata and controls
48 lines (39 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
/**
* A simple test case class. To use it inherit from it and add test methods
* in the constructor using {@link add_test}. Override {@link set_up} and {@link tear_down}
* to provide per-test-method setup and teardown. Then add a `main()` function
* and return the result of {@link run}.
*/
public abstract class Gala.TestCase : Object {
public delegate void TestMethod ();
private GLib.TestSuite suite;
construct {
suite = new GLib.TestSuite (this.get_class ().get_type ().name ());
}
public override void constructed () {
TestSuite.get_root ().add_suite ((owned) suite);
}
protected void add_test (string name, TestMethod test) {
var test_case = new GLib.TestCase (
name,
set_up,
(TestFixtureFunc) test,
tear_down
);
suite.add ((owned) test_case);
}
public virtual void set_up () {
}
public virtual void tear_down () {
}
public void assert_finalize_object<G> (ref G data) {
unowned var weak_pointer = data;
((Object) data).add_weak_pointer (&weak_pointer);
data = null;
assert_null (weak_pointer);
}
}