Skip to content

Commit e0e721c

Browse files
committed
Add unit test on VideoCompressorHelper
1 parent fa755e5 commit e0e721c

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

libraries/androidutils/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies {
3838
testImplementation(libs.test.junit)
3939
testImplementation(libs.test.truth)
4040
testImplementation(libs.test.robolectric)
41+
testImplementation(libs.androidx.test.ext.junit)
4142
testImplementation(libs.coroutines.core)
4243
testImplementation(libs.coroutines.test)
4344
testImplementation(projects.services.toolbox.test)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
package io.element.android.libraries.androidutils.media
9+
10+
import android.util.Size
11+
import androidx.test.ext.junit.runners.AndroidJUnit4
12+
import com.google.common.truth.Truth.assertThat
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
16+
@RunWith(AndroidJUnit4::class)
17+
class VideoCompressorHelperTest {
18+
@Test
19+
fun `test getOutputSize`() {
20+
val helper = VideoCompressorHelper(maxSize = 720)
21+
22+
// Landscape input
23+
var inputSize = Size(1920, 1080)
24+
var outputSize = helper.getOutputSize(inputSize)
25+
assertThat(outputSize).isEqualTo(Size(720, 405))
26+
27+
// Landscape input small height
28+
inputSize = Size(1920, 200)
29+
outputSize = helper.getOutputSize(inputSize)
30+
assertThat(outputSize).isEqualTo(Size(720, 75))
31+
32+
// Portrait input
33+
inputSize = Size(1080, 1920)
34+
outputSize = helper.getOutputSize(inputSize)
35+
assertThat(outputSize).isEqualTo(Size(405, 720))
36+
37+
// Portrait input small width
38+
inputSize = Size(200, 1920)
39+
outputSize = helper.getOutputSize(inputSize)
40+
assertThat(outputSize).isEqualTo(Size(75, 720))
41+
42+
// Square input
43+
inputSize = Size(1000, 1000)
44+
outputSize = helper.getOutputSize(inputSize)
45+
assertThat(outputSize).isEqualTo(Size(720, 720))
46+
47+
// Square input same size
48+
inputSize = Size(720, 720)
49+
outputSize = helper.getOutputSize(inputSize)
50+
assertThat(outputSize).isEqualTo(Size(720, 720))
51+
52+
// Square input no downscaling
53+
inputSize = Size(240, 240)
54+
outputSize = helper.getOutputSize(inputSize)
55+
assertThat(outputSize).isEqualTo(Size(240, 240))
56+
57+
// Small input landscape (no downscaling)
58+
inputSize = Size(640, 480)
59+
outputSize = helper.getOutputSize(inputSize)
60+
assertThat(outputSize).isEqualTo(Size(640, 480))
61+
62+
// Small input portrait (no downscaling)
63+
inputSize = Size(480, 640)
64+
outputSize = helper.getOutputSize(inputSize)
65+
assertThat(outputSize).isEqualTo(Size(480, 640))
66+
}
67+
}

0 commit comments

Comments
 (0)