Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #22 from SRGSSR/develop
Browse files Browse the repository at this point in the history
Integrate tests
  • Loading branch information
SebastienChauvin authored Sep 11, 2018
2 parents 5e00294 + 9914aa0 commit 5cc6226
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

import ch.srg.mediaplayer.segment.model.Segment;
import ch.srg.mediaplayer.utils.SRGMediaPlayerControllerQueueListener;

/**
Expand Down Expand Up @@ -226,7 +229,7 @@ public void testOnDemandAudioPlaythrough() throws Exception {
}

@Test
public void testPlayAtPosition() throws Exception {
public void testPlayAndSeekToPosition() throws Exception {
controller.play(AUDIO_ON_DEMAND_URI, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE);
waitForState(SRGMediaPlayerController.State.READY);
controller.seekTo((long) 30000);
Expand All @@ -235,6 +238,39 @@ public void testPlayAtPosition() throws Exception {
assertEquals(30, controller.getMediaPosition() / 1000);
}

@Test
public void testPlayAtStartingPosition() throws Exception {
Long position = 3000L;
controller.play(AUDIO_ON_DEMAND_URI, position, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE);
waitForState(SRGMediaPlayerController.State.READY);
assertTrue(controller.isPlaying());
assertEquals(3, controller.getMediaPosition() / 1000);
}

@Test
public void testPlayAtStartingPositionNull() throws Exception {
Long position = null;
controller.play(AUDIO_ON_DEMAND_URI, position, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE);
waitForState(SRGMediaPlayerController.State.READY);
assertTrue(controller.isPlaying());
assertEquals(0, controller.getMediaPosition() / 1000);
}

@Test
public void testPlayAtStartingPositionWitSegment() throws Exception {
Segment segment0 = new Segment("segmentId0", "Segment0", null, null, null,
3000L, 10000L, 7000L, 0L, true, false, false);
Segment segment1 = new Segment("segmentId1", "Segment1", null, null, null,
12000L, 15000L, 3000L, 0L, true, false, false);
List<Segment> listSegment = Arrays.asList(segment0, segment1);

controller.prepare(AUDIO_ON_DEMAND_URI, 0L, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE, listSegment, segment1);
controller.start();
waitForState(SRGMediaPlayerController.State.READY);
assertTrue(controller.isPlaying());
assertEquals(12, controller.getMediaPosition() / 1000);
}

@Test
public void testPlayAfterStreamEnd() throws Exception {
controller.play(AUDIO_ON_DEMAND_URI, SRGMediaPlayerController.STREAM_HTTP_PROGRESSIVE);
Expand Down Expand Up @@ -263,7 +299,7 @@ public void testSeek() throws Exception {
controller.seekTo(60 * 1000);
waitForState(SRGMediaPlayerController.State.BUFFERING);
waitForState(SRGMediaPlayerController.State.READY);
assertEquals(60,controller.getMediaPosition() / 1000);
assertEquals(60, controller.getMediaPosition() / 1000);
assertTrue(controller.isPlaying());
}

Expand Down Expand Up @@ -307,7 +343,7 @@ public void testSeekWhilePreparing() throws Exception {
controller.seekTo(60 * 1000);
assertTrue(controller.isLoading() || controller.isPlaying());
waitForState(SRGMediaPlayerController.State.READY);
assertEquals(60,controller.getMediaPosition() / 1000);
assertEquals(60, controller.getMediaPosition() / 1000);
while (!controller.isPlaying()) {
Thread.sleep(100);
}
Expand All @@ -333,13 +369,13 @@ public void testSeekWhilePaused() throws Exception {
controller.pause();
Thread.sleep(100); // Need to wait
assertFalse(controller.isPlaying());
assertEquals(0,controller.getMediaPosition() / 1000);
assertEquals(0, controller.getMediaPosition() / 1000);

controller.seekTo(60 * 1000);
// TODO: No BUFFERING?
waitForState(SRGMediaPlayerController.State.READY);
waitForEvent(SRGMediaPlayerController.Event.Type.DID_SEEK);
assertEquals(60,controller.getMediaPosition() / 1000);
assertEquals(60, controller.getMediaPosition() / 1000);
assertFalse(controller.isPlaying());
}

Expand All @@ -353,13 +389,13 @@ public void testPauseStartPositionKept() throws Exception {
controller.pause();
Thread.sleep(100); // Need to wait
assertFalse(controller.isPlaying());
assertEquals(60,controller.getMediaPosition() / 1000);
assertEquals(60, controller.getMediaPosition() / 1000);

controller.start();
waitForState(SRGMediaPlayerController.State.READY);
waitForEvent(SRGMediaPlayerController.Event.Type.PLAYING_STATE_CHANGE);

assertEquals(60,controller.getMediaPosition() / 1000);
assertEquals(60, controller.getMediaPosition() / 1000);
assertTrue(controller.isPlaying());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ public interface Listener {

@Nullable
private AkamaiMediaAnalyticsConfiguration akamaiMediaAnalyticsConfiguration;
// FIXME : why userAgent letterbox is set here?
private static final String userAgent = "curl/Letterbox_2.0"; // temporarily using curl/ user agent to force subtitles with Akamai beta
@Nullable
private DrmConfig drmConfig;
Expand Down

0 comments on commit 5cc6226

Please sign in to comment.