Skip to content

Commit 6966a23

Browse files
Eukliosbramp
authored andcommitted
Test N/A values in all Progress parser implementations
1 parent 0e8d173 commit 6966a23

File tree

5 files changed

+89
-10
lines changed

5 files changed

+89
-10
lines changed

src/test/java/net/bramp/ffmpeg/fixtures/Progresses.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ private Progresses() {
1010
}
1111

1212
public static final ImmutableList<String> allFiles =
13-
ImmutableList.of("ffmpeg-progress-0", "ffmpeg-progress-1", "ffmpeg-progress-2");
13+
ImmutableList.of(
14+
"ffmpeg-progress-0",
15+
"ffmpeg-progress-1",
16+
"ffmpeg-progress-2");
17+
18+
public static final ImmutableList<String> naProgressFile = ImmutableList.of("ffmpeg-progress-na");
1419

1520
public static final ImmutableList<Progress> allProgresses =
1621
ImmutableList.of(
1722
new Progress(5, 0.0f, 800, 48, 512000000, 0, 0, 1.01f, Progress.Status.CONTINUE),
1823
new Progress(118, 23.4f, -1, -1, 5034667000L, 0, 0, -1, Progress.Status.CONTINUE),
19-
new Progress(
20-
132, 23.1f, 1935500, 1285168, 5312000000L, 0, 0, 0.929f, Progress.Status.END));
24+
new Progress(132, 23.1f, 1935500, 1285168, 5312000000L, 0, 0, 0.929f, Progress.Status.END));
25+
26+
public static final ImmutableList<Progress> naProgresses = ImmutableList.of(
27+
new Progress(0, 0.0f, -1, -1, -1, 0, 0, -1, Progress.Status.END)
28+
);
2129
}

src/test/java/net/bramp/ffmpeg/progress/StreamProgressParserTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.io.IOException;
88
import java.io.InputStream;
9-
import java.util.List;
109
import net.bramp.ffmpeg.fixtures.Progresses;
1110
import org.junit.Test;
1211

@@ -23,6 +22,18 @@ public void testNormal() throws IOException {
2322
InputStream inputStream = combineResource(Progresses.allFiles);
2423
parser.processStream(inputStream);
2524

26-
assertThat(listener.progesses, equalTo((List<Progress>) Progresses.allProgresses));
25+
assertThat(listener.progesses, equalTo(Progresses.allProgresses));
26+
}
27+
28+
@Test
29+
public void testNaProgressPackets() throws IOException {
30+
listener.reset();
31+
32+
StreamProgressParser parser = new StreamProgressParser(listener);
33+
34+
InputStream inputStream = combineResource(Progresses.naProgressFile);
35+
parser.processStream(inputStream);
36+
37+
assertThat(listener.progesses, equalTo(Progresses.naProgresses));
2738
}
2839
}

src/test/java/net/bramp/ffmpeg/progress/TcpProgressParserTest.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.io.OutputStream;
1313
import java.net.Socket;
1414
import java.net.URISyntaxException;
15-
import java.util.List;
1615
import net.bramp.ffmpeg.fixtures.Progresses;
1716
import org.junit.Test;
1817

@@ -44,12 +43,37 @@ public void testNormal() throws IOException, InterruptedException, URISyntaxExce
4443
parser.stop();
4544

4645
assertThat(bytes, greaterThan(0L));
47-
assertThat(progesses, equalTo((List<Progress>) Progresses.allProgresses));
46+
assertThat(progesses, equalTo(Progresses.allProgresses));
47+
}
48+
49+
50+
51+
@Test
52+
public void testNaProgressPackets() throws IOException, InterruptedException, URISyntaxException {
53+
parser.start();
54+
55+
Socket client = new Socket(uri.getHost(), uri.getPort());
56+
assertTrue("Socket is connected", client.isConnected());
57+
58+
InputStream inputStream = combineResource(Progresses.naProgressFile);
59+
OutputStream outputStream = client.getOutputStream();
60+
61+
long bytes = ByteStreams.copy(inputStream, outputStream);
62+
63+
// HACK, but give the TcpProgressParser thread time to actually handle the connection/data
64+
// before the client is closed, and the parser is stopped.
65+
Thread.sleep(100);
66+
67+
client.close();
68+
parser.stop();
69+
70+
assertThat(bytes, greaterThan(0L));
71+
assertThat(progesses, equalTo(Progresses.naProgresses));
4872
}
4973

5074
@Test
5175
public void testPrematureDisconnect()
52-
throws IOException, InterruptedException, URISyntaxException {
76+
throws IOException {
5377
parser.start();
5478
new Socket(uri.getHost(), uri.getPort()).close();
5579
parser.stop();

src/test/java/net/bramp/ffmpeg/progress/UdpProgressParserTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public ProgressParser newParser(ProgressListener listener)
2424
}
2525

2626
@Test
27-
public void testNormal() throws IOException, InterruptedException, URISyntaxException {
27+
public void testNormal() throws IOException, InterruptedException {
2828
parser.start();
2929

3030
final InetAddress addr = InetAddress.getByName(uri.getHost());
@@ -41,10 +41,35 @@ public void testNormal() throws IOException, InterruptedException, URISyntaxExce
4141
}
4242
}
4343

44+
Thread.sleep(1000); // HACK: Wait a short while to avoid closing the receiving socket
45+
46+
parser.stop();
47+
48+
assertThat(progesses, equalTo(Progresses.allProgresses));
49+
}
50+
51+
@Test
52+
public void testNaProgressPackets() throws IOException, InterruptedException, URISyntaxException {
53+
parser.start();
54+
55+
final InetAddress addr = InetAddress.getByName(uri.getHost());
56+
final int port = uri.getPort();
57+
58+
try (DatagramSocket socket = new DatagramSocket()) {
59+
// Load each Progress Fixture, and send in a single datagram packet
60+
for (String progressFixture : Progresses.naProgressFile) {
61+
InputStream inputStream = loadResource(progressFixture);
62+
byte[] bytes = ByteStreams.toByteArray(inputStream);
63+
64+
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, addr, port);
65+
socket.send(packet);
66+
}
67+
}
68+
4469
Thread.sleep(100); // HACK: Wait a short while to avoid closing the receiving socket
4570

4671
parser.stop();
4772

48-
assertThat(progesses, equalTo((List<Progress>) Progresses.allProgresses));
73+
assertThat(progesses, equalTo(Progresses.naProgresses));
4974
}
5075
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
frame=0
2+
fps=0
3+
stream_0_0_q=-1.0
4+
bitrate=N/A
5+
total_size=N/A
6+
out_time_ms=N/A
7+
out_time=N/A
8+
dup_frames=0
9+
drop_frames=0
10+
speed=N/A
11+
progress=end

0 commit comments

Comments
 (0)