aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java1
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidHostServiceFixtureTest.java168
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/BUILD16
3 files changed, 185 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
index 8c3d325bd4..185f52892c 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
@@ -55,6 +55,7 @@ public abstract class AndroidBuildViewTestCase extends BuildViewTestCase {
return builder
// TODO(b/35097211): Remove this once the new testing rules are released.
.addRuleDefinition(new AndroidDeviceScriptFixtureRule())
+ .addRuleDefinition(new AndroidHostServiceFixtureRule())
.addRuleDefinition(new AndroidInstrumentationRule())
.build();
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidHostServiceFixtureTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidHostServiceFixtureTest.java
new file mode 100644
index 0000000000..1d77e5db4f
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidHostServiceFixtureTest.java
@@ -0,0 +1,168 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// 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.google.devtools.build.lib.rules.android;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.RunfilesProvider;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link AndroidHostServiceFixture}. */
+@RunWith(JUnit4.class)
+public class AndroidHostServiceFixtureTest extends AndroidBuildViewTestCase {
+
+ @Before
+ public void setup() throws Exception {
+ scratch.file(
+ "java/com/server/BUILD",
+ "java_binary(",
+ " name = 'server',",
+ " main_class = 'does.not.exist',",
+ " srcs = [],",
+ ")");
+ scratch.file(
+ "java/com/app/BUILD",
+ "android_binary(",
+ " name = 'support',",
+ " manifest = 'AndroidManifest.xml',",
+ ")",
+ "genrule(",
+ " name = 'genrule',",
+ " outs = ['generated.apk'],",
+ " cmd = 'touch $(OUTS)',",
+ ")");
+ }
+
+ @Test
+ public void testPropagatesExecutableRunfiles() throws Exception {
+ ConfiguredTarget hostServiceFixture =
+ scratchConfiguredTarget(
+ "javatests/com/app/BUILD",
+ "fixture",
+ "android_host_service_fixture(",
+ " name = 'fixture',",
+ " executable = '//java/com/server',",
+ ")");
+ assertThat(hostServiceFixture).isNotNull();
+ assertThat(
+ ActionsTestUtil.prettyArtifactNames(
+ hostServiceFixture
+ .getProvider(RunfilesProvider.class)
+ .getDefaultRunfiles()
+ .getArtifactsWithoutMiddlemen()))
+ .containsExactlyElementsIn(
+ ActionsTestUtil.prettyArtifactNames(
+ getConfiguredTarget("//java/com/server")
+ .getProvider(RunfilesProvider.class)
+ .getDefaultRunfiles()
+ .getArtifacts()));
+ }
+
+ @Test
+ public void testProvidesServiceNames() throws Exception {
+ ConfiguredTarget hostServiceFixture =
+ scratchConfiguredTarget(
+ "javatests/com/app/BUILD",
+ "fixture",
+ "android_host_service_fixture(",
+ " name = 'fixture',",
+ " executable = '//java/com/server',",
+ " service_names = ['proxy', 'echo'],",
+ ")");
+ assertThat(getHostServiceFixtureInfoProvider(hostServiceFixture).getServiceNames())
+ .containsExactly("proxy", "echo")
+ .inOrder();
+ }
+
+ @Test
+ public void testProvidesSupportApks() throws Exception {
+ ConfiguredTarget hostServiceFixture =
+ scratchConfiguredTarget(
+ "javatests/com/app/BUILD",
+ "fixture",
+ "android_host_service_fixture(",
+ " name = 'fixture',",
+ " executable = '//java/com/server',",
+ " service_names = ['proxy', 'echo'],",
+ " support_apks = [",
+ " '//java/com/app:support',",
+ " '//java/com/app:generated.apk',",
+ " ],",
+ ")");
+ assertThat(
+ ActionsTestUtil.prettyArtifactNames(
+ getHostServiceFixtureInfoProvider(hostServiceFixture).getSupportApks()))
+ .containsExactly("java/com/app/support.apk", "java/com/app/generated.apk")
+ .inOrder();
+ }
+
+ @Test
+ public void testProvidesProvidesTestArgs() throws Exception {
+ scratch.file(
+ "javatests/com/app/BUILD",
+ "android_host_service_fixture(",
+ " name = 'fixture_with_no_test_args',",
+ " executable = '//java/com/server',",
+ ")",
+ "android_host_service_fixture(",
+ " name = 'fixture_with_test_args',",
+ " executable = '//java/com/server',",
+ " provides_test_args = 1,",
+ ")");
+ assertThat(
+ getHostServiceFixtureInfoProvider(
+ getConfiguredTarget("//javatests/com/app:fixture_with_no_test_args"))
+ .getProvidesTestArgs())
+ .isFalse();
+ assertThat(
+ getHostServiceFixtureInfoProvider(
+ getConfiguredTarget("//javatests/com/app:fixture_with_test_args"))
+ .getProvidesTestArgs())
+ .isTrue();
+ }
+
+ @Test
+ public void testProvidesDaemon() throws Exception {
+ scratch.file(
+ "javatests/com/app/BUILD",
+ "android_host_service_fixture(",
+ " name = 'no_daemon',",
+ " executable = '//java/com/server',",
+ ")",
+ "android_host_service_fixture(",
+ " name = 'daemon',",
+ " executable = '//java/com/server',",
+ " daemon = 1,",
+ ")");
+ assertThat(
+ getHostServiceFixtureInfoProvider(getConfiguredTarget("//javatests/com/app:no_daemon"))
+ .getIsDaemon())
+ .isFalse();
+ assertThat(
+ getHostServiceFixtureInfoProvider(getConfiguredTarget("//javatests/com/app:daemon"))
+ .getIsDaemon())
+ .isTrue();
+ }
+
+ private AndroidHostServiceFixtureInfoProvider getHostServiceFixtureInfoProvider(
+ ConfiguredTarget ct) throws Exception {
+ return (AndroidHostServiceFixtureInfoProvider)
+ ct.get(AndroidHostServiceFixtureInfoProvider.ANDROID_HOST_SERVICE_FIXTURE_INFO.getKey());
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
index db8e70ecda..8e732e018e 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
@@ -95,6 +95,22 @@ java_test(
)
java_test(
+ name = "AndroidHostServiceFixtureTest",
+ srcs = ["AndroidHostServiceFixtureTest.java"],
+ deps = [
+ ":AndroidBuildViewTestCase",
+ "//src/main/java/com/google/devtools/build/lib:android-rules",
+ "//src/main/java/com/google/devtools/build/lib:build-base",
+ "//src/main/java/com/google/devtools/build/lib/actions",
+ "//src/test/java/com/google/devtools/build/lib:actions_testutil",
+ "//src/test/java/com/google/devtools/build/lib:analysis_testutil",
+ "//src/test/java/com/google/devtools/build/lib:testutil",
+ "//third_party:junit4",
+ "//third_party:truth",
+ ],
+)
+
+java_test(
name = "AndroidInstrumentationRuleImplTest",
srcs = ["AndroidInstrumentationRuleImplTest.java"],
deps = [