-
-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathPropertyTargetTest.vala
More file actions
149 lines (113 loc) · 5.25 KB
/
PropertyTargetTest.vala
File metadata and controls
149 lines (113 loc) · 5.25 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Copyright 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
public class MockObject : Object {
public int int_value { get; set; }
public double double_value { get; set; }
}
public class Gala.PropertyTargetTest : TestCase {
private MockObject? target;
private PropertyTarget? default_int_prop_target;
construct {
add_test ("simple propagation", test_simple_propagation);
add_test ("double propagation", test_double_propagation);
add_test ("other actions", test_other_actions);
add_test ("finalize object first", test_finalize_object_first);
add_test ("finalize property target first", test_finalize_property_target_first);
}
public override void set_up () {
target = new MockObject ();
default_int_prop_target = new PropertyTarget (
MULTITASKING_VIEW,
target,
"int-value",
typeof (int),
0,
10
);
}
public override void tear_down () {
target = null;
default_int_prop_target = null;
}
private void test_simple_propagation () {
assert_nonnull (&default_int_prop_target);
assert_nonnull (&target);
assert_cmpint (target.int_value, EQ, 0);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.0);
assert_cmpint (target.int_value, EQ, 0);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.5);
assert_cmpint (target.int_value, EQ, 5);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 1.0);
assert_cmpint (target.int_value, EQ, 10);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.8);
assert_cmpint (target.int_value, EQ, 8);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.3);
assert_cmpint (target.int_value, EQ, 3);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.6);
assert_cmpint (target.int_value, EQ, 6);
assert_finalize_object<MockObject> (ref target);
assert_finalize_object<PropertyTarget> (ref default_int_prop_target);
}
private void test_double_propagation () {
var double_prop_target = new PropertyTarget (
MULTITASKING_VIEW,
target,
"double-value",
typeof (double),
0.0,
2.0
);
assert_nonnull (&double_prop_target);
assert_nonnull (&target);
assert_cmpfloat (target.double_value, EQ, 0.0);
double_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.0);
assert_cmpfloat (target.double_value, EQ, 0.0);
double_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.5);
assert_cmpfloat (target.double_value, EQ, 1.0);
double_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 1.0);
assert_cmpfloat (target.double_value, EQ, 2.0);
double_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.8);
assert_cmpfloat (target.double_value, EQ, 1.6);
double_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.3);
assert_cmpfloat (target.double_value, EQ, 0.6);
double_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.6);
assert_cmpfloat (target.double_value, EQ, 1.2);
assert_finalize_object<MockObject> (ref target);
assert_finalize_object<PropertyTarget> (ref double_prop_target);
}
private void test_other_actions () {
assert_nonnull (&default_int_prop_target);
assert_nonnull (&target);
assert_cmpint (target.int_value, EQ, 0);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.0);
assert_cmpint (target.int_value, EQ, 0);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.5);
assert_cmpint (target.int_value, EQ, 5);
default_int_prop_target.propagate (UPDATE, SWITCH_WORKSPACE, 1.0);
assert_cmpint (target.int_value, EQ, 5);
default_int_prop_target.propagate (UPDATE, CUSTOM, 1.0);
assert_cmpint (target.int_value, EQ, 5);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 1.0);
assert_cmpint (target.int_value, EQ, 10);
assert_finalize_object<MockObject> (ref target);
assert_finalize_object<PropertyTarget> (ref default_int_prop_target);
}
private void test_finalize_object_first () {
assert_nonnull (&target);
assert_nonnull (&default_int_prop_target);
// We can finalize the object before the property target because it doesn't hold a strong reference to it
assert_finalize_object<MockObject> (ref target);
default_int_prop_target.propagate (UPDATE, MULTITASKING_VIEW, 0.5);
assert_finalize_object<PropertyTarget> (ref default_int_prop_target);
}
private void test_finalize_property_target_first () {
assert_nonnull (&target);
assert_nonnull (&default_int_prop_target);
// Finalize the property target before the object and make sure we don't have weak references
// to the object (i.e. we don't crash when finalizing the object)
assert_finalize_object<PropertyTarget> (ref default_int_prop_target);
assert_finalize_object<MockObject> (ref target);
}
}