Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
218 additions
and
70 deletions.
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
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
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
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
37 changes: 37 additions & 0 deletions
37
webcam-capture/src/test/java/com/github/sarxos/webcam/WebcamTest.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,37 @@ | ||
package com.github.sarxos.webcam; | ||
|
||
import java.util.List; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import com.github.sarxos.webcam.ds.test.DummyDriver; | ||
|
||
|
||
/** | ||
* @author bfiryn | ||
*/ | ||
public class WebcamTest { | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
Webcam.setDriver(DummyDriver.class); | ||
} | ||
|
||
@Test | ||
public void test_getDevices() { | ||
|
||
List<Webcam> webcams = Webcam.getWebcams(); | ||
List<WebcamDevice> devices = DummyDriver.getInstance().getDevices(); | ||
|
||
Assert.assertEquals(devices.size(), webcams.size()); | ||
} | ||
|
||
// @Test | ||
// public void test_setDriver() { | ||
// | ||
// } | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
webcam-capture/src/test/java/com/github/sarxos/webcam/ds/test/DummyDevice.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,77 @@ | ||
package com.github.sarxos.webcam.ds.test; | ||
|
||
import java.awt.Color; | ||
import java.awt.Dimension; | ||
import java.awt.Graphics2D; | ||
import java.awt.image.BufferedImage; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import com.github.sarxos.webcam.WebcamDevice; | ||
import com.github.sarxos.webcam.WebcamException; | ||
|
||
|
||
public class DummyDevice implements WebcamDevice { | ||
|
||
private static final AtomicInteger INSTANCE_NUM = new AtomicInteger(0); | ||
private static final Dimension[] DIMENSIONS = new Dimension[] { | ||
new Dimension(300, 200), | ||
new Dimension(400, 300), | ||
}; | ||
|
||
private String name = DummyDevice.class.getSimpleName() + "-" + INSTANCE_NUM.incrementAndGet(); | ||
private Dimension size = DIMENSIONS[0]; | ||
private boolean open = false; | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Dimension[] getSizes() { | ||
return DIMENSIONS; | ||
} | ||
|
||
@Override | ||
public Dimension getSize() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public void setSize(Dimension size) { | ||
this.size = size; | ||
} | ||
|
||
@Override | ||
public BufferedImage getImage() { | ||
|
||
if (!open) { | ||
throw new WebcamException("Not open"); | ||
} | ||
|
||
BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); | ||
Graphics2D g2 = bi.createGraphics(); | ||
g2.setColor(Color.RED); | ||
g2.fillRect(0, 0, size.width, size.height); | ||
g2.drawString(getName(), 20, 20); | ||
g2.dispose(); | ||
bi.flush(); | ||
|
||
return bi; | ||
} | ||
|
||
@Override | ||
public void open() { | ||
open = true; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
open = false; | ||
} | ||
|
||
public boolean isOpen() { | ||
return open; | ||
} | ||
|
||
} |
Oops, something went wrong.