-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to
pillarbox-player
(#430)
- Loading branch information
Showing
17 changed files
with
884 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
...ox-player/src/androidTest/java/ch/srgssr/pillarbox/player/extension/PlayerCommandsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* License information is available from the LICENSE file. | ||
*/ | ||
package ch.srgssr.pillarbox.player.extension | ||
|
||
import androidx.media3.common.Player | ||
import androidx.media3.common.Player.Commands | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class PlayerCommandsTest { | ||
@Test | ||
fun canSeekToNext() { | ||
val player = mockk<Player> { | ||
every { availableCommands } returnsMany listOf( | ||
Commands.Builder().build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TEXT).build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_SEEK_TO_NEXT, Player.COMMAND_GET_TEXT).build() | ||
) | ||
} | ||
|
||
assertFalse(player.availableCommands.canSeekToNext()) | ||
assertFalse(player.availableCommands.canSeekToNext()) | ||
assertTrue(player.availableCommands.canSeekToNext()) | ||
} | ||
|
||
@Test | ||
fun canSeekToPrevious() { | ||
val player = mockk<Player> { | ||
every { availableCommands } returnsMany listOf( | ||
Commands.Builder().build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TEXT).build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_SEEK_TO_PREVIOUS, Player.COMMAND_GET_TEXT).build() | ||
) | ||
} | ||
|
||
assertFalse(player.availableCommands.canSeekToPrevious()) | ||
assertFalse(player.availableCommands.canSeekToPrevious()) | ||
assertTrue(player.availableCommands.canSeekToPrevious()) | ||
} | ||
|
||
@Test | ||
fun canSeekForward() { | ||
val player = mockk<Player> { | ||
every { availableCommands } returnsMany listOf( | ||
Commands.Builder().build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TEXT).build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_SEEK_FORWARD, Player.COMMAND_GET_TEXT).build() | ||
) | ||
} | ||
|
||
assertFalse(player.availableCommands.canSeekForward()) | ||
assertFalse(player.availableCommands.canSeekForward()) | ||
assertTrue(player.availableCommands.canSeekForward()) | ||
} | ||
|
||
@Test | ||
fun canSeekBack() { | ||
val player = mockk<Player> { | ||
every { availableCommands } returnsMany listOf( | ||
Commands.Builder().build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TEXT).build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_SEEK_BACK, Player.COMMAND_GET_TEXT).build() | ||
) | ||
} | ||
|
||
assertFalse(player.availableCommands.canSeekBack()) | ||
assertFalse(player.availableCommands.canSeekBack()) | ||
assertTrue(player.availableCommands.canSeekBack()) | ||
} | ||
|
||
@Test | ||
fun canSeek() { | ||
val player = mockk<Player> { | ||
every { availableCommands } returnsMany listOf( | ||
Commands.Builder().build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TEXT).build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, Player.COMMAND_GET_TEXT).build() | ||
) | ||
} | ||
|
||
assertFalse(player.availableCommands.canSeek()) | ||
assertFalse(player.availableCommands.canSeek()) | ||
assertTrue(player.availableCommands.canSeek()) | ||
} | ||
|
||
@Test | ||
fun canPlayPause() { | ||
val player = mockk<Player> { | ||
every { availableCommands } returnsMany listOf( | ||
Commands.Builder().build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TEXT).build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_PLAY_PAUSE, Player.COMMAND_GET_TEXT).build() | ||
) | ||
} | ||
|
||
assertFalse(player.availableCommands.canPlayPause()) | ||
assertFalse(player.availableCommands.canPlayPause()) | ||
assertTrue(player.availableCommands.canPlayPause()) | ||
} | ||
|
||
@Test | ||
fun canGetTracks() { | ||
val player = mockk<Player> { | ||
every { availableCommands } returnsMany listOf( | ||
Commands.Builder().build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TEXT).build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TRACKS, Player.COMMAND_GET_TEXT).build() | ||
) | ||
} | ||
|
||
assertFalse(player.availableCommands.canGetTracks()) | ||
assertFalse(player.availableCommands.canGetTracks()) | ||
assertTrue(player.availableCommands.canGetTracks()) | ||
} | ||
|
||
@Test | ||
fun canSetTrackSelectionParameters() { | ||
val player = mockk<Player> { | ||
every { availableCommands } returnsMany listOf( | ||
Commands.Builder().build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TEXT).build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_SET_TRACK_SELECTION_PARAMETERS, Player.COMMAND_GET_TEXT).build() | ||
) | ||
} | ||
|
||
assertFalse(player.availableCommands.canSetTrackSelectionParameters()) | ||
assertFalse(player.availableCommands.canSetTrackSelectionParameters()) | ||
assertTrue(player.availableCommands.canSetTrackSelectionParameters()) | ||
} | ||
|
||
@Test | ||
fun canSpeedAndPitch() { | ||
val player = mockk<Player> { | ||
every { availableCommands } returnsMany listOf( | ||
Commands.Builder().build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_GET_TEXT).build(), | ||
Commands.Builder().addAll(Player.COMMAND_STOP, Player.COMMAND_SET_SPEED_AND_PITCH, Player.COMMAND_GET_TEXT).build() | ||
) | ||
} | ||
|
||
assertFalse(player.availableCommands.canSpeedAndPitch()) | ||
assertFalse(player.availableCommands.canSpeedAndPitch()) | ||
assertTrue(player.availableCommands.canSpeedAndPitch()) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
pillarbox-player/src/androidTest/java/ch/srgssr/pillarbox/player/extension/VideoSizeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* License information is available from the LICENSE file. | ||
*/ | ||
package ch.srgssr.pillarbox.player.extension | ||
|
||
import android.util.Rational | ||
import androidx.media3.common.VideoSize | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class VideoSizeTest { | ||
@Test | ||
fun toRational_unknown_video_size() { | ||
val input = VideoSize.UNKNOWN | ||
assertEquals(RATIONAL_ONE, input.toRational()) | ||
} | ||
|
||
@Test | ||
fun toRational_with_a_16_9_aspect_ratio() { | ||
val input = VideoSize(1920, 1080) | ||
assertEquals(Rational(1920, 1080), input.toRational()) | ||
} | ||
|
||
@Test | ||
fun toRational_with_a_square_aspect_ratio() { | ||
val input = VideoSize(500, 500) | ||
assertEquals(Rational(500, 500), input.toRational()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 0 additions & 85 deletions
85
pillarbox-player/src/test/java/ch/srgssr/pillarbox/player/TestAspectRatio.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.