Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Unified Diff: talk/app/webrtc/androidtests/src/org/webrtc/RendererCommonTest.java

Issue 1315843002: Android RendererCommon: Add unittests for getTextureMatrix() (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: talk/app/webrtc/androidtests/src/org/webrtc/RendererCommonTest.java
diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/RendererCommonTest.java b/talk/app/webrtc/androidtests/src/org/webrtc/RendererCommonTest.java
index e07f454ddae1ffb0d6a8a22b47313706e2ab4408..28c0f283c3909af15d9af73324ee4807c4c97b1d 100644
--- a/talk/app/webrtc/androidtests/src/org/webrtc/RendererCommonTest.java
+++ b/talk/app/webrtc/androidtests/src/org/webrtc/RendererCommonTest.java
@@ -28,12 +28,14 @@
package org.webrtc;
import android.test.ActivityTestCase;
+import android.test.MoreAsserts;
import android.test.suitebuilder.annotation.SmallTest;
import android.graphics.Point;
import static org.webrtc.RendererCommon.ScalingType.*;
import static org.webrtc.RendererCommon.getDisplaySize;
+import static org.webrtc.RendererCommon.getTextureMatrix;
public class RendererCommonTest extends ActivityTestCase {
@SmallTest
@@ -87,4 +89,75 @@ public class RendererCommonTest extends ActivityTestCase {
assertEquals(getDisplaySize(SCALE_ASPECT_FILL, 4.0f / 3, 1280, 720), new Point(1280, 720));
assertEquals(getDisplaySize(SCALE_ASPECT_BALANCED, 4.0f / 3, 1280, 720), new Point(1280, 720));
}
+
+ // Only keep 2 rounded decimals to make float comparison robust.
+ static private double[] round(float[] array) {
+ assertEquals(array.length, 16);
+ final double[] doubleArray = new double[16];
+ for (int i = 0; i < 16; ++i) {
+ doubleArray[i] = Math.round(100 * array[i]) / 100.0;
+ }
+ return doubleArray;
+ }
+
+ @SmallTest
+ static public void testTexMatrixDefault() {
+ final float texMatrix[] = new float[16];
+ getTextureMatrix(texMatrix, 0, false, 1.0f, 1.0f);
+ // TODO(magjed): Every tex matrix contains a vertical flip, because we ignore the texture
+ // transform matrix from the SurfaceTexture (which contains a vertical flip). Update tests when
+ // this is fixed.
+ // Assert:
+ // u' = u.
+ // v' = 1 - v.
+ MoreAsserts.assertEquals(round(texMatrix), new double[]
+ {1, 0, 0, 0,
+ 0, -1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 1, 0, 1});
+ }
+
+ @SmallTest
+ static public void testTexMatrixMirror() {
+ final float texMatrix[] = new float[16];
+ getTextureMatrix(texMatrix, 0, true, 1.0f, 1.0f);
+ // Assert:
+ // u' = 1 - u.
+ // v' = 1 - v.
+ MoreAsserts.assertEquals(round(texMatrix), new double[]
+ {-1, 0, 0, 0,
+ 0, -1, 0, 0,
+ 0, 0, 1, 0,
+ 1, 1, 0, 1});
+ }
+
+ @SmallTest
+ static public void testTexMatrixRotation90Deg() {
+ final float texMatrix[] = new float[16];
+ getTextureMatrix(texMatrix, 90, false, 1.0f, 1.0f);
+ // Assert:
+ // u' = 1 - v.
+ // v' = 1 - u.
+ MoreAsserts.assertEquals(round(texMatrix), new double[]
+ {0, -1, 0, 0,
+ -1, 0, 0, 0,
+ 0, 0, 1, 0,
+ 1, 1, 0, 1});
+ }
+
+ @SmallTest
+ static public void testTexMatrixScale() {
+ final float texMatrix[] = new float[16];
+ // Video has aspect ratio 2, but layout is square. This will cause only the center part of the
+ // video to be visible, i.e. the u coordinate will go from 0.25 to 0.75 instead of from 0 to 1.
+ getTextureMatrix(texMatrix, 0, false, 2.0f, 1.0f);
+ // Assert:
+ // u' = 0.25 + 0.5 u.
+ // v' = 1 - v.
+ MoreAsserts.assertEquals(round(texMatrix), new double[]
+ {0.5, 0, 0, 0,
+ 0, -1, 0, 0,
+ 0, 0, 1, 0,
+ 0.25, 1, 0, 1});
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698