11/*  
2+  * Copyright (c) 2020 Neil C Smith 
3+  * Copyright (c) 2019 Kezhu Wang 
24 * Copyright (c) 2018 Antonio Morales 
35 *  
46 * This file is part of gstreamer-java. 
1820 */ 
1921package  org .freedesktop .gstreamer ;
2022
23+ import  java .util .concurrent .atomic .AtomicBoolean ;
24+ 
2125import  static  org .junit .Assert .assertEquals ;
2226import  static  org .junit .Assert .assertFalse ;
2327import  static  org .junit .Assert .assertTrue ;
2428
2529import  org .freedesktop .gstreamer .glib .Natives ;
2630import  org .freedesktop .gstreamer .lowlevel .GPointer ;
2731import  org .freedesktop .gstreamer .lowlevel .GType ;
32+ import  org .freedesktop .gstreamer .util .TestAssumptions ;
2833import  org .junit .BeforeClass ;
2934import  org .junit .AfterClass ;
30- import  org .junit .Before ;
3135import  org .junit .Test ;
3236
3337public  class  PromiseTest  {
@@ -37,7 +41,7 @@ public PromiseTest() {
3741
3842    @ BeforeClass 
3943    public  static  void  setUpClass () throws  Exception  {
40-         Gst .init (Gst .getVersion (), "PromiseTest" ,  new   String [] {} );
44+         Gst .init (Gst .getVersion (), "PromiseTest" );
4145    }
4246
4347    @ AfterClass 
@@ -47,9 +51,8 @@ public static void tearDownClass() throws Exception {
4751
4852    @ Test 
4953    public  void  testReply () {
50-         if  (!Gst .testVersion (1 , 14 )) {
51-             return ;
52-         }
54+         TestAssumptions .requireGstVersion (1 , 14 );
55+         
5356        Promise  promise  = new  Promise ();
5457
5558        promise .reply (null );
@@ -61,9 +64,8 @@ public void testReply() {
6164
6265    @ Test 
6366    public  void  testInterrupt () {
64-         if  (!Gst .testVersion (1 , 14 )) {
65-             return ;
66-         }
67+         TestAssumptions .requireGstVersion (1 , 14 );
68+         
6769        Promise  promise  = new  Promise ();
6870        promise .interrupt ();
6971
@@ -74,9 +76,8 @@ public void testInterrupt() {
7476
7577    @ Test 
7678    public  void  testExpire () {
77-         if  (!Gst .testVersion (1 , 14 )) {
78-             return ;
79-         }
79+         TestAssumptions .requireGstVersion (1 , 14 );
80+         
8081        Promise  promise  = new  Promise ();
8182        promise .expire ();
8283
@@ -87,9 +88,8 @@ public void testExpire() {
8788
8889    @ Test 
8990    public  void  testInvalidateReply () {
90-         if  (!Gst .testVersion (1 , 14 )) {
91-             return ;
92-         }
91+         TestAssumptions .requireGstVersion (1 , 14 );
92+         
9393        Promise  promise  = new  Promise ();
9494        Structure  data  = new  Structure ("data" );
9595
@@ -101,9 +101,8 @@ public void testInvalidateReply() {
101101
102102    @ Test 
103103    public  void  testReplyData () {
104-         if  (!Gst .testVersion (1 , 14 )) {
105-             return ;
106-         }
104+         TestAssumptions .requireGstVersion (1 , 14 );
105+         
107106        Promise  promise  = new  Promise ();
108107        Structure  data  = new  Structure ("data" , "test" , GType .UINT , 1 );
109108        GPointer  pointer  = Natives .getPointer (data );
@@ -117,25 +116,42 @@ public void testReplyData() {
117116
118117    @ Test 
119118    public  void  testDispose () {
120-         if  (!Gst .testVersion (1 , 14 )) {
121-             return ;
122-         }
119+         TestAssumptions .requireGstVersion (1 , 14 );
120+         
123121        Promise  promise  = new  Promise ();
124122        promise .interrupt ();
125123        promise .dispose ();
126124    }
127125
128126    @ Test 
129127    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+         
133145        Promise  promise  = new  Promise (new  Promise .PROMISE_CHANGE () {
134146            @ Override 
135147            public  void  onChange (Promise  promise ) {
148+                 onChangeFired .set (true );
136149            }
137150        });
151+         System .gc ();
152+         System .gc ();
138153        promise .interrupt ();
154+         assertTrue ("Promise Change callback GC'd" , onChangeFired .get ());
139155        promise .dispose ();
140156    }
141157}
0 commit comments