diff options
Diffstat (limited to 'tests')
26 files changed, 373 insertions, 215 deletions
diff --git a/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java b/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java index b9def95e..a9bfa97a 100644 --- a/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java +++ b/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java @@ -16,7 +16,7 @@ package com.android.tv.testing.dvr; -import com.android.tv.dvr.ScheduledRecording; +import com.android.tv.dvr.data.ScheduledRecording; import junit.framework.Assert; diff --git a/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java b/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java index 25c7909b..e306e6c6 100644 --- a/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java +++ b/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java @@ -73,6 +73,8 @@ public abstract class LiveChannelsTestCase extends InstrumentationTestCase { .hasObject(Constants.PROGRAM_GUIDE)) { mDevice.pressBack(); } + // To destroy the activity to make sure next test case's activity launch check works well. + mDevice.pressBack(); super.tearDown(); } diff --git a/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java b/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java index bbc7aa81..82c6a810 100644 --- a/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java +++ b/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java @@ -16,11 +16,11 @@ package com.android.tv.tests.ui; +import static com.android.tv.testing.uihelper.Constants.CHANNEL_BANNER; import static com.android.tv.testing.uihelper.Constants.FOCUSED_VIEW; import static com.android.tv.testing.uihelper.Constants.MENU; import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition; -import android.support.test.filters.SdkSuppress; import android.support.test.filters.SmallTest; import android.support.test.uiautomator.BySelector; import android.support.test.uiautomator.UiObject2; @@ -32,9 +32,8 @@ import com.android.tv.testing.testinput.TvTestInputConstants; import com.android.tv.testing.uihelper.DialogHelper; @SmallTest -@SdkSuppress(minSdkVersion = 23) public class PlayControlsRowViewTest extends LiveChannelsTestCase { - private static final int BUTTON_INDEX_PLAY_PAUSE = 2; + private static final String BUTTON_ID_PLAY_PAUSE = "com.android.tv:id/play_pause"; private BySelector mBySettingsSidePanel; @@ -42,7 +41,9 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { protected void setUp() throws Exception { super.setUp(); mLiveChannelsHelper.assertAppStarted(); - pressKeysForChannel(TvTestInputConstants.CH_1_DEFAULT_DONT_MODIFY); + pressKeysForChannel(TvTestInputConstants.CH_2); + // Wait until KeypadChannelSwitchView closes. + assertWaitForCondition(mDevice, Until.hasObject(CHANNEL_BANNER)); // Tune to a new channel to ensure that the channel is changed. mDevice.pressDPadUp(); getInstrumentation().waitForIdleSync(); @@ -56,7 +57,7 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { public void testFocusedViewInNormalCase() { mMenuHelper.showMenu(); mMenuHelper.assertNavigateToPlayControlsRow(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); mDevice.pressBack(); } @@ -69,49 +70,30 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { // Fast forward button mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD); mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); mDevice.pressBack(); // Next button mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_NEXT); mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); - mDevice.pressBack(); - } - - /** - * Tests the case when the rewinding action is disabled. - * In this case, the button corresponding to the action is disabled, so play/pause button should - * have the focus. - */ - public void testFocusedViewWithDisabledActionBackward() { - // Previous button - mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_PREVIOUS); - mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); - mDevice.pressBack(); - - // Rewind button - mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_REWIND); - mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); mDevice.pressBack(); } public void testFocusedViewInMenu() { mMenuHelper.showMenu(); mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_PLAY); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); mMenuHelper.assertNavigateToRow(R.string.menu_title_channels); mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_NEXT); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); } public void testKeepPausedWhileParentalControlChange() { // Pause the playback. mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_PAUSE); mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); // Show parental controls fragment. mMenuHelper.assertPressOptionsSettings(); assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); @@ -130,14 +112,14 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { mDevice.pressBack(); // Return to the main menu. mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); } public void testKeepPausedAfterVisitingHome() { // Pause the playback. mDevice.pressKeyCode(KeyEvent.KEYCODE_MEDIA_PAUSE); mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); // Press HOME twice to visit the home screen and return to Live TV. mDevice.pressHome(); // Wait until home screen is shown. @@ -147,19 +129,15 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { mDevice.waitForIdle(); // Return to the main menu. mMenuHelper.assertWaitForMenu(); - assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); + assertButtonHasFocus(BUTTON_ID_PLAY_PAUSE); } - private void assertButtonHasFocus(int expectedButtonIndex) { + private void assertButtonHasFocus(String buttonId) { UiObject2 menu = mDevice.findObject(MENU); UiObject2 focusedView = menu.findObject(FOCUSED_VIEW); assertNotNull("Play controls row doesn't have a focused child.", focusedView); UiObject2 focusedButtonGroup = focusedView.getParent(); assertNotNull("The focused item should have parent", focusedButtonGroup); - UiObject2 controlBar = focusedButtonGroup.getParent(); - assertNotNull("The focused item should have grandparent", controlBar); - assertTrue("The grandparent should have more than five children", - controlBar.getChildCount() >= 5); - assertEquals(controlBar.getChildren().get(expectedButtonIndex), focusedButtonGroup); + assertEquals(buttonId, focusedButtonGroup.getResourceName()); } } diff --git a/tests/input/res/values/strings.xml b/tests/input/res/values/strings.xml index 3f2ab3f7..4ef43955 100644 --- a/tests/input/res/values/strings.xml +++ b/tests/input/res/values/strings.xml @@ -15,7 +15,6 @@ --> <resources> <string name="app_name" translatable="false">Test TV Inputs</string> - <string name="about_app" translatable="false">About TV Test Inputs</string> <string name="version" translatable="false">Version: %1$s</string> <string name="sample_tv_input" translatable="false">Test TV Input</string> <string name="simple_input_label" translatable="false">Test Input</string> diff --git a/tests/jank/src/com/android/tv/tests/jank/ProgramGuideJankTest.java b/tests/jank/src/com/android/tv/tests/jank/ProgramGuideJankTest.java index 7d751c4c..03796cfa 100644 --- a/tests/jank/src/com/android/tv/tests/jank/ProgramGuideJankTest.java +++ b/tests/jank/src/com/android/tv/tests/jank/ProgramGuideJankTest.java @@ -30,7 +30,6 @@ import com.android.tv.testing.uihelper.ByResource; import com.android.tv.testing.uihelper.Constants; import com.android.tv.testing.uihelper.LiveChannelsUiDeviceHelper; import com.android.tv.testing.uihelper.MenuHelper; -import com.android.tv.testing.uihelper.UiDeviceUtils; /** * Jank tests for the program guide. @@ -83,7 +82,7 @@ public class ProgramGuideJankTest extends JankTestBase { } @JankTest(expectedFrames = EXPECTED_FRAMES, - beforeLoop = "showProgramGuide", + beforeLoop = "showAndFocusProgramGuide", afterLoop = "clearProgramGuide") @GfxMonitor(processName = Utils.LIVE_CHANNELS_PROCESS_NAME) public void testScrollDown() { @@ -95,7 +94,7 @@ public class ProgramGuideJankTest extends JankTestBase { } @JankTest(expectedFrames = EXPECTED_FRAMES, - beforeLoop = "showProgramGuide", + beforeLoop = "showAndFocusProgramGuide", afterLoop = "clearProgramGuide") @GfxMonitor(processName = Utils.LIVE_CHANNELS_PROCESS_NAME) public void testScrollRight() { @@ -128,11 +127,17 @@ public class ProgramGuideJankTest extends JankTestBase { assertWaitForCondition(mDevice, Until.gone(Constants.PROGRAM_GUIDE)); } - // It's public to be used with @JankTest annotation. public void showProgramGuide() { selectProgramGuideMenuItem(); mDevice.pressDPadCenter(); assertWaitForCondition(mDevice, Until.hasObject(Constants.PROGRAM_GUIDE)); + } + + // It's public to be used with @JankTest annotation. + public void showAndFocusProgramGuide() { + selectProgramGuideMenuItem(); + mDevice.pressDPadCenter(); + assertWaitForCondition(mDevice, Until.hasObject(Constants.PROGRAM_GUIDE)); // If the side panel grid is visible (and thus has focus), move right to clear it. if (mDevice.hasObject( ByResource.id(mTargetResources, R.id.program_guide_side_panel_grid_view))) { diff --git a/tests/unit/src/com/android/tv/MainActivityTest.java b/tests/unit/src/com/android/tv/MainActivityTest.java index b2fe6745..8425597f 100644 --- a/tests/unit/src/com/android/tv/MainActivityTest.java +++ b/tests/unit/src/com/android/tv/MainActivityTest.java @@ -39,7 +39,6 @@ public class MainActivityTest extends BaseMainActivityTestCase { waitUntilChannelLoadingFinish(); List<Channel> channelList = mActivity.getChannelDataManager().getChannelList(); assertTrue("Expected at least one channel", channelList.size() > 0); - assertFalse("PIP disabled", mActivity.isPipEnabled()); } public void testTuneToChannel() throws Throwable { diff --git a/tests/unit/src/com/android/tv/data/ChannelNumberTest.java b/tests/unit/src/com/android/tv/data/ChannelNumberTest.java index 4e6e9f3c..d074baae 100644 --- a/tests/unit/src/com/android/tv/data/ChannelNumberTest.java +++ b/tests/unit/src/com/android/tv/data/ChannelNumberTest.java @@ -42,14 +42,14 @@ public class ChannelNumberTest extends TestCase { */ public void testParseChannelNumber() { assertNull(parseChannelNumber("")); - assertNull(parseChannelNumber(" ")); + assertNull(parseChannelNumber("-")); assertNull(parseChannelNumber("abcd12")); assertNull(parseChannelNumber("12abcd")); assertNull(parseChannelNumber("-12")); assertChannelEquals(parseChannelNumber("1"), "1", false, ""); - assertChannelEquals(parseChannelNumber("1234 4321"), "1234", true, "4321"); + assertChannelEquals(parseChannelNumber("1234-4321"), "1234", true, "4321"); assertChannelEquals(parseChannelNumber("3-4"), "3", true, "4"); - assertChannelEquals(parseChannelNumber("5.6"), "5", true, "6"); + assertChannelEquals(parseChannelNumber("5-6"), "5", true, "6"); } /** @@ -59,13 +59,11 @@ public class ChannelNumberTest extends TestCase { new ComparableTester<ChannelNumber>() .addEquivalentGroup(parseChannelNumber("1"), parseChannelNumber("1")) .addEquivalentGroup(parseChannelNumber("2")) - .addEquivalentGroup(parseChannelNumber("2 1"), parseChannelNumber("2.1"), - parseChannelNumber("2-1")) + .addEquivalentGroup(parseChannelNumber("2-1")) .addEquivalentGroup(parseChannelNumber("2-2")) .addEquivalentGroup(parseChannelNumber("2-10")) .addEquivalentGroup(parseChannelNumber("3")) - .addEquivalentGroup(parseChannelNumber("4"), parseChannelNumber("4 0"), - parseChannelNumber("4.0"), parseChannelNumber("4-0")) + .addEquivalentGroup(parseChannelNumber("4"), parseChannelNumber("4-0")) .addEquivalentGroup(parseChannelNumber("10")) .addEquivalentGroup(parseChannelNumber("100")) .test(); diff --git a/tests/unit/src/com/android/tv/data/ChannelTest.java b/tests/unit/src/com/android/tv/data/ChannelTest.java index 95e3ee90..f3d80cbe 100644 --- a/tests/unit/src/com/android/tv/data/ChannelTest.java +++ b/tests/unit/src/com/android/tv/data/ChannelTest.java @@ -226,7 +226,6 @@ public class ChannelTest extends AndroidTestCase { * See <a href="http://b/23031603">b/23031603</a>. */ public void testComparatorLabel() { - TvInputManagerHelper manager = Mockito.mock(TvInputManagerHelper.class); Mockito.when(manager.isPartnerInput(Matchers.anyString())).thenAnswer( new Answer<Boolean>() { @@ -254,6 +253,29 @@ public class ChannelTest extends AndroidTestCase { comparatorTester.test(); } + public void testNormalizeChannelNumber() { + assertNormalizedDisplayNumber(null, null); + assertNormalizedDisplayNumber("", ""); + assertNormalizedDisplayNumber("1", "1"); + assertNormalizedDisplayNumber("abcde", "abcde"); + assertNormalizedDisplayNumber("1-1", "1-1"); + assertNormalizedDisplayNumber("1.1", "1-1"); + assertNormalizedDisplayNumber("1 1", "1-1"); + assertNormalizedDisplayNumber("1\u058a1", "1-1"); + assertNormalizedDisplayNumber("1\u05be1", "1-1"); + assertNormalizedDisplayNumber("1\u14001", "1-1"); + assertNormalizedDisplayNumber("1\u18061", "1-1"); + assertNormalizedDisplayNumber("1\u20101", "1-1"); + assertNormalizedDisplayNumber("1\u20111", "1-1"); + assertNormalizedDisplayNumber("1\u20121", "1-1"); + assertNormalizedDisplayNumber("1\u20131", "1-1"); + assertNormalizedDisplayNumber("1\u20141", "1-1"); + } + + private void assertNormalizedDisplayNumber(String displayNumber, String normalized) { + assertEquals(normalized, Channel.normalizeDisplayNumber(displayNumber)); + } + private class TestChannelComparator extends Channel.DefaultComparator { public TestChannelComparator(TvInputManagerHelper manager) { super(null, manager); diff --git a/tests/unit/src/com/android/tv/data/ProgramTest.java b/tests/unit/src/com/android/tv/data/ProgramTest.java index 7e474cd6..08dd17f3 100644 --- a/tests/unit/src/com/android/tv/data/ProgramTest.java +++ b/tests/unit/src/com/android/tv/data/ProgramTest.java @@ -19,13 +19,11 @@ import static android.media.tv.TvContract.Programs.Genres.COMEDY; import static android.media.tv.TvContract.Programs.Genres.FAMILY_KIDS; import com.android.tv.data.Program.CriticScore; -import com.android.tv.dvr.SeriesRecording; import android.media.tv.TvContentRating; import android.media.tv.TvContract.Programs.Genres; import android.os.Parcel; import android.support.test.filters.SmallTest; -import android.util.Log; import junit.framework.TestCase; diff --git a/tests/unit/src/com/android/tv/dvr/BaseDvrDataManagerTest.java b/tests/unit/src/com/android/tv/dvr/BaseDvrDataManagerTest.java index 1292759e..6c1b1976 100644 --- a/tests/unit/src/com/android/tv/dvr/BaseDvrDataManagerTest.java +++ b/tests/unit/src/com/android/tv/dvr/BaseDvrDataManagerTest.java @@ -21,6 +21,7 @@ import android.support.test.filters.SmallTest; import android.test.AndroidTestCase; import android.test.MoreAsserts; +import com.android.tv.dvr.data.ScheduledRecording; import com.android.tv.testing.FakeClock; import com.android.tv.testing.dvr.RecordingTestUtils; diff --git a/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java b/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java index b822f164..d142f432 100644 --- a/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java +++ b/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java @@ -18,6 +18,7 @@ package com.android.tv.dvr; import android.support.test.filters.SmallTest; +import com.android.tv.dvr.data.ScheduledRecording; import com.android.tv.testing.dvr.RecordingTestUtils; import junit.framework.TestCase; diff --git a/tests/unit/src/com/android/tv/dvr/DvrDataManagerInMemoryImpl.java b/tests/unit/src/com/android/tv/dvr/DvrDataManagerInMemoryImpl.java index 85e35c4d..b2164dec 100644 --- a/tests/unit/src/com/android/tv/dvr/DvrDataManagerInMemoryImpl.java +++ b/tests/unit/src/com/android/tv/dvr/DvrDataManagerInMemoryImpl.java @@ -24,7 +24,10 @@ import android.util.Log; import android.util.Range; import com.android.tv.common.SoftPreconditions; -import com.android.tv.dvr.ScheduledRecording.RecordingState; +import com.android.tv.dvr.data.RecordedProgram; +import com.android.tv.dvr.data.ScheduledRecording; +import com.android.tv.dvr.data.ScheduledRecording.RecordingState; +import com.android.tv.dvr.data.SeriesRecording; import com.android.tv.util.Clock; import java.util.ArrayList; @@ -37,7 +40,7 @@ import java.util.concurrent.atomic.AtomicLong; /** * A DVR Data manager that stores values in memory suitable for testing. */ -final class DvrDataManagerInMemoryImpl extends BaseDvrDataManager { +public final class DvrDataManagerInMemoryImpl extends BaseDvrDataManager { private final static String TAG = "DvrDataManagerInMemory"; private final AtomicLong mNextId = new AtomicLong(1); private final Map<Long, ScheduledRecording> mScheduledRecordings = new HashMap<>(); diff --git a/tests/unit/src/com/android/tv/dvr/DvrScheduleManagerTest.java b/tests/unit/src/com/android/tv/dvr/DvrScheduleManagerTest.java index 2850a5f7..cfb27211 100644 --- a/tests/unit/src/com/android/tv/dvr/DvrScheduleManagerTest.java +++ b/tests/unit/src/com/android/tv/dvr/DvrScheduleManagerTest.java @@ -20,6 +20,8 @@ import android.support.test.filters.SmallTest; import android.test.MoreAsserts; import android.util.Range; +import com.android.tv.dvr.DvrScheduleManager.ConflictInfo; +import com.android.tv.dvr.data.ScheduledRecording; import com.android.tv.testing.dvr.RecordingTestUtils; import junit.framework.TestCase; @@ -28,7 +30,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Map; /** * Tests for {@link DvrScheduleManager} @@ -586,49 +587,80 @@ public class DvrScheduleManagerTest extends TestCase { RecordingTestUtils.createTestRecordingWithPriorityAndPeriod(++channelId, --priority, 50L, 900L) )); - Map<ScheduledRecording, Boolean> conflictsInfo = DvrScheduleManager - .getConflictingSchedulesInfo(schedules, 1); - - assertNull(conflictsInfo.get(schedules.get(0))); - assertFalse(conflictsInfo.get(schedules.get(1))); - assertTrue(conflictsInfo.get(schedules.get(2))); - assertTrue(conflictsInfo.get(schedules.get(3))); - assertNull(conflictsInfo.get(schedules.get(4))); - assertTrue(conflictsInfo.get(schedules.get(5))); - assertNull(conflictsInfo.get(schedules.get(6))); - assertFalse(conflictsInfo.get(schedules.get(7))); - assertFalse(conflictsInfo.get(schedules.get(8))); - assertFalse(conflictsInfo.get(schedules.get(9))); - assertFalse(conflictsInfo.get(schedules.get(10))); - - conflictsInfo = DvrScheduleManager - .getConflictingSchedulesInfo(schedules, 2); - - assertNull(conflictsInfo.get(schedules.get(0))); - assertNull(conflictsInfo.get(schedules.get(1))); - assertNull(conflictsInfo.get(schedules.get(2))); - assertNull(conflictsInfo.get(schedules.get(3))); - assertNull(conflictsInfo.get(schedules.get(4))); - assertNull(conflictsInfo.get(schedules.get(5))); - assertNull(conflictsInfo.get(schedules.get(6))); - assertFalse(conflictsInfo.get(schedules.get(7))); - assertFalse(conflictsInfo.get(schedules.get(8))); - assertFalse(conflictsInfo.get(schedules.get(9))); - assertTrue(conflictsInfo.get(schedules.get(10))); - - conflictsInfo = DvrScheduleManager - .getConflictingSchedulesInfo(schedules, 3); - - assertNull(conflictsInfo.get(schedules.get(0))); - assertNull(conflictsInfo.get(schedules.get(1))); - assertNull(conflictsInfo.get(schedules.get(2))); - assertNull(conflictsInfo.get(schedules.get(3))); - assertNull(conflictsInfo.get(schedules.get(4))); - assertNull(conflictsInfo.get(schedules.get(5))); - assertNull(conflictsInfo.get(schedules.get(6))); - assertNull(conflictsInfo.get(schedules.get(7))); - assertTrue(conflictsInfo.get(schedules.get(8))); - assertNull(conflictsInfo.get(schedules.get(9))); - assertTrue(conflictsInfo.get(schedules.get(10))); + List<ConflictInfo> conflicts = DvrScheduleManager.getConflictingSchedulesInfo(schedules, 1); + + assertNotInList(schedules.get(0), conflicts); + assertFullConflict(schedules.get(1), conflicts); + assertPartialConflict(schedules.get(2), conflicts); + assertPartialConflict(schedules.get(3), conflicts); + assertNotInList(schedules.get(4), conflicts); + assertPartialConflict(schedules.get(5), conflicts); + assertNotInList(schedules.get(6), conflicts); + assertFullConflict(schedules.get(7), conflicts); + assertFullConflict(schedules.get(8), conflicts); + assertFullConflict(schedules.get(9), conflicts); + assertFullConflict(schedules.get(10), conflicts); + + conflicts = DvrScheduleManager.getConflictingSchedulesInfo(schedules, 2); + + assertNotInList(schedules.get(0), conflicts); + assertNotInList(schedules.get(1), conflicts); + assertNotInList(schedules.get(2), conflicts); + assertNotInList(schedules.get(3), conflicts); + assertNotInList(schedules.get(4), conflicts); + assertNotInList(schedules.get(5), conflicts); + assertNotInList(schedules.get(6), conflicts); + assertFullConflict(schedules.get(7), conflicts); + assertFullConflict(schedules.get(8), conflicts); + assertFullConflict(schedules.get(9), conflicts); + assertPartialConflict(schedules.get(10), conflicts); + + conflicts = DvrScheduleManager.getConflictingSchedulesInfo(schedules, 3); + + assertNotInList(schedules.get(0), conflicts); + assertNotInList(schedules.get(1), conflicts); + assertNotInList(schedules.get(2), conflicts); + assertNotInList(schedules.get(3), conflicts); + assertNotInList(schedules.get(4), conflicts); + assertNotInList(schedules.get(5), conflicts); + assertNotInList(schedules.get(6), conflicts); + assertNotInList(schedules.get(7), conflicts); + assertPartialConflict(schedules.get(8), conflicts); + assertNotInList(schedules.get(9), conflicts); + assertPartialConflict(schedules.get(10), conflicts); + } + + private void assertNotInList(ScheduledRecording schedule, List<ConflictInfo> conflicts) { + for (ConflictInfo conflictInfo : conflicts) { + if (conflictInfo.schedule.equals(schedule)) { + fail(schedule + " conflicts with others."); + } + } + } + + private void assertPartialConflict(ScheduledRecording schedule, List<ConflictInfo> conflicts) { + for (ConflictInfo conflictInfo : conflicts) { + if (conflictInfo.schedule.equals(schedule)) { + if (conflictInfo.partialConflict) { + return; + } else { + fail(schedule + " fully conflicts with others."); + } + } + } + fail(schedule + " doesn't conflict"); + } + + private void assertFullConflict(ScheduledRecording schedule, List<ConflictInfo> conflicts) { + for (ConflictInfo conflictInfo : conflicts) { + if (conflictInfo.schedule.equals(schedule)) { + if (!conflictInfo.partialConflict) { + return; + } else { + fail(schedule + " partially conflicts with others."); + } + } + } + fail(schedule + " doesn't conflict"); } }
\ No newline at end of file diff --git a/tests/unit/src/com/android/tv/dvr/EpisodicProgramLoadTaskTest.java b/tests/unit/src/com/android/tv/dvr/EpisodicProgramLoadTaskTest.java deleted file mode 100644 index 2172d488..00000000 --- a/tests/unit/src/com/android/tv/dvr/EpisodicProgramLoadTaskTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2016 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.os.Build; -import android.support.test.filters.SdkSuppress; -import android.support.test.filters.SmallTest; -import android.test.AndroidTestCase; - -import com.android.tv.dvr.EpisodicProgramLoadTask.ScheduledEpisode; - -import java.util.ArrayList; -import java.util.List; - -/** - * Tests for {@link EpisodicProgramLoadTask} - */ -@SmallTest -@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N) -public class EpisodicProgramLoadTaskTest extends AndroidTestCase { - private static final long SERIES_RECORDING_ID1 = 1; - private static final long SERIES_RECORDING_ID2 = 2; - private static final String SEASON_NUMBER1 = "SEASON NUMBER1"; - private static final String SEASON_NUMBER2 = "SEASON NUMBER2"; - private static final String EPISODE_NUMBER1 = "EPISODE NUMBER1"; - private static final String EPISODE_NUMBER2 = "EPISODE NUMBER2"; - - public void testEpisodeAlreadyScheduled_true() { - List<ScheduledEpisode> episodes = new ArrayList<>(); - ScheduledEpisode episode = new ScheduledEpisode(SERIES_RECORDING_ID1, SEASON_NUMBER1, - EPISODE_NUMBER1); - episodes.add(episode); - assertTrue(EpisodicProgramLoadTask.isEpisodeScheduled(episodes, - new ScheduledEpisode(SERIES_RECORDING_ID1, SEASON_NUMBER1, EPISODE_NUMBER1))); - } - - public void testEpisodeAlreadyScheduled_false() { - List<ScheduledEpisode> episodes = new ArrayList<>(); - ScheduledEpisode episode = new ScheduledEpisode(SERIES_RECORDING_ID1, SEASON_NUMBER1, - EPISODE_NUMBER1); - episodes.add(episode); - assertFalse(EpisodicProgramLoadTask.isEpisodeScheduled(episodes, - new ScheduledEpisode(SERIES_RECORDING_ID2, SEASON_NUMBER1, EPISODE_NUMBER1))); - assertFalse(EpisodicProgramLoadTask.isEpisodeScheduled(episodes, - new ScheduledEpisode(SERIES_RECORDING_ID1, SEASON_NUMBER2, EPISODE_NUMBER1))); - assertFalse(EpisodicProgramLoadTask.isEpisodeScheduled(episodes, - new ScheduledEpisode(SERIES_RECORDING_ID1, SEASON_NUMBER1, EPISODE_NUMBER2))); - } - - public void testEpisodeAlreadyScheduled_null() { - List<ScheduledEpisode> episodes = new ArrayList<>(); - ScheduledEpisode episode = new ScheduledEpisode(SERIES_RECORDING_ID1, SEASON_NUMBER1, - EPISODE_NUMBER1); - episodes.add(episode); - assertFalse(EpisodicProgramLoadTask.isEpisodeScheduled(episodes, - new ScheduledEpisode(SERIES_RECORDING_ID1, null, EPISODE_NUMBER1))); - assertFalse(EpisodicProgramLoadTask.isEpisodeScheduled(episodes, - new ScheduledEpisode(SERIES_RECORDING_ID1, SEASON_NUMBER1, null))); - assertFalse(EpisodicProgramLoadTask.isEpisodeScheduled(episodes, - new ScheduledEpisode(SERIES_RECORDING_ID1, null, null))); - } -} diff --git a/tests/unit/src/com/android/tv/dvr/ScheduledRecordingTest.java b/tests/unit/src/com/android/tv/dvr/ScheduledRecordingTest.java index 96036418..426e60ba 100644 --- a/tests/unit/src/com/android/tv/dvr/ScheduledRecordingTest.java +++ b/tests/unit/src/com/android/tv/dvr/ScheduledRecordingTest.java @@ -26,6 +26,7 @@ import android.util.Range; import com.android.tv.data.Channel; import com.android.tv.data.Program; +import com.android.tv.dvr.data.ScheduledRecording; import com.android.tv.testing.dvr.RecordingTestUtils; import junit.framework.TestCase; diff --git a/tests/unit/src/com/android/tv/dvr/SeriesRecordingTest.java b/tests/unit/src/com/android/tv/dvr/data/SeriesRecordingTest.java index c48fec02..7512ed0e 100644 --- a/tests/unit/src/com/android/tv/dvr/SeriesRecordingTest.java +++ b/tests/unit/src/com/android/tv/dvr/data/SeriesRecordingTest.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.tv.dvr; +package com.android.tv.dvr.data; import android.os.Build; import android.os.Parcel; diff --git a/tests/unit/src/com/android/tv/dvr/DvrDbSyncTest.java b/tests/unit/src/com/android/tv/dvr/provider/DvrDbSyncTest.java index 7cb3721c..9e96a7b8 100644 --- a/tests/unit/src/com/android/tv/dvr/DvrDbSyncTest.java +++ b/tests/unit/src/com/android/tv/dvr/provider/DvrDbSyncTest.java @@ -14,8 +14,9 @@ * limitations under the License */ -package com.android.tv.dvr; +package com.android.tv.dvr.provider; +import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.never; @@ -29,6 +30,11 @@ import android.test.AndroidTestCase; import com.android.tv.data.ChannelDataManager; import com.android.tv.data.Program; +import com.android.tv.dvr.DvrDataManagerImpl; +import com.android.tv.dvr.DvrManager; +import com.android.tv.dvr.data.ScheduledRecording; +import com.android.tv.dvr.data.SeriesRecording; +import com.android.tv.dvr.recorder.SeriesRecordingScheduler; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -47,20 +53,30 @@ public class DvrDbSyncTest extends AndroidTestCase { private static final String BASE_EPISODE_NUMBER = "3"; private static final Program BASE_PROGRAM = new Program.Builder().setId(BASE_PROGRAM_ID) .setStartTimeUtcMillis(BASE_START_TIME_MS).setEndTimeUtcMillis(BASE_END_TIME_MS) + .build(); + private static final Program BASE_SERIES_PROGRAM = new Program.Builder().setId(BASE_PROGRAM_ID) + .setStartTimeUtcMillis(BASE_START_TIME_MS).setEndTimeUtcMillis(BASE_END_TIME_MS) .setSeasonNumber(BASE_SEASON_NUMBER).setEpisodeNumber(BASE_EPISODE_NUMBER).build(); private static final ScheduledRecording BASE_SCHEDULE = ScheduledRecording.builder(INPUT_ID, BASE_PROGRAM).build(); + private static final ScheduledRecording BASE_SERIES_SCHEDULE = + ScheduledRecording.builder(INPUT_ID, BASE_SERIES_PROGRAM).build(); private DvrDbSync mDbSync; + @Mock private DvrManager mDvrManager; @Mock private DvrDataManagerImpl mDataManager; @Mock private ChannelDataManager mChannelDataManager; + @Mock private SeriesRecordingScheduler mSeriesRecordingScheduler; @Override protected void setUp() throws Exception { super.setUp(); MockitoAnnotations.initMocks(this); when(mChannelDataManager.isDbLoadFinished()).thenReturn(true); - mDbSync = new DvrDbSync(getContext(), mDataManager, mChannelDataManager); + when(mDvrManager.addSeriesRecording(anyObject(), anyObject(), anyInt())) + .thenReturn(SeriesRecording.builder(INPUT_ID, BASE_PROGRAM).build()); + mDbSync = new DvrDbSync(getContext(), mDataManager, mChannelDataManager, + mDvrManager, mSeriesRecordingScheduler); } public void testHandleUpdateProgram_null() { @@ -90,21 +106,21 @@ public class DvrDbSyncTest extends AndroidTestCase { } public void testHandleUpdateProgram_changeSeason() { - addSchedule(BASE_PROGRAM_ID, BASE_SCHEDULE); + addSchedule(BASE_PROGRAM_ID, BASE_SERIES_SCHEDULE); String seasonNumber = BASE_SEASON_NUMBER + "1"; String episodeNumber = BASE_EPISODE_NUMBER + "1"; - Program program = new Program.Builder(BASE_PROGRAM).setSeasonNumber(seasonNumber) + Program program = new Program.Builder(BASE_SERIES_PROGRAM).setSeasonNumber(seasonNumber) .setEpisodeNumber(episodeNumber).build(); mDbSync.handleUpdateProgram(program, BASE_PROGRAM_ID); assertUpdateScheduleCalled(program); } public void testHandleUpdateProgram_finished() { - addSchedule(BASE_PROGRAM_ID, ScheduledRecording.buildFrom(BASE_SCHEDULE) + addSchedule(BASE_PROGRAM_ID, ScheduledRecording.buildFrom(BASE_SERIES_SCHEDULE) .setState(ScheduledRecording.STATE_RECORDING_FINISHED).build()); String seasonNumber = BASE_SEASON_NUMBER + "1"; String episodeNumber = BASE_EPISODE_NUMBER + "1"; - Program program = new Program.Builder(BASE_PROGRAM).setSeasonNumber(seasonNumber) + Program program = new Program.Builder(BASE_SERIES_PROGRAM).setSeasonNumber(seasonNumber) .setEpisodeNumber(episodeNumber).build(); mDbSync.handleUpdateProgram(program, BASE_PROGRAM_ID); verify(mDataManager, never()).updateScheduledRecording(anyObject()); diff --git a/tests/unit/src/com/android/tv/dvr/provider/EpisodicProgramLoadTaskTest.java b/tests/unit/src/com/android/tv/dvr/provider/EpisodicProgramLoadTaskTest.java new file mode 100644 index 00000000..301c453d --- /dev/null +++ b/tests/unit/src/com/android/tv/dvr/provider/EpisodicProgramLoadTaskTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2016 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.provider; + +import android.os.Build; +import android.support.test.filters.SdkSuppress; +import android.support.test.filters.SmallTest; +import android.test.AndroidTestCase; + +import com.android.tv.dvr.data.SeasonEpisodeNumber; + +import java.util.ArrayList; +import java.util.List; + +/** + * Tests for {@link EpisodicProgramLoadTask} + */ +@SmallTest +@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N) +public class EpisodicProgramLoadTaskTest extends AndroidTestCase { + private static final long SERIES_RECORDING_ID1 = 1; + private static final long SERIES_RECORDING_ID2 = 2; + private static final String SEASON_NUMBER1 = "SEASON NUMBER1"; + private static final String SEASON_NUMBER2 = "SEASON NUMBER2"; + private static final String EPISODE_NUMBER1 = "EPISODE NUMBER1"; + private static final String EPISODE_NUMBER2 = "EPISODE NUMBER2"; + + public void testEpisodeAlreadyScheduled_true() { + List<SeasonEpisodeNumber> seasonEpisodeNumbers = new ArrayList<>(); + SeasonEpisodeNumber seasonEpisodeNumber = new SeasonEpisodeNumber( + SERIES_RECORDING_ID1, SEASON_NUMBER1, EPISODE_NUMBER1); + seasonEpisodeNumbers.add(seasonEpisodeNumber); + assertTrue(seasonEpisodeNumbers.contains( + new SeasonEpisodeNumber(SERIES_RECORDING_ID1, SEASON_NUMBER1, EPISODE_NUMBER1))); + } + + public void testEpisodeAlreadyScheduled_false() { + List<SeasonEpisodeNumber> seasonEpisodeNumbers = new ArrayList<>(); + SeasonEpisodeNumber seasonEpisodeNumber = new SeasonEpisodeNumber( + SERIES_RECORDING_ID1, SEASON_NUMBER1, EPISODE_NUMBER1); + seasonEpisodeNumbers.add(seasonEpisodeNumber); + assertFalse(seasonEpisodeNumbers.contains( + new SeasonEpisodeNumber(SERIES_RECORDING_ID2, SEASON_NUMBER1, EPISODE_NUMBER1))); + assertFalse(seasonEpisodeNumbers.contains( + new SeasonEpisodeNumber(SERIES_RECORDING_ID1, SEASON_NUMBER2, EPISODE_NUMBER1))); + assertFalse(seasonEpisodeNumbers.contains( + new SeasonEpisodeNumber(SERIES_RECORDING_ID1, SEASON_NUMBER1, EPISODE_NUMBER2))); + } + + public void testEpisodeAlreadyScheduled_null() { + List<SeasonEpisodeNumber> seasonEpisodeNumbers = new ArrayList<>(); + SeasonEpisodeNumber seasonEpisodeNumber = new SeasonEpisodeNumber( + SERIES_RECORDING_ID1, SEASON_NUMBER1, EPISODE_NUMBER1); + seasonEpisodeNumbers.add(seasonEpisodeNumber); + assertFalse(seasonEpisodeNumbers.contains( + new SeasonEpisodeNumber(SERIES_RECORDING_ID1, null, EPISODE_NUMBER1))); + assertFalse(seasonEpisodeNumbers.contains( + new SeasonEpisodeNumber(SERIES_RECORDING_ID1, SEASON_NUMBER1, null))); + assertFalse(seasonEpisodeNumbers.contains( + new SeasonEpisodeNumber(SERIES_RECORDING_ID1, null, null))); + } +}
\ 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/recorder/DvrRecordingServiceTest.java index 0a203ede..7ad8d55d 100644 --- a/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java +++ b/tests/unit/src/com/android/tv/dvr/recorder/DvrRecordingServiceTest.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.tv.dvr; +package com.android.tv.dvr.recorder; import static org.mockito.Mockito.verify; diff --git a/tests/unit/src/com/android/tv/dvr/InputTaskSchedulerTest.java b/tests/unit/src/com/android/tv/dvr/recorder/InputTaskSchedulerTest.java index 85c78ce2..ef0d5fab 100644 --- a/tests/unit/src/com/android/tv/dvr/InputTaskSchedulerTest.java +++ b/tests/unit/src/com/android/tv/dvr/recorder/InputTaskSchedulerTest.java @@ -14,12 +14,11 @@ * limitations under the License */ -package com.android.tv.dvr; +package com.android.tv.dvr.recorder; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.after; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; @@ -37,7 +36,10 @@ import android.test.AndroidTestCase; import com.android.tv.InputSessionManager; import com.android.tv.data.Channel; import com.android.tv.data.ChannelDataManager; -import com.android.tv.dvr.InputTaskScheduler.RecordingTaskFactory; +import com.android.tv.dvr.DvrManager; +import com.android.tv.dvr.WritableDvrDataManager; +import com.android.tv.dvr.data.ScheduledRecording; +import com.android.tv.dvr.recorder.InputTaskScheduler.RecordingTaskFactory; import com.android.tv.testing.FakeClock; import com.android.tv.testing.dvr.RecordingTestUtils; import com.android.tv.util.Clock; @@ -143,7 +145,7 @@ public class InputTaskSchedulerTest extends AndroidTestCase { verify(mRecordingTasks.get(0), timeout((int) LISTENER_TIMEOUT_MS).times(1)).start(); // The first schedule should not be stopped because the second one should wait for the end // of the first schedule. - verify(mRecordingTasks.get(0), after((int) LISTENER_TIMEOUT_MS).never()).stop(); + verify(mRecordingTasks.get(0), timeout((int) LISTENER_TIMEOUT_MS).never()).stop(); } public void testAddSchedule_consecutiveNoFail() throws Exception { @@ -163,9 +165,9 @@ public class InputTaskSchedulerTest extends AndroidTestCase { LOW_PRIORITY, startTimeMs, endTimeMs)); mScheduler.handleBuildSchedule(); verify(mRecordingTasks.get(0), timeout((int) LISTENER_TIMEOUT_MS).times(1)).start(); - verify(mRecordingTasks.get(0), after((int) LISTENER_TIMEOUT_MS).never()).stop(); + verify(mRecordingTasks.get(0), timeout((int) LISTENER_TIMEOUT_MS).never()).stop(); // The second schedule should not fail because it can starts after the first one finishes. - verify(mDataManager, after((int) LISTENER_TIMEOUT_MS).never()) + verify(mDataManager, timeout((int) LISTENER_TIMEOUT_MS).never()) .changeState(any(ScheduledRecording.class), eq(ScheduledRecording.STATE_RECORDING_FAILED)); } @@ -187,7 +189,7 @@ public class InputTaskSchedulerTest extends AndroidTestCase { HIGH_PRIORITY, startTimeMs, endTimeMs)); mScheduler.handleBuildSchedule(); verify(mRecordingTasks.get(0), timeout((int) LISTENER_TIMEOUT_MS).times(1)).start(); - verify(mRecordingTasks.get(0), after((int) LISTENER_TIMEOUT_MS).never()).stop(); + verify(mRecordingTasks.get(0), timeout((int) LISTENER_TIMEOUT_MS).never()).stop(); // The second schedule should wait until the first one finishes rather than creating a new // session even though there are available tuners. assertTrue(mRecordingTasks.size() == 1); @@ -200,7 +202,7 @@ public class InputTaskSchedulerTest extends AndroidTestCase { mScheduler.handleAddSchedule(r); mScheduler.handleBuildSchedule(); mScheduler.handleUpdateSchedule(r); - verify(mRecordingTasks.get(0), after((int) LISTENER_TIMEOUT_MS).never()).cancel(); + verify(mRecordingTasks.get(0), timeout((int) LISTENER_TIMEOUT_MS).never()).cancel(); } public void testUpdateSchedule_cancel() throws Exception { diff --git a/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java b/tests/unit/src/com/android/tv/dvr/recorder/RecordingTaskTest.java index 7404a554..076773e7 100644 --- a/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java +++ b/tests/unit/src/com/android/tv/dvr/recorder/RecordingTaskTest.java @@ -14,17 +14,17 @@ * limitations under the License */ -package com.android.tv.dvr; +package com.android.tv.dvr.recorder; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.longThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -import static org.mockito.hamcrest.MockitoHamcrest.longThat; import android.os.Build; import android.os.Handler; @@ -37,15 +37,18 @@ import android.test.AndroidTestCase; import com.android.tv.InputSessionManager; import com.android.tv.InputSessionManager.RecordingSession; import com.android.tv.data.Channel; -import com.android.tv.dvr.RecordingTask.State; +import com.android.tv.dvr.DvrDataManagerInMemoryImpl; +import com.android.tv.dvr.DvrManager; +import com.android.tv.dvr.data.ScheduledRecording; +import com.android.tv.dvr.recorder.RecordingTask.State; import com.android.tv.testing.FakeClock; import com.android.tv.testing.dvr.RecordingTestUtils; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; +import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.compat.ArgumentMatcher; import java.util.concurrent.TimeUnit; @@ -157,10 +160,10 @@ public class RecordingTaskTest extends AndroidTestCase { private static ArgumentMatcher<Message> messageMatchesWhat(final int what) { return new ArgumentMatcher<Message>() { @Override - public boolean matchesObject(Object argument) { + public boolean matches(Object argument) { Message message = (Message) argument; return message.what == what; } }; } -} +}
\ No newline at end of file diff --git a/tests/unit/src/com/android/tv/dvr/ScheduledProgramReaperTest.java b/tests/unit/src/com/android/tv/dvr/recorder/ScheduledProgramReaperTest.java index 847540c2..d434a34e 100644 --- a/tests/unit/src/com/android/tv/dvr/ScheduledProgramReaperTest.java +++ b/tests/unit/src/com/android/tv/dvr/recorder/ScheduledProgramReaperTest.java @@ -14,15 +14,20 @@ * limitations under the License. */ -package com.android.tv.dvr; +package com.android.tv.dvr.recorder; +import android.os.Build; +import android.support.test.filters.SdkSuppress; +import android.support.test.filters.SmallTest; +import android.test.AndroidTestCase; import android.test.MoreAsserts; +import com.android.tv.dvr.DvrDataManagerInMemoryImpl; +import com.android.tv.dvr.DvrManager; +import com.android.tv.dvr.data.ScheduledRecording; import com.android.tv.testing.FakeClock; import com.android.tv.testing.dvr.RecordingTestUtils; -import junit.framework.TestCase; - import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -31,7 +36,9 @@ import java.util.concurrent.TimeUnit; /** * Tests for {@link ScheduledProgramReaper}. */ -public class ScheduledProgramReaperTest extends TestCase { +@SmallTest +@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N) +public class ScheduledProgramReaperTest extends AndroidTestCase { private static final String INPUT_ID = "input_id"; private static final int CHANNEL_ID = 273; private static final long DURATION = TimeUnit.HOURS.toMillis(1); @@ -41,13 +48,12 @@ public class ScheduledProgramReaperTest extends TestCase { private DvrDataManagerInMemoryImpl mDvrDataManager; @Mock private DvrManager mDvrManager; - @Override protected void setUp() throws Exception { super.setUp(); MockitoAnnotations.initMocks(this); mFakeClock = FakeClock.createWithTimeOne(); - mDvrDataManager = new DvrDataManagerInMemoryImpl(null, mFakeClock); + mDvrDataManager = new DvrDataManagerInMemoryImpl(getContext(), mFakeClock); mReaper = new ScheduledProgramReaper(mDvrDataManager, mFakeClock); } diff --git a/tests/unit/src/com/android/tv/dvr/SchedulerTest.java b/tests/unit/src/com/android/tv/dvr/recorder/SchedulerTest.java index 30ac1ff1..94cfaac1 100644 --- a/tests/unit/src/com/android/tv/dvr/SchedulerTest.java +++ b/tests/unit/src/com/android/tv/dvr/recorder/SchedulerTest.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.tv.dvr; +package com.android.tv.dvr.recorder; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; @@ -31,6 +31,9 @@ import android.test.AndroidTestCase; import com.android.tv.InputSessionManager; import com.android.tv.data.ChannelDataManager; +import com.android.tv.dvr.DvrDataManagerInMemoryImpl; +import com.android.tv.dvr.DvrManager; +import com.android.tv.dvr.data.ScheduledRecording; import com.android.tv.testing.FakeClock; import com.android.tv.testing.dvr.RecordingTestUtils; import com.android.tv.util.TvInputManagerHelper; @@ -84,13 +87,13 @@ public class SchedulerTest extends AndroidTestCase { startTime + TimeUnit.HOURS.toMillis(1)); mDataManager.addScheduledRecording(r); mScheduler.start(); - verify(mMockAlarmManager).set( + verify(mMockAlarmManager).setExactAndAllowWhileIdle( eq(AlarmManager.RTC_WAKEUP), eq(startTime - Scheduler.MS_TO_WAKE_BEFORE_START), any(PendingIntent.class)); Mockito.reset(mMockAlarmManager); mScheduler.update(); - verify(mMockAlarmManager).set( + verify(mMockAlarmManager).setExactAndAllowWhileIdle( eq(AlarmManager.RTC_WAKEUP), eq(startTime - Scheduler.MS_TO_WAKE_BEFORE_START), any(PendingIntent.class)); diff --git a/tests/unit/src/com/android/tv/dvr/SeriesRecordingSchedulerTest.java b/tests/unit/src/com/android/tv/dvr/recorder/SeriesRecordingSchedulerTest.java index efefb93c..afb9c042 100644 --- a/tests/unit/src/com/android/tv/dvr/SeriesRecordingSchedulerTest.java +++ b/tests/unit/src/com/android/tv/dvr/recorder/SeriesRecordingSchedulerTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.tv.dvr; +package com.android.tv.dvr.recorder; import android.os.Build; import android.support.test.filters.SdkSuppress; @@ -24,6 +24,8 @@ import android.test.MoreAsserts; import android.util.LongSparseArray; import com.android.tv.data.Program; +import com.android.tv.dvr.DvrDataManagerInMemoryImpl; +import com.android.tv.dvr.data.SeriesRecording; import com.android.tv.testing.FakeClock; import java.util.ArrayList; diff --git a/tests/unit/src/com/android/tv/dvr/ui/SortedArrayAdapterTest.java b/tests/unit/src/com/android/tv/dvr/ui/SortedArrayAdapterTest.java index a571e626..8fc8270f 100644 --- a/tests/unit/src/com/android/tv/dvr/ui/SortedArrayAdapterTest.java +++ b/tests/unit/src/com/android/tv/dvr/ui/SortedArrayAdapterTest.java @@ -32,10 +32,10 @@ import java.util.Objects; @SmallTest public class SortedArrayAdapterTest extends TestCase { - public static final TestData P1 = TestData.create(1, "one"); - public static final TestData P2 = TestData.create(2, "before"); - public static final TestData P3 = TestData.create(3, "other"); - public static final TestData EXTRA = TestData.create(4, "extra"); + public static final TestData P1 = TestData.create(1, "c"); + public static final TestData P2 = TestData.create(2, "b"); + public static final TestData P3 = TestData.create(3, "a"); + public static final TestData EXTRA = TestData.create(4, "k"); private TestSortedArrayAdapter mAdapter; @Override @@ -111,6 +111,43 @@ public class SortedArrayAdapterTest extends TestCase { assertContentsInOrder(mAdapter, P1); mAdapter.remove(P1); assertEmpty(); + mAdapter.add(P1); + mAdapter.add(P2); + mAdapter.add(P3); + assertContentsInOrder(mAdapter, P3, P2, P1); + mAdapter.removeItems(0, 2); + assertContentsInOrder(mAdapter, P1); + mAdapter.add(P2); + mAdapter.add(P3); + mAdapter.addExtraItem(EXTRA); + assertContentsInOrder(mAdapter, P3, P2, P1, EXTRA); + mAdapter.removeItems(1, 1); + assertContentsInOrder(mAdapter, P3, P1, EXTRA); + mAdapter.removeItems(1, 2); + assertContentsInOrder(mAdapter, P3); + mAdapter.addExtraItem(EXTRA); + mAdapter.addExtraItem(P2); + mAdapter.add(P1); + assertContentsInOrder(mAdapter, P3, P1, EXTRA, P2); + mAdapter.removeItems(1, 2); + assertContentsInOrder(mAdapter, P3, P2); + mAdapter.add(P1); + assertContentsInOrder(mAdapter, P3, P1, P2); + } + + public void testReplace() { + mAdapter.add(P1); + mAdapter.add(P2); + assertNotEmpty(); + assertContentsInOrder(mAdapter, P2, P1); + mAdapter.replace(1, P3); + assertContentsInOrder(mAdapter, P3, P2); + mAdapter.replace(0, P1); + assertContentsInOrder(mAdapter, P2, P1); + mAdapter.addExtraItem(EXTRA); + assertContentsInOrder(mAdapter, P2, P1, EXTRA); + mAdapter.replace(2, P3); + assertContentsInOrder(mAdapter, P2, P1, P3); } public void testChange_sorting() { @@ -194,7 +231,7 @@ public class SortedArrayAdapterTest extends TestCase { } @Override - long getId(TestData item) { + protected long getId(TestData item) { return item.mId; } } diff --git a/tests/unit/src/com/android/tv/experiments/ExperimentsTest.java b/tests/unit/src/com/android/tv/experiments/ExperimentsTest.java new file mode 100644 index 00000000..ab709e39 --- /dev/null +++ b/tests/unit/src/com/android/tv/experiments/ExperimentsTest.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016 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.experiments; + +import android.support.test.filters.SmallTest; + +import com.android.tv.common.BuildConfig; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +/** + * Tests for {@link Experiments}. + */ +@SmallTest +public class ExperimentsTest extends TestCase { + + @Override + protected void setUp() throws Exception { + super.setUp(); + ExperimentFlag.initForTest(); + } + + + public void testEngOnlyDefault() { + assertEquals("ENABLE_DEVELOPER_FEATURES", Boolean.valueOf(BuildConfig.ENG), + Experiments.ENABLE_DEVELOPER_FEATURES.get()); + } + + +} |