Merge "Initial proof-of-concept pass for TextViewCompat host testing." into mnc-ub-dev
diff --git a/v4/build.gradle b/v4/build.gradle
index 727ef33..ba65cab 100644
--- a/v4/build.gradle
+++ b/v4/build.gradle
@@ -64,6 +64,10 @@
     // 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 @@
         minSdkVersion 4
         // TODO: get target from branch
         //targetSdkVersion 19
+
+        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
     }
 
     sourceSets {
@@ -82,6 +88,8 @@
 
         androidTest.setRoot('tests')
         androidTest.java.srcDir 'tests/java'
+        androidTest.res.srcDir 'tests/res'
+        androidTest.manifest.srcFile 'tests/AndroidManifest.xml'
     }
 
     lintOptions {
@@ -93,6 +101,10 @@
         sourceCompatibility JavaVersion.VERSION_1_7
         targetCompatibility JavaVersion.VERSION_1_7
     }
+
+    testOptions {
+        unitTests.returnDefaultValues = true
+    }
 }
 
 android.libraryVariants.all { variant ->
@@ -137,6 +149,17 @@
     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 0000000..556c885
--- /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 0000000..9ab5188
--- /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 0000000..a7d2339
--- /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 0000000..7366127
--- /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 {
+
+}