File tree Expand file tree Collapse file tree 4 files changed +38
-5
lines changed
src/org/freedesktop/gstreamer
test/org/freedesktop/gstreamer Expand file tree Collapse file tree 4 files changed +38
-5
lines changed Original file line number Diff line number Diff line change 1313
1414# NetBeans Files #
1515/nbproject /
16- nb-configuration.xml
16+ nb-configuration.xml
17+
18+ .idea
Original file line number Diff line number Diff line change 1- /*
1+ /*
22 * Copyright (c) 2019 Neil C Smith
3- *
3+ *
44 * This file is part of gstreamer-java.
55 *
66 * This code is free software: you can redistribute it and/or modify it under
2323 * @param <T> Java enum type
2424 */
2525public interface NativeEnum <T extends Enum <T >> {
26-
26+
2727 public int intValue ();
2828
29+ public static <T extends Enum <T > & NativeEnum <T >> T fromInt (Class <T > type , int intValue ) {
30+ for (T value : type .getEnumConstants ()) {
31+ if (value .intValue () == intValue ) {
32+ return value ;
33+ }
34+ }
35+
36+ throw new IllegalArgumentException ("Value " + intValue + " is unacceptable for " +
37+ type .getSimpleName () + " enum" );
38+ }
39+
2940}
Original file line number Diff line number Diff line change 2424import org .freedesktop .gstreamer .Promise ;
2525import org .freedesktop .gstreamer .Structure ;
2626
27+ import org .freedesktop .gstreamer .glib .NativeEnum ;
2728import org .freedesktop .gstreamer .lowlevel .GstAPI .GstCallback ;
2829
2930/**
@@ -262,7 +263,7 @@ public String getTurnServer() {
262263 * state
263264 */
264265 public WebRTCPeerConnectionState getConnectionState () {
265- return (WebRTCPeerConnectionState ) get ("connection-state" );
266+ return NativeEnum . fromInt (WebRTCPeerConnectionState . class , ( Integer ) get ("connection-state" ) );
266267 }
267268
268269 /**
Original file line number Diff line number Diff line change 1+ package org .freedesktop .gstreamer ;
2+
3+ import org .freedesktop .gstreamer .glib .NativeEnum ;
4+ import org .freedesktop .gstreamer .webrtc .WebRTCPeerConnectionState ;
5+ import org .junit .Test ;
6+
7+ import static org .junit .Assert .assertEquals ;
8+
9+ public class WebRTCBinTest {
10+ @ Test
11+ public void connectionStateTest () {
12+ assertEquals (NativeEnum .fromInt (WebRTCPeerConnectionState .class , 0 ), WebRTCPeerConnectionState .NEW );
13+ assertEquals (NativeEnum .fromInt (WebRTCPeerConnectionState .class , 1 ), WebRTCPeerConnectionState .CONNECTING );
14+ assertEquals (NativeEnum .fromInt (WebRTCPeerConnectionState .class , 2 ), WebRTCPeerConnectionState .CONNECTED );
15+ assertEquals (NativeEnum .fromInt (WebRTCPeerConnectionState .class , 3 ), WebRTCPeerConnectionState .DISCONNECTED );
16+ assertEquals (NativeEnum .fromInt (WebRTCPeerConnectionState .class , 4 ), WebRTCPeerConnectionState .FAILED );
17+ assertEquals (NativeEnum .fromInt (WebRTCPeerConnectionState .class , 5 ), WebRTCPeerConnectionState .CLOSED );
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments