Skip to content

Commit

Permalink
adding size preview tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Aug 20, 2024
1 parent 7106c73 commit 0cddec2
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static Pair<Point, Point> getViewport(AspectRatioMode mode, int previewWi
int xf = previewWidth;
int yf = previewHeight;
if ((previewAspectRatio > 1f && streamAspectRatio > previewAspectRatio) ||
(streamAspectRatio <= 1f && previewAspectRatio <= 1 && streamAspectRatio > previewAspectRatio) ||
(streamAspectRatio <= 1f && previewAspectRatio <= 1f && streamAspectRatio > previewAspectRatio) ||
(streamAspectRatio > 1f && previewAspectRatio < 1f)) {
if (mode == AspectRatioMode.Adjust) {
yf = streamHeight * previewWidth / streamWidth;
Expand Down
34 changes: 34 additions & 0 deletions encoder/src/test/java/android/graphics/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package android.graphics;

import java.util.Objects;

public class Point {
public int x;
public int y;

public Point(int x, int y) {
this.x = x;
this.y = y;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Point point = (Point) o;
return x == point.x && y == point.y;
}

@Override
public int hashCode() {
return Objects.hash(x, y);
}

@Override
public String toString() {
return "Point{" +
"x=" + x +
", y=" + y +
'}';
}
}
34 changes: 34 additions & 0 deletions encoder/src/test/java/android/util/Pair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package android.util;

import java.util.Objects;

public class Pair<F, S> {
public final F first;
public final S second;

public Pair(F first, S second) {
this.first = first;
this.second = second;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equals(first, pair.first) && Objects.equals(second, pair.second);
}

@Override
public int hashCode() {
return Objects.hash(first, second);
}

@Override
public String toString() {
return "Pair{" +
"first=" + first +
", second=" + second +
'}';
}
}
72 changes: 72 additions & 0 deletions encoder/src/test/java/com/pedro/encoder/SizeCalculatorTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.pedro.encoder

import android.util.Pair
import android.graphics.Point
import com.pedro.encoder.utils.gl.AspectRatioMode
import com.pedro.encoder.utils.gl.SizeCalculator
import junit.framework.TestCase.assertEquals
import org.junit.Test


/**
* Possible cases:
*
* stream to preview (Adjust and Fill)
* 1:1 to 1:1
* 1:1 to 16:9
* 1:1 to 9:16
*
* 16:9 to 16:9
* 16:9 to 1:1
* 16:9 to 9:16
*
* 9:16 to 9:16
* 9:16 to 16:9
* 9:16 to 1:1
*/
class SizeCalculatorTest {

@Test
fun testAdjust1_1toX() {
val to1_1 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 100, 100, 100, 100)
assertEquals(Pair(Point(0, 0), Point(100, 100)), to1_1)

val to16_9 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 160, 90, 100, 100)
assertEquals(Pair(Point(35, 0), Point(90, 90)), to16_9)

val to9_16 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 90, 160, 100, 100)
assertEquals(Pair(Point(0, 35), Point(90, 90)), to9_16)
}

@Test
fun testAdjust16_9toX() {
val to1_1 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 100, 100, 100, 100)
assertEquals(Pair(Point(0, 0), Point(100, 100)), to1_1)

val to16_9 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 160, 90, 100, 100)
assertEquals(Pair(Point(35, 0), Point(90, 90)), to16_9)

val to9_16 = SizeCalculator.getViewport(AspectRatioMode.Adjust, 90, 160, 100, 100)
assertEquals(Pair(Point(0, 35), Point(90, 90)), to9_16)
}

@Test
fun testAdjust9_16toX() {

}

@Test
fun testFill1_1toX() {

}

@Test
fun testFill16_9toX() {

}

@Test
fun testFill9_16toX() {

}
}

0 comments on commit 0cddec2

Please sign in to comment.