File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2025 elementary, Inc. (https://elementary.io)
3+ * SPDX-License-Identifier: GPL-3.0-or-later
4+ */
5+
6+ /**
7+ * A simple test case class. To use it inherit from it and add test methods
8+ * in the constructor using {@link add_test}. Override {@link set_up} and {@link tear_down}
9+ * to provide per-test-method setup and teardown. Then add a `main()` function
10+ * and return the result of {@link run}.
11+ */
12+ public abstract class Gala.TestCase : Object {
13+ public delegate void TestMethod ();
14+
15+ public string name { get ; construct; }
16+
17+ private GLib . TestSuite suite;
18+
19+ construct {
20+ suite = new GLib .TestSuite (name);
21+ }
22+
23+ public int run (string [] args ) {
24+ Test . init (ref args);
25+ TestSuite . get_root (). add_suite ((owned ) suite);
26+ return Test . run ();
27+ }
28+
29+ protected void add_test (string name , TestMethod test ) {
30+ var test_case = new GLib .TestCase (
31+ name,
32+ set_up,
33+ (TestFixtureFunc ) test,
34+ tear_down
35+ );
36+
37+ suite. add ((owned ) test_case);
38+ }
39+
40+ public virtual void set_up () {
41+ }
42+
43+ public virtual void tear_down () {
44+ }
45+
46+ public void assert_finalize_object<G> (ref G data) {
47+ unowned var weak_pointer = data;
48+ ((Object ) data). add_weak_pointer (&weak_pointer);
49+ data = null ;
50+ assert_null (weak_pointer);
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments