1+ /*
2+ * Copyright (c) 2020 Neil C Smith
3+ * Copyright (c) 2009 Levente Farkas
4+ * Copyright (C) 2009 Tamas Korodi <[email protected] > 5+ * Copyright (C) 2007 Wayne Meissner
6+ *
7+ * This code is free software: you can redistribute it and/or modify it under
8+ * the terms of the GNU Lesser General Public License version 3 only, as
9+ * published by the Free Software Foundation.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14+ * version 3 for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public License
17+ * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
18+ */
119package org .freedesktop .gstreamer ;
220
321import org .freedesktop .gstreamer .glib .GCancellable ;
1129
1230import java .util .Arrays ;
1331import java .util .List ;
32+ import org .freedesktop .gstreamer .util .TestAssumptions ;
1433
1534import static org .junit .Assert .*;
1635
1736public class StructureTest {
18- private Structure structure ;
19-
37+
38+ private Structure structure ;
39+
2040 @ BeforeClass
2141 public static void setUpClass () throws Exception {
22- Gst .init ("StructureTest" , new String [] {} );
42+ Gst .init (Gst . getVersion (), "StructureTest" );
2343 }
24-
44+
2545 @ AfterClass
2646 public static void tearDownClass () throws Exception {
2747 Gst .deinit ();
2848 }
2949
3050 @ Before
3151 public void setUp () {
32- structure = new Structure ("nazgul" );
52+ structure = new Structure ("nazgul" );
3353 }
34-
35- @ Test
36- public void testGetName () {
37- assertEquals ("nazgul" , structure .getName ());
38- }
39-
40- @ Test
41- public void testGetValue () {
42- structure .setValue ("uint" , GType .UINT , 9 );
43- assertEquals (9 , structure .getValue ("uint" ));
44-
45- try {
46- structure .getValue ("noexist" );
47- fail ("Structure.InvalidFieldException should have been thrown" );
48- } catch (Structure .InvalidFieldException e ) {}
49-
50- structure .setDouble ("double" , 9.0 );
51- assertEquals (9.0 , structure .getValue ("double" ));
52-
53- structure .setValue ("bool" , GType .BOOLEAN , true );
54- assertEquals (true , structure .getValue ("bool" ));
55-
56- }
57-
54+
55+ @ Test
56+ public void testGetName () {
57+ assertEquals ("nazgul" , structure .getName ());
58+ }
59+
60+ @ Test
61+ public void testGetValue () {
62+ structure .setValue ("uint" , GType .UINT , 9 );
63+ assertEquals (9 , structure .getValue ("uint" ));
64+
65+ try {
66+ structure .getValue ("noexist" );
67+ fail ("Structure.InvalidFieldException should have been thrown" );
68+ } catch (Structure .InvalidFieldException e ) {
69+ }
70+
71+ structure .setDouble ("double" , 9.0 );
72+ assertEquals (9.0 , structure .getValue ("double" ));
73+
74+ structure .setValue ("bool" , GType .BOOLEAN , true );
75+ assertEquals (true , structure .getValue ("bool" ));
76+
77+ }
78+
5879 @ Test
5980 public void testGetValues () {
6081 GValueAPI .GValueArray ar = new GValueAPI .GValueArray (2 );
@@ -75,16 +96,16 @@ public void testGetValues() {
7596 } catch (Structure .InvalidFieldException ex ) {
7697 }
7798 }
78-
79- @ Test
80- public void testGetInteger () {
81- structure .setInteger ("int" , 9 );
82- assertEquals (9 , structure .getInteger ("int" ));
83-
84- structure .setInteger ("int" , -9 );
85- assertEquals (-9 , structure .getInteger ("int" ));
86- }
87-
99+
100+ @ Test
101+ public void testGetInteger () {
102+ structure .setInteger ("int" , 9 );
103+ assertEquals (9 , structure .getInteger ("int" ));
104+
105+ structure .setInteger ("int" , -9 );
106+ assertEquals (-9 , structure .getInteger ("int" ));
107+ }
108+
88109 @ Test
89110 public void testGetIntegers () {
90111 GValueAPI .GValueArray ar = new GValueAPI .GValueArray (2 );
@@ -96,28 +117,28 @@ public void testGetIntegers() {
96117 assertTrue (in == ints );
97118 assertEquals (32 , ints [0 ]);
98119 assertEquals (-49 , ints [1 ]);
99-
120+
100121 in = new int [1 ];
101122 ints = structure .getIntegers ("integers" , in );
102123 assertFalse (in == ints );
103124 assertEquals (32 , ints [0 ]);
104125 assertEquals (-49 , ints [1 ]);
105-
126+
106127 structure .setInteger ("single_integer" , 18 );
107128 int [] single = structure .getIntegers ("single_integer" , in );
108129 assertTrue (in == single );
109130 assertEquals (18 , single [0 ]);
110131 }
111132
112- @ Test
113- public void testGetDouble () {
114- structure .setDouble ("double" , 9.0 );
115- assertEquals (9.0 , structure .getDouble ("double" ), 0 );
116-
117- structure .setDouble ("double" , -9.0 );
118- assertEquals (-9.0 , structure .getDouble ("double" ), 0 );
119- }
120-
133+ @ Test
134+ public void testGetDouble () {
135+ structure .setDouble ("double" , 9.0 );
136+ assertEquals (9.0 , structure .getDouble ("double" ), 0 );
137+
138+ structure .setDouble ("double" , -9.0 );
139+ assertEquals (-9.0 , structure .getDouble ("double" ), 0 );
140+ }
141+
121142 @ Test
122143 public void testGetDoubles () {
123144 GValueAPI .GValueArray ar = new GValueAPI .GValueArray (2 );
@@ -129,32 +150,32 @@ public void testGetDoubles() {
129150 assertTrue (in == doubles );
130151 assertEquals (3.25 , doubles [0 ], 0.001 );
131152 assertEquals (79.6 , doubles [1 ], 0.001 );
132-
153+
133154 in = new double [1 ];
134155 doubles = structure .getDoubles ("doubles" , in );
135156 assertFalse (in == doubles );
136157 assertEquals (3.25 , doubles [0 ], 0.001 );
137158 assertEquals (79.6 , doubles [1 ], 0.001 );
138-
159+
139160 structure .setDouble ("single_double" , 18.2 );
140161 double [] single = structure .getDoubles ("single_double" , in );
141162 assertTrue (in == single );
142163 assertEquals (18.2 , single [0 ], 0.001 );
143164 }
144165
145- @ Test
146- public void testFraction () {
147- structure .setFraction ("fraction" , 10 , 1 );
166+ @ Test
167+ public void testFraction () {
168+ structure .setFraction ("fraction" , 10 , 1 );
148169
149- assertEquals (true , structure .hasField ("fraction" ));
170+ assertEquals (true , structure .hasField ("fraction" ));
150171
151- assertEquals (10 , structure .getFraction ("fraction" ).getNumerator ());
152- assertEquals (1 , structure .getFraction ("fraction" ).getDenominator ());
172+ assertEquals (10 , structure .getFraction ("fraction" ).getNumerator ());
173+ assertEquals (1 , structure .getFraction ("fraction" ).getDenominator ());
153174
154- structure .setFraction ("fraction" , 17 , 10 );
155- assertEquals (17 , structure .getFraction ("fraction" ).getNumerator ());
156- assertEquals (10 , structure .getFraction ("fraction" ).getDenominator ());
157- }
175+ structure .setFraction ("fraction" , 17 , 10 );
176+ assertEquals (17 , structure .getFraction ("fraction" ).getNumerator ());
177+ assertEquals (10 , structure .getFraction ("fraction" ).getDenominator ());
178+ }
158179
159180 @ Test
160181 public void testValueListInteger () {
@@ -167,7 +188,7 @@ public void testValueListInteger() {
167188 public void testValueListStrings () {
168189 Caps caps = Caps .fromString ("video/x-raw,format={RGB, BGR, RGBx, BGRx}" );
169190 List <String > formats = caps .getStructure (0 ).getValues (String .class , "format" );
170- assertEquals (Arrays .asList ("RGB" , "BGR" , "RGBx" ,"BGRx" ), formats );
191+ assertEquals (Arrays .asList ("RGB" , "BGR" , "RGBx" , "BGRx" ), formats );
171192 }
172193
173194 @ Test (expected = Structure .InvalidFieldException .class )
@@ -182,13 +203,15 @@ public void testSetMistypedObject() {
182203 structure .setObject ("whatever" , Caps .GTYPE_NAME , notACapsInstance );
183204 }
184205
206+ @ Test
185207 public void testSetUntypedObject () {
186208 GCancellable anyKindOfObject = new GCancellable ();
187209 structure .setObject ("whatever" , GType .OBJECT .getTypeName (), anyKindOfObject );
188210 Object value = structure .getValue ("whatever" );
189211 Assert .assertSame (anyKindOfObject , value );
190212 }
191213
214+ @ Test
192215 public void testSetObject () {
193216 GCancellable anyKindOfObject = new GCancellable ();
194217 structure .setObject ("whatever" , GCancellable .GTYPE_NAME , anyKindOfObject );
@@ -202,4 +225,15 @@ public void testSetNullObject() {
202225 Object value = structure .getValue ("whatever" );
203226 Assert .assertNull (value );
204227 }
228+
229+ @ Test
230+ public void testIssue173 () {
231+ TestAssumptions .requireGstVersion (1 , 16 );
232+ TestAssumptions .requireElement ("srtsink" );
233+
234+ Element srtsink = ElementFactory .make ("srtsink" , "srtsink" );
235+ srtsink .set ("uri" , "srt://:8888/" );
236+ Object stats = srtsink .get ("stats" );
237+ assertTrue (stats instanceof Structure );
238+ }
205239}
0 commit comments