Skip to content

Commit

Permalink
Add initial test cases foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jul 23, 2012
1 parent c626e8d commit 00e9bd6
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 70 deletions.
48 changes: 1 addition & 47 deletions pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-parent</artifactId>
<version>0.3.2</version>
<version>0.3.4</version>
<packaging>pom</packaging>

<name>Webcam Capture - Root POM</name>
Expand Down Expand Up @@ -153,52 +153,6 @@
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

<extensions>
Expand Down
2 changes: 1 addition & 1 deletion webcam-capture-driver-civil/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-parent</artifactId>
<version>0.3.2</version>
<version>0.3.4</version>
</parent>

<artifactId>webcam-capture-driver-civil</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion webcam-capture-driver-jmf/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-parent</artifactId>
<version>0.3.2</version>
<version>0.3.4</version>
</parent>

<artifactId>webcam-capture-driver-jmf</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion webcam-capture-driver-openimaj/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-parent</artifactId>
<version>0.3.2</version>
<version>0.3.4</version>
</parent>

<artifactId>webcam-capture-driver-openimaj</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion webcam-capture/.classpath
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" path="src/example/java"/>
<classpathentry kind="src" path="src/example/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
Expand Down
69 changes: 52 additions & 17 deletions webcam-capture/pom.xml
Expand Up @@ -29,7 +29,7 @@
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.html</url>
<distribution>repo</distribution>
<distribution>repo,manual</distribution>
</license>
</licenses>

Expand All @@ -47,15 +47,29 @@
</scm>

<issueManagement>
<system>GitHub</system>
<system>GitHub Issues Manager</system>
<url>https://github.com/sarxos/webcam-capture/issues</url>
</issueManagement>

<ciManagement>
<system>Travis CI</system>
<url>http://travis-ci.org/#!/sarxos/webcam-capture</url>
</ciManagement>

<developers>
<developer>
<id>sarxos</id>
<name>Bartosz Firyn</name>
<email>bartoszfiryn@gmail.com</email>
<roles>
<role>Project Manager</role>
<role>Architect</role>
<role>Developer</role>
</roles>
<url>http://me.sarxos.pl/</url>
<organization>Bartosz Firyn (SarXos)</organization>
<organizationUrl>https://github.com/sarxos</organizationUrl>
<timezone>+1</timezone>
</developer>
</developers>

Expand All @@ -80,6 +94,12 @@
<artifactId>logback-classic</artifactId>
<version>0.9.18</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down Expand Up @@ -285,17 +305,41 @@
<keywords>cam,webcam,camera,spycam,capture</keywords>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.1</version>
<configuration>
<linkJavadoc>true</linkJavadoc>
<aggregate>true</aggregate>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>taglist-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<tags>
<tag>TODO</tag>
<tag>@todo</tag>
<tag>FIXME</tag>
<tag>XXX</tag>
</tags>
<tagListOptions>
<tagClasses>
<tagClass>
<displayName>Todos</displayName>
<tags>
<tag>
<matchString>TODO</matchString>
<matchType>exact</matchType>
</tag>
<tag>
<matchString>FIXME</matchString>
<matchType>exact</matchType>
</tag>
<tag>
<matchString>XXX</matchString>
<matchType>exact</matchType>
</tag>
</tags>
</tagClass>
</tagClasses>
</tagListOptions>
<aggregate>true</aggregate>
</configuration>
</plugin>
Expand All @@ -321,15 +365,6 @@
<includes>com.github.sarxos.webcam</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.1</version>
<configuration>
<linkJavadoc>true</linkJavadoc>
<aggregate>true</aggregate>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
Expand Down
Expand Up @@ -4,6 +4,7 @@
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.slf4j.Logger;
Expand Down Expand Up @@ -228,7 +229,8 @@ public static List<Webcam> getWebcams() {
}
}
}
return webcams;

return Collections.unmodifiableList(webcams);
}

/**
Expand Down
Expand Up @@ -93,8 +93,11 @@ public BufferedImage getImage() {

DataBufferByte buffer = new DataBufferByte(data, bytes.length, OFFSET);
WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);
BufferedImage bi = new BufferedImage(colorModel, raster, false, null);

return new BufferedImage(colorModel, raster, false, null);
bi.flush();

return bi;
}

@Override
Expand Down
@@ -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() {
//
// }

}
@@ -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;
}

}

0 comments on commit 00e9bd6

Please sign in to comment.