Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gordinmitya committed Jul 29, 2021
1 parent 8b91da0 commit 753810b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
7 changes: 4 additions & 3 deletions yuv2buf/src/test/java/ru/gordinmitya/yuv2buf/ReuseTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.gordinmitya.yuv2buf;

import android.graphics.ImageFormat;

import org.junit.Test;

import java.nio.ByteBuffer;
Expand All @@ -12,7 +14,7 @@ public class ReuseTest {
@Test
public void test_reuse() {
final int width = 10, height = 10;
Yuv.ImageWrapper image = YuvCommon.make(Yuv.Type.YUV_I420, width, height, width);
Yuv.ImageWrapper image = YuvCommon.make(ImageFormat.YUV_420_888, width, height, width);
int size = width * height * 3 / 2;
ByteBuffer correctReuse;
ByteBuffer result;
Expand All @@ -28,11 +30,10 @@ public void test_reuse() {
assertSame(correctReuse, result);
}

@SuppressWarnings("ConstantConditions")
@Test
public void test_makesNew() {
final int width = 10, height = 10;
Yuv.ImageWrapper image = YuvCommon.make(Yuv.Type.YUV_I420, width, height, width);
Yuv.ImageWrapper image = YuvCommon.make(ImageFormat.YUV_420_888, width, height, width);
int size = width * height * 3 / 2;
ByteBuffer incorrectReuse;
ByteBuffer result;
Expand Down
7 changes: 4 additions & 3 deletions yuv2buf/src/test/java/ru/gordinmitya/yuv2buf/Yuv420Test.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.gordinmitya.yuv2buf;

import android.graphics.ImageFormat;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -33,11 +34,11 @@ public Yuv420Test(int width, int height, int rowStride) {

@Test
public void check() {
Yuv.ImageWrapper image = YuvCommon.make(Yuv.Type.YUV_I420, width, height, rowStride);
Yuv.ImageWrapper image = YuvCommon.make(ImageFormat.YUV_420_888, width, height, rowStride);
Yuv.Converted converted = Yuv.toBuffer(image, null);
ByteBuffer buffer = converted.buffer;

assertEquals(Yuv.Type.YUV_I420, converted.type);
assertEquals(ImageFormat.YUV_420_888, converted.type);
assertEquals(0, buffer.position());

int sizeY = width * height;
Expand All @@ -55,4 +56,4 @@ public void check() {
for (int i = sizeY + sizeChroma; i < sizeTotal; i++)
assertEquals(V, array[i]);
}
}
}
6 changes: 4 additions & 2 deletions yuv2buf/src/test/java/ru/gordinmitya/yuv2buf/YuvCommon.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.gordinmitya.yuv2buf;

import android.graphics.ImageFormat;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -31,11 +33,11 @@ static int getBufferSize(int width, int height, int rowStride, int pixelStride)
return rowStride * (height - 1) + width * pixelStride - pixelStride / 2;
}

static Yuv.ImageWrapper make(Yuv.Type type, int width, int height, int rowStride) {
static Yuv.ImageWrapper make(@Yuv.YuvType int type, int width, int height, int rowStride) {
assert rowStride >= width;
Yuv.PlaneWrapper y = makeCompact(Y, width, height, rowStride);
Yuv.PlaneWrapper u, v;
if (Yuv.Type.YUV_I420.equals(type)) {
if (ImageFormat.YUV_420_888 == type) {
int stride = rowStride == width ? width / 2 : rowStride;
u = makeCompact(U, width / 2, height / 2, stride);
v = makeCompact(V, width / 2, height / 2, stride);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.gordinmitya.yuv2buf;

import android.graphics.ImageFormat;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void test_getBufferSize() {

@Test
public void test_ImageGeneration_YUV420() {
Yuv.ImageWrapper image = make(Yuv.Type.YUV_I420, width, height, rowStride);
Yuv.ImageWrapper image = make(ImageFormat.YUV_420_888, width, height, rowStride);

assertPlaneParams(image.y, width, height, rowStride, 1);
assertCompactPlane(image.y, Y);
Expand All @@ -57,7 +58,7 @@ public void test_ImageGeneration_YUV420() {

@Test
public void test_ImageGeneration_NV21() {
Yuv.ImageWrapper image = make(Yuv.Type.YUV_NV21, width, height, rowStride);
Yuv.ImageWrapper image = make(ImageFormat.NV21, width, height, rowStride);

assertPlaneParams(image.y, width, height, rowStride, 1);
assertCompactPlane(image.y, Y);
Expand Down
7 changes: 4 additions & 3 deletions yuv2buf/src/test/java/ru/gordinmitya/yuv2buf/YuvNV21Test.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.gordinmitya.yuv2buf;

import android.graphics.ImageFormat;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -33,11 +34,11 @@ public YuvNV21Test(int width, int height, int rowStride) {

@Test
public void check() {
Yuv.ImageWrapper image = YuvCommon.make(Yuv.Type.YUV_NV21, width, height, rowStride);
Yuv.ImageWrapper image = YuvCommon.make(ImageFormat.NV21, width, height, rowStride);
Yuv.Converted converted = Yuv.toBuffer(image, null);
ByteBuffer buffer = converted.buffer;

assertEquals(Yuv.Type.YUV_NV21, converted.type);
assertEquals(ImageFormat.NV21, converted.type);
assertEquals(0, buffer.position());

int sizeY = width * height;
Expand All @@ -54,4 +55,4 @@ public void check() {
assertEquals(expected, array[i]);
}
}
}
}

0 comments on commit 753810b

Please sign in to comment.