-
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.
- Loading branch information
Showing
3 changed files
with
174 additions
and
9 deletions.
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
webcam-capture/src/test/java/com/github/sarxos/webcam/WebcamPanelTest.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,149 @@ | ||
package com.github.sarxos.webcam; | ||
|
||
import java.awt.Dimension; | ||
import java.awt.image.BufferedImage; | ||
|
||
import javax.swing.JFrame; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
|
||
import com.github.sarxos.webcam.WebcamPanel.DrawMode; | ||
import com.github.sarxos.webcam.ds.test.DummyDriver; | ||
|
||
|
||
public class WebcamPanelTest { | ||
|
||
@Test | ||
public void test_size() throws InterruptedException { | ||
|
||
Webcam.setDriver(new DummyDriver()); | ||
|
||
final Webcam w = Webcam.getDefault(); | ||
final WebcamPanel p = new WebcamPanel(w); | ||
|
||
w.open(); | ||
p.repaint(); | ||
|
||
final BufferedImage bi = w.getImage(); | ||
final Dimension d = p.getPreferredSize(); | ||
|
||
Assertions | ||
.assertThat(d.getWidth()) | ||
.isEqualTo(bi.getWidth()); | ||
Assertions | ||
.assertThat(d.getHeight()) | ||
.isEqualTo(bi.getHeight()); | ||
|
||
p.stop(); | ||
w.close(); | ||
} | ||
|
||
@Test | ||
public void test_sizeSpecified() throws InterruptedException { | ||
|
||
Webcam.setDriver(new DummyDriver()); | ||
|
||
final Webcam w = Webcam.getDefault(); | ||
final WebcamPanel p = new WebcamPanel(w, new Dimension(256, 345), false); | ||
|
||
w.open(); | ||
p.repaint(); | ||
|
||
final Dimension d = p.getPreferredSize(); | ||
|
||
Assertions | ||
.assertThat(d.getWidth()) | ||
.isEqualTo(256); | ||
Assertions | ||
.assertThat(d.getHeight()) | ||
.isEqualTo(345); | ||
|
||
p.stop(); | ||
w.close(); | ||
} | ||
|
||
@Test | ||
public void test_modeFill() throws InterruptedException { | ||
|
||
Webcam.setDriver(new DummyDriver()); | ||
|
||
final Webcam w = Webcam.getDefault(); | ||
w.open(); | ||
|
||
final WebcamPanel p = new WebcamPanel(w, new Dimension(256, 345), false); | ||
p.setDrawMode(DrawMode.FILL); | ||
p.start(); | ||
|
||
Assertions | ||
.assertThat(p.getDrawMode()) | ||
.isEqualTo(DrawMode.FILL); | ||
|
||
final JFrame frame = new JFrame(); | ||
frame.setContentPane(p); | ||
frame.pack(); | ||
|
||
Thread.sleep(100); | ||
|
||
frame.dispose(); | ||
|
||
p.stop(); | ||
w.close(); | ||
} | ||
|
||
@Test | ||
public void test_modeFit() throws InterruptedException { | ||
|
||
Webcam.setDriver(new DummyDriver()); | ||
|
||
final Webcam w = Webcam.getDefault(); | ||
w.open(); | ||
|
||
final WebcamPanel p = new WebcamPanel(w, new Dimension(256, 345), false); | ||
p.setDrawMode(DrawMode.FIT); | ||
p.start(); | ||
|
||
Assertions | ||
.assertThat(p.getDrawMode()) | ||
.isEqualTo(DrawMode.FIT); | ||
|
||
final JFrame frame = new JFrame(); | ||
frame.setContentPane(p); | ||
frame.pack(); | ||
|
||
Thread.sleep(100); | ||
|
||
frame.dispose(); | ||
|
||
p.stop(); | ||
w.close(); | ||
} | ||
|
||
@Test | ||
public void test_modeNone() throws InterruptedException { | ||
|
||
Webcam.setDriver(new DummyDriver()); | ||
|
||
final Webcam w = Webcam.getDefault(); | ||
w.open(); | ||
|
||
final WebcamPanel p = new WebcamPanel(w, new Dimension(256, 345), false); | ||
p.setDrawMode(DrawMode.NONE); | ||
p.start(); | ||
|
||
Assertions | ||
.assertThat(p.getDrawMode()) | ||
.isEqualTo(DrawMode.NONE); | ||
|
||
final JFrame frame = new JFrame(); | ||
frame.setContentPane(p); | ||
frame.pack(); | ||
|
||
Thread.sleep(100); | ||
|
||
frame.dispose(); | ||
|
||
p.stop(); | ||
w.close(); | ||
} | ||
} |
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