|
|
|
@ -3,32 +3,37 @@ package com.otaliastudios.cameraview.frame; |
|
|
|
|
|
|
|
|
|
import android.graphics.ImageFormat; |
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
|
|
|
|
|
import com.otaliastudios.cameraview.size.Size; |
|
|
|
|
|
|
|
|
|
import org.junit.After; |
|
|
|
|
import org.junit.Before; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
import static junit.framework.Assert.assertNotNull; |
|
|
|
|
import static org.junit.Assert.assertArrayEquals; |
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
import static org.junit.Assert.assertNotEquals; |
|
|
|
|
import static org.junit.Assert.assertNull; |
|
|
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
import static org.mockito.Mockito.spy; |
|
|
|
|
import static org.mockito.Mockito.times; |
|
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
|
|
|
|
|
|
public class FrameTest { |
|
|
|
|
|
|
|
|
|
private FrameManager<byte[]> manager; |
|
|
|
|
private FrameManager<String> manager; |
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void setUp() { |
|
|
|
|
//noinspection unchecked
|
|
|
|
|
manager = mock(FrameManager.class); |
|
|
|
|
manager = spy(new FrameManager<String>(1, String.class) { |
|
|
|
|
@Override |
|
|
|
|
protected void onFrameDataReleased(@NonNull String data, boolean recycled) { } |
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
|
@Override |
|
|
|
|
protected String onCloneFrameData(@NonNull String data) { |
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@After |
|
|
|
@ -39,23 +44,23 @@ public class FrameTest { |
|
|
|
|
@Test |
|
|
|
|
public void testEquals() { |
|
|
|
|
// Only time should count.
|
|
|
|
|
Frame f1 = new Frame(manager, byte[].class); |
|
|
|
|
Frame f1 = new Frame(manager); |
|
|
|
|
long time = 1000; |
|
|
|
|
f1.setContent(new byte[3], time, 90, new Size(5, 5), ImageFormat.NV21); |
|
|
|
|
Frame f2 = new Frame(manager, byte[].class); |
|
|
|
|
f2.setContent(new byte[2], time, 0, new Size(10, 10), ImageFormat.NV21); |
|
|
|
|
f1.setContent("foo", time, 90, new Size(5, 5), ImageFormat.NV21); |
|
|
|
|
Frame f2 = new Frame(manager); |
|
|
|
|
f2.setContent("bar", time, 0, new Size(10, 10), ImageFormat.NV21); |
|
|
|
|
assertEquals(f1, f2); |
|
|
|
|
|
|
|
|
|
f2.setContent(new byte[2], time + 1, 0, new Size(10, 10), ImageFormat.NV21); |
|
|
|
|
f2.setContent("foo", time + 1, 0, new Size(10, 10), ImageFormat.NV21); |
|
|
|
|
assertNotEquals(f1, f2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testReleaseThrows() { |
|
|
|
|
final Frame frame = new Frame(manager, byte[].class); |
|
|
|
|
frame.setContent(new byte[2], 1000, 90, new Size(10, 10), ImageFormat.NV21); |
|
|
|
|
final Frame frame = new Frame(manager); |
|
|
|
|
frame.setContent("foo", 1000, 90, new Size(10, 10), ImageFormat.NV21); |
|
|
|
|
frame.release(); |
|
|
|
|
verify(manager, times(1)).onFrameReleased(eq(frame), any(byte[].class)); |
|
|
|
|
verify(manager, times(1)).onFrameReleased(frame, "foo"); |
|
|
|
|
|
|
|
|
|
assertThrows(new Runnable() { public void run() { frame.getTime(); }}); |
|
|
|
|
assertThrows(new Runnable() { public void run() { frame.getFormat(); }}); |
|
|
|
@ -75,8 +80,8 @@ public class FrameTest { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testFreeze() { |
|
|
|
|
Frame frame = new Frame(manager, byte[].class); |
|
|
|
|
byte[] data = new byte[]{0, 1, 5, 0, 7, 3, 4, 5}; |
|
|
|
|
Frame frame = new Frame(manager); |
|
|
|
|
String data = "test data"; |
|
|
|
|
long time = 1000; |
|
|
|
|
int rotation = 90; |
|
|
|
|
Size size = new Size(10, 10); |
|
|
|
@ -84,14 +89,14 @@ public class FrameTest { |
|
|
|
|
frame.setContent(data, time, rotation, size, format); |
|
|
|
|
|
|
|
|
|
Frame frozen = frame.freeze(); |
|
|
|
|
assertArrayEquals(data, (byte[]) frozen.getData()); |
|
|
|
|
assertEquals(data, frozen.getData()); |
|
|
|
|
assertEquals(time, frozen.getTime()); |
|
|
|
|
assertEquals(rotation, frozen.getRotation()); |
|
|
|
|
assertEquals(size, frozen.getSize()); |
|
|
|
|
|
|
|
|
|
// Mutate the first, ensure that frozen is not affected
|
|
|
|
|
frame.setContent(new byte[]{3, 2, 1}, 50, 180, new Size(1, 1), ImageFormat.JPEG); |
|
|
|
|
assertArrayEquals(data, (byte[]) frozen.getData()); |
|
|
|
|
frame.setContent("new data", 50, 180, new Size(1, 1), ImageFormat.JPEG); |
|
|
|
|
assertEquals(data, frozen.getData()); |
|
|
|
|
assertEquals(time, frozen.getTime()); |
|
|
|
|
assertEquals(rotation, frozen.getRotation()); |
|
|
|
|
assertEquals(size, frozen.getSize()); |
|
|
|
|