Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/org/rocstreaming/roctoolkit/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ static String notEmpty(String value, String name) {
}
return value;
}

static int notNegative(int value, String name) {
if (value < 0) {
throw new IllegalArgumentException(name + " must not be negative");
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class RocContextConfig {
private int maxFrameSize;

private RocContextConfig(int maxPacketSize, int maxFrameSize) {
this.maxPacketSize = maxPacketSize;
this.maxFrameSize = maxFrameSize;
this.maxPacketSize = Check.notNegative(maxPacketSize, "maxPacketSize");
this.maxFrameSize = Check.notNegative(maxFrameSize, "maxFrameSize");
}

/**
Expand Down Expand Up @@ -71,14 +71,14 @@ public int getMaxPacketSize() {
}

public void setMaxPacketSize(int maxPacketSize) {
this.maxPacketSize = maxPacketSize;
this.maxPacketSize = Check.notNegative(maxPacketSize, "maxPacketSize");
}

public int getMaxFrameSize() {
return maxFrameSize;
}

public void setMaxFrameSize(int maxFrameSize) {
this.maxFrameSize = maxFrameSize;
this.maxFrameSize = Check.notNegative(maxFrameSize, "maxFrameSize");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private RocReceiverConfig(
long noPlaybackTimeout,
long brokenPlaybackTimeout,
long breakageDetectionWindow) {
this.frameSampleRate = frameSampleRate;
this.frameSampleRate = Check.notNegative(frameSampleRate, "frameSampleRate");
this.frameChannels = frameChannels;
this.frameEncoding = frameEncoding;
this.clockSource = clockSource;
Expand Down Expand Up @@ -220,7 +220,7 @@ public int getFrameSampleRate() {
}

public void setFrameSampleRate(int frameSampleRate) {
this.frameSampleRate = frameSampleRate;
this.frameSampleRate = Check.notNegative(frameSampleRate, "frameSampleRate");
}

public ChannelSet getFrameChannels() {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/rocstreaming/roctoolkit/RocSenderConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ private RocSenderConfig(
FecEncoding fecEncoding,
int fecBlockSourcePackets,
int fecBlockRepairPackets) {
this.frameSampleRate = frameSampleRate;
this.frameSampleRate = Check.notNegative(frameSampleRate, "frameSampleRate");
this.frameChannels = frameChannels;
this.frameEncoding = frameEncoding;
this.packetSampleRate = packetSampleRate;
this.packetSampleRate = Check.notNegative(packetSampleRate, "packetSampleRate");
this.packetChannels = packetChannels;
this.packetEncoding = packetEncoding;
this.packetLength = packetLength;
Expand All @@ -52,8 +52,8 @@ private RocSenderConfig(
this.resamplerBackend = resamplerBackend;
this.resamplerProfile = resamplerProfile;
this.fecEncoding = fecEncoding;
this.fecBlockSourcePackets = fecBlockSourcePackets;
this.fecBlockRepairPackets = fecBlockRepairPackets;
this.fecBlockSourcePackets = Check.notNegative(fecBlockSourcePackets, "fecBlockSourcePackets");
this.fecBlockRepairPackets = Check.notNegative(fecBlockRepairPackets, "fecBlockRepairPackets");
}

/**
Expand Down Expand Up @@ -235,7 +235,7 @@ public int getFrameSampleRate() {
}

public void setFrameSampleRate(int frameSampleRate) {
this.frameSampleRate = frameSampleRate;
this.frameSampleRate = Check.notNegative(frameSampleRate, "frameSampleRate");
}

public ChannelSet getFrameChannels() {
Expand All @@ -259,7 +259,7 @@ public int getPacketSampleRate() {
}

public void setPacketSampleRate(int packetSampleRate) {
this.packetSampleRate = packetSampleRate;
this.packetSampleRate = Check.notNegative(packetSampleRate, "packetSampleRate");
}

public ChannelSet getPacketChannels() {
Expand Down Expand Up @@ -331,14 +331,14 @@ public int getFecBlockSourcePackets() {
}

public void setFecBlockSourcePackets(int fecBlockSourcePackets) {
this.fecBlockSourcePackets = fecBlockSourcePackets;
this.fecBlockSourcePackets = Check.notNegative(fecBlockSourcePackets, "fecBlockSourcePackets");
}

public int getFecBlockRepairPackets() {
return fecBlockRepairPackets;
}

public void setFecBlockRepairPackets(int fecBlockRepairPackets) {
this.fecBlockRepairPackets = fecBlockRepairPackets;
this.fecBlockRepairPackets = Check.notNegative(fecBlockRepairPackets, "fecBlockRepairPackets");
}
}
16 changes: 15 additions & 1 deletion src/test/java/org/rocstreaming/roctoolkit/RocContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,21 @@ public void testWithInvalidConfig() {
IllegalArgumentException.class,
() -> new RocContext(new RocContextConfig.Builder().maxPacketSize(-1).maxFrameSize(-1).build())
);
assertEquals("Wrong context configuration values", e.getMessage());
assertEquals("maxPacketSize must not be negative", e.getMessage());
}

@Test
public void testSetNegativeMaxPacketSize() {
RocContextConfig config = new RocContextConfig.Builder().maxPacketSize(1).maxFrameSize(1).build();
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> config.setMaxPacketSize(-1));
assertEquals("maxPacketSize must not be negative", e.getMessage());
}

@Test
public void testSetNegativeMaxFrameSize() {
RocContextConfig config = new RocContextConfig.Builder().maxPacketSize(1).maxFrameSize(1).build();
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> config.setMaxFrameSize(-1));
assertEquals("maxFrameSize must not be negative", e.getMessage());
}

@Test
Expand Down
19 changes: 14 additions & 5 deletions src/test/java/org/rocstreaming/roctoolkit/RocReceiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ private static Stream<Arguments> testInvalidCreationArguments() throws Exception
IllegalArgumentException.class,
new RocContext(),
null),
Arguments.of(
"Bad config argument",
IllegalArgumentException.class,
new RocContext(),
new RocReceiverConfig.Builder(-1, ChannelSet.STEREO, FrameEncoding.PCM_FLOAT).build()),
Arguments.of(
"Error opening receiver",
Exception.class,
Expand All @@ -106,6 +101,20 @@ public void testInvalidCreation(String errorMessage, Class<Exception> exceptionC
assertEquals(errorMessage, exception.getMessage());
}

@Test
public void testInvalidConfig() {
Exception exception = assertThrows(IllegalArgumentException.class,
() -> new RocReceiverConfig.Builder(-1, ChannelSet.STEREO, FrameEncoding.PCM_FLOAT).build());
assertEquals("frameSampleRate must not be negative", exception.getMessage());
}

@Test
public void testSetNegativeFrameSampleRate() {
RocReceiverConfig config = new RocReceiverConfig.Builder(1, ChannelSet.STEREO, FrameEncoding.PCM_FLOAT).build();
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> config.setFrameSampleRate(-1));
assertEquals("frameSampleRate must not be negative", e.getMessage());
}

private static Stream<Arguments> testInvalidSetMulticastGroupArguments() {
return Stream.of(
Arguments.of(
Expand Down
40 changes: 35 additions & 5 deletions src/test/java/org/rocstreaming/roctoolkit/RocSenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ private static Stream<Arguments> testInvalidCreationArguments() throws Exception
IllegalArgumentException.class,
new RocContext(),
null),
Arguments.of(
"Bad config argument",
IllegalArgumentException.class,
new RocContext(),
new RocSenderConfig.Builder(-1, ChannelSet.STEREO, FrameEncoding.PCM_FLOAT).build()),
Arguments.of(
"Error opening sender",
Exception.class,
Expand All @@ -123,6 +118,41 @@ public void testInvalidCreation(String errorMessage, Class<Exception> exceptionC
assertEquals(errorMessage, exception.getMessage());
}

@Test
public void testInvalidConfig() {
Exception exception = assertThrows(IllegalArgumentException.class,
() -> new RocSenderConfig.Builder(-1, ChannelSet.STEREO, FrameEncoding.PCM_FLOAT).build());
assertEquals("frameSampleRate must not be negative", exception.getMessage());
}

@Test
public void testSetNegativeFrameSampleRate() {
RocSenderConfig config = new RocSenderConfig.Builder(1, ChannelSet.STEREO, FrameEncoding.PCM_FLOAT).build();
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> config.setFrameSampleRate(-1));
assertEquals("frameSampleRate must not be negative", e.getMessage());
}

@Test
public void testSetNegativePacketSampleRate() {
RocSenderConfig config = new RocSenderConfig.Builder(1, ChannelSet.STEREO, FrameEncoding.PCM_FLOAT).build();
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> config.setPacketSampleRate(-1));
assertEquals("packetSampleRate must not be negative", e.getMessage());
}

@Test
public void testSetNegativeFecBlockSourcePackets() {
RocSenderConfig config = new RocSenderConfig.Builder(1, ChannelSet.STEREO, FrameEncoding.PCM_FLOAT).build();
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> config.setFecBlockSourcePackets(-1));
assertEquals("fecBlockSourcePackets must not be negative", e.getMessage());
}

@Test
public void testSetNegativeFecBlockRepairPackets() {
RocSenderConfig config = new RocSenderConfig.Builder(1, ChannelSet.STEREO, FrameEncoding.PCM_FLOAT).build();
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> config.setFecBlockRepairPackets(-1));
assertEquals("fecBlockRepairPackets must not be negative", e.getMessage());
}

private static Stream<Arguments> testInvalidSetOutgoingAddressArguments() {
return Stream.of(
Arguments.of(
Expand Down