From d9d9aec0e671cf0db89a8b58a81b1980834f1dc2 Mon Sep 17 00:00:00 2001 From: Kirill Grouchnikov Date: Wed, 18 Nov 2015 15:57:56 -0500 Subject: Initial proof-of-concept pass for TextViewCompat host testing. Change-Id: I6c194dac02ec24b0e5f77caa78461713324a4baa --- v4/build.gradle | 23 +++++++ v4/tests/AndroidManifest.xml | 32 +++++++++ .../android/support/v4/widget/TestActivity.java | 35 ++++++++++ .../support/v4/widget/TextViewCompatTest.java | 79 ++++++++++++++++++++++ .../v4/widget/test/TextViewTestActivity.java | 24 +++++++ 5 files changed, 193 insertions(+) create mode 100644 v4/tests/AndroidManifest.xml create mode 100644 v4/tests/java/android/support/v4/widget/TestActivity.java create mode 100644 v4/tests/java/android/support/v4/widget/TextViewCompatTest.java create mode 100644 v4/tests/java/android/support/v4/widget/test/TextViewTestActivity.java diff --git a/v4/build.gradle b/v4/build.gradle index 727ef3361f..ba65cabb07 100644 --- a/v4/build.gradle +++ b/v4/build.gradle @@ -64,6 +64,10 @@ dependencies { // depend on the generation of this jar. This is done below // when manipulating the libraryVariants. compile files(internalJar.archivePath) + + androidTestCompile 'com.android.support.test:testing-support-lib:0.1' + androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' + testCompile 'junit:junit:4.12' } android { @@ -73,6 +77,8 @@ android { minSdkVersion 4 // TODO: get target from branch //targetSdkVersion 19 + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } sourceSets { @@ -82,6 +88,8 @@ android { androidTest.setRoot('tests') androidTest.java.srcDir 'tests/java' + androidTest.res.srcDir 'tests/res' + androidTest.manifest.srcFile 'tests/AndroidManifest.xml' } lintOptions { @@ -93,6 +101,10 @@ android { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } + + testOptions { + unitTests.returnDefaultValues = true + } } android.libraryVariants.all { variant -> @@ -137,6 +149,17 @@ android.libraryVariants.all { variant -> artifacts.add('archives', sourcesJarTask); } +// TODO make this generic for all projects +afterEvaluate { + def originalTask = tasks['packageDebugAndroidTest'] + tasks['assembleDebugAndroidTest'].doLast { + copy { + from(originalTask.outputFile) + into(rootProject.ext.testApkDistOut) + } + } +} + uploadArchives { repositories { mavenDeployer { diff --git a/v4/tests/AndroidManifest.xml b/v4/tests/AndroidManifest.xml new file mode 100644 index 0000000000..556c885344 --- /dev/null +++ b/v4/tests/AndroidManifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/v4/tests/java/android/support/v4/widget/TestActivity.java b/v4/tests/java/android/support/v4/widget/TestActivity.java new file mode 100644 index 0000000000..9ab5188db1 --- /dev/null +++ b/v4/tests/java/android/support/v4/widget/TestActivity.java @@ -0,0 +1,35 @@ +/* + * 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 android.support.v4.widget; + +import android.app.Activity; +import android.os.Bundle; +import android.view.WindowManager; +import android.widget.FrameLayout; + +public class TestActivity extends Activity { + FrameLayout mContainer; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mContainer = new FrameLayout(this); + + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setContentView(mContainer); + } +} diff --git a/v4/tests/java/android/support/v4/widget/TextViewCompatTest.java b/v4/tests/java/android/support/v4/widget/TextViewCompatTest.java new file mode 100644 index 0000000000..a7d233909c --- /dev/null +++ b/v4/tests/java/android/support/v4/widget/TextViewCompatTest.java @@ -0,0 +1,79 @@ +/* + * 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 android.support.v4.widget; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import android.app.Instrumentation; +import android.test.ActivityInstrumentationTestCase2; +import android.support.test.InstrumentationRegistry; +import android.support.v4.widget.TextViewCompat; +import android.util.Log; +import android.widget.TextView; + +import android.support.test.runner.AndroidJUnit4; + +@RunWith(AndroidJUnit4.class) +public class TextViewCompatTest extends ActivityInstrumentationTestCase2 { + private boolean mDebug; + + Throwable mainThreadException; + + Thread mInstrumentationThread; + + public TextViewCompatTest() { + super("android.support.v4.widget", TestActivity.class); + mDebug = false; + } + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + mInstrumentationThread = Thread.currentThread(); + + // Note that injectInstrumentation was added in v5. Since this is v4 we have to use + // the misspelled (and deprecated) inject API. + injectInsrumentation(InstrumentationRegistry.getInstrumentation()); + } + + @After + @Override + public void tearDown() throws Exception { + getInstrumentation().waitForIdleSync(); + super.tearDown(); + } + + @Test + public void testMaxLines() throws Throwable { + final TextView textView = new TextView(getActivity()); + textView.setMaxLines(4); + + runTestOnUiThread(new Runnable() { + @Override + public void run() { + getActivity().mContainer.addView(textView); + } + }); + + assertEquals("Max lines must match", TextViewCompat.getMaxLines(textView), 4); + } +} diff --git a/v4/tests/java/android/support/v4/widget/test/TextViewTestActivity.java b/v4/tests/java/android/support/v4/widget/test/TextViewTestActivity.java new file mode 100644 index 0000000000..7366127815 --- /dev/null +++ b/v4/tests/java/android/support/v4/widget/test/TextViewTestActivity.java @@ -0,0 +1,24 @@ +/* + * 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 android.support.v4.widget.test; + + +import android.app.Activity; + +public class TextViewTestActivity extends Activity { + +} -- cgit v1.2.3