1
1
/*
2
+ * Copyright (c) 2020 Neil C Smith
3
+ * Copyright (c) 2019 Kezhu Wang
2
4
* Copyright (c) 2018 Antonio Morales
3
5
*
4
6
* This file is part of gstreamer-java.
18
20
*/
19
21
package org .freedesktop .gstreamer ;
20
22
23
+ import java .util .concurrent .atomic .AtomicBoolean ;
24
+
21
25
import static org .junit .Assert .assertEquals ;
22
26
import static org .junit .Assert .assertFalse ;
23
27
import static org .junit .Assert .assertTrue ;
24
28
25
29
import org .freedesktop .gstreamer .glib .Natives ;
26
30
import org .freedesktop .gstreamer .lowlevel .GPointer ;
27
31
import org .freedesktop .gstreamer .lowlevel .GType ;
32
+ import org .freedesktop .gstreamer .util .TestAssumptions ;
28
33
import org .junit .BeforeClass ;
29
34
import org .junit .AfterClass ;
30
- import org .junit .Before ;
31
35
import org .junit .Test ;
32
36
33
37
public class PromiseTest {
@@ -37,7 +41,7 @@ public PromiseTest() {
37
41
38
42
@ BeforeClass
39
43
public static void setUpClass () throws Exception {
40
- Gst .init (Gst .getVersion (), "PromiseTest" , new String [] {} );
44
+ Gst .init (Gst .getVersion (), "PromiseTest" );
41
45
}
42
46
43
47
@ AfterClass
@@ -47,9 +51,8 @@ public static void tearDownClass() throws Exception {
47
51
48
52
@ Test
49
53
public void testReply () {
50
- if (!Gst .testVersion (1 , 14 )) {
51
- return ;
52
- }
54
+ TestAssumptions .requireGstVersion (1 , 14 );
55
+
53
56
Promise promise = new Promise ();
54
57
55
58
promise .reply (null );
@@ -61,9 +64,8 @@ public void testReply() {
61
64
62
65
@ Test
63
66
public void testInterrupt () {
64
- if (!Gst .testVersion (1 , 14 )) {
65
- return ;
66
- }
67
+ TestAssumptions .requireGstVersion (1 , 14 );
68
+
67
69
Promise promise = new Promise ();
68
70
promise .interrupt ();
69
71
@@ -74,9 +76,8 @@ public void testInterrupt() {
74
76
75
77
@ Test
76
78
public void testExpire () {
77
- if (!Gst .testVersion (1 , 14 )) {
78
- return ;
79
- }
79
+ TestAssumptions .requireGstVersion (1 , 14 );
80
+
80
81
Promise promise = new Promise ();
81
82
promise .expire ();
82
83
@@ -87,9 +88,8 @@ public void testExpire() {
87
88
88
89
@ Test
89
90
public void testInvalidateReply () {
90
- if (!Gst .testVersion (1 , 14 )) {
91
- return ;
92
- }
91
+ TestAssumptions .requireGstVersion (1 , 14 );
92
+
93
93
Promise promise = new Promise ();
94
94
Structure data = new Structure ("data" );
95
95
@@ -101,9 +101,8 @@ public void testInvalidateReply() {
101
101
102
102
@ Test
103
103
public void testReplyData () {
104
- if (!Gst .testVersion (1 , 14 )) {
105
- return ;
106
- }
104
+ TestAssumptions .requireGstVersion (1 , 14 );
105
+
107
106
Promise promise = new Promise ();
108
107
Structure data = new Structure ("data" , "test" , GType .UINT , 1 );
109
108
GPointer pointer = Natives .getPointer (data );
@@ -117,25 +116,42 @@ public void testReplyData() {
117
116
118
117
@ Test
119
118
public void testDispose () {
120
- if (!Gst .testVersion (1 , 14 )) {
121
- return ;
122
- }
119
+ TestAssumptions .requireGstVersion (1 , 14 );
120
+
123
121
Promise promise = new Promise ();
124
122
promise .interrupt ();
125
123
promise .dispose ();
126
124
}
127
125
128
126
@ Test
129
127
public void testDisposeWithChangeFunc () {
130
- if (!Gst .testVersion (1 , 14 )) {
131
- return ;
132
- }
128
+ TestAssumptions .requireGstVersion (1 , 14 );
129
+
130
+ Promise promise = new Promise (new Promise .PROMISE_CHANGE () {
131
+ @ Override
132
+ public void onChange (Promise promise ) {
133
+ }
134
+ });
135
+ promise .interrupt ();
136
+ promise .dispose ();
137
+ }
138
+
139
+ @ Test
140
+ public void testChangeFunctionGC () {
141
+ TestAssumptions .requireGstVersion (1 , 14 );
142
+
143
+ final AtomicBoolean onChangeFired = new AtomicBoolean (false );
144
+
133
145
Promise promise = new Promise (new Promise .PROMISE_CHANGE () {
134
146
@ Override
135
147
public void onChange (Promise promise ) {
148
+ onChangeFired .set (true );
136
149
}
137
150
});
151
+ System .gc ();
152
+ System .gc ();
138
153
promise .interrupt ();
154
+ assertTrue ("Promise Change callback GC'd" , onChangeFired .get ());
139
155
promise .dispose ();
140
156
}
141
157
}
0 commit comments