diff options
| author | Steve Kondik <steve@cyngn.com> | 2016-03-10 19:23:13 -0800 |
|---|---|---|
| committer | Steve Kondik <steve@cyngn.com> | 2016-03-10 19:23:13 -0800 |
| commit | 98e06d73262bc654d546ef2ded2cd6c4db5b92bf (patch) | |
| tree | d923c571c21849bf53185b26e3570fdb25fabff9 /v4/tests | |
| parent | 6f0a2cb4415e2e170528c038a8f1cc2f68f60c3c (diff) | |
| parent | 4097efdd93078034122f17442d5b4df675d1028a (diff) | |
| download | android_frameworks_support-98e06d73262bc654d546ef2ded2cd6c4db5b92bf.tar.gz android_frameworks_support-98e06d73262bc654d546ef2ded2cd6c4db5b92bf.tar.bz2 android_frameworks_support-98e06d73262bc654d546ef2ded2cd6c4db5b92bf.zip | |
Merge tag 'android-6.0.1_r22' of https://android.googlesource.com/platform/frameworks/support into cm-13.0staging/cm-13.0+r22
Android 6.0.1 release 22
Change-Id: I032842dcd2a5a216a56a47a7cb109f0cee8ac251
Diffstat (limited to 'v4/tests')
5 files changed, 236 insertions, 10 deletions
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/graphics/ColorUtilsTest.java b/v4/tests/java/android/support/v4/graphics/ColorUtilsTest.java index 855cdba3a5..56cb6fbf43 100644 --- a/v4/tests/java/android/support/v4/graphics/ColorUtilsTest.java +++ b/v4/tests/java/android/support/v4/graphics/ColorUtilsTest.java @@ -17,9 +17,9 @@ package android.support.v4.graphics; import android.graphics.Color; -import android.support.v4.graphics.ColorUtils; import android.test.AndroidTestCase; +import java.lang.Integer; import java.util.ArrayList; /** @@ -31,21 +31,31 @@ public class ColorUtilsTest extends AndroidTestCase { private static final float ALLOWED_OFFSET_HUE = 360 * 0.005f; private static final float ALLOWED_OFFSET_SATURATION = 0.005f; private static final float ALLOWED_OFFSET_LIGHTNESS = 0.005f; + private static final float ALLOWED_OFFSET_MIN_ALPHA = 0.01f; private static final int ALLOWED_OFFSET_RGB_COMPONENT = 2; private static final ArrayList<TestEntry> sEntryList = new ArrayList<>(); static { - sEntryList.add(new TestEntry(Color.BLACK).setHsl(0f, 0f, 0f)); - sEntryList.add(new TestEntry(Color.WHITE).setHsl(0f, 0f, 1f)); - sEntryList.add(new TestEntry(Color.BLUE).setHsl(240f, 1f, 0.5f)); - sEntryList.add(new TestEntry(Color.GREEN).setHsl(120f, 1f, 0.5f)); - sEntryList.add(new TestEntry(Color.RED).setHsl(0f, 1f, 0.5f)); - sEntryList.add(new TestEntry(Color.CYAN).setHsl(180f, 1f, 0.5f)); - sEntryList.add(new TestEntry(0x2196F3).setHsl(207f, 0.9f, 0.54f)); - sEntryList.add(new TestEntry(0xD1C4E9).setHsl(261f, 0.46f, 0.84f)); - sEntryList.add(new TestEntry(0x311B92).setHsl(251.09f, 0.687f, 0.339f)); + sEntryList.add(new TestEntry(Color.BLACK).setHsl(0f, 0f, 0f) + .setWhiteMinAlpha30(0.35f).setWhiteMinAlpha45(0.46f)); + sEntryList.add(new TestEntry(Color.WHITE).setHsl(0f, 0f, 1f) + .setBlackMinAlpha30(0.42f).setBlackMinAlpha45(0.54f)); + sEntryList.add(new TestEntry(Color.BLUE).setHsl(240f, 1f, 0.5f) + .setWhiteMinAlpha30(0.55f).setWhiteMinAlpha45(0.71f)); + sEntryList.add(new TestEntry(Color.GREEN).setHsl(120f, 1f, 0.5f) + .setBlackMinAlpha30(0.43f).setBlackMinAlpha45(0.55f)); + sEntryList.add(new TestEntry(Color.RED).setHsl(0f, 1f, 0.5f) + .setWhiteMinAlpha30(0.84f).setBlackMinAlpha30(0.55f).setBlackMinAlpha45(0.78f)); + sEntryList.add(new TestEntry(Color.CYAN).setHsl(180f, 1f, 0.5f) + .setBlackMinAlpha30(0.43f).setBlackMinAlpha45(0.55f)); + sEntryList.add(new TestEntry(0xFF2196F3).setHsl(207f, 0.9f, 0.54f) + .setBlackMinAlpha30(0.52f).setWhiteMinAlpha30(0.97f).setBlackMinAlpha45(0.7f)); + sEntryList.add(new TestEntry(0xFFD1C4E9).setHsl(261f, 0.46f, 0.84f) + .setBlackMinAlpha30(0.45f).setBlackMinAlpha45(0.58f)); + sEntryList.add(new TestEntry(0xFF311B92).setHsl(251.09f, 0.687f, 0.339f) + .setWhiteMinAlpha30(0.39f).setWhiteMinAlpha45(0.54f)); } public void testToHSL() { @@ -72,6 +82,28 @@ public class ColorUtilsTest extends AndroidTestCase { } } + public void testMinAlphas() { + for (TestEntry entry : sEntryList) { + testMinAlpha("Black title", entry.rgb, entry.blackMinAlpha30, + ColorUtils.calculateMinimumAlpha(Color.BLACK, entry.rgb, 3.0f)); + testMinAlpha("Black body", entry.rgb, entry.blackMinAlpha45, + ColorUtils.calculateMinimumAlpha(Color.BLACK, entry.rgb, 4.5f)); + testMinAlpha("White title", entry.rgb, entry.whiteMinAlpha30, + ColorUtils.calculateMinimumAlpha(Color.WHITE, entry.rgb, 3.0f)); + testMinAlpha("White body", entry.rgb, entry.whiteMinAlpha45, + ColorUtils.calculateMinimumAlpha(Color.WHITE, entry.rgb, 4.5f)); + } + } + + private static void testMinAlpha(String title, int color, float expected, int actual) { + final String message = title + " text within error for #" + Integer.toHexString(color); + if (expected < 0) { + assertEquals(message, actual, -1); + } else { + assertClose(message, expected, actual / 255f, ALLOWED_OFFSET_MIN_ALPHA); + } + } + private static void assertClose(String message, float expected, float actual, float allowedOffset) { StringBuilder sb = new StringBuilder(message); @@ -114,6 +146,10 @@ public class ColorUtilsTest extends AndroidTestCase { private static class TestEntry { final int rgb; final float[] hsl = new float[3]; + float blackMinAlpha45 = -1; + float blackMinAlpha30 = -1; + float whiteMinAlpha45 = -1; + float whiteMinAlpha30 = -1; TestEntry(int rgb) { this.rgb = rgb; @@ -125,5 +161,25 @@ public class ColorUtilsTest extends AndroidTestCase { hsl[2] = l; return this; } + + TestEntry setBlackMinAlpha30(float minAlpha) { + blackMinAlpha30 = minAlpha; + return this; + } + + TestEntry setBlackMinAlpha45(float minAlpha) { + blackMinAlpha45 = minAlpha; + return this; + } + + TestEntry setWhiteMinAlpha30(float minAlpha) { + whiteMinAlpha30 = minAlpha; + return this; + } + + TestEntry setWhiteMinAlpha45(float minAlpha) { + whiteMinAlpha45 = minAlpha; + return this; + } } }
\ No newline at end of file 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 { + +} |
