aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShraddha Basantwani <shraddha.basantwani@ittiam.com>2019-11-07 14:59:29 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-11-07 14:59:29 -0800
commit9016b08332e1288ee1cfe85e0ec88fc2ccbe473f (patch)
tree2b4079d4d7c1498278c311bfd9c7c3ae90d00000
parent3f59e5e681a90b5d61274c2e3cc5aba0a1f1b54e (diff)
parent9526c2f1162ee4024dfdf93b121a95b0df0dfb53 (diff)
downloadTV-9016b08332e1288ee1cfe85e0ec88fc2ccbe473f.tar.gz
Enable robolectric build for tuner module
am: 9526c2f116 Change-Id: I9f72e8b22802ca88fdad488054d57590a0221b93
-rw-r--r--tuner/tests/robotests/Android.mk68
-rw-r--r--tuner/tests/robotests/javatests/com/android/tv/tuner/testing/TvTunerRobolectricTestRunner.java74
-rw-r--r--tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerExoV2Test.java6
-rw-r--r--tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerTest.java4
4 files changed, 147 insertions, 5 deletions
diff --git a/tuner/tests/robotests/Android.mk b/tuner/tests/robotests/Android.mk
new file mode 100644
index 00000000..16af9e9c
--- /dev/null
+++ b/tuner/tests/robotests/Android.mk
@@ -0,0 +1,68 @@
+#############################################################
+# Tv Robolectric test target. #
+#############################################################
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := TvTunerRoboTests
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+
+LOCAL_SRC_FILES := $(call all-java-files-under, javatests)
+
+LOCAL_JAVA_LIBRARIES := \
+ Robolectric_all-target \
+ mockito-robolectric-prebuilt \
+ robolectric_android-all-stub \
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+ tv-lib-dagger
+
+LOCAL_STATIC_ANDROID_LIBRARIES := \
+ androidx.test.core \
+ tv-lib-dagger-android \
+ tv-test-common \
+ tv-test-common-robo \
+ tv-tuner-testing \
+
+LOCAL_ANNOTATION_PROCESSORS := \
+ tv-lib-dagger-android-processor \
+ tv-lib-dagger-compiler \
+
+LOCAL_ANNOTATION_PROCESSOR_CLASSES := \
+ dagger.internal.codegen.ComponentProcessor,dagger.android.processor.AndroidProcessor
+
+LOCAL_INSTRUMENTATION_FOR := LiveTv
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+#############################################################
+# Tv runner target to run the previous target. #
+#############################################################
+include $(CLEAR_VARS)
+LOCAL_MODULE := RunTvTunerRoboTests
+
+BASE_DIR = com/android/tv/tuner
+EXCLUDE_FILES := \
+ $(BASE_DIR)/dvb/DvbTunerHalTest.java \
+ $(BASE_DIR)/exoplayer/tests/SampleSourceExtractorTest.java \
+
+LOCAL_ROBOTEST_FILES := $(call find-files-in-subdirs,$(LOCAL_PATH)/javatests,*Test.java,.)
+LOCAL_ROBOTEST_FILES := $(filter-out $(EXCLUDE_FILES),$(LOCAL_ROBOTEST_FILES))
+
+LOCAL_JAVA_LIBRARIES := \
+ Robolectric_all-target \
+ TvTunerRoboTests \
+ mockito-robolectric-prebuilt \
+ robolectric_android-all-stub \
+ tv-lib-truth \
+ tv-test-common \
+ tv-test-common-robo \
+ tv-tuner-testing \
+
+LOCAL_TEST_PACKAGE := LiveTv
+
+LOCAL_ROBOTEST_TIMEOUT := 36000
+
+include external/robolectric-shadows/run_robotests.mk
diff --git a/tuner/tests/robotests/javatests/com/android/tv/tuner/testing/TvTunerRobolectricTestRunner.java b/tuner/tests/robotests/javatests/com/android/tv/tuner/testing/TvTunerRobolectricTestRunner.java
new file mode 100644
index 00000000..31dc25d5
--- /dev/null
+++ b/tuner/tests/robotests/javatests/com/android/tv/tuner/testing/TvTunerRobolectricTestRunner.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.tv.tuner.testing;
+
+import org.junit.runners.model.InitializationError;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+import org.robolectric.manifest.AndroidManifest;
+import org.robolectric.res.Fs;
+import org.robolectric.res.ResourcePath;
+
+import java.util.List;
+
+/**
+ * Custom test runner TV tuner. This is needed because the default behavior for robolectric is just
+ * to grab the resource directory in the target package. We want to override this to add several
+ * spanning different projects.
+ *
+ * <p><b>Note</b> copied from
+ * http://cs/android/packages/apps/Settings/tests/robotests/src/com/android/settings/testutils/SettingsRobolectricTestRunner.java
+ */
+public class TvTunerRobolectricTestRunner extends RobolectricTestRunner {
+
+ /** We don't actually want to change this behavior, so we just call super. */
+ public TvTunerRobolectricTestRunner(Class<?> testClass) throws InitializationError {
+ super(testClass);
+ }
+
+ /**
+ * We are going to create our own custom manifest so that we can add multiple resource paths to
+ * it.
+ */
+ @Override
+ protected AndroidManifest getAppManifest(Config config) {
+ final String packageName = "com.android.tv.tuner";
+
+ // By adding any resources from libraries we need the AndroidManifest, we can access
+ // them from within the parallel universe's resource loader.
+ return new AndroidManifest(
+ Fs.fileFromPath(config.manifest()),
+ Fs.fileFromPath(config.resourceDir()),
+ Fs.fileFromPath(config.assetDir()),
+ packageName) {
+ @Override
+ public List<ResourcePath> getIncludedResourcePaths() {
+ List<ResourcePath> paths = super.getIncludedResourcePaths();
+ TvTunerRobolectricTestRunner.getIncludedResourcePaths(paths);
+ return paths;
+ }
+ };
+ }
+
+ public static void getIncludedResourcePaths(List<ResourcePath> paths) {
+ paths.add(
+ new ResourcePath(
+ null,
+ Fs.fileFromPath("./packages/apps/TV/tuner/res"),
+ null));
+ }
+}
diff --git a/tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerExoV2Test.java b/tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerExoV2Test.java
index bb107f2b..24adbaa9 100644
--- a/tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerExoV2Test.java
+++ b/tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerExoV2Test.java
@@ -37,6 +37,7 @@ import com.android.tv.testing.constants.ConfigConstants;
import com.android.tv.tuner.exoplayer.MpegTsPlayer;
import com.android.tv.tuner.source.TsDataSourceManager;
import com.android.tv.tuner.source.TunerTsStreamerManager;
+import com.android.tv.tuner.testing.TvTunerRobolectricTestRunner;
import com.android.tv.tuner.tvinput.datamanager.ChannelDataManager;
import com.google.android.exoplayer.audio.AudioCapabilities;
@@ -47,7 +48,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
-import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
@@ -57,8 +57,8 @@ import java.lang.reflect.Field;
import javax.inject.Provider;
-/** Tests for {@link TunerSessionWorker}. */
-@RunWith(RobolectricTestRunner.class)
+/** Tests for {@link TunerSessionWorkerExoV2}. */
+@RunWith(TvTunerRobolectricTestRunner.class)
@Config(sdk = ConfigConstants.SDK, application = TestSingletonApp.class)
public class TunerSessionWorkerExoV2Test {
diff --git a/tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerTest.java b/tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerTest.java
index c1c90839..536af60c 100644
--- a/tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerTest.java
+++ b/tuner/tests/robotests/javatests/com/android/tv/tuner/tvinput/TunerSessionWorkerTest.java
@@ -37,6 +37,7 @@ import com.android.tv.testing.constants.ConfigConstants;
import com.android.tv.tuner.exoplayer.MpegTsPlayer;
import com.android.tv.tuner.source.TsDataSourceManager;
import com.android.tv.tuner.source.TunerTsStreamerManager;
+import com.android.tv.tuner.testing.TvTunerRobolectricTestRunner;
import com.android.tv.tuner.tvinput.datamanager.ChannelDataManager;
import com.google.android.exoplayer.audio.AudioCapabilities;
@@ -47,7 +48,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
-import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
@@ -58,7 +58,7 @@ import java.lang.reflect.Field;
import javax.inject.Provider;
/** Tests for {@link TunerSessionWorker}. */
-@RunWith(RobolectricTestRunner.class)
+@RunWith(TvTunerRobolectricTestRunner.class)
@Config(sdk = ConfigConstants.SDK, application = TestSingletonApp.class)
public class TunerSessionWorkerTest {