-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from bhamail/master
Fix 'String index out of range: 5' error when video device file has no s...
- Loading branch information
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...c/test/java/com/github/sarxos/webcam/ds/gstreamer/impl/VideoDeviceFilenameFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.sarxos.webcam.ds.gstreamer.impl; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author Dan Rollo | ||
* Date: 3/8/14 | ||
* Time: 10:44 PM | ||
*/ | ||
public class VideoDeviceFilenameFilterTest { | ||
|
||
/** | ||
* Accept method was failing with exception: String index out of range: 5 | ||
* This occurs on opensuse 11 where video device files do not all have a suffix. The files are created like so: | ||
* $ ls -l /dev/video* | ||
* /dev/video -> video0 | ||
* /dev/video0 | ||
* | ||
* In this case, the link name 'video' is less that 6 characters long, so the filter statement: | ||
* Character.isDigit(name.charAt(5)) | ||
* causes the exception. | ||
* | ||
* Fix is to also check for length before checking for isDigit(). | ||
*/ | ||
@Test | ||
public void testAcceptHandlesShortVideoDeviceFilename() { | ||
final VideoDeviceFilenameFilter videoDeviceFilenameFilter = new VideoDeviceFilenameFilter(); | ||
assertFalse(videoDeviceFilenameFilter.accept(new File("/dev"), "video")); | ||
assertTrue(videoDeviceFilenameFilter.accept(new File("/dev"), "video0")); | ||
} | ||
} |