aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNick Chalko <nchalko@google.com>2015-12-09 13:48:17 -0800
committerNick Chalko <nchalko@google.com>2015-12-11 15:09:19 -0800
commit1abddd9f6225298066094e20a6c29061b6af4590 (patch)
tree97d701f8681cca9939c86e5e61523775d4c13aea /tests
parent7d67089aa1e9aa2123c3cd2f386d7019a1544db1 (diff)
downloadTV-1abddd9f6225298066094e20a6c29061b6af4590.tar.gz
Sync to ub-tv-heroes at 1.08.301
source change id If9b64d7bbc6e8f77b360e502d34e5452775c0402 Change-Id: I4ffe87911cb85e54880d1d918d1b8fb7bb8cfb7d
Diffstat (limited to 'tests')
-rw-r--r--tests/common/src/com/android/tv/MockTvApplication.java86
-rw-r--r--tests/common/src/com/android/tv/testing/ChannelUtils.java5
-rw-r--r--tests/common/src/com/android/tv/testing/FakeClock.java106
-rw-r--r--tests/common/src/com/android/tv/testing/ProgramUtils.java3
-rw-r--r--tests/common/src/com/android/tv/testing/Utils.java3
-rw-r--r--tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java (renamed from tests/unit/src/com/android/tv/util/FakeClock.java)28
-rw-r--r--tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java4
-rw-r--r--tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java (renamed from tests/unit/src/com/android/tv/ui/SetupViewTest.java)9
-rw-r--r--tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java61
-rw-r--r--tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java73
-rw-r--r--tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java112
-rw-r--r--tests/unit/src/com/android/tv/dvr/RecordingTest.java50
-rw-r--r--tests/unit/src/com/android/tv/dvr/SchedulerTest.java85
-rw-r--r--tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java4
14 files changed, 602 insertions, 27 deletions
diff --git a/tests/common/src/com/android/tv/MockTvApplication.java b/tests/common/src/com/android/tv/MockTvApplication.java
new file mode 100644
index 00000000..7060e6b0
--- /dev/null
+++ b/tests/common/src/com/android/tv/MockTvApplication.java
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import android.app.Application;
+import android.test.mock.MockApplication;
+
+import com.android.tv.analytics.Analytics;
+import com.android.tv.analytics.OptOutPreferenceHelper;
+import com.android.tv.analytics.Tracker;
+import com.android.tv.data.ChannelDataManager;
+import com.android.tv.data.ProgramDataManager;
+import com.android.tv.dvr.DvrDataManager;
+import com.android.tv.dvr.DvrManager;
+import com.android.tv.dvr.DvrSessionManager;
+import com.android.tv.util.TvInputManagerHelper;
+
+/**
+ * A mock TV Application used for testing.
+ */
+public class MockTvApplication extends MockApplication implements ApplicationSingletons {
+ public final ApplicationSingletons mDelegate;
+
+ public MockTvApplication(ApplicationSingletons delegate) {
+ mDelegate = delegate;
+ }
+
+ @Override
+ public DvrManager getDvrManager() {
+ return mDelegate.getDvrManager();
+ }
+
+ @Override
+ public DvrSessionManager getDvrSessionManger() {
+ return mDelegate.getDvrSessionManger();
+ }
+
+ @Override
+ public Analytics getAnalytics() {
+ return mDelegate.getAnalytics();
+ }
+
+ @Override
+ public Tracker getTracker() {
+ return mDelegate.getTracker();
+ }
+
+ @Override
+ public OptOutPreferenceHelper getOptPreferenceHelper() {
+ return mDelegate.getOptPreferenceHelper();
+ }
+
+ @Override
+ public ChannelDataManager getChannelDataManager() {
+ return mDelegate.getChannelDataManager();
+ }
+
+ @Override
+ public ProgramDataManager getProgramDataManager() {
+ return mDelegate.getProgramDataManager();
+ }
+
+ @Override
+ public DvrDataManager getDvrDataManager() {
+ return mDelegate.getDvrDataManager();
+ }
+
+ @Override
+ public TvInputManagerHelper getTvInputManagerHelper() {
+ return mDelegate.getTvInputManagerHelper();
+ }
+}
diff --git a/tests/common/src/com/android/tv/testing/ChannelUtils.java b/tests/common/src/com/android/tv/testing/ChannelUtils.java
index 8d96cbed..00881c86 100644
--- a/tests/common/src/com/android/tv/testing/ChannelUtils.java
+++ b/tests/common/src/com/android/tv/testing/ChannelUtils.java
@@ -41,6 +41,7 @@ import java.util.Map;
*/
public class ChannelUtils {
private static final String TAG = "ChannelUtils";
+ private static final boolean DEBUG = false;
/**
* Query and return the map of (channel_id, ChannelInfo).
@@ -115,10 +116,10 @@ public class ChannelUtils {
Long rowId = existingChannelsMap.get(channel.originalNetworkId);
Uri uri;
if (rowId == null) {
- Log.v(TAG, "Inserting "+ channel);
+ if (DEBUG) Log.d(TAG, "Inserting "+ channel);
uri = resolver.insert(TvContract.Channels.CONTENT_URI, values);
} else {
- Log.v(TAG, "Updating "+ channel);
+ if (DEBUG) Log.d(TAG, "Updating "+ channel);
uri = TvContract.buildChannelUri(rowId);
resolver.update(uri, values, null, null);
existingChannelsMap.remove(channel.originalNetworkId);
diff --git a/tests/common/src/com/android/tv/testing/FakeClock.java b/tests/common/src/com/android/tv/testing/FakeClock.java
new file mode 100644
index 00000000..372a7569
--- /dev/null
+++ b/tests/common/src/com/android/tv/testing/FakeClock.java
@@ -0,0 +1,106 @@
+/*
+ * 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.testing;
+
+import com.android.tv.util.Clock;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Fake implementation of Clock suitable for testing.
+ *
+ * <p>The current time only changes if {@link #setCurrentTimeMillis(long)}, {@link #increment} or
+ * {@link #sleep(long)} is called.
+ */
+public class FakeClock implements Clock {
+ /**
+ * Creates a fake clock with the time set to now and the boot time set to now - 100,000.
+ */
+ public static FakeClock createWithCurrentTime() {
+ long now = System.currentTimeMillis();
+ return new FakeClock(now, now - 100_000);
+ }
+
+ /**
+ * Creates a fake clock with the time set to zero.
+ */
+ public static FakeClock createWithTimeOne() {
+ return new FakeClock(1L, 0L);
+ }
+
+
+ private long mCurrentTimeMillis;
+
+ private long mBootTimeMillis;
+
+ private FakeClock(long currentTimeMillis, long bootTimeMillis) {
+ mCurrentTimeMillis = currentTimeMillis;
+ mBootTimeMillis = bootTimeMillis;
+ }
+
+ public void setCurrentTimeMillis(long ms) {
+ if (ms < mBootTimeMillis) {
+ throw new IllegalStateException("current time can not be before boot time");
+ }
+ mCurrentTimeMillis = ms;
+ }
+
+ public void setBootTimeMillis(long ms) {
+ if (ms > mCurrentTimeMillis) {
+ throw new IllegalStateException("boot time can not be after current time");
+ }
+ mBootTimeMillis = ms;
+ }
+
+ /**
+ * Increment the current time by one unit of time.
+ *
+ * @param unit The time unit to increment by.
+ */
+ public void increment(TimeUnit unit) {
+ increment(unit, 1);
+ }
+
+ /**
+ * Increment the current time by {@code amount} unit of time.
+ *
+ * @param unit The time unit to increment by.
+ * @param amount The amount of time units to increment by.
+ */
+ private void increment(TimeUnit unit, long amount) {
+ mCurrentTimeMillis += unit.toMillis(amount);
+ }
+
+ @Override
+ public long currentTimeMillis() {
+ return mCurrentTimeMillis;
+ }
+
+ @Override
+ public long elapsedRealtime() {
+ return mCurrentTimeMillis - mBootTimeMillis;
+ }
+
+ /**
+ * Sleep does not block it just updates the current time.
+ */
+ @Override
+ public void sleep(long ms) {
+ // TODO: implement blocking if needed.
+ mCurrentTimeMillis += ms;
+ }
+}
diff --git a/tests/common/src/com/android/tv/testing/ProgramUtils.java b/tests/common/src/com/android/tv/testing/ProgramUtils.java
index 92fe9c82..493891b6 100644
--- a/tests/common/src/com/android/tv/testing/ProgramUtils.java
+++ b/tests/common/src/com/android/tv/testing/ProgramUtils.java
@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
public class ProgramUtils {
private static final String TAG = "ProgramUtils";
+ private static final boolean DEBUG = false;
// Populate program data for a week.
private static final long PROGRAM_INSERT_DURATION_MS = TimeUnit.DAYS.toMillis(7);
@@ -77,7 +78,7 @@ public class ProgramUtils {
|| timeMs >= targetEndTimeMs) {
context.getContentResolver().bulkInsert(Programs.CONTENT_URI,
list.toArray(new ContentValues[list.size()]));
- Log.v(TAG, "Inserted " + list.size() + " programs for " + channelUri);
+ if (DEBUG) Log.d(TAG, "Inserted " + list.size() + " programs for " + channelUri);
list.clear();
}
}
diff --git a/tests/common/src/com/android/tv/testing/Utils.java b/tests/common/src/com/android/tv/testing/Utils.java
index c1a7506f..9e1bd3e9 100644
--- a/tests/common/src/com/android/tv/testing/Utils.java
+++ b/tests/common/src/com/android/tv/testing/Utils.java
@@ -29,6 +29,7 @@ import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
+import com.android.tv.common.TvCommonUtils;
import com.android.tv.util.MainThreadExecutor;
import java.io.IOException;
@@ -46,7 +47,7 @@ import java.util.concurrent.Future;
*
* <p>This class is also used to check whether TV app is running in tests or not.
*
- * @see com.android.tv.util.Utils#isRunningInTest
+ * @see TvCommonUtils#isRunningInTest
*/
public final class Utils {
private static final String TAG ="Utils";
diff --git a/tests/unit/src/com/android/tv/util/FakeClock.java b/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java
index a4ab2e4f..30e21e2e 100644
--- a/tests/unit/src/com/android/tv/util/FakeClock.java
+++ b/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java
@@ -11,24 +11,24 @@
* 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
*/
-package com.android.tv.util;
+package com.android.tv.testing.dvr;
-public class FakeClock implements Clock {
- private long mCurrentTimeMillis;
+import com.android.tv.data.Channel;
+import com.android.tv.dvr.Recording;
- public FakeClock() {
- mCurrentTimeMillis = System.currentTimeMillis();
- }
-
- public void setCurrentTimeMillis(long time) {
- mCurrentTimeMillis = time;
- }
+import java.util.Collections;
- @Override
- public long currentTimeMillis() {
- return mCurrentTimeMillis;
+/**
+ * Static utils for using {@link Recording} in tests.
+ */
+public class RecordingTestUtils {
+ public static Recording createTestRecordingWithPeriod(long id, long startTime, long endTime) {
+ return Recording.builder(new Channel.Builder().build(), startTime, endTime)
+ .setId(id)
+ .setPrograms(Collections.EMPTY_LIST)
+ .build();
}
}
diff --git a/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java b/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java
index 78b3a930..96ecefdf 100644
--- a/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java
+++ b/tests/unit/src/com/android/tv/data/ProgramDataManagerTest.java
@@ -32,7 +32,7 @@ import android.util.SparseArray;
import com.android.tv.testing.Constants;
import com.android.tv.testing.ProgramInfo;
-import com.android.tv.util.FakeClock;
+import com.android.tv.testing.FakeClock;
import com.android.tv.util.Utils;
import java.util.ArrayList;
@@ -70,7 +70,7 @@ public class ProgramDataManagerTest extends AndroidTestCase {
protected void setUp() throws Exception {
super.setUp();
- mClock = new FakeClock();
+ mClock = FakeClock.createWithCurrentTime();
mListener = new TestProgramDataManagerListener();
mContentProvider = new FakeContentProvider(getContext());
mContentResolver = new FakeContentResolver();
diff --git a/tests/unit/src/com/android/tv/ui/SetupViewTest.java b/tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java
index d3579d13..bc239a8a 100644
--- a/tests/unit/src/com/android/tv/ui/SetupViewTest.java
+++ b/tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.tv.ui;
+package com.android.tv.data;
import android.content.pm.ResolveInfo;
import android.media.tv.TvInputInfo;
@@ -35,10 +35,10 @@ import java.util.Comparator;
import java.util.LinkedHashMap;
/**
- * Test for {@link SetupView}
+ * Test for {@link TvInputNewComparator}
*/
@SmallTest
-public class SetupViewTest extends AndroidTestCase {
+public class TvInputNewComparatorTest extends AndroidTestCase {
public void testComparator() throws Exception {
final LinkedHashMap<String, Boolean> INPUT_ID_TO_NEW_INPUT = new LinkedHashMap<>();
INPUT_ID_TO_NEW_INPUT.put("2_new_input", true);
@@ -66,8 +66,7 @@ public class SetupViewTest extends AndroidTestCase {
}
}
);
- SetupView.TvInputInfoComparator comparator =
- new SetupView.TvInputInfoComparator(setupUtils, inputManager);
+ TvInputNewComparator comparator = new TvInputNewComparator(setupUtils, inputManager);
ComparatorTester<TvInputInfo> comparatorTester =
ComparatorTester.withoutEqualsTest(comparator);
ResolveInfo resolveInfo = TestUtils.createResolveInfo("test", "test");
diff --git a/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java b/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java
new file mode 100644
index 00000000..06cf7315
--- /dev/null
+++ b/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.dvr;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.tv.testing.dvr.RecordingTestUtils;
+
+import junit.framework.TestCase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for {@link DvrDataManagerImplTest}
+ */
+@SmallTest
+public class DvrDataManagerImplTest extends TestCase {
+ public void testGetNextScheduledStartTimeAfter() throws Exception {
+ long id = 1;
+ List<Recording> recordings = new ArrayList<>();
+ assertNextStartTime(recordings, 0L, DvrDataManager.NEXT_START_TIME_NOT_FOUND);
+ recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 10L, 20L));
+ assertNextStartTime(recordings, 9L, 10L);
+ assertNextStartTime(recordings, 10L, DvrDataManager.NEXT_START_TIME_NOT_FOUND);
+ recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 20L, 30L));
+ assertNextStartTime(recordings, 9L, 10L);
+ assertNextStartTime(recordings, 10L, 20L);
+ assertNextStartTime(recordings, 20L, DvrDataManager.NEXT_START_TIME_NOT_FOUND);
+ recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 30L, 40L));
+ assertNextStartTime(recordings, 9L, 10L);
+ assertNextStartTime(recordings, 10L, 20L);
+ assertNextStartTime(recordings, 20L, 30L);
+ assertNextStartTime(recordings, 30L, DvrDataManager.NEXT_START_TIME_NOT_FOUND);
+ recordings.clear();
+ recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 10L, 20L));
+ recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 10L, 20L));
+ recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 10L, 20L));
+ assertNextStartTime(recordings, 9L, 10L);
+ assertNextStartTime(recordings, 10L, DvrDataManager.NEXT_START_TIME_NOT_FOUND);
+ }
+
+ private void assertNextStartTime(List<Recording> recordings, long startTime, long expected) {
+ assertEquals("getNextScheduledStartTimeAfter()", expected,
+ DvrDataManagerImpl.getNextStartTimeAfter(recordings, startTime));
+ }
+} \ No newline at end of file
diff --git a/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java b/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java
new file mode 100644
index 00000000..85c2f661
--- /dev/null
+++ b/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.dvr;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.test.ServiceTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.tv.ApplicationSingletons;
+import com.android.tv.Features;
+import com.android.tv.MockTvApplication;
+import com.android.tv.common.feature.TestableFeature;
+
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Tests for {@link DvrRecordingService}.
+ */
+@SmallTest
+public class DvrRecordingServiceTest extends ServiceTestCase<DvrRecordingService> {
+
+ @Mock Scheduler mMockScheduler;
+ @Mock ApplicationSingletons mApplicationSingletons;
+ private final TestableFeature mDvrFeature = Features.DVR;
+ private DvrDataManagerInMemoryImpl mDataManager;
+ private DvrRecordingService mService;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mDvrFeature.enableForTest();
+ MockitoAnnotations.initMocks(this);
+ mDataManager = new DvrDataManagerInMemoryImpl(getContext());
+ setApplication(new MockTvApplication(mApplicationSingletons));
+ when(mApplicationSingletons.getDvrDataManager()).thenReturn(mDataManager);
+ setupService();
+ mService = getService();
+ mService.setScheduler(mMockScheduler);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mDvrFeature.resetForTests();
+ super.tearDown();
+ }
+
+ public DvrRecordingServiceTest() {
+ super(DvrRecordingService.class);
+ }
+
+ public void testStartService_null() throws Exception {
+ startService(null);
+ verify(mMockScheduler, Mockito.only()).update();
+ }
+} \ No newline at end of file
diff --git a/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java b/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java
new file mode 100644
index 00000000..063cd61f
--- /dev/null
+++ b/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.dvr;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.tv.common.dvr.DvrSessionClient;
+import com.android.tv.data.Channel;
+import com.android.tv.testing.FakeClock;
+import com.android.tv.testing.dvr.RecordingTestUtils;
+
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Tests for {@link RecordingTask}.
+ */
+@SmallTest
+public class RecordingTaskTest extends AndroidTestCase {
+ private FakeClock mFakeClock;
+ private DvrDataManagerInMemoryImpl mDataManager;
+ @Mock
+ DvrSessionManager mMockSessionManager;
+ @Mock
+ DvrSessionClient mMockDvrSessionClient;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ MockitoAnnotations.initMocks(this);
+ mFakeClock = FakeClock.createWithTimeOne();
+ mDataManager = new DvrDataManagerInMemoryImpl(getContext());
+ }
+
+ public void testRun_sleepUntil() {
+ long startTime = mFakeClock.currentTimeMillis();
+ long endTime = startTime + 1;
+ Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, startTime, endTime);
+ RecordingTask task = new RecordingTask(r, mMockSessionManager, mDataManager,
+ mFakeClock);
+
+ Channel channel = r.getChannel();
+ String inputId = channel.getInputId();
+ when(mMockSessionManager.canAcquireDvrSession(inputId, channel))
+ .thenReturn(true);
+ when(mMockSessionManager.acquireDvrSession(inputId, channel))
+ .thenReturn(mMockDvrSessionClient);
+ task.run();
+ assertEquals("Recording " + r + "finish time", endTime + RecordingTask.MS_AFTER_END,
+ mFakeClock.currentTimeMillis());
+ }
+
+ public void testRun_connectAndRelease() {
+ long startTime = mFakeClock.currentTimeMillis();
+ long endTime = startTime + 1;
+ Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, startTime, endTime);
+ RecordingTask task = new RecordingTask(r, mMockSessionManager, mDataManager,
+ mFakeClock);
+
+ Channel channel = r.getChannel();
+ String inputId = channel.getInputId();
+ when(mMockSessionManager.canAcquireDvrSession(inputId, channel))
+ .thenReturn(true);
+ when(mMockSessionManager.acquireDvrSession(inputId, channel))
+ .thenReturn(mMockDvrSessionClient);
+ task.run();
+
+ verify(mMockSessionManager).canAcquireDvrSession(inputId, channel);
+ verify(mMockSessionManager).acquireDvrSession(inputId, channel);
+ verify(mMockDvrSessionClient).connect(inputId, task);
+ verify(mMockDvrSessionClient).startRecord(channel.getUri(),
+ RecordingTask.getIdAsMediaUri(r));
+ verify(mMockDvrSessionClient).stopRecord();
+ verify(mMockSessionManager).releaseDvrSession(mMockDvrSessionClient);
+ verifyNoMoreInteractions(mMockDvrSessionClient, mMockSessionManager);
+ }
+
+
+ public void testRun_cannotAcquireSession() {
+ long startTime = mFakeClock.currentTimeMillis();
+ long endTime = startTime + 1;
+ Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, startTime, endTime);
+ mDataManager.addRecording(r);
+ RecordingTask task = new RecordingTask(r, mMockSessionManager, mDataManager,
+ mFakeClock);
+
+ when(mMockSessionManager.canAcquireDvrSession(r.getChannel().getInputId(), r.getChannel()))
+ .thenReturn(false);
+ task.run();
+ Recording updatedRecording = mDataManager.getRecording(r.getId());
+ assertEquals("status",Recording.STATE_RECORDING_FAILED, updatedRecording.getState() );
+ }
+} \ No newline at end of file
diff --git a/tests/unit/src/com/android/tv/dvr/RecordingTest.java b/tests/unit/src/com/android/tv/dvr/RecordingTest.java
new file mode 100644
index 00000000..ef012248
--- /dev/null
+++ b/tests/unit/src/com/android/tv/dvr/RecordingTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.dvr;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import android.util.Range;
+
+import com.android.tv.testing.dvr.RecordingTestUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link RecordingTest}
+ */
+@SmallTest
+public class RecordingTest extends TestCase {
+ public void testIsOverLapping() throws Exception {
+ Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, 10L, 20L);
+ assertOverLapping(false, 1L, 9L, r);
+
+ assertOverLapping(true, 1L, 20L, r);
+ assertOverLapping(true, 1L, 10L, r);
+ assertOverLapping(true, 10L, 19L, r);
+ assertOverLapping(true, 10L, 20L, r);
+ assertOverLapping(true, 11L, 20L, r);
+ assertOverLapping(true, 11L, 21L, r);
+ assertOverLapping(true, 20L, 21L, r);
+
+ assertOverLapping(false, 21L, 29L, r);
+ }
+
+ private void assertOverLapping(boolean expected, long lower, long upper, Recording r) {
+ assertEquals("isOverlapping(Range(" + lower + "," + upper + "), recording " + r, expected,
+ r.isOverLapping(new Range<Long>(lower, upper)));
+ }
+}
diff --git a/tests/unit/src/com/android/tv/dvr/SchedulerTest.java b/tests/unit/src/com/android/tv/dvr/SchedulerTest.java
new file mode 100644
index 00000000..281b055a
--- /dev/null
+++ b/tests/unit/src/com/android/tv/dvr/SchedulerTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.dvr;
+
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.tv.testing.FakeClock;
+import com.android.tv.testing.dvr.RecordingTestUtils;
+
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Tests for {@link Scheduler}.
+ */
+@SmallTest
+public class SchedulerTest extends AndroidTestCase {
+ private FakeClock mClock;
+ private DvrDataManagerInMemoryImpl mDataManager;
+ private Scheduler mScheduler;
+ @Mock DvrSessionManager mSessionManager;
+ @Mock AlarmManager mMockAlarmManager;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ MockitoAnnotations.initMocks(this);
+ mClock = FakeClock.createWithCurrentTime();
+ mDataManager = new DvrDataManagerInMemoryImpl(getContext());
+ mScheduler = new Scheduler(mSessionManager, mDataManager, getContext(), mClock,
+ mMockAlarmManager);
+ }
+
+ public void testUpdate_none() throws Exception {
+ mScheduler.update();
+ verifyZeroInteractions(mMockAlarmManager);
+ }
+
+ public void testUpdate_nextIn12Hours() throws Exception {
+ long now = mClock.currentTimeMillis();
+ long startTime = now + TimeUnit.HOURS.toMillis(12);
+ Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, startTime,
+ startTime + TimeUnit.HOURS.toMillis(1));
+ mDataManager.addRecording(r);
+ mScheduler.update();
+ verify(mMockAlarmManager).set(
+ eq(AlarmManager.RTC_WAKEUP),
+ eq(startTime - Scheduler.MS_TO_WAKE_BEFORE_START),
+ any(PendingIntent.class));
+ }
+
+ public void testStartsWithin() throws Exception {
+ long now = mClock.currentTimeMillis();
+ long startTime = now + 3;
+ Recording r = RecordingTestUtils
+ .createTestRecordingWithPeriod(1, startTime, startTime + 100);
+ assertFalse(mScheduler.startsWithin(r, 2));
+ assertTrue(mScheduler.startsWithin(r, 3));
+ }
+} \ No newline at end of file
diff --git a/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java b/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java
index 601ed661..afcb812a 100644
--- a/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java
+++ b/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java
@@ -37,8 +37,8 @@ public class UtilsTest_GetMultiAudioString extends AndroidTestCase {
Utils.getMultiAudioString(context, createAudioTrackInfo("eng"), false));
assertEquals("Unknown language",
Utils.getMultiAudioString(context, createAudioTrackInfo(null), false));
- // TODO: Check whether the following tests are expected.
- assertEquals("", Utils.getMultiAudioString(context, createAudioTrackInfo(""), false));
+ assertEquals("Unknown language",
+ Utils.getMultiAudioString(context, createAudioTrackInfo(""), false));
assertEquals("abc", Utils.getMultiAudioString(context, createAudioTrackInfo("abc"), false));
}