diff options
author | Nick Chalko <nchalko@google.com> | 2016-02-26 13:38:57 -0800 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2016-02-26 13:39:22 -0800 |
commit | ba5845f23b8fbc985890f892961abc8b39886611 (patch) | |
tree | da373b9fe1955a2c7008c2e65df5ec3f5b087454 /tests | |
parent | 1abddd9f6225298066094e20a6c29061b6af4590 (diff) | |
download | TV-ba5845f23b8fbc985890f892961abc8b39886611.tar.gz |
Sync to ub-tv-interns at cc7c29d2a24a1343498f6d95ca5a79e003e6aefe
Change-Id: I580da190231e47c65b69f425b30ec4685eb50ce4
Diffstat (limited to 'tests')
26 files changed, 703 insertions, 355 deletions
diff --git a/tests/common/src/com/android/tv/MockTvApplication.java b/tests/common/src/com/android/tv/MockTvApplication.java index 7060e6b0..24c47a6a 100644 --- a/tests/common/src/com/android/tv/MockTvApplication.java +++ b/tests/common/src/com/android/tv/MockTvApplication.java @@ -16,11 +16,9 @@ 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; @@ -60,11 +58,6 @@ public class MockTvApplication extends MockApplication implements ApplicationSin } @Override - public OptOutPreferenceHelper getOptPreferenceHelper() { - return mDelegate.getOptPreferenceHelper(); - } - - @Override public ChannelDataManager getChannelDataManager() { return mDelegate.getChannelDataManager(); } @@ -83,4 +76,9 @@ public class MockTvApplication extends MockApplication implements ApplicationSin public TvInputManagerHelper getTvInputManagerHelper() { return mDelegate.getTvInputManagerHelper(); } + + @Override + public MainActivityWrapper getMainActivityWrapper() { + return mDelegate.getMainActivityWrapper(); + } } diff --git a/tests/common/src/com/android/tv/testing/ChannelUtils.java b/tests/common/src/com/android/tv/testing/ChannelUtils.java index 00881c86..e09843a6 100644 --- a/tests/common/src/com/android/tv/testing/ChannelUtils.java +++ b/tests/common/src/com/android/tv/testing/ChannelUtils.java @@ -96,7 +96,7 @@ public class ChannelUtils { } else { values.putNull(Channels.COLUMN_VIDEO_FORMAT); } - if (Build.VERSION.SDK_INT >= 23) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!TextUtils.isEmpty(channel.appLinkText)) { values.put(Channels.COLUMN_APP_LINK_TEXT, channel.appLinkText); } diff --git a/tests/common/src/com/android/tv/testing/ProgramUtils.java b/tests/common/src/com/android/tv/testing/ProgramUtils.java index 493891b6..227eb84a 100644 --- a/tests/common/src/com/android/tv/testing/ProgramUtils.java +++ b/tests/common/src/com/android/tv/testing/ProgramUtils.java @@ -25,6 +25,8 @@ import android.media.tv.TvContract.Programs; import android.net.Uri; import android.util.Log; +import com.android.tv.common.TvContentRatingCache; + import java.util.ArrayList; import java.util.concurrent.TimeUnit; @@ -48,7 +50,7 @@ public class ProgramUtils { values.put(Programs.COLUMN_CHANNEL_ID, channelId); values.put(Programs.COLUMN_SHORT_DESCRIPTION, program.description); values.put(Programs.COLUMN_CONTENT_RATING, - Utils.contentRatingsToString(program.contentRatings)); + TvContentRatingCache.contentRatingsToString(program.contentRatings)); long currentTimeMs = System.currentTimeMillis(); long targetEndTimeMs = currentTimeMs + PROGRAM_INSERT_DURATION_MS; diff --git a/tests/common/src/com/android/tv/testing/TvContentRatingConstants.java b/tests/common/src/com/android/tv/testing/TvContentRatingConstants.java index 0795a89c..71af8297 100644 --- a/tests/common/src/com/android/tv/testing/TvContentRatingConstants.java +++ b/tests/common/src/com/android/tv/testing/TvContentRatingConstants.java @@ -33,6 +33,8 @@ public final class TvContentRatingConstants { public static final TvContentRating CONTENT_RATING_US_TV_Y7_US_TV_FV = TvContentRating.createRating("com.android.tv", "US_TV", "US_TV_Y7", "US_TV_FV"); + public static String STRING_US_TV_Y7_US_TV_FV = "com.android.tv/US_TV/US_TV_Y7/US_TV_FV"; + /** * A content rating object. * @@ -43,6 +45,8 @@ public final class TvContentRatingConstants { public static final TvContentRating CONTENT_RATING_US_TV_MA = TvContentRating.createRating("com.android.tv", "US_TV", "US_TV_MA"); + public static String STRING_US_TV_MA = "com.android.tv/US_TV/US_TV_MA"; + /** * A content rating object. * @@ -54,4 +58,7 @@ public final class TvContentRatingConstants { public static final TvContentRating CONTENT_RATING_US_TV_PG_US_TV_L_US_TV_S = TvContentRating.createRating("com.android.tv", "US_TV", "US_TV_PG", "US_TV_L", "US_TV_S"); + + public static String STRING_US_TV_PG_US_TV_L_US_TV_S + = "com.android.tv/US_TV/US_TV_Y7/US_TV_L/US_TV_S"; } diff --git a/tests/common/src/com/android/tv/testing/Utils.java b/tests/common/src/com/android/tv/testing/Utils.java index 9e1bd3e9..6bc4e24e 100644 --- a/tests/common/src/com/android/tv/testing/Utils.java +++ b/tests/common/src/com/android/tv/testing/Utils.java @@ -95,31 +95,6 @@ public final class Utils { return null; } - public static TvContentRating[] stringToContentRatings(String commaSeparatedRatings) { - if (TextUtils.isEmpty(commaSeparatedRatings)) { - return null; - } - String[] ratings = commaSeparatedRatings.split("\\s*,\\s*"); - TvContentRating[] contentRatings = new TvContentRating[ratings.length]; - for (int i = 0; i < contentRatings.length; ++i) { - contentRatings[i] = TvContentRating.unflattenFromString(ratings[i]); - } - return contentRatings; - } - - public static String contentRatingsToString(TvContentRating[] contentRatings) { - if (contentRatings == null || contentRatings.length == 0) { - return null; - } - final String DELIMITER = ","; - StringBuilder ratings = new StringBuilder(contentRatings[0].flattenToString()); - for (int i = 1; i < contentRatings.length; ++i) { - ratings.append(DELIMITER); - ratings.append(contentRatings[i].flattenToString()); - } - return ratings.toString(); - } - /** * Return the Random class which is needed to make random data for testing. * Default seed of the random is today's date. 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 30e21e2e..458c9f2c 100644 --- a/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java +++ b/tests/common/src/com/android/tv/testing/dvr/RecordingTestUtils.java @@ -16,19 +16,47 @@ package com.android.tv.testing.dvr; +import android.support.annotation.RequiresPermission; + import com.android.tv.data.Channel; import com.android.tv.dvr.Recording; +import junit.framework.Assert; + import java.util.Collections; /** * Static utils for using {@link Recording} in tests. */ -public class RecordingTestUtils { - public static Recording createTestRecordingWithPeriod(long id, long startTime, long endTime) { +public final class RecordingTestUtils { + public static Recording createTestRecordingWithIdAndPeriod(long id, long startTime, + long endTime) { return Recording.builder(new Channel.Builder().build(), startTime, endTime) .setId(id) .setPrograms(Collections.EMPTY_LIST) .build(); } + + public static Recording createTestRecordingWithPeriod(long startTime, long endTime) { + return createTestRecordingWithIdAndPeriod(Recording.ID_NOT_SET, startTime, endTime); + } + + public static Recording normalizePriority(Recording orig){ + return Recording.buildFrom(orig).setPriority(orig.getId()).build(); + } + + public static void assertRecordingEquals(Recording expected, Recording actual) { + Assert.assertEquals("id", expected.getId(), actual.getId()); + Assert.assertEquals("uri", expected.getUri(), actual.getUri()); + Assert.assertEquals("channel", expected.getChannel(), actual.getChannel()); + Assert.assertEquals("programs", expected.getPrograms(), actual.getPrograms()); + Assert.assertEquals("start time", expected.getStartTimeMs(), actual.getStartTimeMs()); + Assert.assertEquals("end time", expected.getEndTimeMs(), actual.getEndTimeMs()); + Assert.assertEquals("media size", expected.getSize(), actual.getSize()); + Assert.assertEquals("state", expected.getState(), actual.getState()); + Assert.assertEquals("parent season recording", expected.getParentSeasonRecording(), + actual.getParentSeasonRecording()); + } + + private RecordingTestUtils() { } } diff --git a/tests/common/src/com/android/tv/testing/uihelper/MenuHelper.java b/tests/common/src/com/android/tv/testing/uihelper/MenuHelper.java index 3d992618..ea5360a3 100644 --- a/tests/common/src/com/android/tv/testing/uihelper/MenuHelper.java +++ b/tests/common/src/com/android/tv/testing/uihelper/MenuHelper.java @@ -116,14 +116,9 @@ public class MenuHelper extends BaseUiDeviceHelper { Direction.RIGHT); } - public UiObject2 assertPressOptionsChannelSources() { + public UiObject2 assertPressOptionsSettings() { return assertPressMenuItem(R.string.menu_title_options, - R.string.options_item_channel_sources); - } - - public UiObject2 assertPressOptionsAbout() { - return assertPressMenuItem(R.string.menu_title_options, - R.string.options_item_about); + R.string.options_item_settings); } public UiObject2 assertPressOptionsClosedCaptions() { @@ -139,11 +134,6 @@ public class MenuHelper extends BaseUiDeviceHelper { return assertPressMenuItem(R.string.menu_title_options, R.string.options_item_multi_audio); } - public UiObject2 assertPressOptionsParentalControls() { - return assertPressMenuItem(R.string.menu_title_options, - R.string.options_item_parental_controls); - } - public UiObject2 assertPressProgramGuide() { return assertPressMenuItem(R.string.menu_title_channels, R.string.channels_item_program_guide); diff --git a/tests/func/src/com/android/tv/tests/ui/AboutFragmentTest.java b/tests/func/src/com/android/tv/tests/ui/AboutFragmentTest.java deleted file mode 100644 index cd7a5718..00000000 --- a/tests/func/src/com/android/tv/tests/ui/AboutFragmentTest.java +++ /dev/null @@ -1,57 +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.ui; - -import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition; - -import android.support.test.uiautomator.BySelector; -import android.support.test.uiautomator.Until; -import android.test.suitebuilder.annotation.LargeTest; - -import com.android.tv.Features; -import com.android.tv.R; -import com.android.tv.testing.uihelper.ByResource; -import com.android.tv.testing.uihelper.SidePanelHelper; - -/** - * Test for the About menu. - */ -@LargeTest -public class AboutFragmentTest extends LiveChannelsTestCase { - private SidePanelHelper mSidePanelHelper; - private BySelector mAboutSidePanel; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mSidePanelHelper = new SidePanelHelper(mDevice, mTargetResources); - mAboutSidePanel = mSidePanelHelper.bySidePanelTitled(R.string.side_panel_title_about); - } - - public void testAllowAnalytics_present() { - mLiveChannelsHelper.assertAppStarted(); - mMenuHelper.assertPressOptionsAbout(); - assertWaitForCondition(mDevice, Until.hasObject(mAboutSidePanel)); - BySelector improveSelector = ByResource - .text(mTargetResources, R.string.about_menu_improve_summary); - if (Features.ANALYTICS_OPT_OUT.isEnabled(getInstrumentation().getContext())) { - assertWaitForCondition(mDevice, Until.hasObject(improveSelector)); - } else { - assertFalse(mDevice.hasObject(improveSelector)); - } - mDevice.pressBack(); - } -} diff --git a/tests/func/src/com/android/tv/tests/ui/ChannelSourcesTest.java b/tests/func/src/com/android/tv/tests/ui/ChannelSourcesTest.java index 9959185f..27d8824e 100644 --- a/tests/func/src/com/android/tv/tests/ui/ChannelSourcesTest.java +++ b/tests/func/src/com/android/tv/tests/ui/ChannelSourcesTest.java @@ -23,36 +23,48 @@ import android.test.suitebuilder.annotation.LargeTest; import com.android.tv.R; import com.android.tv.testing.uihelper.ByResource; -import com.android.tv.testing.uihelper.SidePanelHelper; /** * Tests for channel sources. */ @LargeTest public class ChannelSourcesTest extends LiveChannelsTestCase { - private SidePanelHelper mSidePanelHelper; - private BySelector mByChannelSourceSidePanel; + private BySelector mBySettingsSidePanel; @Override protected void setUp() throws Exception { super.setUp(); - mSidePanelHelper = new SidePanelHelper(mDevice, mTargetResources); - mByChannelSourceSidePanel = mSidePanelHelper - .bySidePanelTitled(R.string.side_panel_title_channel_sources); + mBySettingsSidePanel = mSidePanelHelper.bySidePanelTitled( + R.string.side_panel_title_settings); } //TODO: create a cancelable test channel setup. public void testSetup_cancel() { mLiveChannelsHelper.assertAppStarted(); - mMenuHelper.assertPressOptionsChannelSources(); - assertWaitForCondition(mDevice, Until.hasObject(mByChannelSourceSidePanel)); + mMenuHelper.assertPressOptionsSettings(); + assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); - mSidePanelHelper.assertNavigateToItem(R.string.channel_source_item_setup); + mSidePanelHelper.assertNavigateToItem(R.string.settings_channel_source_item_setup); mDevice.pressDPadCenter(); assertWaitForCondition(mDevice, - Until.hasObject(ByResource.text(mTargetResources, R.string.setup_title))); + Until.hasObject(ByResource.text(mTargetResources, R.string.setup_sources_text))); + mDevice.pressBack(); + } + + // SetupSourcesFragment should have no errors if side fragment item is clicked multiple times. + public void testSetupTwice_cancel() { + mLiveChannelsHelper.assertAppStarted(); + mMenuHelper.assertPressOptionsSettings(); + assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); + + mSidePanelHelper.assertNavigateToItem(R.string.settings_channel_source_item_setup); + mDevice.pressDPadCenter(); + mDevice.pressDPadCenter(); + + assertWaitForCondition(mDevice, + Until.hasObject(ByResource.text(mTargetResources, R.string.setup_sources_text))); mDevice.pressBack(); } } diff --git a/tests/func/src/com/android/tv/tests/ui/LiveChannelsAppTest.java b/tests/func/src/com/android/tv/tests/ui/LiveChannelsAppTest.java index 28b54bae..b48968ad 100644 --- a/tests/func/src/com/android/tv/tests/ui/LiveChannelsAppTest.java +++ b/tests/func/src/com/android/tv/tests/ui/LiveChannelsAppTest.java @@ -28,28 +28,28 @@ import com.android.tv.testing.testinput.ChannelStateData; import com.android.tv.testing.testinput.TvTestInputConstants; import com.android.tv.testing.uihelper.Constants; import com.android.tv.testing.uihelper.DialogHelper; -import com.android.tv.testing.uihelper.SidePanelHelper; /** * Basic tests for the LiveChannels app. */ @LargeTest public class LiveChannelsAppTest extends LiveChannelsTestCase { - private SidePanelHelper mSidePanelHelper; + private BySelector mBySettingsSidePanel; @Override protected void setUp() throws Exception { super.setUp(); - mSidePanelHelper = new SidePanelHelper(mDevice, mTargetResources); mLiveChannelsHelper.assertAppStarted(); pressKeysForChannel(TvTestInputConstants.CH_1_DEFAULT_DONT_MODIFY); getInstrumentation().waitForIdleSync(); + mBySettingsSidePanel = mSidePanelHelper.bySidePanelTitled( + R.string.side_panel_title_settings); } - public void testChannelSourcesCancel() { - mMenuHelper.assertPressOptionsChannelSources(); + public void testSettingsCancel() { + mMenuHelper.assertPressOptionsSettings(); BySelector byChannelSourcesSidePanel = mSidePanelHelper - .bySidePanelTitled(R.string.channel_source_item_customize_channels); + .bySidePanelTitled(R.string.settings_channel_source_item_customize_channels); assertWaitForCondition(mDevice, Until.hasObject(byChannelSourcesSidePanel)); mDevice.pressBack(); assertWaitForCondition(mDevice, Until.gone(byChannelSourcesSidePanel)); @@ -105,7 +105,10 @@ public class LiveChannelsAppTest extends LiveChannelsTestCase { public void testPinCancel() { mMenuHelper.showMenu(); - mMenuHelper.assertPressOptionsParentalControls(); + mMenuHelper.assertPressOptionsSettings(); + assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); + mSidePanelHelper.assertNavigateToItem(R.string.settings_parental_controls); + mDevice.pressDPadCenter(); DialogHelper dialogHelper = new DialogHelper(mDevice, mTargetResources); dialogHelper.assertWaitForPinDialogOpen(); mDevice.pressBack(); 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 96f0e1f8..25c7909b 100644 --- a/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java +++ b/tests/func/src/com/android/tv/tests/ui/LiveChannelsTestCase.java @@ -31,6 +31,7 @@ import com.android.tv.testing.testinput.TestInputControlUtils; 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.SidePanelHelper; import com.android.tv.testing.uihelper.UiDeviceUtils; /** @@ -42,6 +43,7 @@ public abstract class LiveChannelsTestCase extends InstrumentationTestCase { protected UiDevice mDevice; protected Resources mTargetResources; protected MenuHelper mMenuHelper; + protected SidePanelHelper mSidePanelHelper; protected LiveChannelsUiDeviceHelper mLiveChannelsHelper; @Override @@ -53,6 +55,7 @@ public abstract class LiveChannelsTestCase extends InstrumentationTestCase { mDevice = UiDevice.getInstance(getInstrumentation()); mTargetResources = getInstrumentation().getTargetContext().getResources(); mMenuHelper = new MenuHelper(mDevice, mTargetResources); + mSidePanelHelper = new SidePanelHelper(mDevice, mTargetResources); mLiveChannelsHelper = new LiveChannelsUiDeviceHelper(mDevice, mTargetResources, context); } 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 8b7eaeae..40ccf267 100644 --- a/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java +++ b/tests/func/src/com/android/tv/tests/ui/PlayControlsRowViewTest.java @@ -30,13 +30,14 @@ import android.view.KeyEvent; import com.android.tv.R; import com.android.tv.testing.testinput.TvTestInputConstants; import com.android.tv.testing.uihelper.DialogHelper; -import com.android.tv.testing.uihelper.SidePanelHelper; @SmallTest @SdkSuppress(minSdkVersion = 23) public class PlayControlsRowViewTest extends LiveChannelsTestCase { private static final int BUTTON_INDEX_PLAY_PAUSE = 2; + private BySelector mBySettingsSidePanel; + @Override protected void setUp() throws Exception { super.setUp(); @@ -45,6 +46,8 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { // Tune to a new channel to ensure that the channel is changed. mDevice.pressDPadUp(); getInstrumentation().waitForIdleSync(); + mBySettingsSidePanel = mSidePanelHelper.bySidePanelTitled( + R.string.side_panel_title_settings); } /** @@ -110,17 +113,21 @@ public class PlayControlsRowViewTest extends LiveChannelsTestCase { mMenuHelper.assertWaitForMenu(); assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); // Show parental controls fragment. - mMenuHelper.assertPressOptionsParentalControls(); + mMenuHelper.assertPressOptionsSettings(); + assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel)); + mSidePanelHelper.assertNavigateToItem(R.string.settings_parental_controls); + mDevice.pressDPadCenter(); DialogHelper dialogHelper = new DialogHelper(mDevice, mTargetResources); dialogHelper.assertWaitForPinDialogOpen(); dialogHelper.enterPinCodes(); dialogHelper.assertWaitForPinDialogClose(); - SidePanelHelper sidePanelHelper = new SidePanelHelper(mDevice, mTargetResources); - BySelector bySidePanel = sidePanelHelper.bySidePanelTitled(R.string.menu_parental_controls); + BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled( + R.string.menu_parental_controls); assertWaitForCondition(mDevice, Until.hasObject(bySidePanel)); mDevice.pressEnter(); mDevice.pressEnter(); mDevice.pressBack(); + mDevice.pressBack(); // Return to the main menu. mMenuHelper.assertWaitForMenu(); assertButtonHasFocus(BUTTON_INDEX_PLAY_PAUSE); diff --git a/tests/input/src/com/android/tv/testinput/TestTvInputService.java b/tests/input/src/com/android/tv/testinput/TestTvInputService.java index a81977d6..b20e0331 100644 --- a/tests/input/src/com/android/tv/testinput/TestTvInputService.java +++ b/tests/input/src/com/android/tv/testinput/TestTvInputService.java @@ -27,6 +27,7 @@ import android.media.tv.TvInputManager; import android.media.tv.TvInputService; import android.media.tv.TvTrackInfo; import android.net.Uri; +import android.os.Build; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -34,7 +35,6 @@ import android.util.Log; import android.view.KeyEvent; import android.view.Surface; -import com.android.tv.common.TvCommonConstants; import com.android.tv.testing.ChannelInfo; import com.android.tv.testing.testinput.ChannelState; @@ -47,6 +47,8 @@ public class TestTvInputService extends TvInputService { private static final String TAG = "TestTvInputServices"; private static final int REFRESH_DELAY_MS = 1000 / 5; private static final boolean DEBUG = false; + private static final boolean HAS_TIME_SHIFT_API = Build.VERSION.SDK_INT + >= Build.VERSION_CODES.M; private final TestInputControl mBackend = TestInputControl.getInstance(); public static String buildInputId(Context context) { @@ -194,7 +196,7 @@ public class TestTvInputService extends TvInputService { } else { Log.i(TAG, "Tuning to " + mChannel); } - if (TvCommonConstants.HAS_TIME_SHIFT_API) { + if (HAS_TIME_SHIFT_API) { notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE); mRecordStartTimeMs = mCurrentPositionMs = mLastCurrentPositionUpdateTimeMs = System.currentTimeMillis(); @@ -319,7 +321,7 @@ public class TestTvInputService extends TvInputService { private void draw(Surface surface, ChannelInfo currentChannel) { if (surface != null) { - String now = TvCommonConstants.HAS_TIME_SHIFT_API + String now = HAS_TIME_SHIFT_API ? new Date(mCurrentPositionMs).toString() : new Date().toString(); String name = currentChannel == null ? "Null" : currentChannel.name; Canvas c = surface.lockCanvas(null); 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 1de5e944..bec933ca 100644 --- a/tests/jank/src/com/android/tv/tests/jank/ProgramGuideJankTest.java +++ b/tests/jank/src/com/android/tv/tests/jank/ProgramGuideJankTest.java @@ -18,14 +18,14 @@ package com.android.tv.tests.jank; import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition; import android.content.res.Resources; -import android.os.SystemClock; +import android.os.Build; +import android.support.test.filters.SdkSuppress; +import android.support.test.jank.GfxMonitor; import android.support.test.jank.JankTest; import android.support.test.jank.JankTestBase; -import android.support.test.jank.WindowContentFrameStatsMonitor; import android.support.test.uiautomator.UiDevice; import android.support.test.uiautomator.Until; import android.test.suitebuilder.annotation.MediumTest; -import android.util.Log; import com.android.tv.R; import com.android.tv.testing.uihelper.ByResource; @@ -38,12 +38,25 @@ import com.android.tv.testing.uihelper.UiDeviceUtils; * Jank tests for the program guide. */ @MediumTest +@SdkSuppress(minSdkVersion = Build.VERSION_CODES.M) public class ProgramGuideJankTest extends JankTestBase { private static final boolean DEBUG = false; private static final String TAG = "ProgramGuideJank"; private static final String STARTING_CHANNEL = "13"; - private static final int EXPECTED_FRAMES = 5; + public static final String LIVE_CHANNELS_PROCESS_NAME = "com.android.tv"; + + /** + * The minimum number of frames expected during each jank test. + * If there is less the test will fail. To be safe we loop the action in each test to create + * twice this many frames under normal conditions. + * <p>200 is chosen so there will be enough frame for the 90th, 95th, and 98th percentile + * measurements are significant. + * + * @see <a href="http://go/janktesthelper-best-practices">Jank Test Helper Best Practices</a> + */ + private static final int EXPECTED_FRAMES = 200; + public static final String LIVE_CHANNELS_PACKAGE = "com.android.tv"; protected UiDevice mDevice; @@ -51,7 +64,6 @@ public class ProgramGuideJankTest extends JankTestBase { protected MenuHelper mMenuHelper; protected LiveChannelsUiDeviceHelper mLiveChannelsHelper; - @Override protected void setUp() throws Exception { super.setUp(); @@ -64,81 +76,40 @@ public class ProgramGuideJankTest extends JankTestBase { pressKeysForChannelNumber(STARTING_CHANNEL); } - @JankTest(expectedFrames = 7, - beforeTest = "warmProgramGuide", - beforeLoop = "selectProgramGuideMenuItem", - afterLoop = "clearProgramGuide") - @WindowContentFrameStatsMonitor - public void testShowProgramGuide() { - mDevice.pressDPadCenter(); - - // Full show has two animations. - long delay = mTargetResources.getInteger(R.integer.program_guide_anim_duration) * 2; - waitForIdleAtLeast(delay); - } @JankTest(expectedFrames = EXPECTED_FRAMES, - beforeLoop = "showProgramGuide") - @WindowContentFrameStatsMonitor - public void testClearProgramGuide() { - mDevice.pressBack(); - // Full show has two animations. - waitForIdleAtLeast(mTargetResources.getInteger(R.integer.program_guide_anim_duration) * 2); + beforeTest = "warmProgramGuide") + @GfxMonitor(processName = LIVE_CHANNELS_PACKAGE) + public void testShowClearProgramGuide() { + int frames = 53; // measured by hand + int repeat = EXPECTED_FRAMES * 2 / frames; + for (int i = 0; i < repeat; i++) { + showProgramGuide(); + clearProgramGuide(); + } } @JankTest(expectedFrames = EXPECTED_FRAMES, beforeLoop = "showProgramGuide", afterLoop = "clearProgramGuide") - @WindowContentFrameStatsMonitor + @GfxMonitor(processName = LIVE_CHANNELS_PROCESS_NAME) public void testScrollDown() { - mDevice.pressDPadDown(); - waitForIdleAtLeast(mTargetResources - .getInteger(R.integer.program_guide_table_detail_toggle_anim_duration)); + int frames = 20; // measured by hand + int repeat = EXPECTED_FRAMES * 2 / frames; + for (int i = 0; i < repeat; i++) { + mDevice.pressDPadDown(); + } } @JankTest(expectedFrames = EXPECTED_FRAMES, beforeLoop = "showProgramGuide", afterLoop = "clearProgramGuide") - @WindowContentFrameStatsMonitor + @GfxMonitor(processName = LIVE_CHANNELS_PROCESS_NAME) public void testScrollRight() { - mDevice.pressDPadRight(); - waitForIdleAtLeast(mTargetResources - .getInteger(R.integer.program_guide_table_detail_toggle_anim_duration)); - } - - /** - * {@link UiDevice#waitForIdle() Wait for idle} , then sleep if needed, then wait for idle - * again. - * - * @param delayInMillis The minimum amount of time to delay. This is usually the expected - * duration of the animation. - */ - private void waitForIdleAtLeast(long delayInMillis) { - - // This seems to give the most reliable numbers. - // The first wait until idle usually returned in 1ms. - // Sometimes it would take the whole duration. If we sleep after that we get bad fps - // because nothing is happening after the idle ends. - // - // So sleeping only for the remaining about ensure there is at least enough time for the - // animation to complete. If we sleep then wait for idle again. This will usually allow - // the animation to complete. - - long startTime = SystemClock.uptimeMillis(); - mDevice.waitForIdle(); - - long idle = SystemClock.uptimeMillis() - startTime; - if (DEBUG) { - Log.d(TAG, "Waited for idle " + (idle) / 1000.0 + " sec"); - } - if (idle < delayInMillis) { - long more = delayInMillis - idle; - SystemClock.sleep(more); - Log.d(TAG, "Slept " + (more) / 1000.0 + " sec"); - mDevice.waitForIdle(); - } - if (DEBUG) { - Log.d(TAG, "Total wait " + (SystemClock.uptimeMillis() - startTime) / 1000.0 + " sec"); + int frames = 30; // measured by hand + int repeat = EXPECTED_FRAMES * 2 / frames; + for (int i = 0; i < repeat; i++) { + mDevice.pressDPadRight(); } } diff --git a/tests/unit/src/com/android/tv/common/TvContentRatingCacheTest.java b/tests/unit/src/com/android/tv/common/TvContentRatingCacheTest.java new file mode 100644 index 00000000..cad1e7ca --- /dev/null +++ b/tests/unit/src/com/android/tv/common/TvContentRatingCacheTest.java @@ -0,0 +1,172 @@ +/* + * 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.common; + +import android.content.ComponentCallbacks2; +import android.media.tv.TvContentRating; +import android.test.AndroidTestCase; +import android.test.MoreAsserts; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.tv.testing.TvContentRatingConstants; +import com.android.tv.util.Utils; + +/** + * Test for {@link android.media.tv.TvContentRating} tests in {@link Utils}. + */ +@SmallTest +public class TvContentRatingCacheTest extends AndroidTestCase { + + /** + * US_TV_MA and US_TV_Y7 in order + */ + public static final String MA_AND_Y7 = TvContentRatingConstants.STRING_US_TV_MA + "," + + TvContentRatingConstants.STRING_US_TV_Y7_US_TV_FV; + + /** + * US_TV_MA and US_TV_Y7 not in order + */ + public static final String Y7_AND_MA = TvContentRatingConstants.STRING_US_TV_Y7_US_TV_FV + "," + + TvContentRatingConstants.STRING_US_TV_MA; + TvContentRatingCache mCache = TvContentRatingCache.getInstance(); + + @Override + protected void setUp() throws Exception { + super.setUp(); + mCache.performTrimMemory(ComponentCallbacks2.TRIM_MEMORY_COMPLETE); + } + + @Override + protected void tearDown() throws Exception { + mCache.performTrimMemory(ComponentCallbacks2.TRIM_MEMORY_COMPLETE); + super.tearDown(); + } + + public void testGetRatings_US_TV_MA() { + TvContentRating[] result = mCache.getRatings(TvContentRatingConstants.STRING_US_TV_MA); + MoreAsserts.assertEquals(asArray(TvContentRatingConstants.CONTENT_RATING_US_TV_MA), result); + } + + public void testGetRatings_US_TV_MA_same() { + TvContentRating[] first = mCache.getRatings(TvContentRatingConstants.STRING_US_TV_MA); + TvContentRating[] second = mCache.getRatings(TvContentRatingConstants.STRING_US_TV_MA); + assertSame(first, second); + } + + public void testGetRatings_US_TV_MA_diffAfterClear() { + TvContentRating[] first = mCache.getRatings(TvContentRatingConstants.STRING_US_TV_MA); + mCache.performTrimMemory(ComponentCallbacks2.TRIM_MEMORY_COMPLETE); + TvContentRating[] second = mCache.getRatings(TvContentRatingConstants.STRING_US_TV_MA); + assertNotSame(first, second); + } + + public void testGetRatings_TWO_orderDoesNotMatter() { + TvContentRating[] first = mCache.getRatings(MA_AND_Y7); + TvContentRating[] second = mCache.getRatings(Y7_AND_MA); + assertSame(first, second); + } + + public void testContentRatingsToString_null() { + String result = TvContentRatingCache.contentRatingsToString(null); + assertEquals("ratings string", null, result); + } + + public void testContentRatingsToString_none() { + String result = TvContentRatingCache.contentRatingsToString(asArray()); + assertEquals("ratings string", null, result); + } + + public void testContentRatingsToString_one() { + String result = TvContentRatingCache + .contentRatingsToString(asArray(TvContentRatingConstants.CONTENT_RATING_US_TV_MA)); + assertEquals("ratings string", TvContentRatingConstants.STRING_US_TV_MA, result); + } + + public void testContentRatingsToString_twoInOrder() { + String result = TvContentRatingCache.contentRatingsToString( + asArray(TvContentRatingConstants.CONTENT_RATING_US_TV_MA, + TvContentRatingConstants.CONTENT_RATING_US_TV_Y7_US_TV_FV)); + assertEquals("ratings string", MA_AND_Y7, result); + } + + public void testContentRatingsToString_twoNotInOrder() { + String result = TvContentRatingCache.contentRatingsToString(asArray( + TvContentRatingConstants.CONTENT_RATING_US_TV_Y7_US_TV_FV, + TvContentRatingConstants.CONTENT_RATING_US_TV_MA)); + assertEquals("ratings string", MA_AND_Y7, result); + } + + public void testContentRatingsToString_double() { + String result = TvContentRatingCache.contentRatingsToString(asArray( + TvContentRatingConstants.CONTENT_RATING_US_TV_MA, + TvContentRatingConstants.CONTENT_RATING_US_TV_MA)); + assertEquals("ratings string", TvContentRatingConstants.STRING_US_TV_MA, result); + } + + public void testStringToContentRatings_null() { + assertNull(TvContentRatingCache.stringToContentRatings(null)); + } + + public void testStringToContentRatings_none() { + assertNull(TvContentRatingCache.stringToContentRatings("")); + } + + public void testStringToContentRatings_bad() { + assertNull(TvContentRatingCache.stringToContentRatings("bad")); + } + + public void testStringToContentRatings_oneGoodOneBad() { + TvContentRating[] results = TvContentRatingCache + .stringToContentRatings(TvContentRatingConstants.STRING_US_TV_Y7_US_TV_FV + ",bad"); + MoreAsserts.assertEquals("ratings", + asArray(TvContentRatingConstants.CONTENT_RATING_US_TV_Y7_US_TV_FV), results); + } + + public void testStringToContentRatings_one() { + TvContentRating[] results = TvContentRatingCache + .stringToContentRatings(TvContentRatingConstants.STRING_US_TV_Y7_US_TV_FV); + MoreAsserts.assertEquals("ratings", + asArray(TvContentRatingConstants.CONTENT_RATING_US_TV_Y7_US_TV_FV), results); + } + + public void testStringToContentRatings_twoNotInOrder() { + TvContentRating[] results = TvContentRatingCache.stringToContentRatings(Y7_AND_MA); + MoreAsserts.assertEquals("ratings", + asArray(TvContentRatingConstants.CONTENT_RATING_US_TV_MA, + TvContentRatingConstants.CONTENT_RATING_US_TV_Y7_US_TV_FV), results); + } + + public void testStringToContentRatings_twoInOrder() { + TvContentRating[] results = TvContentRatingCache.stringToContentRatings(MA_AND_Y7); + MoreAsserts.assertEquals("ratings", + asArray(TvContentRatingConstants.CONTENT_RATING_US_TV_MA, + TvContentRatingConstants.CONTENT_RATING_US_TV_Y7_US_TV_FV), results); + } + + public void testStringToContentRatings_double() { + TvContentRating[] results = TvContentRatingCache.stringToContentRatings( + TvContentRatingConstants.STRING_US_TV_MA + "," + + TvContentRatingConstants.STRING_US_TV_MA); + MoreAsserts + .assertEquals("ratings", asArray(TvContentRatingConstants.CONTENT_RATING_US_TV_MA), + results); + } + + private static TvContentRating[] asArray(TvContentRating... ratings) { + return ratings; + } +} diff --git a/tests/unit/src/com/android/tv/common/ui/setup/leanback/PagingIndicatorTest.java b/tests/unit/src/com/android/tv/common/ui/setup/leanback/PagingIndicatorTest.java new file mode 100644 index 00000000..b342de66 --- /dev/null +++ b/tests/unit/src/com/android/tv/common/ui/setup/leanback/PagingIndicatorTest.java @@ -0,0 +1,94 @@ +/* + * 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.common.ui.setup.leanback; + +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.tv.testing.Utils; + +/** + * Tests for {@link PagingIndicator}. + */ +@SmallTest +public class PagingIndicatorTest extends AndroidTestCase { + private PagingIndicator mIndicator; + + @Override + protected void setUp() throws Exception { + super.setUp(); + Utils.runOnMainSync(new Runnable() { + @Override + public void run() { + mIndicator = new PagingIndicator(getContext()); + } + }); + } + + public void testDotPosition() { + mIndicator.setPageCount(3); + assertDotPosition(); + mIndicator.setPageCount(6); + assertDotPosition(); + mIndicator.setPageCount(9); + assertDotPosition(); + } + + private void assertDotPosition() { + assertSymmetry(); + assertDistance(); + } + + private void assertSymmetry() { + int pageCount = mIndicator.getPageCount(); + int mid = pageCount / 2; + int[] selectedX = mIndicator.getDotSelectedX(); + int sum = selectedX[0] + selectedX[pageCount - 1]; + for (int i = 1; i <= mid; ++i) { + assertEquals("Selected dots are not symmetric", sum, + selectedX[i] + selectedX[pageCount - i - 1]); + } + int[] leftX = mIndicator.getDotSelectedLeftX(); + int[] rightX = mIndicator.getDotSelectedRightX(); + sum = leftX[0] + rightX[pageCount - 1]; + for (int i = 1; i < pageCount - 1; ++i) { + assertEquals("Deselected dots are not symmetric", sum, + leftX[i] + rightX[pageCount - i - 1]); + } + } + + private void assertDistance() { + int pageCount = mIndicator.getPageCount(); + int[] selectedX = mIndicator.getDotSelectedX(); + int[] leftX = mIndicator.getDotSelectedLeftX(); + int[] rightX = mIndicator.getDotSelectedRightX(); + int distance = selectedX[1] - selectedX[0]; + for (int i = 2; i < pageCount; ++i) { + assertEquals("Gaps between selected dots are not even", distance, + selectedX[i] - selectedX[i - 1]); + } + distance = leftX[1] - leftX[0]; + for (int i = 2; i < pageCount - 1; ++i) { + assertEquals("Gaps between left dots are not even", distance, + leftX[i] - leftX[i - 1]); + } + distance = rightX[2] - rightX[1]; + for (int i = 3; i < pageCount; ++i) { + assertEquals("Gaps between right dots are not even", distance, + rightX[i] - rightX[i - 1]); + } + } +} diff --git a/tests/unit/src/com/android/tv/data/ChannelDataManagerTest.java b/tests/unit/src/com/android/tv/data/ChannelDataManagerTest.java index fa127369..4dc91ce3 100644 --- a/tests/unit/src/com/android/tv/data/ChannelDataManagerTest.java +++ b/tests/unit/src/com/android/tv/data/ChannelDataManagerTest.java @@ -36,7 +36,6 @@ import android.text.TextUtils; import android.util.Log; import android.util.SparseArray; -import com.android.tv.analytics.StubTracker; import com.android.tv.testing.ChannelInfo; import com.android.tv.testing.Constants; import com.android.tv.testing.Utils; @@ -89,7 +88,7 @@ public class ChannelDataManagerTest extends AndroidTestCase { TvInputManagerHelper mockHelper = Mockito.mock(TvInputManagerHelper.class); Mockito.when(mockHelper.hasTvInputInfo(Matchers.anyString())).thenReturn(true); mChannelDataManager = new ChannelDataManager(getContext(), mockHelper, - new StubTracker(), mContentResolver); + mContentResolver); mChannelDataManager.addListener(mListener); } }); diff --git a/tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java b/tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java index bc239a8a..0914f804 100644 --- a/tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java +++ b/tests/unit/src/com/android/tv/data/TvInputNewComparatorTest.java @@ -20,6 +20,7 @@ import android.content.pm.ResolveInfo; import android.media.tv.TvInputInfo; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; +import android.util.Pair; import com.android.tv.testing.ComparatorTester; import com.android.tv.util.SetupUtils; @@ -40,12 +41,14 @@ import java.util.LinkedHashMap; @SmallTest 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); - INPUT_ID_TO_NEW_INPUT.put("4_new_input", true); - INPUT_ID_TO_NEW_INPUT.put("0_old_input", false); - INPUT_ID_TO_NEW_INPUT.put("1_old_input", false); - INPUT_ID_TO_NEW_INPUT.put("3_old_input", false); + final LinkedHashMap<String, Pair<Boolean, Boolean>> INPUT_ID_TO_NEW_INPUT = + new LinkedHashMap<>(); + INPUT_ID_TO_NEW_INPUT.put("2_new_input", new Pair(true, false)); + INPUT_ID_TO_NEW_INPUT.put("4_new_input", new Pair(true, false)); + INPUT_ID_TO_NEW_INPUT.put("4_old_input", new Pair(false, false)); + INPUT_ID_TO_NEW_INPUT.put("0_old_input", new Pair(false, true)); + INPUT_ID_TO_NEW_INPUT.put("1_old_input", new Pair(false, true)); + INPUT_ID_TO_NEW_INPUT.put("3_old_input", new Pair(false, true)); SetupUtils setupUtils = Mockito.mock(SetupUtils.class); Mockito.when(setupUtils.isNewInput(Matchers.anyString())).thenAnswer( @@ -53,7 +56,16 @@ public class TvInputNewComparatorTest extends AndroidTestCase { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { String inputId = (String) invocation.getArguments()[0]; - return INPUT_ID_TO_NEW_INPUT.get(inputId); + return INPUT_ID_TO_NEW_INPUT.get(inputId).first; + } + } + ); + Mockito.when(setupUtils.isSetupDone(Matchers.anyString())).thenAnswer( + new Answer<Boolean>() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + String inputId = (String) invocation.getArguments()[0]; + return INPUT_ID_TO_NEW_INPUT.get(inputId).second; } } ); diff --git a/tests/unit/src/com/android/tv/data/WatchedHistoryManagerTest.java b/tests/unit/src/com/android/tv/data/WatchedHistoryManagerTest.java index e5da60eb..eb99cb88 100644 --- a/tests/unit/src/com/android/tv/data/WatchedHistoryManagerTest.java +++ b/tests/unit/src/com/android/tv/data/WatchedHistoryManagerTest.java @@ -19,6 +19,7 @@ package com.android.tv.data; import android.test.AndroidTestCase; import android.test.UiThreadTest; import android.test.suitebuilder.annotation.SmallTest; +import android.test.suitebuilder.annotation.Suppress; import com.android.tv.data.WatchedHistoryManager.WatchedRecord; import com.android.tv.testing.Utils; @@ -30,6 +31,7 @@ import java.util.concurrent.TimeUnit; * Test for {@link com.android.tv.data.WatchedHistoryManagerTest} */ @SmallTest +@Suppress // http://b/27156462 public class WatchedHistoryManagerTest extends AndroidTestCase { private static final boolean DEBUG = false; private static final String TAG = "WatchedHistoryManager"; diff --git a/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java b/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java index 06cf7315..204f7cec 100644 --- a/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java +++ b/tests/unit/src/com/android/tv/dvr/DvrDataManagerImplTest.java @@ -34,22 +34,22 @@ public class DvrDataManagerImplTest extends TestCase { long id = 1; List<Recording> recordings = new ArrayList<>(); assertNextStartTime(recordings, 0L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); - recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 10L, 20L)); + recordings.add(RecordingTestUtils.createTestRecordingWithIdAndPeriod(id++, 10L, 20L)); assertNextStartTime(recordings, 9L, 10L); assertNextStartTime(recordings, 10L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); - recordings.add(RecordingTestUtils.createTestRecordingWithPeriod(id++, 20L, 30L)); + recordings.add(RecordingTestUtils.createTestRecordingWithIdAndPeriod(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)); + recordings.add(RecordingTestUtils.createTestRecordingWithIdAndPeriod(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)); + recordings.add(RecordingTestUtils.createTestRecordingWithIdAndPeriod(id++, 10L, 20L)); + recordings.add(RecordingTestUtils.createTestRecordingWithIdAndPeriod(id++, 10L, 20L)); + recordings.add(RecordingTestUtils.createTestRecordingWithIdAndPeriod(id++, 10L, 20L)); assertNextStartTime(recordings, 9L, 10L); assertNextStartTime(recordings, 10L, DvrDataManager.NEXT_START_TIME_NOT_FOUND); } diff --git a/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java b/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java index 85c2f661..418caa7e 100644 --- a/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java +++ b/tests/unit/src/com/android/tv/dvr/DvrRecordingServiceTest.java @@ -23,8 +23,8 @@ 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.CommonFeatures; import com.android.tv.common.feature.TestableFeature; import org.mockito.Mock; @@ -39,7 +39,7 @@ public class DvrRecordingServiceTest extends ServiceTestCase<DvrRecordingService @Mock Scheduler mMockScheduler; @Mock ApplicationSingletons mApplicationSingletons; - private final TestableFeature mDvrFeature = Features.DVR; + private final TestableFeature mDvrFeature = CommonFeatures.DVR; private DvrDataManagerInMemoryImpl mDataManager; private DvrRecordingService mService; diff --git a/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java b/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java index 063cd61f..8e3b4fd4 100644 --- a/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java +++ b/tests/unit/src/com/android/tv/dvr/RecordingTaskTest.java @@ -16,97 +16,169 @@ package com.android.tv.dvr; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyLong; +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 android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.os.SystemClock; +import android.support.test.filters.SdkSuppress; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; -import com.android.tv.common.dvr.DvrSessionClient; +import com.android.tv.common.recording.TvRecording; import com.android.tv.data.Channel; +import com.android.tv.dvr.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 java.util.concurrent.TimeUnit; + /** * Tests for {@link RecordingTask}. */ @SmallTest +@SdkSuppress(minSdkVersion = 23) public class RecordingTaskTest extends AndroidTestCase { + private static final long DURATION = TimeUnit.MINUTES.toMillis(30); + private static final long START_OFFSET = Scheduler.MS_TO_WAKE_BEFORE_START; + private FakeClock mFakeClock; private DvrDataManagerInMemoryImpl mDataManager; @Mock + Handler mMockHandler; + @Mock DvrSessionManager mMockSessionManager; @Mock - DvrSessionClient mMockDvrSessionClient; + TvRecording.TvRecordingClient mMockTvRecordingClient; @Override protected void setUp() throws Exception { super.setUp(); + if (Looper.myLooper() == null) { + Looper.prepare(); + } MockitoAnnotations.initMocks(this); - mFakeClock = FakeClock.createWithTimeOne(); + mFakeClock = FakeClock.createWithCurrentTime(); 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); + public void testHandle_init() { + Recording r = createRecording(); + RecordingTask task = createRecordingTask(r); Channel channel = r.getChannel(); String inputId = channel.getInputId(); - when(mMockSessionManager.canAcquireDvrSession(inputId, channel)) - .thenReturn(true); + 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()); - } + .thenReturn(mMockTvRecordingClient); + when(mMockHandler.sendEmptyMessageDelayed(anyInt(), anyLong())).thenReturn(true); - 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(); + long delay = START_OFFSET - RecordingTask.MS_BEFORE_START; + long uptime = SystemClock.uptimeMillis(); + assertTrue(task.handleMessage(createMessage(RecordingTask.MESSAGE_INIT))); + assertEquals(State.CONNECTION_PENDING, task.getState()); 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); + verify(mMockTvRecordingClient).connect(eq(inputId), any(TvRecording.ClientCallback.class)); + + verifySendMessageAt(RecordingTask.MESSAGE_START_RECORDING, uptime + delay); + verifyNoMoreInteractions(mMockHandler, mMockTvRecordingClient, mMockSessionManager); + } + + + public void testHandle_init_cannotAcquireSession() { + Recording r = createRecording(); + r = mDataManager.addRecordingInternal(r); + RecordingTask task = createRecordingTask(r); when(mMockSessionManager.canAcquireDvrSession(r.getChannel().getInputId(), r.getChannel())) .thenReturn(false); - task.run(); + + assertTrue(task.handleMessage(createMessage(RecordingTask.MESSAGE_INIT))); + + assertEquals(State.ERROR, task.getState()); + verifySendMessage(Scheduler.HandlerWrapper.MESSAGE_REMOVE); Recording updatedRecording = mDataManager.getRecording(r.getId()); - assertEquals("status",Recording.STATE_RECORDING_FAILED, updatedRecording.getState() ); + assertEquals("status", Recording.STATE_RECORDING_FAILED, updatedRecording.getState()); + } + + public void testOnConnected() { + Recording r = createRecording(); + mDataManager.addRecording(r); + RecordingTask task = createRecordingTask(r); + + task.onConnected(); + + assertEquals(State.CONNECTED, task.getState()); + } + + private Recording createRecording() { + long startTime = mFakeClock.currentTimeMillis() + START_OFFSET; + long endTime = startTime + DURATION; + return RecordingTestUtils.createTestRecordingWithPeriod(startTime, endTime); + } + + private RecordingTask createRecordingTask(Recording r) { + RecordingTask recordingTask = new RecordingTask(r, mMockSessionManager, mDataManager, + mFakeClock); + recordingTask.setHandler(mMockHandler); + return recordingTask; + } + + private void verifySendMessage(int what) { + verify(mMockHandler).sendMessageAtTime(argThat(messageMatchesWhat(what)), anyLong()); + } + + private void verifySendMessageAt(int what, long when) { + verify(mMockHandler).sendMessageAtTime(argThat(messageMatchesWhat(what)), delta(when, 100)); + } + + private static long delta(final long value, final long delta) { + return longThat(new BaseMatcher<Long>() { + @Override + public boolean matches(Object item) { + Long other = (Long) item; + return other >= value - delta && other <= value + delta; + } + + @Override + public void describeTo(Description description) { + description.appendText("eq " + value + "±" + delta); + + } + }); + } + + private Message createMessage(int what) { + Message msg = new Message(); + msg.setTarget(mMockHandler); + msg.what = what; + return msg; + } + + public static ArgumentMatcher<Message> messageMatchesWhat(final int what) { + return new ArgumentMatcher<Message>() { + @Override + 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/RecordingTest.java b/tests/unit/src/com/android/tv/dvr/RecordingTest.java index ef012248..e5ffaa3b 100644 --- a/tests/unit/src/com/android/tv/dvr/RecordingTest.java +++ b/tests/unit/src/com/android/tv/dvr/RecordingTest.java @@ -16,20 +16,31 @@ package com.android.tv.dvr; +import static com.android.tv.testing.dvr.RecordingTestUtils.createTestRecordingWithIdAndPeriod; +import static com.android.tv.testing.dvr.RecordingTestUtils.normalizePriority; + +import android.test.MoreAsserts; import android.test.suitebuilder.annotation.SmallTest; import android.util.Range; +import com.android.tv.data.Channel; +import com.android.tv.data.Program; import com.android.tv.testing.dvr.RecordingTestUtils; import junit.framework.TestCase; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + /** * Tests for {@link RecordingTest} */ @SmallTest public class RecordingTest extends TestCase { public void testIsOverLapping() throws Exception { - Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, 10L, 20L); + Recording r = createTestRecordingWithIdAndPeriod(1, 10L, 20L); assertOverLapping(false, 1L, 9L, r); assertOverLapping(true, 1L, 20L, r); @@ -43,6 +54,43 @@ public class RecordingTest extends TestCase { assertOverLapping(false, 21L, 29L, r); } + public void testBuildProgram() { + Channel c = new Channel.Builder().build(); + Program p = new Program.Builder().build(); + Recording actual = Recording.builder(c, p).build(); + assertEquals("type", Recording.TYPE_PROGRAM, actual.getType()); + } + + public void testBuildTime() { + Recording actual = createTestRecordingWithIdAndPeriod(1, 10L, 20L); + assertEquals("type", Recording.TYPE_TIMED, actual.getType()); + } + + public void testBuildFrom() { + Recording expected = createTestRecordingWithIdAndPeriod(1, 10L, 20L); + Recording actual = Recording.buildFrom(expected).build(); + RecordingTestUtils.assertRecordingEquals(expected, actual); + } + + public void testBuild_priority() { + Recording a = normalizePriority(createTestRecordingWithIdAndPeriod(1, 10L, 20L)); + Recording b = normalizePriority(createTestRecordingWithIdAndPeriod(2, 10L, 20L)); + Recording c = normalizePriority(createTestRecordingWithIdAndPeriod(3, 10L, 20L)); + + // default priority + MoreAsserts.assertContentsInOrder(sortByPriority(c,b,a), a, b, c); + + // make C preferred over B + c = Recording.buildFrom(c).setPriority(b.getPriority() - 1).build(); + MoreAsserts.assertContentsInOrder(sortByPriority(c,b,a), a, c, b); + } + + public Collection<Recording> sortByPriority(Recording a, Recording b, Recording c) { + List<Recording> list = Arrays.asList(a, b, c); + Collections.sort(list, Recording.PRIORITY_COMPARATOR); + return list; + } + 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 index 281b055a..6748eddb 100644 --- a/tests/unit/src/com/android/tv/dvr/SchedulerTest.java +++ b/tests/unit/src/com/android/tv/dvr/SchedulerTest.java @@ -24,6 +24,8 @@ import static org.mockito.Mockito.verifyZeroInteractions; import android.app.AlarmManager; import android.app.PendingIntent; +import android.os.Looper; +import android.support.test.filters.SdkSuppress; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; @@ -39,6 +41,7 @@ import java.util.concurrent.TimeUnit; * Tests for {@link Scheduler}. */ @SmallTest +@SdkSuppress(minSdkVersion = 23) public class SchedulerTest extends AndroidTestCase { private FakeClock mClock; private DvrDataManagerInMemoryImpl mDataManager; @@ -52,8 +55,8 @@ public class SchedulerTest extends AndroidTestCase { MockitoAnnotations.initMocks(this); mClock = FakeClock.createWithCurrentTime(); mDataManager = new DvrDataManagerInMemoryImpl(getContext()); - mScheduler = new Scheduler(mSessionManager, mDataManager, getContext(), mClock, - mMockAlarmManager); + mScheduler = new Scheduler(Looper.myLooper(), mSessionManager, mDataManager, getContext(), + mClock, mMockAlarmManager); } public void testUpdate_none() throws Exception { @@ -64,7 +67,7 @@ public class SchedulerTest extends AndroidTestCase { public void testUpdate_nextIn12Hours() throws Exception { long now = mClock.currentTimeMillis(); long startTime = now + TimeUnit.HOURS.toMillis(12); - Recording r = RecordingTestUtils.createTestRecordingWithPeriod(1, startTime, + Recording r = RecordingTestUtils.createTestRecordingWithPeriod(startTime, startTime + TimeUnit.HOURS.toMillis(1)); mDataManager.addRecording(r); mScheduler.update(); @@ -78,7 +81,7 @@ public class SchedulerTest extends AndroidTestCase { long now = mClock.currentTimeMillis(); long startTime = now + 3; Recording r = RecordingTestUtils - .createTestRecordingWithPeriod(1, startTime, startTime + 100); + .createTestRecordingWithPeriod(startTime, startTime + 100); assertFalse(mScheduler.startsWithin(r, 2)); assertTrue(mScheduler.startsWithin(r, 3)); } diff --git a/tests/unit/src/com/android/tv/util/TestUtils.java b/tests/unit/src/com/android/tv/util/TestUtils.java index db5e93cc..09d32779 100644 --- a/tests/unit/src/com/android/tv/util/TestUtils.java +++ b/tests/unit/src/com/android/tv/util/TestUtils.java @@ -32,7 +32,7 @@ public class TestUtils { // Create a mock TvInputInfo by using private constructor // TODO: Find better way to mock TvInputInfo. // Note that mockito doesn't support mock/spy on final object. - if (Build.VERSION.SDK_INT < 23) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return createTvInputInfoForLmp(service, id, parentId, type); } return createTvInputInfoForMnc(service, id, parentId, type, isHardwareInput); diff --git a/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java b/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java index 162ff63d..42667bee 100644 --- a/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java +++ b/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java @@ -35,9 +35,9 @@ import java.util.Locale; public class UtilsTest_GetDurationString extends AndroidTestCase { // TODO: Mock Context so we can specify current time and locale for test. private Locale mLocale; - private static final long DATE_2015_2_1_MS = getFeb2015InMillis(1, 0, 0); + private static final long DATE_THIS_YEAR_2_1_MS = getFebOfThisYearInMillis(1, 0, 0); - // All possible list for a paramter to test parameter independent result. + // All possible list for a parameter to test parameter independent result. private static final boolean[] PARAM_USE_SHORT_FORMAT = {false, true}; @Override @@ -49,192 +49,197 @@ public class UtilsTest_GetDurationString extends AndroidTestCase { } /** - * Return time in millis assuming that whose year is 2015 and month is Jan. + * Return time in millis assuming that whose year is this year and month is Jan. */ - private static long getJan2015InMillis(int date, int hour, int minutes) { - return new GregorianCalendar( - 2015, Calendar.JANUARY, date, hour, minutes).getTimeInMillis(); + private static long getJanOfThisYearInMillis(int date, int hour, int minutes) { + return new GregorianCalendar(getThisYear(), Calendar.JANUARY, date, hour, minutes) + .getTimeInMillis(); } - private static long getJan2015InMillis(int date, int hour) { - return getJan2015InMillis(date, hour, 0); + private static long getJanOfThisYearInMillis(int date, int hour) { + return getJanOfThisYearInMillis(date, hour, 0); } /** - * Return time in millis assuming that whose year is 2015 and month is Feb. + * Return time in millis assuming that whose year is this year and month is Feb. */ - private static long getFeb2015InMillis(int date, int hour, int minutes) { - return new GregorianCalendar( - 2015, Calendar.FEBRUARY, date, hour, minutes).getTimeInMillis(); + private static long getFebOfThisYearInMillis(int date, int hour, int minutes) { + return new GregorianCalendar(getThisYear(), Calendar.FEBRUARY, date, hour, minutes) + .getTimeInMillis(); } - private static long getFeb2015InMillis(int date, int hour) { - return getFeb2015InMillis(date, hour, 0); + private static long getFebOfThisYearInMillis(int date, int hour) { + return getFebOfThisYearInMillis(date, hour, 0); + } + + private static int getThisYear() { + return new GregorianCalendar().get(GregorianCalendar.YEAR); } public void testSameDateAndTime() { - assertEquals("3:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 3), getFeb2015InMillis(1, 3), false, + assertEquals("3:00 AM", Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 3), getFebOfThisYearInMillis(1, 3), false, DateUtils.FORMAT_12HOUR)); - assertEquals("03:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 3), getFeb2015InMillis(1, 3), false, + assertEquals("03:00", Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 3), getFebOfThisYearInMillis(1, 3), false, DateUtils.FORMAT_24HOUR)); } public void testDurationWithinToday() { assertEquals("12:00 – 3:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - DATE_2015_2_1_MS, getFeb2015InMillis(1, 3), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 3), false, DateUtils.FORMAT_12HOUR)); assertEquals("00:00 – 03:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - DATE_2015_2_1_MS, getFeb2015InMillis(1, 3), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 3), false, DateUtils.FORMAT_24HOUR)); } public void testDurationFromYesterdayToToday() { assertEquals("Jan 31, 3:00 AM – Feb 1, 4:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getJan2015InMillis(31, 3), getFeb2015InMillis(1, 4), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getJanOfThisYearInMillis(31, 3), getFebOfThisYearInMillis(1, 4), false, DateUtils.FORMAT_12HOUR)); assertEquals("Jan 31, 03:00 – Feb 1, 04:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getJan2015InMillis(31, 3), getFeb2015InMillis(1, 4), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getJanOfThisYearInMillis(31, 3), getFebOfThisYearInMillis(1, 4), false, DateUtils.FORMAT_24HOUR)); assertEquals("1/31, 11:30 PM – 12:30 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getJan2015InMillis(31, 23, 30), getFeb2015InMillis(1, 0, 30), true, - DateUtils.FORMAT_12HOUR)); + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getJanOfThisYearInMillis(31, 23, 30), getFebOfThisYearInMillis(1, 0, 30), + true, DateUtils.FORMAT_12HOUR)); assertEquals("1/31, 23:30 – 00:30", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getJan2015InMillis(31, 23, 30), getFeb2015InMillis(1, 0, 30), true, - DateUtils.FORMAT_24HOUR)); + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getJanOfThisYearInMillis(31, 23, 30), getFebOfThisYearInMillis(1, 0, 30), + true, DateUtils.FORMAT_24HOUR)); } public void testDurationFromTodayToTomorrow() { assertEquals("Feb 1, 3:00 AM – Feb 2, 4:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 3), getFeb2015InMillis(2, 4), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 3), getFebOfThisYearInMillis(2, 4), false, DateUtils.FORMAT_12HOUR)); assertEquals("Feb 1, 03:00 – Feb 2, 04:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 3), getFeb2015InMillis(2, 4), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 3), getFebOfThisYearInMillis(2, 4), false, DateUtils.FORMAT_24HOUR)); assertEquals("2/1, 3:00 AM – 2/2, 4:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 3), getFeb2015InMillis(2, 4), true, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 3), getFebOfThisYearInMillis(2, 4), true, DateUtils.FORMAT_12HOUR)); assertEquals("2/1, 03:00 – 2/2, 04:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 3), getFeb2015InMillis(2, 4), true, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 3), getFebOfThisYearInMillis(2, 4), true, DateUtils.FORMAT_24HOUR)); assertEquals("Feb 1, 11:30 PM – Feb 2, 12:30 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 23, 30), getFeb2015InMillis(2, 0, 30), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 23, 30), getFebOfThisYearInMillis(2, 0, 30), + false, DateUtils.FORMAT_12HOUR)); assertEquals("Feb 1, 23:30 – Feb 2, 00:30", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 23, 30), getFeb2015InMillis(2, 0, 30), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 23, 30), getFebOfThisYearInMillis(2, 0, 30), + false, DateUtils.FORMAT_24HOUR)); assertEquals("11:30 PM – 12:30 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 23, 30), getFeb2015InMillis(2, 0, 30), true, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 23, 30), getFebOfThisYearInMillis(2, 0, 30), + true, DateUtils.FORMAT_12HOUR)); - assertEquals("23:30 – 00:30", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 23, 30), getFeb2015InMillis(2, 0, 30), true, + assertEquals("23:30 – 00:30", Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 23, 30), getFebOfThisYearInMillis(2, 0, 30), + true, DateUtils.FORMAT_24HOUR)); } public void testDurationWithinTomorrow() { assertEquals("Feb 2, 2:00 – 4:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 2), getFeb2015InMillis(2, 4), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 2), getFebOfThisYearInMillis(2, 4), false, DateUtils.FORMAT_12HOUR)); assertEquals("Feb 2, 02:00 – 04:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 2), getFeb2015InMillis(2, 4), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 2), getFebOfThisYearInMillis(2, 4), false, DateUtils.FORMAT_24HOUR)); assertEquals("2/2, 2:00 – 4:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 2), getFeb2015InMillis(2, 4), true, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 2), getFebOfThisYearInMillis(2, 4), true, DateUtils.FORMAT_12HOUR)); assertEquals("2/2, 02:00 – 04:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 2), getFeb2015InMillis(2, 4), true, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 2), getFebOfThisYearInMillis(2, 4), true, DateUtils.FORMAT_24HOUR)); } public void testStartOfDay() { assertEquals("12:00 – 1:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - DATE_2015_2_1_MS, getFeb2015InMillis(1, 1), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 1), false, DateUtils.FORMAT_12HOUR)); assertEquals("00:00 – 01:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - DATE_2015_2_1_MS, getFeb2015InMillis(1, 1), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 1), false, DateUtils.FORMAT_24HOUR)); assertEquals("Feb 2, 12:00 – 1:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 0), getFeb2015InMillis(2, 1), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 0), getFebOfThisYearInMillis(2, 1), false, DateUtils.FORMAT_12HOUR)); assertEquals("Feb 2, 00:00 – 01:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 0), getFeb2015InMillis(2, 1), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 0), getFebOfThisYearInMillis(2, 1), false, DateUtils.FORMAT_24HOUR)); assertEquals("2/2, 12:00 – 1:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 0), getFeb2015InMillis(2, 1), true, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 0), getFebOfThisYearInMillis(2, 1), true, DateUtils.FORMAT_12HOUR)); assertEquals("2/2, 00:00 – 01:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 0), getFeb2015InMillis(2, 1), true, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 0), getFebOfThisYearInMillis(2, 1), true, DateUtils.FORMAT_24HOUR)); } public void testEndOfDay() { for (boolean useShortFormat : PARAM_USE_SHORT_FORMAT) { assertEquals("11:00 PM – 12:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 23), getFeb2015InMillis(2, 0), useShortFormat, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 23), getFebOfThisYearInMillis(2, 0), + useShortFormat, DateUtils.FORMAT_12HOUR)); assertEquals("23:00 – 00:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(1, 23), getFeb2015InMillis(2, 0), useShortFormat, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(1, 23), getFebOfThisYearInMillis(2, 0), + useShortFormat, DateUtils.FORMAT_24HOUR)); } assertEquals("Feb 2, 11:00 PM – 12:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 23), getFeb2015InMillis(3, 0), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 23), getFebOfThisYearInMillis(3, 0), false, DateUtils.FORMAT_12HOUR)); assertEquals("Feb 2, 23:00 – 00:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 23), getFeb2015InMillis(3, 0), false, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 23), getFebOfThisYearInMillis(3, 0), false, DateUtils.FORMAT_24HOUR)); assertEquals("2/2, 11:00 PM – 12:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 23), getFeb2015InMillis(3, 0), true, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 23), getFebOfThisYearInMillis(3, 0), true, DateUtils.FORMAT_12HOUR)); assertEquals("2/2, 23:00 – 00:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - getFeb2015InMillis(2, 23), getFeb2015InMillis(3, 0), true, + Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + getFebOfThisYearInMillis(2, 23), getFebOfThisYearInMillis(3, 0), true, DateUtils.FORMAT_24HOUR)); } public void testMidnight() { for (boolean useShortFormat : PARAM_USE_SHORT_FORMAT) { - assertEquals("12:00 AM", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - DATE_2015_2_1_MS, DATE_2015_2_1_MS, useShortFormat, + assertEquals("12:00 AM", Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + DATE_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS, useShortFormat, DateUtils.FORMAT_12HOUR)); - assertEquals("00:00", - Utils.getDurationString(getContext(), DATE_2015_2_1_MS, - DATE_2015_2_1_MS, DATE_2015_2_1_MS, useShortFormat, + assertEquals("00:00", Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS, + DATE_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS, useShortFormat, DateUtils.FORMAT_24HOUR)); } } |