mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
UsbCamera: Make setConnectVerbose public and add test (#1240)
This commit is contained in:
committed by
Peter Johnson
parent
75a67202e5
commit
011f0ff536
@@ -52,7 +52,7 @@ public class UsbCamera extends VideoCamera {
|
||||
*
|
||||
* @param level 0=don't display Connecting message, 1=do display message
|
||||
*/
|
||||
void setConnectVerbose(int level) {
|
||||
public void setConnectVerbose(int level) {
|
||||
CameraServerJNI.setProperty(CameraServerJNI.getSourceProperty(m_handle, "connect_verbose"),
|
||||
level);
|
||||
}
|
||||
|
||||
65
cscore/src/test/java/edu/wpi/cscore/UsbCameraTest.java
Normal file
65
cscore/src/test/java/edu/wpi/cscore/UsbCameraTest.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.cscore;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs;
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class UsbCameraTest {
|
||||
@Nested
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
class ConnectVerbose {
|
||||
@Test
|
||||
void setConnectVerboseEnabledTest() {
|
||||
try (UsbCamera camera = new UsbCamera("Nonexistant Camera", getNonexistentCameraDev())) {
|
||||
camera.setConnectVerbose(1);
|
||||
|
||||
CompletableFuture<String> result = new CompletableFuture<>();
|
||||
CameraServerJNI.setLogger((level, file, line, message) -> {
|
||||
result.complete(message);
|
||||
}, 20);
|
||||
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(5),
|
||||
() -> assertTrue(result.get().contains("Connecting to USB camera on ")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void setConnectVerboseDisabledTest() {
|
||||
try (UsbCamera camera = new UsbCamera("Nonexistant Camera", getNonexistentCameraDev())) {
|
||||
camera.setConnectVerbose(0);
|
||||
|
||||
CompletableFuture<String> result = new CompletableFuture<>();
|
||||
CameraServerJNI.setLogger((level, file, line, message) -> {
|
||||
result.complete(message);
|
||||
}, 20);
|
||||
|
||||
assertThrows(TimeoutException.class,
|
||||
() -> result.get(3, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int getNonexistentCameraDev() {
|
||||
return Arrays.stream(CameraServerJNI.enumerateUsbCameras())
|
||||
.mapToInt(info -> info.dev)
|
||||
.max().orElseGet(() -> -1) + 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user