aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Chalko <nchalko@google.com>2018-02-23 14:53:37 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-02-23 14:53:37 +0000
commit7737f2ff103e5f8fecad10d1755cb78760f9135b (patch)
tree4a39797f8fe724ce09206bba26c2b8ad2d1dc86f
parenta75e73b3b367eecc2bdea4f7fbfd88512fcc95fe (diff)
parenta220fc584a12d01122d0cd127288ec703e36ec9c (diff)
downloadTV-7737f2ff103e5f8fecad10d1755cb78760f9135b.tar.gz
Merge changes I9d3158cd,I85304d06,I7facfa4d,I689eff2a
* changes: CLEANUP: Migrate SampleSourceExtractorTest to robotest CLEANUP: Move VerySlowSampleChunk to a shared testing package CLEANUP: Convert TvActivityTest to robolectric CLEANUP: Add build target for recomendation tests
-rw-r--r--tests/tunerunit/Android.mk25
-rw-r--r--tests/tunerunit/src/com/android/tv/tuner/exoplayer/tests/AssetDataSource.java124
-rw-r--r--tests/tunerunit/src/com/android/tv/tuner/exoplayer/tests/SampleSourceExtractorTest.java246
-rw-r--r--tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java3
-rw-r--r--tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java3
-rw-r--r--tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java3
-rw-r--r--tests/unit/src/com/android/tv/recommendation/RecommenderTest.java3
-rw-r--r--tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java3
-rw-r--r--tests/unit/src/com/android/tv/tests/TvActivityTest.java41
-rw-r--r--tuner/src/com/android/tv/tuner/exoplayer/ExoPlayerSampleExtractor.java25
-rw-r--r--tuner/src/com/android/tv/tuner/exoplayer/buffer/SampleChunk.java6
-rw-r--r--tuner/tests/testing/Android.mk29
-rw-r--r--tuner/tests/testing/AndroidManifest.xml (renamed from tests/tunerunit/AndroidManifest.xml)25
-rw-r--r--tuner/tests/testing/src/com/android/tv/tuner/testing/buffer/VerySlowSampleChunk.java (renamed from tests/tunerunit/src/com/android/tv/tuner/exoplayer/buffer/VerySlowSampleChunk.java)6
14 files changed, 83 insertions, 459 deletions
diff --git a/tests/tunerunit/Android.mk b/tests/tunerunit/Android.mk
deleted file mode 100644
index f599706d..00000000
--- a/tests/tunerunit/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-# Include all test java files.
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := UsbTunerTvInputTests
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
- android-support-test \
- tv-test-common \
-
-LOCAL_JAVA_LIBRARIES := \
- android.test.runner.stubs \
- android.test.base.stubs \
- android.test.mock.stubs \
-
-LOCAL_INSTRUMENTATION_FOR := LiveTv
-
-LOCAL_SDK_VERSION := system_current
-LOCAL_PROGUARD_ENABLED := disabled
-
-include $(BUILD_PACKAGE)
diff --git a/tests/tunerunit/src/com/android/tv/tuner/exoplayer/tests/AssetDataSource.java b/tests/tunerunit/src/com/android/tv/tuner/exoplayer/tests/AssetDataSource.java
deleted file mode 100644
index b3defc55..00000000
--- a/tests/tunerunit/src/com/android/tv/tuner/exoplayer/tests/AssetDataSource.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tv.tuner.exoplayer.tests;
-
-import android.content.Context;
-import android.content.res.AssetManager;
-import com.google.android.exoplayer.C;
-import com.google.android.exoplayer.upstream.DataSource;
-import com.google.android.exoplayer.upstream.DataSpec;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-
-/** A local asset. */
-// Copied from com.google.android.exoplayer.upstream.AssetDataSource for test.
-final class AssetDataSource implements DataSource {
- /** Thrown when an {@link IOException} is encountered reading a local asset. */
- private static final class AssetDataSourceException extends IOException {
- private AssetDataSourceException(IOException cause) {
- super(cause);
- }
- }
-
- private final AssetManager mAssetManager;
-
- private InputStream mInputStream;
- private long mBytesRemaining;
- private boolean mOpened;
-
- /** Constructs a new {@link DataSource} that retrieves data from a local asset. */
- AssetDataSource(Context context) {
- mAssetManager = context.getAssets();
- }
-
- @Override
- public long open(DataSpec dataSpec) throws AssetDataSourceException {
- try {
- String path = dataSpec.uri.getPath();
- if (path.startsWith("/android_asset/")) {
- path = path.substring(15);
- } else if (path.startsWith("/")) {
- path = path.substring(1);
- }
- mInputStream = mAssetManager.open(path, AssetManager.ACCESS_RANDOM);
- long skipped = mInputStream.skip(dataSpec.position);
- if (skipped < dataSpec.position) {
- // mAssetManager.open() returns an AssetInputStream, whose skip() implementation
- // only skips fewer bytes than requested if the skip is beyond the end of the
- // asset's data.
- throw new EOFException();
- }
- if (dataSpec.length != C.LENGTH_UNBOUNDED) {
- mBytesRemaining = dataSpec.length;
- } else {
- mBytesRemaining = mInputStream.available();
- if (mBytesRemaining == Integer.MAX_VALUE) {
- // mAssetManager.open() returns an AssetInputStream, whose available()
- // implementation returns Integer.MAX_VALUE if the remaining length is greater
- // than (or equal to) Integer.MAX_VALUE. We don't know the true length in this
- // case, so treat as unbounded.
- mBytesRemaining = C.LENGTH_UNBOUNDED;
- }
- }
- } catch (IOException e) {
- throw new AssetDataSourceException(e);
- }
-
- mOpened = true;
- return mBytesRemaining;
- }
-
- @Override
- public int read(byte[] buffer, int offset, int readLength) throws AssetDataSourceException {
- if (mBytesRemaining == 0) {
- return -1;
- } else {
- int bytesRead = 0;
- try {
- int bytesToRead =
- mBytesRemaining == C.LENGTH_UNBOUNDED
- ? readLength
- : (int) Math.min(mBytesRemaining, readLength);
- bytesRead = mInputStream.read(buffer, offset, bytesToRead);
- } catch (IOException e) {
- throw new AssetDataSourceException(e);
- }
-
- if (bytesRead > 0 && mBytesRemaining != C.LENGTH_UNBOUNDED) {
- mBytesRemaining -= bytesRead;
- }
-
- return bytesRead;
- }
- }
-
- @Override
- public void close() throws AssetDataSourceException {
- if (mInputStream != null) {
- try {
- mInputStream.close();
- } catch (IOException e) {
- throw new AssetDataSourceException(e);
- } finally {
- mInputStream = null;
- if (mOpened) {
- mOpened = false;
- }
- }
- }
- }
-}
diff --git a/tests/tunerunit/src/com/android/tv/tuner/exoplayer/tests/SampleSourceExtractorTest.java b/tests/tunerunit/src/com/android/tv/tuner/exoplayer/tests/SampleSourceExtractorTest.java
deleted file mode 100644
index d2247c7d..00000000
--- a/tests/tunerunit/src/com/android/tv/tuner/exoplayer/tests/SampleSourceExtractorTest.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tv.tuner.exoplayer.tests;
-
-import android.content.Context;
-import android.net.Uri;
-import android.os.SystemClock;
-import android.support.test.filters.LargeTest;
-import android.test.InstrumentationTestCase;
-import android.util.Pair;
-import com.android.tv.tuner.exoplayer.ExoPlayerSampleExtractor;
-import com.android.tv.tuner.exoplayer.buffer.BufferManager;
-import com.android.tv.tuner.exoplayer.buffer.BufferManager.StorageManager;
-import com.android.tv.tuner.exoplayer.buffer.SampleChunk;
-import com.android.tv.tuner.exoplayer.buffer.VerySlowSampleChunk;
-import com.android.tv.tuner.tvinput.PlaybackBufferListener;
-import com.google.android.exoplayer.MediaFormat;
-import com.google.android.exoplayer.SampleHolder;
-import com.google.android.exoplayer.SampleSource;
-import com.google.android.exoplayer.upstream.DataSource;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.SortedMap;
-
-@LargeTest
-public class SampleSourceExtractorTest extends InstrumentationTestCase {
- // Maximum bandwidth of 1080p channel is about 2.2MB/s. 2MB for a sample will suffice.
- private static final int SAMPLE_BUFFER_SIZE = 1024 * 1024 * 2;
- private static final int CONSUMING_SAMPLES_PERIOD = 100;
- private static final int PREPARE_POLL_DELAY_MILLIS = 100;
- private static final String TEST_TS_ASSET_PATH = "asset:///capture_stream.ts";
-
- public void testTrickplayDisabled() throws Throwable {
- DataSource source = new AssetDataSource(getInstrumentation().getContext());
- MockPlaybackBufferListener listener = new MockPlaybackBufferListener();
- ExoPlayerSampleExtractor extractor =
- new ExoPlayerSampleExtractor(
- Uri.parse(TEST_TS_ASSET_PATH), source, null, listener, false);
-
- assertEquals("Trickplay should be disabled", listener.getLastState(), Boolean.FALSE);
-
- // Prepares the extractor.
- try {
- while (!extractor.prepare()) {
- Thread.sleep(PREPARE_POLL_DELAY_MILLIS);
- }
- } catch (IOException | InterruptedException e) {
- fail("Exception occurred while preparing: " + e.getMessage());
- }
-
- // Selects all tracks.
- List<MediaFormat> trackFormats = extractor.getTrackFormats();
- for (int i = 0; i < trackFormats.size(); ++i) {
- extractor.selectTrack(i);
- }
-
- // Consumes over some period.
- SampleHolder sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_NORMAL);
- sampleHolder.ensureSpaceForWrite(SAMPLE_BUFFER_SIZE);
- for (int i = 0; i < CONSUMING_SAMPLES_PERIOD; ++i) {
- boolean found = false;
- while (!found) {
- for (int j = 0; j < trackFormats.size(); ++j) {
- int result = extractor.readSample(j, sampleHolder);
- switch (result) {
- case SampleSource.SAMPLE_READ:
- found = true;
- break;
- case SampleSource.END_OF_STREAM:
- fail("Failed to read samples");
- break;
- default:
- }
- if (found) {
- break;
- }
- }
- Thread.yield();
- }
- }
-
- extractor.release();
- }
-
- public void testDiskTooSlowTrickplayDisabled() throws Throwable {
- StorageManager storageManager =
- new StubStorageManager(getInstrumentation().getTargetContext());
- BufferManager bufferManager =
- new BufferManager(
- storageManager, new VerySlowSampleChunk.VerySlowSampleChunkCreator());
- bufferManager.setMinimumSampleSizeForSpeedCheck(0);
- DataSource source = new AssetDataSource(getInstrumentation().getContext());
- MockPlaybackBufferListener listener = new MockPlaybackBufferListener();
- ExoPlayerSampleExtractor extractor =
- new ExoPlayerSampleExtractor(
- Uri.parse(TEST_TS_ASSET_PATH), source, bufferManager, listener, false);
-
- assertEquals(
- "Trickplay should be enabled at the first", listener.getLastState(), Boolean.TRUE);
-
- // Prepares the extractor.
- try {
- while (!extractor.prepare()) {
- Thread.sleep(PREPARE_POLL_DELAY_MILLIS);
- }
- } catch (IOException | InterruptedException e) {
- fail("Exception occurred while preparing: " + e.getMessage());
- }
-
- // Selects all tracks.
- List<MediaFormat> trackFormats = extractor.getTrackFormats();
- for (int i = 0; i < trackFormats.size(); ++i) {
- extractor.selectTrack(i);
- }
-
- // Consumes until once speed check is done.
- SampleHolder sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_NORMAL);
- sampleHolder.ensureSpaceForWrite(SAMPLE_BUFFER_SIZE);
- while (!bufferManager.hasSpeedCheckDone()) {
- boolean found = false;
- while (!found) {
- for (int j = 0; j < trackFormats.size(); ++j) {
- int result = extractor.readSample(j, sampleHolder);
- switch (result) {
- case SampleSource.SAMPLE_READ:
- found = true;
- break;
- case SampleSource.END_OF_STREAM:
- fail("Failed to read samples");
- break;
- default:
- }
- if (found) {
- break;
- }
- }
- Thread.yield();
- }
- }
-
- extractor.release();
-
- // Sleep for synchronization.
- SystemClock.sleep(1000);
-
- assertEquals(
- "Disk too slow event should be reported", listener.isReportedDiskTooSlow(), true);
- }
-
- private static class StubStorageManager implements StorageManager {
- private final Context mContext;
-
- StubStorageManager(Context context) {
- mContext = context;
- }
-
- @Override
- public File getBufferDir() {
- return mContext.getCacheDir();
- }
-
- @Override
- public boolean isPersistent() {
- return false;
- }
-
- @Override
- public boolean reachedStorageMax(long bufferSize, long pendingDelete) {
- return false;
- }
-
- @Override
- public boolean hasEnoughBuffer(long pendingDelete) {
- return true;
- }
-
- @Override
- public List<BufferManager.TrackFormat> readTrackInfoFiles(boolean isAudio) {
- return null;
- }
-
- @Override
- public ArrayList<BufferManager.PositionHolder> readIndexFile(String trackId)
- throws IOException {
- return null;
- }
-
- @Override
- public void writeTrackInfoFiles(List<BufferManager.TrackFormat> formatList, boolean isAudio)
- throws IOException {
- // No-op.
- }
-
- @Override
- public void writeIndexFile(
- String trackName, SortedMap<Long, Pair<SampleChunk, Integer>> index)
- throws IOException {
- // No-op.
- }
- }
-
- public class MockPlaybackBufferListener implements PlaybackBufferListener {
- private Boolean mLastState;
- private boolean mIsReportedDiskTooSlow;
-
- public Boolean getLastState() {
- return mLastState;
- }
-
- public boolean isReportedDiskTooSlow() {
- return mIsReportedDiskTooSlow;
- }
-
- // PlaybackBufferListener
- @Override
- public void onBufferStartTimeChanged(long startTimeMs) {
- // No-op.
- }
-
- @Override
- public void onBufferStateChanged(boolean available) {
- mLastState = available;
- }
-
- @Override
- public void onDiskTooSlow() {
- mIsReportedDiskTooSlow = true;
- }
- }
-}
diff --git a/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java b/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java
index c2f0d0c5..ac0e0cac 100644
--- a/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java
+++ b/tests/unit/src/com/android/tv/recommendation/ChannelRecordTest.java
@@ -20,14 +20,17 @@ import static android.support.test.InstrumentationRegistry.getContext;
import static org.junit.Assert.assertEquals;
import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.tv.testing.utils.Utils;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
/** Unit tests for {@link ChannelRecord}. */
@SmallTest
+@RunWith(AndroidJUnit4.class)
public class ChannelRecordTest {
private static final int CHANNEL_RECORD_MAX_HISTORY_SIZE = ChannelRecord.MAX_HISTORY_SIZE;
diff --git a/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java b/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java
index 76c0a5ed..e3560467 100644
--- a/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java
+++ b/tests/unit/src/com/android/tv/recommendation/FavoriteChannelEvaluatorTest.java
@@ -19,12 +19,15 @@ package com.android.tv.recommendation;
import static org.junit.Assert.assertTrue;
import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
+import org.junit.runner.RunWith;
/** Unit tests for {@link FavoriteChannelEvaluator}. */
@SmallTest
+@RunWith(AndroidJUnit4.class)
public class FavoriteChannelEvaluatorTest extends EvaluatorTestCase<FavoriteChannelEvaluator> {
private static final int DEFAULT_NUMBER_OF_CHANNELS = 4;
private static final long DEFAULT_WATCH_START_TIME_MS =
diff --git a/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java b/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java
index fb957a83..7fa09b7a 100644
--- a/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java
+++ b/tests/unit/src/com/android/tv/recommendation/RecentChannelEvaluatorTest.java
@@ -19,14 +19,17 @@ package com.android.tv.recommendation;
import static org.junit.Assert.assertTrue;
import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
+import org.junit.runner.RunWith;
/** Unit tests for {@link RecentChannelEvaluator}. */
@SmallTest
+@RunWith(AndroidJUnit4.class)
public class RecentChannelEvaluatorTest extends EvaluatorTestCase<RecentChannelEvaluator> {
private static final int DEFAULT_NUMBER_OF_CHANNELS = 4;
private static final long DEFAULT_WATCH_START_TIME_MS =
diff --git a/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java b/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java
index 1b5cca72..f70c8e26 100644
--- a/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java
+++ b/tests/unit/src/com/android/tv/recommendation/RecommenderTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import android.test.MoreAsserts;
import com.android.tv.data.api.Channel;
import com.android.tv.recommendation.RecommendationUtils.ChannelRecordSortedMapHelper;
@@ -36,8 +37,10 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
@SmallTest
+@RunWith(AndroidJUnit4.class)
public class RecommenderTest {
private static final int DEFAULT_NUMBER_OF_CHANNELS = 5;
private static final long DEFAULT_WATCH_START_TIME_MS =
diff --git a/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java b/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java
index a675df85..91d61c06 100644
--- a/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java
+++ b/tests/unit/src/com/android/tv/recommendation/RoutineWatchEvaluatorTest.java
@@ -19,6 +19,7 @@ package com.android.tv.recommendation;
import static org.junit.Assert.assertEquals;
import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import android.test.MoreAsserts;
import com.android.tv.data.Program;
import com.android.tv.recommendation.RoutineWatchEvaluator.ProgramTime;
@@ -28,8 +29,10 @@ import java.util.List;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
+import org.junit.runner.RunWith;
@SmallTest
+@RunWith(AndroidJUnit4.class)
public class RoutineWatchEvaluatorTest extends EvaluatorTestCase<RoutineWatchEvaluator> {
private static class ScoredItem implements Comparable<ScoredItem> {
private final String mBase;
diff --git a/tests/unit/src/com/android/tv/tests/TvActivityTest.java b/tests/unit/src/com/android/tv/tests/TvActivityTest.java
deleted file mode 100644
index 30663e9a..00000000
--- a/tests/unit/src/com/android/tv/tests/TvActivityTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tv.tests;
-
-import static android.support.test.InstrumentationRegistry.getTargetContext;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import android.support.test.filters.MediumTest;
-import android.support.test.rule.ActivityTestRule;
-import com.android.tv.TvActivity;
-import com.android.tv.testing.utils.Utils;
-import org.junit.Rule;
-import org.junit.Test;
-
-@MediumTest
-public class TvActivityTest {
- @Rule
- public ActivityTestRule<TvActivity> mActivityTestRule =
- new ActivityTestRule<>(TvActivity.class, false, false);
-
- @Test
- public void testLifeCycle() {
- assertTrue("TvActivity should be enabled.", Utils.isTvActivityEnabled(getTargetContext()));
- assertNotNull(mActivityTestRule.launchActivity(null));
- }
-}
diff --git a/tuner/src/com/android/tv/tuner/exoplayer/ExoPlayerSampleExtractor.java b/tuner/src/com/android/tv/tuner/exoplayer/ExoPlayerSampleExtractor.java
index 488c099f..e10a2991 100644
--- a/tuner/src/com/android/tv/tuner/exoplayer/ExoPlayerSampleExtractor.java
+++ b/tuner/src/com/android/tv/tuner/exoplayer/ExoPlayerSampleExtractor.java
@@ -23,6 +23,7 @@ import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
+import android.support.annotation.VisibleForTesting;
import android.util.Pair;
import com.android.tv.tuner.exoplayer.audio.MpegTsDefaultAudioTrackRenderer;
import com.android.tv.tuner.exoplayer.buffer.BufferManager;
@@ -90,6 +91,25 @@ public class ExoPlayerSampleExtractor implements SampleExtractor {
BufferManager bufferManager,
PlaybackBufferListener bufferListener,
boolean isRecording) {
+ this(
+ uri,
+ source,
+ bufferManager,
+ bufferListener,
+ isRecording,
+ Looper.myLooper(),
+ new HandlerThread("SourceReaderThread"));
+ }
+
+ @VisibleForTesting
+ public ExoPlayerSampleExtractor(
+ Uri uri,
+ DataSource source,
+ BufferManager bufferManager,
+ PlaybackBufferListener bufferListener,
+ boolean isRecording,
+ Looper workerLooper,
+ HandlerThread sourceReaderThread) {
// It'll be used as a timeshift file chunk name's prefix.
mId = System.currentTimeMillis();
@@ -101,7 +121,7 @@ public class ExoPlayerSampleExtractor implements SampleExtractor {
}
};
- mSourceReaderThread = new HandlerThread("SourceReaderThread");
+ mSourceReaderThread = sourceReaderThread;
mSourceReaderWorker =
new SourceReaderWorker(
new ExtractorMediaSource(
@@ -148,8 +168,7 @@ public class ExoPlayerSampleExtractor implements SampleExtractor {
}
},
new ExoPlayerExtractorsFactory(),
- // Do not create a handler if we not on a looper. e.g. test.
- Looper.myLooper() != null ? new Handler() : null,
+ new Handler(workerLooper),
eventListener));
if (isRecording) {
mSampleBuffer =
diff --git a/tuner/src/com/android/tv/tuner/exoplayer/buffer/SampleChunk.java b/tuner/src/com/android/tv/tuner/exoplayer/buffer/SampleChunk.java
index 294912e1..bf77a6eb 100644
--- a/tuner/src/com/android/tv/tuner/exoplayer/buffer/SampleChunk.java
+++ b/tuner/src/com/android/tv/tuner/exoplayer/buffer/SampleChunk.java
@@ -79,7 +79,8 @@ public class SampleChunk {
* @param startPositionUs the start position of the earliest sample to be stored
* @param chunkCallback for total storage usage change notification
*/
- SampleChunk createSampleChunk(
+ @VisibleForTesting
+ public SampleChunk createSampleChunk(
SamplePool samplePool,
File file,
long startPositionUs,
@@ -121,7 +122,8 @@ public class SampleChunk {
* Handles I/O for SampleChunk. Maintains current SampleChunk and the current offset for next
* I/O operation.
*/
- static class IoState {
+ @VisibleForTesting
+ public static class IoState {
private SampleChunk mChunk;
private long mCurrentOffset;
diff --git a/tuner/tests/testing/Android.mk b/tuner/tests/testing/Android.mk
new file mode 100644
index 00000000..0d71b739
--- /dev/null
+++ b/tuner/tests/testing/Android.mk
@@ -0,0 +1,29 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# Include all test java files.
+LOCAL_SRC_FILES := \
+ $(call all-java-files-under, src) \
+ $(call all-Iaidl-files-under, src)
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+ android-support-annotations \
+ android-support-test \
+ guava \
+ mockito-target \
+ platform-robolectric-3.6.1-prebuilt \
+ truth-0-36-prebuilt-jar \
+ ub-uiautomator \
+
+# Link tv-common as shared library to avoid the problem of initialization of the constants
+LOCAL_JAVA_LIBRARIES := tv-common
+
+LOCAL_INSTRUMENTATION_FOR := LiveTv
+LOCAL_MODULE := tv-tuner-testing
+LOCAL_MODULE_TAGS := optional
+LOCAL_SDK_VERSION := system_current
+
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
+LOCAL_AIDL_INCLUDES += $(LOCAL_PATH)/src
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/tests/tunerunit/AndroidManifest.xml b/tuner/tests/testing/AndroidManifest.xml
index ae9609ac..f244ae7b 100644
--- a/tests/tunerunit/AndroidManifest.xml
+++ b/tuner/tests/testing/AndroidManifest.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- ~ Copyright (C) 2018 The Android Open Source Project
+ ~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
@@ -12,21 +12,12 @@
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
- ~ limitations under the License
+ ~ limitations under the License.
-->
-
+<!-- Stub AndroidManifest.xml to build resources -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.tv.tests" >
-
- <uses-sdk android:targetSdkVersion="26" android:minSdkVersion="23" />
-
- <instrumentation
- android:name="android.support.test.runner.AndroidJUnitRunner"
- android:label="Live Channel Unit Tests"
- android:targetPackage="com.android.tv.tuner" />
-
- <application android:label="TunerTest" >
- <uses-library android:name="android.test.runner" />
- </application>
-
-</manifest> \ No newline at end of file
+ package="com.android.tv.tuner.testing"
+ android:versionCode="1">
+ <uses-sdk android:targetSdkVersion="26" android:minSdkVersion="21"/>
+ <application />
+</manifest>
diff --git a/tests/tunerunit/src/com/android/tv/tuner/exoplayer/buffer/VerySlowSampleChunk.java b/tuner/tests/testing/src/com/android/tv/tuner/testing/buffer/VerySlowSampleChunk.java
index ecfbb643..b68431cc 100644
--- a/tests/tunerunit/src/com/android/tv/tuner/exoplayer/buffer/VerySlowSampleChunk.java
+++ b/tuner/tests/testing/src/com/android/tv/tuner/testing/buffer/VerySlowSampleChunk.java
@@ -13,15 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.tv.tuner.exoplayer.buffer;
+package com.android.tv.tuner.testing.buffer;
import android.os.SystemClock;
+import com.android.tv.tuner.exoplayer.buffer.SampleChunk;
+import com.android.tv.tuner.exoplayer.buffer.SamplePool;
import com.google.android.exoplayer.SampleHolder;
import java.io.File;
import java.io.IOException;
+/** A Sample chunk that is slow for testing */
public class VerySlowSampleChunk extends SampleChunk {
+ /** Creates a {@link VerySlowSampleChunk}. */
public static class VerySlowSampleChunkCreator extends SampleChunkCreator {
@Override
public SampleChunk createSampleChunk(