diff --git a/.travis.yml b/.travis.yml index 5a1e0147..d5cce1f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,9 @@ android: - android-26 - doc-26 +script: + - ./gradlew clean connectedCheck testDebugUnitTest + cache: directories: - $HOME/.gradle diff --git a/cameraview/build.gradle b/cameraview/build.gradle index f68b4ffa..f7f2d0de 100644 --- a/cameraview/build.gradle +++ b/cameraview/build.gradle @@ -31,6 +31,9 @@ android { } dependencies { + testCompile 'junit:junit:4.12' + testCompile 'org.mockito:mockito-core:1.10.19' + compile "com.android.support:exifinterface:$supportLibVersion" compile "com.android.support:support-annotations:$supportLibVersion" } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/ExtraProperties.java b/cameraview/src/main/java/com/otaliastudios/cameraview/ExtraProperties.java index 6aac20c7..4ec5778a 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/ExtraProperties.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/ExtraProperties.java @@ -4,6 +4,7 @@ package com.otaliastudios.cameraview; import android.annotation.TargetApi; import android.hardware.Camera; import android.hardware.camera2.CameraCharacteristics; +import android.util.Log; import android.util.SizeF; /** @@ -12,8 +13,8 @@ import android.util.SizeF; @SuppressWarnings("deprecation") public class ExtraProperties { - float verticalViewingAngle; - float horizontalViewingAngle; + private float verticalViewingAngle; + private float horizontalViewingAngle; ExtraProperties(Camera.Parameters params) { verticalViewingAngle = params.getVerticalViewAngle(); diff --git a/cameraview/src/test/java/com/otaliastudios/cameraview/ExtraPropertiesTest.java b/cameraview/src/test/java/com/otaliastudios/cameraview/ExtraPropertiesTest.java new file mode 100644 index 00000000..166b182e --- /dev/null +++ b/cameraview/src/test/java/com/otaliastudios/cameraview/ExtraPropertiesTest.java @@ -0,0 +1,27 @@ +package com.otaliastudios.cameraview; + + +import android.annotation.TargetApi; +import android.hardware.Camera; +import android.hardware.camera2.CameraCharacteristics; +import android.util.SizeF; + +import org.junit.Test; +import org.mockito.Mockito; + +import static org.mockito.Mockito.*; +import static org.junit.Assert.*; + +public class ExtraPropertiesTest { + + @Test + public void testConstructor1() { + Camera.Parameters params = mock(Camera.Parameters.class); + when(params.getVerticalViewAngle()).thenReturn(10f); + when(params.getHorizontalViewAngle()).thenReturn(5f); + ExtraProperties e = new ExtraProperties(params); + assertEquals(e.getVerticalViewingAngle(), 10f, 0f); + assertEquals(e.getHorizontalViewingAngle(), 5f, 0f); + } + +} diff --git a/cameraview/src/test/java/com/otaliastudios/cameraview/Mapper1Test.java b/cameraview/src/test/java/com/otaliastudios/cameraview/Mapper1Test.java new file mode 100644 index 00000000..bbbaec78 --- /dev/null +++ b/cameraview/src/test/java/com/otaliastudios/cameraview/Mapper1Test.java @@ -0,0 +1,54 @@ +package com.otaliastudios.cameraview; + + +import android.hardware.Camera; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class Mapper1Test { + + private Mapper mapper = new Mapper.Mapper1(); + + @Test + public void testMap() { + assertEquals(mapper.map(Flash.OFF), Camera.Parameters.FLASH_MODE_OFF); + assertEquals(mapper.map(Flash.ON), Camera.Parameters.FLASH_MODE_ON); + assertEquals(mapper.map(Flash.AUTO), Camera.Parameters.FLASH_MODE_AUTO); + assertEquals(mapper.map(Flash.TORCH), Camera.Parameters.FLASH_MODE_TORCH); + + assertEquals(mapper.map(Facing.BACK), Camera.CameraInfo.CAMERA_FACING_BACK); + assertEquals(mapper.map(Facing.FRONT), Camera.CameraInfo.CAMERA_FACING_FRONT); + + assertEquals(mapper.map(Hdr.OFF), Camera.Parameters.SCENE_MODE_AUTO); + assertEquals(mapper.map(Hdr.ON), Camera.Parameters.SCENE_MODE_HDR); + + assertEquals(mapper.map(WhiteBalance.AUTO), Camera.Parameters.WHITE_BALANCE_AUTO); + assertEquals(mapper.map(WhiteBalance.DAYLIGHT), Camera.Parameters.WHITE_BALANCE_DAYLIGHT); + assertEquals(mapper.map(WhiteBalance.CLOUDY), Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT); + assertEquals(mapper.map(WhiteBalance.INCANDESCENT), Camera.Parameters.WHITE_BALANCE_INCANDESCENT); + assertEquals(mapper.map(WhiteBalance.FLUORESCENT), Camera.Parameters.WHITE_BALANCE_FLUORESCENT); + } + + + @Test + public void testUnmap() { + assertEquals(Flash.OFF, mapper.unmapFlash(Camera.Parameters.FLASH_MODE_OFF)); + assertEquals(Flash.ON, mapper.unmapFlash(Camera.Parameters.FLASH_MODE_ON)); + assertEquals(Flash.AUTO, mapper.unmapFlash(Camera.Parameters.FLASH_MODE_AUTO)); + assertEquals(Flash.TORCH, mapper.unmapFlash(Camera.Parameters.FLASH_MODE_TORCH)); + + assertEquals(Facing.BACK, mapper.unmapFacing(Camera.CameraInfo.CAMERA_FACING_BACK)); + assertEquals(Facing.FRONT, mapper.unmapFacing(Camera.CameraInfo.CAMERA_FACING_FRONT)); + + assertEquals(Hdr.OFF, mapper.unmapHdr(Camera.Parameters.SCENE_MODE_AUTO)); + assertEquals(Hdr.ON, mapper.unmapHdr(Camera.Parameters.SCENE_MODE_HDR)); + + assertEquals(WhiteBalance.AUTO, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO)); + assertEquals(WhiteBalance.DAYLIGHT, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_DAYLIGHT)); + assertEquals(WhiteBalance.CLOUDY, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT)); + assertEquals(WhiteBalance.INCANDESCENT, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_INCANDESCENT)); + assertEquals(WhiteBalance.FLUORESCENT, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_FLUORESCENT)); + } +} diff --git a/cameraview/src/test/java/com/otaliastudios/cameraview/SizeTest.java b/cameraview/src/test/java/com/otaliastudios/cameraview/SizeTest.java new file mode 100644 index 00000000..3d8b7fd2 --- /dev/null +++ b/cameraview/src/test/java/com/otaliastudios/cameraview/SizeTest.java @@ -0,0 +1,37 @@ +package com.otaliastudios.cameraview; + + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SizeTest { + + + @Test + public void testDimensions() { + Size size = new Size(10, 20); + assertEquals(size.getWidth(), 10f, 0f); + assertEquals(size.getHeight(), 20f, 0f); + assertEquals("10x20", size.toString()); + } + + @Test + public void testEquals() { + Size s1 = new Size(10, 20); + Size s2 = new Size(10, 0); + Size s3 = new Size(10, 20); + assertTrue(s1.equals(s3)); + assertFalse(s1.equals(s2)); + } + + @Test + public void testCompare() { + Size s1 = new Size(10, 20); + Size s2 = new Size(10, 0); + Size s3 = new Size(10, 20); + assertTrue(s1.compareTo(s3) == 0); + assertTrue(s1.compareTo(s2) > 0); + assertTrue(s2.compareTo(s1) < 0); + } +}