aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/src/com/android/tv/util
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/src/com/android/tv/util')
-rw-r--r--tests/unit/src/com/android/tv/util/MockTvSingletons.java (renamed from tests/unit/src/com/android/tv/util/MockApplicationSingletons.java)81
-rw-r--r--tests/unit/src/com/android/tv/util/MultiLongSparseArrayTest.java108
-rw-r--r--tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java59
-rw-r--r--tests/unit/src/com/android/tv/util/TestUtils.java115
-rw-r--r--tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java258
-rw-r--r--tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java52
-rw-r--r--tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java273
-rw-r--r--tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java94
-rw-r--r--tests/unit/src/com/android/tv/util/UtilsTest_IsInGivenDay.java68
-rw-r--r--tests/unit/src/com/android/tv/util/images/ImageCacheTest.java (renamed from tests/unit/src/com/android/tv/util/ImageCacheTest.java)43
-rw-r--r--tests/unit/src/com/android/tv/util/images/ScaledBitmapInfoTest.java79
11 files changed, 381 insertions, 849 deletions
diff --git a/tests/unit/src/com/android/tv/util/MockApplicationSingletons.java b/tests/unit/src/com/android/tv/util/MockTvSingletons.java
index 4cfc7f8a..6de1eb3e 100644
--- a/tests/unit/src/com/android/tv/util/MockApplicationSingletons.java
+++ b/tests/unit/src/com/android/tv/util/MockTvSingletons.java
@@ -17,34 +17,41 @@
package com.android.tv.util;
import android.content.Context;
-
-import com.android.tv.ApplicationSingletons;
+import android.content.Intent;
import com.android.tv.InputSessionManager;
import com.android.tv.MainActivityWrapper;
import com.android.tv.TvApplication;
+import com.android.tv.TvSingletons;
import com.android.tv.analytics.Analytics;
import com.android.tv.analytics.Tracker;
-import com.android.tv.config.RemoteConfig;
+import com.android.tv.common.config.api.RemoteConfig;
+import com.android.tv.common.experiments.ExperimentLoader;
+import com.android.tv.common.recording.RecordingStorageStatusManager;
+import com.android.tv.common.util.Clock;
import com.android.tv.data.ChannelDataManager;
import com.android.tv.data.PreviewDataManager;
import com.android.tv.data.ProgramDataManager;
+import com.android.tv.data.epg.EpgFetcher;
+import com.android.tv.data.epg.EpgReader;
import com.android.tv.dvr.DvrDataManager;
import com.android.tv.dvr.DvrManager;
import com.android.tv.dvr.DvrScheduleManager;
-import com.android.tv.dvr.DvrStorageStatusManager;
import com.android.tv.dvr.DvrWatchedPositionManager;
import com.android.tv.dvr.recorder.RecordingScheduler;
import com.android.tv.perf.PerformanceMonitor;
+import com.android.tv.testing.FakeClock;
+import com.android.tv.tuner.TunerInputController;
+import java.util.concurrent.Executor;
+import javax.inject.Provider;
-/**
- * Mock {@link ApplicationSingletons} class.
- */
-public class MockApplicationSingletons implements ApplicationSingletons {
- private final TvApplication mApp;
+/** Mock {@link TvSingletons} class. */
+public class MockTvSingletons implements TvSingletons {
+ public final FakeClock fakeClock = FakeClock.createWithCurrentTime();
+ private final TvApplication mApp;
private PerformanceMonitor mPerformanceMonitor;
- public MockApplicationSingletons(Context context) {
+ public MockTvSingletons(Context context) {
mApp = (TvApplication) context.getApplicationContext();
}
@@ -54,6 +61,9 @@ public class MockApplicationSingletons implements ApplicationSingletons {
}
@Override
+ public void handleInputCountChanged() {}
+
+ @Override
public ChannelDataManager getChannelDataManager() {
return mApp.getChannelDataManager();
}
@@ -84,8 +94,13 @@ public class MockApplicationSingletons implements ApplicationSingletons {
}
@Override
- public DvrStorageStatusManager getDvrStorageStatusManager() {
- return mApp.getDvrStorageStatusManager();
+ public Clock getClock() {
+ return fakeClock;
+ }
+
+ @Override
+ public RecordingStorageStatusManager getRecordingStorageStatusManager() {
+ return mApp.getRecordingStorageStatusManager();
}
@Override
@@ -124,12 +139,37 @@ public class MockApplicationSingletons implements ApplicationSingletons {
}
@Override
+ public Provider<EpgReader> providesEpgReader() {
+ return mApp.providesEpgReader();
+ }
+
+ @Override
+ public EpgFetcher getEpgFetcher() {
+ return mApp.getEpgFetcher();
+ }
+
+ @Override
+ public SetupUtils getSetupUtils() {
+ return mApp.getSetupUtils();
+ }
+
+ @Override
+ public TunerInputController getTunerInputController() {
+ return mApp.getTunerInputController();
+ }
+
+ @Override
+ public ExperimentLoader getExperimentLoader() {
+ return mApp.getExperimentLoader();
+ }
+
+ @Override
public MainActivityWrapper getMainActivityWrapper() {
return mApp.getMainActivityWrapper();
}
@Override
- public AccountHelper getAccountHelper() {
+ public com.android.tv.util.account.AccountHelper getAccountHelper() {
return mApp.getAccountHelper();
}
@@ -139,6 +179,11 @@ public class MockApplicationSingletons implements ApplicationSingletons {
}
@Override
+ public Intent getTunerSetupIntent(Context context) {
+ return mApp.getTunerSetupIntent(context);
+ }
+
+ @Override
public boolean isRunningInMainProcess() {
return mApp.isRunningInMainProcess();
}
@@ -151,4 +196,14 @@ public class MockApplicationSingletons implements ApplicationSingletons {
public void setPerformanceMonitor(PerformanceMonitor performanceMonitor) {
mPerformanceMonitor = performanceMonitor;
}
+
+ @Override
+ public String getEmbeddedTunerInputId() {
+ return "com.android.tv/.tuner.tvinput.LiveTvTunerTvInputService";
+ }
+
+ @Override
+ public Executor getDbExecutor() {
+ return mApp.getDbExecutor();
+ }
}
diff --git a/tests/unit/src/com/android/tv/util/MultiLongSparseArrayTest.java b/tests/unit/src/com/android/tv/util/MultiLongSparseArrayTest.java
deleted file mode 100644
index 7335f207..00000000
--- a/tests/unit/src/com/android/tv/util/MultiLongSparseArrayTest.java
+++ /dev/null
@@ -1,108 +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.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-
-import android.support.test.filters.SmallTest;
-import android.test.MoreAsserts;
-
-import org.junit.Test;
-
-import java.util.Collections;
-
-/**
- * Tests for {@link MultiLongSparseArray}.
- */
-@SmallTest
-public class MultiLongSparseArrayTest {
- @Test
- public void testEmpty() {
- MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
- assertSame(Collections.EMPTY_SET, sparseArray.get(0));
- }
-
- @Test
- public void testOneElement() {
- MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
- sparseArray.put(0, "foo");
- MoreAsserts.assertContentsInAnyOrder(sparseArray.get(0), "foo");
- }
-
- @Test
- public void testTwoElements() {
- MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
- sparseArray.put(0, "foo");
- sparseArray.put(0, "bar");
- MoreAsserts.assertContentsInAnyOrder(sparseArray.get(0), "foo", "bar");
- }
-
-
- @Test
- public void testClearEmptyCache() {
- MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
- sparseArray.clearEmptyCache();
- assertEquals(0, sparseArray.getEmptyCacheSize());
- sparseArray.put(0, "foo");
- sparseArray.remove(0, "foo");
- assertEquals(1, sparseArray.getEmptyCacheSize());
- sparseArray.clearEmptyCache();
- assertEquals(0, sparseArray.getEmptyCacheSize());
- }
-
- @Test
- public void testMaxEmptyCacheSize() {
- MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
- sparseArray.clearEmptyCache();
- assertEquals(0, sparseArray.getEmptyCacheSize());
- for (int i = 0; i <= MultiLongSparseArray.DEFAULT_MAX_EMPTIES_KEPT + 2; i++) {
- sparseArray.put(i, "foo");
- }
- for (int i = 0; i <= MultiLongSparseArray.DEFAULT_MAX_EMPTIES_KEPT + 2; i++) {
- sparseArray.remove(i, "foo");
- }
- assertEquals(MultiLongSparseArray.DEFAULT_MAX_EMPTIES_KEPT,
- sparseArray.getEmptyCacheSize());
- sparseArray.clearEmptyCache();
- assertEquals(0, sparseArray.getEmptyCacheSize());
- }
-
- @Test
- public void testReuseEmptySets() {
- MultiLongSparseArray<String> sparseArray = new MultiLongSparseArray<>();
- sparseArray.clearEmptyCache();
- assertEquals(0, sparseArray.getEmptyCacheSize());
- // create a bunch of sets
- for (int i = 0; i <= MultiLongSparseArray.DEFAULT_MAX_EMPTIES_KEPT + 2; i++) {
- sparseArray.put(i, "foo");
- }
- // remove them so they are all put in the cache.
- for (int i = 0; i <= MultiLongSparseArray.DEFAULT_MAX_EMPTIES_KEPT + 2; i++) {
- sparseArray.remove(i, "foo");
- }
- assertEquals(MultiLongSparseArray.DEFAULT_MAX_EMPTIES_KEPT,
- sparseArray.getEmptyCacheSize());
-
- // now create elements, that use the cached empty sets.
- for (int i = 0; i < MultiLongSparseArray.DEFAULT_MAX_EMPTIES_KEPT; i++) {
- sparseArray.put(10 + i, "bar");
- assertEquals(MultiLongSparseArray.DEFAULT_MAX_EMPTIES_KEPT - i - 1,
- sparseArray.getEmptyCacheSize());
- }
- }
-}
diff --git a/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java b/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java
deleted file mode 100644
index 2714e2e9..00000000
--- a/tests/unit/src/com/android/tv/util/ScaledBitmapInfoTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.android.tv.util;
-
-import static org.junit.Assert.assertEquals;
-
-import android.graphics.Bitmap;
-import android.support.test.filters.SmallTest;
-
-import com.android.tv.util.BitmapUtils.ScaledBitmapInfo;
-
-import org.junit.Test;
-
-/**
- * Tests for {@link ScaledBitmapInfo}.
- */
-@SmallTest
-public class ScaledBitmapInfoTest {
- private static final Bitmap B80x100 = Bitmap.createBitmap(80, 100, Bitmap.Config.RGB_565);
- private static final Bitmap B960x1440 = Bitmap.createBitmap(960, 1440, Bitmap.Config.RGB_565);
-
- @Test
- public void testSize_B100x100to50x50() {
- ScaledBitmapInfo actual = BitmapUtils.createScaledBitmapInfo("B80x100", B80x100, 50, 50);
- assertScaledBitmapSize(2, 40, 50, actual);
- }
-
- @Test
- public void testNeedsToReload_B100x100to50x50() {
- ScaledBitmapInfo actual = BitmapUtils.createScaledBitmapInfo("B80x100", B80x100, 50, 50);
- assertNeedsToReload(false, actual, 25, 25);
- assertNeedsToReload(false, actual, 50, 50);
- assertNeedsToReload(false, actual, 99, 99);
- assertNeedsToReload(true, actual, 100, 100);
- assertNeedsToReload(true, actual, 101, 101);
- }
-
- /**
- * Reproduces <a href="http://b/20488453">b/20488453</a>.
- */
- @Test
- public void testBug20488453() {
- ScaledBitmapInfo actual = BitmapUtils
- .createScaledBitmapInfo("B960x1440", B960x1440, 284, 160);
- assertScaledBitmapSize(8, 107, 160, actual);
- assertNeedsToReload(false, actual, 284, 160);
- }
-
- private static void assertNeedsToReload(boolean expected, ScaledBitmapInfo scaledBitmap,
- int reqWidth, int reqHeight) {
- assertEquals(scaledBitmap.id + " needToReload(" + reqWidth + "," + reqHeight + ")",
- expected, scaledBitmap.needToReload(reqWidth, reqHeight));
- }
-
- private static void assertScaledBitmapSize(int expectedInSampleSize, int expectedWidth,
- int expectedHeight, ScaledBitmapInfo actual) {
- assertEquals(actual.id + " inSampleSize", expectedInSampleSize, actual.inSampleSize);
- assertEquals(actual.id + " width", expectedWidth, actual.bitmap.getWidth());
- assertEquals(actual.id + " height", expectedHeight, actual.bitmap.getHeight());
- }
-}
diff --git a/tests/unit/src/com/android/tv/util/TestUtils.java b/tests/unit/src/com/android/tv/util/TestUtils.java
deleted file mode 100644
index d200733d..00000000
--- a/tests/unit/src/com/android/tv/util/TestUtils.java
+++ /dev/null
@@ -1,115 +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.util;
-
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.graphics.drawable.Icon;
-import android.hardware.hdmi.HdmiDeviceInfo;
-import android.media.tv.TvInputInfo;
-import android.os.Build;
-import android.os.Bundle;
-
-import java.lang.reflect.Constructor;
-
-/**
- * A class that includes convenience methods for testing.
- */
-public class TestUtils {
- /**
- * Creates a {@link TvInputInfo}.
- */
- public static TvInputInfo createTvInputInfo(ResolveInfo service, String id, String parentId,
- int type, boolean isHardwareInput) throws Exception {
- return createTvInputInfo(service, id, parentId, type, isHardwareInput, false, 0);
- }
-
- /**
- * Creates a {@link TvInputInfo}.
- * <p>
- * If this is called on MNC, {@code canRecord} and {@code tunerCount} are ignored.
- */
- public static TvInputInfo createTvInputInfo(ResolveInfo service, String id, String parentId,
- int type, boolean isHardwareInput, boolean canRecord, int tunerCount) throws Exception {
- // Create a mock TvInputInfo by using private constructor
- // Note that mockito doesn't support mock/spy on final object.
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- return createTvInputInfoForO(service, id, parentId, type, isHardwareInput, canRecord,
- tunerCount);
-
- } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- return createTvInputInfoForNyc(service, id, parentId, type, isHardwareInput, canRecord,
- tunerCount);
- }
- return createTvInputInfoForMnc(service, id, parentId, type, isHardwareInput);
- }
-
- /**
- * private TvInputInfo(ResolveInfo service, String id, int type, boolean isHardwareInput,
- * CharSequence label, int labelResId, Icon icon, Icon iconStandby, Icon iconDisconnected,
- * String setupActivity, boolean canRecord, int tunerCount, HdmiDeviceInfo hdmiDeviceInfo,
- * boolean isConnectedToHdmiSwitch, String parentId, Bundle extras) {
- */
- private static TvInputInfo createTvInputInfoForO(ResolveInfo service, String id,
- String parentId, int type, boolean isHardwareInput, boolean canRecord, int tunerCount)
- throws Exception {
- Constructor<TvInputInfo> constructor = TvInputInfo.class.getDeclaredConstructor(
- ResolveInfo.class, String.class, int.class, boolean.class, CharSequence.class,
- int.class, Icon.class, Icon.class, Icon.class, String.class, boolean.class,
- int.class, HdmiDeviceInfo.class, boolean.class, String.class, Bundle.class);
- constructor.setAccessible(true);
- return constructor.newInstance(service, id, type, isHardwareInput, null, 0, null, null,
- null, null, canRecord, tunerCount, null, false, parentId, null);
- }
-
- /**
- * private TvInputInfo(ResolveInfo service, String id, int type, boolean isHardwareInput,
- * CharSequence label, int labelResId, Icon icon, Icon iconStandby, Icon iconDisconnected,
- * String setupActivity, String settingsActivity, boolean canRecord, int tunerCount,
- * HdmiDeviceInfo hdmiDeviceInfo, boolean isConnectedToHdmiSwitch, String parentId,
- * Bundle extras) {
- */
- private static TvInputInfo createTvInputInfoForNyc(ResolveInfo service, String id,
- String parentId, int type, boolean isHardwareInput, boolean canRecord, int tunerCount)
- throws Exception {
- Constructor<TvInputInfo> constructor = TvInputInfo.class.getDeclaredConstructor(
- ResolveInfo.class, String.class, int.class, boolean.class, CharSequence.class,
- int.class, Icon.class, Icon.class, Icon.class, String.class, String.class,
- boolean.class, int.class, HdmiDeviceInfo.class, boolean.class, String.class,
- Bundle.class);
- constructor.setAccessible(true);
- return constructor.newInstance(service, id, type, isHardwareInput, null, 0, null, null,
- null, null, null, canRecord, tunerCount, null, false, parentId, null);
- }
-
- private static TvInputInfo createTvInputInfoForMnc(ResolveInfo service, String id,
- String parentId, int type, boolean isHardwareInput) throws Exception {
- Constructor<TvInputInfo> constructor = TvInputInfo.class.getDeclaredConstructor(
- ResolveInfo.class, String.class, String.class, int.class, boolean.class);
- constructor.setAccessible(true);
- return constructor.newInstance(service, id, parentId, type, isHardwareInput);
- }
-
- public static ResolveInfo createResolveInfo(String packageName, String name) {
- ResolveInfo resolveInfo = new ResolveInfo();
- resolveInfo.serviceInfo = new ServiceInfo();
- resolveInfo.serviceInfo.packageName = packageName;
- resolveInfo.serviceInfo.name = name;
- resolveInfo.serviceInfo.metaData = new Bundle();
- return resolveInfo;
- }
-}
diff --git a/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java b/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java
index 404ee5d3..6dfed64a 100644
--- a/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java
+++ b/tests/unit/src/com/android/tv/util/TvInputManagerHelperTest.java
@@ -21,22 +21,21 @@ import static android.support.test.InstrumentationRegistry.getContext;
import android.content.pm.ResolveInfo;
import android.media.tv.TvInputInfo;
import android.support.test.filters.SmallTest;
-
+import android.support.test.runner.AndroidJUnit4;
import com.android.tv.testing.ComparatorTester;
-
+import com.android.tv.testing.utils.TestUtils;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-/**
- * Test for {@link TvInputManagerHelper}
- */
+/** Test for {@link TvInputManagerHelper} */
@SmallTest
+@RunWith(AndroidJUnit4.class)
public class TvInputManagerHelperTest {
final HashMap<String, TvInputInfoWrapper> TEST_INPUT_MAP = new HashMap<>();
@@ -45,18 +44,51 @@ public class TvInputManagerHelperTest {
ResolveInfo resolveInfo = TestUtils.createResolveInfo("test", "test");
List<TvInputInfo> inputs = new ArrayList<>();
- inputs.add(createTvInputInfo(resolveInfo, "2_partner_input", null, 0, false,
- "2_partner_input", null, true));
- inputs.add(createTvInputInfo(resolveInfo, "3_partner_input", null, 0, false,
- "3_partner_input", null, true));
- inputs.add(createTvInputInfo(resolveInfo, "1_3rd_party_input", null, 0, false,
- "1_3rd_party_input", null, false));
- inputs.add(createTvInputInfo(resolveInfo, "4_3rd_party_input", null, 0, false,
- "4_3rd_party_input", null, false));
+ inputs.add(
+ createTvInputInfo(
+ resolveInfo,
+ "2_partner_input",
+ null,
+ 0,
+ false,
+ "2_partner_input",
+ null,
+ true));
+ inputs.add(
+ createTvInputInfo(
+ resolveInfo,
+ "3_partner_input",
+ null,
+ 0,
+ false,
+ "3_partner_input",
+ null,
+ true));
+ inputs.add(
+ createTvInputInfo(
+ resolveInfo,
+ "1_3rd_party_input",
+ null,
+ 0,
+ false,
+ "1_3rd_party_input",
+ null,
+ false));
+ inputs.add(
+ createTvInputInfo(
+ resolveInfo,
+ "4_3rd_party_input",
+ null,
+ 0,
+ false,
+ "4_3rd_party_input",
+ null,
+ false));
TvInputManagerHelper manager = createMockTvInputManager();
- ComparatorTester<TvInputInfo> comparatorTester = ComparatorTester.withoutEqualsTest(
+ ComparatorTester<TvInputInfo> comparatorTester =
+ ComparatorTester.withoutEqualsTest(
new TvInputManagerHelper.InputComparatorInternal(manager));
for (TvInputInfo input : inputs) {
comparatorTester.addComparableGroup(input);
@@ -68,20 +100,54 @@ public class TvInputManagerHelperTest {
public void testHardwareInputComparatorHdmi() {
ResolveInfo resolveInfo = TestUtils.createResolveInfo("test", "test");
- TvInputInfo hdmi1 = createTvInputInfo(resolveInfo, "HDMI1", null, TvInputInfo.TYPE_HDMI,
- true, "HDMI1", null, false);
- TvInputInfo hdmi2 = createTvInputInfo(resolveInfo, "HDMI2", null, TvInputInfo.TYPE_HDMI,
- true, "HDMI2", "DVD", false);
- TvInputInfo hdmi3 = createTvInputInfo(resolveInfo, "HDMI3", null, TvInputInfo.TYPE_HDMI,
- true, "HDMI3", "Cable", false);
- TvInputInfo hdmi4 = createTvInputInfo(resolveInfo, "HDMI4", null, TvInputInfo.TYPE_HDMI,
- true, "HDMI4", null, false);
+ TvInputInfo hdmi1 =
+ createTvInputInfo(
+ resolveInfo,
+ "HDMI1",
+ null,
+ TvInputInfo.TYPE_HDMI,
+ true,
+ "HDMI1",
+ null,
+ false);
+ TvInputInfo hdmi2 =
+ createTvInputInfo(
+ resolveInfo,
+ "HDMI2",
+ null,
+ TvInputInfo.TYPE_HDMI,
+ true,
+ "HDMI2",
+ "DVD",
+ false);
+ TvInputInfo hdmi3 =
+ createTvInputInfo(
+ resolveInfo,
+ "HDMI3",
+ null,
+ TvInputInfo.TYPE_HDMI,
+ true,
+ "HDMI3",
+ "Cable",
+ false);
+ TvInputInfo hdmi4 =
+ createTvInputInfo(
+ resolveInfo,
+ "HDMI4",
+ null,
+ TvInputInfo.TYPE_HDMI,
+ true,
+ "HDMI4",
+ null,
+ false);
TvInputManagerHelper manager = createMockTvInputManager();
- ComparatorTester<TvInputInfo> comparatorTester = ComparatorTester.withoutEqualsTest(
+ ComparatorTester<TvInputInfo> comparatorTester =
+ ComparatorTester.withoutEqualsTest(
new TvInputManagerHelper.HardwareInputComparator(getContext(), manager));
- comparatorTester.addComparableGroup(hdmi3)
+ comparatorTester
+ .addComparableGroup(hdmi3)
.addComparableGroup(hdmi2)
.addComparableGroup(hdmi1)
.addComparableGroup(hdmi4)
@@ -92,61 +158,111 @@ public class TvInputManagerHelperTest {
public void testHardwareInputComparatorCec() {
ResolveInfo resolveInfo = TestUtils.createResolveInfo("test", "test");
- TvInputInfo hdmi1 = createTvInputInfo(resolveInfo, "HDMI1", null, TvInputInfo.TYPE_HDMI,
- true, "HDMI1", null, false);
- TvInputInfo hdmi2 = createTvInputInfo(resolveInfo, "HDMI2", null, TvInputInfo.TYPE_HDMI,
- true, "HDMI2", null, false);
+ TvInputInfo hdmi1 =
+ createTvInputInfo(
+ resolveInfo,
+ "HDMI1",
+ null,
+ TvInputInfo.TYPE_HDMI,
+ true,
+ "HDMI1",
+ null,
+ false);
+ TvInputInfo hdmi2 =
+ createTvInputInfo(
+ resolveInfo,
+ "HDMI2",
+ null,
+ TvInputInfo.TYPE_HDMI,
+ true,
+ "HDMI2",
+ null,
+ false);
- TvInputInfo cec1 = createTvInputInfo(resolveInfo, "2_cec", "HDMI1", TvInputInfo.TYPE_HDMI,
- true, "2_cec", null, false);
- TvInputInfo cec2 = createTvInputInfo(resolveInfo, "1_cec", "HDMI2", TvInputInfo.TYPE_HDMI,
- true, "1_cec", null, false);
+ TvInputInfo cec1 =
+ createTvInputInfo(
+ resolveInfo,
+ "2_cec",
+ "HDMI1",
+ TvInputInfo.TYPE_HDMI,
+ true,
+ "2_cec",
+ null,
+ false);
+ TvInputInfo cec2 =
+ createTvInputInfo(
+ resolveInfo,
+ "1_cec",
+ "HDMI2",
+ TvInputInfo.TYPE_HDMI,
+ true,
+ "1_cec",
+ null,
+ false);
TvInputManagerHelper manager = createMockTvInputManager();
- ComparatorTester<TvInputInfo> comparatorTester = ComparatorTester.withoutEqualsTest(
+ ComparatorTester<TvInputInfo> comparatorTester =
+ ComparatorTester.withoutEqualsTest(
new TvInputManagerHelper.HardwareInputComparator(getContext(), manager));
- comparatorTester.addComparableGroup(cec1)
- .addComparableGroup(cec2)
- .test();
+ comparatorTester.addComparableGroup(cec1).addComparableGroup(cec2).test();
}
private TvInputManagerHelper createMockTvInputManager() {
TvInputManagerHelper manager = Mockito.mock(TvInputManagerHelper.class);
- Mockito.doAnswer(new Answer<Boolean>() {
- @Override
- public Boolean answer(InvocationOnMock invocation) throws Throwable {
- TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
- return TEST_INPUT_MAP.get(info.getId()).mIsPartnerInput;
- }
- }).when(manager).isPartnerInput(Mockito.<TvInputInfo>any());
- Mockito.doAnswer(new Answer<String>() {
- @Override
- public String answer(InvocationOnMock invocation) throws Throwable {
- TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
- return TEST_INPUT_MAP.get(info.getId()).mLabel;
- }
- }).when(manager).loadLabel(Mockito.<TvInputInfo>any());
- Mockito.doAnswer(new Answer<String>() {
- @Override
- public String answer(InvocationOnMock invocation) throws Throwable {
- TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
- return TEST_INPUT_MAP.get(info.getId()).mCustomLabel;
- }
- }).when(manager).loadCustomLabel(Mockito.<TvInputInfo>any());
- Mockito.doAnswer(new Answer<TvInputInfo>() {
- @Override
- public TvInputInfo answer(InvocationOnMock invocation) throws Throwable {
- String inputId = (String) invocation.getArguments()[0];
- TvInputInfoWrapper inputWrapper = TEST_INPUT_MAP.get(inputId);
- return inputWrapper == null ? null : inputWrapper.mInput;
- }
- }).when(manager).getTvInputInfo(Mockito.<String>any());
+ Mockito.doAnswer(
+ new Answer<Boolean>() {
+ @Override
+ public Boolean answer(InvocationOnMock invocation) throws Throwable {
+ TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
+ return TEST_INPUT_MAP.get(info.getId()).mIsPartnerInput;
+ }
+ })
+ .when(manager)
+ .isPartnerInput(Mockito.<TvInputInfo>any());
+ Mockito.doAnswer(
+ new Answer<String>() {
+ @Override
+ public String answer(InvocationOnMock invocation) throws Throwable {
+ TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
+ return TEST_INPUT_MAP.get(info.getId()).mLabel;
+ }
+ })
+ .when(manager)
+ .loadLabel(Mockito.<TvInputInfo>any());
+ Mockito.doAnswer(
+ new Answer<String>() {
+ @Override
+ public String answer(InvocationOnMock invocation) throws Throwable {
+ TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
+ return TEST_INPUT_MAP.get(info.getId()).mCustomLabel;
+ }
+ })
+ .when(manager)
+ .loadCustomLabel(Mockito.<TvInputInfo>any());
+ Mockito.doAnswer(
+ new Answer<TvInputInfo>() {
+ @Override
+ public TvInputInfo answer(InvocationOnMock invocation)
+ throws Throwable {
+ String inputId = (String) invocation.getArguments()[0];
+ TvInputInfoWrapper inputWrapper = TEST_INPUT_MAP.get(inputId);
+ return inputWrapper == null ? null : inputWrapper.mInput;
+ }
+ })
+ .when(manager)
+ .getTvInputInfo(Mockito.<String>any());
return manager;
}
- private TvInputInfo createTvInputInfo(ResolveInfo service, String id,
- String parentId, int type, boolean isHardwareInput, String label, String customLabel,
+ private TvInputInfo createTvInputInfo(
+ ResolveInfo service,
+ String id,
+ String parentId,
+ int type,
+ boolean isHardwareInput,
+ String label,
+ String customLabel,
boolean isPartnerInput) {
TvInputInfoWrapper inputWrapper = new TvInputInfoWrapper();
try {
diff --git a/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java b/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java
index 4512bb7d..d84a90d4 100644
--- a/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java
+++ b/tests/unit/src/com/android/tv/util/TvTrackInfoUtilsTest.java
@@ -16,24 +16,22 @@
package com.android.tv.util;
import static com.android.tv.util.TvTrackInfoUtils.getBestTrackInfo;
-import static org.junit.Assert.assertEquals;
+import static com.google.common.truth.Truth.assertWithMessage;
import android.media.tv.TvTrackInfo;
import android.support.test.filters.SmallTest;
-
+import android.support.test.runner.AndroidJUnit4;
import com.android.tv.testing.ComparatorTester;
-
-import org.junit.Test;
-
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
-/**
- * Tests for {@link com.android.tv.util.TvTrackInfoUtils}.
- */
+/** Tests for {@link com.android.tv.util.TvTrackInfoUtils}. */
@SmallTest
+@RunWith(AndroidJUnit4.class)
public class TvTrackInfoUtilsTest {
private static final String UN_MATCHED_ID = "no matching ID";
@@ -54,57 +52,57 @@ public class TvTrackInfoUtilsTest {
.build();
}
- private static final List<TvTrackInfo> ALL = Arrays.asList(INFO_1_EN_1, INFO_2_EN_5,
- INFO_3_FR_8, INFO_4_NULL_2, INFO_5_NULL_6);
- private static final List<TvTrackInfo> NULL_LANGUAGE_TRACKS = Arrays.asList(INFO_4_NULL_2,
- INFO_5_NULL_6);
+ private static final List<TvTrackInfo> ALL =
+ Arrays.asList(INFO_1_EN_1, INFO_2_EN_5, INFO_3_FR_8, INFO_4_NULL_2, INFO_5_NULL_6);
+ private static final List<TvTrackInfo> NULL_LANGUAGE_TRACKS =
+ Arrays.asList(INFO_4_NULL_2, INFO_5_NULL_6);
@Test
public void testGetBestTrackInfo_empty() {
TvTrackInfo result = getBestTrackInfo(Collections.emptyList(), UN_MATCHED_ID, "en", 1);
- assertEquals("best track ", null, result);
+ assertWithMessage("best track ").that(result).isEqualTo(null);
}
@Test
public void testGetBestTrackInfo_exactMatch() {
TvTrackInfo result = getBestTrackInfo(ALL, "1", "en", 1);
- assertEquals("best track ", INFO_1_EN_1, result);
+ assertWithMessage("best track ").that(result).isEqualTo(INFO_1_EN_1);
}
@Test
public void testGetBestTrackInfo_langAndChannelCountMatch() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "en", 5);
- assertEquals("best track ", INFO_2_EN_5, result);
+ assertWithMessage("best track ").that(result).isEqualTo(INFO_2_EN_5);
}
@Test
public void testGetBestTrackInfo_languageOnlyMatch() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "fr", 1);
- assertEquals("best track ", INFO_3_FR_8, result);
+ assertWithMessage("best track ").that(result).isEqualTo(INFO_3_FR_8);
}
@Test
public void testGetBestTrackInfo_channelCountOnlyMatchWithNullLanguage() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, null, 8);
- assertEquals("best track ", INFO_3_FR_8, result);
+ assertWithMessage("best track ").that(result).isEqualTo(INFO_3_FR_8);
}
@Test
public void testGetBestTrackInfo_noMatches() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, "kr", 1);
- assertEquals("best track ", INFO_1_EN_1, result);
+ assertWithMessage("best track ").that(result).isEqualTo(INFO_1_EN_1);
}
@Test
public void testGetBestTrackInfo_noMatchesWithNullLanguage() {
TvTrackInfo result = getBestTrackInfo(ALL, UN_MATCHED_ID, null, 0);
- assertEquals("best track ", INFO_1_EN_1, result);
+ assertWithMessage("best track ").that(result).isEqualTo(INFO_1_EN_1);
}
@Test
public void testGetBestTrackInfo_channelCountAndIdMatch() {
TvTrackInfo result = getBestTrackInfo(NULL_LANGUAGE_TRACKS, "5", null, 6);
- assertEquals("best track ", INFO_5_NULL_6, result);
+ assertWithMessage("best track ").that(result).isEqualTo(INFO_5_NULL_6);
}
@Test
@@ -112,15 +110,17 @@ public class TvTrackInfoUtilsTest {
Comparator<TvTrackInfo> comparator = TvTrackInfoUtils.createComparator("1", "en", 1);
ComparatorTester.withoutEqualsTest(comparator)
// lang not match
- .addComparableGroup(create("1", "kr", 1), create("2", "kr", 2),
+ .addComparableGroup(
+ create("1", "kr", 1),
+ create("2", "kr", 2),
create("1", "ja", 1),
create("1", "ch", 1))
- // lang match not count match
- .addComparableGroup(create("2", "en", 2), create("3", "en", 3),
- create("1", "en", 2))
- // lang and count match
+ // lang match not count match
+ .addComparableGroup(
+ create("2", "en", 2), create("3", "en", 3), create("1", "en", 2))
+ // lang and count match
.addComparableGroup(create("2", "en", 1), create("3", "en", 1))
- // all match
+ // all match
.addComparableGroup(create("1", "en", 1), create("1", "en", 1))
.test();
}
diff --git a/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java b/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java
deleted file mode 100644
index e61802f5..00000000
--- a/tests/unit/src/com/android/tv/util/UtilsTest_GetDurationString.java
+++ /dev/null
@@ -1,273 +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.util;
-
-import static android.support.test.InstrumentationRegistry.getContext;
-import static org.junit.Assert.assertEquals;
-
-import android.support.test.filters.SmallTest;
-import android.text.format.DateUtils;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-
-/**
- * Tests for {@link com.android.tv.util.Utils#getDurationString}.
- * <p/>
- * This test uses deprecated flags {@link DateUtils#FORMAT_12HOUR} and
- * {@link DateUtils#FORMAT_24HOUR} to run this test independent to system's 12/24h format.
- * Note that changing system setting requires permission android.permission.WRITE_SETTINGS
- * and it should be defined in TV app, not this test.
- */
-@SmallTest
-public class UtilsTest_GetDurationString {
- // TODO: Mock Context so we can specify current time and locale for test.
- private Locale mLocale;
- private static final long DATE_THIS_YEAR_2_1_MS = getFebOfThisYearInMillis(1, 0, 0);
-
- // All possible list for a parameter to test parameter independent result.
- private static final boolean[] PARAM_USE_SHORT_FORMAT = {false, true};
-
- @Before
- public void setUp() {
- // Set locale to US
- mLocale = Locale.getDefault();
- Locale.setDefault(Locale.US);
- }
-
- @After
- public void tearDown() {
- // Revive system locale.
- Locale.setDefault(mLocale);
- }
-
- /**
- * Return time in millis assuming that whose year is this year and month is Jan.
- */
- private static long getJanOfThisYearInMillis(int date, int hour, int minutes) {
- return new GregorianCalendar(getThisYear(), Calendar.JANUARY, date, hour, minutes)
- .getTimeInMillis();
- }
-
- private static long getJanOfThisYearInMillis(int date, int hour) {
- return getJanOfThisYearInMillis(date, hour, 0);
- }
-
- /**
- * Return time in millis assuming that whose year is this year and month is Feb.
- */
- private static long getFebOfThisYearInMillis(int date, int hour, int minutes) {
- return new GregorianCalendar(getThisYear(), Calendar.FEBRUARY, date, hour, minutes)
- .getTimeInMillis();
- }
-
- private static long getFebOfThisYearInMillis(int date, int hour) {
- return getFebOfThisYearInMillis(date, hour, 0);
- }
-
- private static int getThisYear() {
- return new GregorianCalendar().get(GregorianCalendar.YEAR);
- }
-
- @Test
- public void testSameDateAndTime() {
- 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_THIS_YEAR_2_1_MS,
- getFebOfThisYearInMillis(1, 3), getFebOfThisYearInMillis(1, 3), false,
- DateUtils.FORMAT_24HOUR));
- }
-
- @Test
- public void testDurationWithinToday() {
- assertEquals("12:00 – 3:00 AM",
- 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_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS,
- getFebOfThisYearInMillis(1, 3), false,
- DateUtils.FORMAT_24HOUR));
- }
-
- @Test
- public void testDurationFromYesterdayToToday() {
- assertEquals("Jan 31, 3:00 AM – Feb 1, 4:00 AM",
- 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_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_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_THIS_YEAR_2_1_MS,
- getJanOfThisYearInMillis(31, 23, 30), getFebOfThisYearInMillis(1, 0, 30),
- true, DateUtils.FORMAT_24HOUR));
- }
-
- @Test
- public void testDurationFromTodayToTomorrow() {
- assertEquals("Feb 1, 3:00 AM – Feb 2, 4:00 AM",
- 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_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_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_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_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_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_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_THIS_YEAR_2_1_MS,
- getFebOfThisYearInMillis(1, 23, 30), getFebOfThisYearInMillis(2, 0, 30),
- true,
- DateUtils.FORMAT_24HOUR));
- }
-
- @Test
- public void testDurationWithinTomorrow() {
- assertEquals("Feb 2, 2:00 – 4:00 AM",
- 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_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_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_THIS_YEAR_2_1_MS,
- getFebOfThisYearInMillis(2, 2), getFebOfThisYearInMillis(2, 4), true,
- DateUtils.FORMAT_24HOUR));
- }
-
- @Test
- public void testStartOfDay() {
- assertEquals("12:00 – 1:00 AM",
- 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_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_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_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_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_THIS_YEAR_2_1_MS,
- getFebOfThisYearInMillis(2, 0), getFebOfThisYearInMillis(2, 1), true,
- DateUtils.FORMAT_24HOUR));
- }
-
- @Test
- public void testEndOfDay() {
- for (boolean useShortFormat : PARAM_USE_SHORT_FORMAT) {
- assertEquals("11:00 PM – 12:00 AM",
- 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_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_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_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_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_THIS_YEAR_2_1_MS,
- getFebOfThisYearInMillis(2, 23), getFebOfThisYearInMillis(3, 0), true,
- DateUtils.FORMAT_24HOUR));
- assertEquals("2/2, 12:00 AM – 2/3, 12:00 AM",
- Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS,
- getFebOfThisYearInMillis(2, 0), getFebOfThisYearInMillis(3, 0), true,
- DateUtils.FORMAT_12HOUR));
- assertEquals("2/2, 00:00 – 2/3, 00:00",
- Utils.getDurationString(getContext(), DATE_THIS_YEAR_2_1_MS,
- getFebOfThisYearInMillis(2, 0), getFebOfThisYearInMillis(3, 0), true,
- DateUtils.FORMAT_24HOUR));
- }
-
- @Test
- public void testMidnight() {
- for (boolean useShortFormat : PARAM_USE_SHORT_FORMAT) {
- 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_THIS_YEAR_2_1_MS,
- DATE_THIS_YEAR_2_1_MS, DATE_THIS_YEAR_2_1_MS, useShortFormat,
- DateUtils.FORMAT_24HOUR));
- }
- }
-}
diff --git a/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java b/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java
deleted file mode 100644
index 1e75342b..00000000
--- a/tests/unit/src/com/android/tv/util/UtilsTest_GetMultiAudioString.java
+++ /dev/null
@@ -1,94 +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.util;
-
-import static android.support.test.InstrumentationRegistry.getTargetContext;
-import static org.junit.Assert.assertEquals;
-
-import android.content.Context;
-import android.media.tv.TvTrackInfo;
-import android.support.test.filters.SmallTest;
-
-import org.junit.Test;
-
-/**
- * Tests for {@link com.android.tv.util.Utils#getMultiAudioString}.
- */
-@SmallTest
-public class UtilsTest_GetMultiAudioString {
- private static final String TRACK_ID = "test_track_id";
- private static final int AUDIO_SAMPLE_RATE = 48000;
-
- @Test
- public void testAudioTrackLanguage() {
- Context context = getTargetContext();
- assertEquals("Korean",
- Utils.getMultiAudioString(context, createAudioTrackInfo("kor"), false));
- assertEquals("English",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng"), false));
- assertEquals("Unknown language",
- Utils.getMultiAudioString(context, createAudioTrackInfo(null), false));
- assertEquals("Unknown language",
- Utils.getMultiAudioString(context, createAudioTrackInfo(""), false));
- assertEquals("abc", Utils.getMultiAudioString(context, createAudioTrackInfo("abc"), false));
- }
-
- @Test
- public void testAudioTrackCount() {
- Context context = getTargetContext();
- assertEquals("English",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", -1), false));
- assertEquals("English",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 0), false));
- assertEquals("English (mono)",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 1), false));
- assertEquals("English (stereo)",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 2), false));
- assertEquals("English (3 channels)",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 3), false));
- assertEquals("English (4 channels)",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 4), false));
- assertEquals("English (5 channels)",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 5), false));
- assertEquals("English (5.1 surround)",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 6), false));
- assertEquals("English (7 channels)",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 7), false));
- assertEquals("English (7.1 surround)",
- Utils.getMultiAudioString(context, createAudioTrackInfo("eng", 8), false));
- }
-
- @Test
- public void testShowSampleRate() {
- assertEquals("Korean (48kHz)",
- Utils.getMultiAudioString(getTargetContext(),
- createAudioTrackInfo("kor", 0), true));
- assertEquals("Korean (7.1 surround, 48kHz)",
- Utils.getMultiAudioString(getTargetContext(),
- createAudioTrackInfo("kor", 8), true));
- }
-
- private static TvTrackInfo createAudioTrackInfo(String language) {
- return createAudioTrackInfo(language, 0);
- }
-
- private static TvTrackInfo createAudioTrackInfo(String language, int channelCount) {
- return new TvTrackInfo.Builder(TvTrackInfo.TYPE_AUDIO, TRACK_ID)
- .setLanguage(language).setAudioChannelCount(channelCount)
- .setAudioSampleRate(AUDIO_SAMPLE_RATE).build();
- }
-}
diff --git a/tests/unit/src/com/android/tv/util/UtilsTest_IsInGivenDay.java b/tests/unit/src/com/android/tv/util/UtilsTest_IsInGivenDay.java
deleted file mode 100644
index 2b43abc1..00000000
--- a/tests/unit/src/com/android/tv/util/UtilsTest_IsInGivenDay.java
+++ /dev/null
@@ -1,68 +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.util;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import android.support.test.filters.SmallTest;
-
-import org.junit.Test;
-
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
-
-/**
- * Tests for {@link com.android.tv.util.Utils#isInGivenDay}.
- */
-@SmallTest
-public class UtilsTest_IsInGivenDay {
- @Test
- public void testIsInGivenDay() {
- assertTrue(Utils.isInGivenDay(
- new GregorianCalendar(2015, Calendar.JANUARY, 1).getTimeInMillis(),
- new GregorianCalendar(2015, Calendar.JANUARY, 1, 0, 30).getTimeInMillis()));
- }
-
- @Test
- public void testIsNotInGivenDay() {
- assertFalse(Utils.isInGivenDay(
- new GregorianCalendar(2015, Calendar.JANUARY, 1).getTimeInMillis(),
- new GregorianCalendar(2015, Calendar.JANUARY, 2).getTimeInMillis()));
- }
-
- @Test
- public void testIfTimeZoneApplied() {
- TimeZone timeZone = TimeZone.getDefault();
-
- TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
-
- // 2015.01.01 00:00 in KST = 2014.12.31 15:00 in UTC
- long date2015StartMs =
- new GregorianCalendar(2015, Calendar.JANUARY, 1).getTimeInMillis();
-
- // 2015.01.01 10:00 in KST = 2015.01.01 01:00 in UTC
- long date2015Start10AMMs =
- new GregorianCalendar(2015, Calendar.JANUARY, 1, 10, 0).getTimeInMillis();
-
- // Those two times aren't in the same day in UTC, but they are in KST.
- assertTrue(Utils.isInGivenDay(date2015StartMs, date2015Start10AMMs));
-
- TimeZone.setDefault(timeZone);
- }
-}
diff --git a/tests/unit/src/com/android/tv/util/ImageCacheTest.java b/tests/unit/src/com/android/tv/util/images/ImageCacheTest.java
index a76194b8..b7715c4a 100644
--- a/tests/unit/src/com/android/tv/util/ImageCacheTest.java
+++ b/tests/unit/src/com/android/tv/util/images/ImageCacheTest.java
@@ -14,23 +14,22 @@
* limitations under the License.
*/
-package com.android.tv.util;
+package com.android.tv.util.images;
-import static com.android.tv.util.BitmapUtils.createScaledBitmapInfo;
-import static org.junit.Assert.assertSame;
+import static com.android.tv.util.images.BitmapUtils.createScaledBitmapInfo;
+import static com.google.common.truth.Truth.assertWithMessage;
import android.graphics.Bitmap;
import android.support.test.filters.MediumTest;
-
-import com.android.tv.util.BitmapUtils.ScaledBitmapInfo;
-
+import android.support.test.runner.AndroidJUnit4;
+import com.android.tv.util.images.BitmapUtils.ScaledBitmapInfo;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
-/**
- * Tests for {@link ImageCache}.
- */
+/** Tests for {@link ImageCache}. */
@MediumTest
+@RunWith(AndroidJUnit4.class)
public class ImageCacheTest {
private static final Bitmap ORIG = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
@@ -47,34 +46,34 @@ public class ImageCacheTest {
mImageCache = ImageCache.newInstance(0.1f);
}
- //TODO: Empty the cache in the setup. Try using @VisibleForTesting
+ // TODO: Empty the cache in the setup. Try using @VisibleForTesting
@Test
public void testPutIfLarger_smaller() throws Exception {
- mImageCache.putIfNeeded( INFO_50);
- assertSame("before", INFO_50, mImageCache.get(KEY));
+ mImageCache.putIfNeeded(INFO_50);
+ assertWithMessage("before").that(mImageCache.get(KEY)).isSameAs(INFO_50);
- mImageCache.putIfNeeded( INFO_25);
- assertSame("after", INFO_50, mImageCache.get(KEY));
+ mImageCache.putIfNeeded(INFO_25);
+ assertWithMessage("after").that(mImageCache.get(KEY)).isSameAs(INFO_50);
}
@Test
public void testPutIfLarger_larger() throws Exception {
- mImageCache.putIfNeeded( INFO_50);
- assertSame("before", INFO_50, mImageCache.get(KEY));
+ mImageCache.putIfNeeded(INFO_50);
+ assertWithMessage("before").that(mImageCache.get(KEY)).isSameAs(INFO_50);
mImageCache.putIfNeeded(INFO_100);
- assertSame("after", INFO_100, mImageCache.get(KEY));
+ assertWithMessage("after").that(mImageCache.get(KEY)).isSameAs(INFO_100);
}
@Test
public void testPutIfLarger_alreadyMax() throws Exception {
- mImageCache.putIfNeeded( INFO_100);
- assertSame("before", INFO_100, mImageCache.get(KEY));
+ mImageCache.putIfNeeded(INFO_100);
+ assertWithMessage("before").that(mImageCache.get(KEY)).isSameAs(INFO_100);
- mImageCache.putIfNeeded( INFO_200);
- assertSame("after", INFO_100, mImageCache.get(KEY));
+ mImageCache.putIfNeeded(INFO_200);
+ assertWithMessage("after").that(mImageCache.get(KEY)).isSameAs(INFO_100);
}
-} \ No newline at end of file
+}
diff --git a/tests/unit/src/com/android/tv/util/images/ScaledBitmapInfoTest.java b/tests/unit/src/com/android/tv/util/images/ScaledBitmapInfoTest.java
new file mode 100644
index 00000000..005775b6
--- /dev/null
+++ b/tests/unit/src/com/android/tv/util/images/ScaledBitmapInfoTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tv.util.images;
+
+import static com.google.common.truth.Truth.assertWithMessage;
+
+import android.graphics.Bitmap;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import com.android.tv.util.images.BitmapUtils.ScaledBitmapInfo;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/** Tests for {@link ScaledBitmapInfo}. */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class ScaledBitmapInfoTest {
+ private static final Bitmap B80x100 = Bitmap.createBitmap(80, 100, Bitmap.Config.RGB_565);
+ private static final Bitmap B960x1440 = Bitmap.createBitmap(960, 1440, Bitmap.Config.RGB_565);
+
+ @Test
+ public void testSize_B100x100to50x50() {
+ ScaledBitmapInfo actual = BitmapUtils.createScaledBitmapInfo("B80x100", B80x100, 50, 50);
+ assertScaledBitmapSize(2, 40, 50, actual);
+ }
+
+ @Test
+ public void testNeedsToReload_B100x100to50x50() {
+ ScaledBitmapInfo actual = BitmapUtils.createScaledBitmapInfo("B80x100", B80x100, 50, 50);
+ assertNeedsToReload(false, actual, 25, 25);
+ assertNeedsToReload(false, actual, 50, 50);
+ assertNeedsToReload(false, actual, 99, 99);
+ assertNeedsToReload(true, actual, 100, 100);
+ assertNeedsToReload(true, actual, 101, 101);
+ }
+
+ /** Reproduces <a href="http://b/20488453">b/20488453</a>. */
+ @Test
+ public void testBug20488453() {
+ ScaledBitmapInfo actual =
+ BitmapUtils.createScaledBitmapInfo("B960x1440", B960x1440, 284, 160);
+ assertScaledBitmapSize(8, 107, 160, actual);
+ assertNeedsToReload(false, actual, 284, 160);
+ }
+
+ private static void assertNeedsToReload(
+ boolean expected, ScaledBitmapInfo scaledBitmap, int reqWidth, int reqHeight) {
+ assertWithMessage(scaledBitmap.id + " needToReload(" + reqWidth + "," + reqHeight + ")")
+ .that(scaledBitmap.needToReload(reqWidth, reqHeight))
+ .isEqualTo(expected);
+ }
+
+ private static void assertScaledBitmapSize(
+ int expectedInSampleSize,
+ int expectedWidth,
+ int expectedHeight,
+ ScaledBitmapInfo actual) {
+ assertWithMessage(actual.id + " inSampleSize")
+ .that(actual.inSampleSize)
+ .isEqualTo(expectedInSampleSize);
+ assertWithMessage(actual.id + " width").that(actual.bitmap.getWidth()).isEqualTo(expectedWidth);
+ assertWithMessage(actual.id + " height")
+ .that(actual.bitmap.getHeight())
+ .isEqualTo(expectedHeight);
+ }
+}