diff options
author | Kirill Grouchnikov <kirillg@google.com> | 2015-11-18 15:57:56 -0500 |
---|---|---|
committer | Kirill Grouchnikov <kirillg@google.com> | 2015-11-19 08:49:44 -0500 |
commit | d9d9aec0e671cf0db89a8b58a81b1980834f1dc2 (patch) | |
tree | 7c996de1cbd2b916754f750c776ed0fd9149708d | |
parent | fe8757b9957264c4bfde40a2067252e9a33e2ada (diff) | |
download | android_frameworks_support-d9d9aec0e671cf0db89a8b58a81b1980834f1dc2.tar.gz android_frameworks_support-d9d9aec0e671cf0db89a8b58a81b1980834f1dc2.tar.bz2 android_frameworks_support-d9d9aec0e671cf0db89a8b58a81b1980834f1dc2.zip |
Initial proof-of-concept pass for TextViewCompat host testing.
Change-Id: I6c194dac02ec24b0e5f77caa78461713324a4baa
-rw-r--r-- | v4/build.gradle | 23 | ||||
-rw-r--r-- | v4/tests/AndroidManifest.xml | 32 | ||||
-rw-r--r-- | v4/tests/java/android/support/v4/widget/TestActivity.java | 35 | ||||
-rw-r--r-- | v4/tests/java/android/support/v4/widget/TextViewCompatTest.java | 79 | ||||
-rw-r--r-- | v4/tests/java/android/support/v4/widget/test/TextViewTestActivity.java | 24 |
5 files changed, 193 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ 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. + --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + package="android.support.v4.test"> + <uses-sdk android:minSdkVersion="4" tools:overrideLibrary="android.support.test, + android.support.test.espresso, android.support.test.espresso.idling"/> + + <application> + <uses-library android:name="android.test.runner" /> + <activity android:name="android.support.v4.widget.test.TextViewTestActivity"/> + <activity android:name="android.support.v4.widget.TestActivity"/> + </application> + + <instrumentation android:name="android.test.InstrumentationTestRunner" + android:targetPackage="android.support.v4.test" + /> +</manifest> 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<TestActivity> { + 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 { + +} |